Library: Foundation
Package: Core
Header: Poco/Nullable.h
Description
Nullable is a simple wrapper class for value types that allows objects or native type variables to have "null" value.
The class is useful for passing parameters to functions when parameters are optional and no default values should be used or when a non-assigned state is needed, such as in e.g. fetching null values from database.
A Nullable can be default constructed. In this case, the Nullable will have a Null value and isNull() will return true. Calling value() (without default value) on a Null object will throw a NullValueException.
A Nullable can also be constructed from a value. It is possible to assign a value to a Nullable, and to reset a Nullable to contain a Null value by calling clear().
For use with Nullable, the value type should support default construction.
Member Summary
Member Functions: assign, clear, isNull, operator !=, operator <, operator =, operator ==, operator >, operator C &, operator const C &, operator const NullType &, swap, value
Types Aliases
Type
using Type = C;
Constructors
Nullable
Nullable();
Creates an empty Nullable.
Nullable
Nullable(
const NullType & param301
);
Creates an empty Nullable.
Nullable
Nullable(
const C & value
);
Creates a Nullable with the given value.
Nullable
Nullable(
C && value
);
Creates a Nullable by moving the given value.
Nullable
Nullable(
const Nullable & other
);
Creates a Nullable by copying another one.
Nullable
Nullable(
Nullable && other
) noexcept;
Creates a Nullable by moving another one.
Destructor
~Nullable
~Nullable() = default;
Destroys the Nullable.
Member Functions
assign
Nullable & assign(
const C & value
);
Assigns a value to the Nullable.
assign
Nullable & assign(
C && value
);
Assigns a value to the Nullable.
assign
Nullable & assign(
const Nullable & other
);
Assigns another Nullable.
assign
Sets value to null.
clear
void clear();
Clears the Nullable.
isNull
bool isNull() const;
Returns true if the Nullable is empty.
operator !=
bool operator != (
const C & value
) const;
Compares Nullable with value for non equality
operator !=
bool operator != (
const Nullable < C > & other
) const;
Compares two Nullables for non equality
operator !=
bool operator != (
const NullType & param303
) const;
Compares with NullData for non equality
operator <
bool operator < (
const Nullable < C > & other
) const;
Compares two Nullable objects. Return true if this object's value is smaler than the other object's value. Null value is smaller than a non-null value.
operator =
Nullable & operator = (
const C & value
);
Assigns a value to the Nullable.
operator =
Nullable & operator = (
C && value
);
Move-assigns a value to the Nullable.
operator =
Nullable & operator = (
const Nullable & other
);
Assigns another Nullable.
operator =
Nullable & operator = (
Nullable && other
) noexcept;
Moves another Nullable.
operator =
Nullable & operator = (
NullType
);
Assigns NullType.
operator ==
bool operator == (
const Nullable < C > & other
) const;
Compares two Nullables for equality
operator ==
bool operator == (
const C & value
) const;
Compares Nullable with value for equality
operator ==
bool operator == (
const NullType & param302
) const;
Compares Nullable with NullData for equality
operator >
bool operator > (
const Nullable < C > & other
) const;
Compares two Nullable objects. Return true if this object's value is greater than the other object's value. A non-null value is greater than a null value.
operator C &
explicit operator C & ();
Get reference to the value
operator const C &
explicit operator const C & () const;
Get const reference to the value
operator const NullType &
operator const NullType & () const;
Get reference to the value
swap
void swap(
Nullable & other
) noexcept;
Swaps this Nullable with other.
value
C & value();
Returns the Nullable's value.
Throws a NullValueException if the Nullable is empty.
value
const C & value() const;
Returns the Nullable's value.
Throws a NullValueException if the Nullable is empty.
value
const C & value(
const C & deflt
) const;