BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
XmlTypeMappingParser.h
1 #pragma once
2 
3 #include <Poco/DOM/Node.h>
4 
5 #include "util/TypeMappingParser.h"
6 #include "util/XmlTypeMappingParserHelper.h"
7 
8 namespace BeeeOn {
9 
17 template <typename TechType>
18 class XmlTypeMappingParser : public TypeMappingParser<TechType>, protected Loggable {
19 public:
21  const std::string &mappingGroup,
22  const std::string &techNode,
23  Poco::Logger &logger);
24 
30  typename TypeMappingParser<TechType>::TypeMappingSequence parse(std::istream &in) override;
31 
32 protected:
37  virtual TechType parseTechType(const Poco::XML::Node &node) = 0;
38 
42  virtual std::string techTypeRepr(const TechType &type) = 0;
43 
44 private:
46 };
47 
48 template <typename TechType>
50  const std::string &mappingGroup,
51  const std::string &techNode,
52  Poco::Logger &logger):
53  m_helper(mappingGroup, techNode, logger)
54 {
55 }
56 
57 template <typename TechType>
59 {
61  std::pair<Poco::AutoPtr<Poco::XML::Node>, ModuleType> mapping;
62 
63  if (logger().trace()) {
64  logger().trace(
65  "loading DOM representation of type mappings",
66  __FILE__, __LINE__);
67  }
68 
69  m_helper.parseDOM(in);
70 
71  while (!(mapping = m_helper.next()).first.isNull()) {
72  const TechType techType = parseTechType(*mapping.first);
73 
74  if (logger().debug()) {
75  logger().debug(
76  "parsed mapping " + techTypeRepr(techType)
77  + " to " + mapping.second.type().toString(),
78  __FILE__, __LINE__);
79  }
80 
81  sequence.emplace_back(techType, mapping.second);
82  }
83 
84  return sequence;
85 }
86 
87 }
std::vector< TypeMapping > TypeMappingSequence
Sequence of particular mappings.
Definition: TypeMappingParser.h:28
TypeMappingParser is an abstract class providing method parse() that reads a given definition file (i...
Definition: TypeMappingParser.h:17
virtual TechType parseTechType(const Poco::XML::Node &node)=0
Parse the XML node describing a technology-specific data type.
XmlTypeMappingParser is an abstract specialization of the TypeMappingParser. It is used to parse an e...
Definition: XmlTypeMappingParser.h:18
virtual std::string techTypeRepr(const TechType &type)=0
Definition: ModuleType.h:18
Definition: Loggable.h:19
TypeMappingParser< TechType >::TypeMappingSequence parse(std::istream &in) override
Parse the input stream as XML file via the XmlTypeMappingParserHelper.
Definition: XmlTypeMappingParser.h:58
Helper defining method for parsing an input stream as an XML input. The purpose is to extract informa...
Definition: XmlTypeMappingParserHelper.h:50