Contenu connexe
Similaire à Boost.Interfaces (20)
Boost.Interfaces
- 4. struct point { ... int x() const { return x_; } int y() const { return y_; } void x( int v) { x_ = v; } void y( int v) { y_ = v; } }; ・ライブラリ作ったよ! モチベーション (1)
- 5. struct point { ... int x() const { return x_; } int y() const { return y_; } void x( int v) { x_ = v; } void y( int v) { y_ = v; } }; ・ライブラリ作ったよ! struct rectangle { ... int x() const { return x_; } int y() const { return y_; } int w() const { return w_; } int h() const { return h_; } }; モチベーション (1)
- 7. void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } ・ライブラリ使うよ! モチベーション (2)
- 8. ・ライブラリ使うよ! void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (2)
- 9. ・ライブラリ使うよ! void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 完全に一致 モチベーション (2)
- 14. インターフェースさえ提供されていれば ... void add(IPoint& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? -> NO 使う側の要求するインターフェースを ライブラリが全て提供するのは無理ぽ モチベーション (3)
- 17. ・それテンプレートでできるよ template < class Point> void add(Point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } テンプレートを使うことで ユーザが自由にインターフェースを定義できる モチベーション (4)
- 20. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; モチベーション (5)
- 21. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
- 22. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; こんな風に書きたいことがある std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
- 25. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); Boost.Interfaces の使い方
- 26. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); ↑ ドットでアクセス Boost.Interfaces の使い方
- 27. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); 解決! ↑ ドットでアクセス Boost.Interfaces の使い方
- 28. interface Point { int x() const ; int y() const ; void x( int v); void y( int v); } Pseudocode Boost.Interfaces クラス定義
- 29. int x() const ; int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) C++ code Boost.Interfaces クラス定義
- 30. int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) C++ code Boost.Interfaces クラス定義
- 31. void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) C++ code Boost.Interfaces クラス定義
- 32. void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) C++ code Boost.Interfaces クラス定義
- 36. interface Point { int x() const ; int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) 完全に一致 Pseudocode C++ code Boost.Interfaces クラス定義
- 37. struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; }; class Point : public ::boost::interfaces::detail::interface_base< Point , Point_interface_impl_ , 496 - Point_interface_impl_ ::start_line_idl_ >::type { private: typedef Point_interface_impl_ implementation_type; typedef ::boost::interfaces::detail::interface_base< Point , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_ > ::boost::type_traits::yes_type is_interface_helper( Point *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point > >::type* = 0 ); Boost.Interfaces クラス定義
- 38. struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; }; class Point : public ::boost::interfaces::detail::interface_base< Point , Point_interface_impl_ , 496 - Point_interface_impl_ ::start_line_idl_ >::type { private: typedef Point_interface_impl_ implementation_type; typedef ::boost::interfaces::detail::interface_base< Point , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_ > ::boost::type_traits::yes_type is_interface_helper( Point *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point > >::type* = 0 ); Boost.Interfaces クラス定義 非常に明解で分かりやすい
- 40. interface Point1D { int x() const ; } interface WritablePoint1D : Point1D { void x( int v); } interface Point2D : Point1D { int y() const ; } interface WritablePoint2D : Point2D , WritablePoint1D { void y( int v); } インターフェースの継承もできる その他の機能 (1)
- 41. BOOST_IDL_BEGIN(Point1D) BOOST_IDL_FN0(x, int ) BOOST_IDL_END(Point1D) BOOST_IDL_BEGIN(WritablePoint1D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN1(x, void , int ) BOOST_IDL_END(WritablePoint1D) BOOST_IDL_BEGIN(Point2D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN0(y, int ) BOOST_IDL_END(Point2D) BOOST_IDL_BEGIN(WritablePoint2D) BOOST_IDL_EXTENDS(Point2D) BOOST_IDL_EXTENDS(WritablePoint1D) BOOST_IDL_FN1(y, void , int ) BOOST_IDL_END(Point2D) インターフェースの継承もできる その他の機能 (1)
- 43. テンプレートなインターフェース も定義できる template<class T> BOOST_IDL_BEGIN1(Stack) BOOST_IDL_CONST_FN0(empty, bool ) BOOST_IDL_FN1(push, void , const T&) BOOST_IDL_FN0(pop, void ) BOOST_IDL_FN0(top, T&) BOOST_IDL_CONST_FN0(top, const T&) BOOST_IDL_END1(Stack) その他の機能 (2)
- 44. Boost.Interfaces は一切 コピーしない // d は rect への 参照を保持 Drawable d = rect; // コンパイルエラー Drawable d2 = rectangle(); // d3 は rect への 参照を保持 Drawable d3 = d; その他の機能 (3)
- 45. Boost.Interfaces は一切 コピーしない // d は rect への 参照を保持 Drawable d = rect; // コンパイルエラー Drawable d2 = rectangle(); // d3 は rect への 参照を保持 Drawable d3 = d; Boost.Interfaces はコピーを 要求しない その他の機能 (3)
- 50. キャスト shared_ptr<Drawable> d( new point()); shared_obj<Drawable> d2( new rectangle()); // OK point& p = extract <point>(*d); // bad_extract point& p2 = extract <point>(d2); その他の機能 (5)
- 52. Aspect Oriented Programming (AOP) typedef crosscut< MyClass, aspect<Pointcut1, Advice1>, aspect<Pointcut2, Advice2>, ... , aspect<PointcutN, AdviceN> > MyCrosscutClass; ミライノハナシ (1)
- 53. リフレクション template < typename Interface> void f(Interface& i) { boost::function< void ( int )> f; if (f = find_function< void ( int )>(i, "foo")) f(3); } ミライノハナシ (2)
- 63. 参考資料 Cryolite 先生 http ://d.hatena.ne.jp/Cryolite/20041130#p2 http://d.hatena.ne.jp/Cryolite/20041201#p1 http://d.hatena.ne.jp/Cryolite/20050205#p1 ABI 周りについて書いてあったり モチベーションについてもっと細かく書いてあったり 本家 http://www.coderage.com/interfaces/