Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

d_String.h

Go to the documentation of this file.
00001 
00002 #ifndef d_String_h
00003 #define d_String_h 1
00004 //------------------------------------------------------------------------------
00005 
00006 #include <string.h>
00007 #include <iostream>
00008 
00009 #include "d_Binary.h"
00010 
00011 //------------------------------------------------------------------------------
00012 class _ODLL oMemoryManager;
00013 
00014 //------------------------------------------------------------------------------
00015 
00016 /**
00017  * This class handles string of chars.
00018  *
00019  * LOCATION:
00020  * d_String.h
00021  *
00022  * USAGE:
00023  * d_String     <variable>;
00024  * 
00025  * Where:
00026  * <VARIABLE>:  NAME OF VARIABLE
00027  *
00028  * EXAMPLES:
00029  * class Customer : public d_Object
00030  * {
00031  *   d_String    surname;
00032  *   d_String    name;
00033  * };
00034  * 
00035  *  * Use a d_String object in app
00036  * d_String       text;
00037  *
00038  * ODMG:
00039  * Compliant 
00040  */
00041 class _ODLL d_String : public d_Binary
00042 {
00043   public:
00044 
00045     // Internal.
00046     typedef enum{ mExact, mWhile, mUntil } modes;
00047 
00048     d_String();
00049     d_String( const d_String& iSource );
00050     d_String( const char* iSource );
00051     d_String( const int iSource );
00052     d_String( const unsigned int iSource );
00053     d_String( const bool iSource );
00054     d_String( const float iSource, int iPrecision = 3 );
00055     d_String( const double iSource, int iPrecision = 3 );
00056 
00057     d_String& operator = (const d_String& iSource);
00058     d_String& operator = (const char* iSource);
00059     d_String& operator = (const char iSource);
00060     d_String& operator = (const long iSource);
00061     d_String& operator = (const float iSource);
00062     d_String& operator += (const d_String& iSource);
00063     d_String& operator += (const char* iSource);
00064     d_String& operator += (const char iSource);
00065     d_String& operator += (const long iSource);
00066     d_String& operator += (const float iSource);
00067     d_String operator + (const d_String& iSource) const;
00068     d_String operator + (const char* iSource) const;
00069     d_String operator + (const char iSource) const;
00070     d_String operator + (const long iSource) const ;
00071     d_String operator + (const float iSource) const;
00072     friend bool const operator == (const d_String& iLeft, const d_String& iRight);
00073     friend bool const operator == (const d_String& iLeft, const char* iRight);
00074     friend bool const operator == (const char* iLeft, const d_String& iRight);
00075     friend bool operator != (const d_String& iLeft, const d_String& iRight);
00076     friend bool operator != (const d_String& iLeft, const char* iRight);
00077     friend bool operator != (const char* iLeft, const d_String& iRight);
00078     friend bool const operator > (const d_String& iLeft, const d_String& iRight);
00079     friend bool const operator > (const d_String& iLeft, const char* iRight);
00080     friend bool const operator > (const char* iLeft, const d_String& iRight);
00081     friend bool const operator < (const d_String& iLeft, const d_String& iRight);
00082     friend bool const operator < (const d_String& iLeft, const char* iRight);
00083     friend bool const operator < (const char* iLeft, const d_String& iRight);
00084     friend bool const operator >= (const d_String& iLeft, const d_String& iRight);
00085     friend bool const operator >= (const d_String& iLeft, const char* iRight);
00086     friend bool const operator >= (const char* iLeft, const d_String& iRight);
00087     friend bool const operator <= (const d_String& iLeft, const d_String& iRight);
00088     friend bool const operator <= (const d_String& iLeft, const char* iRight);
00089     friend bool const operator <= (const char* iLeft, const d_String& iRight);
00090 
00091     void toUpperCase();
00092     void toLowerCase();
00093 
00094     operator const char* () const;
00095 
00096     char& operator [] (const unsigned int iIndex) const;
00097 
00098     friend _ODLL std::ostream& operator<< (std::ostream& ioStream, const d_String& iString);
00099     friend _ODLL std::istream& operator>> (std::istream& iStream, d_String& ioString);
00100 
00101     void erase (const unsigned long iFrom);
00102     void erase (const unsigned long iFrom, const unsigned long iHow);
00103     unsigned long length () const;
00104     char* const c_str () const;
00105     long find (const char* iPattern);
00106     long find_last_of (const char* iPattern);
00107     oInt4 getWord (oUInt4 iWordNum, d_String& ioWord, const char* iSeparators = sepDefault);
00108     int take (const oUInt4 iOffset, const modes iMode, char* iTake, d_String* iResult = 0) const;
00109     int jump (const char* iJump, const oUInt4 iOffset = 0) const;
00110 
00111   //---------------------------------------------------------------------------
00112   // CONSTANTS:
00113   //---------------------------------------------------------------------------
00114   public:
00115     static const char terminator;
00116 
00117   private:
00118     // Internal.
00119     static const char sepDefault[];
00120     
00121     // Internal.
00122 
00123     static const int DEFAULT_SIZE;
00124     static const int DEFAULT_STEP;
00125 };
00126 
00127 //------------------------------------------------------------------------------
00128 inline d_String::d_String()
00129   : d_Binary( DEFAULT_SIZE, DEFAULT_STEP )
00130 {
00131 }
00132 //------------------------------------------------------------------------------
00133 inline d_String::d_String (const d_String& iSource)
00134   : d_Binary( iSource.buffer, iSource._length )
00135 {
00136 }
00137 //------------------------------------------------------------------------------
00138 inline d_String::d_String (const char* iSource)
00139   : d_Binary( iSource, ::strlen( iSource ) + 1 )
00140 {
00141 }
00142 //------------------------------------------------------------------------------
00143 inline d_String& d_String::operator = (const d_String& iSource)
00144 {
00145   _length = 0;
00146   set( (d_Binary&) iSource, 0 );
00147   return *this;
00148 }
00149 //------------------------------------------------------------------------------
00150 inline d_String& d_String::operator = (const char* iSource)
00151 {
00152   _length = 0;
00153   set( iSource, 0, ::strlen( iSource ) + 1 );
00154   return *this;
00155 }
00156 //------------------------------------------------------------------------------
00157 inline d_String& d_String::operator += (const d_String& iSource)
00158 {
00159   set( (d_Binary&) iSource, _length - 1 );
00160   return *this;
00161 }
00162 //------------------------------------------------------------------------------
00163 inline d_String& d_String::operator += (const char* iSource)
00164 {
00165   set( iSource, _length - 1, ::strlen( iSource ) + 1 );
00166   return *this;
00167 }
00168 //------------------------------------------------------------------------------
00169 inline bool const operator == (const d_String& iLeft, const d_String& iRight)
00170 {
00171   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) == 0 );
00172 }
00173 //------------------------------------------------------------------------------
00174 inline bool const operator == (const d_String& iLeft, const char* iRight)
00175 {
00176   return ( ::strcmp( iLeft.c_str(), iRight ) == 0 );
00177 }
00178 //------------------------------------------------------------------------------
00179 inline bool const operator == (const char* iLeft, const d_String& iRight)
00180 {
00181   return ( ::strcmp( iLeft, iRight.c_str() ) == 0 );
00182 }
00183 //------------------------------------------------------------------------------
00184 inline bool operator != (const d_String& iLeft, const d_String& iRight)
00185 {
00186   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) != 0 );
00187 }
00188 //------------------------------------------------------------------------------
00189 inline bool operator != (const d_String& iLeft, const char* iRight)
00190 {
00191   return ( ::strcmp( iLeft.c_str(), iRight ) != 0 );
00192 }
00193 //------------------------------------------------------------------------------
00194 inline bool operator != (const char* iLeft, const d_String& iRight)
00195 {
00196   return ( ::strcmp( iLeft, iRight.c_str() ) != 0 );
00197 }
00198 //------------------------------------------------------------------------------
00199 inline bool const operator > (const d_String& iLeft, const d_String& iRight)
00200 {
00201   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) > 0 );
00202 }
00203 //------------------------------------------------------------------------------
00204 inline bool const operator > (const d_String& iLeft, const char* iRight)
00205 {
00206   return ( ::strcmp( iLeft.c_str(), iRight ) > 0 );
00207 }
00208 //------------------------------------------------------------------------------
00209 inline bool const operator > (const char* iLeft, const d_String& iRight)
00210 {
00211   return ( ::strcmp( iLeft, iRight.c_str() ) > 0 );
00212 }
00213 //------------------------------------------------------------------------------
00214 inline bool const operator < (const d_String& iLeft, const d_String& iRight)
00215 {
00216   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) < 0 );
00217 }
00218 //------------------------------------------------------------------------------
00219 inline bool const operator < (const d_String& iLeft, const char* iRight)
00220 {
00221   return ( ::strcmp( iLeft.c_str(), iRight ) < 0 );
00222 }
00223 //------------------------------------------------------------------------------
00224 inline bool const operator < (const char* iLeft, const d_String& iRight)
00225 {
00226   return ( ::strcmp( iLeft, iRight.c_str() ) < 0 );
00227 }
00228 //------------------------------------------------------------------------------
00229 inline bool const operator >= (const d_String& iLeft, const d_String& iRight)
00230 {
00231   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) >= 0 );
00232 }
00233 //------------------------------------------------------------------------------
00234 inline bool const operator >= (const d_String& iLeft, const char* iRight)
00235 {
00236   return ( ::strcmp( iLeft.c_str(), iRight ) >= 0 );
00237 }
00238 //------------------------------------------------------------------------------
00239 inline bool const operator >= (const char* iLeft, const d_String& iRight)
00240 {
00241   return ( ::strcmp( iLeft, iRight.c_str() ) >= 0 );
00242 }
00243 //------------------------------------------------------------------------------
00244 inline bool const operator <= (const d_String& iLeft, const d_String& iRight)
00245 {
00246   return ( ::strcmp( iLeft.c_str(), iRight.c_str() ) <= 0 );
00247 }
00248 //------------------------------------------------------------------------------
00249 inline bool const operator <= (const d_String& iLeft, const char* iRight)
00250 {
00251   return ( ::strcmp( iLeft.c_str(), iRight ) <= 0 );
00252 }
00253 //------------------------------------------------------------------------------
00254 inline bool const operator <= (const char* iLeft, const d_String& iRight)
00255 {
00256   return ( ::strcmp( iLeft, iRight.c_str() ) <= 0 );
00257 }
00258 //------------------------------------------------------------------------------
00259 inline d_String::operator const char* () const
00260 {
00261   return buffer;
00262 }
00263 //------------------------------------------------------------------------------
00264 inline void d_String::erase (const unsigned long iFrom)
00265 {
00266   cut( iFrom, _length - iFrom - 1 );
00267 }
00268 //------------------------------------------------------------------------------
00269 inline void d_String::erase (const unsigned long iFrom, const unsigned long iHow)
00270 {
00271   cut( iFrom, iHow );
00272 }
00273 //------------------------------------------------------------------------------
00274 inline unsigned long d_String::length () const
00275 {
00276   if( _length == 0 )
00277     return 0;
00278   return _length - 1;
00279 }
00280 //------------------------------------------------------------------------------
00281 inline char* const d_String::c_str () const
00282 {
00283   return buffer;
00284 }
00285 //------------------------------------------------------------------------------
00286 
00287 #endif
00288 

Generated on Fri Nov 29 17:12:13 2002 for Orient ODBMS Just Edition v. 2.0e by doxygen1.3-rc1