CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
boxed_enum.h
1
3#ifndef _aspose_system_boxed_enum_h_
4#define _aspose_system_boxed_enum_h_
5
6#include <system/boxed_value.h>
7#include <system/reflection.h>
8#include <system/details/is_defined.h>
9#include <cstdint>
10
11namespace System
12{
13 template<class T>
14 static bool IsEnumMetaInfoDefined(T value);
15
16 template <class T>
17 static System::String EnumGetName(T value);
18
25 template<typename E, typename UT = typename std::underlying_type<E>::type>
26 class ASPOSECPP_SHARED_CLASS BoxedEnum : public System::BoxedValue<UT>
27 {
28 // BoxedEnum now takes TypeInfo from TypeInfo. It is required that BoxedEnum<T> and EnumValues<T> use the same.
31
32 RTTI_INFO_CUSTOM(System::BoxedEnum<E>, System::BaseTypesInfo<System::BoxedValue<UT>>);
33
34 public:
37 BoxedEnum(E e) : System::BoxedValue<UT>(static_cast<UT>(e)) {}
38
41 bool IsBoxedEnum() override
42 {
43 return true;
44 }
45
48 uint64_t GetUnsignedLongLongValue() const override
49 {
50 return static_cast<uint64_t>(System::BoxedValue<UT>::unbox());
51 }
52
55 System::String ToString() const override
56 {
57 return MakeEnumString();
58 }
59
60 private:
61 template<typename T = E>
62 typename std::enable_if<!Details::IsDefined<EnumMetaInfo<T>>::value, System::String>::type
63 MakeEnumString() const
64 {
66 }
67
68 template<typename T = E>
69 typename std::enable_if<Details::IsDefined<EnumMetaInfo<T>>::value, System::String>::type
70 MakeEnumString() const
71 {
72 const UT& underlyingValue = System::BoxedValue<UT>::unbox();
73 const T& enumValue = static_cast<T>(underlyingValue);
74 System::String res = EnumGetName(enumValue);
76 res = System::String::Format(u"{0}", underlyingValue);
77 return res;
78 }
79
80 };
81}
82
83#endif //_aspose_system_boxed_enum_h_
Represents boxed enumeration value. Objects of this class should only be allocated using System::Make...
Definition: boxed_enum.h:27
System::String ToString() const override
Converts boxed value represented by the current object to string.
Definition: boxed_enum.h:55
uint64_t GetUnsignedLongLongValue() const override
Converts the value of the boxed enumeration constant to 64-bit integer value.
Definition: boxed_enum.h:48
BoxedEnum(E e)
Constructs an instance that represents the specified enumeration value.
Definition: boxed_enum.h:37
bool IsBoxedEnum() override
Determines whether the current object represents a boxed value of enum type.
Definition: boxed_enum.h:41
Represents a boxed value. Objects of this class should only be allocated using System::MakeObject() f...
Definition: boxed_value.h:172
const T & unbox() const
Unboxes the value represented by the current object.
Definition: boxed_value.h:202
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
static String Format(const SharedPtr< IFormatProvider > &fp, const String &format, const Args &... args)
Formats string in C# style.
Definition: string.h:1405
bool IsNullOrEmpty() const
Checks if string is empty or is considered null.
Definition: db_command.h:9
static bool IsEnumMetaInfoDefined(T value)
static System::String EnumGetName(T value)
TypeInfo structure for BoxedValue class.
Definition: type_info.h:367