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"    16 namespace 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;
    65     void    ReadStartTicNode(TicNodeType& nodeType);
    66     bool    TryReadStartTicNode(TicNodeType& nodeType);
    67     void    ReadEndTicNode(TicNodeType nodeType);
    68     bool    TryReadEndTicNode(TicNodeType nodeType);
    71     void    ReadStartTicElementList(
void);
    72     bool    TryReadStartTicElementList(
void);
    73     void    ReadEndTicElementList(
void);
    74     bool    TryReadEndTicElementList(
void);
    77     void    ReadStartTicAttributeList(
void);
    78     bool    TryReadStartTicAttributeList(
void);
    79     void    ReadEndTicAttributeList(
void);
    80     bool    TryReadEndTicAttributeList(
void);
    83     void    ReadStartTicElement(
String& readELementName);
    84     bool    TryReadStartTicElement(
String& readELementName);
    85     bool    TryReadStartTicElement(
const String& elementName, 
String& readELementName);
    86     void    ReadEndTicElement(
void);
    87     bool    TryReadEndTicElement(
void);
    90     void    ReadStartTicAttribute(
String& readAttributeName);
    91     bool    TryReadStartTicAttribute(
String& readAttributeName);
    92     bool    TryReadStartTicAttribute(
const String& attributeName, 
String& readAttributeName);
    93     void    ReadEndTicAttribute(
void);
    94     bool    TryReadEndTicAttribute(
void);
    97     void    SkipTicAttributeValue(
void);
    99     T       ReadTicAttributeValue(
void);
   101     bool    TryReadTicAttributeValue(T& result);
   105     void    ReadTicElementContent(
   108         SectionReadCallback<T> attributesReadMethod,
   109         SectionReadCallback<T> childElementsReadMethod = 
nullptr,
   110         bool attributesAreOptional = 
false,
   111         bool elementsAreOptional = 
false);
   114     bool    TryReadStartTicElement(
const String& elementName, 
String& readELementName, 
String& errorMessage);
   115     bool    TryReadStartTicAttribute(
const String& attributeName, 
String& readAttributeName, 
String& errorMessage);
   116     bool    TryReadTicAttributeContent(
String& result, 
String& errorMessage);
   118     bool    TryReadTicAttributeValue(T& result, 
String& errorMessage);
   119     void    SkipTicAttributeList(
void);
   120     void    SkipTicElementList(
void);
   126     static TicNodeTypeNames    ticNodeTypeNames;
   127     static TicNameNodeTypes    ticNameNodeTypes;
   130     static const char* 
const ticElementNameAttributeName;
   131     static const char* 
