Open
Graph Drawing
Framework

 v.2007.11
 

String.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 1.5 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2007-11-08 16:10:37 +0100 (Do, 08 Nov 2007) $ 
00007  ***************************************************************/
00008  
00051 #ifdef _MSC_VER
00052 #pragma once
00053 #endif
00054 
00055 #ifndef OGDF_STRING_H
00056 #define OGDF_STRING_H
00057 
00058 
00059 #include <ogdf/basic/basic.h>
00060 #include <ogdf/basic/Hashing.h>
00061 
00062 
00063 #define OGDF_STRING_BUFFER_SIZE 1024
00064 
00065 
00066 namespace ogdf {
00067 
00068 
00070 
00074 class String {
00075     
00076     char  *m_pChar; 
00077     size_t m_length;  
00078 
00079     static char s_pBuffer[OGDF_STRING_BUFFER_SIZE]; 
00080 
00081 public:
00083     String();
00085     String(const char c);
00087     String(const char *str);
00088     //String(const char *format, ...);
00090 
00096     String(size_t maxLen, const char *str); // just copy the first 'maxLen' characters into the string; copy all, if maxLen == -1
00098     String(const String &str);
00099 
00100     ~String();
00101 
00103     //operator const char *() const { return m_pChar; }
00104     const char *cstr() const { return m_pChar; }
00105 
00107     size_t length() const { return m_length; }
00108 
00110     char &operator[](size_t i) {
00111         OGDF_ASSERT(0 <= i && i < m_length)
00112         return m_pChar[i];
00113     }
00114 
00116     const char &operator[](size_t i) const {
00117         OGDF_ASSERT(0 <= i && i < m_length)
00118         return m_pChar[i];
00119     }
00120 
00122     friend bool operator==(const String &x, const String &y) {
00123         return (compare(x,y) == 0);
00124     }
00126     friend bool operator==(const char *x, const String &y) {
00127         return (compare(x,y) == 0);
00128     }
00130     friend bool operator==(const String &x, const char *y) {
00131         return (compare(x,y) == 0);
00132     }
00133 
00135     friend bool operator!=(const String &x, const String &y) {
00136         return (compare(x,y) != 0);
00137     }
00139     friend bool operator!=(const char *x, const String &y) {
00140         return (compare(x,y) != 0);
00141     }
00143     friend bool operator!=(const String &x, const char *y) {
00144         return (compare(x,y) != 0);
00145     }
00146 
00148     friend bool operator<(const String &x, const String &y) {
00149         return (compare(x,y) < 0);
00150     }
00152     friend bool operator<(const char *x, const String &y) {
00153         return (compare(x,y) < 0);
00154     }
00156     friend bool operator<(const String &x, const char *y) {
00157         return (compare(x,y) < 0);
00158     }
00159 
00161     friend bool operator<=(const String &x, const String &y) {
00162         return (compare(x,y) <= 0);
00163     }
00165     friend bool operator<=(const char *x, const String &y) {
00166         return (compare(x,y) <= 0);
00167     }
00169     friend bool operator<=(const String &x, const char *y) {
00170         return (compare(x,y) <= 0);
00171     }
00172 
00174     friend bool operator>(const String &x, const String &y) {
00175         return (compare(x,y) > 0);
00176     }
00178     friend bool operator>(const char *x, const String &y) {
00179         return (compare(x,y) > 0);
00180     }
00182     friend bool operator>(const String &x, const char *y) {
00183         return (compare(x,y) > 0);
00184     }
00185 
00187     friend bool operator>=(const String &x, const String &y) {
00188         return (compare(x,y) >= 0);
00189     }
00191     friend bool operator>=(const char *x, const String &y) {
00192         return (compare(x,y) >= 0);
00193     }
00195     friend bool operator>=(const String &x, const char *y) {
00196         return (compare(x,y) >= 0);
00197     }
00198 
00200     String &operator=(const String &str);
00202     String &operator=(const char *str);
00203 
00205     String &operator+=(const String &str);
00206 
00208 
00211     void sprintf(const char *format, ...);
00212 
00214     static int compare (const String &x, const String &y);
00215 
00217     friend istream& operator>>(istream& is, String &str);
00218 
00219     OGDF_NEW_DELETE
00220 };
00221 
00223 inline ostream &operator<<(ostream &os, const String &str) {
00224     os << str.cstr();
00225     return os;
00226 }
00227 
00228 template<> class DefHashFunc<String> {
00229 public:
00230     int hash(const String &key) const;
00231 };
00232 
00233 
00234 } // end namespace ogdf
00235 
00236 
00237 #endif


© 1999-2007 by oreas GmbH, © 2005-2007 by University Dortmund and University Cologne.

Generated on Thu Nov 22 19:40:01 2007 by doxygen 1.5.4.