LibPkg
binary_control_table.h
Go to the documentation of this file.
1 // This file is part of the LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef LIBPKG_BINARY_CONTROL_TABLE
18 #define LIBPKG_BINARY_CONTROL_TABLE
19 
20 #include <map>
21 #include <string>
22 
23 #include "libpkg/version.h"
24 #include "libpkg/binary_control.h"
25 #include "libpkg/table.h"
26 
27 namespace pkg {
28 
29 using std::string;
30 
33  public table
34 {
35 public:
37  class key_type
38  {
39  public:
41  string pkgname;
45  string pkgenv;
47  key_type();
53  key_type(const string& _pkgname,const version& _pkgvrsn, const string &_pkgenv);
54  };
56  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
57  class commit_error;
58 private:
60  string _pathname;
61 
63  std::map<key_type,mapped_type> _data;
64 public:
68  binary_control_table(const string& pathname);
69 
71  virtual ~binary_control_table();
72 
77  const mapped_type& operator[](const key_type& key) const;
78 
84  bool contains(const key_type& key) const;
85 
90  const mapped_type& operator[](const string& pkgname) const;
91 
95  const_iterator begin() const
96  { return _data.begin(); }
97 
101  const_iterator end() const
102  { return _data.end(); }
103 
109  void insert(const mapped_type& ctrl);
110 
116  void commit();
117 
119  void update();
120 };
121 
128  const binary_control_table::key_type& rhs);
129 
132  public std::runtime_error
133 {
134 public:
136  commit_error();
137 };
138 
139 }; /* namespace pkg */
140 
141 #endif
const mapped_type & operator[](const key_type &key) const
Get control record for package given package name and version.
Definition: binary_control_table.cc:34
void update()
Re-read the underlying package index file.
Definition: binary_control_table.cc:67
A class for specifying the name and version of a package.
Definition: binary_control_table.h:37
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
void commit()
Commit changes.
Definition: binary_control_table.cc:87
std::map< key_type, mapped_type >::const_iterator const_iterator
Definition: binary_control_table.h:56
bool operator<(const binary_control_table::key_type &lhs, const binary_control_table::key_type &rhs)
Compare two binary control table keys.
Definition: binary_control_table.cc:138
key_type()
Construct default key type.
Definition: binary_control_table.cc:127
version pkgvrsn
The package version.
Definition: binary_control_table.h:43
const_iterator begin() const
Get const iterator for start of table.
Definition: binary_control_table.h:95
bool contains(const key_type &key) const
Check if a key has a corresponding control record.
Definition: binary_control_table.cc:41
virtual ~binary_control_table()
Destroy binary control table.
Definition: binary_control_table.cc:30
binary_control_table(const string &pathname)
Construct binary control table.
Definition: binary_control_table.cc:24
A class for mapping package name and version to binary control record.
Definition: binary_control_table.h:32
A class to represent a package version.
Definition: version.h:32
binary_control mapped_type
Definition: binary_control_table.h:55
string pkgname
The package name.
Definition: binary_control_table.h:41
const_iterator end() const
Get const iterator for end of table.
Definition: binary_control_table.h:101
string pkgenv
The package environment id.
Definition: binary_control_table.h:45
void insert(const mapped_type &ctrl)
Insert control record into table.
Definition: binary_control_table.cc:60
A class to represent the content of a RiscPkg binary control file.
Definition: binary_control.h:35
A base class to represent a data table.
Definition: table.h:29
An exception class for reporting failure to commit table.
Definition: binary_control_table.h:131

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)