PLCnext API Documentation  20.6.0.30321
PlaceholderExpression.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Exceptions/Exceptions.h"
9 #include "Arp/System/Commons/Environment.hpp"
10 #include <sstream>
11 
12 namespace Arp { namespace System { namespace Commons { namespace Configuration
13 {
14 
16 {
17 public: // typedefs
18 
19 public: // construction/destruction
21  PlaceholderExpression(void) = default;
23  PlaceholderExpression(const PlaceholderExpression& arg) = default;
27  ~PlaceholderExpression(void) = default;
28 
29 public: // operators
30 
31 public: // static operations
32  static bool HasPlaceholder(const String& input, const String& placeholder);
33  static bool HasPlaceholder(const String& input);
34  static bool HasLogicalExpression(const String& input);
35 
36 public: // setter/getter operations
37 
38 public: // operations
39  String Resolve(const String& input);
40  bool TryResolve(const String& input, String& result);
41  bool ResolveCondition(const String& input);
42  String ResolveLogicalExpression(const String& input);
43 
44  template<class T>
45  T ResolveTo(const String& input);
46 
47 protected: // operations
48 
49 private: // static methods
50 
51 private: // methods
52  static bool HasLogicalExpression(const std::string& input);
53 
54 private: // fields
55 
56 private: // static fields
57  static const String envVarSeperator;
58 };
59 
61 // inline methods of class PlaceholderExpression
62 
63 inline bool PlaceholderExpression::HasLogicalExpression(const String& input)
64 {
65  return PlaceholderExpression::HasLogicalExpression(input.GetBaseString());
66 }
67 
68 template<class T>
69 inline T PlaceholderExpression::ResolveTo(const String& input)
70 {
71  if (input.IsEmpty())
72  {
73  throw ArgumentException("Input is empty.");
74  }
75  // else
76  std::istringstream iss(this->Resolve(input));
77  T result;
78  iss >> std::boolalpha >> result;
79  if (iss.fail())
80  {
81  throw ArgumentException("Input is not of required type.");
82  }
83  // else
84  return result;
85 }
86 
87 }}}} // end of namespace Arp::System::Commons::Configuration
PlaceholderExpression & operator=(const PlaceholderExpression &arg)=default
Assignment operator.
This exception is used when an invalid argument occurs.
Definition: ArgumentException.hpp:14
Root namespace for the PLCnext API
~PlaceholderExpression(void)=default
Destructs this instance and frees all resources.
PlaceholderExpression(void)=default
Constructs an PlaceholderExpression instance.
Definition: PlaceholderExpression.hpp:15
System components used by the System, Device, Plc or Io domains.