Crazy Eddie's GUI System  ${CEGUI_VERSION}
int_slice_helper.hpp
1 // This file has been generated by Py++.
2 
3 // Copyright (c) 2003 Raoul M. Gough
4 //
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
7 // at http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // Header file int_slice_helper.hpp
10 //
11 // History
12 // =======
13 // 2003/10/13 rmg File creation
14 // 2008/12/08 Roman Change indexing suite layout
15 //
16 // $Id: int_slice_helper.hpp,v 1.1.2.10 2004/02/08 18:57:42 raoulgough Exp $
17 //
18 
19 #ifndef BOOST_PYTHON_INDEXING_INT_SLICE_HELPER_HPP
20 #define BOOST_PYTHON_INDEXING_INT_SLICE_HELPER_HPP
21 
22 # include <boost/python/errors.hpp>
23 # include <indexing_suite/workaround.hpp>
24 
25 namespace boost { namespace python { namespace indexing {
26  template<typename Algorithms, typename SliceType>
28  {
29  // Works with a SliceType that provides an int-like index_type
30  // that is convertible to the algorithm's index_param
31 
32  typedef Algorithms algorithms_type;
33  typedef SliceType slice_type;
34 
35  typedef typename algorithms_type::container container;
36  typedef typename algorithms_type::reference reference;
37  typedef typename algorithms_type::value_param value_param;
38  typedef typename algorithms_type::container_traits container_traits;
39  typedef typename slice_type::index_type index_type;
40 
41  int_slice_helper (container &c, slice_type const &);
42 
43  bool next();
44 
45  reference current () const;
46  void write (value_param val);
47  void erase_remaining () const;
48 
49  private:
50  void assign (value_param val) const;
51  void insert (value_param val);
52 
53  private:
54  slice_type m_slice;
55  container *m_ptr;
56  index_type m_pos;
57  };
58 
59  template<typename Algorithms, typename SliceType>
61  ::int_slice_helper (container &c, slice_type const &sl)
62  : m_slice (sl),
63  m_ptr (&c),
64  m_pos (-1)
65  {
66  }
67 
68  template<typename Algorithms, typename SliceType>
69  bool
71  {
72  bool result = false; // Assume the worst
73 
74  if (m_pos == -1)
75  {
76  // First time call - get to start of the slice (if any)
77  m_pos = m_slice.start();
78  result = m_slice.in_range (m_pos);
79  }
80 
81  else if (m_slice.in_range (m_pos))
82  {
83  // Subsequent calls - advance by the slice's stride
84  m_pos += m_slice.step();
85  result = m_slice.in_range (m_pos);
86  }
87 
88  return result;
89  }
90 
91  template<typename Algorithms, typename SliceType>
92  typename int_slice_helper<Algorithms, SliceType>::reference
94  {
95  return algorithms_type::get (*m_ptr, m_pos);
96  }
97 
98  template<typename Algorithms, typename SliceType>
100  {
101  if (next())
102  {
103  assign (val);
104  }
105 
106  else
107  {
108  insert (val);
109  }
110  }
111 
112  template<typename Algorithms, typename SliceType>
113  void int_slice_helper<Algorithms, SliceType>::assign (value_param val) const
114  {
115  algorithms_type::assign (*m_ptr, m_pos, val);
116  }
117 
118  namespace detail {
119  template<bool doit> struct maybe_insert {
120 
121  // NOTE: use the name "apply_" instead of "apply" to avoid
122  // weirdo compiler crash in mpl/aux_/apply.hpp on MSVC7. Don't
123  // even ask how I arrived at this fix :-)
124 
125  template<class Algorithms>
126  static void apply_(
127 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
128  // Can't explicitly instantiate member function - must let
129  // the compiler deduce the argument type from a dummy
130  // parameter. Same applies throughout
131  Algorithms *,
132 # endif
133  typename Algorithms::container &,
134  typename Algorithms::index_param,
135  typename Algorithms::value_param)
136  {
137  PyErr_SetString(
138  PyExc_TypeError,
139  "container does not support insertion into slice");
140 
141  boost::python::throw_error_already_set ();
142  }
143  };
144 
145  template<> struct maybe_insert<true> {
146  template<class Algorithms>
147  static void apply_(
148 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
149  Algorithms *,
150 # endif
151  typename Algorithms::container &c,
152  typename Algorithms::index_param i,
153  typename Algorithms::value_param v)
154  {
155  Algorithms::insert (c, i, v);
156  }
157  };
158  }
159 
160  template<typename Algorithms, typename SliceType>
162  {
163  if (m_slice.step() != 1)
164  {
165  PyErr_SetString(
166  PyExc_ValueError, "attempt to insert via extended slice");
167 
168  boost::python::throw_error_already_set ();
169  }
170 
171  else
172  {
175  container_traits::supported_methods, method_insert>::value>::
176 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
177  apply_ (static_cast<Algorithms *>(0),
178 # else
179  BOOST_NESTED_TEMPLATE apply_ <Algorithms>(
180 # endif
181  *m_ptr, m_pos, val);
182 
183  ++m_pos; // Advance for any subsequent inserts
184  }
185  }
186 
187  namespace detail {
188  template<bool doit> struct maybe_erase {
189  template<class Algorithms>
190  static void apply_(
191 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
192  Algorithms *,
193 # endif
194  typename Algorithms::container &,
195  typename Algorithms::index_param,
196  typename Algorithms::index_param)
197  {
198  PyErr_SetString(
199  PyExc_TypeError, "container does not support item deletion");
200 
201  boost::python::throw_error_already_set ();
202  }
203  };
204 
205  template<> struct maybe_erase<true> {
206  template<class Algorithms>
207  static void apply_(
208 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
209  Algorithms *,
210 # endif
211  typename Algorithms::container &c,
212  typename Algorithms::index_param from,
213  typename Algorithms::index_param to)
214  {
215  Algorithms::erase_range (c, from, to);
216  }
217  };
218  }
219 
220  template<typename Algorithms, typename SliceType>
222  {
223  if (m_slice.step() != 1)
224  {
225  PyErr_SetString(
226  PyExc_ValueError, "attempt to delete via extended slice");
227 
228  boost::python::throw_error_already_set ();
229  }
230 
231  else
232  {
235  container_traits::supported_methods, method_delitem>::value>::
236 
237 # if defined (BOOST_NO_MEMBER_TEMPLATES) && defined (BOOST_MSVC6_MEMBER_TEMPLATES)
238  apply_ (static_cast<Algorithms *>(0),
239 # else
240  BOOST_NESTED_TEMPLATE apply_ <Algorithms>(
241 # endif
242  *m_ptr, m_pos, m_slice.stop());
243  }
244  }
245 
246 } } }
247 
248 #endif // BOOST_PYTHON_INDEXING_INT_SLICE_HELPER_HPP
249 
250 
251 
Definition: python_CEGUI.h:11
Definition: int_slice_helper.hpp:188
Definition: int_slice_helper.hpp:119
Definition: int_slice_helper.hpp:27