Beispiel #1
0
        // Function objects that fit in the small-object buffer.
        static inline void
        manage_small(const function_buffer& in_buffer, function_buffer& out_buffer, 
                functor_manager_operation_type op)
        {
          if (op == clone_functor_tag || op == move_functor_tag) {
            const functor_type* in_functor = 
              reinterpret_cast<const functor_type*>(&in_buffer.data);
            new (reinterpret_cast<void*>(&out_buffer.data)) functor_type(*in_functor);

            if (op == move_functor_tag) {
              functor_type* f = reinterpret_cast<functor_type*>(&in_buffer.data);
              (void)f; // suppress warning about the value of f not being used (MSVC)
              f->~Functor();
            }
          } else if (op == destroy_functor_tag) {
            // Some compilers (Borland, vc6, ...) are unhappy with ~functor_type.
             functor_type* f = reinterpret_cast<functor_type*>(&out_buffer.data);
             (void)f; // suppress warning about the value of f not being used (MSVC)
             f->~Functor();
          } else if (op == check_functor_type_tag) {
            const detail::sp_typeinfo& check_type 
              = *out_buffer.type.type;
            if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
              out_buffer.obj_ptr = &in_buffer.data;
            else
              out_buffer.obj_ptr = 0;
          } else /* op == get_functor_type_tag */ {
            out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
            out_buffer.type.const_qualified = false;
            out_buffer.type.volatile_qualified = false;            
          }
        }
Beispiel #2
0
 // Function objects that require heap allocation
 static inline void
 manager(const function_buffer& in_buffer, function_buffer& out_buffer,
         functor_manager_operation_type op, mpl::false_)
 {
   if (op == clone_functor_tag) {
     // Clone the functor
     // GCC 2.95.3 gets the CV qualifiers wrong here, so we
     // can't do the static_cast that we should do.
     const functor_type* f =
       (const functor_type*)(in_buffer.obj_ptr);
     functor_type* new_f = new functor_type(*f);
     out_buffer.obj_ptr = new_f;
   } else if (op == move_functor_tag) {
     out_buffer.obj_ptr = in_buffer.obj_ptr;
     in_buffer.obj_ptr = 0;
   } else if (op == destroy_functor_tag) {
     /* Cast from the void pointer to the functor pointer type */
     functor_type* f =
       static_cast<functor_type*>(out_buffer.obj_ptr);
     delete f;
     out_buffer.obj_ptr = 0;
   } else if (op == check_functor_type_tag) {
     const detail::sp_typeinfo& check_type
       = *out_buffer.type.type;
     if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
       out_buffer.obj_ptr = in_buffer.obj_ptr;
     else
       out_buffer.obj_ptr = 0;
   } else /* op == get_functor_type_tag */ {
     out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
     out_buffer.type.const_qualified = false;
     out_buffer.type.volatile_qualified = false;
   }
 }
Beispiel #3
0
        // Function objects that require heap allocation
        static inline void
        manager(const function_buffer& in_buffer, function_buffer& out_buffer, 
                functor_manager_operation_type op, mpl::false_)
        {
          typedef functor_wrapper<Functor,Allocator> functor_wrapper_type;
          typedef typename Allocator::template rebind<functor_wrapper_type>::other
            wrapper_allocator_type;
          typedef typename wrapper_allocator_type::pointer wrapper_allocator_pointer_type;

          if (op == clone_functor_tag) {
            // Clone the functor
            // GCC 2.95.3 gets the CV qualifiers wrong here, so we
            // can't do the static_cast that we should do.
            const functor_wrapper_type* f =
              static_cast<const functor_wrapper_type*>(in_buffer.obj_ptr);
            wrapper_allocator_type wrapper_allocator(static_cast<Allocator const &>(*f));
            wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
            wrapper_allocator.construct(copy, *f);

            // Get back to the original pointer type
            functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
            out_buffer.obj_ptr = new_f;
          } else if (op == move_functor_tag) {
            out_buffer.obj_ptr = in_buffer.obj_ptr;
            in_buffer.obj_ptr = 0;
          } else if (op == destroy_functor_tag) {
            /* Cast from the void pointer to the functor_wrapper_type */
            functor_wrapper_type* victim =
              static_cast<functor_wrapper_type*>(in_buffer.obj_ptr);
            wrapper_allocator_type wrapper_allocator(static_cast<Allocator const &>(*victim));
            wrapper_allocator.destroy(victim);
            wrapper_allocator.deallocate(victim,1);
            out_buffer.obj_ptr = 0;
          } else if (op == check_functor_type_tag) {
            const detail::sp_typeinfo& check_type 
              = *out_buffer.type.type;
            if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
              out_buffer.obj_ptr = in_buffer.obj_ptr;
            else
              out_buffer.obj_ptr = 0;
          } else /* op == get_functor_type_tag */ {
            out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
            out_buffer.type.const_qualified = false;
            out_buffer.type.volatile_qualified = false;
          }
        }
