7 #ifndef NUKLEI_NULLABLE_H
8 #define NUKLEI_NULLABLE_H
27 typedef std::pair<bool, T> container_t;
29 nullable() : container_(
false, T()) {}
31 nullable(
const T& element) : container_(
true, element) {}
34 void assertConsistency()
const
37 if (isDefined()) get().assertConsistency();
41 nullable& operator=(
const T& element)
42 { set(element);
return *
this; }
49 T& operator* () {
return get(); }
50 const T& operator* ()
const {
return get(); }
52 T* operator-> () {
return &get(); }
53 const T* operator-> ()
const {
return &get(); }
55 bool isDefined()
const {
return container_.first; }
63 {
NUKLEI_ASSERT(container_.first);
return container_.second; }
65 {
NUKLEI_ASSERT(container_.first);
return container_.second; }
67 void set(
const T& element) { container_ = container_t(
true, element); }
69 void clear() { container_ = container_t(
false, T()); }
72 container_t container_;
74 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
75 template<
class Archive>
76 void serialize(Archive &ar,
const unsigned int version)
78 ar & NUKLEI_SERIALIZATION_NVP(container_);