3#ifndef _aspose_system_boxed_value_h_
4#define _aspose_system_boxed_value_h_
7#include <system/get_hash_code.h>
8#include <system/object.h>
9#include <system/object_type.h>
10#include <system/boxable_traits.h>
11#include <system/timespan.h>
12#include <system/decimal.h>
13#include <system/guid.h>
14#include <system/value_type.h>
15#include <system/type_code.h>
23 template <
typename T>
class Nullable;
25 namespace BoxedValueDetail
36 typename std::enable_if<detail::has_operator_equal<T>::value,
bool>::type
39 return value1 == value2;
48 typename std::enable_if<detail::has_only_method_equals<T>::value,
bool>::type
51 return value1.Equals(value2);
61 return (std::isnan(value1) && std::isnan(value2)) ? true : value1 == value2;
71 return (std::isnan(value1) && std::isnan(value2)) ? true : value1 == value2;
77 : std::integral_constant<bool, std::is_arithmetic<T>::value || std::is_enum<T>::value>
81 template<
typename T,
typename Self>
87 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
88 RTTI_INFO_TEMPLATE_CLASS(
ThisType, ThisTypeBaseTypesInfo);
93 auto& self =
static_cast<Self*
>(
this)->unbox();
94 return self < other ? -1 : other < self ? 1 : 0;
162 namespace TypeCodeHelper
213 public std::conditional_t<BoxedValueDetail::ImplementsInterface_v<T, IComparable<T>>,
214 BoxedValueDetail::Comparable<T, BoxedValue<T>>, BoxedValueDetail::NonComparable>,
216 public std::conditional_t<std::is_same<T, System::String>::value, BoxedValueDetail::BoxedStringBase,
217 BoxedValueDetail::NonBoxedStringBase>
220 typedef System::BaseTypesInfo<System::Object> baseTypes;
233 return System::ObjectType::GetType<T>();
239 : m_original_typeid_hash( typeid(T).hash_code() )
240 , m_value_holder(value)
243 "Only arithmetic, enums and specified in IsBoxable<> types are supported, use specializations to extend");
250 return m_value_holder;
260 return typeid(V).hash_code() == m_original_typeid_hash;
268 if( !obj || !obj->
Is(GetType()) )
278 return System::GetHashCode<T>(m_value_holder);
285 return ToStringHelper(m_value_holder);
298 return ToUInt64Helper(m_value_holder);
305 return TypeCodeHelper::GetTypeCodeFor<T>();
313 size_t m_original_typeid_hash;
322 static typename std::enable_if<
323 std::is_arithmetic<C>::value || std::is_enum<C>::value,
String>::type
324 ToStringHelper(
const C& value)
333 static typename std::enable_if<
334 (!std::is_arithmetic<C>::value && !std::is_enum<C>::value && !IsSmartPtr<C>::value), String>::type
335 ToStringHelper(
const C& obj)
337 return obj.ToString();
344 static typename std::enable_if<IsSmartPtr<C>::value, String>::type
345 ToStringHelper(
const C& obj)
347 return obj->ToString();
353 static String ToStringHelper(
bool b)
355 return b ? u
"True" : u
"False";
359 template <
typename C>
360 static typename std::enable_if<std::is_convertible<C, uint64_t>::value, uint64_t>::type
361 ToUInt64Helper(C value)
363 return static_cast<uint64_t
>(value);
367 template <
typename C>
368 static typename std::enable_if<!std::is_convertible<C, uint64_t>::value, uint64_t>::type
383 typedef System::BaseTypesInfo<System::Object> baseTypes;
394 return System::ObjectType::GetType<T>();
401 : m_original_typeid_hash(typeid(T).hash_code())
402 , m_value_holder(value)
410 return m_value_holder;
420 return typeid(V).hash_code() == m_original_typeid_hash;
428 if (!obj || !obj->
Is(Type()))
432 return m_value_holder == boxed->
unbox();
438 return m_value_holder.GetHashCode();
451 size_t m_original_typeid_hash;
460 template <
typename T>
461 struct IsBoxedValue : std::false_type {};
465 template <
typename T>
466 struct IsBoxedValue<BoxedValue<
T>> : std::true_type {};
A base class that defines an interface and implements some fundamental methods of a descendant class ...
Definition: boxed_value.h:121
static SharedPtr< Object > Parse(const TypeInfo &type, const String &str)
Boxes the value of enumeration constant of the specified enumeration with the specified name.
System::String ToString(const System::String &format) const
Converts boxed object to string using specified format string.
virtual uint64_t GetUnsignedLongLongValue() const =0
Converts the boxed represented by the current object to 64-bit integer value.
virtual TypeCode GetTypeCode() const =0
Returns the value representing the type of the boxed value represented by the current object.
virtual bool IsBoxedEnum()=0
Determines if current object represents a boxed value of enum type.
static SharedPtr< Object > Parse(const TypeInfo &type, const String &str, bool ignoreCase)
Boxes the value of enumeration constant of the specified enumeration with the specified name....
Additional base class for BoxedValue for string to implement IEnumerator for char16_t interface.
Definition: boxed_value.h:104
System::SharedPtr< System::Collections::Generic::IEnumerator< char16_t > > GetEnumerator() override
Gets enumerator.
Simple implementation of IComparable<>
Definition: boxed_value.h:83
int CompareTo(T other) override
Compares the current object with the specified object.
Definition: boxed_value.h:91
Dummy base type non-string boxed types.
Definition: boxed_value.h:110
Dummy base type for boxed types what do not implement IComparable<>
Definition: boxed_value.h:99
Represents a boxed value. Objects of this class should only be allocated using System::MakeObject() f...
Definition: boxed_value.h:218
const T & unbox() const
Unboxes the value represented by the current object.
Definition: boxed_value.h:248
BoxedValue(const T &value)
Constructs an object that represents the specified value boxed.
Definition: boxed_value.h:238
bool Equals(ptr obj) override
Determines the equality of the boxed values represented by the current and specified objects.
Definition: boxed_value.h:266
int GetHashCode() const override
Returns a hash code for the current object.
Definition: boxed_value.h:276
uint64_t GetUnsignedLongLongValue() const override
Returns numeric value of boxed object if it can be cast too, zero otherwise.
Definition: boxed_value.h:296
bool is() const
Determines if the type of the boxed value represented by the current object is V.
Definition: boxed_value.h:258
bool IsBoxedEnum() override
Determines if current object represents a boxed value of enum type.
Definition: boxed_value.h:290
TypeCode GetTypeCode() const override
Returns the value representing the type of the boxed value represented by the current object.
Definition: boxed_value.h:303
const System::TypeInfo & GetType() const override
Gets actual type of object.
Definition: boxed_value.h:231
String ToString() const override
Converts boxed value represented by current object to string.
Definition: boxed_value.h:283
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:25
BoxedValue class implementation. Allows it BoxingValue specializations to be declared without duplica...
Definition: boxed_value.h:381
DefaultBoxedValue(const T &value)
Constructs a new instance of DefaultBoxedValue class that represents the specified value.
Definition: boxed_value.h:400
const T & unbox() const
Unboxes the boxed value.
Definition: boxed_value.h:408
int GetHashCode() const override
Returns a hash code for the current object.
Definition: boxed_value.h:436
bool is() const
Determines if the type of the boxed value represented by the current object is V.
Definition: boxed_value.h:418
bool Equals(ptr obj) override
Determines the equality of the boxed values represented by the current and specified objects.
Definition: boxed_value.h:426
String ToString() const override
Returns the string representation of the boxed value.
Definition: boxed_value.h:442
const System::TypeInfo & GetType() const override
Gets actual type of object.
Definition: boxed_value.h:392
Defines a method that compares two objects. Objects of this class should only be allocated using Syst...
Definition: icomparable.h:17
Forward declaration.
Definition: nullable.h:75
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
virtual bool Is(const TypeInfo &targetType) const
Check if object represents an instance of type described by targetType. Analog of C# 'is' operator.
virtual String ToString() const
Analog of C# Object.ToString() method. Enables converting custom objects to string.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
std::enable_if_t< std::is_same< Y, T >::value, SmartPtr< Y > > Cast() const
Casts pointer to its type itself.
Definition: smart_ptr.h:742
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:125
static String Format(const SharedPtr< IFormatProvider > &fp, const String &format, const Args &... args)
Formats string in C# style.
Definition: string.h:1445
String ToString() const
Wrapper for handling String class in contexts where ToString() is being called on value type objects.
Definition: string.h:510
Represents a particular type and provides information about it.
Definition: type_info.h:109
bool Equals< float >(float value1, float value2)
Compares two single-precision floating-point values.
Definition: boxed_value.h:59
bool Equals< double >(double value1, double value2)
Compares two double-precision floating-point values.
Definition: boxed_value.h:69
std::enable_if< detail::has_operator_equal< T >::value, bool >::type Equals(T value1, T value2)
Determines the equality of the specified value using operator==().
Definition: boxed_value.h:37
TypeCode GetTypeCodeFor< float >()
Template specialization for float.
Definition: boxed_value.h:194
TypeCode GetTypeCodeFor< uint16_t >()
Template specialization for uint16_t.
Definition: boxed_value.h:184
TypeCode GetTypeCodeFor< String >()
Template specialization for System::String.
Definition: boxed_value.h:202
TypeCode GetTypeCodeFor< double >()
Template specialization for double.
Definition: boxed_value.h:196
TypeCode GetTypeCodeFor< int64_t >()
Template specialization for int64_t.
Definition: boxed_value.h:190
TypeCode GetTypeCodeFor< bool >()
Template specialization for bool.
Definition: boxed_value.h:174
TypeCode GetTypeCodeFor< char_t >()
Template specialization for char_t.
Definition: boxed_value.h:176
TypeCode GetTypeCodeFor< uint32_t >()
Template specialization for uint32_t.
Definition: boxed_value.h:188
TypeCode GetTypeCodeFor< Decimal >()
Template specialization for System::Decimal.
Definition: boxed_value.h:198
TypeCode GetTypeCodeFor< int16_t >()
Template specialization for int16_t.
Definition: boxed_value.h:182
TypeCode GetTypeCodeFor()
A template function that returns an enum value representing the function's template type argument.
Definition: boxed_value.h:168
TypeCode GetTypeCodeFor< int32_t >()
Template specialization for int32_t.
Definition: boxed_value.h:186
TypeCode GetTypeCodeFor< DateTime >()
Template specialization for System::DateTime.
Definition: boxed_value.h:200
TypeCode GetTypeCodeFor< uint64_t >()
Template specialization for uint64_t.
Definition: boxed_value.h:192
TypeCode GetTypeCodeFor< uint8_t >()
Template specialization for uint8_t.
Definition: boxed_value.h:180
TypeCode GetTypeCodeFor< int8_t >()
Template specialization for int8_t.
Definition: boxed_value.h:178
Definition: db_command.h:9
TypeCode
Represents the type of an object.
Definition: type_code.h:19
@ String
A sealed class type representing Unicode character strings.
@ Boolean
A simple type representing Boolean values of true or false.
@ Int16
An integral type representing signed 16-bit integers with values between -32768 and 32767.
@ Object
A general type representing any reference or value type not explicitly represented by another TypeCod...
@ Single
A floating point type representing values ranging from approximately 1.5 x 10 -45 to 3....
@ SByte
An integral type representing signed 8-bit integers with values between -128 and 127.
@ UInt16
An integral type representing unsigned 16-bit integers with values between 0 and 65535.
@ DateTime
A type representing a date and time value.
@ Char
An integral type representing unsigned 16-bit integers with values between 0 and 65535.
@ Decimal
A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 s...
@ Byte
An integral type representing unsigned 8-bit integers with values between 0 and 255.
@ UInt64
An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615...
@ Int32
An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
@ Double
A floating point type representing values ranging from approximately 5.0 x 10 -324 to 1....
@ UInt32
An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.
@ Int64
An integral type representing signed 64-bit integers with values between -9223372036854775808 and 922...
Template predicate that checks if boxed object should implement given interface by itself.
Definition: boxable_traits.h:33
Template predicate that checks if boxing of the specified type is supported.
Definition: boxable_traits.h:16
TypeInfo structure for BoxedValue class.
Definition: type_info.h:367