• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

iopar.h

00001 #ifndef iopar_h
00002 #define iopar_h
00003 
00004 /*+
00005 ________________________________________________________________________
00006 
00007  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
00008  Author:        A.H. Bril
00009  Date:          21-12-1995
00010  RCS:           $Id: iopar.h,v 1.63 2010-11-09 16:01:18 cvsbert Exp $
00011 ________________________________________________________________________
00012 
00013 -*/
00014  
00015 #include "namedobj.h"
00016 #include "sets.h"
00017 #include "fixedstring.h"
00018 #include "samplingdata.h"
00019 
00020 class BinID;
00021 class BufferString;
00022 class BufferStringSet;
00023 class Coord;
00024 class Color;
00025 class Coord3;
00026 class MultiID;
00027 class SeparString;
00028 class ascistream;
00029 class ascostream;
00030 
00031 /*\brief generalised set of parameters of the keyword-value type.
00032 
00033 Part of the function of this class is as in an STL map<string,string> .
00034 Passing a keyword will return the appropriate value.
00035 
00036 Tools around this basic idea are paring into other types, key composition,
00037 reading/writing to/from file, merging, and more.
00038 
00039 dumpPretty() is used for reports.  The title of the report is the name of the
00040 IOPar. If sKeyHdr and sKeySubHdr are the key, there will be a (sub)header
00041 with the value. Use add() rather than set(). Values may contain newlines.
00042 
00043 */
00044 
00045 
00046 mClass IOPar : public NamedObject
00047 {
00048 public:
00049                         IOPar(const char* nm=0); 
00050                         IOPar(ascistream&);
00051                         IOPar(const IOPar&);
00052                         ~IOPar();
00053     IOPar&              operator =(const IOPar&);
00054     inline bool         operator ==( const IOPar& iop ) const
00055                         { return isEqual(iop); }
00056     inline bool         operator !=( const IOPar& iop ) const
00057                         { return !isEqual(iop); }
00058 
00059     int                 size() const;
00060     inline bool         isEmpty() const         { return size() == 0; }
00061     bool                isEqual(const IOPar&,bool need_same_order=false) const;
00062 
00063     int                 indexOf(const char* key) const;
00064     const char*         getKey(int) const;
00065     const char*         getValue(int) const;
00066     bool                setKey(int,const char*);
00067     void                setValue(int,const char*);
00068     void                remove(int);
00069     void                remove(const char* key);
00070     bool                hasKey( const char* s ) const
00071                         { return !find(s).isEmpty(); }
00072     const char*         findKeyFor(const char*,int nr=0) const;
00074     void                removeWithKey(const char* globexpression);
00077 
00078     void                setEmpty();
00080     void                merge(const IOPar&);
00082     static const char*  compKey(const char*,const char*);
00084     static const char*  compKey(const char*,int);
00086     IOPar*              subselect(const char*) const;
00088     IOPar*              subselect(int) const;
00090     void                removeSubSelection(const char*);
00092     void                removeSubSelection(int);
00094     void                mergeComp(const IOPar&,const char*);
00096 
00097 // GET functions
00098 
00099     FixedString         find(const char*) const;
00101     FixedString         operator[](const char*) const;
00103 
00104                         // Functions for getting 1,2,3 and 4 of the same type
00105 #define mIOParDeclFns(type) \
00106     bool                get(const char*,type&) const; \
00107     bool                get(const char*,type&,type&) const; \
00108     bool                get(const char*,type&,type&,type&) const; \
00109     bool                get(const char*,type&,type&,type&,type&) const
00110 
00111                         mIOParDeclFns(int);
00112                         mIOParDeclFns(od_uint32);
00113                         mIOParDeclFns(od_int64);
00114                         mIOParDeclFns(od_uint64);
00115                         mIOParDeclFns(float);
00116                         mIOParDeclFns(double);
00117 #undef mIOParDeclFns
00118     bool                getYN(const char*,bool&) const;
00119     bool                getYN(const char*,bool&,bool&) const;
00120     bool                getYN(const char*,bool&,bool&,bool&) const;
00121     bool                getYN(const char*,bool&,bool&,bool&,bool&) const;
00122     inline bool         isTrue( const char* key ) const
00123                         { bool is = false; return getYN(key,is) && is; }
00124     inline bool         isFalse( const char* key ) const
00125                         { bool is = true; return getYN(key,is) && !is; }
00126 
00127     bool                get(const char*,int&,int&,float&) const;
00128 
00129     bool                get(const char*,TypeSet<int>&) const;
00130     bool                get(const char*,TypeSet<od_uint32>&) const;
00131     bool                get(const char*,TypeSet<od_int64>&) const;
00132     bool                get(const char*,TypeSet<od_uint64>&) const;
00133     bool                get(const char*,TypeSet<double>&) const;
00134     bool                get(const char*,TypeSet<float>&) const;
00135 
00136     bool                get(const char*,BinID&) const;
00137     bool                get(const char*,Coord&) const;
00138     bool                get(const char*,Coord3&) const;
00139     bool                get(const char*,MultiID&) const;
00140     bool                get(const char*,Color&) const;
00141     bool                get(const char*,SeparString&) const;
00142     bool                get(const char*,BufferString&) const;
00143     bool                get(const char*,BufferString&,BufferString&) const;
00144     bool                get(const char*,BufferStringSet&) const;
00145     template <class T>
00146     bool                get(const char*,Interval<T>&) const;
00147     template <class T>
00148     bool                get(const char*,SamplingData<T>&) const;
00149 
00150     bool                getPtr(const char*,void*&) const;
00151 
00152 #define mIOParDeclFns(type) \
00153     bool                getScaled(const char*,type&,type applied_scale, \
00154                               bool set_to_undef_if_not_found) const; \
00155     bool                getScaled(const char*,type&,type&,type,bool) const; \
00156     bool                getScaled(const char*,type&,type&,type&,type, \
00157                                   bool) const; \
00158     bool                getScaled(const char*,type&,type&,type&,type&,type, \
00159                               bool) const
00160                         mIOParDeclFns(float);
00161                         mIOParDeclFns(double);
00162 #undef mIOParDeclFns
00163 
00164 
00165 // SET functions
00166 
00167     void                set(const char*,const char*);
00169     void                add(const char*,const char*);
00172                         // Functions for 1,2,3 and 4 of the same type
00173 #define mIOParDeclFns(fnnm,type) \
00174     void                fnnm(const char*,type); \
00175     void                fnnm(const char*,type,type); \
00176     void                fnnm(const char*,type,type,type); \
00177     void                fnnm(const char*,type,type,type,type)
00178 
00179                         mIOParDeclFns(set,int);
00180                         mIOParDeclFns(set,od_uint32);
00181                         mIOParDeclFns(set,od_int64);
00182                         mIOParDeclFns(set,od_uint64);
00183                         mIOParDeclFns(set,float);
00184                         mIOParDeclFns(set,double);
00185                         mIOParDeclFns(add,int);
00186                         mIOParDeclFns(add,od_uint32);
00187                         mIOParDeclFns(add,od_int64);
00188                         mIOParDeclFns(add,od_uint64);
00189                         mIOParDeclFns(add,float);
00190                         mIOParDeclFns(add,double);
00191 #undef mIOParDeclFns
00192 #define mIOParDeclYNFns(fnnm) \
00193     void                fnnm##YN(const char*,bool); \
00194     void                fnnm##YN(const char*,bool,bool); \
00195     void                fnnm##YN(const char*,bool,bool,bool); \
00196     void                fnnm##YN(const char*,bool,bool,bool,bool)
00197                         mIOParDeclYNFns(set);
00198                         mIOParDeclYNFns(add);
00199 #undef mIOParDeclYNFns
00200 
00201     void                set(const char*,int,int,float);
00202     void                setPtr(const char*,void*);
00203 
00204     void                set(const char*,const char*,const char*);
00205     void                set(const char*,const BinID&);
00206     void                set(const char*,const Coord&);
00207     void                set(const char*,const Coord3&);
00208     void                set(const char*,const MultiID&);
00209     void                set(const char*,const Color&);
00210     void                set(const char*,const SeparString&);
00211     void                set(const char*,const FixedString&);
00212     void                set(const char*,const BufferString&);
00213     void                set(const char*,const BufferString&,
00214                                         const BufferString&);
00215     void                set(const char*,const BufferStringSet&);
00216     template <class T>
00217     void                set(const char*,const Interval<T>&);
00218     template <class T>
00219     void                set(const char*,const SamplingData<T>&);
00220 
00221     void                set(const char*,const TypeSet<int>&);
00222     void                set(const char*,const TypeSet<od_uint32>&);
00223     void                set(const char*,const TypeSet<od_int64>&);
00224     void                set(const char*,const TypeSet<od_uint64>&);
00225     void                set(const char*,const TypeSet<double>&);
00226     void                set(const char*,const TypeSet<float>&);
00227 
00228 
00229 // I/O  functions
00230 
00231     // to/from string: 'serialisation'
00232     void                getFrom(const char*);
00233     void                getParsFrom(const char*);
00234     void                putTo(BufferString&) const;
00235     void                putParsTo(BufferString&) const;
00236 
00237     // to/from file
00238     void                getFrom(ascistream&);
00239     void                putTo(ascostream&) const;
00240     bool                read(const char* filename,const char* filetype,
00241                                 bool chktype=false);
00244     bool                read(std::istream&,const char* filetype,
00245                                 bool chktype=false);
00246     bool                write(const char* filename,const char* filetype) const;
00249     bool                write(std::ostream&,const char* filetyp) const;
00250     void                dumpPretty(std::ostream&) const;
00251 
00252     static const char*  sKeyDumpPretty()         { return "_pretty"; }
00253     static const char*  sKeyHdr()                { return "->";      }  
00254     static const char*  sKeySubHdr()             { return "-->";     }          
00255 
00256 protected:
00257 
00258     BufferStringSet&    keys_;
00259     BufferStringSet&    vals_;
00260 
00261 };
00262 
00263 
00264 template <class T>
00265 inline bool IOPar::get( const char* k, Interval<T>& i ) const
00266 {
00267     mDynamicCastGet(StepInterval<T>*,si,&i)
00268     return si ? get( k, i.start, i.stop, si->step )
00269               : get( k, i.start, i.stop );
00270 }
00271 
00272 
00273 template <class T>
00274 inline void IOPar::set( const char* k, const Interval<T>& i )
00275 {
00276     mDynamicCastGet(const StepInterval<T>*,si,&i)
00277     if ( si )   set( k, i.start, i.stop, si->step );
00278     else        set( k, i.start, i.stop );
00279 }
00280 
00281 
00282 template <class T>
00283 inline bool IOPar::get( const char* k, SamplingData<T>& sd ) const
00284 {
00285     return get( k, sd.start, sd.step );
00286 }
00287 
00288 
00289 template <class T>
00290 inline void IOPar::set( const char* k, const SamplingData<T>& sd )
00291 {
00292     set( k, sd.start, sd.step );
00293 }
00294 
00295 
00296 #endif

Generated on Tue Nov 30 2010 for Basic by  doxygen 1.7.1