Apply patch for [CVE-2012-2677][boost] ordered_malloc() overflow
[external/boost.git] / boost / python / def_visitor.hpp
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
8 # include <boost/python/detail/prefix.hpp>
9 # include <boost/detail/workaround.hpp>
10
11 namespace boost { namespace python { 
12
13 template <class DerivedVisitor> class def_visitor;
14 template <class T, class X1, class X2, class X3> class class_;
15
16 class def_visitor_access
17 {
18 # if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)                  \
19     || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
20     // Tasteless as this may seem, making all members public allows member templates
21     // to work in the absence of member template friends.
22  public:
23 # else      
24     template <class Derived> friend class def_visitor;
25 # endif
26     
27     // unnamed visit, c.f. init<...>, container suites
28     template <class V, class classT>
29     static void visit(V const& v, classT& c)
30     {
31         v.derived_visitor().visit(c);
32     }
33
34     // named visit, c.f. object, pure_virtual
35     template <class V, class classT, class OptionalArgs>
36     static void visit(
37         V const& v
38       , classT& c
39       , char const* name
40       , OptionalArgs const& options
41     ) 
42     {
43         v.derived_visitor().visit(c, name, options);
44     }
45     
46 };
47
48
49 template <class DerivedVisitor>
50 class def_visitor
51 {
52     friend class def_visitor_access;
53     
54 # if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)                  \
55     || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
56     // Tasteless as this may seem, making all members public allows member templates
57     // to work in the absence of member template friends.
58  public:
59 # else      
60     template <class T, class X1, class X2, class X3> friend class class_;
61 # endif
62     
63     // unnamed visit, c.f. init<...>, container suites
64     template <class classT>
65     void visit(classT& c) const
66     {
67         def_visitor_access::visit(*this, c);
68     }
69
70     // named visit, c.f. object, pure_virtual
71     template <class classT, class OptionalArgs>
72     void visit(classT& c, char const* name, OptionalArgs const& options) const
73     {
74         def_visitor_access::visit(*this, c, name, options);
75     }
76     
77  protected:
78     DerivedVisitor const& derived_visitor() const
79     {
80         return static_cast<DerivedVisitor const&>(*this);
81     }
82 };
83
84 }} // namespace boost::python
85
86 #endif // DEF_VISITOR_DWA2003810_HPP