00001
00002
00008 #if !defined(__ads_Array_h__)
00009 #define __ads_Array_h__
00010
00011
00012 #if defined(DEBUG_ads) && !defined(DEBUG_Array)
00013 #define DEBUG_Array
00014 #endif
00015
00016 #ifdef DEBUG_Array
00017 #ifndef DEBUG_ArrayContainer
00018 #define DEBUG_ArrayContainer
00019 #endif
00020 #ifndef DEBUG_ArrayIndexing
00021 #define DEBUG_ArrayIndexing
00022 #endif
00023 #endif
00024
00025 #include "ArrayContainer.h"
00026 #include "ArrayIndexing.h"
00027
00028 BEGIN_NAMESPACE_ADS
00029
00031
00037
00038 template<int N, typename T, bool A>
00039 class Array :
00040 public ArrayContainer<T,A>, public ArrayIndexing<N,T> {
00041 private:
00042
00043
00044
00045
00046
00047 typedef ArrayTypes<T> types;
00048 typedef ArrayContainer<T,A> container_base;
00049 typedef ArrayIndexing<N,T> indexing_base;
00050
00051 public:
00052
00053
00054
00055
00056
00058 typedef typename types::value_type value_type;
00060
00064 typedef typename types::parameter_type parameter_type;
00066
00069 typedef typename types::unqualified_value_type
00070 unqualified_value_type;
00071
00073 typedef typename types::pointer pointer;
00075 typedef typename types::const_pointer const_pointer;
00076
00078 typedef typename types::iterator iterator;
00080 typedef typename types::const_iterator const_iterator;
00081
00083 typedef typename types::reference reference;
00085 typedef typename types::const_reference const_reference;
00086
00088
00094 typedef typename types::size_type size_type;
00096 typedef typename types::difference_type difference_type;
00097
00099
00103 typedef typename Loki::Select< A || Loki::TypeTraits<value_type>::isConst,
00104 const void*, void* >::Result
00105 void_pointer;
00106
00108 typedef typename indexing_base::index_type index_type;
00110 typedef typename indexing_base::range_type range_type;
00111
00112 private:
00113
00115
00120 typedef typename Loki::Select< A || Loki::TypeTraits<value_type>::isConst,
00121 const_pointer, pointer >::Result
00122 pointer_parameter;
00123
00124 public:
00125
00126
00128
00129
00131 Array() :
00132 container_base(),
00133 indexing_base()
00134 {}
00135
00137
00141 Array(const Array& x) :
00142 container_base(x),
00143 indexing_base(x)
00144 {}
00145
00146
00151 template<typename T2, bool A2>
00152 Array(const Array<N,T2,A2>& x) :
00153 container_base(x),
00154 indexing_base(x.ranges(), data())
00155 {}
00156
00158
00162 Array&
00163 operator=(const Array& other) {
00164 container_base::operator=(other);
00165 indexing_base::rebuild(other.ranges(), data());
00166 return *this;
00167 }
00168
00170
00174 template<typename T2, bool A2>
00175 Array&
00176 operator=(const Array<N,T2,A2>& x) {
00177 container_base::operator=(x);
00178 indexing_base::rebuild(x.ranges(), data());
00179 return *this;
00180 }
00181
00182
00184
00187 explicit
00188 Array(const size_type extent0, const size_type extent1) :
00189 container_base(extent0 * extent1),
00190 indexing_base(index_type(extent0, extent1), container_base::data()) {
00191 LOKI_STATIC_CHECK(N == 2, Dimension_must_be_2);
00192 }
00193
00195
00198 explicit
00199 Array(const size_type extent0, const size_type extent1,
00200 const size_type extent2) :
00201 container_base(extent0 * extent1 * extent2),
00202 indexing_base(index_type(extent0, extent1, extent2),
00203 container_base::data()) {
00204 LOKI_STATIC_CHECK(N == 3, Dimension_must_be_3);
00205 }
00206
00207
00209 explicit
00210 Array(const index_type& extents) :
00211 container_base(computeProduct(extents)),
00212 indexing_base(extents, container_base::data())
00213 {}
00214
00216 explicit
00217 Array(const index_type& extents, parameter_type value) :
00218 container_base(computeProduct(extents)),
00219 indexing_base(extents, container_base::data()) {
00220 fill(value);
00221 }
00222
00224
00227 template<typename InputIterator>
00228 explicit
00229 Array(const index_type& extents, InputIterator first, InputIterator last) :
00230 container_base(first, last),
00231 indexing_base(extents, container_base::data()) {
00232 assert(computeProduct(extents) == size());
00233 }
00234
00235
00237 explicit
00238 Array(const range_type& ranges) :
00239 container_base(ranges.content()),
00240 indexing_base(ranges, container_base::data())
00241 {}
00242
00244 explicit
00245 Array(const range_type& ranges, const value_type value) :
00246 container_base(ranges.content()),
00247 indexing_base(ranges, container_base::data())
00248 {
00249 fill(value);
00250 }
00251
00253
00256 template<typename InputIterator>
00257 explicit
00258 Array(const range_type& ranges, InputIterator first, InputIterator last) :
00259 container_base(ranges.content()),
00260 indexing_base(ranges, container_base::data()) {
00261 copy(first, last);
00262 }
00263
00265 Array(const index_type& extents, const void_pointer data) :
00266 container_base(reinterpret_cast<pointer_parameter>(data),
00267 reinterpret_cast<pointer_parameter>(data) +
00268 computeProduct(extents)),
00269 indexing_base(extents, reinterpret_cast<pointer_parameter>(data))
00270 {}
00271
00273 void
00274 rebuild(const index_type& extents, const void_pointer data) {
00275 pointer d = reinterpret_cast<pointer_parameter>(data);
00276 container_base::rebuild(d, d + computeProduct(extents));
00277 indexing_base::rebuild(extents, d);
00278 }
00279
00281 Array(const range_type& ranges, const void_pointer data) :
00282 container_base(reinterpret_cast<pointer_parameter>(data),
00283 reinterpret_cast<pointer_parameter>(data) +
00284 ranges.content()),
00285 indexing_base(ranges, reinterpret_cast<pointer_parameter>(data))
00286 {}
00287
00289 void
00290 rebuild(const range_type& ranges, const void_pointer data) {
00291 container_base::rebuild(reinterpret_cast<pointer_parameter>(data),
00292 reinterpret_cast<pointer_parameter>(data) +
00293 ranges.content());
00294 indexing_base::rebuild(ranges,
00295 reinterpret_cast<pointer_parameter>(data));
00296 }
00297
00299 ~Array()
00300 {}
00301
00302
00303
00304 public:
00305
00306
00310
00311
00313 using container_base::size;
00314
00316 using container_base::empty;
00317
00319 using container_base::max_size;
00320
00322 using container_base::begin;
00323
00325 using container_base::end;
00326
00328
00333 using container_base::data;
00334
00336
00341 using container_base::operator[];
00342
00343
00344
00346
00347
00349 using indexing_base::rank;
00350
00351
00352
00356
00357
00359 using indexing_base::extents;
00360
00362 using indexing_base::extent;
00363
00365 using indexing_base::ranges;
00366
00368 using indexing_base::lbounds;
00369
00371 using indexing_base::ubounds;
00372
00374 using indexing_base::lbound;
00375
00377 using indexing_base::ubound;
00378
00380 using indexing_base::strides;
00381
00383 using indexing_base::root;
00384
00385
00386
00390
00391
00393 using indexing_base::operator();
00394
00396
00399
00400
00401
00402
00403
00404
00405
00406
00408
00411
00412
00413
00414
00415
00416
00417
00418
00419
00421
00424
00425
00426
00427
00428
00429
00430
00431
00432
00434
00437
00438
00439
00440
00441
00442
00443
00444
00445
00447
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00464
00465
00467 using indexing_base::index;
00468
00470 using indexing_base::index_to_indices;
00471
00472
00473
00475
00476
00478
00481 void
00482 iterator_to_indices(const const_iterator iter, int& i, int& j) const {
00483 index_to_indices(iter - begin(), i, j);
00484 }
00485
00487
00490 void
00491 iterator_to_indices(const const_iterator iter,
00492 int& i, int& j, int& k) const {
00493 index_to_indices(iter - begin(), i, j, k);
00494 }
00495
00497
00500 void
00501 iterator_to_indices(const const_iterator iter,
00502 ads::FixedArray<2,int>& multi_index) const {
00503 index_to_indices(iter - begin(), multi_index);
00504 }
00505
00507
00510 void
00511 iterator_to_indices(const const_iterator iter,
00512 ads::FixedArray<3,int>& multi_index) const {
00513 index_to_indices(iter - begin(), multi_index);
00514 }
00515
00516
00517
00519
00520
00522 size_type
00523 getMemoryUsage() const {
00524 return sizeof(Array) + sizeof(value_type) * size();
00525 }
00526
00527
00528
00532
00533
00535 using container_base::negate;
00536
00538 using container_base::fill;
00539
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00555
00556
00557
00558
00560
00561
00563 void
00564 swap(Array& x) {
00565 container_base::swap(x);
00566 indexing_base::swap(x);
00567 }
00568
00570 void
00571 resize(const index_type& ext);
00572
00574 void
00575 resize(const range_type& rng);
00576
00577
00578
00580
00581
00583 Array&
00584 operator=(parameter_type x) {
00585 container_base::operator=(x);
00586 return *this;
00587 }
00588
00589
00590
00592
00593
00595 void
00596 put(std::ostream& out) const {
00597 indexing_base::put(out);
00598 container_base::put(out);
00599 }
00600
00602 void
00603 get(std::istream& in) {
00604 get(in, Loki::Int2Type<A>());
00605 }
00606
00608
00617 void
00618 write(std::ostream& out) const {
00619 indexing_base::write(out);
00620 container_base::write(out);
00621 }
00622
00624
00633 void
00634 read(std::istream& in) {
00635 read(in, Loki::Int2Type<A>());
00636 }
00637
00639 void
00640 write_elements_ascii(std::ostream& out) const {
00641 container_base::write_elements_ascii(out);
00642 }
00643
00645 void
00646 write_elements_binary(std::ostream& out) const {
00647 container_base::write_elements_binary(out);
00648 }
00649
00651 void
00652 read_elements_ascii(std::istream& in) {
00653 container_base::read_elements_ascii(in);
00654 }
00655
00657 void
00658 read_elements_binary(std::istream& in) {
00659 container_base::read_elements_binary(in);
00660 }
00661
00662
00663
00665
00666
00667
00668 template<typename T2, bool A2>
00669 bool
00670 operator==(const Array<N,T2,A2>& x) const {
00671 return indexing_base::operator==(x) && container_base::operator==(x);
00672 }
00673
00674
00675
00676
00677
00678
00679
00680 private:
00681
00683
00686 void
00687 get(std::istream& in, Loki::Int2Type<true>);
00688
00690
00693 void
00694 get(std::istream& in, Loki::Int2Type<false>);
00695
00697
00700 void
00701 read(std::istream& in, Loki::Int2Type<true>);
00702
00704
00707 void
00708 read(std::istream& in, Loki::Int2Type<false>);
00709
00710 };
00711
00712
00713
00714
00715
00716
00717
00718 #if 0
00720
00721 template<int N, typename T1, typename T2, bool A1, bool A2>
00722 bool
00723 operator==(const Array<N,T1,A1>& x, const Array<N,T2,A2>& y) {
00724 return x.operator==(y);
00725 }
00726 #endif
00727
00729
00730 template<int N, typename T1, typename T2, bool A1, bool A2>
00731 inline
00732 bool
00733 operator!=(const Array<N,T1,A1>& x, const Array<N,T2,A2>& y) {
00734 return !(x == y);
00735 }
00736
00737
00738
00739
00740
00741
00743
00753 template<int N, typename T, bool A>
00754 inline
00755 std::istream&
00756 operator>>(std::istream& in, Array<N,T,A>& x) {
00757 x.get(in);
00758 return in;
00759 }
00760
00761
00763
00773 template<int N, typename T, bool A>
00774 inline
00775 std::ostream&
00776 operator<<(std::ostream& out, const Array<N,T,A>& x) {
00777 x.put(out);
00778 return out;
00779 }
00780
00781 END_NAMESPACE_ADS
00782
00783 #define __Array_ipp__
00784 #include "Array.ipp"
00785 #undef __Array_ipp__
00786
00787 #define __Array1_h__
00788 #include "Array1.h"
00789 #undef __Array1_h__
00790
00791 #endif