8#ifndef ARP_USE_ARP_SYSTEM_CORE
10#include "Arp/Base/Core/Enum.hxx"
15#include "Arp/System/Core/TypeName.hxx"
16#include "Arp/System/Core/Exception.hpp"
28template<
class T =
void>
34 using U =
typename std::underlying_type<T>::type;
42 static const T
Zero =
static_cast<T
>(0);
55 static bool TryParse(
const String& input, T& result);
67 static bool TryParse(
const char* input, T& result);
92 String
ToString(
bool throwIfInvalid =
true)
const;
117 operator T(
void)
const;
133 return Enum<T>(value);
145inline Enum<T>& Enum<T>::operator=(Value rhs)
152inline Enum<T>::operator T()
const
154 return this->GetValue();
158inline Enum<T>& Enum<T>::operator&=(Enum rhs)
160 this->value =
static_cast<T
>(
static_cast<U
>(this->value) &
static_cast<U
>(rhs.value));
165inline Enum<T>& Enum<T>::operator|=(Enum rhs)
167 this->value =
static_cast<T
>(
static_cast<U
>(this->value) |
static_cast<U
>(rhs.value));
172inline T Enum<T>::GetValue()
const
178inline typename Enum<T>::U Enum<T>::ToUnderlyingType()
const
180 return static_cast<U
>(this->value);
184inline String Enum<T>::ToString(
bool throwIfInvalid)
const
186 std::ostringstream oss;
188 if (oss.fail() && throwIfInvalid)
190 throw Exception(
"Invalid value for Enum '{0}' occurs: {1}", TypeName<Enum>(),
static_cast<U
>(this->value));
196inline bool Enum<T>::TryParse(
const String& input, T& result)
198 return Enum::TryParse(input.CStr(), result);
202inline bool Enum<T>::TryParse(
const String& input, Enum& result)
204 return Enum::TryParse(input.CStr(), result);
208inline bool Enum<T>::TryParse(
const char* input, T& result)
211 std::istringstream iss(input);
223inline bool Enum<T>::TryParse(
const char* input, Enum& result)
226 if (!Enum::TryParse(input, value))
235inline Enum<T> Enum<T>::Parse(
const String& input)
238 if (!Enum::TryParse(input, result))
240 throw Exception(
"Invalid string for Enum '{0}' occurs: {1}", TypeName<Enum>(), input);
247inline Enum<T> Enum<T>::Parse(
const char* input)
250 if (!Enum::TryParse(input, result))
252 throw Exception(
"Invalid string for Enum '{0}' occurs: {1}", TypeName<Enum>(), input);
268inline std::ostream& operator<<(std::ostream& os, Enum<T> value)
270 return os << value.GetValue();
278inline std::istream& operator>>(std::istream& is, Enum<T>& value)
280 T enumValue = Enum<T>::Zero;
297inline Enum<T> operator|(Enum<T> lhs, Enum<T> rhs)
299 Enum<T> result = lhs;
309inline Enum<T> operator&(Enum<T> lhs, Enum<T> rhs)
311 Enum<T> result = lhs;
324inline bool operator==(Enum<T> lhs, Enum<T> rhs)
326 return lhs.GetValue() == rhs.GetValue();
334inline bool operator<(Enum<T> lhs, Enum<T> rhs)
336 return lhs.GetValue() < rhs.GetValue();
344inline bool operator>(Enum<T> lhs, Enum<T> rhs)
346 return lhs.GetValue() > rhs.GetValue();
354inline bool operator<=(Enum<T> lhs, Enum<T> rhs)
356 return lhs.GetValue() <= rhs.GetValue();
364inline bool operator>=(Enum<T> lhs, Enum<T> rhs)
366 return lhs.GetValue() >= rhs.GetValue();
377inline bool operator==(Enum<T> lhs, T rhs)
379 return lhs.GetValue() == rhs;
387inline bool operator<(Enum<T> lhs, T rhs)
389 return lhs.GetValue() < rhs;
397inline bool operator>(Enum<T> lhs, T rhs)
399 return lhs.GetValue() > rhs;
407inline bool operator<=(Enum<T> lhs, T rhs)
409 return lhs.GetValue() <= rhs;
417inline bool operator>=(Enum<T> lhs, T rhs)
419 return lhs.GetValue() >= rhs;
430inline bool operator==(T lhs, Enum<T> rhs)
432 return lhs == rhs.GetValue();
440inline bool operator<(T lhs, Enum<T> rhs)
442 return lhs < rhs.GetValue();
450inline bool operator>(T lhs, Enum<T> rhs)
452 return lhs > rhs.GetValue();
460inline bool operator<=(T lhs, Enum<T> rhs)
462 return lhs <= rhs.GetValue();
470inline bool operator>=(T lhs, Enum<T> rhs)
472 return lhs >= rhs.GetValue();
static constexpr T Zero
Zero initialized Enum value.
Definition: Enum.hxx:30
T Value
The adapted enum class type.
Definition: Enum.hxx:23
typename std::underlying_type< T >::type U
The underlying integral type of the adapted enum class type.
Definition: Enum.hxx:24
Enum< T > make_enum(T value)
Global make function to adapt any enum class by class Enum.
Definition: Enum.ipp:222
Enum & operator=(Value arg)
The assignment operator for a value of the adapted type.
Definition: Enum.ipp:126
T GetValue(void) const
Gets the adapted enum value.
Definition: Enum.ipp:155
Enum & operator&=(Enum rhs)
The assignment AND operator.
Definition: Enum.ipp:136
Enum & operator|=(Enum rhs)
The assignment OR operator.
Definition: Enum.ipp:146
static bool TryParse(const String &input, Enum &result)
Tries to parse the given input string.
Definition: Enum.ipp:45
String ToString(bool throwIfInvalid=true) const
Converts this instance to its string representation.
Definition: Enum.ipp:199
U ToUnderlyingType(void) const
Converts this instance to the underlying integral type of its adapted enum type
Definition: Enum.ipp:190
Enum(Value initialValue=Zero)
Constructs an instance of Enum with the given value.
Definition: Enum.ipp:25
static Enum Parse(const String &input)
Parses the given input string.
Definition: Enum.ipp:90
Root namespace for the PLCnext API