00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00050 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY
00051 #define STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY
00052
00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00054 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY_MAJOR 4
00055 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY_MINOR 0
00056 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY_REVISION 4
00057 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_ARRAY_PROXY_EDIT 57
00058 #endif
00059
00060
00061
00062
00063
00064 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00065 # include <stlsoft/stlsoft.h>
00066 #endif
00067 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS
00068 # include <stlsoft/util/constraints.hpp>
00069 #endif
00070 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00071 # include <stlsoft/collections/util/collections.hpp>
00072 #endif
00073
00074
00075
00076
00077
00078 #ifndef _STLSOFT_NO_NAMESPACE
00079 namespace stlsoft
00080 {
00081 #endif
00082
00083
00084
00085
00086
00095 template <ss_typename_param_k T>
00096 class array_proxy
00097 : public stl_collection_tag
00098 {
00099 public:
00100 typedef T value_type;
00101 typedef array_proxy<T> class_type;
00102 typedef value_type* pointer;
00103 typedef value_type* const_pointer;
00104 typedef value_type* iterator;
00105 typedef value_type* const_iterator;
00106 typedef value_type& reference;
00107 typedef value_type& const_reference;
00108 typedef ss_size_t size_type;
00109
00112 public:
00113 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00118 template <ss_typename_param_k D>
00119 array_proxy(array_proxy<D> &d)
00120 : m_begin(d.begin())
00121 , m_end(d.end())
00122 {
00123
00124
00125
00126 stlsoft_constraint_must_have_base(D, T);
00127
00128
00129 stlsoft_constraint_must_be_same_size(D, T);
00130 }
00131
00132 # ifdef STLSOFT_CF_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT
00136 template <ss_typename_param_k D, ss_size_t N>
00137 ss_explicit_k array_proxy(D (&d)[N])
00138 : m_begin(&d[0])
00139 , m_end(&d[N])
00140 {
00141
00142
00143
00144 stlsoft_constraint_must_have_base(D, T);
00145
00146
00147 stlsoft_constraint_must_be_same_size(D, T);
00148 }
00149
00153 # if defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00154 template <ss_size_t N>
00155 ss_explicit_k array_proxy(T (&t)[N])
00156 : m_begin(&t[0])
00157 , m_end(&t[N])
00158 {}
00159 # endif
00160 # endif
00161 #endif // STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00162
00167 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00168 defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00169 array_proxy(pointer begin, pointer end)
00170 : m_begin(begin)
00171 , m_end(end)
00172 {}
00173 #endif
00174
00175 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00180 template <ss_typename_param_k D>
00181 array_proxy(D *b, D *e)
00182 : m_begin(b)
00183 , m_end(e)
00184 {
00185
00186
00187
00188 stlsoft_constraint_must_have_base(D, T);
00189
00190
00191 stlsoft_constraint_must_be_same_size(D, T);
00192 }
00193 #endif // STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00194
00195 #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00196 defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00201 array_proxy(pointer p, ss_size_t n)
00202 : m_begin(p)
00203 , m_end(p + n)
00204 {}
00205 #endif
00206
00207 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00212 template <ss_typename_param_k D>
00213 array_proxy(D *p, ss_size_t n)
00214 : m_begin(p)
00215 , m_end(p + n)
00216 {
00217
00218
00219
00220 stlsoft_constraint_must_have_base(D, T);
00221
00222
00223 stlsoft_constraint_must_be_same_size(D, T);
00224 }
00225 #endif // STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00227
00230 public:
00233 pointer base()
00234 {
00235 return m_begin;
00236 }
00239 pointer base() const
00240 {
00241 return m_begin;
00242 }
00244 size_type size() const
00245 {
00246 return m_end - m_begin;
00247 }
00249 ss_bool_t empty() const
00250 {
00251 return m_begin == m_end;
00252 }
00254 static size_type max_size()
00255 {
00256 return static_cast<size_type>(-1) / sizeof(value_type);
00257 }
00259
00262 public:
00267 reference operator [](ss_size_t index)
00268 {
00269 STLSOFT_MESSAGE_ASSERT("index out of bounds, in array_proxy", !(size() < index));
00270
00271 return m_begin[index];
00272 }
00277 const_reference operator [](ss_size_t index) const
00278 {
00279 STLSOFT_MESSAGE_ASSERT("index out of bounds, in array_proxy", !(size() < index));
00280
00281 return const_cast<pointer>(m_begin)[index];
00282 }
00284
00287 public:
00291 iterator begin()
00292 {
00293 return m_begin;
00294 }
00298 iterator end()
00299 {
00300 return m_end;
00301 }
00305 const_iterator begin() const
00306 {
00307 return m_begin;
00308 }
00312 const_iterator end() const
00313 {
00314 return m_end;
00315 }
00317
00318
00319 private:
00320 pointer const m_begin;
00321 pointer const m_end;
00322
00323
00324 private:
00325 array_proxy& operator =(array_proxy const&);
00326 };
00327
00328
00329
00330
00331
00332 #ifdef STLSOFT_CF_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT
00333 template <ss_typename_param_k T, ss_size_t N>
00334 inline array_proxy<T> make_array_proxy(T (&t)[N])
00335 {
00336 return array_proxy<T>(&t[0], &t[N]);
00337
00338 }
00339 #endif
00340
00341 template <ss_typename_param_k T>
00342 inline array_proxy<T> make_array_proxy(T *begin, T *end)
00343 {
00344 return array_proxy<T>(begin, end);
00345 }
00346
00347 template <ss_typename_param_k T>
00348 inline array_proxy<const T> make_array_proxy(T const* begin, T const* end)
00349 {
00350 return array_proxy<const T>(begin, end);
00351 }
00352
00353 template <ss_typename_param_k T>
00354 inline array_proxy<T> make_array_proxy(T *p, ss_size_t n)
00355 {
00356 return array_proxy<T>(p, n);
00357 }
00358
00359 #if 0
00360 template <ss_typename_param_k T>
00361 inline array_proxy<const T> make_array_proxy(T const* p, ss_size_t n)
00362 {
00363 return array_proxy<const T>(p, n);
00364 }
00365 #endif
00366
00368
00369
00370 #ifdef STLSOFT_UNITTEST
00371 # include "./unittest/array_proxy_unittest_.h"
00372 #endif
00373
00374
00375
00376 #ifndef _STLSOFT_NO_NAMESPACE
00377 }
00378 #endif
00379
00380
00381
00382 #endif
00383
00384