|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
22 #ifndef ELM_UTIL_DELEGATE_H
23 #define ELM_UTIL_DELEGATE_H
25 #include <elm/assert.h>
26 #include <elm/util/Option.h>
27 #include <elm/util/Exception.h>
32 template <
class C,
class I,
class T>
36 : cont(&container), id(identifier) { }
38 : cont(delegate.cont), id(delegate.id) { }
40 inline operator T(
void)
const {
return ((
const C *)cont)->get(
id); }
41 inline const T&
operator*(
void)
const {
return ((
const C *)cont)->get(
id); }
43 { cont->set(
id,
value);
return *
this; }
45 { cont = delegate.cont;
id = delegate.id;
return *
this; }
63 template <
class C,
class I,
class T,
class D = Default<T> >
67 : cont(&container), id(identifier) { }
69 : cont(delegate.cont), id(delegate.id) { }
71 inline operator T(
void)
const
72 {
return ((
const C *)cont)->get(
id, D::def); }
74 {
return ((
const C *)cont)->get(
id, D::def); }
76 { cont->put(
id,
value);
return *
this; }
78 { cont = delegate.cont;
id = delegate.id;
return *
this; }
98 typedef typename C::key_t
key_t;
99 typedef typename C::val_t
val_t;
102 : _map(
map), _key(key) { }
109 inline void put(
const val_t& val) { _map.put(_key, val); }
111 inline operator val_t(
void)
const {
return get(); }
const T & operator*(void) const
Definition: delegate.h:73
const T & operator*(void) const
Definition: delegate.h:41
MapDelegate< C, I, T > & operator=(const MapDelegate< C, I, T > &delegate)
Definition: delegate.h:77
StrictMapDelegate(C &map, const key_t &key)
Definition: delegate.h:101
ArrayDelegate(C &container, const I &identifier)
Definition: delegate.h:35
self_t & operator=(const val_t &val)
Definition: delegate.h:113
Definition: Exception.h:29
val_t get(void) const
Definition: delegate.h:104
void map(const C &c, const F &f, D &d)
Definition: util.h:89
MapDelegate(C &container, const I &identifier)
Definition: delegate.h:66
val_t operator*(void) const
Definition: delegate.h:112
bool isNone() const
Definition: Option.h:71
ArrayDelegate< C, I, T > & operator=(const T &value)
Definition: delegate.h:42
StrictMapDelegate< C > self_t
Definition: delegate.h:97
Definition: delegate.h:33
MapDelegate< C, I, T > & operator=(const T &value)
Definition: delegate.h:75
Definition: delegate.h:87
C::val_t val_t
Definition: delegate.h:99
Definition: delegate.h:95
static T def
Definition: delegate.h:57
ArrayDelegate(const ArrayDelegate &delegate)
Definition: delegate.h:37
string message(void) override
Definition: utility.cpp:91
void put(const val_t &val)
Definition: delegate.h:109
MapDelegate(const MapDelegate &delegate)
Definition: delegate.h:68
Definition: delegate.h:64
C::key_t key_t
Definition: delegate.h:98
ArrayDelegate< C, I, T > & operator=(const ArrayDelegate< C, I, T > &delegate)
Definition: delegate.h:44
Definition: delegate.h:55