| 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 | public:
|
|---|
| 51 | FormatParser();
|
|---|
| 52 | virtual ~FormatParser();
|
|---|
| 53 | void load(std::istream* file);
|
|---|
| 54 | void save(std::ostream* file, const std::vector<atom *> &atoms);
|
|---|
| 55 |
|
|---|
| 56 | protected:
|
|---|
| 57 | void AtomInserted(atomId_t);
|
|---|
| 58 | void AtomRemoved(atomId_t);
|
|---|
| 59 |
|
|---|
| 60 | private:
|
|---|
| 61 | //!> structure that contains all information from the xml file
|
|---|
| 62 | struct scafacos {
|
|---|
| 63 | std::string name;
|
|---|
| 64 | std::string description;
|
|---|
| 65 | std::string reference_method;
|
|---|
| 66 | double error_potential;
|
|---|
| 67 | double error_field;
|
|---|
| 68 | struct configuration {
|
|---|
| 69 | Vector offset;
|
|---|
| 70 | RealSpaceMatrix box;
|
|---|
| 71 | bool periodicity[NDIM];
|
|---|
| 72 | std::string epsilon;
|
|---|
| 73 |
|
|---|
| 74 | struct particle {
|
|---|
| 75 | Vector position;
|
|---|
| 76 | double q;
|
|---|
| 77 | double potential;
|
|---|
| 78 | Vector field;
|
|---|
| 79 |
|
|---|
| 80 | bool operator==(const particle &p) const;
|
|---|
| 81 | bool operator!=(const particle &p) const {
|
|---|
| 82 | return !((*this) == p);
|
|---|
| 83 | }
|
|---|
| 84 | };
|
|---|
| 85 | std::vector<struct particle> p;
|
|---|
| 86 |
|
|---|
| 87 | bool operator==(const configuration &c) const;
|
|---|
| 88 | bool operator!=(const configuration &c) const {
|
|---|
| 89 | return !((*this) == c);
|
|---|
| 90 | }
|
|---|
| 91 | } config;
|
|---|
| 92 |
|
|---|
| 93 | bool operator==(const scafacos &s) const;
|
|---|
| 94 | bool operator!=(const scafacos &s) const {
|
|---|
| 95 | return !((*this) == s);
|
|---|
| 96 | }
|
|---|
| 97 | } data;
|
|---|
| 98 |
|
|---|
| 99 | //!> additional parser-specific information for an atom.
|
|---|
| 100 | struct additionalAtomInfo {
|
|---|
| 101 | /** Default constructor for additionalAtomInfo.
|
|---|
| 102 | *
|
|---|
| 103 | * Sets all parser-specific values to zero.
|
|---|
| 104 | */
|
|---|
| 105 | additionalAtomInfo() :
|
|---|
| 106 | charge(0.),
|
|---|
| 107 | potential(0),
|
|---|
| 108 | field(zeroVec)
|
|---|
| 109 | {}
|
|---|
| 110 |
|
|---|
| 111 | /** Default constructor for additionalAtomInfo.
|
|---|
| 112 | *
|
|---|
| 113 | */
|
|---|
| 114 | additionalAtomInfo(double _charge, double _potential, const Vector& _field) :
|
|---|
| 115 | charge(_charge),
|
|---|
| 116 | potential(_potential),
|
|---|
| 117 | field(_field)
|
|---|
| 118 | {}
|
|---|
| 119 |
|
|---|
| 120 | //!> charge of the atom
|
|---|
| 121 | double charge;
|
|---|
| 122 | //!> potential at position of atom
|
|---|
| 123 | double potential;
|
|---|
| 124 | //!> field at position of atom
|
|---|
| 125 | Vector field;
|
|---|
| 126 | };
|
|---|
| 127 |
|
|---|
| 128 | //!> typedef for map to associate additional parser-specific information to each atom.
|
|---|
| 129 | typedef std::map< atomId_t, additionalAtomInfo> AtomInfoMap_t;
|
|---|
| 130 |
|
|---|
| 131 | //!> map to associate additional parser-specific information to each atom.
|
|---|
| 132 | AtomInfoMap_t additionalAtomData;
|
|---|
| 133 |
|
|---|
| 134 | //!> static instance with default additional atom information
|
|---|
| 135 | static additionalAtomInfo defaultAtomInfo;
|
|---|
| 136 |
|
|---|
| 137 | /** Getter for additionalAtomInfo.
|
|---|
| 138 | *
|
|---|
| 139 | * @param _atom constant ref to atom
|
|---|
| 140 | * @return constant reference to additional atom info container,
|
|---|
| 141 | * otherwise to default atom info
|
|---|
| 142 | */
|
|---|
| 143 | const additionalAtomInfo& getAtomData(const atom &_atom) const;
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | #endif /* XMLPARSER_HPP_ */
|
|---|