ARC SDK
Software.h
Go to the documentation of this file.
1 #ifndef __ARC_SOFTWAREVERSION_H__
2 #define __ARC_SOFTWAREVERSION_H__
3 
8 #include <list>
9 #include <utility>
10 #include <string>
11 #include <ostream>
12 
13 #include <arc/Logger.h>
14 
15 namespace Arc {
16 
17  class ApplicationEnvironment;
18 
20 
38  class Software {
39  public:
41 
52  typedef bool (Software::*ComparisonOperator)(const Software&) const;
53 
55 
58  Software() : family(""), name(""), version("") {};
59 
61 
73  Software(const std::string& name_version);
74 
76 
83  Software(const std::string& name, const std::string& version);
84 
86 
94  Software(const std::string& family, const std::string& name, const std::string& version);
95 
97 
104  NOTEQUAL = 0,
105  EQUAL = 1,
107  LESSTHAN = 3,
110  };
111 
113 
125 
127 
131  bool empty() const { return name.empty(); }
132 
134 
143  bool operator==(const Software& sw) const { return family == sw.family &&
144  name == sw.name &&
145  version == sw.version; }
147 
155  bool operator!=(const Software& sw) const { return !operator==(sw); }
156 
158 
188  bool operator> (const Software& sw) const;
190 
199  bool operator< (const Software& sw) const { return sw.operator>(*this); }
201 
212  bool operator>=(const Software& sw) const { return (*this == sw ? true : *this > sw); }
214 
225  bool operator<=(const Software& sw) const { return (*this == sw ? true : *this < sw); }
226 
228 
237  friend std::ostream& operator<<(std::ostream& out, const Software& sw) { out << sw(); return out; }
238 
240 
247  std::string operator()() const;
249 
255  operator std::string(void) const { return operator()(); }
256 
258 
262  const std::string& getFamily() const { return family; }
264 
267  const std::string& getName() const { return name; }
269 
272  const std::string& getVersion() const { return version; }
273 
274  const std::list<std::string>& getOptions() const { return option; }
275 
276  void addOption(const std::string& opt) { option.push_back(opt); }
277 
278  void addOptions(const std::list<std::string>& opts) { option.insert(option.end(),opts.begin(),opts.end()); }
279 
281 
289  static std::string toString(ComparisonOperatorEnum co);
290 
292 
296  static const std::string VERSIONTOKENS;
297 
298  private:
299  std::string family;
300  std::string name;
301  std::string version;
302  std::list<std::string> tokenizedVersion;
303  std::list<std::string> option;
304 
305  static Logger logger;
306  };
307 
308 
310 
328  public:
330 
335 
337 
347 
349 
357 
359 
365  SoftwareRequirement(const SoftwareRequirement& sr) { *this = sr; }
366 
368 
377  void add(const Software& sw, Software::ComparisonOperatorEnum co);
378 
380 
392  bool isSatisfied(const Software& sw) const { return isSatisfied(std::list<Software>(1, sw)); }
394 
411  bool isSatisfied(const std::list<Software>& swList) const { return isSatisfiedSelect(swList); }
413 
426  bool isSatisfied(const std::list<ApplicationEnvironment>& swList) const;
427 
429 
444  bool selectSoftware(const Software& sw) { return selectSoftware(std::list<Software>(1, sw)); }
446 
469  bool selectSoftware(const std::list<Software>& swList);
471 
484  bool selectSoftware(const std::list<ApplicationEnvironment>& swList);
485 
487 
506  bool isResolved() const;
507 
509 
513  bool empty() const { return softwareList.empty(); }
515 
519  void clear() { softwareList.clear(); comparisonOperatorList.clear(); }
520 
522 
528  const std::list<Software>& getSoftwareList() const { return softwareList; }
530 
536  const std::list<Software::ComparisonOperatorEnum>& getComparisonOperatorList() const { return comparisonOperatorList; }
537 
538  private:
539  std::list<Software> softwareList;
540  std::list<Software::ComparisonOperatorEnum> comparisonOperatorList;
541 
542  bool isSatisfiedSelect(const std::list<Software>&, SoftwareRequirement* = NULL) const;
543 
544  static Logger logger;
545  };
546 } // namespace Arc
547 
548 #endif // __ARC_SOFTWAREVERSION_H__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
static ComparisonOperator convert(const ComparisonOperatorEnum &co)
Convert a ComparisonOperatorEnum value to a comparison method pointer.
const std::string & getVersion() const
Get version.
Definition: Software.h:272
bool operator<=(const Software &sw) const
Less-than or equal operator.
Definition: Software.h:225
Class used to express and resolve version requirements on software.
Definition: Software.h:327
bool isResolved() const
Indicates whether requirements have been resolved or not.
bool isSatisfied(const Software &sw) const
Test if requirements are satisfied.
Definition: Software.h:392
bool operator!=(const Software &sw) const
Inequality operator.
Definition: Software.h:155
std::string operator()() const
Get string representation.
Definition: Software.h:104
static const std::string VERSIONTOKENS
Tokens used to split version string.
Definition: Software.h:296
bool operator>=(const Software &sw) const
Greater-than or equal operator.
Definition: Software.h:212
bool operator==(const Software &sw) const
Equality operator.
Definition: Software.h:143
void clear()
Clear the object.
Definition: Software.h:519
A logger class.
Definition: Logger.h:493
ComparisonOperatorEnum
Comparison operator enum.
Definition: Software.h:103
bool operator<(const Software &sw) const
Less-than operator.
Definition: Software.h:199
SoftwareRequirement()
Create a empty SoftwareRequirement object.
Definition: Software.h:334
Software()
Dummy constructor.
Definition: Software.h:58
Definition: Software.h:106
Definition: Software.h:105
SoftwareRequirement(const SoftwareRequirement &sr)
Copy constructor.
Definition: Software.h:365
SoftwareRequirement & operator=(const SoftwareRequirement &sr)
Assignment operator.
void add(const Software &sw, Software::ComparisonOperatorEnum co)
Add a Software object a corresponding comparion operator to this object.
bool selectSoftware(const Software &sw)
Select software.
Definition: Software.h:444
bool(Software::* ComparisonOperator)(const Software &) const
Definition of a comparison operator method pointer.
Definition: Software.h:52
bool operator>(const Software &sw) const
Greater-than operator.
bool empty() const
Indicates whether the object is empty.
Definition: Software.h:131
const std::list< Software > & getSoftwareList() const
Get list of Software objects.
Definition: Software.h:528
const std::string & getFamily() const
Get family.
Definition: Software.h:262
Definition: Software.h:109
const std::string & getName() const
Get name.
Definition: Software.h:267
Definition: Software.h:107
bool isSatisfied(const std::list< Software > &swList) const
Test if requirements are satisfied.
Definition: Software.h:411
friend std::ostream & operator<<(std::ostream &out, const Software &sw)
Write Software string representation to a std::ostream.
Definition: Software.h:237
Definition: Software.h:108
static std::string toString(ComparisonOperatorEnum co)
Convert Software::ComparisonOperator to a string.
bool empty() const
Test if the object is empty.
Definition: Software.h:513
Used to represent software (names and version) and comparison.
Definition: Software.h:38
const std::list< Software::ComparisonOperatorEnum > & getComparisonOperatorList() const
Get list of comparison operators.
Definition: Software.h:536