LibPkg
control.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 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_CONTROL
7 #define LIBPKG_CONTROL
8 
9 #include <map>
10 #include <string>
11 #include <iosfwd>
12 #include <stdexcept>
13 
14 namespace pkg {
15 
16 using std::string;
17 
24 class control
25 {
26 public:
35  class key_type:
36  public string
37  {
38  friend class control;
39  private:
41  int _priority;
42  public:
46  key_type(const string& value);
47 
51  key_type(const char* value);
52 
56  int priority() const
57  { return _priority; }
58  };
59 
61  typedef string mapped_type;
62 
64  typedef std::pair<const key_type,mapped_type> value_type;
65 
67  typedef std::map<key_type,mapped_type>::iterator iterator;
68 
70  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
71 
72  class parse_error;
73 private:
78  class cmp_key
79  {
80  public:
86  bool operator()(const key_type& lhs,const key_type& rhs) const;
87  };
88 
90  std::map<key_type,mapped_type,cmp_key> _data;
91 public:
93  control();
94 
96  virtual ~control();
97 
101  const_iterator begin() const
102  { return _data.begin(); }
103 
107  const_iterator end() const
108  { return _data.end(); }
109 
114  const_iterator find(key_type key) const;
115 
119  iterator begin()
120  { return _data.begin(); }
121 
125  iterator end()
126  { return _data.end(); }
127 
132  iterator find(key_type key);
133 
142  mapped_type& operator[](key_type key);
143 
147  void clear();
148 
152  unsigned int size();
153 
157  string pkgname() const;
158 
163  string version() const;
164 
169  string standards_version() const;
170 
174  string description() const;
175 
180  string short_description() const;
181 
186  string depends() const;
187 
192  string recommends() const;
193 
198  string suggests() const;
199 
204  string conflicts() const;
205 
210  string url() const;
211 
217  string components() const;
218 
223  string environment() const;
224 
229  string osdepends() const;
230 
231 protected:
242  virtual int priority(const string& value) const;
243 };
244 
247  public std::runtime_error
248 {
249 public:
253  parse_error(const char* message);
254 };
255 
261 std::ostream& operator<<(std::ostream& out,const control& ctrl);
262 
268 std::istream& operator>>(std::istream& in,control& ctrl);
269 
270 }; /* namespace pkg */
271 
272 #endif
key_type(const string &value)
Construct key from string.
Definition: control.cc:145
const_iterator begin() const
Get constant iterator for beginning of control file.
Definition: control.h:101
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:179
std::map< key_type, mapped_type >::iterator iterator
The iterator type.
Definition: control.h:67
string suggests() const
Get suggestions.
Definition: control.cc:83
string standards_version() const
Get standard-version.
Definition: control.cc:62
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
string pkgname() const
Get package name.
Definition: control.cc:48
An exception class for reporting parse errors.
Definition: control.h:246
iterator end()
Get iterator for end of control file.
Definition: control.h:125
The key type.
Definition: control.h:35
std::istream & operator>>(std::istream &in, component &comp)
Read component record from input stream.
Definition: component.cc:193
int priority() const
Get priority.
Definition: control.h:56
string depends() const
Get dependencies.
Definition: control.cc:69
virtual ~control()
Destroy control file.
Definition: control.cc:22
void clear()
Clear control file.
Definition: control.cc:43
std::pair< const key_type, mapped_type > value_type
The value type.
Definition: control.h:64
const_iterator end() const
Get constant iterator for end of control file.
Definition: control.h:107
std::map< key_type, mapped_type >::const_iterator const_iterator
The constant iterator type.
Definition: control.h:70
friend class control
Definition: control.h:38
A class to represent the content of a RiscPkg control file.
Definition: control.h:24
string environment() const
Get environment.
Definition: control.cc:125
string url() const
Get download URL.
Definition: control.cc:110
string recommends() const
Get recommendations.
Definition: control.cc:76
unsigned int size()
Get number of fields.
string osdepends() const
Get OS dependencies.
Definition: control.cc:133
const_iterator find(key_type key) const
Find constant iterator for key.
Definition: control.cc:25
string short_description() const
Get short description.
Definition: control.cc:104
mapped_type & operator[](key_type key)
Get value corresponding to given key.
Definition: control.cc:37
string version() const
Get package version.
Definition: control.cc:55
string mapped_type
The mapped type.
Definition: control.h:61
string conflicts() const
Get conflicts.
Definition: control.cc:90
string components() const
Get components.
Definition: control.cc:117
iterator begin()
Get iterator for beginning of control file.
Definition: control.h:119
string description() const
Get description.
Definition: control.cc:97

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)