00001 #ifndef tableascio_h
00002 #define tableascio_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bufstringset.h"
00016 #include "repos.h"
00017 #include <iosfwd>
00018 class IOPar;
00019 class UnitOfMeasure;
00020
00021 namespace Table
00022 {
00023
00024 class FormatDesc;
00025 class ImportHandler;
00026 class ExportHandler;
00027 class Converter;
00028 class FileFormatRepository;
00029
00030 mGlobal FileFormatRepository& FFR();
00031
00032
00041 mClass AscIO
00042 {
00043 public:
00044
00045 AscIO( const FormatDesc& fd )
00046 : fd_(fd)
00047 , imphndlr_(0)
00048 , exphndlr_(0)
00049 , cnvrtr_(0)
00050 , needfullline_(false)
00051 , hdrread_(false) { units_.allowNull(true);}
00052 virtual ~AscIO();
00053
00054 const FormatDesc& desc() const { return fd_; }
00055 const char* errMsg() const { return errmsg_.str(); }
00056
00057 protected:
00058
00059 const FormatDesc& fd_;
00060 mutable BufferString errmsg_;
00061 BufferStringSet vals_;
00062 ObjectSet<const UnitOfMeasure> units_;
00063 ImportHandler* imphndlr_;
00064 ExportHandler* exphndlr_;
00065 Converter* cnvrtr_;
00066 mutable bool hdrread_;
00067 bool needfullline_;
00068 BufferStringSet fullline_;
00069
00070 friend class AscIOImp_ExportHandler;
00071 friend class AscIOExp_ImportHandler;
00072
00073 void emptyVals() const;
00074 void addVal(const char*,const UnitOfMeasure*) const;
00075 bool getHdrVals(std::istream&) const;
00076 int getNextBodyVals(std::istream&) const;
00078 bool putHdrVals(std::ostream&) const;
00079 bool putNextBodyVals(std::ostream&) const;
00080
00081 const char* text(int) const;
00082 int getIntValue(int,int udf=mUdf(int)) const;
00083 float getfValue(int,float udf=mUdf(float)) const;
00084 double getdValue(int,double udf=mUdf(double)) const;
00085
00086
00087 int formOf(bool hdr,int iinf) const;
00088 int columnOf(bool hdr,int iinf,int ielem) const;
00089
00090 };
00091
00092
00096 mClass FileFormatRepository
00097 {
00098 public:
00099
00100 void getGroups(BufferStringSet&) const;
00101 void getFormats(const char* grp,BufferStringSet&) const;
00102
00103 const IOPar* get(const char* grp,const char* nm) const;
00104 void set(const char* grp,const char* nm,
00105 IOPar*,Repos::Source);
00107
00108 bool write(Repos::Source) const;
00109
00110 protected:
00111
00112 FileFormatRepository();
00113 void addFromFile(const char*,Repos::Source);
00114 const char* grpNm(int) const;
00115 int gtIdx(const char*,const char*) const;
00116
00117 struct Entry
00118 {
00119 Entry( Repos::Source src, IOPar* iop )
00120 : iopar_(iop), src_(src) {}
00121 ~Entry();
00122
00123 IOPar* iopar_;
00124 Repos::Source src_;
00125 };
00126
00127 ObjectSet<Entry> entries_;
00128
00129 mGlobal friend FileFormatRepository& FFR();
00130
00131 };
00132
00133
00134 };
00135
00136
00137 #endif