OpendTect  6.3
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 ________________________________________________________________________
10 
11 -*/
12 
13 #include "basicmod.h"
14 #include "namedobj.h"
15 #include "fixedstring.h"
16 #include "samplingdata.h"
17 #include "idxpair.h"
18 #include "integerid.h"
19 #include "groupedid.h"
20 #include "geometry.h"
21 #include "od_iosfwd.h"
22 
23 class BufferStringSet;
24 class SeparString;
25 class ascistream;
26 class ascostream;
27 class uiString;
28 
53 mExpClass(Basic) IOPar : public NamedObject
54 {
55 public:
56  IOPar(const char* nm=0);
57  IOPar(ascistream&);
58  IOPar(const IOPar&);
59  ~IOPar();
60  IOPar& operator =(const IOPar&);
61  inline bool operator ==( const IOPar& iop ) const
62  { return isEqual(iop); }
63  inline bool operator !=( const IOPar& iop ) const
64  { return !isEqual(iop); }
65 
66  int size() const;
67  int indexOf(const char* key) const;
68  inline bool isPresent( const char* ky ) const
69  { return indexOf(ky) >= 0; }
70 
71  inline bool isEmpty() const { return size() == 0; }
72  bool isEqual(const IOPar&,bool need_same_order=false) const;
73  bool includes(const IOPar&) const;
74  FixedString getKey(int) const;
75  FixedString getValue(int) const;
76  bool setKey(int,const char*);
77  void setValue(int,const char*);
78  void sortOnKeys();
79 
80  inline bool hasKey( const char* s ) const { return isPresent(s); }
81  const char* findKeyFor(const char*,int nr=0) const;
83 
84  void remove(int);
85  void removeWithKey(const char* key);
86  void removeWithKeyPattern(const char* globexpression);
89 
90  void setEmpty();
92  void merge(const IOPar&);
94  void addFrom(const IOPar&);
96  static const char* compKey(const char*,const char*);
98  static const char* compKey(const char*,int);
100  static const char* compKey( const char* ky1, const OD::String& ky2 )
101  { return compKey(ky1,ky2.str()); }
102  IOPar* subselect(const char*) const;
104  IOPar* subselect(int) const;
106  IOPar* subselect( const OD::String& fs ) const
107  { return subselect( fs.str() ); }
108  void removeSubSelection(const char*);
110  void removeSubSelection(int);
112  void removeSubSelection( const OD::String& fs )
113  { removeSubSelection( fs.str() ); }
114  void mergeComp(const IOPar&,const char*);
116 
117 // GET functions
118 
119  const char* find(const char*) const;
121  FixedString operator[]( const char* ky ) const
122  { return FixedString( find(ky) ); }
123 
124  // Functions for getting 1,2,3 and 4 of the same type
125 #define mIOParDeclFns(type) \
126  bool get(const char*,type&) const; \
127  bool get(const char*,type&,type&) const; \
128  bool get(const char*,type&,type&,type&) const; \
129  bool get(const char*,type&,type&,type&,type&) const
130 
131  mIOParDeclFns(int);
135  mIOParDeclFns(float);
136  mIOParDeclFns(double);
137 #undef mIOParDeclFns
138  bool getYN(const char*,bool&) const;
139  bool getYN(const char*,bool&,bool&) const;
140  bool getYN(const char*,bool&,bool&,bool&) const;
141  bool getYN(const char*,bool&,bool&,bool&,bool&) const;
142  inline bool isTrue( const char* key ) const
143  { bool is = false; return getYN(key,is) && is; }
144  inline bool isFalse( const char* key ) const
145  { bool is = true; return getYN(key,is) && !is; }
146 
147 
148  bool get(const char*,int&,int&,float&) const;
149 
150  bool get(const char*,TypeSet<int>&) const;
151  bool get(const char*,TypeSet<od_uint32>&) const;
152  bool get(const char*,TypeSet<od_int64>&) const;
153  bool get(const char*,TypeSet<od_uint64>&) const;
154  bool get(const char*,TypeSet<double>&) const;
155  bool get(const char*,TypeSet<float>&) const;
156 
157  template <class iT>
158  inline bool get(const char*,IntegerID<iT>&) const;
159  template <class fT>
160  inline bool get(const char*,Geom::Point2D<fT>&) const;
161  template <class fT>
162  inline bool get(const char*,Geom::Point3D<fT>&) const;
163  template <class T>
164  inline bool get(const char*,Interval<T>&) const;
165  template <class T>
166  inline bool get(const char*,SamplingData<T>&) const;
167  template <class T1,class T2>
168  inline bool get(const char*,std::pair<T1,T2>&) const;
169 
170  bool get(const char*,TrcKey&) const;
171  bool get(const char*,DBKey&) const;
172  bool get(const char*,Color&) const;
173  bool get(const char*,SeparString&) const;
174  bool get(const char*,uiString&) const;
175  bool get(const char*,BufferString&) const;
176  bool get(const char*,BufferString&,BufferString&) const;
177  bool get(const char*,BufferString&,BufferString&,
178  BufferString&) const;
179  bool get(const char*,BufferStringSet&) const;
180 
181  bool getPtr(const char*,void*&) const;
182 
183 #define mIOParDeclFns(type) \
184  bool getScaled(const char*,type&,type applied_scale, \
185  bool set_to_undef_if_not_found) const; \
186  bool getScaled(const char*,type&,type&,type,bool) const; \
187  bool getScaled(const char*,type&,type&,type&,type, \
188  bool) const; \
189  bool getScaled(const char*,type&,type&,type&,type&,type, \
190  bool) const
191  mIOParDeclFns(float);
192  mIOParDeclFns(double);
193 #undef mIOParDeclFns
194 
195 
196 // SET functions
197 
198  void set(const char* ky,const char* val);
200  void add(const char* ky,const char* val);
202  void add( const char* ky, const OD::String& val )
203  { add( ky, val.str() ); }
204  void update(const char* ky,const char* val);
207  // Functions for 1,2,3 and 4 of the same type
208 #define mIOParDeclFns(fnnm,type) \
209  void fnnm(const char*,type); \
210  void fnnm(const char*,type,type); \
211  void fnnm(const char*,type,type,type); \
212  void fnnm(const char*,type,type,type,type)
213 
214  mIOParDeclFns(set,int);
216  mIOParDeclFns(set,od_int64);
218  mIOParDeclFns(set,float);
219  mIOParDeclFns(set,double);
220  mIOParDeclFns(add,int);
222  mIOParDeclFns(add,od_int64);
224  mIOParDeclFns(add,float);
225  mIOParDeclFns(add,double);
226 #undef mIOParDeclFns
227 #define mIOParDeclYNFns(fnnm) \
228  void fnnm##YN(const char*,bool); \
229  void fnnm##YN(const char*,bool,bool); \
230  void fnnm##YN(const char*,bool,bool,bool); \
231  void fnnm##YN(const char*,bool,bool,bool,bool)
232  mIOParDeclYNFns(set);
233  mIOParDeclYNFns(add);
234 #undef mIOParDeclYNFns
235 
236  template<class iT>
237  inline void set(const char*,IntegerID<iT>);
238  template <class fT>
239  inline void set(const char*,const Geom::Point2D<fT>&);
240  template <class fT>
241  inline void set(const char*,const Geom::Point3D<fT>&);
242  template <class T>
243  inline void set(const char*,const Interval<T>&);
244  template <class T>
245  inline void set(const char*,const SamplingData<T>&);
246  template <class T1,class T2>
247  inline void set(const char*,const std::pair<T1,T2>&);
248 
249  template<class iT>
250  inline void update(const char*,IntegerID<iT>);
251  void update(const char*,const DBKey&);
252 
253  void set(const char*,int,int,float);
254  void setPtr(const char*,void*);
255 
256  void set(const char*,const char*,const char*);
257  void set(const char*,const char*,const char*,const char*);
258  void set(const char*,const TrcKey&);
259  void set(const char*,const DBKey&);
260  void set(const char*,const Color&);
261  void set(const char*,const SeparString&);
262  void set(const char*,const uiString&);
263  void set(const char*,const OD::String&);
264  void set(const char*,const OD::String&,
265  const OD::String&);
266  void set(const char*,const OD::String&,
267  const OD::String&,
268  const OD::String&);
269  void set(const char*,const BufferStringSet&);
270 
271  void set(const char*,const TypeSet<int>&);
272  void set(const char*,const TypeSet<od_uint32>&);
273  void set(const char*,const TypeSet<od_int64>&);
274  void set(const char*,const TypeSet<od_uint64>&);
275  void set(const char*,const TypeSet<double>&);
276  void set(const char*,const TypeSet<float>&);
277 
278  void setToDateTime(const char* ky=0);
279  void setToUser(const char* ky=0);
280  void setStdCreationEntries();
281 
282 
283 // I/O functions
284 
285  // to/from string: 'serialisation'
286  void getFrom(const char*);
287  void getParsFrom(const char*);
288  void putTo(BufferString&) const;
289  void putParsTo(BufferString&) const;
290 
291  // to/from file
292  void getFrom(ascistream&);
293  void putTo(ascostream&) const;
294  bool read(const char* filename,const char* filetype,
295  bool chktype=false);
298  bool read(od_istream&,const char* filetype,
299  bool chktype=false);
300  bool write(const char* filename,const char* filetype) const;
303  bool write(od_ostream&,const char* filetyp) const;
304  int majorVersion() const { return majorversion_; }
306  int minorVersion() const { return minorversion_; }
308  int odVersion() const;
312  void dumpPretty(BufferString&) const;
313  void dumpPretty(od_ostream&) const;
314 
315  void collectIDs(TypeSet<int>&) const;
316 
317  static const char* sKeyDumpPretty() { return "_pretty"; }
318  static const char* sKeyHdr() { return "->"; }
319  static const char* sKeySubHdr() { return "-->"; }
320 
321 protected:
322 
325 
328 
329 };
330 
331 
332 template <class T>
333 inline bool IOPar::get( const char* keyw, Interval<T>& intv ) const
334 {
336  return si ? get( keyw, intv.start, intv.stop, si->step )
337  : get( keyw, intv.start, intv.stop );
338 }
339 
340 
341 template <class T>
342 inline void IOPar::set( const char* keyw, const Interval<T>& intv )
343 {
344  mDynamicCastGet(const StepInterval<T>*,si,&intv)
345  if ( si ) set( keyw, intv.start, intv.stop, si->step );
346  else set( keyw, intv.start, intv.stop );
347 }
348 
349 
350 template <class T>
351 inline bool IOPar::get( const char* keyw, SamplingData<T>& sd ) const
352 {
353  return get( keyw, sd.start, sd.step );
354 }
355 
356 
357 template <class T>
358 inline void IOPar::set( const char* keyw, const SamplingData<T>& sd )
359 {
360  set( keyw, sd.start, sd.step );
361 }
362 
363 
364 template<class iT>
365 bool IOPar::get( const char* keyw, IntegerID<iT>& id ) const
366 {
367  iT idio = id.getI();
368  const bool rv = get( keyw, idio );
369  if ( rv )
370  id.setI( idio );
371  return rv;
372 }
373 
374 
375 template<class iT>
376 void IOPar::set( const char* keyw, IntegerID<iT> id )
377 {
378  set( keyw, id.getI() );
379 }
380 
381 
382 template<class iT>
383 void IOPar::update( const char* keyw, IntegerID<iT> id )
384 {
385  if ( id.isInvalid() )
386  removeWithKey( keyw );
387  else
388  set( keyw, id.getI() );
389 }
390 
391 
392 template <class fT>
393 bool IOPar::get( const char* keyw, Geom::Point2D<fT>& crd ) const
394 {
395  return get( keyw, crd.x_, crd.y_ );
396 }
397 
398 
399 template <class fT>
400 bool IOPar::get( const char* keyw, Geom::Point3D<fT>& crd ) const
401 {
402  return get( keyw, crd.x_, crd.y_, crd.z_ );
403 }
404 
405 
406 template<class fT>
407 void IOPar::set( const char* keyw, const Geom::Point2D<fT>& crd )
408 {
409  set( keyw, crd.x_, crd.y_ );
410 }
411 
412 
413 template<class fT>
414 void IOPar::set( const char* keyw, const Geom::Point3D<fT>& crd )
415 {
416  set( keyw, crd.x_, crd.y_, crd.z_ );
417 }
418 
419 
420 template <class T1,class T2>
421 bool IOPar::get( const char* keyw, std::pair<T1,T2>& p ) const
422 {
423  return get( keyw, p.first, p.second );
424 }
425 
426 
427 template<class T1,class T2>
428 void IOPar::set( const char* keyw, const std::pair<T1,T2>& p )
429 {
430  set( keyw, p.first, p.second );
431 }
#define mExpClass(module)
Definition: commondefs.h:157
int size() const
T step
Definition: samplingdata.h:48
int minorVersion() const
Only set if read from file. Otherwise set to current.
Definition: iopar.h:306
#define mIOParDeclFns(type)
Definition: iopar.h:208
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
const char * str() const
Definition: odstring.h:46
static const char * sKeyHdr()
Definition: iopar.h:318
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:51
OD::String that holds an existing text string.
Definition: fixedstring.h:27
#define od_int64
Definition: plftypes.h:34
OpendTect standard ascii format file writing.
Definition: ascstream.h:30
bool isPresent(const char *ky) const
Definition: iopar.h:68
bool isFalse(const char *key) const
Definition: iopar.h:144
List encoded in a string.
Definition: separstr.h:32
Definition: uistring.h:88
Set of BufferString objects.
Definition: bufstringset.h:25
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:173
bool get(const char *, int &) const
single integer ID with comparison but no automatic conversion. Note that you will want to make a subc...
Definition: integerid.h:47
uiString & operator=(const uiString &)
no copy, ref counted
int majorVersion() const
Only set if read from file. Otherwise set to current.
Definition: iopar.h:304
Interval of values.
Definition: commontypes.h:27
OD class for stream read.
Definition: od_istream.h:23
bool hasKey(const char *s) const
Definition: iopar.h:80
3D point or vector
Definition: commontypes.h:57
IOPar * subselect(const OD::String &fs) const
Definition: iopar.h:106
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:53
void removeWithKey(const char *key)
#define od_uint32
Definition: plftypes.h:30
bool isEmpty() const
Definition: iopar.h:71
BufferStringSet & vals_
Definition: iopar.h:327
void update(const char *ky, const char *val)
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:29
T start
Definition: samplingdata.h:47
Interval with step.
Definition: commontypes.h:29
T x_
Definition: geometry.h:80
T x_
Definition: geometry.h:166
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:60
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:123
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:187
OpendTect standard ascii format file reading.
Definition: ascstream.h:81
void setEmpty()
#define od_uint64
Definition: plftypes.h:35
#define mIOParDeclYNFns(fnnm)
Definition: iopar.h:227
T stop
Definition: ranges.h:91
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:38
T z_
Definition: geometry.h:168
object with a name.
Definition: namedobj.h:20
FixedString operator[](const char *ky) const
Definition: iopar.h:121
static const char * sKeyDumpPretty()
Definition: iopar.h:317
void add(const char *ky, const OD::String &val)
Definition: iopar.h:202
bool isTrue(const char *key) const
Definition: iopar.h:142
Color is an RGB color object, with a transparancy. The storage is in a 4-byte integer, similar to Qt.
Definition: color.h:24
T start
Definition: ranges.h:90
static const char * compKey(const char *ky1, const OD::String &ky2)
Definition: iopar.h:100
Holds the fundamental sampling info: start and interval.
Definition: samplingdata.h:20
Full key to any object in the OpendTect data store.
Definition: dbkey.h:36
void removeSubSelection(const OD::String &fs)
Definition: iopar.h:112
Represents a unique trace position in one of the surveys that OpendTect is managing.
Definition: trckey.h:26
2D point or vector class.
Definition: commontypes.h:58
void set(const char *ky, const char *val)
int majorversion_
Definition: iopar.h:323
T y_
Definition: geometry.h:167
BufferStringSet & keys_
Definition: iopar.h:326
T y_
Definition: geometry.h:81
static const char * sKeySubHdr()
Definition: iopar.h:319
int minorversion_
Definition: iopar.h:324

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