22 #ifndef BOOST_PYTHON_INDEXING_VISITOR_HPP 23 #define BOOST_PYTHON_INDEXING_VISITOR_HPP 25 #include <indexing_suite/slice_handler.hpp> 26 #include <indexing_suite/suite_utils.hpp> 28 #include <boost/python/def_visitor.hpp> 29 #include <boost/python/iterator.hpp> 30 #include <boost/python/default_call_policies.hpp> 31 #include <boost/type_traits/ice.hpp> 32 #include <boost/bind.hpp> 35 namespace boost {
namespace python {
namespace indexing {
43 template<
typename PrecallPolicy>
47 explicit precall_only (PrecallPolicy
const ©) : m_precall (copy) { }
49 bool precall (PyObject *args) {
return m_precall.precall (args); }
50 bool precall (PyObject *args)
const {
return m_precall.precall (args); }
53 PrecallPolicy m_precall;
65 #define OPTIONAL_ALGO_SUPPORT(ADDER_NAME, METHOD_NAME, ALGO_FN) template<bool doit> struct ADDER_NAME { template<class PythonClass, class Algorithms, class Policy> static void apply (PythonClass &, Algorithms const &, Policy const &) { } }; template<> struct ADDER_NAME<true> { template<class PythonClass, class Algorithms, class Policy> static void apply( PythonClass &pyClass, Algorithms const &, Policy const &policy) { pyClass.def (METHOD_NAME, &Algorithms::ALGO_FN, policy); } } 75 #define OPTIONAL_SLICE_SUPPORT(ADDER_NAME, METHOD_NAME, SLICE_HANDLER_FN) template<bool doit> struct ADDER_NAME { template<class PythonClass, class Algorithms, class Policy> static void apply (PythonClass &, Algorithms const &, Policy const &) { } }; template<> struct ADDER_NAME<true> { template<class PythonClass, class Algorithms, class Policy> static void apply( PythonClass &pyClass, Algorithms const &, Policy const &policy) { pyClass.def ( METHOD_NAME, slice_handler<Algorithms, Policy>::SLICE_HANDLER_FN (policy)); } } 84 template<
class PythonClass,
class Algorithms,
class Policy>
85 static void apply (PythonClass &, Algorithms
const &, Policy
const &) { }
94 template<
class PythonClass,
class Algorithms,
class Policy>
106 boost::python::range<Policy>(
117 OPTIONAL_ALGO_SUPPORT (maybe_add_len,
"__len__", size);
118 OPTIONAL_ALGO_SUPPORT (maybe_add_getitem,
"__getitem__",
get);
119 OPTIONAL_ALGO_SUPPORT (maybe_add_setitem,
"__setitem__", assign);
120 OPTIONAL_ALGO_SUPPORT (maybe_add_delitem,
"__delitem__", erase_one);
121 OPTIONAL_SLICE_SUPPORT (maybe_add_getslice,
"__getitem__", make_getitem);
122 OPTIONAL_SLICE_SUPPORT (maybe_add_setslice,
"__setitem__", make_setitem);
123 OPTIONAL_SLICE_SUPPORT (maybe_add_delslice,
"__delitem__", make_delitem);
124 OPTIONAL_ALGO_SUPPORT (maybe_add_sort,
"sort", sort);
125 OPTIONAL_ALGO_SUPPORT (maybe_add_reverse,
"reverse", reverse);
126 OPTIONAL_ALGO_SUPPORT (maybe_add_append,
"append", push_back);
127 OPTIONAL_ALGO_SUPPORT (maybe_add_insert,
"insert", insert);
128 OPTIONAL_SLICE_SUPPORT (maybe_add_extend,
"extend", make_extend);
129 OPTIONAL_ALGO_SUPPORT (maybe_add_index,
"index", get_index);
130 OPTIONAL_ALGO_SUPPORT (maybe_add_count,
"count", count);
131 OPTIONAL_ALGO_SUPPORT (maybe_add_contains,
"__contains__", contains);
132 OPTIONAL_ALGO_SUPPORT (maybe_add_has_key,
"has_key", contains);
138 template<
class Algorithms,
class Policy, method_set_type MethodMask>
140 :
public def_visitor< visitor< Algorithms, Policy, MethodMask > >
144 BOOST_STATIC_CONSTANT (
146 enabled_methods = Algorithms::supported_methods & MethodMask);
149 typedef Algorithms algorithms_type;
151 explicit visitor (Policy
const &policy = Policy()) : m_policy (policy) { }
154 template <
class PythonClass>
155 void visit (PythonClass &pyClass)
const 159 maybe_add_len<detail::is_member<enabled_methods, method_len>::value>
160 ::apply(pyClass, algorithms_type(), precallPolicy);
164 >::apply(pyClass, algorithms_type(), m_policy);
168 >::apply(pyClass, algorithms_type(), m_policy);
172 >::apply(pyClass, algorithms_type(), m_policy);
176 >::apply(pyClass, algorithms_type(), m_policy);
180 >::apply(pyClass, algorithms_type(), m_policy);
184 >::apply(pyClass, algorithms_type(), m_policy);
188 >::apply (pyClass, algorithms_type(), m_policy);
192 >::apply (pyClass, algorithms_type(), precallPolicy);
196 >::apply (pyClass, algorithms_type(), precallPolicy);
200 >::apply (pyClass, algorithms_type(), precallPolicy);
204 >::apply (pyClass, algorithms_type(), precallPolicy);
208 >::apply (pyClass, algorithms_type(), precallPolicy);
212 >::apply (pyClass, algorithms_type(), precallPolicy);
216 >::apply (pyClass, algorithms_type(), precallPolicy);
220 >::apply (pyClass, algorithms_type(), precallPolicy);
224 >::apply (pyClass, algorithms_type(), precallPolicy);
226 Algorithms::visit_container_class (pyClass, m_policy);
231 #undef OPTIONAL_SLICE_SUPPORT 232 #undef OPTIONAL_ALGO_SUPPORT 234 #endif // BOOST_PYTHON_INDEXING_VISITOR_HPP Definition: visitor.hpp:139
Definition: python_CEGUI.h:9
Definition: visitor.hpp:83
Definition: visitor.hpp:44
Definition: methods.hpp:108