ROSE
0.11.96.11
|
Holds a value or nothing.
This class is similar to boost::optional except simpler in order to avoid problems we were seeing with Microsoft compilers.
The stored value type (Value) cannot be a reference type.
Definition at line 49 of file Optional.h.
#include <Optional.h>
Public Types | |
typedef T | Value |
Type of stored value. | |
Public Member Functions | |
Optional () | |
Default constructs nothing. More... | |
Optional (const Value &v) | |
Construct from value. More... | |
Optional (const Nothing &) | |
Construct from nothing. More... | |
Optional (const Optional &other) | |
Copy constructor. More... | |
~Optional () | |
Destructor. More... | |
Optional & | operator= (const Value &value) |
Value assignment. More... | |
Optional & | operator= (const Nothing &) |
Nothing assignment. More... | |
Optional & | operator= (const Optional &other) |
Optional assignment. More... | |
void | reset () |
Reset as if default-constructed. | |
Value | orDefault () const |
Obtain a value or a default. More... | |
template<class U > | |
bool | assignTo (U &out) const |
Conditionally save a value. More... | |
operator unspecified_bool () const | |
Type for Boolean context. More... | |
const Value & | operator* () const |
Dereference to obtain value. More... | |
Value & | operator* () |
Dereference to obtain value. More... | |
const Value & | get () const |
Dereference to obtain value. More... | |
Value & | get () |
Dereference to obtain value. More... | |
const Value * | operator-> () const |
Obtain a pointer to the value. More... | |
Value * | operator-> () |
Obtain a pointer to the value. More... | |
const Value & | orElse (const Value &dflt) const |
Obtain value or something else. More... | |
const Value & | orElse (Value &dflt) |
Obtain value or something else. More... | |
const Optional | orElse (const Optional &other) const |
Obtain value or something else. More... | |
bool | isEqual (const Optional &other) const |
Compare two values. More... | |
bool | isEqual (const Value &other) const |
Compare two values. More... | |
bool | isEqual (const Nothing &) const |
Compare two values. More... | |
|
inline |
Default constructs nothing.
Constructs an optional value that points to nothing. The default constructor for Value is not called.
Definition at line 92 of file Optional.h.
|
inline |
Construct from value.
Constructs an optional object that holds a copy of v
.
Definition at line 97 of file Optional.h.
|
inline |
Construct from nothing.
Constructs an optional object that holds nothing. The default constructor for Value is not called.
Definition at line 104 of file Optional.h.
|
inline |
Copy constructor.
Copy constructs an optional so that the new object has the same state (nothing or not) as the source object. If the source contains an object (not nothing) then the object is copy constructed into this optional.
Definition at line 110 of file Optional.h.
|
inline |
Destructor.
The destructor invokes the destructor for the value if a value is stored, otherwise it does nothing.
Definition at line 121 of file Optional.h.
|
inline |
Value assignment.
Assigns the value
to this optional. If this optional previously contained a value then the Value assignment operator is used, otherwise the Value copy constructor is used.
Definition at line 132 of file Optional.h.
|
inline |
Nothing assignment.
Assigns nothing to this optional. If this optional previously contained a value then the value's destructor is called.
Definition at line 147 of file Optional.h.
|
inline |
Optional assignment.
Causes this optional to contain nothing or a copy of the other
value depending on whether other
contains a value or not. If this didn't contain a value but other
did, then the Value copy constructor is used; if both contained a value then the Value assignment operator is used; if this contained a value but other
doesn't, then the Value destructor is called.
Definition at line 162 of file Optional.h.
|
inline |
Dereference to obtain value.
If this optional contains a value then a reference to that value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 191 of file Optional.h.
|
inline |
Dereference to obtain value.
If this optional contains a value then a reference to that value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 194 of file Optional.h.
|
inline |
Dereference to obtain value.
If this optional contains a value then a reference to that value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 197 of file Optional.h.
Referenced by Sawyer::Cached< T >::get(), Sawyer::Optional< Value >::isEqual(), Sawyer::Optional< Value >::operator*(), and Sawyer::Optional< Value >::operator->().
|
inline |
Dereference to obtain value.
If this optional contains a value then a reference to that value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 202 of file Optional.h.
|
inline |
Obtain a pointer to the value.
If this optional contains a value then a pointer to the value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 215 of file Optional.h.
|
inline |
Obtain a pointer to the value.
If this optional contains a value then a pointer to the value is returned. Otherwise an std::domain_error
is thrown (the value is not in the container's domain).
Definition at line 218 of file Optional.h.
|
inline |
Obtain value or something else.
Returns a reference to the contained value if it exists, otherwise returns a reference to the argument.
Definition at line 235 of file Optional.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::attributeOrElse().
|
inline |
Obtain value or something else.
Returns a reference to the contained value if it exists, otherwise returns a reference to the argument.
Definition at line 238 of file Optional.h.
|
inline |
Obtain value or something else.
Returns a reference to the contained value if it exists, otherwise returns a reference to the argument.
Definition at line 241 of file Optional.h.
|
inline |
Obtain a value or a default.
Returns a copy of the contained value if it exists, otherwise returns a default constructed value.
Definition at line 257 of file Optional.h.
Referenced by Sawyer::Attribute::Storage< SyncTag >::getAttribute().
|
inline |
Conditionally save a value.
If this optional object has a value then its value is written to out
and this method returns true; otherwise the value of out
is not changed and this method returns false. This method is convenient to use in conditional statements like this:
where the alternative would be
Definition at line 283 of file Optional.h.
|
inline |
Compare two values.
Compares two optionals and returns true if they are both empty or if neither is empty and their values compare equal. This method should be used instead of ==
. The ==
operator is disabled because it is prone to misuse in the presense of implicit conversion to bool
.
Definition at line 299 of file Optional.h.
|
inline |
Compare two values.
Compares two optionals and returns true if they are both empty or if neither is empty and their values compare equal. This method should be used instead of ==
. The ==
operator is disabled because it is prone to misuse in the presense of implicit conversion to bool
.
Definition at line 302 of file Optional.h.
|
inline |
Compare two values.
Compares two optionals and returns true if they are both empty or if neither is empty and their values compare equal. This method should be used instead of ==
. The ==
operator is disabled because it is prone to misuse in the presense of implicit conversion to bool
.
Definition at line 305 of file Optional.h.
|
inline |
Type for Boolean context.
Implicit conversion to a type that can be used in a boolean context such as an if
or while
statement. For instance:
Definition at line 327 of file Optional.h.