00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_FORMAT_JCAMPFILE_H 00006 #define BALL_FORMAT_JCAMPFILE_H 00007 00008 #ifndef BALL_FORMAT_LINEBASEDFILE_H 00009 # include <BALL/FORMAT/lineBasedFile.h> 00010 #endif 00011 00012 #ifndef BALL_DATATYPE_STRINGHASHMAP_H 00013 # include <BALL/DATATYPE/stringHashMap.h> 00014 #endif 00015 00016 namespace BALL 00017 { 00028 class BALL_EXPORT JCAMPFile 00029 : public LineBasedFile 00030 { 00031 public: 00032 00036 // The value types supported by JCAMP 00037 enum ContentType 00038 { 00040 STRING, 00042 NUMERIC, 00044 ARRAY 00045 }; 00046 00048 class BALL_EXPORT JCAMPValue 00049 { 00050 public: 00052 String string_value; 00054 std::vector<double> numeric_value; 00056 ContentType type; 00057 00058 JCAMPValue() : string_value(""), numeric_value(), type(STRING) {} 00059 00060 bool operator == (const JCAMPValue& value) const; 00061 00062 bool operator != (const JCAMPValue& value) const; 00063 }; 00064 00066 typedef std::pair<String, JCAMPValue> KeyValuePair; 00067 00069 typedef StringHashMap<JCAMPValue> EntryMap; 00070 00072 typedef StringHashMap<String> HeaderMap; 00073 00075 00078 00080 JCAMPFile() {} 00081 00083 JCAMPFile(const String& name, OpenMode open_mode = std::ios::in) 00084 throw(Exception::FileNotFound); 00085 00087 virtual ~JCAMPFile() {} 00088 00090 00093 00095 void read() 00096 throw(Exception::ParseError); 00097 00099 bool write() 00100 throw(File::CannotWrite); 00101 00103 HeaderMap& getHeader() { return header_; } 00104 00106 const HeaderMap& getHeader() const { return header_; } 00107 00109 EntryMap& getEntries() { return entries_; } 00110 00112 const EntryMap& getEntries() const { return entries_; } 00113 00115 const JCAMPValue& operator [] (const String& name) const { return entries_[name]; } 00116 00118 double getDoubleValue(const String& name) const 00119 throw(Exception::InvalidFormat); 00120 00122 Index getIntValue(const String& name) const 00123 throw(Exception::InvalidFormat); 00124 00126 bool hasEntry(const String& name) const { return entries_.has(name); } 00127 00129 bool hasHeader(const String& name) const { return header_.has(name); } 00130 00132 const JCAMPFile& operator = (const JCAMPFile& file) ; 00133 00135 00138 00141 bool operator == (const JCAMPFile& f) const; 00142 00145 bool operator != (const JCAMPFile& f) const; 00147 00148 00149 protected: 00150 00152 HeaderMap header_; 00153 00155 EntryMap entries_; 00156 }; 00157 } 00158 00159 #endif // BALL_FORMAT_JCAMPFILE_H