LibPkg
component.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright © 2003-2005 Graham Shaw.
3 // Copyright © 2013 Alan Buckley.
4 // Distribution and use are subject to the GNU Lesser General Public License,
5 // a copy of which may be found in the file !LibPkg.Copyright.
6 
7 #ifndef LIBPKG_COMPONENT
8 #define LIBPKG_COMPONENT
9 
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <stdexcept>
14 
15 namespace pkg
16 {
17 
27 class component
28 {
29 public:
32  enum flag_type
33  {
42  run,
46  };
47 
48  class parse_error;
49 private:
50  std::string _name;
51  unsigned int _flags;
52  std::string _path;
53 
54 public:
58  component();
59 
68  component(std::string::const_iterator first, std::string::const_iterator last);
69 
73  component(const std::string& compstr);
74 
76  ~component();
77 
79  bool operator==(const component &other) const;
81  bool operator!=(const component &other) const;
82 
87  operator std::string() const;
88 
93  const std::string &name() const {return _name;}
94 
98  unsigned int flags() const {return _flags;}
99 
104  bool flag(flag_type flag) const
105  { return (_flags>>flag)&1; }
106 
111  void flag(flag_type flag,bool value);
112 
116  const std::string &path() const {return _path;}
121  void path(const std::string &path) {_path = path;}
122 
123 private:
128  void parse(std::string::const_iterator first,std::string::const_iterator last);
129 
130 };
131 
134  public std::runtime_error
135 {
136 public:
140  parse_error(const char* message);
141 };
142 
148 void parse_component_list(std::string::const_iterator first,
149  std::string::const_iterator last,std::vector<component> *out);
150 
156 std::ostream& operator<<(std::ostream& out,
157  const component &comp);
158 
164 std::istream& operator>>(std::istream& in, component &comp);
165 
166 
167 }; /* namespace pkg */
168 
169 #endif
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:175
A flag to indicate this component should be added to the RISC OS application pseudo folder...
Definition: component.h:45
parse_error(const char *message)
Construct parse error.
Definition: component.cc:131
component()
Empty constructor, unnamed component with no flags.
Definition: component.cc:21
A flag to indicate this component can have it's install location changed and it may be moved after in...
Definition: component.h:36
std::istream & operator>>(std::istream &in, component &comp)
Read component record from input stream.
Definition: component.cc:189
bool operator!=(const component &other) const
Check if it is different from another component.
Definition: component.cc:42
bool operator==(const component &other) const
Check if it is the same as another component.
Definition: component.cc:37
bool flag(flag_type flag) const
Get component flag.
Definition: component.h:104
A flag to indicate this component should be added to the RISC OS boot look at file, so it is booted when the desktop starts.
Definition: component.h:39
An exception class for reporting parse errors.
Definition: component.h:133
A flag to indicate this component should be added to the RISC OS boot run file, so it is run when the...
Definition: component.h:42
void path(const std::string &path)
Set the installation path.
Definition: component.h:121
A class to represent a component of a package.
Definition: component.h:27
const std::string & path() const
Get the installation path.
Definition: component.h:116
flag_type
The options available/selected for this component.
Definition: component.h:32
const std::string & name() const
Get the name of the component The name is the same as the logical path to the component.
Definition: component.h:93
~component()
Destroy component.
Definition: component.cc:33
void parse_component_list(std::string::const_iterator first, std::string::const_iterator last, std::vector< component > *out)
Parse component list.
Definition: component.cc:135
unsigned int flags() const
Get the bit field containing the component flags.
Definition: component.h:98

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)