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 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <string>
|
---|
17 |
|
---|
18 | #include "FormatParser.hpp"
|
---|
19 | #include "FormatParserTrait.hpp"
|
---|
20 | #include "FormatParserInterface.hpp"
|
---|
21 | #include "FormatParser_common.hpp"
|
---|
22 | #include "ParserTypes.hpp"
|
---|
23 |
|
---|
24 | #include "TremoloParser_ElementKeys.hpp"
|
---|
25 | #include "TremoloKey.hpp"
|
---|
26 | #include "TremoloAtomInfoContainer.hpp"
|
---|
27 |
|
---|
28 | class molecule;
|
---|
29 |
|
---|
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 |
|
---|
42 | /**
|
---|
43 | * Loads a tremolo file into the World and saves the World as a tremolo file.
|
---|
44 | */
|
---|
45 | template <>
|
---|
46 | class FormatParser< tremolo > : virtual public FormatParserInterface, public FormatParser_common
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | FormatParser();
|
---|
50 | virtual ~FormatParser();
|
---|
51 | void load(std::istream* file);
|
---|
52 | void save(std::ostream* file, const std::vector<atom *> &atoms);
|
---|
53 | void setFieldsForSave(std::string atomDataLine);
|
---|
54 | void setAtomData(const std::string &atomdata_string);
|
---|
55 |
|
---|
56 | private:
|
---|
57 | /**
|
---|
58 | * Map to associate element keys with the respective elements.
|
---|
59 | */
|
---|
60 | struct ElementKeys knownTypes;
|
---|
61 |
|
---|
62 | public:
|
---|
63 |
|
---|
64 | void parseKnownTypes(std::istream &file)
|
---|
65 | {
|
---|
66 | knownTypes.parseKnownTypes(file);
|
---|
67 | }
|
---|
68 | void createKnownTypesByIdentity()
|
---|
69 | {
|
---|
70 | knownTypes.createKnownTypesByIdentity();
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected:
|
---|
74 | void AtomInserted(atomId_t);
|
---|
75 | void AtomRemoved(atomId_t);
|
---|
76 |
|
---|
77 | private:
|
---|
78 | void readAtomDataLine(std::string line);
|
---|
79 | void readAtomDataLine(std::string line, molecule *newmol);
|
---|
80 | void parseAtomDataKeysLine(std::string line, int offset);
|
---|
81 | void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
|
---|
82 | void processNeighborInformation(const std::vector<atomId_t> &atoms);
|
---|
83 | void adaptImprData();
|
---|
84 | void adaptTorsion();
|
---|
85 | std::string adaptIdDependentDataString(std::string data);
|
---|
86 | bool isUsedField(std::string fieldName);
|
---|
87 | void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom);
|
---|
88 | void saveLine(std::ostream* file, atom* currentAtom);
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Map to associate the known keys with numbers.
|
---|
92 | */
|
---|
93 | std::map<std::string, TremoloKey::atomDataKey> knownKeys;
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Inverse Map to have a name to each known keys.
|
---|
97 | */
|
---|
98 | std::map<TremoloKey::atomDataKey, std::string> knownKeyNames;
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Fields used in the tremolo file.
|
---|
102 | */
|
---|
103 | std::vector<std::string> usedFields;
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Data which is currently not stored in atoms but was provided by the input
|
---|
107 | * file.
|
---|
108 | */
|
---|
109 | std::map<const atomId_t, TremoloAtomInfoContainer> additionalAtomData;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Default additional atom data.
|
---|
113 | */
|
---|
114 | TremoloAtomInfoContainer defaultAdditionalData;
|
---|
115 | };
|
---|
116 |
|
---|
117 | #endif /* TREMOLOPARSER_HPP_ */
|
---|