OpendTect-6_4  6.4
bufstring.h
Go to the documentation of this file.
1 #ifndef bufstring_h
2 #define bufstring_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: 12-4-2000
10  Contents: Variable buffer length strings with minimum size.
11  RCS: $Id$
12 ________________________________________________________________________
13 
14 -*/
15 
16 #include "basicmod.h"
17 #include "fixedstring.h"
18 #include "string2.h"
19 class QString;
20 
40 mExpClass(Basic) BufferString : public OD::String
41 {
42 public:
43 
44  inline BufferString();
45  inline BufferString(const char*);
46  BufferString(const OD::String&);
47  BufferString(int minlen,bool setnull);
48  BufferString(const BufferString&);
49  template <class T>
50  inline BufferString(const char*,const T&,const char* s=0);
51  BufferString(const QString&);
52  virtual ~BufferString();
53  inline BufferString& operator=( const BufferString& b )
54  { return assignTo(b.buf_); }
55  inline BufferString& operator=( const char* s )
56  { return assignTo(s); }
57  inline BufferString& operator=( const FixedString& s )
58  { return assignTo(s.str()); }
59  inline BufferString& operator=( const OD::String& s )
60  { return assignTo(s.str()); }
61  template <class T>
62  inline BufferString& operator=(const T&);
63 
64  inline operator const char*() const { return buf(); }
65 
66  inline bool operator==(const BufferString&) const;
67  inline bool operator!=(const BufferString&) const;
68  inline bool operator==(const char*) const;
69  inline bool operator!=(const char*) const;
70  inline bool operator==(const OD::String&) const;
71  inline bool operator!=(const OD::String&) const;
72  inline bool operator==(const FixedString&) const;
73  inline bool operator!=(const FixedString&) const;
74 
75  inline char* getCStr()
76  { return const_cast<char*>(const_cast<BufferString*>(this)->gtBuf()); }
77  void fill(char*,int maxnrchar) const;
79 
80  inline char& operator []( int idx ) { return getCStr()[idx]; }
81  char* find(char);
82  char* find(const char*);
83  inline const char* find(char) const;
84  inline const char* find(const char*) const;
85  char* findLast(char);
86  char* findLast(const char*);
87  inline const char* findLast(char) const;
88  inline const char* findLast(const char*) const;
89 
90  BufferString& setEmpty();
91  BufferString& set(const char*);
92  BufferString& set( const OD::String& s ) { return set(s.str()); }
93  template <class T>
94  BufferString& set(const T&);
95  BufferString& set(float,int nrdec);
96  BufferString& set(double,int nrdec);
97  BufferString& setLim(float,int maxnrchars);
98  BufferString& setLim(double,int maxnrchars);
99 
100  BufferString& add(char);
101  BufferString& add(const char*);
102  BufferString& add( const OD::String& s ) { return add(s.str()); }
103  BufferString& add(const QString&);
104  template <class T>
105  BufferString& add(const T&);
106  BufferString& add(float,int nrdec);
107  BufferString& add(double,int nrdec);
108  BufferString& addLim(float,int maxnrchars);
109  BufferString& addLim(double,int maxnrchars);
110 
111  BufferString& addSpace(int nrspaces=1);
112  BufferString& addTab(int nrtabs=1);
113  BufferString& addNewLine(int nrnewlines=1);
114 
115  inline unsigned int bufSize() const { return len_; }
116  bool setBufSize(unsigned int);
117  inline unsigned int minBufSize() const { return minlen_; }
118  void setMinBufSize(unsigned int);
119 
120  BufferString& replace(char from,char to);
121  BufferString& replace(const char* from,const char* to);
122  BufferString& remove(char);
123  inline BufferString& remove( const char* s ) { return replace(s,0); }
124  BufferString& trimBlanks();
125 
126  BufferString& insertAt(int idx, const char*);
127  //< If idx >= size(), pads spaces
128  BufferString& replaceAt(int idx, const char*,bool cutoff=true);
129  //< If idx >= size(), pads spaces
130  BufferString& toLower();
131  BufferString& toUpper();
132  BufferString& embed(char open,char close);
133  BufferString& unEmbed(char open,char close);
134  inline BufferString& quote( char q='\'' ) { return embed(q,q); }
135  inline BufferString& unQuote( char q='\'' ) { return unEmbed(q,q); }
136 
137  enum CleanType { OnlyAlphaNum, AllowDots,
138  NoSpaces, NoFileSeps, NoSpecialChars };
139  BufferString& clean(CleanType ct=OnlyAlphaNum);
140 
141  static const BufferString& empty();
142 
143 protected:
144 
145  char* buf_;
146  unsigned int len_;
147  const unsigned int minlen_;
148 
149  BufferString& assignTo(const char*);
150 
151  const char* gtBuf() const;
152  inline const char* gtStr() const;
153 
154 private:
155 
156  void init();
157  inline void destroy() { delete [] buf_; buf_ = 0; }
158  BufferString& addArr32Chars(const char*,int);
159 
160 public:
161 
162  // use add instead
163  inline BufferString& operator+=( const char* s ) { return add( s ); }
164  inline BufferString& operator+=( const OD::String& s )
165  { return add(s.str()); }
166  template <class T>
167  inline BufferString& operator+=( const T& t ) { return add( t ); }
168 
169 };
170 
171 
172 #ifndef __win__
173 
174 // Avoid silent conversion to BufferString from any type.
175 
178 inline bool operator==(const char*,const BufferString&)
179 { OD_Undef_const_char_eq_bs_finder(); return false; }
180 inline bool operator!=(const char*,const BufferString&)
181 { OD_Undef_const_char_neq_bs_finder(); return true; }
182 
183 #endif
184 
185 
186 #define mBufferStringSimpConstrInitList \
187  minlen_(mMaxFilePathLength+1), buf_(0), len_(0)
188 
191 inline BufferString::BufferString( const char* s )
195 
196 template <class T> inline
197 BufferString::BufferString( const char* s1, const T& t, const char* s2 )
199 { *this += s1; *this += t; *this += s2; }
200 
201 inline const char* BufferString::gtStr() const
202 { return buf_ && *buf_ ? const_cast<char*>( buf_ ) : 0; }
203 
204 inline bool BufferString::operator==( const BufferString& s ) const
205 { return isEqual( s.buf_ ); }
206 inline bool BufferString::operator!=( const BufferString& s ) const
207 { return !isEqual( s.buf_ ); }
208 inline bool BufferString::operator==( const char* s ) const
209 { return isEqual( s ); }
210 inline bool BufferString::operator!=( const char* s ) const
211 { return !isEqual( s ); }
212 inline bool BufferString::operator==( const FixedString& s ) const
213 { return isEqual( s.str() ); }
214 inline bool BufferString::operator!=( const FixedString& s ) const
215 { return !isEqual( s.str() ); }
216 inline bool BufferString::operator==( const OD::String& s ) const
217 { return isEqual( s.str() ); }
218 inline bool BufferString::operator!=( const OD::String& s ) const
219 { return !isEqual( s.str() ); }
220 
221 inline const char* BufferString::find( char c ) const
222 { return OD::String::find( c ); }
223 inline const char* BufferString::find( const char* s ) const
224 { return OD::String::find( s ); }
225 inline const char* BufferString::findLast( char c ) const
226 { return OD::String::findLast( c ); }
227 inline const char* BufferString::findLast( const char* s ) const
228 { return OD::String::findLast( s ); }
229 
230 template <class T> inline BufferString& BufferString::operator=( const T& t )
231 { return set( t ); }
232 
233 template <class T> inline BufferString& BufferString::add( const T& t )
234 { return add( toString(t) ); }
235 
236 inline BufferString& BufferString::set( const char* s )
237 { setEmpty(); return add( s ); }
238 
239 template <class T> inline BufferString& BufferString::set( const T& t )
240 { setEmpty(); return add( t ); }
241 
242 inline BufferString& BufferString::set( float f, int nrdec )
243 { setEmpty(); return add( f, nrdec ); }
244 
245 inline BufferString& BufferString::set( double d, int nrdec )
246 { setEmpty(); return add( d, nrdec ); }
247 
248 inline BufferString& BufferString::setLim( float f, int maxnrchars )
249 { setEmpty(); return addLim( f, maxnrchars ); }
250 
251 inline BufferString& BufferString::setLim( double d, int maxnrchars )
252 { setEmpty(); return addLim( d, maxnrchars ); }
253 
254 
255 #endif
const char * find(char) const
bool operator==(const BufferString &) const
Definition: bufstring.h:204
#define mExpClass(module)
Definition: commondefs.h:160
BufferString & quote(char q='\'')
Definition: bufstring.h:134
CleanType
Definition: bufstring.h:137
const char * str() const
Definition: odstring.h:48
BufferString & operator=(const FixedString &s)
Definition: bufstring.h:57
T to(const F &fr)
Definition: convert.h:33
BufferString & operator=(const BufferString &b)
Definition: bufstring.h:53
void OD_Undef_const_char_eq_bs_finder()
char * findLast(char)
OD::String that holds an existing text string.
Definition: fixedstring.h:29
BufferString & operator+=(const T &t)
Definition: bufstring.h:167
const char * gtStr() const
Definition: bufstring.h:201
bool init()
BufferString & setEmpty()
Definition: bufstring.h:137
BufferString & operator=(const OD::String &s)
Definition: bufstring.h:59
bool operator!=(const char *, const BufferString &)
Definition: bufstring.h:180
BufferString & add(const OD::String &s)
Definition: bufstring.h:102
BufferString & operator+=(const char *s)
Definition: bufstring.h:163
BufferString & addLim(float, int maxnrchars)
unsigned int len_
Definition: bufstring.h:146
bool operator==(const char *, const BufferString &)
Definition: bufstring.h:178
bool isEqual(const char *, CaseSensitivity c=CaseSensitive) const
unsigned int bufSize() const
Definition: bufstring.h:115
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
BufferString & assignTo(const char *)
unsigned int minBufSize() const
Definition: bufstring.h:117
bool operator!=(const BufferString &) const
Definition: bufstring.h:206
char * buf_
Definition: bufstring.h:145
BufferString & set(const char *)
Definition: bufstring.h:236
BufferString & unQuote(char q='\'')
Definition: bufstring.h:135
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
const char * findLast(char) const
char * find(char)
BufferString & setLim(float, int maxnrchars)
Definition: bufstring.h:248
OpendTect.
Definition: commontypes.h:29
BufferString & operator=(const char *s)
Definition: bufstring.h:55
BufferString & add(char)
BufferString()
Definition: bufstring.h:189
BufferString & operator+=(const OD::String &s)
Definition: bufstring.h:164
#define mBufferStringSimpConstrInitList
Definition: bufstring.h:186
void OD_Undef_const_char_neq_bs_finder()
char * getCStr()
Definition: bufstring.h:75
Export_Basic const char * toString(ViewStyle)
const unsigned int minlen_
Definition: bufstring.h:147
void destroy()
Definition: bufstring.h:157

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019