22 #ifndef BOOST_PYTHON_INDEXING_MAP_HPP
23 #define BOOST_PYTHON_INDEXING_MAP_HPP
25 #include <indexing_suite/container_traits.hpp>
26 #include <indexing_suite/container_suite.hpp>
27 #include <indexing_suite/algorithms.hpp>
28 #include <boost/detail/workaround.hpp>
30 #include <indexing_suite/pair.hpp>
32 namespace boost {
namespace python {
namespace indexing {
37 template<
typename Container>
43 # if BOOST_WORKAROUND (BOOST_MSVC, <= 1200)
45 typedef typename Container::referent_type value_type;
47 typedef typename Container::mapped_type value_type;
49 typedef value_type & reference;
50 typedef typename Container::key_type index_type;
51 typedef typename Container::key_type key_type;
53 typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <value_type>::param_type
55 typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type
57 typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <index_type>::param_type
60 BOOST_STATIC_CONSTANT(
72 base_class::is_mutable,
84 template<
typename ContainerTraits,
typename Ovr = detail::no_overr
ide>
88 typename detail::maybe_override
89 <map_algorithms<ContainerTraits, Ovr>, Ovr>
93 typedef typename detail::maybe_override<self_type, Ovr>::type most_derived;
97 typedef typename Parent::container container;
98 typedef typename Parent::reference reference;
99 typedef typename Parent::index_param index_param;
100 typedef typename Parent::value_param value_param;
102 static reference
get (container &, index_param);
105 static boost::python::list keys( container & );
107 static void assign (container &, index_param, value_param);
108 static void insert (container &, index_param, value_param);
110 template<
typename PythonClass,
typename Policy>
111 static void visit_container_class( PythonClass &pyClass, Policy
const &policy)
113 ContainerTraits::visit_container_class (pyClass, policy);
114 pyClass.def(
"keys", &self_type::keys );
116 typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type;
117 mapping::register_value_type< PythonClass, value_type, Policy >( pyClass );
119 pyClass.def(
"__iter__", python::iterator< BOOST_DEDUCED_TYPENAME most_derived::container >() );
124 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
130 template <
class Key,
class T,
class Compare,
class Allocator>
133 typedef std::map<Key, T, Compare, Allocator> Container;
147 template <
class Key,
class T,
class Compare,
class Allocator>
150 typedef std::multimap<Key, T, Compare, Allocator> Container;
164 method_set_type MethodMask = all_methods,
176 template<
typename ContainerTraits,
typename Ovr>
177 BOOST_DEDUCED_TYPENAME map_algorithms<ContainerTraits, Ovr>::reference
180 return most_derived::find_or_throw (c, ix)->second;
184 template<
typename ContainerTraits,
typename Ovr>
186 map_algorithms<ContainerTraits, Ovr>::keys( container &c )
188 boost::python::list _keys;
191 typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type;
192 for( iter_type index = most_derived::begin(c); index != most_derived::end(c); ++index ){
195 if( !_keys.count( index->first ) ){
196 _keys.append( index->first );
208 template<
typename ContainerTraits,
typename Ovr>
210 map_algorithms<ContainerTraits, Ovr>::assign(
211 container &c, index_param ix, value_param val)
221 template<
typename ContainerTraits,
typename Ovr>
223 map_algorithms<ContainerTraits, Ovr>::insert(
224 container &c, index_param ix, value_param val)
227 <BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type,
228 BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type>
233 if (!c.insert (pair_type (ix, val)).second)
236 PyExc_ValueError,
"Map already holds value for insertion");
238 boost::python::throw_error_already_set ();
243 #endif // BOOST_PYTHON_INDEXING_MAP_HPP
Definition: methods.hpp:90
Definition: algorithms.hpp:128
Definition: python_CEGUI.h:9
Definition: container_traits.hpp:59
Definition: proxy_iterator.hpp:155
Definition: container_suite.hpp:42
Definition: algorithms.hpp:532