LibPkg
status_table.h
Go to the documentation of this file.
1 // This file is part of 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_STATUS_TABLE
18 #define LIBPKG_STATUS_TABLE
19 
20 #include <map>
21 #include <string>
22 
23 #include "libpkg/status.h"
24 #include "libpkg/table.h"
25 
26 namespace pkg {
27 
28 using std::string;
29 
32  public table
33 {
34 public:
35  typedef string key_type;
37  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
38  class commit_error;
39 private:
42  string _pathname;
43 
45  std::map<key_type,mapped_type> _data;
46 public:
50  status_table(const string& pathname=string());
51 
53  virtual ~status_table();
54 
60  const mapped_type& operator[](const key_type& key) const;
61 
65  const_iterator begin() const
66  { return _data.begin(); }
67 
71  const_iterator end() const
72  { return _data.end(); }
73 
78  const_iterator find(const key_type& key) const;
79 
86  void insert(const key_type& key,const mapped_type& value);
87 
91  void insert(const status_table& table);
92 
94  void clear();
95 
100  void commit();
101 
106  void rollback();
107 private:
112  bool read(const string& pathname);
113 };
114 
117  public std::runtime_error
118 {
119 public:
121  commit_error();
122 };
123 
124 }; /* namespace pkg */
125 
126 #endif
void insert(const key_type &key, const mapped_type &value)
Set status of package.
Definition: status_table.cc:47
const_iterator begin() const
Get const iterator for start of table.
Definition: status_table.h:65
status mapped_type
Definition: status_table.h:36
virtual ~status_table()
Destroy status table.
Definition: status_table.cc:31
status_table(const string &pathname=string())
Construct status table.
Definition: status_table.cc:25
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
const mapped_type & operator[](const key_type &key) const
Get status of package.
Definition: status_table.cc:35
std::map< key_type, mapped_type >::const_iterator const_iterator
Definition: status_table.h:37
A class to represent the current or required status of a package.
Definition: status.h:44
void commit()
Commit changes.
Definition: status_table.cc:68
const_iterator end() const
Get const iterator for end of table.
Definition: status_table.h:71
An exception class for reporting failure to commit table.
Definition: status_table.h:116
string key_type
Definition: status_table.h:35
void clear()
Clear status of all packages.
Definition: status_table.cc:62
A class for mapping package name to package status.
Definition: status_table.h:31
void rollback()
Roll back changes.
Definition: status_table.cc:110
const_iterator find(const key_type &key) const
Find const iterator for package.
Definition: status_table.cc:42
A base class to represent a data table.
Definition: table.h:29

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)