PLCnext API Documentation 25.0.2.69
TicReader.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/PimplPtr.hxx"
9#include "Arp/Base/Core/TryConvert.hpp"
10#include "Arp/System/Commons/Exceptions/XmlException.hpp"
11#include <functional>
12#include <sstream>
13
15{
16class XmlReader;
17}
18
19namespace Arp::Io::Commons::Configuration
20{
21
23class ARP_EXPORT TicReader
24{
25public: // Impl forward declaration
26 class Impl;
27
28public: // usings
29 using AttributeReader = std::function<void(TicReader& reader, const String& readAttributeName)>;
30 using SubelementReader = std::function<void(TicReader& reader, const String& readElementName)>;
32
33public: // canonical construction/destruction/assignment
34 TicReader(const TicReader& arg) = delete;
35 TicReader(TicReader&& arg)noexcept;
36 TicReader& operator=(const TicReader& arg) = delete;
37 TicReader& operator=(TicReader&& arg)noexcept;
39
40public: // construction
41 explicit TicReader(XmlReader&& xmlReader);
42
43public: // setter/getter operations
44 size_t GetLineNumber(void);
45 const String& GetDocumentFileName(void);
46
47public: // operations
48 void ReadDocumentStart(String& rootElementName);
49 void ReadDocumentEnd(void);
50 void ReadElementContent(const AttributeReader& attributeReader, const SubelementReader& elementReader);
51 void Skip(void);
52 String ReadTicAttributeValue(void);
53
54public: // template operations
55 template<class T> T ReadTicAttributeValueAs(void);
56
57public: // Impl operations
58 Impl& GetImpl(void);
59 const Impl& GetImpl(void)const;
60
61private: // Impl usings
62 using Pimpl = PimplPtr<Impl>;
63
64private: // Impl fields
65 Pimpl pimpl;
66};
67
73template<class T>
75{
77
78 T result{};
79 String attribute = this->ReadTicAttributeValue();
80 if (!TryConvert::ToValue<T>(attribute, result))
81 {
82 throw XmlException::Create(this->GetDocumentFileName(), static_cast<long>(this->GetLineNumber()), "Cannot convert value '{}'", result);
83 }
84 return result;
85}
86
87} // end of namespace Arp::Io::Commons::Configuration
Adapter class to implement PImpl idiom.
Definition: PimplPtr.hxx:15
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
This class is used to read the content of Tic files.
Definition: TicReader.hpp:24
const String & GetDocumentFileName(void)
Returns the filename of the current Tic document.
Definition: TicReader.cpp:49
TicReader(TicReader &&arg) noexcept
Default move constructor.
size_t GetLineNumber(void)
Returns the current line number of the read Tic document.
Definition: TicReader.cpp:56
String ReadTicAttributeValue(void)
Reads the value of the current attribute as String.
Definition: TicReader.cpp:95
TicReader & operator=(TicReader &&arg) noexcept
Default move-assignment operator.
T ReadTicAttributeValueAs(void)
Reads the value of the current attribute and converts it to the specified type T .
Definition: TicReader.hpp:74
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
Namespace for classes to read XML files