00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_FORMAT_CIFFILE_H
00008 #define BALL_FORMAT_CIFFILE_H
00009
00010 #ifndef BALL_SYSTEM_FILE_H
00011 # include <BALL/SYSTEM/file.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
00015 # include <BALL/DATATYPE/stringHashMap.h>
00016 #endif
00017
00018 #ifndef BALL_KERNEL_MOLECULE_H
00019 # include <BALL/KERNEL/molecule.h>
00020 #endif
00021
00022 #define CIFPARSER_LINE_LENGTH 2550
00023
00024 namespace BALL
00025 {
00032 class BALL_EXPORT CIFFile
00033 : public File
00034 {
00035 public:
00036 BALL_CREATE(CIFFile)
00037
00038
00039 class Item
00040 {
00041 public:
00042
00044 void clear() throw();
00045 void addPair(String key, String value) throw();
00046 void startLoop() throw();
00047 void addTag(String tag) throw();
00048 void addValue(String value) throw();
00049
00050
00051 bool is_loop;
00052
00054
00056 std::vector<String> keys;
00058 std::vector<std::vector<String> > values;
00059
00061 std::pair<String, String> entry;
00062
00063 void operator >> (std::ostream& os) const
00064 throw();
00065
00066 };
00067
00069 class SaveFrame
00070 {
00071 public:
00072
00074 String framename;
00075
00077 std::vector<Item> items;
00078
00079 void clear();
00080 void start(String name);
00081 void addDataItem(Item item);
00082
00083 void operator >> (std::ostream& os) const
00084 throw();
00085
00086 };
00087
00089 class Datacontent
00090 {
00091 public:
00092
00094 Datacontent() throw();
00095 Datacontent(SaveFrame new_saveframe) throw();
00096 Datacontent(Item new_item) throw();
00097
00099 bool is_saveframe;
00100
00102 SaveFrame sframe;
00103
00105 Item dataitem;
00106
00107 void operator >> (std::ostream& os) const
00108 throw();
00109
00110 };
00111
00113 class Datablock
00114 {
00115 public:
00116
00118 String name;
00119
00121 std::vector<Datacontent> data;
00122
00124 void clear();
00125
00127 void start(String blockname);
00128
00129 void insertDatacontent(Datacontent content) throw();
00130 void insertDatacontent(const SaveFrame& new_saveframe) throw();
00131 void insertDatacontent(const Item item) throw();
00132
00134 void setName(String blockname);
00135
00136 void operator >> (std::ostream& os) const
00137 throw();
00138 };
00139
00141 struct State
00142 {
00143 CIFFile* current_parser;
00144 };
00145
00149
00152 CIFFile()
00153 throw();
00154
00157 CIFFile(const CIFFile& file)
00158 throw(Exception::FileNotFound);
00159
00162 CIFFile(const String& filename, File::OpenMode open_mode = std::ios::in)
00163 throw(Exception::FileNotFound);
00164
00167 virtual ~CIFFile()
00168 throw();
00169
00171
00174
00178 const CIFFile& operator = (const CIFFile& rhs)
00179 throw(Exception::FileNotFound);
00180
00182
00186
00189 virtual bool write()
00190 throw(File::CannotWrite);
00191
00194 virtual bool read()
00195 throw(Exception::ParseError);
00196
00198
00201 void inSafeframe(const char* name)
00202 throw();
00203
00204 void inItem(const char* name)
00205 throw();
00206
00207 void inDatablock(const char* name)
00208 throw();
00209
00210 void insertDatablock(const Datablock& datablock)
00211 throw();
00212
00213 const Datablock getDatablock(const String& name)
00214 throw();
00215
00216 void setMolecule(Molecule* molecule)
00217 throw();
00218
00219 void clearParameters()
00220 throw();
00222
00223 static State state;
00224
00225 protected:
00226 virtual void initRead_();
00227
00228 Molecule* molecule_;
00229
00230 String current_datablock_;
00231 String current_saveframe_;
00232 String current_item_;
00233
00234 StringHashMap<Datablock> datablocks_;
00235 };
00236 }
00237 #endif // BALL_FORMAT_CIFFILE_H