00001 #ifndef tabledef_h
00002 #define tabledef_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "sets.h"
00016 #include "rowcol.h"
00017 #include "namedobj.h"
00018 #include "datainpspec.h"
00019 #include "propertyref.h"
00020
00021 class UnitOfMeasure;
00022
00023
00024 namespace Table
00025 {
00026
00027 enum ReqSpec { Optional=0, Required=1, Hidden=2 };
00028
00041 mClass TargetInfo : public NamedObject
00042 {
00043 public:
00044
00061 struct Form : NamedObject
00062 {
00063 Form( const char* nm, DataInpSpec* spec )
00064 : NamedObject(nm)
00065 { add( spec ); }
00066 Form( const char* nm, const DataInpSpec& spec )
00067 : NamedObject(nm)
00068 { add( spec.clone() ); }
00069
00070 ~Form() { deepErase(specs_); }
00071
00072 Form& add( const DataInpSpec& spec )
00073 { specs_ += spec.clone(); return *this; }
00074 Form& add( DataInpSpec* spec )
00075 { specs_ += spec ? spec : new StringInpSpec;
00076 return *this; }
00077
00078 Form* duplicate( const char* nm ) const
00079 {
00080 Form* ret = new Form( nm, *specs_[0] );
00081 for ( int idx=1; idx<specs_.size(); idx++ )
00082 ret->specs_ += specs_[idx]->clone();
00083 return ret;
00084 }
00085
00086 ObjectSet<DataInpSpec> specs_;
00087 };
00088
00089
00090 TargetInfo( const char* nm, ReqSpec rs=Optional )
00092 : NamedObject(nm), req_(rs)
00093 , proptype_(PropertyRef::Other)
00094 { add( nm ); }
00095 TargetInfo( const char* nm, DataInpSpec* spec,
00096 ReqSpec rs=Optional,
00097 PropertyRef::StdType p=PropertyRef::Other )
00098 : NamedObject(nm), req_(rs), proptype_(p)
00099 { add( nm, spec ); }
00100 TargetInfo( const char* nm, const DataInpSpec& spec,
00101 ReqSpec rs=Optional,
00102 PropertyRef::StdType p=PropertyRef::Other )
00103 : NamedObject(nm), req_(rs), proptype_(p)
00104 { add( nm, spec ); }
00105
00106 ~TargetInfo() { deepErase( forms_ ); }
00107
00108 TargetInfo& add( const char* nm, DataInpSpec* spec=0 )
00109 { forms_ += new Form( nm, spec ); return *this; }
00110 TargetInfo& add( const char* nm, const DataInpSpec& spec )
00111 { forms_ += new Form( nm, spec ); return *this; }
00112 TargetInfo& add( Form* frm )
00113 { forms_ += frm; return *this; }
00114
00115 bool isOptional() const { return req_ != Required; }
00116 bool isHidden() const { return req_ == Hidden; }
00117 PropertyRef::StdType propertyType() const { return proptype_; }
00118 void setPropertyType( PropertyRef::StdType p )
00119 { proptype_ = p; }
00120 int nrForms() const { return forms_.size(); }
00121 Form& form( int idx ) { return *forms_[idx]; }
00122 const Form& form( int idx ) const { return *forms_[idx]; }
00123 int formNr( const char* formnm ) const
00124 {
00125 for ( int idx=0; idx<forms_.size(); idx++ )
00126 if ( forms_[idx]->name() == formnm )
00127 return idx;
00128 return -1;
00129 }
00130
00136 struct Selection
00137 {
00139 struct Elem
00140 {
00141 Elem()
00142 : pos_(0,-1) {}
00143 Elem( const RowCol& rc, const char* kw=0 )
00144 : pos_(rc), keyword_(kw) {}
00145 Elem( const char* s )
00146 : pos_(0,-1), val_(s) {}
00147
00148 bool isInFile() const
00149 { return pos_.col >= 0; }
00150 bool isKeyworded() const
00151 { return isInFile() && !keyword_.isEmpty();}
00152 bool isSpecified() const
00153 { return !val_.isEmpty(); }
00154 bool isEmpty() const
00155 { return !isInFile() && !isSpecified();}
00156 bool operator ==( const Elem& v ) const
00157 { return pos_ == v.pos_ && val_ == v.val_
00158 && keyword_ == v.keyword_; }
00159
00160 RowCol pos_;
00161 BufferString keyword_;
00162 BufferString val_;
00163 };
00164
00165 int form_;
00166 TypeSet<Elem> elems_;
00167 const UnitOfMeasure* unit_;
00168
00169 Selection()
00170 : form_(0), unit_(0) {}
00171
00172 bool havePos( int ielem ) const
00173 { return ielem < elems_.size()
00174 && elems_[ielem].isInFile(); }
00175 bool isKeyworded( int ielem ) const
00176 { return ielem < elems_.size()
00177 && elems_[ielem].isKeyworded(); }
00178 bool isInFile( int ielem=0 ) const
00179 { return ielem < elems_.size()
00180 && elems_[ielem].isInFile(); }
00181 const char* getVal( int ielem ) const
00182 { return ielem >= elems_.size() ? 0
00183 : elems_[ielem].val_.buf(); }
00184 bool isFilled() const
00185 { return elems_.size() > 0 && !elems_[0].isEmpty(); }
00186 };
00187
00188 mutable Selection selection_;
00189
00190 void fillPar(IOPar&) const;
00191 void usePar(const IOPar&);
00192
00193 static TargetInfo* mkHorPosition( bool isreq )
00194 { return mkPos(true,isreq); }
00196 static TargetInfo* mkZPosition( bool isreq, bool withunits=true )
00197 { return mkPos(false,isreq,withunits); }
00198 static TargetInfo* mkDepthPosition( bool isreq, bool withunits=true )
00199 { return mkPos(false,isreq,withunits,1); }
00200 static TargetInfo* mkTimePosition( bool isreq, bool withunits=true )
00201 { return mkPos(false,isreq,withunits,-1); }
00202
00203 protected:
00204
00205 ReqSpec req_;
00206 PropertyRef::StdType proptype_;
00207 ObjectSet<Form> forms_;
00208
00209 static TargetInfo* mkPos(bool,bool,bool wu=false,int zopt=0);
00210
00211 };
00212
00213
00216 mClass FormatDesc : public NamedObject
00217 {
00218 public:
00219 FormatDesc( const char* nm )
00220 : NamedObject(nm)
00221 , nrhdrlines_(0)
00222 , eohtokencol_(-1) {}
00223 ~FormatDesc()
00224 { deepErase( headerinfos_ ); deepErase( bodyinfos_ ); }
00225
00226 ObjectSet<TargetInfo> headerinfos_;
00227 ObjectSet<TargetInfo> bodyinfos_;
00228
00229 int nrhdrlines_;
00230 BufferString eohtoken_;
00231 int eohtokencol_;
00232 BufferString eobtoken_;
00233
00234 bool needEOHToken() const
00235 { return nrhdrlines_ < 0 && !eohtoken_.isEmpty(); }
00236 int nrHdrLines() const
00237 { return needEOHToken() ? mUdf(int)
00238 : nrhdrlines_ > 0 ? nrhdrlines_ : 0; }
00239 bool haveEOBToken() const
00240 { return !eobtoken_.isEmpty(); }
00241
00242 bool isGood() const;
00243 bool bodyUsesCol(int) const;
00244
00245 void fillPar(IOPar&) const;
00246 void usePar(const IOPar&);
00247
00248 void clear()
00249 {
00250 nrhdrlines_ = eohtokencol_ = 0;
00251 eohtoken_.setEmpty(); eobtoken_.setEmpty();
00252 }
00253 };
00254
00255 };
00256
00257
00258 #endif