#include "Sct/Addressing.h" #include "Sct/LogicErrors.h" #include "Sct/Tokenize.h" typedef Sct::Tokenize::Tokens Tokens; typedef Sct::Tokenize::TokenVec TokenVec; namespace Sct { namespace TokenizeHelper { bool notNumber(const std::string & s) { return s=="" || s.find_first_not_of("0123456789") != s.npos; }; }; }; using Sct::TokenizeHelper::notNumber; Sct::UniquePartitionIdentifier::operator std::string() const { std::ostringstream os; os << this->tag() << ":" << this->partition(); return os.str(); }; Sct::UniqueCrateIdentifier::operator std::string() const { std::ostringstream os; os << this->tag() << ":" << this->partition() << "." << this->crate(); return os.str(); }; Sct::UniqueRodIdentifier::operator std::string() const { std::ostringstream os; os << this->tag() << ":" << this->partition() << "." << this->crate() << "." << this->rod(); return os.str(); }; Sct::UniqueTimIdentifier::operator std::string() const { std::ostringstream os; os << this->tag() << ":" << this->partition() << "." << this->crate(); return os.str(); }; Sct::UniquePartitionIdentifier::UniquePartitionIdentifier(const string & s) { Sct::Tokenize t1(s,":"); const TokenVec & t1Vec = t1.tokenVec(); if (t1Vec.size() != 2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (t1Vec[0] != tag()) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; const std::string & remainder = t1Vec[1]; Sct::Tokenize t2(remainder, "."); const TokenVec & t2Vec = t2.tokenVec(); if (t2.size()!=1) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (notNumber(t2Vec[0])) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; { std::istringstream ip(t2Vec[0]); PartitionIdentifier p; ip>>p; *this = UPID(p); }; }; Sct::UniqueCrateIdentifier::UniqueCrateIdentifier(const string & s) { Sct::Tokenize t1(s,":"); const TokenVec & t1Vec = t1.tokenVec(); if (t1Vec.size() != 2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (t1Vec[0] != tag()) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; const std::string & remainder = t1Vec[1]; Sct::Tokenize t2(remainder, "."); const TokenVec & t2Vec = t2.tokenVec(); if (t2.size()!=2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (notNumber(t2Vec[0]) || notNumber(t2Vec[1])) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; { std::istringstream ip(t2Vec[0]); std::istringstream ic(t2Vec[1]); PartitionIdentifier p; CrateIdentifier c; ip>>p; ic>>c; *this = UCID(p,c); }; }; Sct::UniqueRodIdentifier::UniqueRodIdentifier(const string & s) { Sct::Tokenize t1(s,":"); const TokenVec & t1Vec = t1.tokenVec(); if (t1Vec.size() != 2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (t1Vec[0] != tag()) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; const std::string & remainder = t1Vec[1]; Sct::Tokenize t2(remainder, "."); const TokenVec & t2Vec = t2.tokenVec(); if (t2.size()!=3) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (notNumber(t2Vec[0]) || notNumber(t2Vec[1]) || notNumber(t2Vec[2])) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; { std::istringstream ip(t2Vec[0]); std::istringstream ic(t2Vec[1]); std::istringstream ir(t2Vec[2]); PartitionIdentifier p; CrateIdentifier c; RodIdentifier r; ip>>p; ic>>c; ir>>r; *this = URID(p,c,r); }; }; Sct::UniqueTimIdentifier::UniqueTimIdentifier(const string & s) { Sct::Tokenize t1(s,":"); const TokenVec & t1Vec = t1.tokenVec(); if (t1Vec.size() != 2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (t1Vec[0] != tag()) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; const std::string & remainder = t1Vec[1]; Sct::Tokenize t2(remainder, "."); const TokenVec & t2Vec = t2.tokenVec(); if (t2.size()!=2) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; if (notNumber(t2Vec[0]) || notNumber(t2Vec[1])) { throw InvalidArgumentError(tag()+ " can't parse [" + s + "].", __FILE__, __LINE__); }; { std::istringstream ip(t2Vec[0]); std::istringstream ic(t2Vec[1]); PartitionIdentifier p; CrateIdentifier c; ip>>p; ic>>c; *this = UTID(p,c); }; };