32 #ifndef RDKIT_RDVALUE_TAGGED_UNION_H
33 #define RDKIT_RDVALUE_TAGGED_UNION_H
44 #include <boost/any.hpp>
45 #include <boost/utility.hpp>
46 #include <boost/lexical_cast.hpp>
47 #include <boost/type_traits/is_floating_point.hpp>
51 #define RDVALUE_HASBOOL
121 inline short GetTag<std::string>() {
125 inline short GetTag<std::vector<double>>() {
129 inline short GetTag<std::vector<float>>() {
133 inline short GetTag<std::vector<int>>() {
137 inline short GetTag<std::vector<unsigned int>>() {
141 inline short GetTag<std::vector<std::string>>() {
145 inline short GetTag<boost::any>() {
158 std::vector<double> *
vd;
159 std::vector<float> *
vf;
160 std::vector<int> *
vi;
161 std::vector<unsigned int> *
vu;
162 std::vector<std::string> *
vs;
172 inline Value(std::vector<double> *v) :
vd(v) {}
173 inline Value(std::vector<float> *v) :
vf(v) {}
175 inline Value(std::vector<unsigned int> *v) :
vu(v) {}
176 inline Value(std::vector<std::string> *v) :
vs(v) {}
181 return boost::any_cast<T *>(*value.
a);
184 inline boost::any *valuePtrCast<boost::any>(
Value value) {
189 inline std::string *valuePtrCast<std::string>(
Value value) {
193 inline std::vector<double> *valuePtrCast<std::vector<double>>(
Value value) {
197 inline std::vector<float> *valuePtrCast<std::vector<float>>(
Value value) {
201 inline std::vector<int> *valuePtrCast<std::vector<int>>(
Value value) {
205 inline std::vector<unsigned int> *valuePtrCast<std::vector<unsigned int>>(
210 inline std::vector<std::string> *valuePtrCast<std::vector<std::string>>(
247 inline RDValue(
const std::vector<unsigned int> &v)
248 :
value(new std::vector<unsigned int>(v)),
250 inline RDValue(
const std::vector<std::string> &v)
258 return RDTypeTag::detail::valuePtrCast<T>(
value);
306 inline void copy_rdvalue(RDValue &dest,
const RDValue &src) {
310 dest.type = src.type;
313 dest.value.s =
new std::string(*src.value.s);
316 dest.value.a =
new boost::any(*src.value.a);
319 dest.value.vd =
new std::vector<double>(*src.value.vd);
322 dest.value.vf =
new std::vector<float>(*src.value.vf);
325 dest.value.vi =
new std::vector<int>(*src.value.vi);
328 dest.value.vu =
new std::vector<unsigned int>(*src.value.vu);
331 dest.value.vs =
new std::vector<std::string>(*src.value.vs);
338 #ifdef RDK_32BIT_BUILD
351 RDTypeTag::GetTag<typename boost::remove_reference<T>::type>();
352 if (v.getTag() == tag)
return true;
356 return v.value.a->type() ==
typeid(T);
373 BOOST_STATIC_ASSERT(!(
374 (boost::is_pointer<T>::value &&
375 (boost::is_integral<
typename boost::remove_pointer<T>::type>::value ||
376 boost::is_floating_point<
377 typename boost::remove_pointer<T>::type>::value)) ||
378 (boost::is_reference<T>::value &&
379 (boost::is_integral<
typename boost::remove_reference<T>::type>::value ||
380 boost::is_floating_point<
381 typename boost::remove_reference<T>::type>::value))));
383 if (rdvalue_is<boost::any>(v)) {
384 return boost::any_cast<T>(*v.ptrCast<boost::any>());
386 throw boost::bad_any_cast();
393 throw boost::bad_any_cast();
398 if (rdvalue_is<float>(v))
return v.value.f;
399 throw boost::bad_any_cast();
404 if (rdvalue_is<int>(v))
return v.value.i;
405 throw boost::bad_any_cast();
409 if (rdvalue_is<unsigned int>(v))
return v.value.u;
410 throw boost::bad_any_cast();
415 if (rdvalue_is<bool>(v))
return v.value.b;
416 throw boost::bad_any_cast();