LibPkg
component.h
Go to the documentation of this file.
1 // This file is part of the LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 // Copyright 2013-2020 Alan Buckley
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #ifndef LIBPKG_COMPONENT
19 #define LIBPKG_COMPONENT
20 
21 #include <string>
22 #include <iostream>
23 #include <vector>
24 #include <stdexcept>
25 
26 namespace pkg
27 {
28 
38 class component
39 {
40 public:
43  enum flag_type
44  {
53  run,
57  };
58 
59  class parse_error;
60 private:
61  std::string _name;
62  unsigned int _flags;
63  std::string _path;
64 
65 public:
69  component();
70 
79  component(std::string::const_iterator first, std::string::const_iterator last);
80 
84  component(const std::string& compstr);
85 
87  ~component();
88 
90  bool operator==(const component &other) const;
92  bool operator!=(const component &other) const;
93 
98  operator std::string() const;
99 
104  const std::string &name() const {return _name;}
105 
109  unsigned int flags() const {return _flags;}
110 
115  bool flag(flag_type flag) const
116  { return (_flags>>flag)&1; }
117 
122  void flag(flag_type flag,bool value);
123 
127  const std::string &path() const {return _path;}
132  void path(const std::string &path) {_path = path;}
133 
134 private:
139  void parse(std::string::const_iterator first,std::string::const_iterator last);
140 
141 };
142 
145  public std::runtime_error
146 {
147 public:
151  parse_error(const char* message);
152 };
153 
159 void parse_component_list(std::string::const_iterator first,
160  std::string::const_iterator last,std::vector<component> *out);
161 
167 std::ostream& operator<<(std::ostream& out,
168  const component &comp);
169 
175 std::istream& operator>>(std::istream& in, component &comp);
176 
177 
178 }; /* namespace pkg */
179 
180 #endif
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:190
unsigned int flags() const
Get the bit field containing the component flags.
Definition: component.h:109
A flag to indicate this component should be added to the RISC OS application pseudo folder...
Definition: component.h:56
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
component()
Empty constructor, unnamed component with no flags.
Definition: component.cc: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:104
A flag to indicate this component can have it&#39;s install location changed and it may be moved after in...
Definition: component.h:47
bool flag(flag_type flag) const
Get component flag.
Definition: component.h:115
std::istream & operator>>(std::istream &in, component &comp)
Read component record from input stream.
Definition: component.cc:204
const std::string & path() const
Get the installation path.
Definition: component.h:127
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:50
An exception class for reporting parse errors.
Definition: component.h:144
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:53
void path(const std::string &path)
Set the installation path.
Definition: component.h:132
A class to represent a component of a package.
Definition: component.h:38
flag_type
The options available/selected for this component.
Definition: component.h:43
~component()
Destroy component.
Definition: component.cc:44
bool operator!=(const component &other) const
Check if it is different from another component.
Definition: component.cc:53
bool operator==(const component &other) const
Check if it is the same as another component.
Definition: component.cc:48
void parse_component_list(std::string::const_iterator first, std::string::const_iterator last, std::vector< component > *out)
Parse component list.
Definition: component.cc:150

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)