LibPkg
status.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
18 #define LIBPKG_STATUS
19 
20 #include <utility>
21 #include <string>
22 #include <stdexcept>
23 #include <iosfwd>
24 
25 namespace pkg {
26 
27 using std::string;
28 
44 class status
45 {
46 public:
48  {
68  };
69  enum flag_type
70  {
80  };
82  {
95  };
96  class parse_error;
97 private:
99  state_type _state;
101  unsigned short _flags;
103  unsigned short _iflags;
107  string _version;
111  string _environment_id;
112 public:
116  status();
117 
124  status(state_type state,const string& version, const string &environment_id);
125 
127  ~status();
128 
133  { return _state; }
134 
139  bool flag(flag_type flag) const
140  { return (_flags>>flag)&1; }
141 
147  { return (_iflags>>flag)&1; }
148 
152  unsigned int flags() const
153  { return _flags; }
154 
158  string version() const
159  { return _version; }
160 
164  string environment_id() const
165  { return _environment_id;}
166 
170  void state(state_type state);
171 
176  void flag(flag_type flag,bool value);
177 
182  void flag(internal_flag_type flag,bool value);
183 
187  void version(const string& version);
188 
192  void environment_id(const string &environment_id);
193 };
194 
197  public std::runtime_error
198 {
199 public:
203  parse_error(const string& message);
204 };
205 
211 bool operator==(const status& lhs,const status& rhs);
212 
218 bool operator!=(const status& lhs,const status& rhs);
219 
225 std::ostream& operator<<(std::ostream& out,
226  const std::pair<string,status>& pkgstat);
227 
233 std::istream& operator>>(std::istream& in,std::pair<string,status>& pkgstat);
234 
246 bool unpack_req(const status& curstat,const status& selstat);
247 
259 bool remove_req(const status& curstat,const status& selstat);
260 
273 bool config_req(const status& curstat,const status& selstat);
274 
285 bool purge_req(const status& curstat,const status& selstat);
286 
287 }; /* namespace pkg */
288 
289 #endif
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:190
string environment_id() const
Get environment id.
Definition: status.h:164
bool remove_req(const status &curstat, const status &selstat)
Determine whether a package should be removed.
Definition: status.cc:244
A flag to indicate that this package must be removed.
Definition: status.h:86
A flag to indicate that a package has been installed automatically to meet a dependency (and should t...
Definition: status.h:75
state_type state() const
Get installation state.
Definition: status.h:132
bool flag(flag_type flag) const
Get status flag.
Definition: status.h:139
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
bool unpack_req(const status &curstat, const status &selstat)
Determine whether a package should be unpacked.
Definition: status.cc:236
A class to represent the current or required status of a package.
Definition: status.h:44
A flag to indicate that a package has been placed on hold (which prevents any change of state unless ...
Definition: status.h:79
A state to indicate that a package has been removed but its configuration files may remain...
Definition: status.h:54
std::istream & operator>>(std::istream &in, component &comp)
Read component record from input stream.
Definition: component.cc:204
bool purge_req(const status &curstat, const status &selstat)
Determine whether a package should be purged.
Definition: status.cc:260
A state to indicate that a package is partially configured.
Definition: status.h:64
An exception class for reporting parse errors.
Definition: status.h:196
internal_flag_type
Definition: status.h:81
bool flag(internal_flag_type flag) const
Get internal flag.
Definition: status.h:146
A state to indicate that a package is partially unpacked or partially removed.
Definition: status.h:58
~status()
Destroy status.
Definition: status.cc:77
A state to indicate that a package has either been purged or was never installed. ...
Definition: status.h:51
unsigned int flags() const
Get status flags.
Definition: status.h:152
flag_type
Definition: status.h:69
status()
Construct status.
Definition: status.cc:63
A class to represent a package version.
Definition: version.h:32
A state to indicate that a package has been unpacked but not configured.
Definition: status.h:61
bool operator!=(const status &lhs, const status &rhs)
Test whether two status records are unequal.
Definition: status.cc:119
A flag to indicate that this package must be installed.
Definition: status.h:90
bool operator==(const status &lhs, const status &rhs)
Test whether two status records are equal.
Definition: status.cc:111
A state to indicate that a package has been successfully unpacked and configured. ...
Definition: status.h:67
string version() const
Get package version.
Definition: status.h:158
state_type
Definition: status.h:47
bool config_req(const status &curstat, const status &selstat)
Determine whether a package should be configured.
Definition: status.cc:252
A flag to indicate that this package must be upgraded.
Definition: status.h:94

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)