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
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #ifndef STLSOFT_INCL_H_STLSOFT
00062 # include "stlsoft.h"
00063 #endif
00064 #ifndef STLSOFT_INCL_H_STLSOFT_CONSTRAINTS
00065 # include "stlsoft_constraints.h"
00066 #endif
00067
00068
00069
00070
00071
00072 #ifndef _STLSOFT_NO_NAMESPACE
00073 namespace stlsoft
00074 {
00075 #endif
00076
00077
00078
00079
00080
00083 template <ss_typename_param_k T>
00084 class array_proxy
00085 {
00086 public:
00087 typedef T value_type;
00088 typedef array_proxy<T> class_type;
00089 typedef value_type *pointer;
00090 typedef value_type *const_pointer;
00091 typedef value_type *iterator;
00092 typedef value_type *const_iterator;
00093 typedef value_type &reference;
00094 typedef value_type &const_reference;
00095 typedef ss_size_t size_type;
00096
00099 public:
00100 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00105 template <ss_typename_param_k D>
00106 array_proxy(array_proxy<D> const &d)
00107 : m_begin(d.begin())
00108 , m_end(d.end())
00109 {
00110
00111
00112
00113 stlsoft_constraint_must_have_base(D, T);
00114
00115
00116 stlsoft_constraint_must_be_same_size(D, T);
00117 }
00118
00119 # ifdef __STLSOFT_CF_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT
00123 template <ss_typename_param_k D, ss_size_t N>
00124 ss_explicit_k array_proxy(D (&d)[N])
00125 : m_begin(&d[0])
00126 , m_end(&d[N])
00127 {
00128
00129
00130
00131 stlsoft_constraint_must_have_base(D, T);
00132
00133
00134 stlsoft_constraint_must_be_same_size(D, T);
00135 }
00136
00140 # if defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00141 template <ss_size_t N>
00142 ss_explicit_k array_proxy(T (&t)[N])
00143 : m_begin(&t[0])
00144 , m_end(&t[N])
00145 {}
00146 # endif
00147 # endif
00148 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00149
00154 #if !defined(__STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00155 defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00156 array_proxy(pointer begin, pointer end)
00157 : m_begin(begin)
00158 , m_end(end)
00159 {}
00160 #endif
00161
00162 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00167 template <ss_typename_param_k D>
00168 array_proxy(D *begin, D *end)
00169 : m_begin(begin)
00170 , m_end(end)
00171 {
00172
00173
00174
00175 stlsoft_constraint_must_have_base(D, T);
00176
00177
00178 stlsoft_constraint_must_be_same_size(D, T);
00179 }
00180 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00181
00182 #if !defined(__STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00183 defined(STLSOFT_CF_NON_TEMPLATE_CTOR_REQUIRED_WITH_TEMPLATE_CTOR)
00188 array_proxy(pointer p, ss_size_t n)
00189 : m_begin(p)
00190 , m_end(p + n)
00191 {}
00192 #endif
00193
00194 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00199 template <ss_typename_param_k D>
00200 array_proxy(D *p, ss_size_t n)
00201 : m_begin(p)
00202 , m_end(p + n)
00203 {
00204
00205
00206
00207 stlsoft_constraint_must_have_base(D, T);
00208
00209
00210 stlsoft_constraint_must_be_same_size(D, T);
00211 }
00212 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00213
00214
00217 public:
00220 pointer base()
00221 {
00222 return m_begin;
00223 }
00226 pointer base() const
00227 {
00228 return m_begin;
00229 }
00231 size_type size() const
00232 {
00233 return m_end - m_begin;
00234 }
00236 ss_bool_t empty() const
00237 {
00238 return m_begin == m_end;
00239 }
00241 static size_type max_size()
00242 {
00243 return static_cast<size_type>(-1) / sizeof(value_type);
00244 }
00246
00249 public:
00254 reference operator [](ss_size_t index)
00255 {
00256 stlsoft_message_assert("index out of bounds, in array_proxy", !(size() < index));
00257
00258 return m_begin[index];
00259 }
00264 const_reference operator [](ss_size_t index) const
00265 {
00266 stlsoft_message_assert("index out of bounds, in array_proxy", !(size() < index));
00267
00268 return const_cast<pointer>(m_begin)[index];
00269 }
00271
00274 public:
00278 iterator begin()
00279 {
00280 return m_begin;
00281 }
00285 iterator end()
00286 {
00287 return m_end;
00288 }
00292 const_iterator begin() const
00293 {
00294 return m_begin;
00295 }
00299 const_iterator end() const
00300 {
00301 return m_end;
00302 }
00304
00305
00306 private:
00307 pointer const m_begin;
00308 pointer const m_end;
00309
00310
00311 private:
00312 array_proxy &operator =(array_proxy const &);
00313 };
00314
00315 #ifdef __STLSOFT_CF_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT
00316 template <ss_typename_param_k T, ss_size_t N>
00317 inline array_proxy<T> make_array_proxy(T (&t)[N])
00318 {
00319 return array_proxy<T>(&t[0], &t[N]);
00320
00321 }
00322 #endif
00323
00324 template <ss_typename_param_k T>
00325 inline array_proxy<T> make_array_proxy(T *begin, T *end)
00326 {
00327 return array_proxy<T>(begin, end);
00328 }
00329
00330 template <ss_typename_param_k T>
00331 inline array_proxy<T> make_array_proxy(T *p, ss_size_t n)
00332 {
00333 return array_proxy<T>(p, n);
00334 }
00335
00337
00338
00339 #ifdef STLSOFT_UNITTEST
00340
00341 namespace unittest
00342 {
00343 ss_bool_t test_stlsoft_array_proxy(unittest_reporter *r)
00344 {
00345 ss_bool_t bSuccess = true;
00346
00347 unittest_initialiser init(r, "STLSoft", "array_proxy", __FILE__);
00348
00349 #if 0
00350 if(<<TODO>>)
00351 {
00352 r->report("<<TODO>> failed ", __LINE__);
00353 bSuccess = false;
00354 }
00355 #endif
00356
00357 return bSuccess;
00358 }
00359
00360 unittest_registrar unittest_stlsoft_array_proxy(test_stlsoft_array_proxy);
00361
00362 }
00363
00364 #endif
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376