00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_FORMAT_JCAMPFILE_H
00008 #define BALL_FORMAT_JCAMPFILE_H
00009
00010 #ifndef BALL_FORMAT_LINEBASEDFILE_H
00011 # include <BALL/FORMAT/lineBasedFile.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
00015 # include <BALL/DATATYPE/stringHashMap.h>
00016 #endif
00017
00018 namespace BALL
00019 {
00030 class BALL_EXPORT JCAMPFile
00031 : public LineBasedFile
00032 {
00033 public:
00034
00038
00039 enum ContentType
00040 {
00042 STRING,
00044 NUMERIC,
00046 ARRAY
00047 };
00048
00050 class BALL_EXPORT JCAMPValue
00051 {
00052 public:
00054 String string_value;
00056 std::vector<double> numeric_value;
00058 ContentType type;
00059
00060 JCAMPValue() : string_value(""), numeric_value(), type(STRING) {}
00061
00062 bool operator == (const JCAMPValue& value) const
00063 ;
00064
00065 bool operator != (const JCAMPValue& value) const
00066 ;
00067 };
00068
00070 typedef std::pair<String, JCAMPValue> KeyValuePair;
00071
00073 typedef StringHashMap<JCAMPValue> EntryMap;
00074
00076 typedef StringHashMap<String> HeaderMap;
00077
00079
00082
00084 JCAMPFile() {}
00085
00087 JCAMPFile(const String& name, OpenMode open_mode = std::ios::in)
00088 throw(Exception::FileNotFound);
00089
00091 JCAMPFile(const JCAMPFile& file)
00092 throw(Exception::FileNotFound);
00093
00095 virtual ~JCAMPFile() {}
00096
00098
00101
00103 void read()
00104 throw(Exception::ParseError);
00105
00107 bool write()
00108 throw(File::CannotWrite);
00109
00111 HeaderMap& getHeader() { return header_; }
00112
00114 const HeaderMap& getHeader() const { return header_; }
00115
00117 EntryMap& getEntries() { return entries_; }
00118
00120 const EntryMap& getEntries() const { return entries_; }
00121
00123 const JCAMPValue& operator [] (const String& name) const { return entries_[name]; }
00124
00126 double getDoubleValue(const String& name) const
00127 throw(Exception::InvalidFormat);
00128
00130 Index getIntValue(const String& name) const
00131 throw(Exception::InvalidFormat);
00132
00134 bool hasEntry(const String& name) const { return entries_.has(name); }
00135
00137 bool hasHeader(const String& name) const { return header_.has(name); }
00138
00140 const JCAMPFile& operator = (const JCAMPFile& file) ;
00141
00143
00146
00149 bool operator == (const JCAMPFile& f) const ;
00150
00153 bool operator != (const JCAMPFile& f) const ;
00155
00156
00157 protected:
00158
00160 HeaderMap header_;
00161
00163 EntryMap entries_;
00164 };
00165 }
00166
00167 #endif // BALL_FORMAT_JCAMPFILE_H