/usr/include/BALL/FORMAT/CIFFile.h is in libball1.4-dev 1.4.3~beta1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_FORMAT_CIFFILE_H
#define BALL_FORMAT_CIFFILE_H
#ifndef BALL_SYSTEM_FILE_H
# include <BALL/SYSTEM/file.h>
#endif
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
# include <BALL/DATATYPE/stringHashMap.h>
#endif
#ifndef BALL_KERNEL_MOLECULE_H
# include <BALL/KERNEL/molecule.h>
#endif
#include <map>
#define CIFPARSER_LINE_LENGTH 2550
namespace BALL
{
/** CIF file class.
* This class enables BALL to read and write input and output CIF files for
* the NMR shift application.
*
* \ingroup StructureFormats
*/
class BALL_EXPORT CIFFile
: public File
{
public:
/** Nested class for the dataitems of the CIFFile **/
class Item
{
public:
Item();
Item(const Item& item);
virtual ~Item();
/** Acessors **/
void clear();
void addPair(String key, String value);
void startLoop();
void addTag(String tag);
void addValue(String value);
/** Returns the index of the Item identifier key. If there is no such key, -1 is returned. **/
Index getKeyIndex(String key);
/* a data item may be a tag-value pair or a table */
bool is_loop;
/** Stores all loop data indices **/
//StringHashMap< Index > data;
/** Stores all raw loop data **/
std::vector<String> keys;
/** Stores the loop data per line **/
std::vector<std::vector<String> > values;
/** Stores the tag-value pair in key - value format **/
std::pair<String, String> entry;
std::ostream& operator >> (std::ostream& os) const;
};
/** Nested class for the saveframes of the CIFFile **/
class SaveFrame
{
public:
void clear();
void start(String name);
void addDataItem(Item item);
void setCategory(String cat) {category = cat;};
std::ostream& operator >> (std::ostream& os) const;
const String& getCategory() const {return category;};
/** Returns a dummy Dataitem, if no item with such name exists **/
const Item& getDataItem(const String& item_name) const;
// we allow manipulation
Item& getDataItem(const String& item_name);
const String& getDataItemValue(const String& item_name) const;
// we allow manipulation
String& getDataItemValue(const String& item_name);
bool hasItem (const String& item_name) const;
String getItemValue(const String& name) const;
/** The name of this saveframe **/
String framename;
String category; // always first_item.entry.second
/** Stores all dataitems of the saveframe **/
std::vector<Item> items;
StringHashMap<Index> pair_items;
Item dummy_data_item_;
};
/** Nested class for the data entity of the CIFFile **/
class Datacontent
{
public:
/** Constructors **/
Datacontent();
Datacontent(SaveFrame new_saveframe);
Datacontent(Item new_item);
/** all data of a datablock is either a saveframe or a single item **/
bool is_saveframe;
/** Stores the saveframe **/
SaveFrame saveframe;
/** Stores the item **/
Item dataitem;
std::ostream& operator >> (std::ostream& os) const;
};
/** Nested class for the datablock entity of the CIFFile **/
class Datablock
{
public:
/** Clears the Datablock **/
void clear();
/** Sets the name of a new Datablock **/
void start(String blockname);
void insertDatacontent(const Datacontent& content);
void insertDatacontent(const SaveFrame& new_saveframe);
void insertDatacontent(const Item& item);
const Item& getDataItem(const String& item_name) const;
Item& getDataItem(const String& item_name);
/** Returns the saveframe of category name.
*/
const std::vector<Index> getSaveframeIndicesByCategory(const String& name) const;
std::vector<Index> getSaveframeIndicesByCategory(const String& name);
/* Returns copies of saveframes of category name */
std::vector<SaveFrame> getSaveframesByCategory(const String& name) const;
/** Returns the saveframe labeled 'name'.
*/
const SaveFrame& getSaveframeByName(const String& name) const;
SaveFrame& getSaveframeByName(const String& name);
const SaveFrame& getSaveframeByIndex(const Index index) const;
SaveFrame& getSaveframeByIndex(const Index index);
/** Returns true if the datablock contains a Saveframe of category name.
*/
//
bool hasSaveframeName(const String& name) const;
bool hasSaveframeCategory(const String& name) const;
bool hasItem(const String& name) const;
/** Sets the name of a Datablock **/
void setName(String blockname);
std::ostream& operator >> (std::ostream& os) const;
//////////////////////////////////////////////////
/** The name of this saveframe **/
String name;
/** Stores the datablock content **/
std::vector<Datacontent> data;
/** Hashes the saveframes - we assume, that they are unique**/
StringHashMap<Index> saveframe_names;
//StringHashMap<std::vector<Index> > saveframe_categories;
std::multimap<String, Index> saveframe_categories;
/** Hashes the items*/
StringHashMap<Index> item_names;
Item dummy_data_item_;
SaveFrame dummy_saveframe_;
vector<SaveFrame> dummy_saveframes_;
vector<Index> dummy_indices_;
};
/** State of the parser **/
struct State
{
CIFFile* current_parser;
};
/** @name Constructors and Destructors
*/
//@{
/** Default constructor
*/
CIFFile();
/** Detailed constructor
* @throw Exception::FileNotFound if the file could not be opened
*/
CIFFile(const String& filename, File::OpenMode open_mode = std::ios::in);
/** Destructor
*/
virtual ~CIFFile();
//@}
/** @name Reading and Writing of Crytallographic Information
*/
//@{
/** Write a CIFFile.
* @throw File::CannotWrite if writing to the file failed
*/
virtual bool write();
/** Read a CIFFile.
* @throw Exception::ParseError if a syntax error was encountered
*/
virtual bool read();
//@}
/** @name Accessors
*/
//@{
void inSafeframe(const char* name);
void inItem(const char* name);
void inDatablock(const char* name);
void insertDatablock(const Datablock& datablock);
const Datablock& getDatablock(const String& name) const;
// we allow manipulation :-)
Datablock& getDatablock(const String& name);
bool hasDatablock(const String& name) const;
void setMolecule(Molecule* molecule);
void clearParameters();
//@}
static State state;
protected:
virtual void initRead_();
Molecule* molecule_;
String current_datablock_;
String current_saveframe_;
String current_item_;
StringHashMap<Index> datablocks_hash_;
vector<Datablock> datablocks_;
};
}
#endif // BALL_FORMAT_CIFFILE_H
|