Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

idep_string.cxx

Go to the documentation of this file.
00001 // string.c
00002 #include "idep_string.h"
00003 
00004 #include <string.h>     // strlen() strcmp()
00005 #include <memory.h>     // memcpy()
00006 
00007                 // -*-*-*- static functions -*-*-*-
00008 
00009 static char *init (const char *str) 
00010 {
00011     int size = strlen(str) + 1;
00012     char *string = new char[size];
00013     memcpy(string, str, size);
00014     return string;
00015 }
00016 
00017                 // -*-*-*- idep_String -*-*-*-
00018 
00019 // CREATORS
00020 idep_String::idep_String() 
00021 : d_string_p(init(""))
00022 { 
00023 }
00024 
00025 idep_String::idep_String(const idep_String& string) 
00026 : d_string_p(init(string.d_string_p))
00027 { 
00028 }
00029 
00030 idep_String::idep_String(const char* str) 
00031 : d_string_p(init(str))
00032 { 
00033 }
00034 
00035 idep_String::~idep_String() 
00036 {
00037     delete d_string_p;
00038 }
00039 
00040 // MANIPULATORS
00041 idep_String& idep_String::operator=(const idep_String& string) 
00042 {
00043     if (this != &string) {
00044         delete d_string_p;
00045         d_string_p = init(string.d_string_p);
00046     }
00047     return *this;
00048 }
00049 
00050 idep_String& idep_String::operator=(const char* str) 
00051 {
00052     char *tmp = d_string_p;     // string could be a substring of itself
00053     d_string_p = init(str);
00054     delete tmp;
00055     return *this;
00056 }
00057 
00058 idep_String& idep_String::operator+=(const idep_String& string) 
00059 {
00060     return *this += string.d_string_p;
00061 }
00062     
00063 idep_String& idep_String::operator+=(const char* str) 
00064 {
00065     char *tmp = d_string_p;     
00066     int len = length();
00067     int size = strlen(str) + 1;
00068     d_string_p = new char[len + size];
00069     memcpy(d_string_p, tmp, len);
00070     memcpy(d_string_p + len, str, size);
00071     delete tmp;
00072     return *this;
00073 }
00074 
00075 // ACCESSORS
00076 idep_String::operator const char *() const 
00077 {
00078     return d_string_p;
00079 }
00080 
00081 int idep_String::length() const 
00082 {
00083     return strlen(d_string_p);
00084 }    
00085 
00086 // FREE OPERATORS
00087 idep_String operator+(const idep_String& left, const idep_String& right) 
00088 {
00089     return idep_String(left) += right;
00090 }
00091 
00092 idep_String operator+(const char* str, const idep_String& string) 
00093 {
00094     return idep_String(str) += string;
00095 }
00096 
00097 idep_String operator+(const idep_String& string, const char* str) 
00098 {
00099     return idep_String(string) += str;
00100 }
00101 
00102 int operator==(const idep_String& left, const idep_String& right) 
00103 {
00104     return strcmp(left, right) == 0;
00105 }
00106 
00107 int operator!=(const idep_String& left, const idep_String& right) 
00108 {
00109     return strcmp(left, right) != 0;
00110 }
00111 
00112 int operator<(const idep_String& left, const idep_String& right) 
00113 {
00114     return strcmp(left, right) <  0;
00115 }
00116 
00117 int operator<=(const idep_String& left, const idep_String& right) 
00118 {
00119     return strcmp(left, right) <= 0;
00120 }
00121 
00122 int operator>(const idep_String& left, const idep_String& right) 
00123 {
00124     return strcmp(left, right) >  0;
00125 }
00126 
00127 int operator>=(const idep_String& left, const idep_String& right) 
00128 {
00129     return strcmp(left, right) >= 0;
00130 }
00131 
00132 
00133 int operator==(const char* str, const idep_String& string) 
00134 {
00135     return strcmp(str, string) == 0;
00136 }
00137 
00138 int operator!=(const char* str, const idep_String& string) 
00139 {
00140     return strcmp(str, string) != 0;
00141 }
00142 
00143 int operator<(const char* str, const idep_String& string) 
00144 {
00145     return strcmp(str, string) <  0;
00146 }
00147 
00148 int operator<=(const char* str, const idep_String& string) 
00149 {
00150     return strcmp(str, string) <= 0;
00151 }
00152 
00153 int operator>(const char* str, const idep_String& string) 
00154 {
00155     return strcmp(str, string) >  0;
00156 }
00157 
00158 int operator>=(const char* str, const idep_String& string) 
00159 {
00160     return strcmp(str, string) >= 0;
00161 }
00162 
00163 
00164 int operator==(const idep_String& string, const char *str) 
00165 {
00166     return strcmp(str, string) == 0;
00167 }
00168 
00169 int operator!=(const idep_String& string, const char *str) 
00170 {
00171     return strcmp(string, str) != 0;
00172 }
00173 
00174 int operator<(const idep_String& string, const char *str) 
00175 {
00176     return strcmp(string, str) <  0;
00177 }
00178 
00179 int operator<=(const idep_String& string, const char *str) 
00180 {
00181     return strcmp(string, str) <= 0;
00182 }
00183 
00184 int operator>(const idep_String& string, const char *str) 
00185 {
00186     return strcmp(string, str) >  0;
00187 }
00188 
00189 int operator>=(const idep_String& string, const char *str) 
00190 {
00191     return strcmp(string, str) >= 0;
00192 }
00193 

Generated on Mon Feb 15 11:06:48 2010 for loon by  doxygen 1.3.9.1