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 00081 JCAMPFile() {} 00082 00086 JCAMPFile(const String& name, OpenMode open_mode = std::ios::in); 00087 00090 virtual ~JCAMPFile() {} 00091 00093 00096 00100 void read(); 00101 00105 bool write(); 00106 00108 HeaderMap& getHeader() { return header_; } 00109 00111 const HeaderMap& getHeader() const { return header_; } 00112 00114 EntryMap& getEntries() { return entries_; } 00115 00117 const EntryMap& getEntries() const { return entries_; } 00118 00120 const JCAMPValue& operator [] (const String& name) const { return entries_[name]; } 00121 00125 double getDoubleValue(const String& name) const; 00126 00130 Index getIntValue(const String& name) const; 00131 00133 bool hasEntry(const String& name) const { return entries_.has(name); } 00134 00136 bool hasHeader(const String& name) const { return header_.has(name); } 00137 00139 const JCAMPFile& operator = (const JCAMPFile& file) ; 00140 00142 00145 00148 bool operator == (const JCAMPFile& f) const; 00149 00152 bool operator != (const JCAMPFile& f) const; 00154 00155 00156 protected: 00157 00159 HeaderMap header_; 00160 00162 EntryMap entries_; 00163 }; 00164 } 00165 00166 #endif // BALL_FORMAT_JCAMPFILE_H