1 #ifndef __DIADES__UTILS__IDENTIFIER__HH 2 #define __DIADES__UTILS__IDENTIFIER__HH 15 #include<unordered_map> 25 using std::unordered_map;
35 class IdentifierFactory;
76 static string typeName() {
return "Utils::IdentifierData"; }
89 IdentifierData(
const std::string & idLabel,
unsigned id,
double rank):
std::string(idLabel),_id(id),_rank(rank){}
143 static string typeName() {
return "Utils::Identifier"; }
226 if(
this != &identifier)
228 _data = identifier.
_data;
259 return _data->begin();
272 return _data->
rank();
300 return _data->rbegin();
313 return _data->rend();
327 return _data->size();
353 always_require(Exception,valid(),
"operator[]: Invalid identifier");
354 return _data->operator[](pos);
377 Identifier & operator+= (
const string& str );
421 const string &
str()
const 440 return _data->c_str();
453 return _data == identifier.
_data;
465 return !operator==(identifier);
477 bool operator<(
const Identifier & identifier)
const;
488 friend istream & operator >> (istream & is,
Identifier & identifier);
503 if(identifier.
valid())
505 return os << identifier.
str();
507 return os <<
"__DIADES__UTILS__INVALID__IDENTIFIER";
541 static void destroy();
554 static string typeName() {
return "Utils::IdentifierFactory"; }
588 Identifier getIdentifier(
const std::string & str);
604 if(identifier.
valid())
606 return (
size_t) (identifier.
rank() * 100000);
const char * c_str() const
An Identifier is a reference to a string (IdentifierData) that only contains alpha-numeric characters...
#define always_require(Exception, expr, message)
size_t operator()(const Diades::Utils::Identifier &identifier) const
A IdentifierFactory is a factory in charge of creating IdentifierData.
vector< Identifier > _identifiers
const char & operator[](size_t pos) const
const string & str() const
istream & getIdentifierString(istream &is, std::string &identifier)
Utils::Exception< Identifier > Exception
static IdentifierFactory * _instance
unordered_map< string, unsigned > _dictionary
This is the internal representation of an Identifier.
map< double, Identifier > _rankings
Namespace of the Diades project.
string::const_reverse_iterator ConstReverseIterator
std::ostream & operator<<(std::ostream &os, const Identifier &identifier)
Identifier & operator=(const Identifier &identifier)
ConstReverseIterator rend()
Utils::Exception< IdentifierFactory > Exception
Diades::Utils::Identifier Identifier
Identifier(IdentifierData *data)
Utils::Exception< IdentifierData > Exception
ConstIterator begin() const
Identifier(const Identifier &identifier)
IdentifierData(const IdentifierData &data)
IdentifierData(const std::string &idLabel, unsigned id, double rank)
ConstReverseIterator rbegin()
string::const_iterator ConstIterator