00001
00055 #ifndef __ARRAY__
00056 #define __ARRAY__
00057
00058 #include <stdexcept>
00059 #include <vector>
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00073
00082 template<typename T,typename A = std::allocator<T> >
00083 class Array_2D{
00084
00085 private:
00087 typedef std::vector<T,A> Storage;
00088
00089 public:
00090
00092
00093
00094 typedef typename Storage::value_type value_type;
00095 typedef typename Storage::allocator_type allocator_type;
00096
00097 typedef typename Storage::size_type size_type;
00098 typedef typename Storage::difference_type difference_type;
00099
00100 typedef typename Storage::iterator iterator;
00101 typedef typename Storage::const_iterator const_iterator;
00102
00103 typedef typename Storage::reverse_iterator reverse_iterator;
00104 typedef typename Storage::const_reverse_iterator const_reverse_iterator;
00105
00106 typedef typename Storage::reference reference;
00107 typedef typename Storage::const_reference const_reference;
00109
00111
00112
00113 explicit inline Array_2D(const A& a = A());
00114
00115 explicit inline Array_2D(const size_type nx,
00116 const size_type ny,
00117 const T& val = T(),const A& a = A());
00118
00119 template<typename Element_iterator>
00120 inline Array_2D(Element_iterator begin_elt,
00121 Element_iterator end_elt,
00122 const size_type nx,
00123 const size_type ny,
00124 const A& a = A());
00125
00126 inline Array_2D(const Array_2D<T,A>& a);
00128
00130 void assign(const size_type nx,
00131 const size_type ny,
00132 const T& val);
00133
00135
00136
00137 inline bool empty() const;
00138
00139 inline size_type x_size() const;
00140 inline size_type y_size() const;
00141 inline size_type size() const;
00142
00143 inline size_type max_size() const;
00144
00145 inline void resize(const size_type nx,
00146 const size_type ny);
00148
00150 inline void swap(Array_2D<T,A>& a);
00151
00153 inline allocator_type get_allocator() const;
00154
00156
00157
00158 inline Array_2D<T,A>& operator=(const Array_2D<T,A>& a);
00159 inline bool operator==(const Array_2D<T,A>& a);
00160 inline bool operator!=(const Array_2D<T,A>& a);
00162
00164
00165
00166 template<typename Vector_position>
00167 inline reference operator[](const Vector_position& v);
00168
00169 template<typename Vector_position>
00170 inline const_reference operator[](const Vector_position& v) const;
00171
00172 inline reference operator()(const size_type x,
00173 const size_type y);
00174
00175 inline const_reference operator()(const size_type x,
00176 const size_type y) const;
00177
00178 template<typename Vector_position>
00179 inline reference at(const Vector_position& v);
00180
00181 template<typename Vector_position>
00182 inline const_reference at(const Vector_position& v) const;
00183
00184 inline reference at(const size_type x,
00185 const size_type y);
00186
00187 inline const_reference at(const size_type x,
00188 const size_type y) const;
00190
00192
00193
00200 inline iterator begin();
00201 inline const_iterator begin() const;
00203
00205
00206
00213 inline iterator end();
00214 inline const_iterator end() const;
00216
00218
00219
00220 inline reverse_iterator rbegin();
00221 inline const_reverse_iterator rbegin() const;
00222 inline reverse_iterator rend();
00223 inline const_reverse_iterator rend() const;
00225
00226
00227 private:
00229
00230
00231 int x_dim,y_dim;
00233
00235 Storage storage;
00236
00238
00239
00240 template<typename Vector_position>
00241 inline size_type offset(const Vector_position& v) const;
00242
00243 inline size_type offset(const size_type& x,
00244 const size_type& y) const;
00246 };
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00273
00282 template<typename T,typename A = std::allocator<T> >
00283 class Array_3D{
00284
00285 private:
00287 typedef std::vector<T,A> Storage;
00288
00289 public:
00290
00292
00293
00294 typedef typename Storage::value_type value_type;
00295 typedef typename Storage::allocator_type allocator_type;
00296
00297 typedef typename Storage::size_type size_type;
00298 typedef typename Storage::difference_type difference_type;
00299
00300 typedef typename Storage::iterator iterator;
00301 typedef typename Storage::const_iterator const_iterator;
00302
00303 typedef typename Storage::reverse_iterator reverse_iterator;
00304 typedef typename Storage::const_reverse_iterator const_reverse_iterator;
00305
00306 typedef typename Storage::reference reference;
00307 typedef typename Storage::const_reference const_reference;
00309
00311
00312
00313 explicit inline Array_3D(const A& a = A());
00314
00315 explicit inline Array_3D(const size_type nx,
00316 const size_type ny,
00317 const size_type nz,
00318 const T& val = T(),
00319 const A& a = A());
00320
00321 template<typename Element_iterator>
00322 inline Array_3D(Element_iterator begin_elt,
00323 Element_iterator end_elt,
00324 const size_type nx,
00325 const size_type ny,
00326 const size_type nz,
00327 const A& a = A());
00328
00329 inline Array_3D(const Array_3D<T,A>& a);
00331
00333 void assign(const size_type nx,
00334 const size_type ny,
00335 const size_type nz,
00336 const T& val);
00337
00339
00340
00341 inline bool empty() const;
00342
00343 inline size_type x_size() const;
00344 inline size_type y_size() const;
00345 inline size_type z_size() const;
00346 inline size_type size() const;
00347
00348 inline size_type max_size() const;
00349
00350 inline void resize(const size_type nx,
00351 const size_type ny,
00352 const size_type nz);
00354
00356 inline void swap(Array_3D<T,A>& a);
00357
00359 inline allocator_type get_allocator() const;
00360
00362
00363
00364 inline Array_3D<T,A>& operator=(const Array_3D<T,A>& a);
00365 inline bool operator==(const Array_3D<T,A>& a);
00366 inline bool operator!=(const Array_3D<T,A>& a);
00368
00370
00371
00372 template<typename Vector_position>
00373 inline reference operator[](const Vector_position& v);
00374
00375 template<typename Vector_position>
00376 inline const_reference operator[](const Vector_position& v) const;
00377
00378 inline reference operator()(const size_type x,
00379 const size_type y,
00380 const size_type z);
00381
00382 inline const_reference operator()(const size_type x,
00383 const size_type y,
00384 const size_type z) const;
00385
00386 template<typename Vector_position>
00387 inline reference at(const Vector_position& v);
00388
00389 template<typename Vector_position>
00390 inline const_reference at(const Vector_position& v) const;
00391
00392 inline reference at(const size_type x,
00393 const size_type y,
00394 const size_type z);
00395
00396 inline const_reference at(const size_type x,
00397 const size_type y,
00398 const size_type z) const;
00400
00402
00403
00410 inline iterator begin();
00411 inline const_iterator begin() const;
00413
00415
00416
00423 inline iterator end();
00424 inline const_iterator end() const;
00426
00428
00429
00430 inline reverse_iterator rbegin();
00431 inline const_reverse_iterator rbegin() const;
00432 inline reverse_iterator rend();
00433 inline const_reverse_iterator rend() const;
00435
00436
00437 private:
00439
00440
00441 int x_dim,y_dim,z_dim;
00443
00445 Storage storage;
00446
00448
00449
00450 template<typename Vector_position>
00451 inline size_type offset(const Vector_position& v) const;
00452
00453 inline size_type offset(const size_type& x,
00454 const size_type& y,
00455 const size_type& z) const;
00457 };
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 template<typename T,typename A>
00500 Array_2D<T,A>::Array_2D(const A& a)
00501 :x_dim(0),y_dim(0),storage(){}
00502
00503
00504 template<typename T,typename A>
00505 Array_2D<T,A>::Array_2D(const size_type nx,
00506 const size_type ny,
00507 const T& val,
00508 const A& a)
00509 :x_dim(nx),y_dim(ny),storage(nx*ny,val,a){}
00510
00511
00518 template<typename T,typename A>
00519 template<typename Element_iterator>
00520 Array_2D<T,A>::Array_2D(Element_iterator begin_elt,
00521 Element_iterator end_elt,
00522 const size_type nx,
00523 const size_type ny,
00524 const A& a)
00525 :x_dim(nx),y_dim(ny),storage(a){
00526
00527 const size_type s = x_dim*y_dim;
00528 storage.reserve(s);
00529
00530 Element_iterator elt;
00531 size_type index;
00532 for(elt=begin_elt,index=0;(elt!=end_elt)&&(index<s);elt++,index++){
00533 storage.push_back(*elt);
00534 }
00535
00536 if (index!=s) {
00537 storage.clear();
00538 storage.reserve(0);
00539 throw std::length_error("Not enough elements to initialize the array");
00540 }
00541 }
00542
00543
00544 template<typename T,typename A>
00545 Array_2D<T,A>::Array_2D(const Array_2D<T,A>& a)
00546 :x_dim(a.x_dim),y_dim(a.y_dim),storage(a.storage){}
00547
00548
00549 template<typename T,typename A>
00550 void
00551 Array_2D<T,A>::assign(const size_type nx,
00552 const size_type ny,
00553 const T& val){
00554 x_dim = nx;
00555 y_dim = ny;
00556 storage.assign(x_dim*y_dim,val);;
00557 }
00558
00559
00560 template<typename T,typename A>
00561 bool
00562 Array_2D<T,A>::empty() const{
00563 return storage.empty();
00564 }
00565
00566
00567 template<typename T,typename A>
00568 typename Array_2D<T,A>::size_type
00569 Array_2D<T,A>::x_size() const{
00570 return x_dim;
00571 }
00572
00573
00574 template<typename T,typename A>
00575 typename Array_2D<T,A>::size_type
00576 Array_2D<T,A>::y_size() const{
00577 return y_dim;
00578 }
00579
00580
00581 template<typename T,typename A>
00582 typename Array_2D<T,A>::size_type
00583 Array_2D<T,A>::size() const{
00584 return storage.size();
00585 }
00586
00587
00588 template<typename T,typename A>
00589 typename Array_2D<T,A>::size_type
00590 Array_2D<T,A>::max_size() const{
00591 return storage.max_size();
00592 }
00593
00594
00595 template<typename T,typename A>
00596 void
00597 Array_2D<T,A>::resize(const size_type nx,
00598 const size_type ny){
00599 x_dim = nx;
00600 y_dim = ny;
00601 storage.resize(x_dim * y_dim);
00602 }
00603
00604
00605 template<typename T,typename A>
00606 void
00607 Array_2D<T,A>::swap(Array_2D<T,A>& a){
00608 size_type x_buf = x_dim;
00609 size_type y_buf = y_dim;
00610
00611 x_dim = a.x_dim;
00612 y_dim = a.y_dim;
00613
00614 a.x_dim = x_buf;
00615 a.y_dim = y_buf;
00616
00617 storage.swap(a.storage);
00618 }
00619
00620
00621 template<typename T,typename A>
00622 typename Array_2D<T,A>::allocator_type
00623 Array_2D<T,A>::get_allocator() const{
00624 return storage.get_allocator();
00625 }
00626
00627
00628 template<typename T,typename A>
00629 Array_2D<T,A>&
00630 Array_2D<T,A>::operator=(const Array_2D<T,A>& a){
00631
00632 if (&a!=this){
00633 x_dim = a.x_dim;
00634 y_dim = a.y_dim;
00635 storage = a.storage;
00636 }
00637
00638 return *this;
00639 }
00640
00641
00642 template<typename T,typename A>
00643 bool
00644 Array_2D<T,A>::operator==(const Array_2D<T,A>& a){
00645 return ((x_dim==a.x_dim)&&(y_dim==a.y_dim)&&(storage==a.storage));
00646 }
00647
00648
00649 template<typename T,typename A>
00650 bool
00651 Array_2D<T,A>::operator!=(const Array_2D<T,A>& a){
00652 return !(*this==a);
00653 }
00654
00655
00656 template<typename T,typename A>
00657 template<typename Vector_position>
00658 typename Array_2D<T,A>::reference
00659 Array_2D<T,A>::operator[](const Vector_position& v){
00660 return storage[offset(v)];
00661 }
00662
00663
00664 template<typename T,typename A>
00665 template<typename Vector_position>
00666 typename Array_2D<T,A>::const_reference
00667 Array_2D<T,A>::operator[](const Vector_position& v) const{
00668 return storage[offset(v)];
00669 }
00670
00671
00672 template<typename T,typename A>
00673 typename Array_2D<T,A>::reference
00674 Array_2D<T,A>::operator()(const size_type x,const size_type y){
00675 return storage[offset(x,y)];
00676 }
00677
00678
00679 template<typename T,typename A>
00680 typename Array_2D<T,A>::const_reference
00681 Array_2D<T,A>::operator()(const size_type x,const size_type y) const{
00682 return storage[offset(x,y)];
00683 }
00684
00685
00686 template<typename T,typename A>
00687 template<typename Vector_position>
00688 typename Array_2D<T,A>::reference
00689 Array_2D<T,A>::at(const Vector_position& v){
00690
00691 if ((v[0]>=x_dim)||(v[1]>=y_dim)){
00692 if (v[0]>=x_dim) {
00693 throw std::out_of_range("Out of range X");
00694 }
00695 else{
00696 throw std::out_of_range("Out of range Y");
00697 }
00698 }
00699
00700 return storage[offset(v)];
00701 }
00702
00703
00704 template<typename T,typename A>
00705 template<typename Vector_position>
00706 typename Array_2D<T,A>::const_reference
00707 Array_2D<T,A>::at(const Vector_position& v) const{
00708
00709 if ((v[0]>=x_dim)||(v[1]>=y_dim)){
00710 if (v[0]>=x_dim) {
00711 throw std::out_of_range("Out of range X");
00712 }
00713 else{
00714 throw std::out_of_range("Out of range Y");
00715 }
00716 }
00717
00718 return storage[offset(v)];
00719 }
00720
00721
00722 template<typename T,typename A>
00723 typename Array_2D<T,A>::reference
00724 Array_2D<T,A>::at(const size_type x,const size_type y){
00725
00726 if ((x>=x_dim)||(y>=y_dim)){
00727 if (x>=x_dim) {
00728 throw std::out_of_range("Out of range X");
00729 }
00730 else{
00731 throw std::out_of_range("Out of range Y");
00732 }
00733 }
00734
00735 return storage[offset(x,y)];
00736 }
00737
00738
00739 template<typename T,typename A>
00740 typename Array_2D<T,A>::const_reference
00741 Array_2D<T,A>::at(const size_type x,const size_type y) const{
00742
00743 if ((x>=x_dim)||(y>=y_dim)){
00744 if (x>=x_dim) {
00745 throw std::out_of_range("Out of range X");
00746 }
00747 else{
00748 throw std::out_of_range("Out of range Y");
00749 }
00750 }
00751
00752 return storage[offset(x,y)];
00753 }
00754
00755
00756 template<typename T,typename A>
00757 typename Array_2D<T,A>::iterator
00758 Array_2D<T,A>::begin(){
00759 return storage.begin();
00760 }
00761
00762
00763 template<typename T,typename A>
00764 typename Array_2D<T,A>::const_iterator
00765 Array_2D<T,A>::begin() const{
00766 return storage.begin();
00767 }
00768
00769
00770 template<typename T,typename A>
00771 typename Array_2D<T,A>::iterator
00772 Array_2D<T,A>::end(){
00773 return storage.end();
00774 }
00775
00776
00777 template<typename T,typename A>
00778 typename Array_2D<T,A>::const_iterator
00779 Array_2D<T,A>::end() const{
00780 return storage.end();
00781 }
00782
00783
00784 template<typename T,typename A>
00785 typename Array_2D<T,A>::reverse_iterator
00786 Array_2D<T,A>::rbegin(){
00787 return storage.rbegin();
00788 }
00789
00790
00791 template<typename T,typename A>
00792 typename Array_2D<T,A>::const_reverse_iterator
00793 Array_2D<T,A>::rbegin() const{
00794 return storage.rbegin();
00795 }
00796
00797
00798 template<typename T,typename A>
00799 typename Array_2D<T,A>::reverse_iterator
00800 Array_2D<T,A>::rend(){
00801 return storage.rend();
00802 }
00803
00804
00805 template<typename T,typename A>
00806 typename Array_2D<T,A>::const_reverse_iterator
00807 Array_2D<T,A>::rend() const{
00808 return storage.rend();
00809 }
00810
00811
00812 template<typename T,typename A>
00813 template<typename Vector_position>
00814 typename Array_2D<T,A>::size_type
00815 Array_2D<T,A>::offset(const Vector_position& v) const{
00816 return v[0]*y_dim + v[1];
00817 }
00818
00819
00820 template<typename T,typename A>
00821 typename Array_2D<T,A>::size_type
00822 Array_2D<T,A>::offset(const size_type& x,const size_type& y) const{
00823 return x*y_dim + y;
00824 }
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853 template<typename T,typename A>
00854 Array_3D<T,A>::Array_3D(const A& a)
00855 :x_dim(0),y_dim(0),z_dim(0),storage(){}
00856
00857
00858 template<typename T,typename A>
00859 Array_3D<T,A>::Array_3D(const size_type nx,
00860 const size_type ny,
00861 const size_type nz,
00862 const T& val,
00863 const A& a)
00864 :x_dim(nx),y_dim(ny),z_dim(nz),storage(nx*ny*nz,val,a){}
00865
00866
00873 template<typename T,typename A>
00874 template<typename Element_iterator>
00875 Array_3D<T,A>::Array_3D(Element_iterator begin_elt,
00876 Element_iterator end_elt,
00877 const size_type nx,
00878 const size_type ny,
00879 const size_type nz,
00880 const A& a)
00881 :x_dim(nx),y_dim(ny),z_dim(nz),storage(a){
00882
00883 const size_type s = x_dim*y_dim*z_dim;
00884 storage.reserve(s);
00885
00886 Element_iterator elt;
00887 size_type index;
00888 for(elt=begin_elt,index=0;(elt!=end_elt)&&(index<s);elt++,index++){
00889 storage.push_back(*elt);
00890 }
00891
00892 if (index!=s) {
00893 storage.clear();
00894 storage.reserve(0);
00895 throw length_error("Not enough elements to initialize the array");;
00896 }
00897 }
00898
00899
00900 template<typename T,typename A>
00901 Array_3D<T,A>::Array_3D(const Array_3D<T,A>& a)
00902 :x_dim(a.x_dim),y_dim(a.y_dim),z_dim(a.z_dim),storage(a.storage){}
00903
00904
00905 template<typename T,typename A>
00906 void
00907 Array_3D<T,A>::assign(const size_type nx,
00908 const size_type ny,
00909 const size_type nz,
00910 const T& val){
00911 x_dim = nx;
00912 y_dim = ny;
00913 z_dim = nz;
00914 storage.assign(x_dim*y_dim*z_dim,val);;
00915 }
00916
00917
00918 template<typename T,typename A>
00919 bool
00920 Array_3D<T,A>::empty() const{
00921 return storage.empty();
00922 }
00923
00924
00925 template<typename T,typename A>
00926 typename Array_3D<T,A>::size_type
00927 Array_3D<T,A>::x_size() const{
00928 return x_dim;
00929 }
00930
00931
00932 template<typename T,typename A>
00933 typename Array_3D<T,A>::size_type
00934 Array_3D<T,A>::y_size() const{
00935 return y_dim;
00936 }
00937
00938
00939 template<typename T,typename A>
00940 typename Array_3D<T,A>::size_type
00941 Array_3D<T,A>::z_size() const{
00942 return z_dim;
00943 }
00944
00945
00946 template<typename T,typename A>
00947 typename Array_3D<T,A>::size_type
00948 Array_3D<T,A>::size() const{
00949 return storage.size();
00950 }
00951
00952
00953 template<typename T,typename A>
00954 typename Array_3D<T,A>::size_type
00955 Array_3D<T,A>::max_size() const{
00956 return storage.max_size();
00957 }
00958
00959
00960 template<typename T,typename A>
00961 void
00962 Array_3D<T,A>::resize(const size_type nx,
00963 const size_type ny,
00964 const size_type nz){
00965 x_dim = nx;
00966 y_dim = ny;
00967 z_dim = nz;
00968 storage.resize(x_dim * y_dim * z_dim);
00969 }
00970
00971
00972 template<typename T,typename A>
00973 void
00974 Array_3D<T,A>::swap(Array_3D<T,A>& a){
00975 size_type x_buf = x_dim;
00976 size_type y_buf = y_dim;
00977 size_type z_buf = z_dim;
00978
00979 x_dim = a.x_dim;
00980 y_dim = a.y_dim;
00981 z_dim = a.z_dim;
00982
00983 a.x_dim = x_buf;
00984 a.y_dim = y_buf;
00985 a.z_dim = z_buf;
00986
00987 storage.swap(a.storage);
00988 }
00989
00990
00991 template<typename T,typename A>
00992 typename Array_3D<T,A>::allocator_type
00993 Array_3D<T,A>::get_allocator() const{
00994 return storage.get_allocator();
00995 }
00996
00997
00998 template<typename T,typename A>
00999 Array_3D<T,A>&
01000 Array_3D<T,A>::operator=(const Array_3D<T,A>& a){
01001
01002 if (&a!=this){
01003 x_dim = a.x_dim;
01004 y_dim = a.y_dim;
01005 z_dim = a.z_dim;
01006 storage = a.storage;
01007 }
01008
01009 return *this;
01010 }
01011
01012
01013 template<typename T,typename A>
01014 bool
01015 Array_3D<T,A>::operator==(const Array_3D<T,A>& a){
01016 return ((x_dim==a.x_dim)
01017 &&(y_dim==a.y_dim)
01018 &&(z_dim==a.z_dim)
01019 &&(storage==a.storage));
01020 }
01021
01022
01023 template<typename T,typename A>
01024 bool
01025 Array_3D<T,A>::operator!=(const Array_3D<T,A>& a){
01026 return !(*this==a);
01027 }
01028
01029
01030 template<typename T,typename A>
01031 template<typename Vector_position>
01032 typename Array_3D<T,A>::reference
01033 Array_3D<T,A>::operator[](const Vector_position& v){
01034 return storage[offset(v)];
01035 }
01036
01037
01038 template<typename T,typename A>
01039 template<typename Vector_position>
01040 typename Array_3D<T,A>::const_reference
01041 Array_3D<T,A>::operator[](const Vector_position& v) const{
01042 return storage[offset(v)];
01043 }
01044
01045
01046 template<typename T,typename A>
01047 typename Array_3D<T,A>::reference
01048 Array_3D<T,A>::operator()(const size_type x,
01049 const size_type y,
01050 const size_type z){
01051
01052 return storage[offset(x,y,z)];
01053 }
01054
01055
01056 template<typename T,typename A>
01057 typename Array_3D<T,A>::const_reference
01058 Array_3D<T,A>::operator()(const size_type x,
01059 const size_type y,
01060 const size_type z) const{
01061
01062 return storage[offset(x,y,z)];
01063 }
01064
01065
01066 template<typename T,typename A>
01067 template<typename Vector_position>
01068 typename Array_3D<T,A>::reference
01069 Array_3D<T,A>::at(const Vector_position& v){
01070
01071 if ((v[0]>=x_dim)||(v[1]>=y_dim)||(v[2]>=z_dim)){
01072 if (v[0]>=x_dim) {
01073 throw std::out_of_range("Out of range X");
01074 }
01075 else if (v[1]>=y_dim) {
01076 throw std::out_of_range("Out of range Y");
01077 }
01078 else {
01079 throw std::out_of_range("Out of range Z");
01080 }
01081 }
01082
01083 return storage[offset(v)];
01084 }
01085
01086
01087 template<typename T,typename A>
01088 template<typename Vector_position>
01089 typename Array_3D<T,A>::const_reference
01090 Array_3D<T,A>::at(const Vector_position& v) const{
01091
01092 if ((v[0]>=x_dim)||(v[1]>=y_dim)||(v[2]>=z_dim)){
01093 if (v[0]>=x_dim) {
01094 throw std::out_of_range("Out of range X");
01095 }
01096 else if (v[1]>=y_dim) {
01097 throw std::out_of_range("Out of range Y");
01098 }
01099 else {
01100 throw std::out_of_range("Out of range Z");
01101 }
01102 }
01103
01104 return storage[offset(v)];
01105 }
01106
01107
01108 template<typename T,typename A>
01109 typename Array_3D<T,A>::reference
01110 Array_3D<T,A>::at(const size_type x,
01111 const size_type y,
01112 const size_type z){
01113
01114 if ((x>=x_dim)||(y>=y_dim)||(z>=z_dim)){
01115 if (x>=x_dim) {
01116 throw std::out_of_range("Out of range X");
01117 }
01118 else if (y>=y_dim) {
01119 throw std::out_of_range("Out of range Y");
01120 }
01121 else {
01122 throw std::out_of_range("Out of range Z");
01123 }
01124 }
01125
01126 return storage[offset(x,y,z)];
01127 }
01128
01129
01130 template<typename T,typename A>
01131 typename Array_3D<T,A>::const_reference
01132 Array_3D<T,A>::at(const size_type x,
01133 const size_type y,
01134 const size_type z) const{
01135
01136 if ((x>=x_dim)||(y>=y_dim)||(z>=z_dim)){
01137 if (x>=x_dim) {
01138 throw std::out_of_range("Out of range X");
01139 }
01140 else if (y>=y_dim) {
01141 throw std::out_of_range("Out of range Y");
01142 }
01143 else {
01144 throw std::out_of_range("Out of range Z");
01145 }
01146 }
01147
01148 return storage[offset(x,y,z)];
01149 }
01150
01151
01152 template<typename T,typename A>
01153 typename Array_3D<T,A>::iterator
01154 Array_3D<T,A>::begin(){
01155 return storage.begin();
01156 }
01157
01158
01159 template<typename T,typename A>
01160 typename Array_3D<T,A>::const_iterator
01161 Array_3D<T,A>::begin() const{
01162 return storage.begin();
01163 }
01164
01165
01166 template<typename T,typename A>
01167 typename Array_3D<T,A>::iterator
01168 Array_3D<T,A>::end(){
01169 return storage.end();
01170 }
01171
01172
01173 template<typename T,typename A>
01174 typename Array_3D<T,A>::const_iterator
01175 Array_3D<T,A>::end() const{
01176 return storage.end();
01177 }
01178
01179
01180 template<typename T,typename A>
01181 typename Array_3D<T,A>::reverse_iterator
01182 Array_3D<T,A>::rbegin(){
01183 return storage.rbegin();
01184 }
01185
01186
01187 template<typename T,typename A>
01188 typename Array_3D<T,A>::const_reverse_iterator
01189 Array_3D<T,A>::rbegin() const{
01190 return storage.rbegin();
01191 }
01192
01193
01194 template<typename T,typename A>
01195 typename Array_3D<T,A>::reverse_iterator
01196 Array_3D<T,A>::rend(){
01197 return storage.rend();
01198 }
01199
01200
01201 template<typename T,typename A>
01202 typename Array_3D<T,A>::const_reverse_iterator
01203 Array_3D<T,A>::rend() const{
01204 return storage.rend();
01205 }
01206
01207
01208 template<typename T,typename A>
01209 template<typename Vector_position>
01210 typename Array_3D<T,A>::size_type
01211 Array_3D<T,A>::offset(const Vector_position& v) const{
01212 return (v[0]*y_dim + v[1])*z_dim + v[2];
01213 }
01214
01215
01216 template<typename T,typename A>
01217 typename Array_3D<T,A>::size_type
01218 Array_3D<T,A>::offset(const size_type& x,
01219 const size_type& y,
01220 const size_type& z) const{
01221 return (x*y_dim + y)*z_dim + z;
01222 }
01223
01224 #endif