def_visitor.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright David Abrahams 2003.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef DEF_VISITOR_DWA2003810_HPP
  6. # define DEF_VISITOR_DWA2003810_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/detail/workaround.hpp>
  9. namespace boost { namespace python {
  10. template <class DerivedVisitor> class def_visitor;
  11. template <class T, class X1, class X2, class X3> class class_;
  12. class def_visitor_access
  13. {
  14. # if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
  15. || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
  16. // Tasteless as this may seem, making all members public allows member templates
  17. // to work in the absence of member template friends.
  18. public:
  19. # else
  20. template <class Derived> friend class def_visitor;
  21. # endif
  22. // unnamed visit, c.f. init<...>, container suites
  23. template <class V, class classT>
  24. static void visit(V const& v, classT& c)
  25. {
  26. v.derived_visitor().visit(c);
  27. }
  28. // named visit, c.f. object, pure_virtual
  29. template <class V, class classT, class OptionalArgs>
  30. static void visit(
  31. V const& v
  32. , classT& c
  33. , char const* name
  34. , OptionalArgs const& options
  35. )
  36. {
  37. v.derived_visitor().visit(c, name, options);
  38. }
  39. };
  40. template <class DerivedVisitor>
  41. class def_visitor
  42. {
  43. friend class def_visitor_access;
  44. # if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
  45. || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
  46. // Tasteless as this may seem, making all members public allows member templates
  47. // to work in the absence of member template friends.
  48. public:
  49. # else
  50. template <class T, class X1, class X2, class X3> friend class class_;
  51. # endif
  52. // unnamed visit, c.f. init<...>, container suites
  53. template <class classT>
  54. void visit(classT& c) const
  55. {
  56. def_visitor_access::visit(*this, c);
  57. }
  58. // named visit, c.f. object, pure_virtual
  59. template <class classT, class OptionalArgs>
  60. void visit(classT& c, char const* name, OptionalArgs const& options) const
  61. {
  62. def_visitor_access::visit(*this, c, name, options);
  63. }
  64. protected:
  65. DerivedVisitor const& derived_visitor() const
  66. {
  67. return static_cast<DerivedVisitor const&>(*this);
  68. }
  69. };
  70. }} // namespace boost::python
  71. #endif // DEF_VISITOR_DWA2003810_HPP