OpendTect  6.6
fixedstring.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: Kristofer
7  Date: April 2009
8  RCS: $Id$
9 ________________________________________________________________________
10 
11 */
12 
13 #include "basicmod.h"
14 #include "odstring.h"
15 
16 
17 
29 {
30 public:
31 
32  inline FixedString( const char* p = nullptr )
33  : str_(p) {}
34  inline FixedString& operator=( const FixedString& fs )
35  { str_ = fs.str_; return *this;}
36  inline FixedString& operator=( const char* p )
37  { str_ = p; return *this; }
38  FixedString& operator=(const OD::String&);
40  inline operator const char*() const { return buf(); }
41 
42  inline bool operator==( const FixedString& fs ) const
43  { return isEqual(fs.str_);}
44  inline bool operator!=( const FixedString& fs ) const
45  { return !isEqual(fs.str_);}
46  inline bool operator==( const char* s ) const
47  { return isEqual(s);}
48  inline bool operator!=( const char* s ) const
49  { return !isEqual(s);}
50  inline bool operator==( const OD::String& s ) const
51  { return isEqual(s.str()); }
52  inline bool operator!=( const OD::String& s ) const
53  { return !isEqual(s.str()); }
54  bool operator==(const BufferString&) const;
55  bool operator!=(const BufferString&) const;
56 
57  inline operator bool() const { return !isNull(); }
58  inline bool operator !() const { return isNull(); }
59  inline bool isNull() const { return !str_; }
60  inline char firstChar() const { return str_ ? *str_ : '\0'; }
61 
62  static const FixedString& empty();
63 
64 
65 protected:
66 
67  inline const char* gtBuf() const
68  { return str_ ? str_ : ""; }
69  inline const char* gtStr() const
70  { return !str_ || !*str_ ? nullptr : str_; }
71 
72  const char* str_;
73 
74 };
75 
76 
77 namespace Values
78 {
79 
80 template<>
82 {
83 public:
84 
85  static FixedString val() { return FixedString();}
86  static bool hasUdf() { return true; }
87  static bool isUdf( const FixedString& s ) { return s.isEmpty(); }
88  static void setUdf( FixedString& s ) { s = FixedString(); }
89 
90 };
91 
92 }
93 
94 
95 #ifndef __win__
96 
97 // Avoid silent conversion general OD::String -> FixedString as it is dangerous.
100 { OD_Undef_FixedString_eq_bs_finder(); return *this; }
101 
102 #endif
103 
104 
FixedString::operator==
bool operator==(const BufferString &) const
FixedString::operator!=
bool operator!=(const char *s) const
Definition: fixedstring.h:48
FixedString::isNull
bool isNull() const
Definition: fixedstring.h:59
Values::Undef< FixedString >::setUdf
static void setUdf(FixedString &s)
Definition: fixedstring.h:88
FixedString::gtStr
const char * gtStr() const
Definition: fixedstring.h:69
Values::Undef< FixedString >::val
static FixedString val()
Definition: fixedstring.h:85
FixedString::empty
static const FixedString & empty()
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
FixedString::str_
const char * str_
Definition: fixedstring.h:72
FixedString::firstChar
char firstChar() const
Definition: fixedstring.h:60
FixedString::operator!=
bool operator!=(const FixedString &fs) const
Definition: fixedstring.h:44
Values::Undef< FixedString >::hasUdf
static bool hasUdf()
Definition: fixedstring.h:86
OD::String::str
const char * str() const
Definition: odstring.h:47
mClass
#define mClass(module)
Definition: commondefs.h:181
FixedString::operator!=
bool operator!=(const BufferString &) const
FixedString::operator==
bool operator==(const OD::String &s) const
Definition: fixedstring.h:50
OD::String::isEmpty
bool isEmpty() const
Definition: odstring.h:50
FixedString
OD::String that holds an existing text string.
Definition: fixedstring.h:29
OD_Undef_FixedString_eq_bs_finder
void OD_Undef_FixedString_eq_bs_finder()
Values::Undef< FixedString >::isUdf
static bool isUdf(const FixedString &s)
Definition: fixedstring.h:87
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
FixedString::operator==
bool operator==(const char *s) const
Definition: fixedstring.h:46
FixedString::operator=
FixedString & operator=(const FixedString &fs)
Definition: fixedstring.h:34
OD::String
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
FixedString::operator!=
bool operator!=(const OD::String &s) const
Definition: fixedstring.h:52
Values::Undef< FixedString >
Definition: fixedstring.h:82
odstring.h
Values
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:113
FixedString::FixedString
FixedString(const char *p=nullptr)
Definition: fixedstring.h:32
FixedString::operator==
bool operator==(const FixedString &fs) const
Definition: fixedstring.h:42
FixedString::operator=
FixedString & operator=(const char *p)
Definition: fixedstring.h:36
FixedString::gtBuf
const char * gtBuf() const
Definition: fixedstring.h:67

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