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();
167 operator const T&()
const
170 Details::ThrowNullableObjectMustHaveAValue();
176 void reset() { m_has_value =
false; }
180 bool IsNull()
const {
return !m_has_value; }
188 template<
typename T1>
189 bool NullableBoolHelper(
const T1& other,
const std::function<
bool()>& f,
bool default_if_both_are_null =
false)
const
195 return default_if_both_are_null;
219 template<
typename T1>
220 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator==(
const T1& other)
const
222 return m_has_value && m_value == other;
229 template<
typename T1>
232 return NullableBoolHelper<Nullable<T1>>(other,
233 [&] {
return m_value == other.
get_Value(); },
241 template<
typename T1>
242 typename std::enable_if<IsNullable<T1>::value,
bool>::type
Equals(
const T1& other)
const
244 return ((!m_has_value) && (!other.m_has_value)) || (m_has_value && other.m_has_value && (m_value == other.get_Value()));
255 template<
typename T1>
256 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator!=(
const T1& other)
const
258 return IsNull() ? true : m_value != other;
265 template<
typename T1>
268 return NullableBoolHelper<Nullable<T1>>(other,
269 [&] {
return m_value != other.
get_Value(); }
280 template<
typename T1>
281 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>(
const T1& other)
const
283 return m_has_value && m_value > other;
290 template<
typename T1>
293 return NullableBoolHelper<Nullable<T1>>(other,
294 [&] {
return m_value > other.
get_Value(); }
305 template<
typename T1>
306 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<(
const T1& other)
const
308 return m_has_value && m_value < other;
315 template<
typename T1>
318 return NullableBoolHelper<Nullable<T1>>(other,
319 [&] {
return m_value < other.
get_Value(); }
331 template<
typename T1>
332 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>=(
const T1& other)
const
334 return m_has_value && m_value >= other;
341 template<
typename T1>
344 return NullableBoolHelper<Nullable<T1>>(other,
345 [&] {
return m_value >= other.
get_Value(); }
356 template<
typename T1>
357 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<=(
const T1& other)
const
359 return m_has_value && m_value <= other;
366 template<
typename T1>
369 return NullableBoolHelper<Nullable<T1>>(other,
370 [&] {
return m_value <= other.
get_Value(); }
381 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
392 template<
typename T1>
395 return (
IsNull() || other.IsNull()) ?
nullptr :
403 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
405 static_assert(std::is_null_pointer<T1>::value,
"Operator '-' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
413 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
424 template<
typename T1>
427 return (
IsNull() || other.IsNull()) ?
nullptr :
444 template<
typename T1>
457 template<
typename T1>
460 m_has_value = m_has_value && !other.
IsNull();
468 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
470 static_assert(std::is_null_pointer<T1>::value,
"Operator '-=' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
478 template<typename T1, typename = typename std::enable_if<!std::is_null_pointer<T1>::value, T1>::type>
491 template<
typename T1 = T>
510 template<
typename T1 = T>
530 template<
typename T1>
533 m_has_value = m_has_value && !other.
IsNull();
543 return m_has_value ? System::GetHashCode<T>(m_value) : 0;
550 return m_has_value ? ToStringHelper(m_value) : u
"";
558 return m_has_value ? m_value : default_value;
563 return m_has_value ? m_value : Default<T>();
577 static typename std::enable_if<
578 std::is_arithmetic<C>::value || std::is_enum<C>::value,
String>::type
579 ToStringHelper(
const C& value)
588 static typename std::enable_if<
589 (!std::is_arithmetic<C>::value && !std::is_enum<C>::value && !IsSmartPtr<C>::value && !IsExceptionWrapper<C>::value), String>::type
590 ToStringHelper(
const C& obj)
592 return obj.ToString();
599 static typename std::enable_if<
600 IsSmartPtr<C>::value || IsExceptionWrapper<C>::value, String>::type
601 ToStringHelper(
const C& obj)
603 return obj->ToString();
609 static String ToStringHelper(
bool b)
611 return b ? u
"True" : u
"False";
650 template<
typename T1,
typename T2>
651 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
660 template<
typename T1,
typename T2>
661 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
670 template<
typename T1,
typename T2>
671 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
680 template<
typename T1,
typename T2>
681 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
690 template<
typename T1,
typename T2>
691 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
700 template<
typename T1,
typename T2>
701 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
713 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
716 return other.
IsNull() ? nullptr :
Nullable<
decltype(some + other.get_Value())>(some + other.get_Value());
728 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
731 return other.
IsNull() ? nullptr :
Nullable<
decltype(some - other.get_Value())>(some - other.get_Value());
736 template <
typename T>
737 struct IsBoxable<Nullable<T>> : std::true_type {};
741 template <
typename T>
744 if (value ==
nullptr)
745 *stream <<
"nullptr";
754 template <
typename T>
765 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:531
Nullable< T > operator+=(std::nullptr_t)
Resets the current object so that it represents a null-value.
Definition: nullable.h:434
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:281
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:458
bool operator>(std::nullptr_t) const
Always returns false.
Definition: nullable.h:274
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:266
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:479
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:176
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:249
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:414
auto operator-(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value() - other.get_Value())>
Subtracts nullable values.
Definition: nullable.h:425
bool operator<(std::nullptr_t) const
Always returns false.
Definition: nullable.h:299
bool operator==(std::nullptr_t) const
Determines if the value represented by the current object is null.
Definition: nullable.h:213
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:189
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:342
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:306
int GetHashCode() const
Returns a hash code for the current object.
Definition: nullable.h:541
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:242
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:256
Nullable< T > operator-=(T1)
Returns an instance of Nullable class that represents a null-value.
Definition: nullable.h:469
bool operator>=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:325
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:492
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:230
Nullable< T > operator+(std::nullptr_t) const
Returns a default constructed instance of Nullable<T> class.
Definition: nullable.h:375
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:511
String ToString() const
Converts the value represented by the current object to string.
Definition: nullable.h:548
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:291
bool operator<=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:350
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:357
bool IsNull() const
Determines if the current object represents a null-value.
Definition: nullable.h:180
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:316
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:445
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:561
auto operator+(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value()+other.get_Value())>
Sums nullable values.
Definition: nullable.h:393
void set_Value(const T &value)
Sets a new value to nullable object.
Definition: nullable.h:154
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:367
auto operator+(const T1 &other) const -> Nullable< decltype(get_Value()+other)>
Sums nullable and non-nullable values.
Definition: nullable.h:382
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:220
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:404
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:556
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:332
bool get_HasValue() const
Determines whether the current object represents any value.
Definition: nullable.h:162
Represents C# System.Nullable (with no type arguments) static class. Unable to use original name due ...
Definition: nullable.h:776
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:1419
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