31 #ifndef RDKIT_RDVALUE_TAGGED_UNION_H 32 #define RDKIT_RDVALUE_TAGGED_UNION_H 42 #include <boost/cstdint.hpp> 43 #include <boost/any.hpp> 44 #include <boost/utility.hpp> 45 #include <boost/lexical_cast.hpp> 46 #include <boost/type_traits/is_floating_point.hpp> 50 #define RDVALUE_HASBOOL 120 inline short GetTag<std::string>() {
124 inline short GetTag<std::vector<double> >() {
128 inline short GetTag<std::vector<float> >() {
132 inline short GetTag<std::vector<int> >() {
136 inline short GetTag<std::vector<unsigned int> >() {
140 inline short GetTag<std::vector<std::string> >() {
144 inline short GetTag<boost::any>() {
157 std::vector<double> *
vd;
158 std::vector<float> *
vf;
159 std::vector<int> *
vi;
160 std::vector<unsigned int> *
vu;
161 std::vector<std::string> *
vs;
167 inline Value(
unsigned int v) : u(v) {}
169 inline Value(std::string *v) : s(v) {}
170 inline Value(boost::any *v) : a(v) {}
171 inline Value(std::vector<double> *v) : vd(v) {}
172 inline Value(std::vector<float> *v) : vf(v) {}
173 inline Value(std::vector<int> *v) : vi(v) {}
174 inline Value(std::vector<unsigned int> *v) : vu(v) {}
175 inline Value(std::vector<std::string> *v) : vs(v) {}
180 return boost::any_cast<T *>(*value.
a);
183 inline boost::any *valuePtrCast<boost::any>(
Value value) {
188 inline std::string *valuePtrCast<std::string>(
Value value) {
192 inline std::vector<double> *valuePtrCast<std::vector<double> >(
Value value) {
196 inline std::vector<float> *valuePtrCast<std::vector<float> >(
Value value) {
200 inline std::vector<int> *valuePtrCast<std::vector<int> >(
Value value) {
204 inline std::vector<unsigned int> *valuePtrCast<std::vector<unsigned int> >(
209 inline std::vector<std::string> *valuePtrCast<std::vector<std::string> >(
233 : value(new
boost::any(v)), type(RDTypeTag::
AnyTag) {}
235 : value(new
std::string(v)), type(RDTypeTag::
StringTag){};
238 : value(new
boost::any(v)), type(RDTypeTag::
AnyTag) {}
243 : value(new
std::vector<float>(v)), type(RDTypeTag::
VecFloatTag) {}
245 : value(new
std::vector<int>(v)), type(RDTypeTag::
VecIntTag) {}
246 inline RDValue(
const std::vector<unsigned int> &v)
247 : value(new
std::vector<unsigned int>(v)),
249 inline RDValue(
const std::vector<std::string> &v)
257 return RDTypeTag::detail::valuePtrCast<T>(value);
343 RDTypeTag::GetTag<typename boost::remove_reference<T>::type>();
353 #ifdef RDK_32BIT_BUILD 364 BOOST_STATIC_ASSERT(!(
365 (boost::is_pointer<T>::value &&
366 (boost::is_integral<
typename boost::remove_pointer<T>::type>::value ||
367 boost::is_floating_point<
368 typename boost::remove_pointer<T>::type>::value)) ||
369 (boost::is_reference<T>::value &&
370 (boost::is_integral<
typename boost::remove_reference<T>::type>::value ||
371 boost::is_floating_point<
372 typename boost::remove_reference<T>::type>::value))));
374 if (rdvalue_is<boost::any>(v)) {
375 return boost::any_cast<T>(*v.
ptrCast<boost::any>());
377 throw boost::bad_any_cast();
384 throw boost::bad_any_cast();
389 if (rdvalue_is<float>(v))
return v.
value.
f;
390 throw boost::bad_any_cast();
395 if (rdvalue_is<int>(v))
return v.
value.
i;
396 throw boost::bad_any_cast();
399 inline unsigned int rdvalue_cast<
unsigned int>(RDValue_cast_t v) {
400 if (rdvalue_is<unsigned int>(v))
return v.
value.
u;
401 throw boost::bad_any_cast();
406 if (rdvalue_is<bool>(v))
return v.
value.
b;
407 throw boost::bad_any_cast();
bool rdvalue_is< double >(RDValue v)
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
T rdvalue_cast(RDValue v)
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
bool rdvalue_is(RDValue v)
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)
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
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
RDValue(const std::vector< int > &v)
RDValue(const std::string &v)