00001 #ifndef __ARC_SOFTWAREVERSION_H__
00002 #define __ARC_SOFTWAREVERSION_H__
00003
00004 #include <list>
00005 #include <utility>
00006 #include <string>
00007 #include <ostream>
00008
00009 #include <arc/Logger.h>
00010
00011 namespace Arc {
00012
00013 class ApplicationEnvironment;
00014
00016
00031 class Software {
00032 public:
00034
00045 typedef bool (Software::*ComparisonOperator)(const Software&) const;
00046
00048
00051 Software() : family(""), name(""), version("") {};
00052
00054
00066 Software(const std::string& name_version);
00067
00069
00076 Software(const std::string& name, const std::string& version);
00077
00079
00087 Software(const std::string& family, const std::string& name, const std::string& version);
00088
00090
00096 enum ComparisonOperatorEnum {
00097 NOTEQUAL = 0,
00098 EQUAL = 1,
00099 GREATERTHAN = 2,
00100 LESSTHAN = 3,
00101 GREATERTHANOREQUAL = 4,
00102 LESSTHANOREQUAL = 5
00103 };
00104
00106
00117 static ComparisonOperator convert(const ComparisonOperatorEnum& co);
00118
00120
00124 bool empty() const { return name.empty(); }
00125
00127
00136 bool operator==(const Software& sw) const { return family == sw.family &&
00137 name == sw.name &&
00138 version == sw.version; }
00140
00148 bool operator!=(const Software& sw) const { return !operator==(sw); }
00149
00151
00181 bool operator> (const Software& sw) const;
00183
00192 bool operator< (const Software& sw) const { return sw.operator>(*this); }
00194
00205 bool operator>=(const Software& sw) const { return (*this == sw ? true : *this > sw); }
00207
00218 bool operator<=(const Software& sw) const { return (*this == sw ? true : *this < sw); }
00219
00221
00230 friend std::ostream& operator<<(std::ostream& out, const Software& sw) { out << sw(); return out; }
00231
00233
00240 std::string operator()() const;
00242
00248 operator std::string(void) const { return operator()(); }
00249
00251
00255 const std::string& getFamily() const { return family; }
00257
00260 const std::string& getName() const { return name; }
00262
00265 const std::string& getVersion() const { return version; }
00266
00267 const std::list<std::string>& getOptions() const { return option; }
00268
00269 void addOption(const std::string& opt) { option.push_back(opt); }
00270
00272
00280 static std::string toString(ComparisonOperator co);
00281
00283
00287 static const std::string VERSIONTOKENS;
00288
00289 private:
00290 std::string family;
00291 std::string name;
00292 std::string version;
00293 std::list<std::string> tokenizedVersion;
00294 std::list<std::string> option;
00295
00296 static Logger logger;
00297 };
00298
00299
00301
00315 class SoftwareRequirement {
00316 public:
00318
00322 SoftwareRequirement() {}
00324
00338 SoftwareRequirement(const Software& sw, Software::ComparisonOperator swComOp);
00339
00341
00350 SoftwareRequirement(const Software& sw, Software::ComparisonOperatorEnum co = Software::EQUAL);
00351
00353
00360 SoftwareRequirement& operator=(const SoftwareRequirement& sr);
00361
00363
00369 SoftwareRequirement(const SoftwareRequirement& sr) { *this = sr; }
00370
00372
00385 void add(const Software& sw, Software::ComparisonOperator swComOp);
00386
00388
00397 void add(const Software& sw, Software::ComparisonOperatorEnum co);
00398
00400
00412 bool isSatisfied(const Software& sw) const { return isSatisfied(std::list<Software>(1, sw)); }
00414
00431 bool isSatisfied(const std::list<Software>& swList) const { return isSatisfiedSelect(swList); }
00433
00446 bool isSatisfied(const std::list<ApplicationEnvironment>& swList) const;
00447
00449
00464 bool selectSoftware(const Software& sw) { return selectSoftware(std::list<Software>(1, sw)); }
00466
00489 bool selectSoftware(const std::list<Software>& swList);
00491
00504 bool selectSoftware(const std::list<ApplicationEnvironment>& swList);
00505
00507
00526 bool isResolved() const;
00527
00529
00533 bool empty() const { return softwareList.empty(); }
00535
00539 void clear() { softwareList.clear(); comparisonOperatorList.clear(); }
00540
00542
00548 const std::list<Software>& getSoftwareList() const { return softwareList; }
00550
00556 const std::list<Software::ComparisonOperator>& getComparisonOperatorList() const { return comparisonOperatorList; }
00557
00558 private:
00559 std::list<Software> softwareList;
00560 std::list<Software::ComparisonOperator> comparisonOperatorList;
00561
00562 bool isSatisfiedSelect(const std::list<Software>&, SoftwareRequirement* = NULL) const;
00563
00564 static Logger logger;
00565 };
00566 }
00567
00568 #endif // __ARC_SOFTWAREVERSION_H__