8#include "Arp/System/Core/Enum.hxx" 
    9#include "Arp/System/Core/TypeName.hxx" 
   10#include "Arp/System/Commons/Chrono/Duration.hpp" 
   11#include "Arp/System/Commons/Exceptions/Exceptions.h" 
   12#include "Arp/System/Commons/Xml/XmlErrorHandler.hpp" 
   13#include "Arp/System/Commons/Xml/XmlNodeType.hpp" 
   16#include "boost/lexical_cast.hpp" 
   18namespace Arp { 
namespace System { 
namespace Commons { 
namespace Xml
 
   21class LibXmlErrorHandler;
 
   87            return boost::lexical_cast<T>(elementString);
 
   89        catch (std::exception& e)
 
   94                "Cannot convert '{}' to {}: {}", elementString, 
TypeName<T>().GetFullName(), e.what());
 
  113        if (TryGetAttributeValue<T>(attributeName, returnValue))
 
  120                "GetAttributeValue failed for mandatory attribute: {0} elementName: {1}",
 
  141        if (TryGetAttributeValueEnum<T>(attributeName, returnValue))
 
  148                "GetAttributeValueEnum failed for mandatory attribute: {0} elementName: {1}",
 
  168        if (!TryGetAttributeValueEnum<T>(attributeName, result))
 
  171                "GetAttributeValueOfEnum failed for mandatory attribute: {0} elementName: {1}", attributeName, 
GetElementLocalName());
 
  193        char* charValue = GetAttributeValueInternal(attributeName);
 
  194        if (charValue == 
nullptr)
 
  198        std::istringstream iss(charValue);
 
  200        FreeInternalAttributeValue(charValue);
 
  221        char* charValue = GetAttributeValueInternal(attributeName);
 
  222        if (charValue == 
nullptr)
 
  228        FreeInternalAttributeValue(charValue);
 
  252        value = defaultValue;
 
  253        return TryGetAttributeValueEnum<T>(attributeName, value);
 
  274        if (TryGetAttributeValueDuration<T>(attributeName, returnValue))
 
  281                "GetAttributeValueDuration failed for mandatory attribute: {0} elementName: {1}",
 
  324        value = defaultValue;
 
  325        return TryGetAttributeValueDuration<T>(attributeName, value);
 
  345        char* charValue = 
nullptr;
 
  348            charValue = GetAttributeValueInternal(attributeName);
 
  349            if (charValue == 
nullptr)
 
  354            value = boost::lexical_cast<T>(charValue);
 
  355            FreeInternalAttributeValue(charValue);
 
  358        catch (boost::bad_lexical_cast&)
 
  361            String strValue(charValue);
 
  362            FreeInternalAttributeValue(charValue);
 
  363            throw XmlException(
"Cast of attribute {0} to {1} failed value: {2}", attributeName,
 
  390        value = defaultValue;
 
  391        return TryGetAttributeValue<T>(attributeName, value);
 
  394    void EnableValidationException();
 
  395    void DisableValidationException();
 
  406    template<
typename... Args>
 
  413    char* GetAttributeValueInternal(
const char* attributeName);
 
  414    void FreeInternalAttributeValue(
char* attributeValue);
 
  415    XmlNodeType MoveToContent();
 
  416    void EnableValidation(
const String& xsdFile);
 
  417    void CheckForValidationException();
 
  418    bool MoveToNextElement(
void);
 
  424    bool validationEnabled;
 
  425    LibXmlErrorHandler* errorHandler;
 
  426    bool exceptionOnValidationError; 
 
  429    bool startElementRead;
 
  453template<
typename... Args>
 
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:21
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
Definition: Duration.hpp:16
This exception is used for xml parsing errors.
Definition: XmlException.hpp:15
static XmlException Create(void)
Creates an XmlException instance using a default message text.
Definition: XmlException.cpp:47
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:25
bool TryGetAttributeValueEnum(const char *attributeName, T &value)
trys reads an attribute value from the current element and converts the String to Enum<T>
Definition: XmlReader.hpp:191
XmlException CreateException(const char *message, const Args &... args)
Creates an exception by prefixing the given message with current doc name and line number
Definition: XmlReader.hpp:454
T ReadElementContent()
reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed
Definition: XmlReader.hpp:82
T GetAttributeValue(const char *attributeName)
reads an attribute value from the current element
Definition: XmlReader.hpp:110
int GetCurrentDepth()
gets the current depth of the current element inside the xml document
Definition: XmlReader.cpp:330
bool Read()
Reads to the next element inside the xml file
Definition: XmlReader.cpp:215
Enum< T > GetAttributeValueEnum(const char *attributeName)
reads an attribute value from the current element and converts the String to Enum<T>
Definition: XmlReader.hpp:137
XmlNodeType GetCurrentNodeType()
gets the type of the current xml element
Definition: XmlReader.cpp:245
bool ReadToNextSibling(const String &name)
reads to the next element with name which is a sibling of the current element
Definition: XmlReader.cpp:524
bool IsEmptyElement()
test if the current element is an empty element
Definition: XmlReader.cpp:307
bool TryGetAttributeValue(const char *attributeName, T defaultValue, T &value)
tries to read an attribute value from the current element if the attribute was not found or the conve...
Definition: XmlReader.hpp:387
bool SkipElement()
skips the current element with its whole subtree
Definition: XmlReader.cpp:361
bool TryGetAttributeValueDuration(const char *attributeName, T defaultValue, T &value)
tries to read an attribute value from the current element as std::crono::duration if the attribute wa...
Definition: XmlReader.hpp:322
XmlReader(void)
Default contructor.
Definition: XmlReader.cpp:23
bool TryGetAttributeValueEnum(const char *attributeName, Enum< T > &value)
trys reads an attribute value from the current element and converts the String to Enum<T>
Definition: XmlReader.hpp:219
void ReadStartElement(const char *elementName=nullptr)
reads to the next element and test if this is a start element with the given name
Definition: XmlReader.cpp:566
static XmlReader CreateForString(const String &buffer)
Creates a new Instance of the XmlReader reading from an in memory buffer
Definition: XmlReader.cpp:149
bool TryReadStartElement(const char *elementName=nullptr)
trys to read the next element and test if this is a start element with the given name
Definition: XmlReader.cpp:587
bool MoveToElement()
Moves the position of the current instance to the node that contains the current Attribute node.
Definition: XmlReader.cpp:268
T GetAttributeValueOfEnum(const char *attributeName)
reads an attribute value from the current element and converts the String to Enum<T>
Definition: XmlReader.hpp:165
const String & GetDocumentFileName()
Gets the current document filename of this XML reader
Definition: XmlReader.cpp:204
void ReadEndElement(void)
reads until the next end element is reached skips over an empty element
Definition: XmlReader.cpp:687
T GetAttributeValueDuration(const char *attributeName)
reads an attribute value from the current element and converts the String to std::chrono::duration i....
Definition: XmlReader.hpp:270
bool ReadToDescendant(const String &name)
reads the xml file until an element with name is reached or the current element is closed reads to th...
Definition: XmlReader.cpp:489
bool Skip()
skips the current element with its whole subtree (use SkipElement() because naming is more clear)
Definition: XmlReader.cpp:350
bool SkipElementContent()
skips the content of current element with its whole subtree but does not read end element tag
Definition: XmlReader.cpp:395
String ReadElementContent(void)
reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed
Definition: XmlReader.cpp:743
~XmlReader(void)
Destructs this instance and frees all resources.
Definition: XmlReader.cpp:49
static XmlReader Create(const String &filename)
Creates a new Instance of the XmlReader
Definition: XmlReader.cpp:82
bool TryGetAttributeValueEnum(const char *attributeName, T defaultValue, Enum< T > &value)
tries to read an attribute value from the current element as enum if the attribute was not found or t...
Definition: XmlReader.hpp:250
static bool TryCreate(const String &filename, XmlReader &reader)
Tries to creates a new Instance of the XmlReader
Definition: XmlReader.cpp:100
long GetLineNumber()
Gets the actual line number of this XML reader
Definition: XmlReader.cpp:192
String GetElementLocalName(void)
Reads the local name of the current active element
Definition: XmlReader.cpp:171
bool TryReadEndElement(void)
tries to read until the next end element is reached skips over an empty element
Definition: XmlReader.cpp:702
bool ReadToFollowing(const String &name)
reads the xml file until an element with name is reached or end of file is reached
Definition: XmlReader.cpp:465
bool TryGetAttributeValueDuration(const char *attributeName, T &value)
trys reads an attribute value from the current element and converts the String to std::chrono::durati...
Definition: XmlReader.hpp:299
bool TryGetAttributeValue(const char *attributeName, T &value)
tries to read an attribute value from the current element
Definition: XmlReader.hpp:343
static Enum Parse(const String &input)
Parses the given input string.
Definition: Enum.ipp:90
std::uint8_t uint8
The Arp unsigned integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:25
std::int8_t int8
The Arp integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:27
Root namespace for the PLCnext API
class ARP_DEPRECATED("Use Arp::Enum<T> instead.") EnumStrings
Deprecated! The class implements an adapter for enums to define the string literals of the enum entri...
Definition: EnumStrings.hxx:38