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

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