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;
168 inline Value(
unsigned int v) : u(v) {}
170 inline Value(std::string *v) : s(v) {}
171 inline Value(boost::any *v) : a(v) {}
172 inline Value(std::vector<double> *v) : vd(v) {}
173 inline Value(std::vector<float> *v) : vf(v) {}
174 inline Value(std::vector<int> *v) : vi(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>>(
220 short reserved_tag = 0;
234 : value(new
boost::any(v)), type(RDTypeTag::
AnyTag) {}
236 : value(new
std::string(v)), type(RDTypeTag::
StringTag){};
239 : value(new
boost::any(v)), type(RDTypeTag::
AnyTag) {}
244 : value(new
std::vector<float>(v)), type(RDTypeTag::
VecFloatTag) {}
246 : value(new
std::vector<int>(v)), type(RDTypeTag::
VecIntTag) {}
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);
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();
408 inline unsigned int rdvalue_cast<
unsigned int>(RDValue_cast_t v) {
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();
RDValue(const std::vector< unsigned int > &v)
boost::uint64_t GetTag< float >()
void copy_rdvalue(RDValue &dest, const RDValue &src)
static const boost::uint64_t VecDoubleTag
boost::uint64_t GetTag< int >()
static const boost::uint64_t UnsignedIntTag
static const boost::uint64_t AnyTag
static const boost::uint64_t DoubleTag
RDValue(const std::vector< float > &v)
Value(std::vector< int > *v)
static const boost::uint64_t FloatTag
std::vector< unsigned int > * vu
static const boost::uint64_t StringTag
RDValue(const std::vector< std::string > &v)
static void cleanup_rdvalue(RDValue &rdvalue)
std::vector< float > * vf
static const boost::uint64_t VecIntTag
static const boost::uint64_t VecUnsignedIntTag
T * valuePtrCast(Value value)
static const boost::uint64_t VecStringTag
Value(std::vector< float > *v)
bool rdvalue_is(const RDValue_cast_t)
static const boost::uint64_t IntTag
Value(std::vector< std::string > *v)
RDValue(const boost::any &v)
boost::uint64_t GetTag< unsigned int >()
Value(std::vector< unsigned int > *v)
Value(std::vector< double > *v)
static const boost::uint64_t BoolTag
boost::uint64_t getTag() const
static const boost::uint64_t VecFloatTag
T rdvalue_cast(RDValue_cast_t v)
RDValue(const std::vector< double > &v)
boost::uint64_t GetTag< double >()
std::vector< std::string > * vs
RDTypeTag::detail::Value value
boost::uint64_t GetTag< bool >()
std::vector< double > * vd
bool rdvalue_is< double >(const RDValue_cast_t)
RDValue(const std::vector< int > &v)
RDValue(const std::string &v)