PLCnext API Documentation 25.0.2.69
PlaceholderExpression.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Core/Enumerator.hxx"
9#include "Arp/System/Commons/Exceptions/Exceptions.h"
10#include "Arp/System/Commons/Environment.hpp"
11#include <sstream>
12
13namespace Arp { namespace System { namespace Commons { namespace Configuration
14{
15
17{
18public: // nested types
19 class Enumerator : public Arp::Enumerator<const String&>
20 {
21 public: // construcion
22 explicit Enumerator(const String& input);
23
24 public: // Enumerator<String> operations
25 bool MoveNext(void)override;
26 bool IsCurrentBuiltIn(void); // placeholder starts with '!'
27
28 private:
29 size_t currentStart = 0;
30 size_t currentEnd = 0;
31 String input;
32 };
33
34public: // construction/destruction
36 PlaceholderExpression(void) = default;
42 ~PlaceholderExpression(void) = default;
43
44public: // operators
45
46public: // static operations
47 static bool HasPlaceholder(const String& input, const String& placeholder);
48 static bool HasPlaceholder(const String& input);
49 static bool HasLogicalExpression(const String& input);
50 static String GetPlaceholderName(const String& placeholderToken);
51 static Enumerator GetEnumerator(const String& input);
52
53public: // setter/getter operations
54
55public: // operations
56 String Resolve(const String& input);
57 bool TryResolve(const String& input, String& result);
58 bool ResolveCondition(const String& input);
59 String ResolveLogicalExpression(const String& input);
60
61 template<class T>
62 T ResolveTo(const String& input);
63
64protected: // operations
65
66private: // static methods
67
68private: // methods
69 static bool TryResolveLogicalExpression(const String& input, bool& result);
70 static bool TryResolveLogicalExpression(const String& input, String& result);
71 static bool HasLogicalExpression(const std::string& input);
72
73private: // fields
74
75private: // static fields
76 static const String envVarSeperator;
77};
78
80// inline methods of class PlaceholderExpression
81
82template<class T>
83inline T PlaceholderExpression::ResolveTo(const String& input)
84{
85 if (input.IsEmpty())
86 {
87 throw ArgumentException("Input is empty.");
88 }
89 // else
90 std::istringstream iss(this->Resolve(input));
91 T result;
92 iss >> std::boolalpha >> result;
93 if (iss.fail())
94 {
95 throw ArgumentException("Input is not of required type.");
96 }
97 // else
98 return result;
99}
100
101}}}} // end of namespace Arp::System::Commons::Configuration
This exception is thrown when an invalid argument occurs.
Definition: ArgumentException.hpp:17
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:24
Enumerator(void)
Constructs a default Enumerator instance.
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
bool IsEmpty(void) const
Determines if this string is empty.
Definition: String.ipp:991
bool MoveNext(void) override
Moves this enumerator to the next position.
Definition: PlaceholderExpression.cpp:162
Definition: PlaceholderExpression.hpp:17
PlaceholderExpression(const PlaceholderExpression &arg)=default
Copy constructor.
~PlaceholderExpression(void)=default
Destructs this instance and frees all resources.
PlaceholderExpression & operator=(const PlaceholderExpression &arg)=default
Assignment operator.
PlaceholderExpression(void)=default
Constructs an PlaceholderExpression instance.
Root namespace for the PLCnext API