8#include "Arp/System/Commons/Diagnostics/Logging/Loggable.hxx"
9#include "Arp/System/Commons/Xml/XmlReader.hpp"
10#include "Arp/System/Commons/Exceptions/XmlException.hpp"
11#include "Arp/System/Commons/Configuration/TicNodeType.hpp"
12#include "Arp/System/Commons/Configuration/TicSerializationContext.hpp"
16namespace Arp {
namespace System {
namespace Commons {
namespace Configuration
27 using TicNodeTypeNames = std::map<TicNodeType, String>;
28 using TicNameNodeTypes = std::map<String, TicNodeType>;
39 static SectionReadCallback<T> Null;
40 static SectionReadCallback<T> Empty;
63 void ReadStartTicNode(TicNodeType& nodeType);
64 bool TryReadStartTicNode(TicNodeType& nodeType);
65 void ReadEndTicNode(TicNodeType nodeType);
66 bool TryReadEndTicNode(TicNodeType nodeType);
69 void ReadStartTicElementList(
void);
70 bool TryReadStartTicElementList(
void);
71 void ReadEndTicElementList(
void);
72 bool TryReadEndTicElementList(
void);
75 void ReadStartTicAttributeList(
void);
76 bool TryReadStartTicAttributeList(
void);
77 void ReadEndTicAttributeList(
void);
78 bool TryReadEndTicAttributeList(
void);
81 void ReadStartTicElement(
String& readELementName);
82 bool TryReadStartTicElement(
String& readELementName);
83 bool TryReadStartTicElement(
const String& elementName,
String& readELementName);
84 void ReadEndTicElement(
void);
85 bool TryReadEndTicElement(
void);
88 void ReadStartTicAttribute(
String& readAttributeName);
89 bool TryReadStartTicAttribute(
String& readAttributeName);
90 bool TryReadStartTicAttribute(
const String& attributeName,
String& readAttributeName);
91 void ReadEndTicAttribute(
void);
92 bool TryReadEndTicAttribute(
void);
95 void SkipTicAttributeValue(
void);
97 T ReadTicAttributeValue(
void);
99 bool TryReadTicAttributeValue(T& result);
103 void ReadTicElementContent(
106 SectionReadCallback<T> attributesReadMethod,
107 SectionReadCallback<T> childElementsReadMethod =
nullptr,
108 bool attributesAreOptional =
false,
109 bool elementsAreOptional =
false);
112 bool TryReadStartTicElement(
const String& elementName,
String& readELementName,
String& errorMessage);
113 bool TryReadStartTicAttribute(
const String& attributeName,
String& readAttributeName,
String& errorMessage);
114 bool TryReadTicAttributeContent(
String& result,
String& errorMessage);
116 bool TryReadTicAttributeValue(T& result,
String& errorMessage);
117 void SkipTicAttributeList(
void);
118 void SkipTicElementList(
void);
124 static TicNodeTypeNames ticNodeTypeNames;
125 static TicNameNodeTypes ticNameNodeTypes;
128 static const char*
const ticElementNameAttributeName;
129 static const char*
const ticAttributeNameAttributeName;
136inline T TicReader::ReadTicAttributeValue()
140 if (!this->TryReadTicAttributeValue<T>(result, errorMessage))
148inline bool TicReader::TryReadTicAttributeValue(T& result)
151 return this->TryReadTicAttributeValue<T>(result, errorMessage);
155inline bool TicReader::TryReadTicAttributeValue(T& result,
String& errorMessage)
158 if (!this->TryReadTicAttributeContent(attributeValue, errorMessage))
163 std::stringstream iss(attributeValue);
164 iss >> std::boolalpha >> result;
168inline bool TicReader::TryReadTicAttributeValue(
String& result,
String& errorMessage)
171 return this->TryReadTicAttributeContent(result, errorMessage);
179inline void TicReader::ReadTicElementContent(
182 SectionReadCallback<T> attributesReader,
183 SectionReadCallback<T> childElementsReader,
184 bool attributesAreOptional,
185 bool elementsAreOptional)
187 bool hasAttributesRead =
false;
188 bool hasChildElementsRead =
false;
190 while (!(hasAttributesRead && hasChildElementsRead))
192 TicNodeType nodeType = TicNodeType::None;
193 if (this->TryReadStartTicNode(nodeType))
195 bool mustReadEndTicNode =
true;
198 case TicNodeType::AttributeList:
199 if (attributesReader ==
nullptr)
201 this->SkipTicAttributeList();
205 (configuration.*attributesReader)(*
this, context);
207 hasAttributesRead =
true;
209 case TicNodeType::ElementList:
210 if (childElementsReader ==
nullptr)
212 this->SkipTicElementList();
213 mustReadEndTicNode =
false;
217 (configuration.*childElementsReader)(*
this, context);
219 hasChildElementsRead =
true;
222 throw XmlException(
"Invalid TIC file format: expecting attribute or element list");
225 if(mustReadEndTicNode)
227 this->ReadEndTicNode(nodeType);
232 if (!hasAttributesRead && !attributesAreOptional)
234 throw XmlException(
"Invalid TIC file format: expecting attribute list");
236 else if (attributesReader ==
nullptr && attributesAreOptional)
238 hasAttributesRead =
true;
241 if (!hasChildElementsRead && !elementsAreOptional)
243 throw XmlException(
"Invalid TIC file format: expecting element list");
245 else if (elementsAreOptional)
247 hasChildElementsRead =
true;
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Definition: TicReader.hpp:23
Definition: TicSerializationContext.hpp:19
Derive from this class to inherit logging functionality.
Definition: Loggable.hxx:28
This exception is used for xml parsing errors.
Definition: XmlException.hpp:15
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:26
Namespace for logging classes
Namespace for classes to read XML files
Root namespace for the PLCnext API
Definition: TicReader.hpp:37