MCPcopy Create free account
hub / github.com/Tencent/mars / function_base

Class function_base

mars/boost/function/function_base.hpp:620–715  ·  view source on GitHub ↗

* The function_base class contains the basic elements needed for the * function1, function2, function3, etc. classes. It is common to all * functions (and as such can be used to tell if we have one of the * functionN objects). */

Source from the content-addressed store, hash-verified

618 * functionN objects).
619 */
620class function_base
621{
622public:
623 function_base() : vtable(0) { }
624
625 /** Determine if the function is empty (i.e., has no target). */
626 bool empty() const { return !vtable; }
627
628 /** Retrieve the type of the stored function object, or BOOST_SP_TYPEID(void)
629 if this is empty. */
630 const detail::sp_typeinfo& target_type() const
631 {
632 if (!vtable) return BOOST_SP_TYPEID(void);
633
634 detail::function::function_buffer type;
635 get_vtable()->manager(functor, type, detail::function::get_functor_type_tag);
636 return *type.type.type;
637 }
638
639 template<typename Functor>
640 Functor* target()
641 {
642 if (!vtable) return 0;
643
644 detail::function::function_buffer type_result;
645 type_result.type.type = &BOOST_SP_TYPEID(Functor);
646 type_result.type.const_qualified = is_const<Functor>::value;
647 type_result.type.volatile_qualified = is_volatile<Functor>::value;
648 get_vtable()->manager(functor, type_result,
649 detail::function::check_functor_type_tag);
650 return static_cast<Functor*>(type_result.obj_ptr);
651 }
652
653 template<typename Functor>
654 const Functor* target() const
655 {
656 if (!vtable) return 0;
657
658 detail::function::function_buffer type_result;
659 type_result.type.type = &BOOST_SP_TYPEID(Functor);
660 type_result.type.const_qualified = true;
661 type_result.type.volatile_qualified = is_volatile<Functor>::value;
662 get_vtable()->manager(functor, type_result,
663 detail::function::check_functor_type_tag);
664 // GCC 2.95.3 gets the CV qualifiers wrong here, so we
665 // can't do the static_cast that we should do.
666 return static_cast<const Functor*>(type_result.obj_ptr);
667 }
668
669 template<typename F>
670 bool contains(const F& f) const
671 {
672 if (const F* fp = this->template target<F>())
673 {
674 return function_equal(*fp, f);
675 } else {
676 return false;
677 }

Callers

nothing calls this directly

Calls 2

get_vtableFunction · 0.85
managerMethod · 0.45

Tested by

no test coverage detected