LibPkg
control.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_CONTROL
18 #define LIBPKG_CONTROL
19 
20 #include <map>
21 #include <string>
22 #include <iosfwd>
23 #include <stdexcept>
24 
25 namespace pkg {
26 
27 using std::string;
28 
35 class control
36 {
37 public:
46  class key_type:
47  public string
48  {
49  friend class control;
50  private:
52  int _priority;
53  public:
57  key_type(const string& value);
58 
62  key_type(const char* value);
63 
67  int priority() const
68  { return _priority; }
69  };
70 
72  typedef string mapped_type;
73 
75  typedef std::pair<const key_type,mapped_type> value_type;
76 
78  typedef std::map<key_type,mapped_type>::iterator iterator;
79 
81  typedef std::map<key_type,mapped_type>::const_iterator const_iterator;
82 
83  class parse_error;
84 private:
89  class cmp_key
90  {
91  public:
97  bool operator()(const key_type& lhs,const key_type& rhs) const;
98  };
99 
101  std::map<key_type,mapped_type,cmp_key> _data;
102 public:
104  control();
105 
107  virtual ~control();
108 
112  const_iterator begin() const
113  { return _data.begin(); }
114 
118  const_iterator end() const
119  { return _data.end(); }
120 
125  const_iterator find(key_type key) const;
126 
130  iterator begin()
131  { return _data.begin(); }
132 
136  iterator end()
137  { return _data.end(); }
138 
143  iterator find(key_type key);
144 
153  mapped_type& operator[](key_type key);
154 
158  void clear();
159 
163  unsigned int size();
164 
168  string pkgname() const;
169 
174  string version() const;
175 
180  string standards_version() const;
181 
185  string description() const;
186 
191  string short_description() const;
192 
197  string depends() const;
198 
203  string recommends() const;
204 
209  string suggests() const;
210 
215  string conflicts() const;
216 
221  string url() const;
222 
228  string components() const;
229 
234  string environment() const;
235 
240  string osdepends() const;
241 
242 protected:
253  virtual int priority(const string& value) const;
254 };
255 
258  public std::runtime_error
259 {
260 public:
264  parse_error(const char* message);
265 };
266 
272 std::ostream& operator<<(std::ostream& out,const control& ctrl);
273 
279 std::istream& operator>>(std::istream& in,control& ctrl);
280 
281 }; /* namespace pkg */
282 
283 #endif
key_type(const string &value)
Construct key from string.
Definition: control.cc:156
const_iterator begin() const
Get constant iterator for beginning of control file.
Definition: control.h:112
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:190
std::map< key_type, mapped_type >::iterator iterator
The iterator type.
Definition: control.h:78
string suggests() const
Get suggestions.
Definition: control.cc:94
string standards_version() const
Get standard-version.
Definition: control.cc:73
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
string pkgname() const
Get package name.
Definition: control.cc:59
An exception class for reporting parse errors.
Definition: control.h:257
iterator end()
Get iterator for end of control file.
Definition: control.h:136
The key type.
Definition: control.h:46
std::istream & operator>>(std::istream &in, component &comp)
Read component record from input stream.
Definition: component.cc:204
int priority() const
Get priority.
Definition: control.h:67
string depends() const
Get dependencies.
Definition: control.cc:80
virtual ~control()
Destroy control file.
Definition: control.cc:33
void clear()
Clear control file.
Definition: control.cc:54
std::pair< const key_type, mapped_type > value_type
The value type.
Definition: control.h:75
const_iterator end() const
Get constant iterator for end of control file.
Definition: control.h:118
std::map< key_type, mapped_type >::const_iterator const_iterator
The constant iterator type.
Definition: control.h:81
friend class control
Definition: control.h:49
A class to represent the content of a RiscPkg control file.
Definition: control.h:35
string environment() const
Get environment.
Definition: control.cc:136
string url() const
Get download URL.
Definition: control.cc:121
string recommends() const
Get recommendations.
Definition: control.cc:87
unsigned int size()
Get number of fields.
string osdepends() const
Get OS dependencies.
Definition: control.cc:144
const_iterator find(key_type key) const
Find constant iterator for key.
Definition: control.cc:36
string short_description() const
Get short description.
Definition: control.cc:115
mapped_type & operator[](key_type key)
Get value corresponding to given key.
Definition: control.cc:48
string version() const
Get package version.
Definition: control.cc:66
string mapped_type
The mapped type.
Definition: control.h:72
string conflicts() const
Get conflicts.
Definition: control.cc:101
string components() const
Get components.
Definition: control.cc:128
iterator begin()
Get iterator for beginning of control file.
Definition: control.h:130
string description() const
Get description.
Definition: control.cc:108

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)