CharString.h

00001 /*  _________________________________________________________________________
00002  *
00003  *  UTILIB: A utility library for developing portable C++ codes.
00004  *  Copyright (c) 2001, Sandia National Laboratories.
00005  *  This software is distributed under the GNU Lesser General Public License.
00006  *  For more information, see the README file in the top UTILIB directory.
00007  *  _________________________________________________________________________
00008  */
00009 
00010 //
00011 // CharString.h
00012 //
00027 #ifndef __CharString_h
00028 #define __CharString_h
00029 
00030 #ifdef __GNUC__
00031 #pragma interface
00032 #endif
00033 
00034 #ifdef NON_ANSI
00035 #include <iostream.h>
00036 #else
00037 #include <iostream>
00038 using namespace std;
00039 #endif
00040 #ifndef ANSI_HDRS
00041 #include <string.h>
00042 #else
00043 #include <cstring>
00044 #endif
00045 #include "SimpleArray.h"
00046 
00047 
00048 #ifdef SWIG
00049 class CharString : public SimpleArray<char> {
00050 #else
00051 class UTILIB_API CharString : public SimpleArray<char> {
00052 #endif
00053 
00054 public:
00055 
00057   CharString();
00068 #ifndef NON_ANSI
00069   explicit 
00070 #endif
00071   CharString(const size_type len, char* str=(char*)0, 
00072                 const EnumDataOwned own=DataNotOwned);
00078   CharString(char* str, const EnumDataOwned own=DataNotOwned);
00084   CharString(const char* str, const EnumDataOwned own=DataNotOwned);
00086   CharString(const CharString& array);
00088   CharString& operator=(const CharString& str)
00089         {
00090         if (Data != str.Data) {
00091            free();
00092            construct(str.size(),str.data(),AcquireOwnership);
00093            }
00094         return *this;
00095         }
00096 
00098   size_type size() const
00099         { return Len-1; }
00101   int resize(const size_type);
00102 
00104   int  operator== (const char* array) const;
00106   int  operator!= (const char* array) const;
00108   int  operator== (char* array) const
00109                 {return operator==((const char*)array);}
00111   int  operator!= (char* array) const
00112                 {return operator!=((const char*)array);}
00114   int  operator< (const CharString& array) const;
00116   int  operator> (const CharString& array) const;
00117 
00119   CharString& operator+=(const char* array);
00121   CharString& operator+=(char* array)
00122                 {return operator+=((const char*)array);}
00124   CharString& operator+=(const int val);
00126   CharString& operator+=(const double val);
00127 
00134   CharString& set_subvec(const size_type start, const size_type len,
00135                                 const CharString& datavec, 
00136                                 const size_type offset=0);
00137 
00139   int write(ostream& output) const;
00141   int write(PackBuffer& output) const 
00142                 {return SimpleArray<char>::write(output);}
00149   int read(istream& input);
00151   int read(UnPackBuffer& input);
00152 
00153   friend int compare(const CharString& str1, const CharString& str2);
00154 
00155 protected:
00156 
00158   virtual void construct(const size_type len, char *d, 
00159                                         const EnumDataOwned o=DataNotOwned);
00160 
00161 };
00162 
00163 long int  aslong(const CharString& str, int& status);
00164 
00165 double    asdouble(const CharString& str, int& status);
00166 
00167 #endif