42 #if !defined(BOOST_SPIRIT_HOLD_ANY_MAY_02_2007_0857AM) 43 #define BOOST_SPIRIT_HOLD_ANY_MAY_02_2007_0857AM 49 #include <boost/config.hpp> 50 #include <boost/type_traits/remove_reference.hpp> 51 #include <boost/type_traits/is_reference.hpp> 52 #include <boost/throw_exception.hpp> 53 #include <boost/static_assert.hpp> 54 #include <boost/mpl/bool.hpp> 55 #include <boost/assert.hpp> 56 #include <boost/detail/sp_typeinfo.hpp> 65 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 66 # pragma warning(push) 67 # pragma warning(disable: 4100) // 'x': unreferenced formal parameter 68 # pragma warning(disable: 4127) // conditional expression is constant 72 namespace boost {
namespace spirit
77 bad_any_cast(boost::detail::sp_typeinfo
const& src, boost::detail::sp_typeinfo
const& dest)
81 virtual const char*
what()
const throw() {
return "bad any cast"; }
90 template <
typename Char>
93 boost::detail::sp_typeinfo
const& (*get_type)();
94 void (*static_delete)(
void**);
95 void (*destruct)(
void**);
96 void (*clone)(
void*
const*,
void**);
97 void (*move)(
void*
const*,
void**);
101 template <
typename Small>
107 template<
typename T,
typename Char>
110 static boost::detail::sp_typeinfo
const&
get_type()
112 return BOOST_SP_TYPEID(T);
116 reinterpret_cast<T*
>(x)->~T();
120 reinterpret_cast<T*
>(x)->~T();
122 static void clone(
void*
const* src,
void** dest)
124 new (dest) T(*reinterpret_cast<T const*>(src));
126 static void move(
void*
const* src,
void** dest)
128 *
reinterpret_cast<T*
>(dest) =
129 *reinterpret_cast<T const*>(src);
138 template<
typename T,
typename Char>
141 static boost::detail::sp_typeinfo
const&
get_type()
143 return BOOST_SP_TYPEID(T);
148 delete (*
reinterpret_cast<T**
>(x));
153 (*
reinterpret_cast<T**
>(x))->~T();
155 static void clone(
void*
const* src,
void** dest)
157 *dest =
new T(**reinterpret_cast<T* const*>(src));
159 static void move(
void*
const* src,
void** dest)
161 **
reinterpret_cast<T**
>(dest) =
162 **reinterpret_cast<T* const*>(src);
167 template <
typename T>
170 typedef mpl::bool_<(sizeof(T) <= sizeof(void*))>
is_small;
172 template <
typename Char>
183 return &static_table;
192 template <
typename Char>
197 template <
typename T>
199 : table(spirit::detail::get_table<T>::template get<Char>()), object(0)
208 : table(spirit::detail::get_table< ::
std::
string>::template get<Char>()), object(0)
214 : table(spirit::detail::get_table<spirit::detail::empty>::template get<Char>()),
220 : table(spirit::detail::get_table<spirit::detail::empty>::template get<Char>()),
228 table->static_delete(&
object);
236 if (table == x.table) {
238 table->move(&x.object, &
object);
242 x.table->clone(&x.object, &
object);
249 template <
typename T>
255 if (table == x_table) {
257 table->destruct(&
object);
270 table->destruct(&
object);
283 template <
typename T>
298 std::swap(table, x.table);
299 std::swap(
object, x.object);
303 boost::detail::sp_typeinfo
const&
type()
const 305 return table->get_type();
308 template <
typename T>
311 if (type() != BOOST_SP_TYPEID(T))
315 *
reinterpret_cast<T const*
>(&object) :
316 *reinterpret_cast<T const*>(
object);
325 #ifdef BOOST_SPIRIT_ANY_IMPLICIT_CASTING 327 template <
typename T>
328 operator T
const& ()
const {
return cast<T>(); }
329 #endif // implicit casting 340 table->static_delete(&
object);
346 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS 348 template <
typename T,
typename Char_>
359 template <
typename T,
typename Char>
362 if (operand && operand->
type() == BOOST_SP_TYPEID(T)) {
364 reinterpret_cast<T*
>(&operand->object) :
365 reinterpret_cast<T*>(operand->object);
370 template <
typename T,
typename Char>
376 template <
typename T,
typename Char>
379 typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
381 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 388 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
391 nonref* result =
any_cast<nonref>(&operand);
397 template <
typename T,
typename Char>
400 typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
402 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 405 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
418 template <
typename T>
421 template <
typename Char>
428 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 429 # pragma warning(pop) basic_hold_any(T const &x)
basic_hold_any< wchar_t > whold_any
const void * castsmallvoid() const
boost::detail::sp_typeinfo const & type() const
static void move(void *const *src, void **dest)
basic_hold_any & operator=(basic_hold_any const &x)
static void clone(void *const *src, void **dest)
std::string name(int nuc)
basic_hold_any & operator=(T const &x)
basic_hold_any(basic_hold_any const &x)
static void destruct(void **x)
basic_hold_any & assign(basic_hold_any const &x)
basic_hold_any & assign(T const &x)
static void move(void *const *src, void **dest)
static void clone(void *const *src, void **dest)
basic_hold_any(const char *x)
basic_hold_any< char > hold_any
bad_any_cast(boost::detail::sp_typeinfo const &src, boost::detail::sp_typeinfo const &dest)
T * any_cast(basic_hold_any< Char > *operand)
static boost::detail::sp_typeinfo const & get_type()
static boost::detail::sp_typeinfo const & get_type()
static void destruct(void **x)
virtual const char * what() const
static void static_delete(void **x)
static void static_delete(void **x)
mpl::bool_<(sizeof(T)<=sizeof(void *))> is_small
basic_hold_any & swap(basic_hold_any &x)