LibPkg
path_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 #ifndef LIBPKG_PATH_TABLE
17 #define LIBPKG_PATH_TABLE
18 
19 #include <map>
20 #include <string>
21 #include <stdexcept>
22 
23 #include "libpkg/table.h"
24 
25 namespace pkg {
26 
27 using std::string;
28 
34 class path_table:
35  public table
36 {
37 public:
38  typedef string key_type;
39  typedef string mapped_type;
40  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
41  class parse_error;
42  class invalid_source_path;
43  class commit_error;
44 private:
47  string _pathname;
48 
53  std::map<key_type,mapped_type> _data;
54 public:
56  path_table();
57 
61  path_table(const string& pathname);
62 
64  virtual ~path_table();
65 
71  string operator()(const string& src_pathname,const string& pkgname) const;
72 
76  const_iterator begin() const
77  { return _data.begin(); }
78 
82  const_iterator end() const
83  { return _data.end(); }
84 
89  const_iterator find(const string& src_pathname);
90 
95  void alter(const string& src_pathname,const string& dst_pathname);
96 
100  void erase(const string& src_pathname);
101 
103  void clear();
104 
108  size_t size() const
109  { return _data.size(); }
110 
115  void commit();
116 
121  void rollback();
122 
127  bool ensure_defaults();
128 private:
133  bool read(const string& pathname);
134 };
135 
138  public std::runtime_error
139 {
140 public:
144  parse_error(const string& message);
145 };
146 
149  public std::runtime_error
150 {
151 public:
153  invalid_source_path(const string& path);
154 };
155 
158  public std::runtime_error
159 {
160 public:
162  commit_error();
163 };
164 
176 string resolve_pathrefs(const path_table& table,const string& in);
177 
178 }; /* namespace pkg */
179 
180 #endif
const_iterator find(const string &src_pathname)
Find table entry.
Definition: path_table.cc:116
void erase(const string &src_pathname)
Erase table entry.
Definition: path_table.cc:133
size_t size() const
Get number of paths in table.
Definition: path_table.h:108
virtual ~path_table()
Destroy path table.
Definition: path_table.cc:74
void rollback()
Roll back changes.
Definition: path_table.cc:186
string operator()(const string &src_pathname, const string &pkgname) const
Convert source pathname to destination pathname.
Definition: path_table.cc:77
An exception class for reporting failure to commit table.
Definition: path_table.h:157
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
string resolve_pathrefs(const path_table &paths, const string &in)
Resolve logical path references.
Definition: path_table.cc:309
string key_type
Definition: path_table.h:38
path_table()
Construct empty path table.
Definition: path_table.cc:65
bool ensure_defaults()
Ensure that default paths are present in the table.
Definition: path_table.cc:197
void alter(const string &src_pathname, const string &dst_pathname)
Alter table entry.
Definition: path_table.cc:127
const_iterator begin() const
Get const iterator for start of table.
Definition: path_table.h:76
void commit()
Commit changes.
Definition: path_table.cc:145
string mapped_type
Definition: path_table.h:39
const_iterator end() const
Get const iterator for end of table.
Definition: path_table.h:82
const char * dst_pathname
Definition: path_table.cc:32
void clear()
Clear all paths.
Definition: path_table.cc:139
std::map< key_type, mapped_type >::const_iterator const_iterator
Definition: path_table.h:40
const char * src_pathname
Definition: path_table.cc:31
An exception class for reporting invalid source paths.
Definition: path_table.h:148
A base class to represent a data table.
Definition: table.h:29
An exception class for reporting parse errors.
Definition: path_table.h:137
A class for mapping source paths to destination paths.
Definition: path_table.h:34

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)