Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Ustring.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       Ustring.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef Ustring_h
00020 #define Ustring_h
00021 
00022 #include <iostream>
00023 #include <string>
00024 // MemUsage.h defines/undefines D_MEMUSAGE
00025 #include "y2util/MemUsage.h"
00026 #include <set>
00027 
00029 //
00030 //      CLASS NAME : UstringHash
00038 class UstringHash
00039 #ifdef D_MEMUSAGE
00040  : public MemUsage
00041 #endif
00042  {
00043 
00044   protected:
00045 
00046     typedef std::set<std::string> UstringHash_type;
00047 
00048     UstringHash_type _UstringHash;
00049 
00050   public:
00051 
00052     const std::string & add( const std::string & nstr_r )
00053     {
00054         return *(_UstringHash.insert( nstr_r ).first);
00055     }
00056 
00060     unsigned size() const { return _UstringHash.size(); }
00061     unsigned long sum() const {
00062         UstringHash_type::const_iterator it = _UstringHash.begin();
00063         UstringHash_type::const_iterator e = _UstringHash.end();
00064         unsigned long sum = 0;
00065         while (it != e)
00066         {
00067             sum += it->size();
00068             it++;
00069         }
00070         return sum;
00071     }
00072 #ifdef D_MEMUSAGE
00073     virtual size_t mem_size () const { return sizeof (UstringHash); }
00074 #endif
00075 };
00076 
00078 
00080 //
00081 //      CLASS NAME : Ustring
00124 class Ustring
00125 #ifdef D_MEMUSAGE
00126   : public MemUsage
00127 #endif
00128  {
00129 
00130   private:
00131 
00136     std::string _name;
00137 
00138   public:
00139 #ifdef D_MEMUSAGE
00140     virtual size_t mem_size () const { return sizeof (Ustring); }
00141 #endif
00142 
00146     Ustring( UstringHash & nameHash_r, const std::string & n  )
00147       :_name( nameHash_r.add( n ) )
00148     {}
00149 
00150   public:
00151 
00155     operator const std::string & () const { return _name; }
00156 
00160     const std::string & asString() const { return _name; }
00161 
00165     const std::string * operator->() const { return & _name; }
00166 
00167     // operator ==
00168 
00169     friend bool operator==( const Ustring & lhs, const Ustring & rhs ) {
00170       return ( (const std::string &)lhs == (const std::string &)rhs );
00171     }
00172 
00173     friend bool operator==( const Ustring & lhs, const std::string & rhs ) {
00174       return ( (const std::string &)lhs == rhs );
00175     }
00176 
00177     friend bool operator==( const std::string & lhs, const Ustring & rhs ) {
00178       return ( lhs == (const std::string &)rhs );
00179     }
00180 
00181     // operator !=
00182 
00183     friend bool operator!=( const Ustring & lhs, const Ustring & rhs ) {
00184       return ( ! operator==( lhs, rhs ) );
00185     }
00186 
00187     friend bool operator!=( const Ustring & lhs, const std::string & rhs ) {
00188       return ( ! operator==( lhs, rhs ) );
00189     }
00190 
00191     friend bool operator!=( const std::string & lhs, const Ustring & rhs ) {
00192       return ( ! operator==( lhs, rhs ) );
00193     }
00194 
00195     // operator <
00196 
00197     friend bool operator<( const Ustring & lhs, const Ustring & rhs ) {
00198       return ( (const std::string &)lhs < (const std::string &)rhs );
00199     }
00200 
00201     friend bool operator<( const Ustring & lhs, const std::string & rhs ) {
00202       return ( (const std::string &)lhs < rhs );
00203     }
00204 
00205     friend bool operator<( const std::string & lhs, const Ustring & rhs ) {
00206       return ( lhs < (const std::string &)rhs );
00207     }
00208 
00209     // operator >
00210 
00211     friend bool operator>( const Ustring & lhs, const Ustring & rhs ) {
00212       return ( (const std::string &)lhs > (const std::string &)rhs );
00213     }
00214 
00215     friend bool operator>( const Ustring & lhs, const std::string & rhs ) {
00216       return ( (const std::string &)lhs > rhs );
00217     }
00218 
00219     friend bool operator>( const std::string & lhs, const Ustring & rhs ) {
00220       return ( lhs > (const std::string &)rhs );
00221     }
00222 
00223     // operator >=
00224 
00225     friend bool operator>=( const Ustring & lhs, const Ustring & rhs ) {
00226       return ( ! operator<( lhs, rhs ) );
00227     }
00228 
00229     friend bool operator>=( const Ustring & lhs, const std::string & rhs ) {
00230       return ( ! operator<( lhs, rhs ) );
00231     }
00232 
00233     friend bool operator>=( const std::string & lhs, const Ustring & rhs ) {
00234       return ( ! operator<( lhs, rhs ) );
00235     }
00236 
00237     // operator <=
00238 
00239     friend bool operator<=( const Ustring & lhs, const Ustring & rhs ) {
00240       return ( ! operator>( lhs, rhs ) );
00241     }
00242 
00243     friend bool operator<=( const Ustring & lhs, const std::string & rhs ) {
00244       return ( ! operator>( lhs, rhs ) );
00245     }
00246 
00247     friend bool operator<=( const std::string & lhs, const Ustring & rhs ) {
00248       return ( ! operator>( lhs, rhs ) );
00249     }
00250 
00251     // IO
00252 
00253     friend std::ostream & operator<<( std::ostream & str, const Ustring & obj ) {
00254       return str << (const std::string &)obj;
00255     }
00256 };
00257 
00258 #endif // Ustring_h

Generated on Thu Feb 23 23:56:10 2006 for liby2util by doxygen 1.3.6