OpendTect-6_4  6.4
uistring.h
Go to the documentation of this file.
1 #ifndef uistring_h
2 #define uistring_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: Jan 2014
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "gendefs.h"
16 #include "keystrs.h"
17 #include "threadlock.h"
18 #include "string2.h"
19 #include "typeset.h"
20 
21 class uiStringData;
22 
23 mFDQtclass( QString );
24 mFDQtclass( QStringList );
25 mFDQtclass( QTranslator );
26 
27 
28 #define mTextTranslationClass(clss,application) \
29 private: \
30  static inline uiString tr( const char* text, const char* disambiguation = 0, \
31  int pluralnr=-1 ) \
32  { return uiString( text, #clss, application, disambiguation, pluralnr ); } \
33  static inline uiString legacyTr( const char* text, \
34  const char* disambiguation = 0, \
35  int pluralnr=-1 ) \
36  { return uiString( text, #clss, application, disambiguation, pluralnr ); }
37 
38 #define mODTextTranslationClass(clss) \
39 mTextTranslationClass( clss, uiString::sODLocalizationApplication() )
40 
41 
91 public:
92  uiString();
93  uiString(const uiString&);
94  ~uiString();
95 
96  uiString& set(const char*);
97  bool isSet() const { return !isEmpty(); }
98  bool isEmpty() const;
99  void setEmpty();
100  uiString& toLower(bool yn=true);
103  bool operator!() const { return isEmpty(); }
104 
105  uiString& operator=(const uiString&);
106  bool operator>(const uiString& b) const;
107  bool operator<(const uiString& b) const;
108  int size() const;
109  static const uiString& emptyString() { return emptystring_; }
110 
111 
114  template <class T>
115  uiString& arg(const T& var);
116  uiString& arg(const uiString&);
117 
122  uiString& append(const char*, bool withnewline=false);
123  uiString& append(const OD::String&, bool withnewline=false);
124  uiString& append(const uiString&, bool withnewline=false);
125 
126 
128  const OD::String& getFullString(BufferString* = 0) const;
134  wchar_t* createWCharString() const;
137  const char* getOriginalString() const;
138  const mQtclass(QString)& getQString() const;
140  const mQtclass(QString)& fillQString(QString&) const;
143  void getHexEncoded(BufferString&) const;
146  bool setFromHexEncoded(const char*);
148 private:
149 
150 #ifdef __debug__
151  char* debugstr_;
152 #endif
153  bool isCacheValid() const;
154  const mQtclass(QString)& getQStringInternal() const;
155 
156  friend class uiStringData;
157  mutable uiStringData* data_;
159  static const uiString emptystring_;
160 
161 public:
162 
163  //Only for expert users
164 #ifdef mNoAutoUiString
165  mDeprecated uiString(const char* inp);
166  mDeprecated uiString(const OD::String&);
167  mDeprecated uiString& operator=(const char*);
168  mDeprecated uiString& operator=(const OD::String&);
169 #else
170  uiString(const char*);
171  uiString(const OD::String&);
172  uiString& operator=(const char*);
173  uiString& operator=(const OD::String&);
174 #endif
175 
178  bool operator==(const uiString& b) const;
180  bool operator!=(const uiString& b) const { return !(*this==b); }
182  bool isEqualTo(const uiString& oth) const;
184 
185  static const char* sODLocalizationApplication() { return "od"; }
186 
187  void makeIndependent();
189  uiString(const char* original,
190  const char* context,
191  const char* application,
192  const char* disambiguation,
193  int pluralnr);
194  void setFrom(const mQtclass(QString)&);
197  void addLegacyVersion(const uiString&);
207  bool translate(const mQtclass(QTranslator)&,
208  mQtclass(QString)&) const;
210 
211  static uiString getOrderString(int);
212  //Returns 1st, 2nd, 3rd
213 
214  uiString& addSpace(int nr=1);
215 };
216 
217 
220 public:
222  uiStringSet( const uiString* );
225  : TypeSet<uiString>(sl) {}
226  uiStringSet( const uiString& s ) { add( s ); }
227 
228  uiString createOptionString(bool use_and=true,int maxnritems=-1,
229  char space = ' ') const;
231  void fill(mQtclass(QStringList)&) const;
232  uiString cat(const char* sepstr="\n") const;
233 };
234 
235 
236 /*\brief allows returning status and accompanying user info.
237 
238  This class helps us make sure there is always user info on errors. Therefore,
239  you will find a 'setIsOK' but not OK means setting a non-empty message.
240 
241 */
242 
244 {
245 public:
246 
247  uiRetVal() {}
248  uiRetVal(const uiString&);
249  uiRetVal(const uiStringSet&);
250  uiRetVal(const uiRetVal&);
251  static uiRetVal OK() { return ok_; }
252  uiRetVal& operator =(const uiRetVal&);
253  uiRetVal& operator =(const uiString&);
254  uiRetVal& operator =(const uiStringSet&);
255  operator uiString() const;
256 
257  bool isOK() const;
258  inline bool isError() const { return !isOK(); }
259  bool isMultiMessage() const;
260  uiStringSet messages() const;
261  bool isSingleWord(const uiString&) const;
262 
263  uiRetVal& setOK();
264  uiRetVal& set(const uiRetVal&);
265  uiRetVal& set(const uiString&);
266  uiRetVal& set(const uiStringSet&);
267  uiRetVal& add(const uiRetVal&);
268  uiRetVal& add(const uiString&);
269  uiRetVal& add(const uiStringSet&);
270  void resetError() { msgs_.setEmpty(); }
271 
272  BufferString getText() const;
273 
274 private:
275 
278 
279  static const uiRetVal ok_;
280 
281 };
282 
283 mGlobal(Basic) bool isFinished(const uiRetVal&);
284 mGlobal(Basic) bool isCancelled(const uiRetVal&);
285 
286 
287 mGlobal(Basic) uiString toUiString(const uiString&);
288 mGlobal(Basic) uiString toUiString(const char*);
289 mGlobal(Basic) uiString toUiString(const OD::String&);
290 mGlobal(Basic) uiString toUiString(od_int32);
291 mGlobal(Basic) uiString toUiString(od_int64);
292 mGlobal(Basic) uiString toUiString(od_uint32);
293 mGlobal(Basic) uiString toUiString(od_uint64);
294 mGlobal(Basic) uiString toUiString(float);
295 mGlobal(Basic) uiString toUiString(double);
296 mGlobal(Basic) uiString toUiString(float,int nrdec);
297 mGlobal(Basic) uiString toUiString(double,int nrdec);
298 mGlobal(Basic) uiString toUiString(float,char format,int precision);
299 mGlobal(Basic) uiString toUiString(double,char format,int precision);
300 
301 
302 //User when string should be revisited later
303 #define mToUiStringTodo(i) ::toUiString(i)
304 #define mFromUiStringTodo(i) i.getFullString()
305 
306 
307 //Legacy Will be removed
308 mGlobal(Basic) mDeprecated inline uiString mkUiString(const char* var)
309 { return toUiString(var); }
310 
330 mGlobal(Basic) uiString od_static_tr( const char* function, const char* text,
331  const char* disambiguation = 0, int pluralnr=-1 );
332 mGlobal(Basic) uiString getUiYesNoString(bool res);
333 
334 template <class T> inline
335 uiString& uiString::arg( const T& var )
336 {
337  return arg( toUiString(var) );
338 }
339 
340 
341 
342 
343 #endif
bool operator!() const
Definition: uistring.h:103
#define mExpClass(module)
Definition: commondefs.h:160
bool operator!=(const uiString &b) const
Don&#39;t use, will force crash. Only here to keep TypeSet happy.
Definition: uistring.h:180
#define mQtclass(cls)
Definition: commondefs.h:229
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
bool isError() const
Definition: uistring.h:258
uiString getUiYesNoString(bool res)
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
Threads::Lock lock_
Definition: uistring.h:277
#define mGlobal(module)
Definition: commondefs.h:163
static uiRetVal OK()
Definition: uistring.h:251
#define od_int64
Definition: plftypes.h:36
static const uiRetVal ok_
Definition: uistring.h:279
uiRetVal()
Definition: uistring.h:247
uiStringData * data_
Definition: uistring.h:157
uiStringSet msgs_
Definition: uistring.h:276
static const uiString & emptyString()
Definition: uistring.h:109
Definition: uistring.h:89
uiString mkUiString(const char *var)
Definition: uistring.h:308
Threads::Lock datalock_
Protects data_ variable.
Definition: uistring.h:158
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:198
bool isCancelled(const uiRetVal &)
Set of (small) copyable elements.
Definition: commontypes.h:30
uiStringSet(const uiString &s)
Definition: uistring.h:226
#define od_uint32
Definition: plftypes.h:32
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
#define mFDQtclass(cls)
Definition: commondefs.h:228
uiStringSet(const uiStringSet &sl)
Definition: uistring.h:224
uiString toUiString(const uiString &)
uiStringSet()
Definition: uistring.h:221
bool isSet() const
Definition: uistring.h:97
uiString & arg(const T &var)
Definition: uistring.h:335
#define od_uint64
Definition: plftypes.h:37
#define od_int32
Definition: plftypes.h:31
#define mDeprecated
Definition: plfdefs.h:233
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Definition: uistring.h:243
void resetError()
Definition: uistring.h:270
OpendTect.
Definition: commontypes.h:29
Definition: uistring.h:218
bool isEmpty(const NLAModel *mdl)
bool isFinished(const uiRetVal &)
uiString od_static_tr(const char *function, const char *text, const char *disambiguation=0, int pluralnr=-1)
static const char * sODLocalizationApplication()
Definition: uistring.h:185
static const uiString emptystring_
Definition: uistring.h:159

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