OpendTect  6.6
iopar.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Bril
8  Date: 21-12-1995
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "basicmod.h"
15 #include "namedobj.h"
16 #include "fixedstring.h"
17 #include "dbkey.h"
18 #include "samplingdata.h"
19 #include "od_iosfwd.h"
20 
21 class BufferStringSet;
22 class SeparString;
23 class ascistream;
24 class ascostream;
25 class uiString;
26 namespace OD
27 {
28  namespace JSON
29  {
30  class Object;
31  };
32 };
33 
54 mExpClass(Basic) IOPar : public NamedObject
55 {
56 public:
57  IOPar(const char* nm=nullptr);
59  IOPar(const IOPar&);
60  ~IOPar();
61  IOPar& operator =(const IOPar&);
62  inline bool operator ==( const IOPar& iop ) const
63  { return isEqual(iop); }
64  inline bool operator !=( const IOPar& iop ) const
65  { return !isEqual(iop); }
66 
67  int size() const;
68  int indexOf(const char* key) const;
69  inline bool isPresent( const char* ky ) const
70  { return indexOf(ky) >= 0; }
71 
72  inline bool isEmpty() const { return size() == 0; }
73  bool isEqual(const IOPar&,bool need_same_order=false) const;
74  bool includes(const IOPar&) const;
75  FixedString getKey(int) const;
76  FixedString getValue(int) const;
77  bool setKey(int,const char*);
78  void setValue(int,const char*);
79  int maxContentSize(bool keys_else_values) const;
80 
81  inline bool hasKey( const char* s ) const { return isPresent(s); }
82  const char* findKeyFor(const char*,int nr=0) const;
86 
87  void remove(int);
88  void removeWithKey(const char* key);
89  void removeWithKeyPattern(const char* globexpression);
92 
93  void setEmpty();
95  void merge(const IOPar&);
97  void addFrom(const IOPar&);
99  static const char* compKey(const char*,const char*);
101  static const char* compKey(const char*,int);
103  static const char* compKey( const char* ky1, const OD::String& ky2 )
104  { return compKey(ky1,ky2.str()); }
105  IOPar* subselect(const char*) const;
107  IOPar* subselect(int) const;
109  IOPar* subselect( const OD::String& fs ) const
110  { return subselect( fs.str() ); }
111  void removeSubSelection(const char*);
115  void removeSubSelection( const OD::String& fs )
116  { removeSubSelection( fs.str() ); }
117  void mergeComp(const IOPar&,const char*);
119 
120 // GET functions
121 
122  const char* find(const char*) const;
124  FixedString operator[]( const char* ky ) const
125  { return FixedString( find(ky) ); }
126 
127  // Functions for getting 1,2,3 and 4 of the same type
128 #define mIOParDeclFns(type) \
129  bool get(const char*,type&) const; \
130  bool get(const char*,type&,type&) const; \
131  bool get(const char*,type&,type&,type&) const; \
132  bool get(const char*,type&,type&,type&,type&) const
133 
141  mIOParDeclFns(double);
142 #undef mIOParDeclFns
143  bool getYN(const char*,bool&) const;
144  bool getYN(const char*,bool&,bool&) const;
145  bool getYN(const char*,bool&,bool&,bool&) const;
146  bool getYN(const char*,bool&,bool&,bool&,bool&) const;
147  inline bool isTrue( const char* key ) const
148  { bool is = false; return getYN(key,is) && is; }
149  inline bool isFalse( const char* key ) const
150  { bool is = true; return getYN(key,is) && !is; }
151 
152  bool get(const char*,int&,int&,float&) const;
153 
154  bool get(const char*,BoolTypeSet&) const;
155  bool get(const char*,TypeSet<od_int16>&) const;
156  bool get(const char*,TypeSet<od_uint16>&) const;
157  bool get(const char*,TypeSet<int>&) const;
158  bool get(const char*,TypeSet<od_uint32>&) const;
159  bool get(const char*,TypeSet<od_int64>&) const;
160  bool get(const char*,TypeSet<od_uint64>&) const;
161  bool get(const char*,TypeSet<double>&) const;
162  bool get(const char*,TypeSet<float>&) const;
163  bool get(const char*,TypeSet<MultiID>&) const;
164  bool get(const char*,DBKeySet&) const;
165 
166  bool get(const char*,BinID&) const;
167  bool get(const char*,TrcKey&) const;
168  bool get(const char*,Coord&) const;
169  bool get(const char*,Coord3&) const;
170  bool get(const char*,MultiID&) const;
171  bool get(const char*,Color&) const;
172  bool get(const char*,SeparString&) const;
173  bool get(const char*,uiString&) const;
174  bool get(const char*,BufferString&) const;
175  bool get(const char*,BufferString&,BufferString&) const;
176  bool get(const char*,BufferString&,BufferString&,
177  BufferString&) const;
178  bool get(const char*,BufferStringSet&) const;
179  template <class T>
180  bool get(const char*,Interval<T>&) const;
181  template <class T>
182  bool get(const char*,SamplingData<T>&) const;
183 
184  bool getPtr(const char*,void*&) const;
185 
186 #define mIOParDeclFns(type) \
187  bool getScaled(const char*,type&,type applied_scale, \
188  bool set_to_undef_if_not_found) const; \
189  bool getScaled(const char*,type&,type&,type,bool) const; \
190  bool getScaled(const char*,type&,type&,type&,type, \
191  bool) const; \
192  bool getScaled(const char*,type&,type&,type&,type&,type, \
193  bool) const
195  mIOParDeclFns(double);
196 #undef mIOParDeclFns
197 
198 
199 // SET functions
200 
201  void set(const char* ky,const char* val);
203  void add(const char* ky,const char* val);
205  void add( const char* ky, const OD::String& val )
206  { add( ky, val.str() ); }
207  void addVal(const char* ky,const char* valtoadd);
210  void update(const char* ky,const char* val);
213  // Functions for 1,2,3 and 4 of the same type
214 #define mIOParDeclFns(fnnm,type) \
215  void fnnm(const char*,type); \
216  void fnnm(const char*,type,type); \
217  void fnnm(const char*,type,type,type); \
218  void fnnm(const char*,type,type,type,type)
219 
228 
231  mIOParDeclFns(add,int);
235  mIOParDeclFns(add,float);
236  mIOParDeclFns(add,double);
237 #undef mIOParDeclFns
238 #define mIOParDeclYNFns(fnnm) \
239  void fnnm##YN(const char*,bool); \
240  void fnnm##YN(const char*,bool,bool); \
241  void fnnm##YN(const char*,bool,bool,bool); \
242  void fnnm##YN(const char*,bool,bool,bool,bool)
245 #undef mIOParDeclYNFns
246 
247  void set(const char*,int,int,float);
248  void setPtr(const char*,void*);
249 
250  void set(const char*,const char*,const char*);
251  void set(const char*,const char*,const char*,const char*);
252  void set(const char*,const BinID&);
253  void set(const char*,const TrcKey&);
254  void set(const char*,const Coord&);
255  void set(const char*,const Coord3&);
256  void set(const char*,const MultiID&);
257  void set(const char*,const Color&);
258  void set(const char*,const SeparString&);
259  void set(const char*,const uiString&);
260  void set(const char*,const OD::String&);
261  void set(const char*,const OD::String&,
262  const OD::String&);
263  void set(const char*,const OD::String&,
264  const OD::String&,
265  const OD::String&);
266  void set(const char*,const BufferStringSet&);
267  template <class T>
268  void set(const char*,const Interval<T>&);
269  template <class T>
270  void set(const char*,const SamplingData<T>&);
271 
272  void set(const char*,const BoolTypeSet&);
273  void set(const char*,const TypeSet<od_int16>&);
274  void set(const char*,const TypeSet<od_uint16>&);
275  void set(const char*,const TypeSet<int>&);
276  void set(const char*,const TypeSet<od_uint32>&);
277  void set(const char*,const TypeSet<od_int64>&);
278  void set(const char*,const TypeSet<od_uint64>&);
279  void set(const char*,const TypeSet<double>&);
280  void set(const char*,const TypeSet<float>&);
281  void set(const char*,const TypeSet<MultiID>&);
282  void set(const char*,const DBKeySet&);
283 
284  void setToDateTime(const char* ky=nullptr);
285  void setToUser(const char* ky=nullptr);
287 
288 
289 // I/O functions
290 
291  // to/from string: 'serialisation'
292  void getFrom(const char*);
293  void getParsFrom(const char*);
294  void putTo(BufferString&) const;
295  void putParsTo(BufferString&) const;
296 
297  // to/from file
299  void putTo(ascostream&) const;
300  bool read(const char* filename,const char* filetype,
301  bool chktype=false);
304  bool read(od_istream&,const char* filetype,
305  bool chktype=false);
306  bool write(const char* filename,const char* filetype) const;
309  bool write(od_ostream&,const char* filetyp) const;
310  int majorVersion() const { return majorversion_; }
312  int minorVersion() const { return minorversion_; }
314  int patchVersion() const;
316  int odVersion() const;
320  void dumpPretty(BufferString&) const;
321  void dumpPretty(od_ostream&) const;
322 
323  static const char* sKeyDumpPretty() { return "_pretty"; }
324  static const char* sKeyHdr() { return "->"; }
325  static const char* sKeySubHdr() { return "-->"; }
326 
327 protected:
328 
331  void setPatchVersion(int); // is defined as hiddenparam
332 
335 
336 };
337 
338 
339 template <class T>
340 inline bool IOPar::get( const char* k, Interval<T>& i ) const
341 {
343  return si ? get( k, i.start, i.stop, si->step )
344  : get( k, i.start, i.stop );
345 }
346 
347 
348 template <class T>
349 inline void IOPar::set( const char* k, const Interval<T>& i )
350 {
351  mDynamicCastGet(const StepInterval<T>*,si,&i)
352  if ( si ) set( k, i.start, i.stop, si->step );
353  else set( k, i.start, i.stop );
354 }
355 
356 
357 template <class T>
358 inline bool IOPar::get( const char* k, SamplingData<T>& sd ) const
359 {
360  return get( k, sd.start, sd.step );
361 }
362 
363 
364 template <class T>
365 inline void IOPar::set( const char* k, const SamplingData<T>& sd )
366 {
367  set( k, sd.start, sd.step );
368 }
369 
370 
IOPar::set
void set(const char *, const BinID &)
od_uint64
#define od_uint64
Definition: plftypes.h:36
IOPar::set
void set(const char *ky, const char *val)
Coord3
A cartesian coordinate in 3D space.
Definition: coord.h:72
NamedObject
object with a name.
Definition: namedobj.h:42
IOPar::read
bool read(const char *filename, const char *filetype, bool chktype=false)
IOPar::set
void set(const char *, const uiString &)
IOPar::minorversion_
int minorversion_
Definition: iopar.h:330
IOPar::set
void set(const char *, const Coord &)
IOPar::get
bool get(const char *, BufferString &, BufferString &) const
IOPar::size
int size() const
IOPar::subselect
IOPar * subselect(const OD::String &fs) const
Definition: iopar.h:109
IOPar::set
void set(const char *, const TypeSet< uint64_t > &)
IOPar::sKeySubHdr
static const char * sKeySubHdr()
Definition: iopar.h:325
IOPar::get
bool get(const char *, short &) const
IOPar::hasKey
bool hasKey(const char *s) const
Definition: iopar.h:81
IOPar::setPatchVersion
void setPatchVersion(int)
IOPar::get
bool get(const char *, TypeSet< MultiID > &) const
IOPar::getYN
bool getYN(const char *, bool &, bool &, bool &, bool &) const
IOPar::set
void set(const char *, int, int, float)
IOPar::fillJSON
void fillJSON(OD::JSON::Object &obj)
only save the top level objects
IOPar::subselect
IOPar * subselect(const char *) const
returns iopar with key that start with <str>.
IOPar::removeWithKeyPattern
void removeWithKeyPattern(const char *globexpression)
BufferStringSet
Set of BufferString objects.
Definition: bufstringset.h:26
IOPar::get
bool get(const char *, BoolTypeSet &) const
IOPar::set
void set(const char *, const Color &)
IOPar::isTrue
bool isTrue(const char *key) const
Definition: iopar.h:147
IOPar::get
bool get(const char *, TypeSet< uint64_t > &) const
IOPar::get
bool get(const char *, TrcKey &) const
od_int64
#define od_int64
Definition: plftypes.h:35
IOPar::indexOf
int indexOf(const char *key) const
fixedstring.h
OD
OpendTect.
Definition: commontypes.h:28
IOPar::set
void set(const char *, const TypeSet< int64_t > &)
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
IOPar::set
void set(const char *, const TypeSet< short > &)
IOPar::removeSubSelection
void removeSubSelection(int)
removes with key that start with number.
od_istream
OD class for stream read common access to the std::cin.
Definition: od_istream.h:24
IOPar::set
void set(const char *, const char *, const char *, const char *)
IOPar::merge
void merge(const IOPar &)
merge entries using the set() command
namedobj.h
IOPar::set
void set(const char *, const TypeSet< int > &)
IOPar::removeSubSelection
void removeSubSelection(const char *)
removes with key that start with <str>.
samplingdata.h
IOPar::IOPar
IOPar(const char *nm=nullptr)
empty
mDynamicCastGet
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:148
IOPar::findKeyFor
const char * findKeyFor(const char *, int nr=0) const
returns null if value not found
IOPar::get
bool get(const char *, uiString &) const
IOPar::setToUser
void setToUser(const char *ky=nullptr)
IOPar::set
void set(const char *, const TrcKey &)
IOPar::get
bool get(const char *, Coord &) const
IOPar::set
void set(const char *, const BoolTypeSet &)
IOPar::getValue
FixedString getValue(int) const
operator==
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:81
IOPar::putTo
void putTo(ascostream &) const
IOPar::get
bool get(const char *, Color &) const
IOPar::setValue
void setValue(int, const char *)
IOPar::set
void set(const char *, const OD::String &)
IOPar::read
bool read(od_istream &, const char *filetype, bool chktype=false)
IOPar::setPtr
void setPtr(const char *, void *)
IOPar::get
bool get(const char *, TypeSet< int > &) const
ascostream
OpendTect standard ascii format file writing.
Definition: ascstream.h:32
IOPar::get
bool get(const char *, TypeSet< double > &) const
BinID
Positioning in a seismic survey: inline/crossline or lineNr/trcNr.
Definition: binid.h:31
StepInterval
Interval with step.
Definition: commontypes.h:32
Coord
A cartesian coordinate in 2D space.
Definition: coord.h:25
IOPar::add
void add(const char *ky, const char *val)
IOPar::write
bool write(od_ostream &, const char *filetyp) const
find
const BufferString * find(const BufferStringSet &, const char *)
IOPar::IOPar
IOPar(ascistream &)
IOPar::putTo
void putTo(BufferString &) const
IOPar::set
void set(const char *, const Coord3 &)
OD::String::str
const char * str() const
Definition: odstring.h:47
IOPar::set
void set(const char *, const TypeSet< unsigned short > &)
indexOf
BufferStringSet::idx_type indexOf(const BufferStringSet &, const char *)
IOPar::set
void set(const char *, const OD::String &, const OD::String &, const OD::String &)
IOPar::compKey
static const char * compKey(const char *, const char *)
The composite key: (a,b) -> a.b.
IOPar::getYN
bool getYN(const char *, bool &, bool &) const
IOPar::set
void set(const char *, const TypeSet< MultiID > &)
IOPar::removeWithKey
void removeWithKey(const char *key)
operator!=
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:90
IOPar::set
void set(const char *, const TypeSet< float > &)
IOPar::set
void set(const char *, const OD::String &, const OD::String &)
IOPar::get
bool get(const char *, int &, int &, float &) const
IOPar::mergeComp
void mergeComp(const IOPar &, const char *)
merge entries, where IOPar's entries get a prefix
od_int16
#define od_int16
Definition: plftypes.h:26
IOPar::majorVersion
int majorVersion() const
Only set if read from file. Otherwise set to current.
Definition: iopar.h:310
SamplingData
Holds the fundamental sampling info: start and interval.
Definition: samplingdata.h:22
IOPar::get
bool get(const char *, TypeSet< float > &) const
IOPar::compKey
static const char * compKey(const char *, int)
The composite key where int will be --> string.
IOPar::setToDateTime
void setToDateTime(const char *ky=nullptr)
IOPar::setEmpty
void setEmpty()
remove all entries (doesn't clear name)
mIOParDeclFns
#define mIOParDeclFns(type)
Definition: iopar.h:214
SeparString
Definition: separstr.h:136
IOPar::putParsTo
void putParsTo(BufferString &) const
FixedString
OD::String that holds an existing text string.
Definition: fixedstring.h:29
SamplingData::start
T start
Definition: samplingdata.h:49
IOPar::~IOPar
~IOPar()
IOPar::isPresent
bool isPresent(const char *ky) const
Definition: iopar.h:69
IOPar::set
void set(const char *, const char *, const char *)
od_uint16
#define od_uint16
Definition: plftypes.h:27
Conv::set
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
IOPar::update
void update(const char *ky, const char *val)
IOPar::vals_
BufferStringSet & vals_
Definition: iopar.h:334
IOPar::set
void set(const char *, const BufferStringSet &)
dbkey.h
IOPar::get
bool get(const char *, Coord3 &) const
MultiID
Compound key consisting of ints.
Definition: multiid.h:24
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
IOPar::get
bool get(const char *, DBKeySet &) const
TrcKey
Represents a unique trace position in one of the surveys that OpendTect is managing.
Definition: trckey.h:28
IOPar::patchVersion
int patchVersion() const
Only set if read from file. Otherwise set to current.
IOPar::get
bool get(const char *, BufferString &) const
IOPar::find
const char * find(const char *) const
returns null if not found
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
IOPar::getPtr
bool getPtr(const char *, void *&) const
IOPar::isFalse
bool isFalse(const char *key) const
Definition: iopar.h:149
IOPar::get
bool get(const char *, TypeSet< unsigned int > &) const
IOPar::getKey
FixedString getKey(int) const
IOPar::maxContentSize
int maxContentSize(bool keys_else_values) const
IOPar::set
void set(const char *, const DBKeySet &)
OD::String
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
od_iosfwd.h
IOPar::dumpPretty
void dumpPretty(BufferString &) const
IOPar::get
bool get(const char *, BufferString &, BufferString &, BufferString &) const
DBKeySet
Definition: dbkey.h:58
IOPar::setStdCreationEntries
void setStdCreationEntries()
IOPar::getFrom
void getFrom(ascistream &)
IOPar::write
bool write(const char *filename, const char *filetype) const
IOPar::compKey
static const char * compKey(const char *ky1, const OD::String &ky2)
Definition: iopar.h:103
IOPar::dumpPretty
void dumpPretty(od_ostream &) const
IOPar::removeSubSelection
void removeSubSelection(const OD::String &fs)
Definition: iopar.h:115
IOPar::getYN
bool getYN(const char *, bool &, bool &, bool &) const
IOPar::isEqual
bool isEqual(const IOPar &, bool need_same_order=false) const
IOPar::sKeyDumpPretty
static const char * sKeyDumpPretty()
Definition: iopar.h:323
IOPar::set
void set(const char *, const SeparString &)
IOPar::get
bool get(const char *, TypeSet< int64_t > &) const
ascistream
OpendTect standard ascii format file reading.
Definition: ascstream.h:83
IOPar::set
void set(const char *, const TypeSet< unsigned int > &)
IOPar::includes
bool includes(const IOPar &) const
IOPar::set
void set(const char *, const MultiID &)
IOPar::getFrom
void getFrom(const char *)
IOPar::setKey
bool setKey(int, const char *)
IOPar::get
bool get(const char *, SeparString &) const
IOPar::operator[]
FixedString operator[](const char *ky) const
Definition: iopar.h:124
IOPar::get
bool get(const char *, BinID &) const
IOPar::get
bool get(const char *, BufferStringSet &) const
od_uint32
#define od_uint32
Definition: plftypes.h:31
Interval
Interval of values.
Definition: commontypes.h:30
IOPar::IOPar
IOPar(const IOPar &)
SamplingData::step
T step
Definition: samplingdata.h:50
IOPar::get
bool get(const char *, TypeSet< short > &) const
Color
Color is an RGB color object, with a transparancy. The storage is in a 4-byte integer,...
Definition: color.h:26
od_ostream
OD class for stream write common access to the user log file, or std::cout in other than od_main.
Definition: od_ostream.h:26
IOPar::sKeyHdr
static const char * sKeyHdr()
Definition: iopar.h:324
IOPar::getYN
bool getYN(const char *, bool &) const
IOPar::isEmpty
bool isEmpty() const
Definition: iopar.h:72
mIOParDeclYNFns
#define mIOParDeclYNFns(fnnm)
Definition: iopar.h:238
IOPar::add
void add(const char *ky, const OD::String &val)
Definition: iopar.h:205
IOPar::remove
void remove(int)
IOPar::minorVersion
int minorVersion() const
Only set if read from file. Otherwise set to current.
Definition: iopar.h:312
IOPar::keys_
BufferStringSet & keys_
Definition: iopar.h:333
IOPar::majorversion_
int majorversion_
Definition: iopar.h:329
IOPar
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:55
IOPar::get
bool get(const char *, TypeSet< unsigned short > &) const
IOPar::odVersion
int odVersion() const
IOPar::subselect
IOPar * subselect(int) const
returns iopar with key that start with number.
IOPar::getParsFrom
void getParsFrom(const char *)
OD::JSON::Object
ValueSet where the values and subsets have a key.
Definition: odjson.h:283
IOPar::get
bool get(const char *, MultiID &) const
IOPar::set
void set(const char *, const TypeSet< double > &)
TypeSet< BoolTypeSetType >
IOPar::addFrom
void addFrom(const IOPar &)
merge entries but do not overwrite
IOPar::addVal
void addVal(const char *ky, const char *valtoadd)

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