LibPkg
path_table.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright © 2003-2010 Graham Shaw.
3 // Distribution and use are subject to the GNU Lesser General Public License,
4 // a copy of which may be found in the file !LibPkg.Copyright.
5 
6 #ifndef LIBPKG_PATH_TABLE
7 #define LIBPKG_PATH_TABLE
8 
9 #include <map>
10 #include <string>
11 #include <stdexcept>
12 
13 #include "libpkg/table.h"
14 
15 namespace pkg {
16 
17 using std::string;
18 
24 class path_table:
25  public table
26 {
27 public:
28  typedef string key_type;
29  typedef string mapped_type;
30  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
31  class parse_error;
32  class invalid_source_path;
33  class commit_error;
34 private:
37  string _pathname;
38 
43  std::map<key_type,mapped_type> _data;
44 public:
46  path_table();
47 
51  path_table(const string& pathname);
52 
54  virtual ~path_table();
55 
61  string operator()(const string& src_pathname,const string& pkgname) const;
62 
67  { return _data.begin(); }
68 
73  { return _data.end(); }
74 
79  const_iterator find(const string& src_pathname);
80 
85  void alter(const string& src_pathname,const string& dst_pathname);
86 
90  void erase(const string& src_pathname);
91 
93  void clear();
94 
98  size_t size() const
99  { return _data.size(); }
100 
105  void commit();
106 
111  void rollback();
112 
117  bool ensure_defaults();
118 private:
123  bool read(const string& pathname);
124 };
125 
128  public std::runtime_error
129 {
130 public:
134  parse_error(const string& message);
135 };
136 
139  public std::runtime_error
140 {
141 public:
143  invalid_source_path(const string& path);
144 };
145 
148  public std::runtime_error
149 {
150 public:
152  commit_error();
153 };
154 
166 string resolve_pathrefs(const path_table& table,const string& in);
167 
168 }; /* namespace pkg */
169 
170 #endif
const_iterator find(const string &src_pathname)
Find table entry.
Definition: path_table.cc:101
void erase(const string &src_pathname)
Erase table entry.
Definition: path_table.cc:118
virtual ~path_table()
Destroy path table.
Definition: path_table.cc:59
void rollback()
Roll back changes.
Definition: path_table.cc:171
parse_error(const string &message)
Construct parse error.
Definition: path_table.cc:282
An exception class for reporting failure to commit table.
Definition: path_table.h:147
size_t size() const
Get number of paths in table.
Definition: path_table.h:98
char * _data
Definition: zipfile.cc:68
string resolve_pathrefs(const path_table &paths, const string &in)
Resolve logical path references.
Definition: path_table.cc:294
string key_type
Definition: path_table.h:28
string operator()(const string &src_pathname, const string &pkgname) const
Convert source pathname to destination pathname.
Definition: path_table.cc:62
path_table()
Construct empty path table.
Definition: path_table.cc:50
bool ensure_defaults()
Ensure that default paths are present in the table.
Definition: path_table.cc:182
void alter(const string &src_pathname, const string &dst_pathname)
Alter table entry.
Definition: path_table.cc:112
void commit()
Commit changes.
Definition: path_table.cc:130
invalid_source_path(const string &path)
Construct invalid source path error.
Definition: path_table.cc:286
string mapped_type
Definition: path_table.h:29
const_iterator end() const
Get const iterator for end of table.
Definition: path_table.h:72
const char * dst_pathname
Definition: path_table.cc:20
void clear()
Clear all paths.
Definition: path_table.cc:124
std::map< key_type, mapped_type >::const_iterator const_iterator
Definition: path_table.h:30
commit_error()
Construct commit error.
Definition: path_table.cc:290
const char * src_pathname
Definition: path_table.cc:19
An exception class for reporting invalid source paths.
Definition: path_table.h:138
A base class to represent a data table.
Definition: table.h:18
An exception class for reporting parse errors.
Definition: path_table.h:127
A class for mapping source paths to destination paths.
Definition: path_table.h:24
const_iterator begin() const
Get const iterator for start of table.
Definition: path_table.h:66

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)