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/core/typeinfo.hpp>
65#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
67# pragma warning(disable: 4100)
68# pragma warning(disable: 4127)
72namespace boost {
namespace spirit
77 bad_any_cast(boost::core::typeinfo
const& src, boost::core::typeinfo
const& dest)
78 :
from(src.name()),
to(dest.name())
81 virtual const char*
what()
const throw() {
return "bad any cast"; }
90 template <
typename Char>
93 boost::core::typeinfo
const& (*get_type)();
96 void (*
clone)(
void*
const*,
void**);
97 void (*
move)(
void*
const*,
void**);
101 template <
typename Small>
107 template<
typename T,
typename Char>
112 return BOOST_CORE_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>
143 return BOOST_CORE_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)
205 : table(spirit::detail::get_table< ::
std::string>::template get<Char>()), object(0)
207 new (&object) ::std::string(x);
211 : table(spirit::detail::get_table<spirit::detail::
empty>::template get<Char>()),
217 : table(spirit::detail::get_table<spirit::detail::
empty>::template get<Char>()),
225 table->static_delete(&
object);
228 template <
typename T>
229 static void new_object(
void*&
object, T
const& x, mpl::true_)
234 template <
typename T>
235 static void new_object(
void*&
object, T
const& x, mpl::false_)
244 if (table == x.table) {
246 table->move(&x.object, &
object);
250 x.table->clone(&x.object, &
object);
257 template <
typename T>
263 if (table == x_table) {
265 table->destruct(&
object);
271 table->destruct(&
object);
284 template <
typename T>
299 std::swap(table, x.table);
300 std::swap(
object, x.object);
304 boost::core::typeinfo
const&
type()
const
306 return table->get_type();
309 template <
typename T>
312 if (
type() != BOOST_CORE_TYPEID(T))
316 *
reinterpret_cast<T const*
>(&object) :
317 *
reinterpret_cast<T const*
>(object);
326#ifdef BOOST_SPIRIT_ANY_IMPLICIT_CASTING
328 template <
typename T>
329 operator T
const& ()
const {
return cast<T>(); }
341 table->static_delete(&
object);
347#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
349 template <
typename T,
typename Char_>
360 template <
typename T,
typename Char>
363 if (operand && operand->
type() == BOOST_CORE_TYPEID(T)) {
365 reinterpret_cast<T*
>(&operand->object) :
366 reinterpret_cast<T*
>(operand->object);
371 template <
typename T,
typename Char>
377 template <
typename T,
typename Char>
380 typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
382#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
389 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
392 nonref* result = any_cast<nonref>(&operand);
398 template <
typename T,
typename Char>
401 typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
403#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
406 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
419 template <
typename T>
422 template <
typename Char>
429#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
basic_hold_any & operator=(basic_hold_any const &x)
basic_hold_any & operator=(T const &x)
const void * castsmallvoid() const
basic_hold_any(basic_hold_any const &x)
basic_hold_any & swap(basic_hold_any &x)
basic_hold_any & assign(T const &x)
static void new_object(void *&object, T const &x, mpl::true_)
basic_hold_any(T const &x)
basic_hold_any & assign(basic_hold_any const &x)
static void new_object(void *&object, T const &x, mpl::false_)
boost::core::typeinfo const & type() const
friend T * any_cast(basic_hold_any< Char_ > *)
basic_hold_any(const char *x)
basic_hold_any< wchar_t > whold_any
basic_hold_any< char > hold_any
T * any_cast(basic_hold_any< Char > *operand)
bad_any_cast(boost::core::typeinfo const &src, boost::core::typeinfo const &dest)
virtual const char * what() const
void(* static_delete)(void **)
void(* move)(void *const *, void **)
void(* destruct)(void **)
void(* clone)(void *const *, void **)
static boost::core::typeinfo const & get_type()
static void destruct(void **x)
static void move(void *const *src, void **dest)
static void static_delete(void **x)
static void clone(void *const *src, void **dest)
static void move(void *const *src, void **dest)
static void clone(void *const *src, void **dest)
static boost::core::typeinfo const & get_type()
static void static_delete(void **x)
static void destruct(void **x)
static fxn_ptr_table< Char > * get()
mpl::bool_<(sizeof(T)<=sizeof(void *)) is_small)