|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_UTIL_OPTION_H
22 #define ELM_UTIL_OPTION_H
24 #include <elm/assert.h>
25 #include <elm/type_info.h>
40 inline Option(
const Option<T> &opt): one(opt.one) { t::put<T>(val, t::get<T>(opt.val)); }
42 inline bool some()
const {
return one; }
43 inline bool none()
const {
return !one; }
46 { ASSERTP(one,
"no value in option");
return t::get<T>(val); }
50 {
if(one) f(t::get<T>(val));
return *
this; }
52 {
if(!one) f();
return *
this; }
55 { one = opt.one;
if(opt.one) t::put<T>(val, opt.val);
return *
this; }
61 {
return (this->
none() && opt.
none()) || (this->
some() && opt.
some() && val == opt.val); }
68 inline operator bool(
void)
const {
return some(); }
70 inline bool isOne()
const {
return one; }
71 inline bool isNone()
const {
return !one; }
t::ret< T > value() const
Definition: Option.h:45
Option(const Option< T > &opt)
Definition: Option.h:40
bool operator==(const Option< T > &o) const
Definition: Option.h:64
bool isOne() const
Definition: Option.h:70
bool operator!=(const Option< T > &o) const
Definition: Option.h:65
const Option< T > & if_one(const F &f) const
Definition: Option.h:49
typename type_info< T >::var_t var
Definition: type_info.h:282
bool operator==(const OptionalNone &_) const
Definition: Option.h:62
Option< T > some(const T &val)
Definition: Option.h:81
t::ret< T > operator*() const
Definition: Option.h:47
bool equals(const Option< T > &opt) const
Definition: Option.h:60
typename type_info< T >::in_t in
Definition: type_info.h:283
bool isNone() const
Definition: Option.h:71
bool none() const
Definition: Option.h:43
AutoStringStartup & _
Definition: debug_CrashHandler.cpp:232
Option< T > & operator=(t::in< T > value)
Definition: Option.h:56
const OptionalNone none
Definition: util_Option.cpp:154
bool equals(const OptionalNone &_) const
Definition: Option.h:59
Option< T > & operator=(const Option< T > &opt)
Definition: Option.h:54
bool some() const
Definition: Option.h:42
static void put(T &x, const T &v)
Definition: type_info.h:69
Option(const OptionalNone &none)
Definition: Option.h:38
const Option< T > & if_else(const F &f) const
Definition: Option.h:51
typename type_info< T >::ret_t ret
Definition: type_info.h:285
Option(t::in< T > value)
Definition: Option.h:39
bool operator!=(const OptionalNone &_) const
Definition: Option.h:63
Option()
Definition: Option.h:37