const ticAttributeNameAttributeName;
   142 inline XmlReader& TicReader::GetXmlReader()
   144     return this->xmlReader;
   147 inline bool TicReader::TryReadStartTicElementList()
   149     TicNodeType nodeType = TicNodeType::None;
   150     return this->TryReadStartTicNode(nodeType) && nodeType == TicNodeType::ElementList;
   153 inline void TicReader::ReadStartTicElementList()
   155     if (!this->TryReadStartTicElementList())
   157         throw XmlException(
"Invalid Tic file format: missing StartTicElementList tag '<{0}>'.", ticNodeTypeNames[TicNodeType::ElementList]);
   161 inline bool TicReader::TryReadEndTicElementList()
   163     return this->TryReadEndTicNode(TicNodeType::ElementList);
   166 inline void TicReader::ReadEndTicElementList()
   168     if (!this->TryReadEndTicElementList())
   170         throw XmlException(
"Invalid Tic file format: missing EndTicElementList tag '</{0}>'.", ticNodeTypeNames[TicNodeType::ElementList]);
   174 inline bool TicReader::TryReadStartTicAttributeList()
   176     TicNodeType nodeType = TicNodeType::None;
   177     return this->TryReadStartTicNode(nodeType) && nodeType == TicNodeType::AttributeList;
   180 inline void TicReader::ReadStartTicAttributeList()
   182     if (!this->TryReadStartTicAttributeList())
   184         throw XmlException(
"Invalid Tic file format: missing StartTicAttributeList tag '<{0}>'.", ticNodeTypeNames[TicNodeType::AttributeList]);
   188 inline bool TicReader::TryReadEndTicAttributeList()
   190     return this->TryReadEndTicNode(TicNodeType::AttributeList);
   193 inline void TicReader::ReadEndTicAttributeList()
   195     if (!this->TryReadEndTicAttributeList())
   197         throw XmlException(
"Invalid Tic file format: missing EndTicAttributeList tag '</{0}>'.", ticNodeTypeNames[TicNodeType::AttributeList]);
   201 inline void TicReader::ReadStartTicElement(
String& readELementName)
   204     if (!this->TryReadStartTicElement(String::Empty, readELementName, errorMessage))
   210 inline bool TicReader::TryReadStartTicElement(
String& readELementName)
   213     return this->TryReadStartTicElement(String::Empty, readELementName, errorMessage);
   216 inline bool TicReader::TryReadStartTicElement(
const String& elementName, 
String& readELementName)
   219     return this->TryReadStartTicElement(elementName, readELementName, errorMessage);
   222 inline void TicReader::ReadEndTicElement()
   224     if (!this->TryReadEndTicElement())
   226         throw XmlException(
"Invalid Tic file format: missing EndTicElement tag '</{0}>'.", ticNodeTypeNames[TicNodeType::Element]);
   230 inline bool TicReader::TryReadEndTicElement()
   232     return this->TryReadEndTicNode(TicNodeType::Element);
   235 inline void TicReader::ReadStartTicAttribute(
String& readAttributeName)
   238     if (!this->TryReadStartTicAttribute(String::Empty, readAttributeName, errorMessage))
   244 inline bool TicReader::TryReadStartTicAttribute(
String& readAttributeName)
   247     return this->TryReadStartTicAttribute(String::Empty, readAttributeName, errorMessage);
   250 inline bool TicReader::TryReadStartTicAttribute(
const String& attributeName, 
String& readAttributeName)
   253     return this->TryReadStartTicAttribute(attributeName, readAttributeName, errorMessage);
   256 inline void TicReader::ReadEndTicAttribute(
void)
   258     if (!this->TryReadEndTicAttribute())
   260         throw XmlException(
"Invalid Tic file format: missing EndTicAttribute tag '</{0}>'.", ticNodeTypeNames[TicNodeType::Attribute]);
   264 inline bool TicReader::TryReadEndTicAttribute()
   266     return this->TryReadEndTicNode(TicNodeType::Attribute);
   269 inline void TicReader::SkipTicAttributeValue()
   271     (void) this->ReadTicAttributeValue<String>();
   275 inline T TicReader::ReadTicAttributeValue()
   279     if (!this->TryReadTicAttributeValue<T>(result, errorMessage))
   287 inline bool TicReader::TryReadTicAttributeValue(T& result)
   290     return this->TryReadTicAttributeValue<T>(result, errorMessage);
   294 inline bool TicReader::TryReadTicAttributeValue(T& result, 
String& errorMessage)
   297     if (!this->TryReadTicAttributeContent(attributeValue, errorMessage))
   302     std::stringstream iss(attributeValue);
   303     iss >> boolalpha >> result;
   307 inline bool TicReader::TryReadTicAttributeValue(
String& result, 
String& errorMessage)
   310     if (!this->TryReadTicAttributeContent(result, errorMessage))
   322 inline void TicReader::ReadTicElementContent(
   325     SectionReadCallback<T> attributesReader,
   326     SectionReadCallback<T> childElementsReader,
   327     bool attributesAreOptional,
   328     bool elementsAreOptional)
   330     bool hasAttributesRead = 
false;
   331     bool hasChildElementsRead = 
false;
   333     while (!(hasAttributesRead && hasChildElementsRead))
   335         TicNodeType nodeType = TicNodeType::None;
   336         if (this->TryReadStartTicNode(nodeType))
   338             bool mustReadEndTicNode = 
true;
   341                 case TicNodeType::AttributeList:
   342                     if (attributesReader == 
nullptr)
   344                         this->SkipTicAttributeList();
   348                         (configuration.*attributesReader)(*
this, context);
   350                     hasAttributesRead = 
true;
   352                 case TicNodeType::ElementList:
   353                     if (childElementsReader == 
nullptr)
   355                         this->SkipTicElementList();
   356                         mustReadEndTicNode = 
false; 
   360                         (configuration.*childElementsReader)(*
this, context);
   362                     hasChildElementsRead = 
true;
   365                     throw XmlException(
"Invalid TIC file format: expecting attribute or element list");
   368             if(mustReadEndTicNode)
   370                 this->ReadEndTicNode(nodeType);
   375             if (!hasAttributesRead && !attributesAreOptional)
   377                 throw XmlException(
"Invalid TIC file format: expecting attribute list");
   379             else if (attributesReader == 
nullptr && attributesAreOptional)
   381                 hasAttributesRead = 
true;
   384             if (!hasChildElementsRead && !elementsAreOptional)
   386                 throw XmlException(
"Invalid TIC file format: expecting element list");
   388             else if (elementsAreOptional)
   390                 hasChildElementsRead = 
true;
 Definition: TicSerializationContext.hpp:18
 
Namespace for classes to read XML files
 
Definition: TicReader.hpp:36
 
Definition: Loggable.hxx:18
 
Definition: TicReader.hpp:22
 
Root namespace for the PLCnext API
 
This exception is used for xml parsing errors.
Definition: XmlException.hpp:14
 
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:22
 
System components used by the System, Device, Plc or Io domains.
 
Namespace for logging classes