11 #ifndef RTIREFLEX_DISC_UNION_H
12 #define RTIREFLEX_DISC_UNION_H
14 #include <boost/variant.hpp>
15 #include <boost/optional.hpp>
16 #include <boost/utility/typed_in_place_factory.hpp>
41 return val_ == rhs.val_;
48 template <
class T,
int... Tags>
56 template <
int Head,
int... Tail>
57 struct Match<Head, Tail...>
59 static bool exec(
int discriminator) {
60 return (Head == discriminator) ?
61 true : Match<Tail...>::exec(discriminator);
68 static bool exec(
int discriminator) {
69 return (Last == discriminator);
76 static bool exec(
int discriminator) {
77 return (-1 == discriminator);
82 struct case_discriminator;
84 template <
class T,
int Head,
int... Tail>
85 struct case_discriminator<Case<T, Head, Tail...>>
88 enum { value = Head };
92 struct case_discriminator<Case<T>>
99 template <
class T,
int... Tags>
112 return detail::Match<Tags...>::exec(discriminator);
130 const T &
get()
const {
return val_; }
131 T &
get() {
return val_; }
134 return lhs.val_ == rhs.val_;
138 template <
class TagType,
class... Cases>
155 caseptr_tuple_(other.caseptr_tuple_),
156 active_index_(other.active_index_)
161 Union(rhs).swap(*
this);
175 template <
typename CaseType,
int... Tags>
180 template <
typename CaseType,
int... Tags>
183 Union(rhs).swap(*
this);
187 template <
class Tag,
class... C>
192 template <
typename Tag,
class... C>
195 Union(rhs).swap(*
this);
225 caseptr_tuple_ = caseptrs;
231 caseptr_tuple_ = caseptrs;
236 return caseptr_tuple_;
241 return caseptr_tuple_;
246 var_.swap(other.var_);
247 caseptr_tuple_.swap(other.caseptr_tuple_);
248 std::swap(active_index_, other.active_index_);
253 return active_index_;
258 return (active_index_ == -1) &&
262 const std::type_info &
type()
const
269 return var_ == rhs.var_;
280 return var_ < rhs.var_;
295 template <
class... T>
298 return make_tuple((&args)...);
304 #endif // RTIREFLEX_DISC_UNION_H
void set_active_index(int i)
Definition: disc_union.h:209
Definition: disc_union.h:139
Definition: disc_union.h:27
std::tuple< boost::optional< T >...> tuple_type
Definition: disc_union.h:29
tuple_type & get_opt_tuple()
Definition: disc_union.h:36
Union & operator=(const variant_type &lhs)
Definition: disc_union.h:169
const caseptr_tuple_type & get_caseptr_tuple() const
Definition: disc_union.h:234
Union()
Definition: disc_union.h:147
const variant_type & get_variant() const
Definition: disc_union.h:204
friend bool operator==(const Case &lhs, const Case &rhs)
Definition: disc_union.h:133
const tuple_type & get_opt_tuple() const
Definition: disc_union.h:32
void set_caseptr_tuple_for_reading(const caseptr_tuple_type &caseptrs)
Definition: disc_union.h:229
bool operator==(const Union &rhs) const
Definition: disc_union.h:267
void swap(AutoDynamicData &lhs, AutoDynamicData &rhs)
Swap the contents of two AutoDynamicData instances. Never throws.
Definition: auto_dd.cxx:106
int get_active_index() const
Definition: disc_union.h:251
std::tuple< T...> raw_tuple_type
Definition: disc_union.h:30
Union(const variant_type &v)
Definition: disc_union.h:165
Union(const Case< CaseType, Tags...> &c)
Definition: disc_union.h:176
static bool matches(int discriminator)
Definition: disc_union.h:110
Case(const T &t)
Definition: disc_union.h:117
std::tuple< Cases...> case_tuple_type
Definition: disc_union.h:143
void swap(Union &other)
Definition: disc_union.h:244
void set_caseptr_tuple_for_writing(const caseptr_tuple_type &caseptrs, int ai)
Definition: disc_union.h:223
Case()
Definition: disc_union.h:115
bool operator==(const U &rhs) const
Definition: disc_union.h:273
variant_type & get_variant()
Definition: disc_union.h:199
std::tuple< T *...> make_caseptr_tuple(T &...args)
Definition: disc_union.h:296
Union & operator=(const Case< CaseType, Tags...> &rhs)
Definition: disc_union.h:181
Definition: disc_union.h:108
T type
Definition: disc_union.h:107
void * Blank
Definition: disc_union.h:141
Case & operator=(const Case &rhs)
Definition: disc_union.h:125
boost::variant< Blank, Cases...> variant_type
Definition: disc_union.h:144
bool empty() const
Definition: disc_union.h:256
std::tuple< typename Cases::case_ptr_type...> caseptr_tuple_type
Definition: disc_union.h:145
const std::type_info & type() const
Definition: disc_union.h:262
bool operator<(const Union &rhs) const
Definition: disc_union.h:278
Case(const Case &c)
Definition: disc_union.h:121
bool operator==(const Sparse &rhs) const
Definition: disc_union.h:40
Union(const Union &other)
Definition: disc_union.h:153
Union & operator=(const Union &rhs)
Definition: disc_union.h:159
Union(const Union< Tag, C...> &u)
Definition: disc_union.h:188
bool operator<(const U &rhs) const
Definition: disc_union.h:284
void reset_caseptr_tuple()
Definition: disc_union.h:218
TagType tag_type
Definition: disc_union.h:142
Union & operator=(const Union< Tag, C...> &rhs)
Definition: disc_union.h:193
Definition: disc_union.h:49
T * case_ptr_type
Definition: disc_union.h:105
caseptr_tuple_type & get_caseptr_tuple()
Definition: disc_union.h:239