Crazy Eddie's GUI System  ${CEGUI_VERSION}
element_proxy.hpp
1 // This file has been generated by Py++.
2 
3 // Header file element_proxy.hpp
4 //
5 // Proxy objects for invidivual elements in a container wrapped by
6 // container_proxy
7 //
8 // Copyright (c) 2003 Raoul M. Gough
9 //
10 // Use, modification and distribution is subject to the Boost Software
11 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
12 // at http://www.boost.org/LICENSE_1_0.txt)
13 //
14 // History
15 // =======
16 // 2003/ 9/15 rmg File creation from container_proxy.hpp
17 // 2008/12/08 Roman Change indexing suite layout
18 //
19 // $Id: element_proxy.hpp,v 1.1.2.10 2003/12/03 12:18:51 raoulgough Exp $
20 //
21 
22 #ifndef BOOST_PYTHON_INDEXING_ELEMENT_PROXY_HPP
23 #define BOOST_PYTHON_INDEXING_ELEMENT_PROXY_HPP
24 
25 #include <indexing_suite/shared_proxy_impl.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/get_pointer.hpp>
28 #include <boost/utility/addressof.hpp>
29 #include <boost/detail/workaround.hpp>
30 
31 namespace boost { namespace python { namespace indexing {
32  template<typename ContainerProxy>
34  {
35  public:
36  typedef typename ContainerProxy::shared_proxy proxy_type;
37  typedef typename ContainerProxy::raw_value_type raw_value_type;
38  typedef typename ContainerProxy::size_type size_type;
39  typedef boost::shared_ptr<proxy_type> proxy_pointer;
40 
41  typedef typename proxy_type::value_type value_type;
42  typedef typename proxy_type::reference reference;
43  typedef typename proxy_type::pointer pointer;
44  typedef typename proxy_type::iterator_category iterator_category;
45  typedef typename proxy_type::difference_type difference_type;
46 
47  typedef value_type element_type; // Alias for register_ptr_to_python
48 
49  element_proxy () : m_ptr () { }
50  explicit element_proxy (proxy_type *ptr) : m_ptr (ptr) { }
51  explicit element_proxy (proxy_pointer const &ptr) : m_ptr (ptr) { }
52 
53  explicit element_proxy (raw_value_type const &val)
54  : m_ptr (new proxy_type(val))
55  {
56  // Create new standalone value (i.e. detached)
57  }
58 
59  reference operator* () const { return m_ptr->operator*(); }
60  pointer operator-> () const { return (*m_ptr).operator->(); }
61  pointer get () const { return operator->(); } // Alias for pointer_holder
62 
63  // Implicit conversion to raw_value_type
64  operator reference () const { return operator*(); }
65 
66 #if BOOST_WORKAROUND (BOOST_MSVC, <= 1200)
67  // The implicit conversion doesn't work on MSVC6, so help it along
68  // a little.
69  bool operator== (value_type const &val) const { return (**this) == val; }
70  bool operator!= (value_type const &val) const { return (**this) != val; }
71  bool operator< (value_type const &val) const { return (**this) < val; }
72  bool operator> (value_type const &val) const { return (**this) > val; }
73 #endif
74 
75  element_proxy &operator= (value_type const &copy)
76  {
77  proxy_type &proxy = *m_ptr;
78  ContainerProxy *container = proxy.owner();
79  size_type index = proxy.index();
80 
81  if (container)
82  {
83  container->replace (index, copy);
84  // Proxy was attached before, but is now detached. Make sure
85  // we now refer to the new element, instead of the detached
86  // copy of the old element
87  m_ptr = container->at (index).m_ptr;
88 
89  // Note: in the special case that this we and the container
90  // proxy itself have the only references to the
91  // shared_proxy_impl, it is not necessary to first detach
92  // the proxy. Maybe best to implement when changing to
93  // intrusive_ptr instead of shared_ptr.
94  }
95 
96  else
97  {
98  *proxy = copy;
99  }
100 
101  return *this;
102  }
103 
104  element_proxy &operator= (element_proxy const &copy)
105  {
106  // Required to make sorting a container_proxy work
107  return (*this) = *copy;
108  }
109 
110  size_t use_count() const { return m_ptr.use_count(); } // For debugging
111 
112  private:
113  proxy_pointer m_ptr;
114  };
115 
116  template<typename ContainerProxy>
118  {
119  public:
121  typedef typename base_type::proxy_type proxy_type;
122  typedef typename base_type::proxy_pointer proxy_pointer;
123  typedef typename base_type::raw_value_type raw_value_type;
124 
125  typedef typename proxy_type::value_type const value_type;
126  typedef value_type &reference;
127  typedef value_type *pointer;
128  typedef typename base_type::iterator_category iterator_category;
129  typedef typename base_type::difference_type difference_type;
130 
131  const_element_proxy () : m_base () { }
132  explicit const_element_proxy (proxy_type *ptr) : m_base (ptr) { }
133 
134  explicit const_element_proxy (proxy_pointer const &ptr) : m_base (ptr) {}
135 
137  : m_base (copy.m_base)
138  {
139  }
140 
142  : m_base (copy)
143  {
144  }
145 
146  explicit const_element_proxy (raw_value_type const &val)
147  : m_base (new proxy_type(val))
148  {
149  }
150 
151  reference operator* () const { return *m_base; }
152  pointer operator-> () const { return m_base.operator->(); }
153 
154  // Implicit conversion to raw_value_type const &
155  operator reference () const { return *m_base; }
156 
157 #if BOOST_WORKAROUND (BOOST_MSVC, <= 1200)
158  // The implicit conversion doesn't work on MSVC6, so help it along
159  // a little.
160  bool operator== (value_type const &val) const { return m_base == val; }
161  bool operator!= (value_type const &val) const { return m_base != val; }
162  bool operator< (value_type const &val) const { return m_base < val; }
163  bool operator> (value_type const &val) const { return m_base > val; }
164 #endif
165 
166  size_t use_count() const { return m_base.use_count(); } // For debugging
167 
168  private:
169  base_type m_base;
170  };
171 
172 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
173 }} // namespace python::indexing
174 #endif
175 
176  template<typename ContainerProxy>
177  typename ContainerProxy::raw_value_type *
178  get_pointer (python::indexing::element_proxy<ContainerProxy> const &proxy)
179  {
180  return ::boost::addressof (*proxy);
181  }
182 
183 #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
184  // Don't hide these other get_pointer overloads
185  using boost::get_pointer;
186 }} // namespace python::indexing
187 #endif
188 }
189 
190 #endif // BOOST_PYTHON_INDEXING_ELEMENT_PROXY_HPP
191 
192 
193 
Definition: python_CEGUI.h:9
Definition: element_proxy.hpp:33
Definition: element_proxy.hpp:117