BALL 1.5.0
Loading...
Searching...
No Matches
CIFFile.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_FORMAT_CIFFILE_H
6#define BALL_FORMAT_CIFFILE_H
7
8#ifndef BALL_SYSTEM_FILE_H
9# include <BALL/SYSTEM/file.h>
10#endif
11
12#ifndef BALL_DATATYPE_STRINGHASHMAP_H
14#endif
15
16#ifndef BALL_KERNEL_MOLECULE_H
17# include <BALL/KERNEL/molecule.h>
18#endif
19
20#include <map>
21
22#define CIFPARSER_LINE_LENGTH 2550
23
24namespace BALL
25{
33 : public File
34 {
35 public:
36
38 class Item
39 {
40 public:
41
43
44 Item(const Item& item);
45
46 virtual ~Item();
47
49 void clear();
50 void addPair(String key, String value);
51 void startLoop();
52 void addTag(String tag);
53 void addValue(String value);
54
57
58 /* a data item may be a tag-value pair or a table */
59 bool is_loop;
60
62 //StringHashMap< Index > data;
64 std::vector<String> keys;
66 std::vector<std::vector<String> > values;
67
69 std::pair<String, String> entry;
70
71 std::ostream& operator >> (std::ostream& os) const;
72
73 };
74
77 {
78 public:
79
80 void clear();
81 void start(String name);
82 void addDataItem(Item item);
83 void setCategory(String cat) {category = cat;};
84
85 std::ostream& operator >> (std::ostream& os) const;
86 const String& getCategory() const {return category;};
87
89 const Item& getDataItem(const String& item_name) const;
90 // we allow manipulation
91 Item& getDataItem(const String& item_name);
92
93 const String& getDataItemValue(const String& item_name) const;
94 // we allow manipulation
95 String& getDataItemValue(const String& item_name);
96
97
98
99 bool hasItem (const String& item_name) const;
100 String getItemValue(const String& name) const;
101
102
105 String category; // always first_item.entry.second
106
108 std::vector<Item> items;
110
112
113 };
114
117 {
118 public:
119
122 Datacontent(SaveFrame new_saveframe);
123 Datacontent(Item new_item);
124
127
130
133
134 std::ostream& operator >> (std::ostream& os) const;
135
136 };
137
140 {
141 public:
143 void clear();
144
146 void start(String blockname);
147
148 void insertDatacontent(const Datacontent& content);
149 void insertDatacontent(const SaveFrame& new_saveframe);
150 void insertDatacontent(const Item& item);
151
152 const Item& getDataItem(const String& item_name) const;
153 Item& getDataItem(const String& item_name);
154
157 const std::vector<Index> getSaveframeIndicesByCategory(const String& name) const;
158 std::vector<Index> getSaveframeIndicesByCategory(const String& name);
159 /* Returns copies of saveframes of category name */
160 std::vector<SaveFrame> getSaveframesByCategory(const String& name) const;
161
162
165 const SaveFrame& getSaveframeByName(const String& name) const;
167
168 const SaveFrame& getSaveframeByIndex(const Index index) const;
170
171
174 //
175 bool hasSaveframeName(const String& name) const;
176 bool hasSaveframeCategory(const String& name) const;
177 bool hasItem(const String& name) const;
178
180 void setName(String blockname);
181
182 std::ostream& operator >> (std::ostream& os) const;
184
186
188 std::vector<Datacontent> data;
189
192 //StringHashMap<std::vector<Index> > saveframe_categories;
193 std::multimap<String, Index> saveframe_categories;
194
197
200 vector<SaveFrame> dummy_saveframes_;
201 vector<Index> dummy_indices_;
202
203 };
204
206 struct State
207 {
209 };
210
214
218
222 CIFFile(const String& filename, File::OpenMode open_mode = std::ios::in);
223
226 virtual ~CIFFile();
227
229
233
237 virtual bool write();
238
242 virtual bool read();
243
245
248 void inSafeframe(const char* name);
249
250 void inItem(const char* name);
251
252 void inDatablock(const char* name);
253
254 void insertDatablock(const Datablock& datablock);
255
256 const Datablock& getDatablock(const String& name) const;
257
258
259 // we allow manipulation :-)
261
262 bool hasDatablock(const String& name) const;
263
264 void setMolecule(Molecule* molecule);
265
268
269 static State state;
270
271 protected:
272 virtual void initRead_();
273
275
279
281 vector<Datablock> datablocks_;
282 };
283}
284#endif // BALL_FORMAT_CIFFILE_H
void setMolecule(Molecule *molecule)
CIFFile(const String &filename, File::OpenMode open_mode=std::ios::in)
void inDatablock(const char *name)
void inSafeframe(const char *name)
StringHashMap< Index > datablocks_hash_
Definition CIFFile.h:280
virtual ~CIFFile()
virtual bool read()
void clearParameters()
String current_datablock_
Definition CIFFile.h:276
Datablock & getDatablock(const String &name)
virtual void initRead_()
bool hasDatablock(const String &name) const
vector< Datablock > datablocks_
Definition CIFFile.h:281
const Datablock & getDatablock(const String &name) const
virtual bool write()
String current_item_
Definition CIFFile.h:278
void inItem(const char *name)
String current_saveframe_
Definition CIFFile.h:277
void insertDatablock(const Datablock &datablock)
Molecule * molecule_
Definition CIFFile.h:274
static State state
Definition CIFFile.h:269
void addTag(String tag)
std::pair< String, String > entry
Definition CIFFile.h:69
std::vector< String > keys
Definition CIFFile.h:64
std::vector< std::vector< String > > values
Definition CIFFile.h:66
Index getKeyIndex(String key)
void addValue(String value)
void addPair(String key, String value)
Item(const Item &item)
Item & getDataItem(const String &item_name)
const String & getDataItemValue(const String &item_name) const
void addDataItem(Item item)
StringHashMap< Index > pair_items
Definition CIFFile.h:109
std::vector< Item > items
Definition CIFFile.h:108
String & getDataItemValue(const String &item_name)
const String & getCategory() const
Definition CIFFile.h:86
bool hasItem(const String &item_name) const
const Item & getDataItem(const String &item_name) const
String getItemValue(const String &name) const
void setCategory(String cat)
Definition CIFFile.h:83
void start(String name)
Datacontent(SaveFrame new_saveframe)
Datacontent(Item new_item)
Item & getDataItem(const String &item_name)
std::vector< SaveFrame > getSaveframesByCategory(const String &name) const
const SaveFrame & getSaveframeByIndex(const Index index) const
const Item & getDataItem(const String &item_name) const
bool hasItem(const String &name) const
SaveFrame & getSaveframeByName(const String &name)
SaveFrame dummy_saveframe_
Definition CIFFile.h:199
const SaveFrame & getSaveframeByName(const String &name) const
void insertDatacontent(const SaveFrame &new_saveframe)
vector< SaveFrame > dummy_saveframes_
Definition CIFFile.h:200
StringHashMap< Index > item_names
Definition CIFFile.h:196
const std::vector< Index > getSaveframeIndicesByCategory(const String &name) const
void insertDatacontent(const Item &item)
vector< Index > dummy_indices_
Definition CIFFile.h:201
bool hasSaveframeCategory(const String &name) const
std::multimap< String, Index > saveframe_categories
Definition CIFFile.h:193
SaveFrame & getSaveframeByIndex(const Index index)
void insertDatacontent(const Datacontent &content)
bool hasSaveframeName(const String &name) const
std::vector< Datacontent > data
Definition CIFFile.h:188
StringHashMap< Index > saveframe_names
Definition CIFFile.h:191
void setName(String blockname)
void start(String blockname)
std::vector< Index > getSaveframeIndicesByCategory(const String &name)
CIFFile * current_parser
Definition CIFFile.h:208
std::ios::openmode OpenMode
Definition file.h:165
#define BALL_EXPORT