Unique strings. More...
#include <Ustring.h>
Public Member Functions | |
Ustring (UstringHash &nameHash_r, const std::string &n) | |
const std::string & | asString () const |
operator const std::string & () const | |
std::string::size_type | size () const |
bool | empty () const |
int | compare (const std::string &rhs) const |
int | compare (const Ustring &rhs) const |
const std::string * | operator-> () const |
Private Attributes | |
std::string | _name |
Friends | |
bool | operator== (const Ustring &lhs, const Ustring &rhs) |
bool | operator== (const Ustring &lhs, const std::string &rhs) |
bool | operator== (const std::string &lhs, const Ustring &rhs) |
bool | operator!= (const Ustring &lhs, const Ustring &rhs) |
bool | operator!= (const Ustring &lhs, const std::string &rhs) |
bool | operator!= (const std::string &lhs, const Ustring &rhs) |
bool | operator< (const Ustring &lhs, const Ustring &rhs) |
bool | operator< (const Ustring &lhs, const std::string &rhs) |
bool | operator< (const std::string &lhs, const Ustring &rhs) |
bool | operator> (const Ustring &lhs, const Ustring &rhs) |
bool | operator> (const Ustring &lhs, const std::string &rhs) |
bool | operator> (const std::string &lhs, const Ustring &rhs) |
bool | operator>= (const Ustring &lhs, const Ustring &rhs) |
bool | operator>= (const Ustring &lhs, const std::string &rhs) |
bool | operator>= (const std::string &lhs, const Ustring &rhs) |
bool | operator<= (const Ustring &lhs, const Ustring &rhs) |
bool | operator<= (const Ustring &lhs, const std::string &rhs) |
bool | operator<= (const std::string &lhs, const Ustring &rhs) |
std::ostream & | operator<< (std::ostream &str, const Ustring &obj) |
Unique strings.
Ustring provides an immutable string and uses a UstringHash to keep the strings representaion class (which contains the actual data) unique.
That way Ustrings of the same value and using the same UstringHash can be stored at various locations, while the actual string data are stored only once.
The UstringHash to use is passed to the constructor, and no more needed after the string has been stored.
Conversion to string is possible and cheap, as the created string will, unless he's modified, share it's data with the one inside the Ustring.
Comparison between Ustrings and strings are based on string.
A ->
operator is provided as an easy way to invoke const string methods, like size() or c_str().
ustr->size(); // short for ((const std::string &)u).size();
Most common usage will be deriving some class from Ustring, that provides a static UstringHash, and some constructor. Everything else is provided by Ustring.
class PkgName : public Ustring { private: static UstringHash _nameHash; public: explicit PkgName( const std::string & n = "" ) : Ustring( _nameHash, n ) {} };
Ustring::Ustring | ( | UstringHash & | nameHash_r, | |
const std::string & | n | |||
) | [inline] |
Constructor calls UstringHash::add on the given string, and stores the string returned from the hash.
const std::string& Ustring::asString | ( | ) | const [inline] |
Conversion to const std::string &
References _name.
Referenced by YCPPathRep::Component::compare(), YSFilename::evaluate(), YCPTermRep::functionalAdd(), YSImport::name(), YCPTermRep::name(), SymbolEntry::name(), operator const std::string &(), SymbolEntry::setValue(), YCPTermRep::shallowCopy(), YCPSymbolRep::symbol(), YCPSymbolRep::symbol_cstr(), YSymbolEntry::toStream(), YSymbolEntry::toString(), YSFilename::toString(), YSImport::toString(), YSInclude::toString(), YSTextdomain::toString(), YSTypedef::toString(), YCPTermRep::toString(), YCPSymbolRep::toString(), YCPPathRep::Component::toString(), SymbolEntry::toString(), YSymbolEntry::toXml(), YSFilename::toXml(), YSImport::toXml(), YSInclude::toXml(), YSTextdomain::toXml(), YCPSymbolRep::toXml(), YCPPathRep::Component::toXml(), and YSymbolEntry::YSymbolEntry().
int Ustring::compare | ( | const Ustring & | rhs | ) | const [inline] |
int Ustring::compare | ( | const std::string & | rhs | ) | const [inline] |
bool Ustring::empty | ( | ) | const [inline] |
short for ((const std::string &)ustr).empty();
Referenced by Import::import().
Ustring::operator const std::string & | ( | ) | const [inline] |
Conversion to const std::string &
References asString().
const std::string* Ustring::operator-> | ( | ) | const [inline] |
ustr->???(); // short for ((const std::string &)ustr).???();
std::string::size_type Ustring::size | ( | ) | const [inline] |
short for ((const std::string &)ustr).size();
Referenced by Bytecode::writeUstring().
bool operator!= | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator!= | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
bool operator< | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator< | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
std::ostream& operator<< | ( | std::ostream & | str, | |
const Ustring & | obj | |||
) | [friend] |
bool operator<= | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator<= | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
bool operator== | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator== | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
bool operator> | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator> | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
bool operator>= | ( | const std::string & | lhs, | |
const Ustring & | rhs | |||
) | [friend] |
bool operator>= | ( | const Ustring & | lhs, | |
const std::string & | rhs | |||
) | [friend] |
std::string Ustring::_name [private] |
!!! It should actualy be const !!! But that way default copy and assingment can be used.
Referenced by asString().