Crazy Eddie's GUI System  ${CEGUI_VERSION}
multimap.hpp
1 // This file has been generated by Py++.
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
5 // at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Header file multimap.hpp
8 //
9 // Indexing algorithms support for std::multimap instances
10 //
11 // History
12 // =======
13 // 2006/10/27 Roman File creation from map.hpp
14 // 2008/12/08 Roman Change indexing suite layout
15 // 2010/04/29 Roman Adding "__len__" method
16 //
17 
18 #ifndef BOOST_PYTHON_INDEXING_MULTIMAP_HPP
19 #define BOOST_PYTHON_INDEXING_MULTIMAP_HPP
20 
21 #include <indexing_suite/container_traits.hpp>
22 #include <indexing_suite/container_suite.hpp>
23 #include <indexing_suite/algorithms.hpp>
24 #include <boost/detail/workaround.hpp>
25 #include <functional>
26 #include <map>
27 #include <indexing_suite/pair.hpp>
28 
29 namespace boost { namespace python { namespace indexing {
31  // ContainerTraits implementation for std::map instances
33 
34  template<typename Container>
35  class multimap_traits : public base_container_traits<Container>
36  {
38 
39  public:
40 # if BOOST_WORKAROUND (BOOST_MSVC, <= 1200)
41  // MSVC6 has a nonstandard name for mapped_type in std::multimap
42  typedef typename Container::referent_type value_type;
43 # else
44  typedef typename Container::mapped_type value_type;
45 # endif
46  typedef value_type & reference;
47  typedef typename Container::key_type index_type; // operator[]
48  typedef typename Container::key_type key_type; // find, count, ...
49 
50  typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <value_type>::param_type
51  value_param;
52  typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type
53  key_param;
54  typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <index_type>::param_type
55  index_param;
56 
57  BOOST_STATIC_CONSTANT(
58  method_set_type,
59  supported_methods = (
60  method_iter
61 
62  | method_getitem
63  | method_contains
64  | method_count
65  | method_has_key
66  | method_len
67 
69  base_class::is_mutable,
70  method_setitem
71  | method_delitem
72  | method_insert
73  >::value
74  ));
75  };
76 
78  // Algorithms implementation for std::multimap instances
80 
81  template<typename ContainerTraits, typename Ovr = detail::no_override>
83  : public assoc_algorithms
84  <ContainerTraits,
85  typename detail::maybe_override
86  <multimap_algorithms<ContainerTraits, Ovr>, Ovr>
87  ::type>
88  {
90  typedef typename detail::maybe_override<self_type, Ovr>::type most_derived;
92 
93  public:
94  typedef typename Parent::container container;
95  typedef typename Parent::reference reference;
96  typedef typename Parent::index_param index_param;
97  typedef typename Parent::value_param value_param;
98 
99  static boost::python::list get (container &, index_param);
100  // Version to return only the mapped type
101 
102  static boost::python::list keys( container & );
103 
104  static void assign (container &, index_param, value_param);
105  static void insert (container &, index_param, value_param);
106 
107  template<typename PythonClass, typename Policy>
108  static void visit_container_class( PythonClass &pyClass, Policy const &policy)
109  {
110  ContainerTraits::visit_container_class (pyClass, policy);
111  pyClass.def( "keys", &self_type::keys );
112 
113  typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type;
114  mapping::register_value_type< PythonClass, value_type, Policy >( pyClass );
115  //now we can expose iterators functionality
116  pyClass.def( "__iter__", python::iterator< BOOST_DEDUCED_TYPENAME most_derived::container >() );
117 
118  }
119 
120  };
121 
122  template<
123  class Container,
124  method_set_type MethodMask = all_methods,
125  class Traits = multimap_traits<Container>
126  >
128  : container_suite<Container, MethodMask, multimap_algorithms<Traits> >
129  {
130  };
131 
133  // Index into a container (multimap version)
135 
136  template<typename ContainerTraits, typename Ovr>
137  boost::python::list
138  multimap_algorithms<ContainerTraits, Ovr>::get (container &c, index_param ix)
139  {
140  boost::python::list l;
141  typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type;
142  for( iter_type index = c.lower_bound( ix ); index != c.upper_bound( ix ); ++index ){
143  boost::python::object v( index->second );
144  l.append( v );
145  }
146  return l;
147  }
148 
149  template<typename ContainerTraits, typename Ovr>
150  boost::python::list
152  {
153  boost::python::list _keys;
154  //For some reason code with set could not be compiled
155  //std::set< key_param > unique_keys;
156  typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type;
157  for( iter_type index = most_derived::begin(c); index != most_derived::end(c); ++index ){
158  //if( unique_keys.end() == unique_keys.find( index->first ) ){
159  // unique_keys.insert( index->first );
160  if( !_keys.count( index->first ) ){
161  _keys.append( index->first );
162  }
163  //}
164  }
165 
166  return _keys;
167  }
168 
169 
171  // Assign a value at a particular index (map version)
173 
174  template<typename ContainerTraits, typename Ovr>
175  void
177  container &c, index_param ix, value_param val)
178  {
179  typedef std::pair<
180  BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type
181  , BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type>
182  pair_type;
183 
184  // Can't use std::make_pair, because param types may be references
185  c.insert (pair_type (ix, val));
186  }
187 
188 
190  // Insert a new key, value pair into a map
192 
193  template<typename ContainerTraits, typename Ovr>
194  void
196  container &c, index_param ix, value_param val)
197  {
198  typedef std::pair
199  <BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type,
200  BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type>
201  pair_type;
202 
203  // Can't use std::make_pair, because param types may be references
204  c.insert (pair_type (ix, val) );
205  }
206 } } }
207 
208 #endif // BOOST_PYTHON_INDEXING_MULTIMAP_HPP
209 
210 
211 
Definition: algorithms.hpp:128
Definition: multimap.hpp:127
Definition: python_CEGUI.h:11
Definition: container_traits.hpp:59
Definition: container_suite.hpp:42
Definition: multimap.hpp:35