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 typedef std::map<TicNodeType, String> TicNodeTypeNames;
28 typedef std::map<String, TicNodeType> TicNameNodeTypes;
39 static SectionReadCallback<T> Null;
40 static SectionReadCallback<T> Empty;
64 void ReadStartTicNode(TicNodeType& nodeType);
65 bool TryReadStartTicNode(TicNodeType& nodeType);
66 void ReadEndTicNode(TicNodeType nodeType);
67 bool TryReadEndTicNode(TicNodeType nodeType);
70 void ReadStartTicElementList(
void);
71 bool TryReadStartTicElementList(
void);
72 void ReadEndTicElementList(
void);
73 bool TryReadEndTicElementList(
void);
76 void ReadStartTicAttributeList(
void);
77 bool TryReadStartTicAttributeList(
void);
78 void ReadEndTicAttributeList(
void);
79 bool TryReadEndTicAttributeList(
void);
82 void ReadStartTicElement(
String& readELementName);
83 bool TryReadStartTicElement(
String& readELementName);
84 bool TryReadStartTicElement(
const String& elementName,
String& readELementName);
85 void ReadEndTicElement(
void);
86 bool TryReadEndTicElement(
void);
89 void ReadStartTicAttribute(
String& readAttributeName);
90 bool TryReadStartTicAttribute(
String& readAttributeName);
91 bool TryReadStartTicAttribute(
const String& attributeName,
String& readAttributeName);
92 void ReadEndTicAttribute(
void);
93 bool TryReadEndTicAttribute(
void);
96 void SkipTicAttributeValue(
void);
98 T ReadTicAttributeValue(
void);
100 bool TryReadTicAttributeValue(T& result);
104 void ReadTicElementContent(
107 SectionReadCallback<T> attributesReadMethod,
108 SectionReadCallback<T> childElementsReadMethod =
nullptr,
109 bool attributesAreOptional =
false,
110 bool elementsAreOptional =
false);
113 bool TryReadStartTicElement(
const String& elementName,
String& readELementName,
String& errorMessage);
114 bool TryReadStartTicAttribute(
const String& attributeName,
String& readAttributeName,
String& errorMessage);
115 bool TryReadTicAttributeContent(
String& result,
String& errorMessage);
117 bool TryReadTicAttributeValue(T& result,
String& errorMessage);
118 void SkipTicAttributeList(
void);
119 void SkipTicElementList(
void);
125 static TicNodeTypeNames ticNodeTypeNames;
126 static TicNameNodeTypes ticNameNodeTypes;
129 static const char*
const ticElementNameAttributeName;
130 static const char*
const ticAttributeNameAttributeName;
137inline T TicReader::ReadTicAttributeValue()
141 if (!this->TryReadTicAttributeValue<T>(result, errorMessage))
149inline bool TicReader::TryReadTicAttributeValue(T& result)
152 return this->TryReadTicAttributeValue<T>(result, errorMessage);
156inline bool TicReader::TryReadTicAttributeValue(T& result,
String& errorMessage)
159 if (!this->TryReadTicAttributeContent(attributeValue, errorMessage))
164 std::stringstream iss(attributeValue);
165 iss >> std::boolalpha >> result;
169inline bool TicReader::TryReadTicAttributeValue(
String& result,
String& errorMessage)
172 if (!this->TryReadTicAttributeContent(result, errorMessage))
184inline void TicReader::ReadTicElementContent(
187 SectionReadCallback<T> attributesReader,
188 SectionReadCallback<T> childElementsReader,
189 bool attributesAreOptional,
190 bool elementsAreOptional)
192 bool hasAttributesRead =
false;
193 bool hasChildElementsRead =
false;
195 while (!(hasAttributesRead && hasChildElementsRead))
197 TicNodeType nodeType = TicNodeType::None;
198 if (this->TryReadStartTicNode(nodeType))
200 bool mustReadEndTicNode =
true;
203 case TicNodeType::AttributeList:
204 if (attributesReader ==
nullptr)
206 this->SkipTicAttributeList();
210 (configuration.*attributesReader)(*
this, context);
212 hasAttributesRead =
true;
214 case TicNodeType::ElementList:
215 if (childElementsReader ==
nullptr)
217 this->SkipTicElementList();
218 mustReadEndTicNode =
false;
222 (configuration.*childElementsReader)(*
this, context);
224 hasChildElementsRead =
true;
227 throw XmlException(
"Invalid TIC file format: expecting attribute or element list");
230 if(mustReadEndTicNode)
232 this->ReadEndTicNode(nodeType);
237 if (!hasAttributesRead && !attributesAreOptional)
239 throw XmlException(
"Invalid TIC file format: expecting attribute list");
241 else if (attributesReader ==
nullptr && attributesAreOptional)
243 hasAttributesRead =
true;
246 if (!hasChildElementsRead && !elementsAreOptional)
248 throw XmlException(
"Invalid TIC file format: expecting element list");
250 else if (elementsAreOptional)
252 hasChildElementsRead =
true;
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Definition: TicReader.hpp:23
~TicReader(void)=default
Destructs this instance and frees all resources.
TicReader(TicReader &&arg)
Move contructor.
Definition: TicReader.cpp:42
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:25
Namespace for logging classes
Namespace for classes to read XML files
Root namespace for the PLCnext API
Definition: TicReader.hpp:37