OpendTect-6_4  6.4
odstring.h
Go to the documentation of this file.
1 #ifndef odstring_h
2 #define odstring_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Dec 2013
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "gendefs.h"
17 
18 
19 namespace OD
20 {
21 
22 
32 {
33 public:
34 
35 
36  virtual ~String() {}
37 
38  inline bool operator==(const String&) const;
39  inline bool operator!=(const String&) const;
40  inline bool operator==(const char*) const;
41  inline bool operator!=(const char*) const;
42  template <class T>
43  inline bool operator==(const T&) const;
44  template <class T>
45  inline bool operator!=( const T& t ) const { return !(*this==t); }
46 
47  inline const char* buf() const { return gtBuf(); }
48  inline const char* str() const { return gtStr(); }
49  inline operator const char*() const { return gtBuf(); }
50  unsigned int size() const;
51  inline bool isEmpty() const { return !gtStr(); }
52  inline const char& operator []( int idx ) const { return gtBuf()[idx]; }
53  virtual char firstChar() const { return gtBuf()[0]; }
54 
55 # define mODStringDefSens CaseSensitivity c=CaseSensitive
56  bool isEqual(const char*,mODStringDefSens) const;
57  bool isStartOf(const char*,mODStringDefSens) const;
58  bool startsWith(const char*,mODStringDefSens) const;
59  bool isEndOf(const char*,mODStringDefSens) const;
60  bool endsWith(const char*,mODStringDefSens) const;
61  bool matches(const char*,mODStringDefSens) const;
62 
63  bool contains(char) const;
64  bool contains(const char*) const;
65  const char* find(char) const;
66  const char* findLast(char) const;
67  const char* find(const char*) const;
68  const char* findLast(const char*) const;
69 
70  unsigned int count(char) const;
71  unsigned int getLevenshteinDist(const char*,bool casesens) const;
72 
73  bool isNumber(bool int_only=false) const;
74  bool isYesNo() const;
75  int toInt() const;
76  float toFloat() const;
77  double toDouble() const;
78  bool toBool() const;
79 
80  bool operator >(const char*) const;
81  bool operator <(const char*) const;
82  template <class T>
83  inline bool operator >(const T&) const;
84  template <class T>
85  inline bool operator <(const T&) const;
86 
87  static const String& empty();
88 
89 protected:
90 
91  virtual const char* gtBuf() const = 0;
93  virtual const char* gtStr() const = 0;
95 
96 };
97 
98 
99 
100 inline bool String::operator==( const String& s ) const
101 { return isEqual( s.str() ); }
102 inline bool String::operator!=( const String& s ) const
103 { return !isEqual( s.str() ); }
104 
105 inline bool String::operator==( const char* s ) const
106 { return isEqual( s ); }
107 inline bool String::operator!=( const char* s ) const
108 { return !isEqual( s ); }
109 
110 template <class T> inline bool String::operator==( const T& t ) const
111 { return isEqual( toString(t) ); }
112 
113 template <class T> inline bool String::operator >( const T& t ) const
114 { return *this > ( toString( t ) ); }
115 
116 template <class T> inline bool String::operator <( const T& t ) const
117 { return *this < ( toString( t ) ); }
118 
119 
120 } // namespace OD
121 
122 
123 #endif
#define mExpClass(module)
Definition: commondefs.h:160
int toInt(const char *s, int defval=0)
Definition: string2.h:73
float toFloat(const char *s, float defval=0)
Definition: string2.h:67
const char * str() const
Definition: odstring.h:48
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
virtual ~String()
Definition: odstring.h:36
#define mODStringDefSens
Definition: odstring.h:55
double toDouble(const char *s, double defval=0)
Definition: string2.h:70
bool operator<(const char *) const
bool isEqual(const char *, CaseSensitivity c=CaseSensitive) const
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
bool operator>(const char *) const
bool operator==(const String &) const
Definition: odstring.h:100
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
virtual char firstChar() const
Definition: odstring.h:53
const char * buf() const
Definition: odstring.h:47
bool operator!=(const T &t) const
Definition: odstring.h:45
bool isEmpty() const
Definition: odstring.h:51
OpendTect.
Definition: commontypes.h:29
Export_Basic const char * toString(PythonSource)
bool operator!=(const String &) const
Definition: odstring.h:102
bool toBool(const char *s, bool defval=true)
Definition: string2.h:64

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