Poco

template < typename C >

class Nullable

Library: Foundation
Package: Core
Header: Poco/Nullable.h

Description

Nullable is a simple wrapper class for value types that allows to introduce a "null" value or state to value objects.

The class is useful for passing parameters to functions when parameters are optional and no default values should be used.

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 =, swap, value

Constructors

Nullable inline

Nullable();

Creates an empty Nullable.

Nullable inline

Nullable(
    const C & value
);

Creates a Nullable with the given value.

Nullable inline

Nullable(
    const Nullable & other
);

Creates a Nullable by copying another one.

Destructor

~Nullable inline

~Nullable();

Destroys the Nullable.

Member Functions

assign inline

Nullable & assign(
    const C & value
);

Assigns a value to the Nullable.

assign inline

Nullable & assign(
    const Nullable & other
);

Assigns another Nullable.

clear inline

void clear();

Clears the Nullable.

isNull inline

bool isNull() const;

Returns true if and only if the Nullable is empty.

operator = inline

Nullable & operator = (
    const C & value
);

operator = inline

Nullable & operator = (
    const Nullable & other
);

swap inline

void swap(
    Nullable & other
);

value inline

const C & value() const;

Returns the Nullable's value.

Throws a NullValueException if the Nullable is empty.

value inline

const C & value(
    const C & deflt
) const;

Returns the Nullable's value, or the given default value if the Nullable is empty.