00001
00002
00008 #if !defined(__ads_StaticArrayOfArrays_h__)
00009 #define __ads_StaticArrayOfArrays_h__
00010
00011
00012 #if defined(DEBUG_ads) && !defined(DEBUG_StaticArrayOfArrays)
00013 #define DEBUG_StaticArrayOfArrays
00014 #endif
00015
00016 #include "Array.h"
00017
00018 BEGIN_NAMESPACE_ADS
00019
00021
00024 template<typename T = double>
00025 class StaticArrayOfArrays :
00026 public ArrayContainer<T> {
00027
00028
00029
00030
00031
00032 private:
00033
00034 typedef ArrayTypes<T> Types;
00035 typedef ArrayContainer<T> Base;
00036
00037
00038
00039
00040
00041 public:
00042
00044 typedef typename Types::value_type value_type;
00046
00049 typedef typename Types::parameter_type parameter_type;
00051
00054 typedef typename Types::unqualified_value_type unqualified_value_type;
00055
00057 typedef typename Types::pointer pointer;
00059 typedef typename Types::const_pointer const_pointer;
00060
00062 typedef typename Types::iterator iterator;
00064 typedef typename Types::const_iterator const_iterator;
00065
00067 typedef typename Types::reference reference;
00069 typedef typename Types::const_reference const_reference;
00070
00072
00078 typedef typename Types::size_type size_type;
00080 typedef typename Types::difference_type difference_type;
00081
00082
00083
00084
00085
00086 private:
00087
00089 Array<1,iterator> _pointers;
00090
00091 public:
00092
00093
00095
00096
00098 StaticArrayOfArrays() :
00099 Base(),
00100 _pointers(1) {
00101
00102 _pointers[0] = Base::begin();
00103 }
00104
00106 template<typename IntForwardIter, typename ValueForwardIter>
00107 StaticArrayOfArrays(IntForwardIter sizesBeginning, IntForwardIter sizesEnd,
00108 ValueForwardIter valuesBeginning,
00109 ValueForwardIter valuesEnd);
00110
00112 template<typename IntForwardIter>
00113 void
00114 rebuild(const size_type numberOfElements,
00115 IntForwardIter sizesBeginning, IntForwardIter sizesEnd);
00116
00118 template<typename IntForwardIter, typename ValueForwardIter>
00119 void
00120 rebuild(IntForwardIter sizesBeginning, IntForwardIter sizesEnd,
00121 ValueForwardIter valuesBeginning, ValueForwardIter valuesEnd) {
00122 rebuild(std::distance(valuesBeginning, valuesEnd), sizesBeginning,
00123 sizesEnd);
00124 std::copy(valuesBeginning, valuesEnd, begin());
00125 }
00126
00128 StaticArrayOfArrays(const StaticArrayOfArrays& other) :
00129 Base(other),
00130 _pointers(other._pointers) {
00131 _pointers += begin() - other.begin();
00132 }
00133
00135 ~StaticArrayOfArrays()
00136 {}
00137
00138
00139
00141
00142
00144 StaticArrayOfArrays&
00145 operator=(const StaticArrayOfArrays& other) {
00146 if (&other != this) {
00147 Base::operator=(other);
00148 _pointers = other._pointers;
00149 _pointers += begin() - other.begin();
00150 }
00151 return *this;
00152 }
00153
00154
00155
00157
00158
00160 size_type
00161 getNumberOfArrays() const {
00162 return _pointers.size() - 1;
00163 }
00164
00165
00167
00168 size_type
00169 size() const {
00170 return Base::size();
00171 }
00172
00174 using Base::empty;
00175
00177 using Base::max_size;
00178
00180 size_type
00181 getMemoryUsage() const {
00182 return Base::getMemoryUsage() + _pointers.getMemoryUsage();
00183 }
00184
00185
00187
00189 const_iterator
00190 begin() const {
00191 return Base::begin();
00192 }
00193
00194
00196
00197 const_iterator
00198 end() const {
00199 return Base::end();
00200 }
00201
00202
00203
00205
00206
00208 size_type
00209 size(const int n) const {
00210 return size_type(_pointers[n + 1] - _pointers[n]);
00211 }
00212
00214 bool
00215 empty(const int n) const {
00216 return size(n) == 0;
00217 }
00218
00220 const_iterator
00221 begin(const int n) const {
00222 return _pointers[n];
00223 }
00224
00226 const_iterator
00227 end(const int n) const {
00228 return _pointers[n + 1];
00229 }
00230
00231
00233 const_iterator
00234 operator[](const int n) const {
00235 return begin(n);
00236 }
00237
00239 const_iterator
00240 operator()(const int n) const {
00241 return operator[](n);
00242 }
00243
00245 parameter_type
00246 operator()(const int n, const int m) const {
00247 #ifdef DEBUG_StaticArrayOfArrays
00248 assert(0 <= m && m < size(n));
00249 #endif
00250 return *(begin(n) + m);
00251 }
00252
00253
00254
00256
00257
00258
00260
00262 iterator
00263 begin() {
00264 return Base::begin();
00265 }
00266
00267
00269
00270 iterator
00271 end() {
00272 return Base::end();
00273 }
00274
00276 using Base::negate;
00277
00279 void
00280 swap(StaticArrayOfArrays& other) {
00281 if (&other != this) {
00282 Base::swap(other);
00283 _pointers.swap(other._pointers);
00284 }
00285 }
00286
00288 void
00289 clear() {
00290 Base::resize(0);
00291 _pointers.resize(1);
00292 _pointers[0] = begin();
00293 }
00294
00295
00296
00298
00299
00301 iterator
00302 begin(const int n) {
00303 return _pointers[n];
00304 }
00305
00307 iterator
00308 end(const int n) {
00309 return _pointers[n + 1];
00310 }
00311
00313 iterator
00314 operator[](const int n) {
00315 return begin(n);
00316 }
00317
00319 iterator
00320 operator()(const int n) {
00321 return operator[](n);
00322 }
00323
00325 reference
00326 operator()(const int n, const int m) {
00327 #ifdef DEBUG_StaticArrayOfArrays
00328 assert(0 <= m && m < size(n));
00329 #endif
00330 return *(begin(n) + m);
00331 }
00332
00333
00334
00336
00337
00339 StaticArrayOfArrays&
00340 operator=(parameter_type x) {
00341 Base::operator=(x);
00342 return *this;
00343 }
00344
00345
00346
00348
00349
00351 bool
00352 operator==(const StaticArrayOfArrays<T>& x) const {
00353 if (Base::operator!=(x)) {
00354 return false;
00355 }
00356 for (int n = 0; n != getNumberOfArrays(); ++n) {
00357 if (size(n) != x.size(n)) {
00358 return false;
00359 }
00360 }
00361 return true;
00362 }
00363
00365 bool
00366 operator!=(const StaticArrayOfArrays<T>& x) const {
00367 return ! operator==(x);
00368 }
00369
00370
00371
00373
00374
00376 void
00377 put(std::ostream& out) const;
00378
00380 void
00381 get(std::istream& in);
00382
00383
00384 };
00385
00386
00387
00388
00389
00391
00403 template<typename T>
00404 inline
00405 std::ostream&
00406 operator<<(std::ostream& out, const StaticArrayOfArrays<T>& x) {
00407 x.put(out);
00408 return out;
00409 }
00410
00412
00424 template<typename T>
00425 inline
00426 std::istream&
00427 operator>>(std::istream& in, StaticArrayOfArrays<T>& x) {
00428 x.get(in);
00429 return in;
00430 }
00431
00432 END_NAMESPACE_ADS
00433
00434 #define __StaticArrayOfArrays_ipp__
00435 #include "StaticArrayOfArrays.ipp"
00436 #undef __StaticArrayOfArrays_ipp__
00437
00438 #endif