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