Beispiel #4
0
        static inline void
        manage(const function_buffer& in_buffer, function_buffer& out_buffer, 
               functor_manager_operation_type op)
        {
          switch (op) {
          case clone_functor_tag: 
            out_buffer.obj_ref = in_buffer.obj_ref;
            return;

          case move_functor_tag:
            out_buffer.obj_ref = in_buffer.obj_ref;
            in_buffer.obj_ref.obj_ptr = 0;
            return;

          case destroy_functor_tag:
            out_buffer.obj_ref.obj_ptr = 0;
            return;

          case check_functor_type_tag:
            {
              const detail::sp_typeinfo& check_type 
                = *out_buffer.type.type;

              // Check whether we have the same type. We can add
              // cv-qualifiers, but we can't take them away.
              if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(F))
                  && (!in_buffer.obj_ref.is_const_qualified 
                      || out_buffer.type.const_qualified)
                  && (!in_buffer.obj_ref.is_volatile_qualified
                      || out_buffer.type.volatile_qualified))
                out_buffer.obj_ptr = in_buffer.obj_ref.obj_ptr;
              else
                out_buffer.obj_ptr = 0;
            }
            return;

          case get_functor_type_tag:
            out_buffer.type.type = &BOOST_SP_TYPEID(F);
            out_buffer.type.const_qualified = in_buffer.obj_ref.is_const_qualified;
            out_buffer.type.volatile_qualified = in_buffer.obj_ref.is_volatile_qualified;
            return;
          }
        }
Beispiel #5
0
 // Function pointers
 static inline void
 manage_ptr(const function_buffer& in_buffer, function_buffer& out_buffer, 
         functor_manager_operation_type op)
 {
   if (op == clone_functor_tag)
     out_buffer.func_ptr = in_buffer.func_ptr;
   else if (op == move_functor_tag) {
     out_buffer.func_ptr = in_buffer.func_ptr;
     in_buffer.func_ptr = 0;
   } else if (op == destroy_functor_tag)
     out_buffer.func_ptr = 0;
   else if (op == check_functor_type_tag) {
     const detail::sp_typeinfo& check_type 
       = *out_buffer.type.type;
     if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
       out_buffer.obj_ptr = &in_buffer.func_ptr;
     else
       out_buffer.obj_ptr = 0;
   } else /* op == get_functor_type_tag */ {
     out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
     out_buffer.type.const_qualified = false;
     out_buffer.type.volatile_qualified = false;
   }
 }
Beispiel #6
0
        /* Dispatch to an appropriate manager based on whether we have a
           function pointer or a function object pointer. */
        static inline void
        manage(const function_buffer& in_buffer, function_buffer& out_buffer, 
               functor_manager_operation_type op)
        {
          typedef typename get_function_tag<functor_type>::type tag_type;
          switch (op) {
          case get_functor_type_tag:
            out_buffer.type.type = &BOOST_SP_TYPEID(functor_type);
            out_buffer.type.const_qualified = false;
            out_buffer.type.volatile_qualified = false;
            return;

          default:
            manager(in_buffer, out_buffer, op, tag_type());
            return;
          }
        }
Beispiel #7
0
 virtual void * get_deleter( sp_typeinfo const & ti ) override
 {
     return ti == BOOST_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
 }
 virtual void * get_deleter( detail::sp_typeinfo const & ti )
 {
     return ti == BOOST_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
 }
template< class D, class T > D * get_deleter( shared_array<T> const & p )
{
    return static_cast< D * >( p._internal_get_deleter( BOOST_SP_TYPEID(D) ) );
}