00001 #ifndef IDGENERATOR_H_ 00002 #define IDGENERATOR_H_ 00003 00004 #include "TObject.h" 00005 #include <map> 00006 #include <string> 00007 00008 namespace IDs{ 00009 class generator; 00010 typedef std::string Generator_t; 00011 typedef std::string Config_t; 00012 00014 const Generator_t kAnyGenerator="any"; 00016 const Config_t kAnyConfig="any"; 00019 const Config_t kDefaultConfig="default"; 00020 00021 const std::string field_separator="#"; 00022 } 00023 00025 class IDs::generator:public TObject{ 00026 public: 00032 generator(Generator_t g , Config_t c); 00033 00036 generator():fType(kAnyGenerator),fConfig(kAnyConfig){}; 00037 00041 generator(const std::string& s) 00042 : fType(kAnyGenerator),fConfig(kAnyConfig) { 00043 operator=(s); 00044 }; 00045 00046 virtual ~generator(){}; 00047 00048 void Reset(){fType=kAnyGenerator; fConfig=kAnyConfig;}; 00049 00050 public: 00052 Generator_t Type()const{return fType;}; 00053 00055 void Type(const Generator_t& g){ fType=g;}; 00056 00058 Config_t Config()const{return fConfig;}; 00059 00061 void Config(const Config_t& c){fConfig=c;}; 00062 00065 bool operator==(const generator& rhs)const; 00066 bool matches(const generator& rhs)const; 00067 00070 bool operator!=(const generator& rhs)const{return !(this->operator==(rhs));}; 00071 00073 bool operator<(const generator& rhs)const; 00075 bool operator>(const generator& rhs)const; 00076 00078 std::string str()const; 00079 00080 IDs::generator& operator=(const std::string& rhs); 00081 00083 bool isWildCardType() const { return fType == kAnyGenerator; } 00084 00086 bool isWildCardConfig() const { return fConfig == kAnyConfig; } 00087 00089 bool isWildCard() const { return isWildCardConfig() || isWildCardType(); } 00090 00092 void Debug()const; 00093 00094 private: 00096 Generator_t fType; 00098 Config_t fConfig; 00099 00100 ClassDef(generator,1); 00101 }; 00102 00103 inline bool IDs::generator::operator==(const IDs::generator& rhs)const{ 00104 return (fType==rhs.fType) && (fConfig==rhs.fConfig) ; 00105 } 00106 00107 inline bool IDs::generator::matches(const generator& rhs)const{ 00108 return (isWildCardType() || rhs.isWildCardType() || fType==rhs.fType) 00109 && (isWildCardConfig() || rhs.isWildCardConfig() || fConfig==rhs.fConfig) ; 00110 } 00111 00112 inline bool IDs::generator::operator>(const IDs::generator& rhs)const{ 00113 int type_cmp=fType.compare(rhs.fType); 00114 return type_cmp>0 || (type_cmp==0 && fConfig.compare(rhs.fConfig)>0); 00115 } 00116 00117 inline bool IDs::generator::operator<(const IDs::generator& rhs)const{ 00118 int type_cmp=fType.compare(rhs.fType); 00119 return type_cmp<0 || (type_cmp==0 && fConfig.compare(rhs.fConfig)<0); 00120 } 00121 inline IDs::generator::generator(Generator_t t , Config_t c): 00122 fType(t),fConfig(c){ 00123 if(fConfig=="") fConfig=kAnyConfig; 00124 } 00125 00126 ostream& operator<< (ostream& os ,const IDs::generator& id) ; 00127 00128 #endif //IDGENERATOR_H_ 00129 00130 // emacs metadata 00131 // Local Variables: 00132 // mode: c++ 00133 // End: