cpp-ElementTree
Python ElementTree-alike XML API for C++
Public Member Functions | List of all members
etree::Nullable< T > Class Template Reference

Lightweight wrapper to add nullable semantics to another type. More...

#include <element.hpp>

Public Member Functions

 Nullable ()
 Construct an unset Nullable.
 
 Nullable (const T &val)
 Construct a set Nullable containing a value. More...
 
 Nullable (const Nullable< T > &val)
 Copy the value from another Nullable. More...
 
 Nullable (T &&val)
 C++11: construct a set Nullable by moving a value. More...
 
 ~Nullable ()
 Destroy the contained value if this Nullable is set.
 
ETREE_EXPLICIT operator bool () const
 Evaluate to true if this Nullable is set.
 
T & operator* ()
 Return the contained value, or throw missing_value_error().
 
const T & operator* () const
 Return the contained value, or throw missing_value_error().
 
const T * operator-> () const
 Return the contained value, or throw missing_value_error().
 
Nullable< T > & operator= (const Nullable< T > &other)
 Copy the instance and its contained value, if any.
 
bool operator== (const Nullable< T > &other) const
 Return true if both nullables are empty, or both nullables contain the same value.
 
bool operator== (const T &other) const
 Return true if both nullables are empty, or both nullables contain the same value.
 

Detailed Description

template<typename T>
class etree::Nullable< T >

Lightweight wrapper to add nullable semantics to another type.

This template is presently only implemented for the Element type, attempting to instantiate it with other types will fail.

Nullable objects can be implicitly converted to boolean to test whether their contents exists, and dereferenced to access the stored value, if any:

Nullable<Element> maybe = parent.child("foo");
if(maybe) {
// Nullable contains a value. "*maybe" will dereference its value.
} else {
// Nullable is empty. "*maybe" will throw an exception.
}

Constructor & Destructor Documentation

template<typename T>
etree::Nullable< T >::Nullable ( const T &  val)

Construct a set Nullable containing a value.

Parameters
valValue to copy.
template<typename T>
etree::Nullable< T >::Nullable ( const Nullable< T > &  val)

Copy the value from another Nullable.

Parameters
valValue to copy.
template<typename T>
etree::Nullable< T >::Nullable ( T &&  val)

C++11: construct a set Nullable by moving a value.

Parameters
valValue to copy.

The documentation for this class was generated from the following files: