Back to index

nordugrid-arc-nox  1.1.0~rc6
Software.h
Go to the documentation of this file.
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 
00105 #ifndef SWIG
00106 
00107 
00118     static ComparisonOperator convert(const ComparisonOperatorEnum& co);
00119 #endif
00120 
00122 
00126     bool empty() const { return name.empty(); }
00127 
00129 
00140     bool operator==(const Software& sw) const { return family  == sw.family &&
00141                                                        name    == sw.name &&
00142                                                        (version.empty() || sw.version.empty() || version == sw.version); }
00144 
00156     bool operator!=(const Software& sw) const { return family == sw.family &&
00157                                                        name   == sw.name &&
00158                                                        !(version == sw.version || version.empty() || sw.version.empty()); }
00160 
00188     bool operator> (const Software& sw) const;
00190 
00199     bool operator< (const Software& sw) const { return sw.operator>(*this); }
00201 
00212     bool operator>=(const Software& sw) const { return (*this == sw ? true : *this > sw); }
00214 
00225     bool operator<=(const Software& sw) const { return (*this == sw ? true : *this < sw); }
00226 
00228 
00237     friend std::ostream& operator<<(std::ostream& out, const Software& sw) { out << sw(); return out; }
00238 
00240 
00247     std::string operator()() const;
00249 
00255     operator std::string(void) const { return operator()(); }
00256 
00258 
00262     const std::string& getFamily() const { return family; }
00264 
00267     const std::string& getName() const { return name; }
00269 
00272     const std::string& getVersion() const { return version; }
00273 
00274 #ifndef SWIG
00275 
00276 
00284     static std::string toString(ComparisonOperator co);
00285 #endif
00286 
00288 
00292     static const std::string VERSIONTOKENS;
00293 
00294   private:
00295     std::string family;
00296     std::string name;
00297     std::string version;
00298     std::list<std::string> tokenizedVersion;
00299 
00300     static Logger logger;
00301   };
00302 
00303 
00305 
00319   class SoftwareRequirement {
00320   public:
00322 
00331     SoftwareRequirement(bool requiresAll = false) : requiresAll(requiresAll) {}
00332 #ifndef SWIG
00333 
00334 
00352     SoftwareRequirement(const Software& sw,
00353                         Software::ComparisonOperator swComOp = &Software::operator==,
00354                         bool requiresAll = false);
00355 #endif
00356 
00358 
00371     SoftwareRequirement(const Software& sw,
00372                         Software::ComparisonOperatorEnum co,
00373                         bool requiresAll = false);
00374 
00376 
00383     SoftwareRequirement& operator=(const SoftwareRequirement& sr);
00384 
00386 
00392     SoftwareRequirement(const SoftwareRequirement& sr) { *this = sr; }
00393 
00394 #ifndef SWIG
00395 
00396 
00409     void add(const Software& sw, Software::ComparisonOperator swComOp = &Software::operator==);
00410 #endif
00411 
00412 
00421     void add(const Software& sw, Software::ComparisonOperatorEnum co);
00422 
00424 
00433     bool isRequiringAll() const { return requiresAll; }
00435 
00443     void setRequirement(bool all) { requiresAll = all; }
00444 
00446 
00458     bool isSatisfied(const Software& sw) const { return isSatisfied(std::list<Software>(1, sw)); }
00460 
00477     bool isSatisfied(const std::list<Software>& swList) const;
00479 
00492     bool isSatisfied(const std::list<ApplicationEnvironment>& swList) const;
00493 
00495 
00510     bool selectSoftware(const Software& sw) { return selectSoftware(std::list<Software>(1, sw)); }
00512 
00535     bool selectSoftware(const std::list<Software>& swList);
00537 
00550     bool selectSoftware(const std::list<ApplicationEnvironment>& swList);
00551 
00553 
00572     bool isResolved() const;
00573 
00575 
00579     bool empty() const { return softwareList.empty(); }
00581 
00585     void clear() { softwareList.clear(); comparisonOperatorList.clear(); orderedSoftwareList.clear(); }
00586 
00588 
00594     const std::list<Software>& getSoftwareList() const { return softwareList; }
00596 
00602     const std::list<Software::ComparisonOperator>& getComparisonOperatorList() const { return comparisonOperatorList; }
00603 
00604   private:
00605     std::list<Software> softwareList;
00606     std::list<Software::ComparisonOperator> comparisonOperatorList;
00607     typedef std::pair<Software*, Software::ComparisonOperator> SWRelPair;
00608     std::list< std::list<SWRelPair> > orderedSoftwareList;
00609     bool requiresAll;
00610 
00611     static Logger logger;
00612   };
00613 } // namespace Arc
00614 
00615 #endif // __ARC_SOFTWAREVERSION_H__