Loading...
Searching...
No Matches
CIFFile.h
Go to the documentation of this file.
// -*- 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
{
class BALL_EXPORT CIFFile
: public File
{
public:
class Item
{
public:
Item();
Item(const Item& item);
virtual ~Item();
void clear();
void addPair(String key, String value);
void startLoop();
void addTag(String tag);
void addValue(String value);
Index getKeyIndex(String key);
/* a data item may be a tag-value pair or a table */
bool is_loop;
//StringHashMap< Index > data;
std::vector<String> keys;
std::vector<std::vector<String> > values;
std::pair<String, String> entry;
std::ostream& operator >> (std::ostream& os) const;
};
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;};
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;
String framename;
String category; // always first_item.entry.second
std::vector<Item> items;
StringHashMap<Index> pair_items;
Item dummy_data_item_;
};
class Datacontent
{
public:
Datacontent();
Datacontent(SaveFrame new_saveframe);
Datacontent(Item new_item);
bool is_saveframe;
SaveFrame saveframe;
Item dataitem;
std::ostream& operator >> (std::ostream& os) const;
};
class Datablock
{
public:
void clear();
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);
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;
const SaveFrame& getSaveframeByName(const String& name) const;
SaveFrame& getSaveframeByName(const String& name);
const SaveFrame& getSaveframeByIndex(const Index index) const;
SaveFrame& getSaveframeByIndex(const Index index);
//
bool hasSaveframeName(const String& name) const;
bool hasSaveframeCategory(const String& name) const;
bool hasItem(const String& name) const;
void setName(String blockname);
std::ostream& operator >> (std::ostream& os) const;
String name;
std::vector<Datacontent> data;
StringHashMap<Index> saveframe_names;
//StringHashMap<std::vector<Index> > saveframe_categories;
std::multimap<String, Index> saveframe_categories;
StringHashMap<Index> item_names;
Item dummy_data_item_;
SaveFrame dummy_saveframe_;
vector<SaveFrame> dummy_saveframes_;
vector<Index> dummy_indices_;
};
struct State
{
CIFFile* current_parser;
};
CIFFile();
CIFFile(const String& filename, File::OpenMode open_mode = std::ios::in);
virtual ~CIFFile();
virtual bool write();
virtual bool read();
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
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::CIFFile::Datablock
Definition CIFFile.h:140
BALL::CIFFile::Datablock::getDataItem
Item & getDataItem(const String &item_name)
BALL::CIFFile::Datablock::getSaveframesByCategory
std::vector< SaveFrame > getSaveframesByCategory(const String &name) const
BALL::CIFFile::Datablock::getSaveframeByIndex
const SaveFrame & getSaveframeByIndex(const Index index) const
BALL::CIFFile::Datablock::getDataItem
const Item & getDataItem(const String &item_name) const
BALL::CIFFile::Datablock::hasItem
bool hasItem(const String &name) const
BALL::CIFFile::Datablock::getSaveframeByName
SaveFrame & getSaveframeByName(const String &name)
BALL::CIFFile::Datablock::dummy_saveframe_
SaveFrame dummy_saveframe_
Definition CIFFile.h:199
BALL::CIFFile::Datablock::clear
void clear()
BALL::CIFFile::Datablock::getSaveframeByName
const SaveFrame & getSaveframeByName(const String &name) const
BALL::CIFFile::Datablock::insertDatacontent
void insertDatacontent(const SaveFrame &new_saveframe)
BALL::CIFFile::Datablock::dummy_saveframes_
vector< SaveFrame > dummy_saveframes_
Definition CIFFile.h:200
BALL::CIFFile::Datablock::item_names
StringHashMap< Index > item_names
Definition CIFFile.h:196
BALL::CIFFile::Datablock::getSaveframeIndicesByCategory
const std::vector< Index > getSaveframeIndicesByCategory(const String &name) const
BALL::CIFFile::Datablock::insertDatacontent
void insertDatacontent(const Item &item)
BALL::CIFFile::Datablock::dummy_indices_
vector< Index > dummy_indices_
Definition CIFFile.h:201
BALL::CIFFile::Datablock::hasSaveframeCategory
bool hasSaveframeCategory(const String &name) const
BALL::CIFFile::Datablock::saveframe_categories
std::multimap< String, Index > saveframe_categories
Definition CIFFile.h:193
BALL::CIFFile::Datablock::name
String name
Definition CIFFile.h:185
BALL::CIFFile::Datablock::getSaveframeByIndex
SaveFrame & getSaveframeByIndex(const Index index)
BALL::CIFFile::Datablock::dummy_data_item_
Item dummy_data_item_
Definition CIFFile.h:198
BALL::CIFFile::Datablock::insertDatacontent
void insertDatacontent(const Datacontent &content)
BALL::CIFFile::Datablock::hasSaveframeName
bool hasSaveframeName(const String &name) const
BALL::CIFFile::Datablock::data
std::vector< Datacontent > data
Definition CIFFile.h:188
BALL::CIFFile::Datablock::saveframe_names
StringHashMap< Index > saveframe_names
Definition CIFFile.h:191
BALL::CIFFile::Datablock::setName
void setName(String blockname)
BALL::CIFFile::Datablock::start
void start(String blockname)
BALL::CIFFile::Datablock::getSaveframeIndicesByCategory
std::vector< Index > getSaveframeIndicesByCategory(const String &name)
BALL::CIFFile::Datacontent
Definition CIFFile.h:117
BALL::CIFFile::Datacontent::dataitem
Item dataitem
Definition CIFFile.h:132
BALL::CIFFile::Datacontent::saveframe
SaveFrame saveframe
Definition CIFFile.h:129
BALL::CIFFile::Datacontent::is_saveframe
bool is_saveframe
Definition CIFFile.h:126
BALL::CIFFile::Datacontent::Datacontent
Datacontent(SaveFrame new_saveframe)
BALL::CIFFile::Datacontent::Datacontent
Datacontent(Item new_item)
BALL::CIFFile::Datacontent::Datacontent
Datacontent()
BALL::CIFFile::Item
Definition CIFFile.h:39
BALL::CIFFile::Item::addTag
void addTag(String tag)
BALL::CIFFile::Item::entry
std::pair< String, String > entry
Definition CIFFile.h:69
BALL::CIFFile::Item::keys
std::vector< String > keys
Definition CIFFile.h:64
BALL::CIFFile::Item::clear
void clear()
BALL::CIFFile::Item::values
std::vector< std::vector< String > > values
Definition CIFFile.h:66
BALL::CIFFile::Item::getKeyIndex
Index getKeyIndex(String key)
BALL::CIFFile::Item::startLoop
void startLoop()
BALL::CIFFile::Item::addValue
void addValue(String value)
BALL::CIFFile::Item::addPair
void addPair(String key, String value)
BALL::CIFFile::Item::is_loop
bool is_loop
Definition CIFFile.h:59
BALL::CIFFile::Item::Item
Item(const Item &item)
BALL::CIFFile::Item::~Item
virtual ~Item()
BALL::CIFFile::Item::Item
Item()
BALL::CIFFile::SaveFrame
Definition CIFFile.h:77
BALL::CIFFile::SaveFrame::category
String category
Definition CIFFile.h:105
BALL::CIFFile::SaveFrame::clear
void clear()
BALL::CIFFile::SaveFrame::getDataItem
Item & getDataItem(const String &item_name)
BALL::CIFFile::SaveFrame::getDataItemValue
const String & getDataItemValue(const String &item_name) const
BALL::CIFFile::SaveFrame::addDataItem
void addDataItem(Item item)
BALL::CIFFile::SaveFrame::pair_items
StringHashMap< Index > pair_items
Definition CIFFile.h:109
BALL::CIFFile::SaveFrame::items
std::vector< Item > items
Definition CIFFile.h:108
BALL::CIFFile::SaveFrame::getDataItemValue
String & getDataItemValue(const String &item_name)
BALL::CIFFile::SaveFrame::dummy_data_item_
Item dummy_data_item_
Definition CIFFile.h:111
BALL::CIFFile::SaveFrame::getCategory
const String & getCategory() const
Definition CIFFile.h:86
BALL::CIFFile::SaveFrame::hasItem
bool hasItem(const String &item_name) const
BALL::CIFFile::SaveFrame::getDataItem
const Item & getDataItem(const String &item_name) const
BALL::CIFFile::SaveFrame::getItemValue
String getItemValue(const String &name) const
BALL::CIFFile::SaveFrame::framename
String framename
Definition CIFFile.h:104
BALL::CIFFile::SaveFrame::setCategory
void setCategory(String cat)
Definition CIFFile.h:83
BALL::CIFFile::SaveFrame::start
void start(String name)
BALL::CIFFile::setMolecule
void setMolecule(Molecule *molecule)
BALL::CIFFile::CIFFile
CIFFile(const String &filename, File::OpenMode open_mode=std::ios::in)
BALL::CIFFile::CIFFile
CIFFile()
BALL::CIFFile::inDatablock
void inDatablock(const char *name)
BALL::CIFFile::inSafeframe
void inSafeframe(const char *name)
BALL::CIFFile::datablocks_hash_
StringHashMap< Index > datablocks_hash_
Definition CIFFile.h:280
BALL::CIFFile::~CIFFile
virtual ~CIFFile()
BALL::CIFFile::read
virtual bool read()
BALL::CIFFile::clearParameters
void clearParameters()
BALL::CIFFile::current_datablock_
String current_datablock_
Definition CIFFile.h:276
BALL::CIFFile::getDatablock
Datablock & getDatablock(const String &name)
BALL::CIFFile::initRead_
virtual void initRead_()
BALL::CIFFile::hasDatablock
bool hasDatablock(const String &name) const
BALL::CIFFile::datablocks_
vector< Datablock > datablocks_
Definition CIFFile.h:281
BALL::CIFFile::getDatablock
const Datablock & getDatablock(const String &name) const
BALL::CIFFile::write
virtual bool write()
BALL::CIFFile::current_item_
String current_item_
Definition CIFFile.h:278
BALL::CIFFile::inItem
void inItem(const char *name)
BALL::CIFFile::current_saveframe_
String current_saveframe_
Definition CIFFile.h:277
BALL::CIFFile::insertDatablock
void insertDatablock(const Datablock &datablock)
BALL::CIFFile::molecule_
Molecule * molecule_
Definition CIFFile.h:274
BALL::CIFFile::state
static State state
Definition CIFFile.h:269
BALL::File::File
File()
BALL::File::OpenMode
std::ios::openmode OpenMode
Definition file.h:165
BALL::Molecule
Definition molecule.h:31
BALL::StringHashMap
Definition stringHashMap.h:42
BALL::String
Definition string.h:57
file.h
molecule.h
BALL
Definition constants.h:13
BALL::Index
BALL_INDEX_TYPE Index
Definition COMMON/global.h:105
stringHashMap.h
BALL::CIFFile::State
Definition CIFFile.h:207
BALL::CIFFile::State::current_parser
CIFFile * current_parser
Definition CIFFile.h:208