Open
Graph Drawing
Framework

 v.2012.05
 

String.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_STRING_H
00048 #define OGDF_STRING_H
00049 
00050 
00051 #include <ogdf/basic/basic.h>
00052 #include <ogdf/basic/Hashing.h>
00053 
00054 
00055 #define OGDF_STRING_BUFFER_SIZE 1024
00056 
00057 
00058 namespace ogdf {
00059 
00060 
00062 
00066 class OGDF_EXPORT String {
00067     
00068     char  *m_pChar; 
00069     size_t m_length;  
00070 
00071     static char s_pBuffer[OGDF_STRING_BUFFER_SIZE]; 
00072 
00073 public:
00075     String();
00077     String(const char c);
00079     String(const char *str);
00080     //String(const char *format, ...);
00082 
00087     String(size_t maxLen, const char *str);
00089     String(const String &str);
00090 
00091     ~String();
00092 
00094     //operator const char *() const { return m_pChar; }
00095     const char *cstr() const { return m_pChar; }
00096 
00098     size_t length() const { return m_length; }
00099 
00101     char &operator[](size_t i) {
00102         OGDF_ASSERT(0 <= i && i < m_length)
00103         return m_pChar[i];
00104     }
00105 
00107     const char &operator[](size_t i) const {
00108         OGDF_ASSERT(0 <= i && i < m_length)
00109         return m_pChar[i];
00110     }
00111 
00113     friend bool operator==(const String &x, const String &y) {
00114         return (compare(x,y) == 0);
00115     }
00117     friend bool operator==(const char *x, const String &y) {
00118         return (compare(x,y) == 0);
00119     }
00121     friend bool operator==(const String &x, const char *y) {
00122         return (compare(x,y) == 0);
00123     }
00124 
00126     friend bool operator!=(const String &x, const String &y) {
00127         return (compare(x,y) != 0);
00128     }
00130     friend bool operator!=(const char *x, const String &y) {
00131         return (compare(x,y) != 0);
00132     }
00134     friend bool operator!=(const String &x, const char *y) {
00135         return (compare(x,y) != 0);
00136     }
00137 
00139     friend bool operator<(const String &x, const String &y) {
00140         return (compare(x,y) < 0);
00141     }
00143     friend bool operator<(const char *x, const String &y) {
00144         return (compare(x,y) < 0);
00145     }
00147     friend bool operator<(const String &x, const char *y) {
00148         return (compare(x,y) < 0);
00149     }
00150 
00152     friend bool operator<=(const String &x, const String &y) {
00153         return (compare(x,y) <= 0);
00154     }
00156     friend bool operator<=(const char *x, const String &y) {
00157         return (compare(x,y) <= 0);
00158     }
00160     friend bool operator<=(const String &x, const char *y) {
00161         return (compare(x,y) <= 0);
00162     }
00163 
00165     friend bool operator>(const String &x, const String &y) {
00166         return (compare(x,y) > 0);
00167     }
00169     friend bool operator>(const char *x, const String &y) {
00170         return (compare(x,y) > 0);
00171     }
00173     friend bool operator>(const String &x, const char *y) {
00174         return (compare(x,y) > 0);
00175     }
00176 
00178     friend bool operator>=(const String &x, const String &y) {
00179         return (compare(x,y) >= 0);
00180     }
00182     friend bool operator>=(const char *x, const String &y) {
00183         return (compare(x,y) >= 0);
00184     }
00186     friend bool operator>=(const String &x, const char *y) {
00187         return (compare(x,y) >= 0);
00188     }
00189 
00191     String &operator=(const String &str);
00193     String &operator=(const char *str);
00194 
00196     String &operator+=(const String &str);
00197 
00199 
00202     void sprintf(const char *format, ...);
00203 
00205     static int compare (const String &x, const String &y);
00206 
00208     friend istream& operator>>(istream& is, String &str);
00209 
00210     OGDF_NEW_DELETE
00211 };
00212 
00214 inline ostream &operator<<(ostream &os, const String &str) {
00215     os << str.cstr();
00216     return os;
00217 }
00218 
00219 template<> class DefHashFunc<String> {
00220 public:
00221     int hash(const String &key) const;
00222 };
00223 
00224 
00225 } // end namespace ogdf
00226 
00227 
00228 #endif