3#ifndef _aspose_system_nullable_h_
4#define _aspose_system_nullable_h_
6#include <system/get_hash_code.h>
7#include <system/boxable_traits.h>
8#include <system/default.h>
9#include <system/string.h>
28 ASPOSECPP_SHARED_API
void ThrowNullableObjectMustHaveAValue();
29 ASPOSECPP_SHARED_API
void ThrowNullableNullReference();
96 Nullable(
const T1& value) : m_has_value(true), m_value(value)
103 template<
typename T1>
109 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>>
116 template<
typename T1>
117 typename std::enable_if<!IsNullable<T1>::value && !std::is_null_pointer<T1>::value,
Nullable<T>&>::type
operator=(
const T1& x)
119 this->m_has_value =
true;
120 this->m_value =
static_cast<T
>(x);
129 template<
typename T1>
132 this->m_has_value = x.m_has_value;
135 this->m_value = x.m_value;
147 Details::ThrowNullableObjectMustHaveAValue();
159 operator const T&()
const
162 Details::ThrowNullableObjectMustHaveAValue();
168 void reset() { m_has_value =
false; }
172 bool IsNull()
const {
return !m_has_value; }
180 template<
typename T1>
181 bool NullableBoolHelper(
const T1& other,
const std::function<
bool()>& f,
bool default_if_both_are_null =
false)
const
187 return default_if_both_are_null;
211 template<
typename T1>
212 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator==(
const T1& other)
const
214 return m_has_value && m_value == other;
221 template<
typename T1>
224 return NullableBoolHelper<Nullable<T1>>(other,
225 [&] {
return m_value == other.
get_Value(); },
233 template<
typename T1>
234 typename std::enable_if<IsNullable<T1>::value,
bool>::type
Equals(
const T1& other)
const
236 return ((!m_has_value) && (!other.m_has_value)) || (m_has_value && other.m_has_value && (m_value == other.get_Value()));
247 template<
typename T1>
248 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator!=(
const T1& other)
const
250 return IsNull() ? true : m_value != other;
257 template<
typename T1>
260 return NullableBoolHelper<Nullable<T1>>(other,
261 [&] {
return m_value != other.
get_Value(); }
272 template<
typename T1>
273 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>(
const T1& other)
const
275 return m_has_value && m_value > other;
282 template<
typename T1>
285 return NullableBoolHelper<Nullable<T1>>(other,
286 [&] {
return m_value > other.
get_Value(); }
297 template<
typename T1>
298 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<(
const T1& other)
const
300 return m_has_value && m_value < other;
307 template<
typename T1>
310 return NullableBoolHelper<Nullable<T1>>(other,
311 [&] {
return m_value < other.
get_Value(); }
323 template<
typename T1>
324 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>=(
const T1& other)
const
326 return m_has_value && m_value >= other;
333 template<
typename T1>
336 return NullableBoolHelper<Nullable<T1>>(other,
337 [&] {
return m_value >= other.
get_Value(); }
348 template<
typename T1>
349 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<=(
const T1& other)
const
351 return m_has_value && m_value <= other;
358 template<
typename T1>
361 return NullableBoolHelper<Nullable<T1>>(other,
362 [&] {
return m_value <= other.
get_Value(); }
373 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
384 template<
typename T1>
387 return (
IsNull() || other.IsNull()) ?
nullptr :
395 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
397 static_assert(std::is_null_pointer<T1>::value,
"Operator '-' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
405 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
416 template<
typename T1>
419 return (
IsNull() || other.IsNull()) ?
nullptr :
436 template<
typename T1>
449 template<
typename T1>
452 m_has_value = m_has_value && !other.
IsNull();
460 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
462 static_assert(std::is_null_pointer<T1>::value,
"Operator '-=' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
470 template<typename T1, typename = typename std::enable_if<!std::is_null_pointer<T1>::value, T1>::type>
483 template<
typename T1 = T>
502 template<
typename T1 = T>
522 template<
typename T1>
525 m_has_value = m_has_value && !other.
IsNull();
535 return m_has_value ? System::GetHashCode<T>(m_value) : 0;
542 return m_has_value ? ToStringHelper(m_value) : u
"";
550 return m_has_value ? m_value : default_value;
555 return m_has_value ? m_value : Default<T>();
569 static typename std::enable_if<
570 std::is_arithmetic<C>::value || std::is_enum<C>::value,
String>::type
571 ToStringHelper(
const C& value)
580 static typename std::enable_if<
581 (!std::is_arithmetic<C>::value && !std::is_enum<C>::value && !IsSmartPtr<C>::value && !IsExceptionWrapper<C>::value), String>::type
582 ToStringHelper(
const C& obj)
584 return obj.ToString();
591 static typename std::enable_if<
592 IsSmartPtr<C>::value || IsExceptionWrapper<C>::value, String>::type
593 ToStringHelper(
const C& obj)
595 return obj->ToString();
601 static String ToStringHelper(
bool b)
603 return b ? u
"True" : u
"False";
642 template<
typename T1,
typename T2>
643 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
652 template<
typename T1,
typename T2>
653 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
662 template<
typename T1,
typename T2>
663 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
672 template<
typename T1,
typename T2>
673 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
682 template<
typename T1,
typename T2>
683 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
692 template<
typename T1,
typename T2>
693 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
705 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
708 return other.
IsNull() ? nullptr :
Nullable<
decltype(some + other.get_Value())>(some + other.get_Value());
720 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
723 return other.
IsNull() ? nullptr :
Nullable<
decltype(some - other.get_Value())>(some - other.get_Value());
728 template <
typename T>
729 struct IsBoxable<Nullable<T>> : std::true_type {};
733 template <
typename T>
736 if (value ==
nullptr)
737 *stream <<
"nullptr";
746 template <
typename T>
757 template <
typename T>
Forward declaration.
Definition: nullable.h:75
Nullable< T > operator-=(const Nullable< T1 > &other)
Applies operator-=() to the value represented by the current object using the value represented by th...
Definition: nullable.h:523
Nullable< T > operator+=(std::nullptr_t)
Resets the current object so that it represents a null-value.
Definition: nullable.h:426
std::enable_if<!IsNullable< T1 >::value, bool >::type operator>(const T1 &other) const
Determines if the value represented by the current object is greater than the specified value by appl...
Definition: nullable.h:273
Nullable< T > operator+=(const Nullable< T1 > &other)
Applies operator+=() to the value represented by the current object using the value represented by th...
Definition: nullable.h:450
bool operator>(std::nullptr_t) const
Always returns false.
Definition: nullable.h:266
bool operator!=(const Nullable< T1 > &other) const
Determines if the value represented by the current object is not equal to the value represented by th...
Definition: nullable.h:258
std::enable_if<!IsNullable< T1 >::value, Nullable< T > >::type operator-=(const T1 &other)
Applies operator-=() to the value represented by the current object using the specified value as a ri...
Definition: nullable.h:471
Nullable< T > & operator=(const Nullable< T1 > &x)
Replaces the object's currently represented value with the specified one.
Definition: nullable.h:130
void reset()
Sets the currently represented value to null.
Definition: nullable.h:168
Nullable< T > operator=(std::nullptr_t)
Assigns a null to the current object.
Definition: nullable.h:110
bool operator!=(std::nullptr_t) const
Determines if the value represented by the current object is not null.
Definition: nullable.h:241
Nullable(std::nullptr_t)
Constructs an instance that represents null.
Definition: nullable.h:88
auto operator-(const T1 &other) const -> Nullable< decltype(get_Value() - other)>
Subtracts nullable and non-nullable values.
Definition: nullable.h:406
auto operator-(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value() - other.get_Value())>
Subtracts nullable values.
Definition: nullable.h:417
bool operator<(std::nullptr_t) const
Always returns false.
Definition: nullable.h:291
bool operator==(std::nullptr_t) const
Determines if the value represented by the current object is null.
Definition: nullable.h:205
bool NullableBoolHelper(const T1 &other, const std::function< bool()> &f, bool default_if_both_are_null=false) const
Helper function to check if this and other are both not nulls and call a lambda if so....
Definition: nullable.h:181
bool operator>=(const Nullable< T1 > &other) const
Determines if the value represented by the current object is greater or equal to the value represente...
Definition: nullable.h:334
T ValueType
An alias for a type of the value represented by this class.
Definition: nullable.h:81
T get_Value() const
Returns a copy of the value represented by the current object.
Definition: nullable.h:144
std::enable_if<!IsNullable< T1 >::value, bool >::type operator<(const T1 &other) const
Determines if the value represented by the current object is less than the specified value by applyin...
Definition: nullable.h:298
int GetHashCode() const
Returns a hash code for the current object.
Definition: nullable.h:533
std::enable_if< IsNullable< T1 >::value, bool >::type Equals(const T1 &other) const
Determines if the value represented by the current object is equal to the value represented by the sp...
Definition: nullable.h:234
std::enable_if<!IsNullable< T1 >::value, bool >::type operator!=(const T1 &other) const
Determines if the value represented by the current object is not equal to the specified value.
Definition: nullable.h:248
Nullable< T > operator-=(T1)
Returns an instance of Nullable class that represents a null-value.
Definition: nullable.h:461
bool operator>=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:317
std::enable_if< std::is_same< T1, bool >::value, Nullable< T > >::type operator|=(bool other)
Applies operator|=() to the value represented by the current object using the specified value as a ri...
Definition: nullable.h:484
bool operator==(const Nullable< T1 > &other) const
Determines if the value represented by the current object is equal to the value represented by the sp...
Definition: nullable.h:222
Nullable< T > operator+(std::nullptr_t) const
Returns a default constructed instance of Nullable<T> class.
Definition: nullable.h:367
Nullable()
Constructs an instance that represents null-value.
Definition: nullable.h:84
std::enable_if< std::is_same< T1, bool >::value, Nullable< T > >::type operator&=(bool other)
Applies operator&=() to the value represented by the current object using the specified value as a ri...
Definition: nullable.h:503
String ToString() const
Converts the value represented by the current object to string.
Definition: nullable.h:540
bool operator>(const Nullable< T1 > &other) const
Determines if the value represented by the current object is greater than the value represented by th...
Definition: nullable.h:283
bool operator<=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:342
std::enable_if<!IsNullable< T1 >::value, bool >::type operator<=(const T1 &other) const
Determines if the value represented by the current object is less or equal to the specified value by ...
Definition: nullable.h:349
bool IsNull() const
Determines if the current object represents a null-value.
Definition: nullable.h:172
bool operator<(const Nullable< T1 > &other) const
Determines if the value represented by the current object is less than the value represented by the s...
Definition: nullable.h:308
std::enable_if<!IsNullable< T1 >::value, Nullable< T > >::type operator+=(const T1 &other)
Applies operator+=() to the value represented by the current object using the specified value as a ri...
Definition: nullable.h:437
std::enable_if<!IsNullable< T1 >::value &&!std::is_null_pointer< T1 >::value, Nullable< T > & >::type operator=(const T1 &x)
Replaces the object's currently represented value with the specified one.
Definition: nullable.h:117
T GetValueOrDefault()
Definition: nullable.h:553
auto operator+(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value()+other.get_Value())>
Sums nullable values.
Definition: nullable.h:385
bool operator<=(const Nullable< T1 > &other) const
Determines if the value represented by the current object is less or equal to the value represented b...
Definition: nullable.h:359
auto operator+(const T1 &other) const -> Nullable< decltype(get_Value()+other)>
Sums nullable and non-nullable values.
Definition: nullable.h:374
std::enable_if<!IsNullable< T1 >::value, bool >::type operator==(const T1 &other) const
Determines if the value represented by the current object is equal to the specified value.
Definition: nullable.h:212
Nullable(const Nullable< T1 > &value)
Constructs an instance that represents a value that is represented by the specified Nullable object....
Definition: nullable.h:104
Nullable< T > operator-(T1) const
Subtracts nullable and null-pointed values.
Definition: nullable.h:396
Nullable(const T1 &value)
Constructs an instance of Nullable class that represents the specified value converted (if necessary)...
Definition: nullable.h:96
T GetValueOrDefault(T default_value)
Returns the value represented by the current object or the specified value if the value represented b...
Definition: nullable.h:548
std::enable_if<!IsNullable< T1 >::value, bool >::type operator>=(const T1 &other) const
Determines if the value represented by the current object is greater or equal to the value represente...
Definition: nullable.h:324
bool get_HasValue() const
Determines whether the current object represents any value.
Definition: nullable.h:154
Represents C# System.Nullable (with no type arguments) static class. Unable to use original name due ...
Definition: nullable.h:768
static const System::TypeInfo & GetUnderlyingType(const System::TypeInfo &nullableType)
Returns the underlying type argument of the specified nullable type.
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:1415
std::string ToUtf8String() const
Converts string to std::string. Uses UTF-8 encoding.
Represents a particular type and provides information about it.
Definition: type_info.h:109
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:156
Decimal operator+(const T &x, const Decimal &d)
Returns a new instance of Decimal class that represents a value that is a sum of the specified value ...
Definition: decimal.h:542
constexpr bool operator>(std::nullptr_t, DateTime)
Definition: date_time.h:714
auto operator-(DayOfWeek a, DayOfWeek b)
Calculates the number of days between two days of week.
Definition: day_of_week.h:25
std::ostream & operator<<(std::ostream &stream, DateTime date_time)
Insert data into the stream using UTF-8 encoding.
Definition: date_time.h:729
constexpr bool operator<(std::nullptr_t, DateTime)
Definition: date_time.h:712
constexpr bool operator<=(std::nullptr_t, DateTime)
Definition: date_time.h:713
constexpr bool operator>=(std::nullptr_t, DateTime)
Definition: date_time.h:715
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:150
A template predicate that determines if its template argument T in Nullable or its subclass.
Definition: nullable.h:23
Tests if specific type is a specialization of specific template. If it is, inherits std::true_type,...
Definition: detail.h:80