Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00053 #ifdef _MSC_VER
00054 #pragma once
00055 #endif
00056
00057 #ifndef OGDF_STRING_H
00058 #define OGDF_STRING_H
00059
00060
00061 #include <ogdf/basic/basic.h>
00062 #include <ogdf/basic/Hashing.h>
00063
00064
00065 #define OGDF_STRING_BUFFER_SIZE 1024
00066
00067
00068 namespace ogdf {
00069
00070
00072
00076 class OGDF_EXPORT String {
00077
00078 char *m_pChar;
00079 size_t m_length;
00080
00081 static char s_pBuffer[OGDF_STRING_BUFFER_SIZE];
00082
00083 public:
00085 String();
00087 String(const char c);
00089 String(const char *str);
00090
00092
00097 String(size_t maxLen, const char *str);
00099 String(const String &str);
00100
00101 ~String();
00102
00104
00105 const char *cstr() const { return m_pChar; }
00106
00108 size_t length() const { return m_length; }
00109
00111 char &operator[](size_t i) {
00112 OGDF_ASSERT(0 <= i && i < m_length)
00113 return m_pChar[i];
00114 }
00115
00117 const char &operator[](size_t i) const {
00118 OGDF_ASSERT(0 <= i && i < m_length)
00119 return m_pChar[i];
00120 }
00121
00123 friend bool operator==(const String &x, const String &y) {
00124 return (compare(x,y) == 0);
00125 }
00127 friend bool operator==(const char *x, const String &y) {
00128 return (compare(x,y) == 0);
00129 }
00131 friend bool operator==(const String &x, const char *y) {
00132 return (compare(x,y) == 0);
00133 }
00134
00136 friend bool operator!=(const String &x, const String &y) {
00137 return (compare(x,y) != 0);
00138 }
00140 friend bool operator!=(const char *x, const String &y) {
00141 return (compare(x,y) != 0);
00142 }
00144 friend bool operator!=(const String &x, const char *y) {
00145 return (compare(x,y) != 0);
00146 }
00147
00149 friend bool operator<(const String &x, const String &y) {
00150 return (compare(x,y) < 0);
00151 }
00153 friend bool operator<(const char *x, const String &y) {
00154 return (compare(x,y) < 0);
00155 }
00157 friend bool operator<(const String &x, const char *y) {
00158 return (compare(x,y) < 0);
00159 }
00160
00162 friend bool operator<=(const String &x, const String &y) {
00163 return (compare(x,y) <= 0);
00164 }
00166 friend bool operator<=(const char *x, const String &y) {
00167 return (compare(x,y) <= 0);
00168 }
00170 friend bool operator<=(const String &x, const char *y) {
00171 return (compare(x,y) <= 0);
00172 }
00173
00175 friend bool operator>(const String &x, const String &y) {
00176 return (compare(x,y) > 0);
00177 }
00179 friend bool operator>(const char *x, const String &y) {
00180 return (compare(x,y) > 0);
00181 }
00183 friend bool operator>(const String &x, const char *y) {
00184 return (compare(x,y) > 0);
00185 }
00186
00188 friend bool operator>=(const String &x, const String &y) {
00189 return (compare(x,y) >= 0);
00190 }
00192 friend bool operator>=(const char *x, const String &y) {
00193 return (compare(x,y) >= 0);
00194 }
00196 friend bool operator>=(const String &x, const char *y) {
00197 return (compare(x,y) >= 0);
00198 }
00199
00201 String &operator=(const String &str);
00203 String &operator=(const char *str);
00204
00206 String &operator+=(const String &str);
00207
00209
00212 void sprintf(const char *format, ...);
00213
00215 static int compare (const String &x, const String &y);
00216
00218 friend istream& operator>>(istream& is, String &str);
00219
00220 OGDF_NEW_DELETE
00221 };
00222
00224 inline ostream &operator<<(ostream &os, const String &str) {
00225 os << str.cstr();
00226 return os;
00227 }
00228
00229 template<> class DefHashFunc<String> {
00230 public:
00231 int hash(const String &key) const;
00232 };
00233
00234
00235 }
00236
00237
00238 #endif