10 #ifndef ADOBE_ANY_REGULAR_HPP 11 #define ADOBE_ANY_REGULAR_HPP 17 #include <boost/mpl/bool.hpp> 18 #include <boost/mpl/if.hpp> 19 #include <boost/noncopyable.hpp> 20 #include <boost/operators.hpp> 21 #include <boost/static_assert.hpp> 22 #include <boost/type_traits/has_nothrow_copy.hpp> 23 #include <boost/type_traits/is_pointer.hpp> 24 #include <boost/type_traits/is_reference.hpp> 25 #include <boost/type_traits/is_same.hpp> 26 #include <boost/type_traits/remove_const.hpp> 27 #include <boost/type_traits/remove_pointer.hpp> 28 #include <boost/type_traits/remove_reference.hpp> 29 #include <boost/concept_check.hpp> 39 #include <adobe/implementation/swap.hpp> 41 #if defined(ADOBE_STD_SERIALIZATION) 152 namespace implementation {
154 enum { vtable_version = 1 };
156 struct any_regular_interface_t;
160 typedef any_regular_interface_t interface_type;
163 void (*destruct)(
const interface_type&);
164 type_info_t (*
type_info)(
const interface_type&);
165 interface_type* (*clone)(
const interface_type&,
void*);
166 interface_type* (*move_clone)(interface_type&,
void*);
167 void (*assign)(interface_type&,
const interface_type&);
168 bool (*equals)(
const interface_type&,
const interface_type&);
169 void (*exchange)(interface_type&, interface_type&);
180 const vtable_t* vtable_m;
188 struct any_regular_interface_t {
189 typedef any_regular_interface_t interface_type;
191 any_regular_interface_t(
const vtable_t& x) { object_m.vtable_m = &x; }
193 pad_vtable_t object_m;
195 void destruct()
const {
return object_m.vtable_m->destruct(*
this); }
196 type_info_t
type_info()
const {
return object_m.vtable_m->type_info(*
this); }
197 interface_type* clone(
void* x)
const {
return object_m.vtable_m->clone(*
this, x); }
198 interface_type* move_clone(
void* x) {
return object_m.vtable_m->move_clone(*
this, x); }
199 void assign(
const interface_type& x) { object_m.vtable_m->assign(*
this, x); }
200 bool equals(
const interface_type& x)
const {
return object_m.vtable_m->equals(*
this, x); }
201 void exchange(interface_type& x) { object_m.vtable_m->exchange(*
this, x); }
206 template <
typename T>
207 struct any_regular_model_local : any_regular_interface_t, boost::noncopyable
209 typedef any_regular_interface_t interface_type;
213 static const vtable_t vtable_s;
215 any_regular_model_local() : interface_type(vtable_s), object_m() { }
217 explicit any_regular_model_local(T x)
218 : interface_type(vtable_s), object_m(
adobe::
move(x)) { }
220 static const any_regular_model_local&
self(
const interface_type& x)
221 {
return static_cast<const any_regular_model_local&
>(x); }
223 static any_regular_model_local&
self(interface_type& x)
224 {
return static_cast<any_regular_model_local&
>(x); }
226 static type_info_t
type_info(
const interface_type&)
227 {
return adobe::type_info<T>(); }
229 static void destruct(
const interface_type& x)
230 {
self(x).~any_regular_model_local(); }
232 static interface_type* clone(
const interface_type& x,
void* storage)
233 { return ::new(storage) any_regular_model_local(
self(x).object_m); }
235 static interface_type* move_clone(interface_type& x,
void* storage)
236 { return ::new(storage) any_regular_model_local(
adobe::move(
self(x).object_m)); }
238 static void assign(interface_type& x,
const interface_type& y)
239 {
self(x).object_m =
self(y).object_m; }
241 static bool equals(
const interface_type& x,
const interface_type& y)
242 {
return self(x).object_m ==
self(y).object_m; }
244 static void exchange(interface_type& x, interface_type& y)
245 {
swap(
self(x).object_m,
self(y).object_m); }
247 const T&
get()
const {
return object_m; }
248 T&
get() {
return object_m; }
253 template <
typename T>
254 const vtable_t any_regular_model_local<T>::vtable_s
261 &any_regular_model_local::destruct,
263 &any_regular_model_local::clone,
264 &any_regular_model_local::move_clone,
265 &any_regular_model_local::assign,
266 &any_regular_model_local::equals,
267 &any_regular_model_local::exchange,
270 template <
typename T>
271 struct any_regular_model_remote : any_regular_interface_t, boost::noncopyable
273 BOOST_CLASS_REQUIRE(T,
adobe, RegularConcept);
275 typedef any_regular_interface_t interface_type;
278 typedef capture_allocator<object_t> allocator_type;
280 struct object_t : boost::noncopyable
282 aligned_storage<allocator_type> alloc_m;
286 static object_t* new_move(T& x)
289 object_t* result = a.allocate(1);
290 construct(&result->alloc_m, aligned_storage<allocator_type>(a));
295 object_t* object_ptr_m;
297 static const vtable_t vtable_s;
299 explicit any_regular_model_remote(T x)
300 : interface_type(vtable_s), object_ptr_m(new_move(x))
303 any_regular_model_remote(move_from<any_regular_model_remote> x)
304 : interface_type(vtable_s), object_ptr_m(x.source.object_ptr_m) { x.source.object_ptr_m = 0; }
306 ~any_regular_model_remote()
309 allocator_type a = object_ptr_m->alloc_m.get();
310 destroy(&object_ptr_m->alloc_m);
311 destroy(&object_ptr_m->data_m);
312 a.deallocate(object_ptr_m, 1);
316 static const any_regular_model_remote&
self(
const interface_type& x)
317 {
return static_cast<const any_regular_model_remote&
>(x); }
319 static any_regular_model_remote&
self(interface_type& x)
320 {
return static_cast<any_regular_model_remote&
>(x); }
322 static type_info_t
type_info(
const interface_type&)
323 {
return adobe::type_info<T>(); }
325 static void destruct(
const interface_type& x)
326 {
return self(x).~any_regular_model_remote(); }
328 static interface_type* clone(
const interface_type& x,
void* storage)
329 { return ::new(storage) any_regular_model_remote(
self(x).
get()); }
331 static interface_type* move_clone(interface_type& x,
void* storage)
332 { return ::new(storage) any_regular_model_remote(move_from<any_regular_model_remote>(
self(x))); }
334 static void assign(interface_type& x,
const interface_type& y)
335 {
self(x).
get() =
self(y).
get(); }
337 static bool equals(
const interface_type& x,
const interface_type& y)
338 {
return self(x).
get() ==
self(y).
get(); }
340 static void exchange(interface_type& x, interface_type& y)
341 {
return swap(
self(x).object_ptr_m,
self(y).object_ptr_m); }
343 const T&
get()
const {
return object_ptr_m->data_m; }
344 T&
get() {
return object_ptr_m->data_m; }
349 template <
typename T>
350 const vtable_t any_regular_model_remote<T>::vtable_s
357 &any_regular_model_remote::destruct,
359 &any_regular_model_remote::clone,
360 &any_regular_model_remote::move_clone,
361 &any_regular_model_remote::assign,
362 &any_regular_model_remote::equals,
363 &any_regular_model_remote::exchange,
426 class any_regular_t : boost::equality_comparable<any_regular_t, any_regular_t>
428 typedef implementation::any_regular_interface_t interface_type;
429 typedef double storage_t[2];
431 #ifndef ADOBE_NO_DOCUMENTATION 433 template <
typename T>
439 typedef promote_type& reference_type;
440 typedef const promote_type& const_reference_type;
442 typedef implementation::any_regular_model_local<promote_type> regular_model_local_type;
443 typedef implementation::any_regular_model_remote<promote_type> regular_model_remote_type;
445 typedef boost::mpl::bool_<(
sizeof(regular_model_local_type)
446 <=
sizeof(storage_t))
447 && (boost::has_nothrow_copy<promote_type>::value
450 typedef typename boost::mpl::if_<use_local_type,
451 regular_model_local_type,
452 regular_model_remote_type>::type model_type;
454 typedef typename boost::mpl::if_c<
455 boost::is_same<promote_type, T>::value,
456 reference_type, T>::type result_type;
458 typedef typename boost::mpl::if_c<
459 boost::is_same<promote_type, T>::value,
460 const_reference_type, T>::type const_result_type;
463 template <
typename T>
struct helper;
464 template <
typename T>
friend struct helper;
484 x.object().move_clone(storage());
497 template <
typename T>
499 { ::new (storage())
typename traits<T>::model_type(
adobe::move(x)); }
514 template <
typename T>
522 template <
typename T>
523 typename traits<T>::const_result_type
cast()
const 524 {
return helper<T>::cast(*
this); }
535 template <
typename T>
536 typename traits<T>::result_type
cast()
537 {
return helper<T>::cast(*
this); }
552 template <
typename T>
556 ::new (storage())
typename traits<T>::model_type(
adobe::move(x));
563 x.object().move_clone(storage());
585 template <
typename T>
591 {
return x.
cast<T>(); }
593 typename traits<T>::const_result_type operator () (
const any_regular_t& x)
const 594 {
return x.
cast<T>(); }
597 #if defined(ADOBE_STD_SERIALIZATION) 607 interface_type& object() {
return *
static_cast<interface_type*
>(storage()); }
608 const interface_type& object()
const {
return *
static_cast<const interface_type*
>(storage()); }
610 void* storage() {
return &data_m; }
611 const void* storage()
const {
return &data_m; }
615 #ifndef ADOBE_NO_DOCUMENTATION 617 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS 623 template <
typename T>
625 {
return helper<T>::ptr_cast(*
this); }
630 #ifndef ADOBE_NO_DOCUMENTATION 639 any_regular_t::interface_type& a(x.object());
640 any_regular_t::interface_type& b(y.object());
642 if (a.type_info() == b.type_info()) { a.exchange(b);
return; }
649 b.move_clone(x.storage());
653 tmp.object().move_clone(y.storage());
660 #ifndef ADOBE_NO_DOCUMENTATION 662 template <
typename T>
663 struct any_regular_t::helper
667 if (r.
type_info() != adobe::type_info<T>())
669 return &
reinterpret_cast<typename traits<T>::model_type&
>(r.object()).
get();
672 static inline typename traits<T>::const_result_type cast(
const any_regular_t& r)
674 typedef typename traits<T>::promote_type promote_type;
676 if (r.
type_info() != adobe::type_info<promote_type>())
678 return static_cast<typename traits<T>::const_result_type
>(
679 reinterpret_cast<const typename traits<T>::model_type&
>(r.object()).
get());
682 static inline typename traits<T>::result_type cast(
any_regular_t& r)
684 typedef typename traits<T>::promote_type promote_type;
686 if (r.
type_info() != adobe::type_info<promote_type>())
688 return static_cast<typename traits<T>::result_type
>(
689 reinterpret_cast<typename traits<T>::model_type&
>(r.object()).
get());
696 if (r.
type_info() == adobe::type_info<promote_type>())
697 r.
cast<promote_type>() = static_cast<promote_type>(x);
710 struct any_regular_t::helper<any_regular_t>
712 static inline any_regular_t* ptr_cast(any_regular_t& r)
715 static inline const any_regular_t& cast(
const any_regular_t& r)
718 static inline any_regular_t& cast(any_regular_t& r)
746 template <
typename R>
751 typedef typename boost::remove_const<typename boost::remove_reference<R>::type>::type
759 return x.
cast<result_type>();
765 template <
typename R>
770 typedef typename boost::remove_reference<R>::type result_type;
777 return x.
cast<result_type>();
783 template <
typename R>
788 typedef typename boost::remove_pointer<R>::type result_type;
795 return x->ptr_cast<result_type>();
801 template <
typename R>
806 typedef typename boost::remove_const<typename boost::remove_pointer<R>::type>::type
814 if (x->
type_info() != type_info<result_type>())
return 0;
815 return &x->
cast<result_type>();
version_1::any_regular_t any_regular_t
R operator()(const any_regular_t &x) const
any_regular_t(move_from< any_regular_t > x)
move_from is used for move_ctors.
friend type_info_t type_info()
retruns the type_info_t object corresponding to the type T
type_info_t type_info() const
BOOST_STATIC_ASSERT(sizeof(closed_hash_set< int >)==sizeof(void *))
R operator()(any_regular_t &x) const
any_regular_t(const any_regular_t &x)
bool operator==(const circular_queue< T > &x, const circular_queue< T > &y)
An exception class thrown during ASL failures to cast.
Partial re-implementation of standard type_info .
any_regular_t & operator=(any_regular_t x)
The is_movable trait can be used to identify movable types.
R operator()(const any_regular_t *x) const
void swap(circular_queue< T > &, circular_queue< T > &)
traits< T >::result_type cast()
traits< T >::const_result_type cast() const
R operator()(any_regular_t *x) const
A runtime polymorphic type similar to boost::any which can hold any type which models Regular...
any_regular_t & assign(T x)
bool empty(const any_regular_t &x)
any_regular_t & assign(any_regular_t x)
std::ostream & operator<<(std::ostream &s, const extents_t &x)