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(ComparisonOperator 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 
336 
351 
353 
363 
365 
373 
375 
381  SoftwareRequirement(const SoftwareRequirement& sr) { *this = sr; }
382 
384 
397  void add(const Software& sw, Software::ComparisonOperator swComOp);
398 
400 
409  void add(const Software& sw, Software::ComparisonOperatorEnum co);
410 
412 
424  bool isSatisfied(const Software& sw) const { return isSatisfied(std::list<Software>(1, sw)); }
426 
443  bool isSatisfied(const std::list<Software>& swList) const { return isSatisfiedSelect(swList); }
445 
458  bool isSatisfied(const std::list<ApplicationEnvironment>& swList) const;
459 
461 
476  bool selectSoftware(const Software& sw) { return selectSoftware(std::list<Software>(1, sw)); }
478 
501  bool selectSoftware(const std::list<Software>& swList);
503 
516  bool selectSoftware(const std::list<ApplicationEnvironment>& swList);
517 
519 
538  bool isResolved() const;
539 
541 
545  bool empty() const { return softwareList.empty(); }
547 
551  void clear() { softwareList.clear(); comparisonOperatorList.clear(); }
552 
554 
560  const std::list<Software>& getSoftwareList() const { return softwareList; }
562 
568  const std::list<Software::ComparisonOperator>& getComparisonOperatorList() const { return comparisonOperatorList; }
569 
570  private:
571  std::list<Software> softwareList;
572  std::list<Software::ComparisonOperator> comparisonOperatorList;
573 
574  bool isSatisfiedSelect(const std::list<Software>&, SoftwareRequirement* = NULL) const;
575 
576  static Logger logger;
577  };
578 } // namespace Arc
579 
580 #endif // __ARC_SOFTWAREVERSION_H__