yast2-core
Public Member Functions | Private Attributes | Friends | List of all members
Ustring Class Reference

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)
 

Detailed Description

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 ) {}
};
See Also
UstringHash

Constructor & Destructor Documentation

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.

Member Function Documentation

const std::string& Ustring::asString ( ) const
inline
int Ustring::compare ( const std::string &  rhs) const
inline

References asString().

int Ustring::compare ( const Ustring rhs) const
inline
bool Ustring::empty ( ) const
inline

short for ((const std::string &)ustr).empty();

References asString().

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).???();

References asString().

std::string::size_type Ustring::size ( ) const
inline

short for ((const std::string &)ustr).size();

References asString().

Referenced by Bytecode::writeUstring().

Friends And Related Function Documentation

bool operator!= ( const Ustring 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 Ustring rhs 
)
friend
bool operator< ( const Ustring lhs,
const std::string &  rhs 
)
friend
bool operator< ( const std::string &  lhs,
const Ustring rhs 
)
friend
std::ostream& operator<< ( std::ostream &  str,
const Ustring obj 
)
friend
bool operator<= ( const Ustring 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 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 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 Ustring rhs 
)
friend
bool operator>= ( const Ustring lhs,
const std::string &  rhs 
)
friend
bool operator>= ( const std::string &  lhs,
const Ustring rhs 
)
friend

Member Data Documentation

std::string Ustring::_name
private

!!! It should actualy be const !!! But that way default copy and assingment can be used.

Referenced by asString().


The documentation for this class was generated from the following file:

Generated on a sunny day for yast2-core by doxygen 1.8.6