| 1 | /* | 
|---|
| 2 | * XmlParser.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Mar 23, 2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef XMLPARSER_HPP_ | 
|---|
| 9 | #define XMLPARSER_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <map> | 
|---|
| 17 | #include <string> | 
|---|
| 18 |  | 
|---|
| 19 | #include "FormatParser.hpp" | 
|---|
| 20 | #include "FormatParserTrait.hpp" | 
|---|
| 21 | #include "FormatParserInterface.hpp" | 
|---|
| 22 | #include "FormatParser_common.hpp" | 
|---|
| 23 | #include "ParserTypes.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 26 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | // declaration of specialized FormatParserTrait | 
|---|
| 29 | template<> | 
|---|
| 30 | struct FormatParserTrait<xml> | 
|---|
| 31 | { | 
|---|
| 32 | //!> Name of the parser | 
|---|
| 33 | static const std::string name; | 
|---|
| 34 | //!> suffix of the files the parser understands to read and write | 
|---|
| 35 | static const std::string suffix; | 
|---|
| 36 | //!> ParserTypes enumeration for the parser | 
|---|
| 37 | static const enum ParserTypes type; | 
|---|
| 38 | }; | 
|---|
| 39 |  | 
|---|
| 40 | class ParserXmlUnitTest; | 
|---|
| 41 |  | 
|---|
| 42 | /** | 
|---|
| 43 | * Parser for XYZ files. | 
|---|
| 44 | */ | 
|---|
| 45 | template <> | 
|---|
| 46 | class FormatParser< xml >  : virtual public FormatParserInterface, public FormatParser_common | 
|---|
| 47 | { | 
|---|
| 48 | //!> grant unit test access to private parts | 
|---|
| 49 | friend class ParserXmlUnitTest; | 
|---|
| 50 | //!> grant mem debugger access | 
|---|
| 51 | friend void AddStaticEntitiestoIgnoreList(); | 
|---|
| 52 | public: | 
|---|
| 53 | FormatParser(); | 
|---|
| 54 | virtual ~FormatParser(); | 
|---|
| 55 | void load(std::istream* file); | 
|---|
| 56 | void save(std::ostream* file, const std::vector<atom *> &atoms); | 
|---|
| 57 |  | 
|---|
| 58 | protected: | 
|---|
| 59 | void AtomInserted(atomId_t); | 
|---|
| 60 | void AtomRemoved(atomId_t); | 
|---|
| 61 |  | 
|---|
| 62 | private: | 
|---|
| 63 | //!> structure that contains all information from the xml file | 
|---|
| 64 | struct scafacos { | 
|---|
| 65 | std::string name; | 
|---|
| 66 | std::string description; | 
|---|
| 67 | std::string reference_method; | 
|---|
| 68 | double error_potential; | 
|---|
| 69 | double error_field; | 
|---|
| 70 | struct configuration { | 
|---|
| 71 | Vector offset; | 
|---|
| 72 | RealSpaceMatrix box; | 
|---|
| 73 | bool periodicity[NDIM]; | 
|---|
| 74 | std::string epsilon; | 
|---|
| 75 |  | 
|---|
| 76 | struct particle { | 
|---|
| 77 | Vector position; | 
|---|
| 78 | double q; | 
|---|
| 79 | double potential; | 
|---|
| 80 | Vector field; | 
|---|
| 81 |  | 
|---|
| 82 | bool operator==(const particle &p) const; | 
|---|
| 83 | bool operator!=(const particle &p) const { | 
|---|
| 84 | return !((*this) == p); | 
|---|
| 85 | } | 
|---|
| 86 | }; | 
|---|
| 87 | std::vector<struct particle> p; | 
|---|
| 88 |  | 
|---|
| 89 | bool operator==(const configuration &c) const; | 
|---|
| 90 | bool operator!=(const configuration &c) const { | 
|---|
| 91 | return !((*this) == c); | 
|---|
| 92 | } | 
|---|
| 93 | } config; | 
|---|
| 94 |  | 
|---|
| 95 | bool operator==(const scafacos &s) const; | 
|---|
| 96 | bool operator!=(const scafacos &s) const { | 
|---|
| 97 | return !((*this) == s); | 
|---|
| 98 | } | 
|---|
| 99 | } data; | 
|---|
| 100 |  | 
|---|
| 101 | //!> additional parser-specific information for an atom. | 
|---|
| 102 | struct additionalAtomInfo { | 
|---|
| 103 | /** Default constructor for additionalAtomInfo. | 
|---|
| 104 | * | 
|---|
| 105 | * Sets all parser-specific values to zero. | 
|---|
| 106 | */ | 
|---|
| 107 | additionalAtomInfo() : | 
|---|
| 108 | charge(0.), | 
|---|
| 109 | potential(0), | 
|---|
| 110 | field(zeroVec) | 
|---|
| 111 | {} | 
|---|
| 112 |  | 
|---|
| 113 | /** Default constructor for additionalAtomInfo. | 
|---|
| 114 | * | 
|---|
| 115 | */ | 
|---|
| 116 | additionalAtomInfo(double _charge, double _potential, const Vector& _field) : | 
|---|
| 117 | charge(_charge), | 
|---|
| 118 | potential(_potential), | 
|---|
| 119 | field(_field) | 
|---|
| 120 | {} | 
|---|
| 121 |  | 
|---|
| 122 | //!> charge of the atom | 
|---|
| 123 | double charge; | 
|---|
| 124 | //!> potential at position of atom | 
|---|
| 125 | double potential; | 
|---|
| 126 | //!> field at position of atom | 
|---|
| 127 | Vector field; | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | //!> typedef for map to associate additional parser-specific information to each atom. | 
|---|
| 131 | typedef std::map< atomId_t, additionalAtomInfo> AtomInfoMap_t; | 
|---|
| 132 |  | 
|---|
| 133 | //!> map to associate additional parser-specific information to each atom. | 
|---|
| 134 | AtomInfoMap_t additionalAtomData; | 
|---|
| 135 |  | 
|---|
| 136 | //!> static instance with default additional atom information | 
|---|
| 137 | static additionalAtomInfo defaultAtomInfo; | 
|---|
| 138 |  | 
|---|
| 139 | /** Getter for additionalAtomInfo. | 
|---|
| 140 | * | 
|---|
| 141 | * @param _atom constant ref to atom | 
|---|
| 142 | * @return constant reference to additional atom info container, | 
|---|
| 143 | *         otherwise to default atom info | 
|---|
| 144 | */ | 
|---|
| 145 | const additionalAtomInfo& getAtomData(const atom &_atom) const; | 
|---|
| 146 | }; | 
|---|
| 147 |  | 
|---|
| 148 |  | 
|---|
| 149 | #endif /* XMLPARSER_HPP_ */ | 
|---|