00001 00002 #include "Sct/Addressing.h" 00003 #include "Sct/LogicErrors.h" 00004 #include "Sct/Tokenize.h" 00005 00006 typedef Sct::Tokenize::Tokens Tokens; 00007 typedef Sct::Tokenize::TokenVec TokenVec; 00008 00009 namespace Sct { 00010 namespace TokenizeHelper { 00011 bool notNumber(const std::string & s) { 00012 return 00013 s=="" || 00014 s.find_first_not_of("0123456789") != s.npos; 00015 }; 00016 }; 00017 }; 00018 00019 using Sct::TokenizeHelper::notNumber; 00020 00021 Sct::UniquePartitionIdentifier::operator std::string() const { 00022 std::ostringstream os; 00023 os << this->tag() << ":" 00024 << this->partition(); 00025 return os.str(); 00026 }; 00027 00028 Sct::UniqueCrateIdentifier::operator std::string() const { 00029 std::ostringstream os; 00030 os << this->tag() << ":" 00031 << this->partition() 00032 << "." 00033 << this->crate(); 00034 return os.str(); 00035 }; 00036 00037 Sct::UniqueRodIdentifier::operator std::string() const { 00038 std::ostringstream os; 00039 os << this->tag() << ":" 00040 << this->partition() 00041 << "." 00042 << this->crate() 00043 << "." 00044 << this->rod(); 00045 return os.str(); 00046 }; 00047 00048 Sct::UniqueTimIdentifier::operator std::string() const { 00049 std::ostringstream os; 00050 os << this->tag() << ":" 00051 << this->partition() 00052 << "." 00053 << this->crate(); 00054 return os.str(); 00055 }; 00056 00057 00058 Sct::UniquePartitionIdentifier::UniquePartitionIdentifier(const string & s) { 00059 00060 Sct::Tokenize t1(s,":"); 00061 00062 const TokenVec & t1Vec = t1.tokenVec(); 00063 00064 if (t1Vec.size() != 2) { 00065 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00066 }; 00067 00068 if (t1Vec[0] != tag()) { 00069 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00070 }; 00071 00072 const std::string & remainder = t1Vec[1]; 00073 00074 Sct::Tokenize t2(remainder, "."); 00075 00076 const TokenVec & t2Vec = t2.tokenVec(); 00077 00078 if (t2.size()!=1) { 00079 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00080 }; 00081 00082 if (notNumber(t2Vec[0])) { 00083 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00084 }; 00085 00086 { 00087 std::istringstream ip(t2Vec[0]); 00088 00089 PartitionIdentifier p; 00090 ip>>p; 00091 00092 *this = UPID(p); 00093 }; 00094 }; 00095 00096 Sct::UniqueCrateIdentifier::UniqueCrateIdentifier(const string & s) { 00097 00098 Sct::Tokenize t1(s,":"); 00099 00100 const TokenVec & t1Vec = t1.tokenVec(); 00101 00102 if (t1Vec.size() != 2) { 00103 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00104 }; 00105 00106 if (t1Vec[0] != tag()) { 00107 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00108 }; 00109 00110 const std::string & remainder = t1Vec[1]; 00111 00112 Sct::Tokenize t2(remainder, "."); 00113 00114 const TokenVec & t2Vec = t2.tokenVec(); 00115 00116 if (t2.size()!=2) { 00117 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00118 }; 00119 00120 if (notNumber(t2Vec[0]) || 00121 notNumber(t2Vec[1])) { 00122 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00123 }; 00124 00125 { 00126 std::istringstream ip(t2Vec[0]); 00127 std::istringstream ic(t2Vec[1]); 00128 00129 PartitionIdentifier p; 00130 CrateIdentifier c; 00131 00132 ip>>p; 00133 ic>>c; 00134 00135 *this = UCID(p,c); 00136 }; 00137 }; 00138 00139 Sct::UniqueRodIdentifier::UniqueRodIdentifier(const string & s) { 00140 00141 Sct::Tokenize t1(s,":"); 00142 00143 const TokenVec & t1Vec = t1.tokenVec(); 00144 00145 if (t1Vec.size() != 2) { 00146 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00147 }; 00148 00149 if (t1Vec[0] != tag()) { 00150 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00151 }; 00152 00153 const std::string & remainder = t1Vec[1]; 00154 00155 Sct::Tokenize t2(remainder, "."); 00156 00157 const TokenVec & t2Vec = t2.tokenVec(); 00158 00159 if (t2.size()!=3) { 00160 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00161 }; 00162 00163 if (notNumber(t2Vec[0]) || 00164 notNumber(t2Vec[1]) || 00165 notNumber(t2Vec[2])) { 00166 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00167 }; 00168 00169 { 00170 std::istringstream ip(t2Vec[0]); 00171 std::istringstream ic(t2Vec[1]); 00172 std::istringstream ir(t2Vec[2]); 00173 00174 PartitionIdentifier p; 00175 CrateIdentifier c; 00176 RodIdentifier r; 00177 00178 ip>>p; 00179 ic>>c; 00180 ir>>r; 00181 00182 *this = URID(p,c,r); 00183 }; 00184 }; 00185 00186 Sct::UniqueTimIdentifier::UniqueTimIdentifier(const string & s) { 00187 00188 Sct::Tokenize t1(s,":"); 00189 00190 const TokenVec & t1Vec = t1.tokenVec(); 00191 00192 if (t1Vec.size() != 2) { 00193 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00194 }; 00195 00196 if (t1Vec[0] != tag()) { 00197 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00198 }; 00199 00200 const std::string & remainder = t1Vec[1]; 00201 00202 Sct::Tokenize t2(remainder, "."); 00203 00204 const TokenVec & t2Vec = t2.tokenVec(); 00205 00206 if (t2.size()!=2) { 00207 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00208 }; 00209 00210 if (notNumber(t2Vec[0]) || 00211 notNumber(t2Vec[1])) { 00212 throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); 00213 }; 00214 00215 { 00216 std::istringstream ip(t2Vec[0]); 00217 std::istringstream ic(t2Vec[1]); 00218 00219 PartitionIdentifier p; 00220 CrateIdentifier c; 00221 00222 ip>>p; 00223 ic>>c; 00224 00225 *this = UTID(p,c); 00226 }; 00227 }; 00228