yast2-core
|
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 ) {} };
|
inline |
Constructor calls UstringHash::add on the given string, and stores the string returned from the hash.
|
inline |
Conversion to const std::string &
References _name.
Referenced by YCPPathRep::Component::compare(), compare(), empty(), YSFilename::evaluate(), YCPTermRep::functionalAdd(), YCPTermRep::name(), SymbolEntry::name(), YSImport::name(), operator const std::string &(), operator->(), SymbolEntry::setValue(), YCPTermRep::shallowCopy(), size(), YCPSymbolRep::symbol(), YCPSymbolRep::symbol_cstr(), YSymbolEntry::toStream(), YCPSymbolRep::toString(), YSymbolEntry::toString(), YCPTermRep::toString(), SymbolEntry::toString(), YSTypedef::toString(), YSTextdomain::toString(), YSInclude::toString(), YSImport::toString(), YSFilename::toString(), YCPSymbolRep::toXml(), YSymbolEntry::toXml(), YSTextdomain::toXml(), YSInclude::toXml(), YSImport::toXml(), YSFilename::toXml(), and YSymbolEntry::YSymbolEntry().
|
inline |
References asString().
|
inline |
|
inline |
short for ((const std::string &)ustr).empty();
References asString().
Referenced by Import::import().
|
inline |
Conversion to const std::string &
References asString().
|
inline |
ustr->???(); // short for ((const std::string &)ustr).???();
References asString().
|
inline |
short for ((const std::string &)ustr).size();
References asString().
Referenced by Bytecode::writeUstring().
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
!!! It should actualy be const !!! But that way default copy and assingment can be used.
Referenced by asString().