OpendTect  6.6
tabledef.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: Oct 2006
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "generalmod.h"
15 #include "coordsystem.h"
16 #include "sets.h"
17 #include "rowcol.h"
18 #include "namedobj.h"
19 #include "datainpspec.h"
20 #include "propertyref.h"
21 
22 class UnitOfMeasure;
23 
24 namespace Table
25 {
26 
27  enum ReqSpec { Optional=0, Required=1, Hidden=2 };
28 
41 mExpClass(General) TargetInfo : public NamedObject
42 {
43 public:
44 
61  struct Form : NamedObject
62  {
63  Form( const char* nm, DataInpSpec* spec )
64  : NamedObject(nm)
65  { add( spec ); }
66  Form( const char* nm, const DataInpSpec& spec )
67  : NamedObject(nm)
68  { add( spec.clone() ); }
69 
70  ~Form() { deepErase(specs_); }
71 
72  Form& add( const DataInpSpec& spec )
73  { specs_ += spec.clone(); return *this; }
74  Form& add( DataInpSpec* spec )
75  { specs_ += spec ? spec : new StringInpSpec;
76  return *this; }
77 
78  Form* duplicate( const char* nm ) const
79  {
80  Form* ret = new Form( nm, *specs_[0] );
81  for ( int idx=1; idx<specs_.size(); idx++ )
82  ret->specs_ += specs_[idx]->clone();
83  return ret;
84  }
85 
87  };
88 
89 
90  TargetInfo( const char* nm, ReqSpec rs=Optional )
92  : NamedObject(nm), req_(rs)
93  , proptype_(PropertyRef::Other)
94  { add( nm ); }
95  TargetInfo( const char* nm, DataInpSpec* spec,
96  ReqSpec rs=Optional,
98  : NamedObject(nm), req_(rs), proptype_(p)
99  { add( nm, spec ); }
100  TargetInfo( const char* nm, const DataInpSpec& spec,
101  ReqSpec rs=Optional,
103  : NamedObject(nm), req_(rs), proptype_(p)
104  { add( nm, spec ); }
105 
106  ~TargetInfo() { deepErase( forms_ ); }
107 
108  TargetInfo& add( const char* nm, DataInpSpec* spec=0 )
109  { forms_ += new Form( nm, spec ); return *this; }
110  TargetInfo& add( const char* nm, const DataInpSpec& spec )
111  { forms_ += new Form( nm, spec ); return *this; }
112  TargetInfo& add( Form* frm )
113  { forms_ += frm; return *this; }
114 
115  bool isOptional() const { return req_ != Required; }
116  bool isHidden() const { return req_ == Hidden; }
117  PropertyRef::StdType propertyType() const { return proptype_; }
119  { proptype_ = p; }
120  int nrForms() const { return forms_.size(); }
121  Form& form( int idx ) { return *forms_[idx]; }
122  const Form& form( int idx ) const { return *forms_[idx]; }
123  int formNr( const char* formnm ) const
124  {
125  for ( int idx=0; idx<forms_.size(); idx++ )
126  if ( forms_[idx]->name() == formnm )
127  return idx;
128  return -1;
129  }
130 
136  struct Selection
137  {
139  struct Elem
140  {
142  : pos_(0,-1) {}
143  Elem( const RowCol& rc, const char* kw=0 )
144  : pos_(rc), keyword_(kw) {}
145  Elem( const char* s )
146  : pos_(0,-1), val_(s) {}
147 
148  bool isInFile() const
149  { return pos_.col() >= 0; }
150  bool isKeyworded() const
151  { return isInFile() && !keyword_.isEmpty();}
152  bool isSpecified() const
153  { return !val_.isEmpty(); }
154  bool isEmpty() const
155  { return !isInFile() && !isSpecified();}
156  bool operator ==( const Elem& v ) const
157  { return pos_ == v.pos_ && val_ == v.val_
158  && keyword_ == v.keyword_; }
159 
163  };
164 
165  int form_;
169 
171  : form_(0), unit_(0), coordsys_(0) {}
172 
173  bool havePos( int ielem ) const
174  { return ielem < elems_.size()
175  && elems_[ielem].isInFile(); }
176  bool isKeyworded( int ielem ) const
177  { return ielem < elems_.size()
178  && elems_[ielem].isKeyworded(); }
179  bool isInFile( int ielem=0 ) const
180  { return ielem < elems_.size()
181  && elems_[ielem].isInFile(); }
182  const char* getVal( int ielem ) const
183  { return ielem >= elems_.size() ? 0
184  : elems_[ielem].val_.buf(); }
185  bool isFilled() const
186  { return elems_.size() > 0 && !elems_[0].isEmpty(); }
187  };
188 
190 
191  void fillPar(IOPar&) const;
192  void usePar(const IOPar&);
193 
194  static TargetInfo* mkHorPosition(bool isreq,bool wic=true,bool wll=false,
195  bool wcrs=true);
197  static TargetInfo* mkZPosition( bool isreq, bool withunits=true )
198  { return mkZPos(isreq,withunits); }
199  static TargetInfo* mkDepthPosition( bool isreq, bool withunits=true )
200  { return mkZPos(isreq,withunits,1); }
201  static TargetInfo* mkTimePosition( bool isreq, bool withunits=true )
202  { return mkZPos(isreq,withunits,-1); }
203  bool needsConversion() const;
204  Coord convert(const Coord&) const;
205 
206 protected:
207 
211 
212  static TargetInfo* mkZPos(bool,bool wu=false,int zopt=0);
213 
214 };
215 
216 
220 {
221 public:
222  FormatDesc( const char* nm )
223  : NamedObject(nm)
224  , nrhdrlines_(0)
225  , eohtokencol_(-1) {}
227  { deepErase( headerinfos_ ); deepErase( bodyinfos_ ); }
228 
231 
236 
237  bool needEOHToken() const
238  { return nrhdrlines_ < 0 && !eohtoken_.isEmpty(); }
239  int nrHdrLines() const
240  { return needEOHToken() ? mUdf(int)
241  : nrhdrlines_ > 0 ? nrhdrlines_ : 0; }
242  bool haveEOBToken() const
243  { return !eobtoken_.isEmpty(); }
244 
245  bool isGood() const;
246  bool bodyUsesCol(int) const;
247 
248  void fillPar(IOPar&) const;
249  void usePar(const IOPar&);
250 
251  void clear()
252  {
253  nrhdrlines_ = eohtokencol_ = 0;
254  eohtoken_.setEmpty(); eobtoken_.setEmpty();
255  }
256 };
257 
258 }; // namespace Table
259 
260 
Table::TargetInfo::form
const Form & form(int idx) const
Definition: tabledef.h:122
ConstRefMan< Coords::CoordSystem >
Table::TargetInfo::needsConversion
bool needsConversion() const
Table::TargetInfo::mkZPosition
static TargetInfo * mkZPosition(bool isreq, bool withunits=true)
Definition: tabledef.h:197
NamedObject
object with a name.
Definition: namedobj.h:42
Table::TargetInfo::Selection::Elem::pos_
RowCol pos_
Definition: tabledef.h:160
Table::Optional
@ Optional
Definition: tabledef.h:27
Table::TargetInfo::Selection::Elem::isEmpty
bool isEmpty() const
Definition: tabledef.h:154
Table::TargetInfo::Selection::Elem::isKeyworded
bool isKeyworded() const
Definition: tabledef.h:150
Table::FormatDesc::nrhdrlines_
int nrhdrlines_
if < 0 eohtoken will be used
Definition: tabledef.h:232
Table::TargetInfo::form
Form & form(int idx)
Definition: tabledef.h:121
Table::TargetInfo::Selection::Elem
holds the 'value' of a certain selection
Definition: tabledef.h:140
Table::TargetInfo::mkHorPosition
static TargetInfo * mkHorPosition(bool isreq, bool wic=true, bool wll=false, bool wcrs=true)
form(0)=(X,Y), form(1)=inl/crl, form(1/2)=long/lat
Table::FormatDesc::fillPar
void fillPar(IOPar &) const
Table::TargetInfo::Form
Specific form in which a piece of information can be found.
Definition: tabledef.h:62
coordsystem.h
DataInpSpec::clone
virtual DataInpSpec * clone() const =0
ObjectSet< DataInpSpec >
Table::TargetInfo::fillPar
void fillPar(IOPar &) const
Table::TargetInfo::Form::add
Form & add(const DataInpSpec &spec)
Definition: tabledef.h:72
Table::TargetInfo::add
TargetInfo & add(Form *frm)
Definition: tabledef.h:112
Table::TargetInfo::Selection::havePos
bool havePos(int ielem) const
Definition: tabledef.h:173
Table::TargetInfo::isOptional
bool isOptional() const
Definition: tabledef.h:115
Table::TargetInfo::Selection::coordsys_
ConstRefMan< Coords::CoordSystem > coordsys_
Definition: tabledef.h:168
Table::TargetInfo::Selection::Selection
Selection()
Definition: tabledef.h:170
Table::TargetInfo::mkZPos
static TargetInfo * mkZPos(bool, bool wu=false, int zopt=0)
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
namedobj.h
Table::FormatDesc::FormatDesc
FormatDesc(const char *nm)
Definition: tabledef.h:222
Table::TargetInfo::selection_
Selection selection_
Definition: tabledef.h:189
ODInst::Other
@ Other
Definition: odinst.h:44
Table::FormatDesc::eobtoken_
BufferString eobtoken_
end-of-body: no more data
Definition: tabledef.h:235
Table::TargetInfo::Form::~Form
~Form()
Definition: tabledef.h:70
Table::TargetInfo::Selection::isInFile
bool isInFile(int ielem=0) const
Definition: tabledef.h:179
PropertyRef::Other
@ Other
Definition: propertyref.h:49
Table
Definition: geom2dascio.h:20
operator==
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:81
Table::FormatDesc::headerinfos_
ObjectSet< TargetInfo > headerinfos_
Definition: tabledef.h:229
Table::TargetInfo::nrForms
int nrForms() const
Definition: tabledef.h:120
Table::TargetInfo::Selection
Selected element/positioning This selects the specific form and where/how it can be found in the file...
Definition: tabledef.h:137
Table::FormatDesc::bodyinfos_
ObjectSet< TargetInfo > bodyinfos_
Definition: tabledef.h:230
Table::TargetInfo::forms_
ObjectSet< Form > forms_
Definition: tabledef.h:210
Table::FormatDesc::haveEOBToken
bool haveEOBToken() const
Definition: tabledef.h:242
Table::TargetInfo::usePar
void usePar(const IOPar &)
Table::FormatDesc::isGood
bool isGood() const
Table::TargetInfo::TargetInfo
TargetInfo(const char *nm, const DataInpSpec &spec, ReqSpec rs=Optional, PropertyRef::StdType p=PropertyRef::Other)
Definition: tabledef.h:100
Table::FormatDesc::~FormatDesc
~FormatDesc()
Definition: tabledef.h:226
Table::FormatDesc::eohtoken_
BufferString eohtoken_
end-of-header token
Definition: tabledef.h:233
Coord
A cartesian coordinate in 2D space.
Definition: coord.h:25
Table::TargetInfo::propertyType
PropertyRef::StdType propertyType() const
Definition: tabledef.h:117
Table::TargetInfo::isHidden
bool isHidden() const
Definition: tabledef.h:116
Table::TargetInfo::add
TargetInfo & add(const char *nm, DataInpSpec *spec=0)
Definition: tabledef.h:108
Table::FormatDesc::bodyUsesCol
bool bodyUsesCol(int) const
Table::TargetInfo::TargetInfo
TargetInfo(const char *nm, DataInpSpec *spec, ReqSpec rs=Optional, PropertyRef::StdType p=PropertyRef::Other)
Definition: tabledef.h:95
Table::TargetInfo::req_
ReqSpec req_
Definition: tabledef.h:208
Table::TargetInfo::Selection::isKeyworded
bool isKeyworded(int ielem) const
Definition: tabledef.h:176
Table::TargetInfo::Selection::getVal
const char * getVal(int ielem) const
Definition: tabledef.h:182
Table::TargetInfo::Selection::Elem::val_
BufferString val_
Definition: tabledef.h:162
Table::TargetInfo::Selection::Elem::keyword_
BufferString keyword_
Definition: tabledef.h:161
DataInpSpec
Specification of input characteristics.
Definition: datainpspec.h:90
OD::String::isEmpty
bool isEmpty() const
Definition: odstring.h:50
Table::TargetInfo::mkTimePosition
static TargetInfo * mkTimePosition(bool isreq, bool withunits=true)
Definition: tabledef.h:201
datainpspec.h
Table::TargetInfo::mkDepthPosition
static TargetInfo * mkDepthPosition(bool isreq, bool withunits=true)
Definition: tabledef.h:199
Table::TargetInfo::Selection::Elem::Elem
Elem(const RowCol &rc, const char *kw=0)
Definition: tabledef.h:143
propertyref.h
Table::TargetInfo::Selection::Elem::isSpecified
bool isSpecified() const
Definition: tabledef.h:152
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
Table::FormatDesc::needEOHToken
bool needEOHToken() const
Definition: tabledef.h:237
Table::TargetInfo::TargetInfo
TargetInfo(const char *nm, ReqSpec rs=Optional)
Definition: tabledef.h:90
PropertyRef
Ref Data for a (usually petrophysical) property.
Definition: propertyref.h:43
UnitOfMeasure
Unit of Measure.
Definition: unitofmeasure.h:35
deepErase
void deepErase(BufferStringSet &)
Table::FormatDesc::eohtokencol_
int eohtokencol_
if < 0 eohtoken can be in any col
Definition: tabledef.h:234
Table::TargetInfo::Selection::isFilled
bool isFilled() const
Definition: tabledef.h:185
Table::TargetInfo::Form::Form
Form(const char *nm, DataInpSpec *spec)
Definition: tabledef.h:63
Table::FormatDesc::usePar
void usePar(const IOPar &)
Table::TargetInfo::proptype_
PropertyRef::StdType proptype_
Definition: tabledef.h:209
Table::TargetInfo::Form::add
Form & add(DataInpSpec *spec)
Definition: tabledef.h:74
BufferString::setEmpty
BufferString & setEmpty()
Table::TargetInfo::setPropertyType
void setPropertyType(PropertyRef::StdType p)
Definition: tabledef.h:118
Table::FormatDesc::nrHdrLines
int nrHdrLines() const
Definition: tabledef.h:239
Table::Hidden
@ Hidden
Definition: tabledef.h:27
Table::ReqSpec
ReqSpec
Definition: tabledef.h:27
PropertyRef::StdType
StdType
Definition: propertyref.h:46
Table::TargetInfo::Selection::Elem::Elem
Elem(const char *s)
Definition: tabledef.h:145
Table::TargetInfo::Selection::Elem::isInFile
bool isInFile() const
Definition: tabledef.h:148
Table::TargetInfo::add
TargetInfo & add(const char *nm, const DataInpSpec &spec)
Definition: tabledef.h:110
mUdf
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
Table::TargetInfo::Form::specs_
ObjectSet< DataInpSpec > specs_
Definition: tabledef.h:86
Table::TargetInfo::Selection::unit_
const UnitOfMeasure * unit_
Definition: tabledef.h:167
Table::TargetInfo::Form::Form
Form(const char *nm, const DataInpSpec &spec)
Definition: tabledef.h:66
RowCol
IdxPair used for its row() and col().
Definition: rowcol.h:25
Table::FormatDesc
description of input our output data content
Definition: tabledef.h:220
Table::Required
@ Required
Definition: tabledef.h:27
Table::TargetInfo::formNr
int formNr(const char *formnm) const
Definition: tabledef.h:123
StringInpSpec
Specifications for character string inputs.
Definition: datainpspec.h:588
Table::TargetInfo::convert
Coord convert(const Coord &) const
Table::TargetInfo::Selection::elems_
TypeSet< Elem > elems_
Definition: tabledef.h:166
sets.h
Table::TargetInfo
Description of a Logical piece of information.
Definition: tabledef.h:42
Table::TargetInfo::Selection::Elem::Elem
Elem()
Definition: tabledef.h:141
Table::FormatDesc::clear
void clear()
Definition: tabledef.h:251
rowcol.h
IOPar
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:55
Table::TargetInfo::Form::duplicate
Form * duplicate(const char *nm) const
Definition: tabledef.h:78
ObjectSet::clone
virtual ObjectSet * clone() const
Definition: objectset.h:50
Table::TargetInfo::Selection::form_
int form_
Definition: tabledef.h:165
TypeSet
Sets of (small) copyable elements.
Definition: commontypes.h:29
Table::TargetInfo::~TargetInfo
~TargetInfo()
Definition: tabledef.h:106

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