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();
95 Nullable(
const T1& value) : m_has_value(true), m_value(value)
102 template<
typename T1>
108 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>>
115 template<
typename T1>
116 typename std::enable_if<!IsNullable<T1>::value && !std::is_null_pointer<T1>::value,
Nullable<T>&>::type
operator=(
const T1& x)
118 this->m_has_value =
true;
119 this->m_value =
static_cast<T
>(x);
128 template<
typename T1>
131 this->m_has_value = x.m_has_value;
134 this->m_value = x.m_value;
146 Details::ThrowNullableObjectMustHaveAValue();
158 operator const T&()
const
161 Details::ThrowNullableObjectMustHaveAValue();
167 void reset() { m_has_value =
false; }
171 bool IsNull()
const {
return !m_has_value; }
179 template<
typename T1>
180 bool NullableBoolHelper(
const T1& other,
const std::function<
bool()>& f,
bool default_if_both_are_null =
false)
const
186 return default_if_both_are_null;
210 template<
typename T1>
211 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator==(
const T1& other)
const
213 return m_has_value && m_value == other;
220 template<
typename T1>
223 return NullableBoolHelper<Nullable<T1>>(other,
224 [&] {
return m_value == other.
get_Value(); },
232 template<
typename T1>
233 typename std::enable_if<IsNullable<T1>::value,
bool>::type
Equals(
const T1& other)
const
235 return ((!m_has_value) && (!other.m_has_value)) || (m_has_value && other.m_has_value && (m_value == other.get_Value()));
246 template<
typename T1>
247 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator!=(
const T1& other)
const
249 return IsNull() ? true : m_value != other;
256 template<
typename T1>
259 return NullableBoolHelper<Nullable<T1>>(other,
260 [&] {
return m_value != other.
get_Value(); }
271 template<
typename T1>
272 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>(
const T1& other)
const
274 return m_has_value && m_value > other;
281 template<
typename T1>
284 return NullableBoolHelper<Nullable<T1>>(other,
285 [&] {
return m_value > other.
get_Value(); }
296 template<
typename T1>
297 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<(
const T1& other)
const
299 return m_has_value && m_value < other;
306 template<
typename T1>
309 return NullableBoolHelper<Nullable<T1>>(other,
310 [&] {
return m_value < other.
get_Value(); }
322 template<
typename T1>
323 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator>=(
const T1& other)
const
325 return m_has_value && m_value >= other;
332 template<
typename T1>
335 return NullableBoolHelper<Nullable<T1>>(other,
336 [&] {
return m_value >= other.
get_Value(); }
347 template<
typename T1>
348 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
operator<=(
const T1& other)
const
350 return m_has_value && m_value <= other;
357 template<
typename T1>
360 return NullableBoolHelper<Nullable<T1>>(other,
361 [&] {
return m_value <= other.
get_Value(); }
372 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
383 template<
typename T1>
386 return (
IsNull() || other.IsNull()) ?
nullptr :
394 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
396 static_assert(std::is_null_pointer<T1>::value,
"Operator '-' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
404 template<typename T1, typename = typename std::enable_if<!IsNullable<T1>::value,
int>::type>
415 template<
typename T1>
418 return (
IsNull() || other.IsNull()) ?
nullptr :
435 template<
typename T1>
448 template<
typename T1>
451 m_has_value = m_has_value && !other.
IsNull();
459 template<typename T1, typename = typename std::enable_if<std::is_null_pointer<T1>::value>::type>
461 static_assert(std::is_null_pointer<T1>::value,
"Operator '-=' is ambiguous on operands of type 'Nullable<T>' and '<null>'");
469 template<typename T1, typename = typename std::enable_if<!std::is_null_pointer<T1>::value, T1>::type>
482 template<
typename T1 = T>
501 template<
typename T1 = T>
521 template<
typename T1>
524 m_has_value = m_has_value && !other.
IsNull();
534 return m_has_value ? System::GetHashCode<T>(m_value) : 0;
541 return m_has_value ? ToStringHelper(m_value) : u
"";
549 return m_has_value ? m_value : default_value;
554 return m_has_value ? m_value : Default<T>();
568 static typename std::enable_if<
569 std::is_arithmetic<C>::value || std::is_enum<C>::value,
String>::type
570 ToStringHelper(
const C& value)
579 static typename std::enable_if<
580 (!std::is_arithmetic<C>::value && !std::is_enum<C>::value && !IsSmartPtr<C>::value && !IsExceptionWrapper<C>::value), String>::type
581 ToStringHelper(
const C& obj)
583 return obj.ToString();
590 static typename std::enable_if<
591 IsSmartPtr<C>::value || IsExceptionWrapper<C>::value, String>::type
592 ToStringHelper(
const C& obj)
594 return obj->ToString();
600 static String ToStringHelper(
bool b)
602 return b ? u
"True" : u
"False";
641 template<
typename T1,
typename T2>
642 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
651 template<
typename T1,
typename T2>
652 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
661 template<
typename T1,
typename T2>
662 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
671 template<
typename T1,
typename T2>
672 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
681 template<
typename T1,
typename T2>
682 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
691 template<
typename T1,
typename T2>
692 typename std::enable_if<!IsNullable<T1>::value,
bool>::type
704 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
707 return other.
IsNull() ? nullptr :
Nullable<
decltype(some + other.get_Value())>(some + other.get_Value());
719 typename =
typename std::enable_if<!IsNullable<T1>::value && !IsNullable<T2>::value && !std::is_same<T1, System::String>::value,
int>::type
722 return other.
IsNull() ? nullptr :
Nullable<
decltype(some - other.get_Value())>(some - other.get_Value());
727 template <
typename T>
728 struct IsBoxable<Nullable<T>> : std::true_type {};
732 template <
typename T>
735 if (value ==
nullptr)
736 *stream <<
"nullptr";
745 template <
typename T>
756 template <
typename T>
Forward declaration.
Definition: nullable.h:74
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:522
Nullable< T > operator+=(std::nullptr_t)
Resets the current object so that it represents a null-value.
Definition: nullable.h:425
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:272
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:449
bool operator>(std::nullptr_t) const
Always returns false.
Definition: nullable.h:265
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:257
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:470
Nullable< T > & operator=(const Nullable< T1 > &x)
Replaces the object's currently represented value with the specified one.
Definition: nullable.h:129
void reset()
Sets the currently represented value to null.
Definition: nullable.h:167
Nullable< T > operator=(std::nullptr_t)
Assigns a null to the current object.
Definition: nullable.h:109
bool operator!=(std::nullptr_t) const
Determines if the value represented by the current object is not null.
Definition: nullable.h:240
Nullable(std::nullptr_t)
Constructs an instance that represents null.
Definition: nullable.h:87
auto operator-(const T1 &other) const -> Nullable< decltype(get_Value() - other)>
Subtracts nullable and non-nullable values.
Definition: nullable.h:405
auto operator-(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value() - other.get_Value())>
Subtracts nullable values.
Definition: nullable.h:416
bool operator<(std::nullptr_t) const
Always returns false.
Definition: nullable.h:290
bool operator==(std::nullptr_t) const
Determines if the value represented by the current object is null.
Definition: nullable.h:204
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:180
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:333
T ValueType
An alias for a type of the value represented by this class.
Definition: nullable.h:80
T get_Value() const
Returns a copy of the value represented by the current object.
Definition: nullable.h:143
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:297
int GetHashCode() const
Returns a hash code for the current object.
Definition: nullable.h:532
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:233
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:247
Nullable< T > operator-=(T1)
Returns an instance of Nullable class that represents a null-value.
Definition: nullable.h:460
bool operator>=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:316
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:483
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:221
Nullable< T > operator+(std::nullptr_t) const
Returns a default constructed instance of Nullable<T> class.
Definition: nullable.h:366
Nullable()
Constructs an instance that represents null-value.
Definition: nullable.h:83
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:502
String ToString() const
Converts the value represented by the current object to string.
Definition: nullable.h:539
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:282
bool operator<=(std::nullptr_t) const
Always returns false.
Definition: nullable.h:341
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:348
bool IsNull() const
Determines if the current object represents a null-value.
Definition: nullable.h:171
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:307
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:436
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:116
T GetValueOrDefault()
Definition: nullable.h:552
auto operator+(const Nullable< T1 > &other) const -> System::Nullable< decltype(get_Value()+other.get_Value())>
Sums nullable values.
Definition: nullable.h:384
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:358
auto operator+(const T1 &other) const -> Nullable< decltype(get_Value()+other)>
Sums nullable and non-nullable values.
Definition: nullable.h:373
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:211
Nullable(const Nullable< T1 > &value)
Constructs an instance that represents a value that is represented by the specified Nullable object....
Definition: nullable.h:103
Nullable< T > operator-(T1) const
Subtracts nullable and null-pointed values.
Definition: nullable.h:395
Nullable(const T1 &value)
Constructs an instance of Nullable class that represents the specified value converted (if necessary)...
Definition: nullable.h:95
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:547
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:323
bool get_HasValue() const
Determines whether the current object represents any value.
Definition: nullable.h:153
Represents C# System.Nullable (with no type arguments) static class. Unable to use original name due ...
Definition: nullable.h:767
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:1405
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:157
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:151
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