32 #ifndef RDKIT_RDVALUE_TAGGED_UNION_H 33 #define RDKIT_RDVALUE_TAGGED_UNION_H 43 #include <boost/cstdint.hpp> 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> >(
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);
344 RDTypeTag::GetTag<typename boost::remove_reference<T>::type>();
354 #ifdef RDK_32BIT_BUILD 365 BOOST_STATIC_ASSERT(!(
366 (boost::is_pointer<T>::value &&
367 (boost::is_integral<
typename boost::remove_pointer<T>::type>::value ||
368 boost::is_floating_point<
369 typename boost::remove_pointer<T>::type>::value)) ||
370 (boost::is_reference<T>::value &&
371 (boost::is_integral<
typename boost::remove_reference<T>::type>::value ||
372 boost::is_floating_point<
373 typename boost::remove_reference<T>::type>::value))));
375 if (rdvalue_is<boost::any>(v)) {
376 return boost::any_cast<T>(*v.
ptrCast<boost::any>());
378 throw boost::bad_any_cast();
385 throw boost::bad_any_cast();
390 if (rdvalue_is<float>(v))
return v.
value.
f;
391 throw boost::bad_any_cast();
396 if (rdvalue_is<int>(v))
return v.
value.
i;
397 throw boost::bad_any_cast();
400 inline unsigned int rdvalue_cast<
unsigned int>(RDValue_cast_t v) {
401 if (rdvalue_is<unsigned int>(v))
return v.
value.
u;
402 throw boost::bad_any_cast();
407 if (rdvalue_is<bool>(v))
return v.
value.
b;
408 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)