OpendTect-6_4  6.4
separstr.h
Go to the documentation of this file.
1 #ifndef separstr_h
2 #define separstr_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: May 1995
10  Contents: String with a separator between the items
11  RCS: $Id$
12 ________________________________________________________________________
13 
14 -*/
15 
16 #include "basicmod.h"
17 #include "bufstring.h"
18 #include "fixedstring.h"
19 #include "convert.h"
20 
21 class BufferStringSet;
22 
34 {
35 public:
36 
37  SeparString( const char* escapedstr=0, char separ=',' )
38  { initSep( separ ); initRep( escapedstr ); }
39  SeparString( const SeparString& ss )
40  : rep_(ss.rep_) { initSep( ss.sep_[0] ); }
41 
42  SeparString& operator=(const SeparString&);
43  SeparString& operator=(const char* escapedstr);
44 
45  inline bool isEmpty() const { return rep_.isEmpty(); }
46  inline void setEmpty() { rep_.setEmpty(); }
47 
48  int size() const;
49  FixedString operator[](int) const;
50  FixedString from(int) const;
51 
52  int getIValue(int) const;
53  od_uint32 getUIValue(int) const;
54  od_int64 getI64Value(int) const;
55  od_uint64 getUI64Value(int) const;
56  float getFValue(int) const;
57  double getDValue(int) const;
58  bool getYN(int) const;
59 
60  int indexOf(const char* unescapedstr) const;
61 
62  SeparString& add(const BufferStringSet&);
63  SeparString& add(const SeparString&);
64  SeparString& add(const char* unescapedstr);
65  inline SeparString& add( const OD::String& ods )
66  { return add( ods.buf() ); }
67  template <class T>
68  inline SeparString& add( T t )
69  { return add( toString(t) ); }
70 
71  template <class T>
72  inline SeparString& operator +=( T t ) { return add( t ); }
73  template <class T>
74  inline SeparString& operator +=( const OD::String& ods )
75  { return add( ods.buf() ); }
76 
77  inline operator const char*() const
78  { return buf(); }
79 
80  inline char* getCStr() { return rep_.getCStr(); }
82  inline const char* buf() const { return rep_.buf(); }
84  BufferString& rep() { return rep_; }
86  const OD::String& rep() const { return rep_; }
88 
89  inline const char* unescapedStr() const { return getUnescaped(buf()); }
93  inline char sepChar() const { return *sep_; }
94  inline const char* sepStr() const { return sep_; }
95  void setSepChar(char);
96 
97 private:
98 
99  char sep_[2];
101 
102  void initRep(const char*);
103  inline void initSep( char s ) { sep_[0] = s; sep_[1] = '\0'; }
104 
106 
107  const char* getEscaped(const char* unescapedstr,char sep) const;
108  const char* getUnescaped(const char* escapedstartptr,
109  const char* nextsep=0) const;
110 
111  const char* findSeparator(const char*) const;
112 };
113 
114 
120 {
121 public:
122 
123  FileMultiString(const char* escapedstr=0)
124  : SeparString(escapedstr, separator() ) {}
125  template <class T> FileMultiString( const T& t )
126  : SeparString(t,separator()) {}
127 
128  static char separator() { return '`'; }
129 
130  // The function template overloading add(const SeparString&) in the base
131  // class needs an exact match! Passing a derived object would make the
132  // template function convert it to (const char*).
133  inline FileMultiString& add( const FileMultiString& fms )
134  { return add( (SeparString&)fms ); }
135  template <class T> inline
136  FileMultiString& operator +=( T t ) { return add( t ); }
137  inline FileMultiString& operator +=( const OD::String& ods )
138  { return add( ods.buf() ); }
139 
140  template <class T> inline
142  { SeparString::add( t ); return *this; }
143  inline FileMultiString& add( const OD::String& ods )
144  { return add( ods.buf() ); }
145 
146 };
147 
148 #endif
#define mExpClass(module)
Definition: commondefs.h:160
FileMultiString(const T &t)
Definition: separstr.h:125
char sep_[2]
Definition: separstr.h:99
BufferString rep_
Definition: separstr.h:100
virtual BufferString * operator[](size_type)
const OD::String & rep() const
Output escaped.
Definition: separstr.h:86
OD::String that holds an existing text string.
Definition: fixedstring.h:29
#define od_int64
Definition: plftypes.h:36
ObjectSet< BufferString > & operator+=(BufferString *t)
Definition: objectset.h:71
SeparString & add(const BufferStringSet &)
Concatenation.
List encoded in a string.
Definition: separstr.h:33
Set of BufferString objects.
Definition: bufstringset.h:28
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:169
FileMultiString(const char *escapedstr=0)
Definition: separstr.h:123
SeparString(const char *escapedstr=0, char separ=',')
Definition: separstr.h:37
size_type size() const
Definition: objectset.h:50
SeparString with backquotes as separators, use in most ascii files.
Definition: separstr.h:119
SeparString & add(T t)
Definition: separstr.h:68
static char separator()
Definition: separstr.h:128
char sepChar() const
Definition: separstr.h:93
#define od_uint32
Definition: plftypes.h:32
BufferString retstr_
Definition: separstr.h:105
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
char * getCStr()
Output escaped.
Definition: separstr.h:80
BufferStringSet & add(const char *)
FileMultiString & add(const FileMultiString &fms)
Definition: separstr.h:133
SeparString & add(const OD::String &ods)
Definition: separstr.h:65
const char * buf() const
Definition: odstring.h:47
const char * unescapedStr() const
Definition: separstr.h:89
const char * sepStr() const
Definition: separstr.h:94
#define od_uint64
Definition: plftypes.h:37
bool isEmpty() const
Definition: separstr.h:45
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
FileMultiString & add(T t)
Definition: separstr.h:141
const char * buf() const
Output escaped.
Definition: separstr.h:82
void setEmpty()
Definition: separstr.h:46
void initSep(char s)
Definition: separstr.h:103
FileMultiString & add(const OD::String &ods)
Definition: separstr.h:143
ManagedObjectSet< BufferString > & operator=(const ObjectSet< BufferString > &)
Export_Basic const char * toString(ViewStyle)
BufferString & rep()
Output escaped.
Definition: separstr.h:84
SeparString(const SeparString &ss)
Definition: separstr.h:39

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