| [6bc51d] | 1 | /* | 
|---|
|  | 2 | * TremoloParser.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Mar 2, 2010 | 
|---|
|  | 5 | *      Author: metzler | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef TREMOLOPARSER_HPP_ | 
|---|
|  | 9 | #define TREMOLOPARSER_HPP_ | 
|---|
|  | 10 |  | 
|---|
| [56f73b] | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
| [05e2ed] | 16 | #include <boost/function.hpp> | 
|---|
| [9131f3] | 17 | #include <string> | 
|---|
| [765f16] | 18 |  | 
|---|
|  | 19 | #include "FormatParser.hpp" | 
|---|
|  | 20 | #include "FormatParserTrait.hpp" | 
|---|
|  | 21 | #include "FormatParserInterface.hpp" | 
|---|
|  | 22 | #include "FormatParser_common.hpp" | 
|---|
|  | 23 | #include "ParserTypes.hpp" | 
|---|
| [6bc51d] | 24 |  | 
|---|
| [031e2c6] | 25 | #include "TremoloKey.hpp" | 
|---|
|  | 26 | #include "TremoloAtomInfoContainer.hpp" | 
|---|
| [b8d4a3] | 27 |  | 
|---|
| [031e2c6] | 28 | class molecule; | 
|---|
| [5a667d] | 29 | class AtomDataValidator; | 
|---|
| [4415da] | 30 |  | 
|---|
| [765f16] | 31 | // declaration of specialized FormatParserTrait | 
|---|
|  | 32 | template<> | 
|---|
|  | 33 | struct FormatParserTrait<tremolo> | 
|---|
|  | 34 | { | 
|---|
|  | 35 | //!> Name of the parser | 
|---|
|  | 36 | static const std::string name; | 
|---|
|  | 37 | //!> suffix of the files the parser understands to read and write | 
|---|
|  | 38 | static const std::string suffix; | 
|---|
|  | 39 | //!> ParserTypes enumeration for the parser | 
|---|
|  | 40 | static const enum ParserTypes type; | 
|---|
|  | 41 | }; | 
|---|
|  | 42 |  | 
|---|
| [4415da] | 43 | /** | 
|---|
|  | 44 | * Loads a tremolo file into the World and saves the World as a tremolo file. | 
|---|
|  | 45 | */ | 
|---|
| [765f16] | 46 | template <> | 
|---|
|  | 47 | class FormatParser< tremolo >  : virtual public FormatParserInterface, public FormatParser_common | 
|---|
| [9131f3] | 48 | { | 
|---|
| [5a667d] | 49 | friend class AtomDataValidator; | 
|---|
| [6bc51d] | 50 | public: | 
|---|
| [765f16] | 51 | FormatParser(); | 
|---|
|  | 52 | virtual ~FormatParser(); | 
|---|
| [9131f3] | 53 | void load(std::istream* file); | 
|---|
| [fac58f] | 54 | void save(std::ostream* file, const std::vector<const atom *> &atoms); | 
|---|
| [ca331c] | 55 | std::string getAtomData() const; | 
|---|
| [81c980b] | 56 | void setAtomData(const std::string &atomdata_string); | 
|---|
| [ca331c] | 57 | void resetAtomData(const std::string &atomdata_string); | 
|---|
| [6bc51d] | 58 |  | 
|---|
| [531f27] | 59 | /** Save given \a atoms in tremolo's exttypes file | 
|---|
|  | 60 | * | 
|---|
|  | 61 | * \note You should have stored the atoms beforehand to give them unique | 
|---|
|  | 62 | * and sensible ids. | 
|---|
|  | 63 | * | 
|---|
|  | 64 | * @param output output stream | 
|---|
|  | 65 | * @param atoms vector of atoms whose ids to store | 
|---|
|  | 66 | * @param id id to given this exttypes group | 
|---|
|  | 67 | * @return true - all atomic ids are valid, false - one id was not set (-1) | 
|---|
|  | 68 | */ | 
|---|
| [99db9b] | 69 | bool saveAtomsInExttypes( | 
|---|
|  | 70 | std::ostream &output, | 
|---|
|  | 71 | const std::vector<const atom*> &atoms, | 
|---|
|  | 72 | const int id) const; | 
|---|
| [531f27] | 73 |  | 
|---|
| [6bc86c] | 74 | protected: | 
|---|
|  | 75 | void AtomInserted(atomId_t); | 
|---|
|  | 76 | void AtomRemoved(atomId_t); | 
|---|
|  | 77 |  | 
|---|
| [6bc51d] | 78 | private: | 
|---|
| [23fd43] | 79 | //!> typedef for usedFields' vector of strings | 
|---|
|  | 80 | typedef std::vector<std::string> usedFields_t; | 
|---|
|  | 81 |  | 
|---|
| [220d2c] | 82 | void readAtomDataLine( | 
|---|
|  | 83 | const std::string &line, | 
|---|
|  | 84 | molecule *newmol, | 
|---|
|  | 85 | const size_t _timestep, | 
|---|
|  | 86 | atom *&_addedatoms); | 
|---|
| [23fd43] | 87 | void parseAtomDataKeysLine(const std::string &line, const int offset, usedFields_t &fields); | 
|---|
| [5a667d] | 88 | static bool testParseAtomDataKeysLine(const std::string &line); | 
|---|
| [23fd43] | 89 | void readNeighbors(std::stringstream* line, const int numberOfNeighbors, const int atomId); | 
|---|
| [9f8b01] | 90 | void processNeighborInformation(const std::vector<atomId_t> &atoms); | 
|---|
| [05e2ed] | 91 | void adaptImprData(const std::vector<atomId_t> &atoms); | 
|---|
|  | 92 | void adaptTorsion(const std::vector<atomId_t> &atoms); | 
|---|
|  | 93 | std::string adaptIdDependentDataString(const std::string &data, const boost::function<int (const int)> &idgetter); | 
|---|
| [23fd43] | 94 | bool isUsedField(const usedFields_t &fields, const std::string &fieldName) const; | 
|---|
| [fac58f] | 95 | void writeNeighbors(std::ostream* file, const int numberOfNeighbors, const atom* const currentAtom); | 
|---|
| [33af20] | 96 | void saveLine( | 
|---|
|  | 97 | std::ostream* file, | 
|---|
|  | 98 | const atom* const currentAtom, | 
|---|
|  | 99 | const size_t _timestep); | 
|---|
| [23fd43] | 100 | void save_AtomDataLine(std::ostream* file) const; | 
|---|
|  | 101 | void save_BoxLine(std::ostream* file) const; | 
|---|
| [fac58f] | 102 | void distributeContinuousIds(const std::vector<const atom *> &AtomList); | 
|---|
| [27cfde] | 103 | void makeUsedFieldsUnique(usedFields_t &fields) const; | 
|---|
| [9131f3] | 104 | /** | 
|---|
|  | 105 | * Map to associate the known keys with numbers. | 
|---|
|  | 106 | */ | 
|---|
| [5a667d] | 107 | static std::map<std::string, TremoloKey::atomDataKey> knownKeys; | 
|---|
| [9131f3] | 108 |  | 
|---|
| [4d4d33] | 109 | /** | 
|---|
|  | 110 | * Inverse Map to have a name to each known keys. | 
|---|
|  | 111 | */ | 
|---|
|  | 112 | std::map<TremoloKey::atomDataKey, std::string> knownKeyNames; | 
|---|
|  | 113 |  | 
|---|
| [9131f3] | 114 | /** | 
|---|
| [23fd43] | 115 | * Fields used globally when storing to a tremolo file. | 
|---|
|  | 116 | */ | 
|---|
|  | 117 | usedFields_t usedFields_save; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | /** | 
|---|
|  | 120 | * Fields used locally when parsing in a tremolo file. | 
|---|
| [9131f3] | 121 | */ | 
|---|
| [23fd43] | 122 | usedFields_t usedFields_load; | 
|---|
| [9131f3] | 123 |  | 
|---|
|  | 124 | /** | 
|---|
|  | 125 | * Data which is currently not stored in atoms but was provided by the input | 
|---|
|  | 126 | * file. | 
|---|
|  | 127 | */ | 
|---|
| [8bf9c6] | 128 | std::map<const atomId_t, TremoloAtomInfoContainer> additionalAtomData; | 
|---|
| [b8d4a3] | 129 |  | 
|---|
|  | 130 | /** | 
|---|
|  | 131 | * Default additional atom data. | 
|---|
|  | 132 | */ | 
|---|
|  | 133 | TremoloAtomInfoContainer defaultAdditionalData; | 
|---|
| [05e2ed] | 134 |  | 
|---|
|  | 135 | //!> bound function to convert id to global id, stored to avoid creation many times | 
|---|
|  | 136 | const boost::function<int (const int)> idglobalizer; | 
|---|
|  | 137 |  | 
|---|
|  | 138 | //!> bound function to convert id to local id, stored to avoid creation many times | 
|---|
|  | 139 | const boost::function<int (const int)> idlocalizer; | 
|---|
| [6bc51d] | 140 | }; | 
|---|
|  | 141 |  | 
|---|
|  | 142 | #endif /* TREMOLOPARSER_HPP_ */ | 
|---|