00001 #ifndef separstr_h 00002 #define separstr_h 00003 00004 /*+ 00005 ________________________________________________________________________ 00006 00007 (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt 00008 Author: A.H.Bril 00009 Date: May 1995 00010 Contents: String with a separator between the items 00011 RCS: $Id: separstr.h,v 1.25 2010-10-14 08:39:58 cvsbert Exp $ 00012 ________________________________________________________________________ 00013 00014 -*/ 00015 00016 #include "bufstring.h" 00017 #include "convert.h" 00018 00019 class BufferStringSet; 00020 00021 00032 mClass SeparString 00033 { 00034 public: 00035 SeparString( const SeparString& ss ) 00036 : rep_(ss.rep_) { initSep( ss.sep_[0] ); } 00037 00038 SeparString( const char* escapedstr=0, char separ=',' ) 00039 { initSep( separ ); initRep( escapedstr ); } 00040 00041 SeparString& operator=(const SeparString&); 00042 SeparString& operator=(const char* escapedstr); 00043 00044 inline bool isEmpty() const { return rep_.isEmpty(); } 00045 inline void setEmpty() { rep_.setEmpty(); } 00046 00047 int size() const; 00048 const char* operator[](int) const; 00049 const char* from(int) const; 00050 00051 int getIValue(int) const; 00052 od_uint32 getUIValue(int) const; 00053 od_int64 getI64Value(int) const; 00054 od_uint64 getUI64Value(int) const; 00055 float getFValue(int) const; 00056 double getDValue(int) const; 00057 bool getYN(int) const; 00058 00059 int indexOf(const char* unescapedstr) const; 00060 00061 SeparString& add(const BufferStringSet&); 00062 SeparString& add(const SeparString&); 00063 SeparString& add(const char* unescapedstr); 00064 template <class T> 00065 SeparString& add( T t ) 00066 { return add( Conv::to<const char*>(t) ); } 00067 00068 template <class T> 00069 SeparString& operator +=( T t ) { return add( t ); } 00070 00071 inline operator const char*() const 00072 { return buf(); } 00073 00074 inline char* buf() { return rep_.buf(); } 00076 inline const char* buf() const { return rep_.buf(); } 00078 BufferString& rep() { return rep_; } 00080 const BufferString& rep() const { return rep_; } 00082 00083 inline const char* unescapedStr() const { return getUnescaped(buf()); } 00087 inline char sepChar() const { return *sep_; } 00088 void setSepChar(char); 00089 00090 private: 00091 00092 char sep_[2]; 00093 BufferString rep_; 00094 00095 void initRep(const char*); 00096 inline void initSep( char s ) { sep_[0] = s; sep_[1] = '\0'; } 00097 00098 mutable BufferString retstr_; 00099 00100 const char* getEscaped(const char* unescapedstr,char sep) const; 00101 const char* getUnescaped(const char* escapedstartptr, 00102 const char* nextsep=0) const; 00103 00104 const char* findSeparator(const char*) const; 00105 }; 00106 00107 mGlobal std::ostream& operator <<(std::ostream&,const SeparString&); 00108 mGlobal std::istream& operator >>(std::istream&,SeparString&); 00109 00110 00111 00114 mClass FileMultiString : public SeparString 00115 { 00116 public: 00117 00118 FileMultiString(const char* escapedstr=0) 00119 : SeparString(escapedstr, separator() ) {} 00120 template <class T> FileMultiString( T t ) 00121 : SeparString(t, separator() ) {} 00122 00123 static char separator() { return '`'; } 00124 static const char* separatorStr(); 00125 00126 // The function template overloading add(const SeparString&) in the base 00127 // class needs an exact match! Passing a derived object would make the 00128 // template function convert it to (const char*). 00129 FileMultiString& add(const FileMultiString& fms) 00130 { return add( (SeparString&)fms ); } 00131 template <class T> 00132 FileMultiString& add( T t ) 00133 { SeparString::add( t ); return *this; } 00134 template <class T> 00135 FileMultiString& operator +=( T t ) { return add( t ); } 00136 00137 }; 00138 00139 #endif
1.7.1