76 #ifndef SLIP_ARRAY4D_HPP
77 #define SLIP_ARRAY4D_HPP
90 #include <boost/serialization/access.hpp>
91 #include <boost/serialization/split_member.hpp>
92 #include <boost/serialization/string.hpp>
93 #include <boost/serialization/complex.hpp>
94 #include <boost/serialization/version.hpp>
99 class stride_iterator;
104 template <
typename T>
107 template <
typename T>
120 bool operator<(const slip::Array4d<T>& x,
128 bool operator<=(const slip::Array4d<T>& x,
159 template <
typename T>
237 static const std::size_t
DIM = 4;
259 const std::size_t d2,
260 const std::size_t d3,
261 const std::size_t d4);
272 const std::size_t d2,
273 const std::size_t d3,
274 const std::size_t d4,
285 const std::size_t d2,
286 const std::size_t d3,
287 const std::size_t d4,
302 template<
typename InputIterator>
309 d1_(d1),d2_(d2),d3_(d3),d4_(d4),size_(d1 * d2 * d3 * d4),data_(0)
313 std::fill_n(this->
begin(),this->size_,T());
340 void resize(std::size_t d1,
2656 const range & row_range,
const range & col_range);
2686 const range & row_range,
const range & col_range);
2717 const range & row_range,
const range & col_range)
const;
2748 const range & row_range,
const range & col_range)
const;
2779 const range & row_range,
const range & col_range);
2810 const range & row_range,
const range & col_range);
2841 const range & row_range,
const range & col_range)
const;
2872 const range & row_range,
const range & col_range)
const;
2888 friend std::ostream& operator<< <>(std::ostream & out,
2926 std::fill_n(this->
begin(),this->size_,value);
2948 template<
typename InputIterator>
2968 friend bool operator== <>(
const Array4d<T>& x,
2977 friend bool operator!= <>(
const Array4d<T>& x,
2986 friend bool operator< <>(
const Array4d<T>& x,
2995 friend bool operator> <>(
const Array4d<T>& x,
3004 friend bool operator<= <>(
const Array4d<T>& x,
3013 friend bool operator>= <>(
const Array4d<T>& x,
3073 std::string
name()
const;
3190 void copy_attributes(
const self& rhs);
3194 template<
class Archive>
3195 void save(Archive & ar,
const unsigned int version)
const
3197 ar & this->d1_ & this->d2_ & this->d3_ & this->d4_& this->size_ ;
3198 for (
size_t i = 0; i < this->size_; ++i)
3203 template<
class Archive>
3204 void load(Archive & ar,
const unsigned int version)
3206 ar & this->d1_ & this->d2_ & this->d3_ & this->d4_& this->size_ ;
3209 for (
size_t i = 0; i < this->size_; ++i)
3214 BOOST_SERIALIZATION_SPLIT_MEMBER();
3249 template<
typename T>
3252 d1_(0),d2_(0),d3_(0),d4_(0),size_(0),data_(0)
3256 template<
typename T>
3262 d1_(d1),d2_(d2),d3_(d3),d4_(d4),size_(d1 * d2 * d3 * d4),data_(0)
3265 std::fill_n(this->data_[0][0][0],this->size_,T());
3268 template<
typename T>
3275 d1_(d1),d2_(d2),d3_(d3),d4_(d4),size_(d1 * d2 * d3 * d4),data_(0)
3278 std::fill_n(this->data_[0][0][0],this->size_,val);
3281 template<
typename T>
3288 d1_(d1),d2_(d2),d3_(d3),d4_(d4),size_(d1 * d2 * d3 * d4),data_(0)
3291 std::copy(val,val + this->size_, this->data_[0][0][0]);
3294 template<
typename T>
3297 d1_(rhs.d1_),d2_(rhs.d2_),d3_(rhs.d3_),d4_(rhs.d4_),size_(rhs.size_),data_(0)
3300 if(this->size_ != 0)
3302 std::copy(rhs.data_[0][0][0],rhs.data_[0][0][0] + this->size_,this->data_[0][0][0]);
3306 template<
typename T>
3310 this->desallocate();
3319 template<
typename T>
3325 if( this->d1_ != rhs.d1_ || this->d2_ != rhs.d2_ || this->d3_ != rhs.d3_ || this->d4_ != rhs.d4_)
3327 this->desallocate();
3328 this->copy_attributes(rhs);
3333 std::copy(rhs.data_[0][0][0],rhs.data_[0][0][0] + this->size_,this->data_[0][0][0]);
3339 template<
typename T>
3349 template<
typename T>
3357 if( this->d1_ != d1 || this->d2_ != d2 || this->d3_ != d3 || this->d4_ != d4)
3359 this->desallocate();
3364 this->size_ = d1 * d2 * d3 * d4;
3367 if( this->d1_ != 0 && this->d2_ != 0 && this->d3_ != 0 && this->d4_ != 0)
3369 std::fill_n(this->data_[0][0][0],this->size_,val);
3388 template<
typename T>
3392 return this->data_[0][0][0];
3395 template<
typename T>
3399 return this->data_[0][0][0] + this->size_;
3402 template<
typename T>
3406 return this->data_[0][0][0];
3409 template<
typename T>
3413 return this->data_[0][0][0] + this->size_;
3416 template<
typename T>
3423 template<
typename T>
3430 template<
typename T>
3438 template<
typename T>
3448 template<
typename T>
3452 assert(slice < this->d2_);
3453 assert(row < this->d3_);
3454 assert(col < this->d4_);
3459 template<
typename T>
3461 typename Array4d<T>::const_slab_iterator
Array4d<T>::slab_begin(
const typename Array4d<T>::size_type slice,
3462 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col)
const{
3463 assert(slice < this->d2_);
3464 assert(row < this->d3_);
3465 assert(col < this->d4_);
3469 template<
typename T>
3471 typename Array4d<T>::slab_iterator
Array4d<T>::slab_end(
const typename Array4d<T>::size_type slice,
3472 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col){
3473 assert(slice < this->d2_);
3474 assert(row < this->d3_);
3475 assert(col < this->d4_);
3476 return (this->slab_begin(slice,row,col) + this->d1_);
3480 template<
typename T>
3482 typename Array4d<T>::const_slab_iterator
Array4d<T>::slab_end(
const typename Array4d<T>::size_type slice,
3483 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col)
const{
3484 assert(slice < this->d2_);
3485 assert(row < this->d3_);
3486 assert(col < this->d4_);
3488 return (tp->slab_begin(slice,row,col) + this->d1_);
3492 template<
typename T>
3494 typename Array4d<T>::reverse_slab_iterator
Array4d<T>::slab_rbegin(
const typename Array4d<T>::size_type slice,
3495 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col){
3496 assert(slice < this->d2_);
3497 assert(row < this->d3_);
3498 assert(col < this->d4_);
3502 template<
typename T>
3504 typename Array4d<T>::const_reverse_slab_iterator
Array4d<T>::slab_rbegin(
const typename Array4d<T>::size_type slice,
3505 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col)
const{
3506 assert(slice < this->d2_);
3507 assert(row < this->d3_);
3508 assert(col < this->d4_);
3513 template<
typename T>
3515 typename Array4d<T>::reverse_slab_iterator
Array4d<T>::slab_rend(
const typename Array4d<T>::size_type slice,
3516 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col){
3517 assert(slice < this->d2_);
3518 assert(row < this->d3_);
3519 assert(col < this->d4_);
3523 template<
typename T>
3525 typename Array4d<T>::const_reverse_slab_iterator
Array4d<T>::slab_rend(
const typename Array4d<T>::size_type slice,
3526 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col)
const{
3527 assert(slice < this->d2_);
3528 assert(row < this->d3_);
3529 assert(col < this->d4_);
3536 template<
typename T>
3538 typename Array4d<T>::slice_iterator
3540 const typename Array4d<T>::size_type col)
3542 assert(slab < this->d1_);
3543 assert(row < this->d3_);
3544 assert(col < this->d4_);
3548 template<
typename T>
3550 typename Array4d<T>::const_slice_iterator
3552 const typename Array4d<T>::size_type col)
const
3554 assert(slab < this->d1_);
3555 assert(row < this->d3_);
3556 assert(col < this->d4_);
3560 template<
typename T>
3562 typename Array4d<T>::slice_iterator
3563 Array4d<T>::slice_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type row,
3564 const typename Array4d<T>::size_type col)
3566 assert(slab < this->d1_);
3567 assert(row < this->d3_);
3568 assert(col < this->d4_);
3572 template<
typename T>
3574 typename Array4d<T>::const_slice_iterator
3575 Array4d<T>::slice_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type row,
3576 const typename Array4d<T>::size_type col)
const
3578 assert(slab < this->d1_);
3579 assert(row < this->d3_);
3580 assert(col < this->d4_);
3584 template<
typename T>
3586 typename Array4d<T>::reverse_slice_iterator
3588 const typename Array4d<T>::size_type col)
3590 assert(slab < this->d1_);
3591 assert(row < this->d3_);
3592 assert(col < this->d4_);
3596 template<
typename T>
3598 typename Array4d<T>::const_reverse_slice_iterator
3600 const typename Array4d<T>::size_type col)
const
3602 assert(slab < this->d1_);
3603 assert(row < this->d3_);
3604 assert(col < this->d4_);
3608 template<
typename T>
3610 typename Array4d<T>::reverse_slice_iterator
3611 Array4d<T>::slice_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type row,
3612 const typename Array4d<T>::size_type col)
3614 assert(slab < this->d1_);
3615 assert(row < this->d3_);
3616 assert(col < this->d4_);
3620 template<
typename T>
3622 typename Array4d<T>::const_reverse_slice_iterator
3623 Array4d<T>::slice_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type row,
3624 const typename Array4d<T>::size_type col)
const
3626 assert(slab < this->d1_);
3627 assert(row < this->d3_);
3628 assert(col < this->d4_);
3634 template<
typename T>
3636 typename Array4d<T>::row_iterator
3637 Array4d<T>::row_begin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3638 const typename Array4d<T>::size_type row)
3640 assert(slab < this->d1_);
3641 assert(slice < this->d2_);
3642 assert(row < this->d3_);
3643 return this->data_[slab][slice][row];
3646 template<
typename T>
3648 typename Array4d<T>::const_row_iterator
3649 Array4d<T>::row_begin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3650 const typename Array4d<T>::size_type row)
const
3652 assert(slab < this->d1_);
3653 assert(slice < this->d2_);
3654 assert(row < this->d3_);
3655 return this->data_[slab][slice][row];
3658 template<
typename T>
3660 typename Array4d<T>::row_iterator
3661 Array4d<T>::row_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3662 const typename Array4d<T>::size_type row)
3664 assert(slab < this->d1_);
3665 assert(slice < this->d2_);
3666 assert(row < this->d3_);
3667 return this->data_[slab][slice][row] + this->d4_;
3670 template<
typename T>
3672 typename Array4d<T>::const_row_iterator
3673 Array4d<T>::row_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3674 const typename Array4d<T>::size_type row)
const
3676 assert(slab < this->d1_);
3677 assert(slice < this->d2_);
3678 assert(row < this->d3_);
3679 return this->data_[slab][slice][row] + this->d4_;
3683 template<
typename T>
3685 typename Array4d<T>::reverse_row_iterator
3686 Array4d<T>::row_rbegin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3687 const typename Array4d<T>::size_type row)
3689 assert(slab < this->d1_);
3690 assert(slice < this->d2_);
3691 assert(row < this->d3_);
3695 template<
typename T>
3697 typename Array4d<T>::const_reverse_row_iterator
3698 Array4d<T>::row_rbegin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3699 const typename Array4d<T>::size_type row)
const
3701 assert(slab < this->d1_);
3702 assert(slice < this->d2_);
3703 assert(row < this->d3_);
3708 template<
typename T>
3710 typename Array4d<T>::reverse_row_iterator
3711 Array4d<T>::row_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3712 const typename Array4d<T>::size_type row)
3714 assert(slab < this->d1_);
3715 assert(slice < this->d2_);
3716 assert(row < this->d3_);
3720 template<
typename T>
3722 typename Array4d<T>::const_reverse_row_iterator
3723 Array4d<T>::row_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3724 const typename Array4d<T>::size_type row)
const
3726 assert(slab < this->d1_);
3727 assert(slice < this->d2_);
3728 assert(row < this->d3_);
3734 template<
typename T>
3736 typename Array4d<T>::col_iterator
3737 Array4d<T>::col_begin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3738 const typename Array4d<T>::size_type col)
3740 assert(slab < this->d1_);
3741 assert(slice < this->d2_);
3742 assert(col < this->d4_);
3746 template<
typename T>
3748 typename Array4d<T>::const_col_iterator
3749 Array4d<T>::col_begin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3750 const typename Array4d<T>::size_type col)
const
3752 assert(slab < this->d1_);
3753 assert(slice < this->d2_);
3754 assert(col < this->d4_);
3759 template<
typename T>
3761 typename Array4d<T>::col_iterator
3762 Array4d<T>::col_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3763 const typename Array4d<T>::size_type col)
3765 assert(slab < this->d1_);
3766 assert(slice < this->d2_);
3767 assert(col < this->d4_);
3771 template<
typename T>
3773 typename Array4d<T>::const_col_iterator
3774 Array4d<T>::col_end(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3775 const typename Array4d<T>::size_type col)
const
3777 assert(slab < this->d1_);
3778 assert(slice < this->d2_);
3779 assert(col < this->d4_);
3784 template<
typename T>
3786 typename Array4d<T>::reverse_col_iterator
3787 Array4d<T>::col_rbegin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3788 const typename Array4d<T>::size_type col)
3790 assert(slab < this->d1_);
3791 assert(slice < this->d2_);
3792 assert(col < this->d4_);
3796 template<
typename T>
3798 typename Array4d<T>::const_reverse_col_iterator
3799 Array4d<T>::col_rbegin(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3800 const typename Array4d<T>::size_type col)
const
3802 assert(slab < this->d1_);
3803 assert(slice < this->d2_);
3804 assert(col < this->d4_);
3809 template<
typename T>
3811 typename Array4d<T>::reverse_col_iterator
3812 Array4d<T>::col_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3813 const typename Array4d<T>::size_type col)
3815 assert(slab < this->d1_);
3816 assert(slice < this->d2_);
3817 assert(col < this->d4_);
3821 template<
typename T>
3823 typename Array4d<T>::const_reverse_col_iterator
3824 Array4d<T>::col_rend(
const typename Array4d<T>::size_type slab,
const typename Array4d<T>::size_type slice,
3825 const typename Array4d<T>::size_type col)
const
3827 assert(slab < this->d1_);
3828 assert(slice < this->d2_);
3829 assert(col < this->d4_);
3835 template<
typename T>
3837 typename Array4d<T>::slab_range_iterator
Array4d<T>::slab_begin(
const typename Array4d<T>::size_type slice,
3838 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3840 assert(slice < this->d2_);
3841 assert(row < this->d3_);
3842 assert(col < this->d4_);
3844 assert(range.
start() >= 0);
3845 assert(range.
stop() >= 0);
3846 assert(range.
start() < (int)this->d1_);
3847 assert(range.
stop() < (int)this->d1_);
3853 template<
typename T>
3855 typename Array4d<T>::slab_range_iterator
Array4d<T>::slab_end(
const typename Array4d<T>::size_type slice,
3856 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3858 assert(slice < this->d2_);
3859 assert(row < this->d3_);
3860 assert(col < this->d4_);
3861 assert(range.
start() < (int)this->d1_);
3862 assert(range.
stop() < (int)this->d1_);
3868 template<
typename T>
3870 typename Array4d<T>::const_slab_range_iterator
Array4d<T>::slab_begin(
const typename Array4d<T>::size_type slice,
3871 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3873 assert(slice < this->d2_);
3874 assert(row < this->d3_);
3875 assert(col < this->d4_);
3877 assert(range.
start() >= 0);
3878 assert(range.
stop() >= 0);
3879 assert(range.
start() < (int)this->d1_);
3880 assert(range.
stop() < (int)this->d1_);
3886 template<
typename T>
3888 typename Array4d<T>::const_slab_range_iterator
Array4d<T>::slab_end(
const typename Array4d<T>::size_type slice,
3889 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3891 assert(slice < this->d2_);
3892 assert(row < this->d3_);
3893 assert(col < this->d4_);
3894 assert(range.
start() < (int)this->d1_);
3895 assert(range.
stop() < (int)this->d1_);
3900 template<
typename T>
3902 typename Array4d<T>::reverse_slab_range_iterator
Array4d<T>::slab_rbegin(
const typename Array4d<T>::size_type slice,
3903 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3905 assert(slice < this->d2_);
3906 assert(row < this->d3_);
3907 assert(col < this->d4_);
3908 assert(range.
start() < (int)this->d1_);
3913 template<
typename T>
3915 typename Array4d<T>::reverse_slab_range_iterator
Array4d<T>::slab_rend(
const Array4d<T>::size_type slice,
3916 const Array4d<T>::size_type row,
const Array4d<T>::size_type col,
3918 assert(slice < this->d2_);
3919 assert(row < this->d3_);
3920 assert(col < this->d4_);
3921 assert(range.
start() < (int)this->d1_);
3926 template<
typename T>
3928 typename Array4d<T>::const_reverse_slab_range_iterator
Array4d<T>::slab_rbegin(
const typename Array4d<T>::size_type slice,
3929 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3931 assert(slice < this->d2_);
3932 assert(row < this->d3_);
3933 assert(col < this->d4_);
3934 assert(range.
start() < (int)this->d1_);
3938 template<
typename T>
3940 typename Array4d<T>::const_reverse_slab_range_iterator
Array4d<T>::slab_rend(
const typename Array4d<T>::size_type slice,
3941 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3943 assert(slice < this->d2_);
3944 assert(row < this->d3_);
3945 assert(col < this->d4_);
3946 assert(range.
start() < (int)this->d1_);
3953 template<
typename T>
3955 typename Array4d<T>::slice_range_iterator
3957 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3960 assert(slab < this->d1_);
3961 assert(row < this->d3_);
3962 assert(col < this->d4_);
3964 assert(range.
start() >= 0);
3965 assert(range.
stop() >= 0);
3966 assert(range.
start() < (int)this->d2_);
3967 assert(range.
stop() < (int)this->d2_);
3971 template<
typename T>
3973 typename Array4d<T>::const_slice_range_iterator
3975 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3978 assert(slab < this->d1_);
3979 assert(row < this->d3_);
3980 assert(col < this->d4_);
3982 assert(range.
start() >= 0);
3983 assert(range.
stop() >= 0);
3984 assert(range.
start() < (int)this->d2_);
3985 assert(range.
stop() < (int)this->d2_);
3989 template<
typename T>
3991 typename Array4d<T>::slice_range_iterator
3993 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
3996 assert(slab < this->d1_);
3997 assert(row < this->d3_);
3998 assert(col < this->d4_);
3999 assert(range.
start() < (int)this->d2_);
4000 assert(range.
stop() < (int)this->d2_);
4004 template<
typename T>
4006 typename Array4d<T>::const_slice_range_iterator
4008 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
4011 assert(slab < this->d1_);
4012 assert(row < this->d3_);
4013 assert(col < this->d4_);
4014 assert(range.
start() < (int)this->d2_);
4015 assert(range.
stop() < (int)this->d2_);
4019 template<
typename T>
4021 typename Array4d<T>::reverse_slice_range_iterator
4023 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
4026 assert(slab < this->d1_);
4027 assert(row < this->d3_);
4028 assert(col < this->d4_);
4029 assert(range.
start() < (int)this->d2_);
4033 template<
typename T>
4035 typename Array4d<T>::const_reverse_slice_range_iterator
4037 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
4040 assert(slab < this->d1_);
4041 assert(row < this->d3_);
4042 assert(col < this->d4_);
4043 assert(range.
start() < (int)this->d2_);
4047 template<
typename T>
4049 typename Array4d<T>::reverse_slice_range_iterator
4051 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
4054 assert(slab < this->d1_);
4055 assert(row < this->d3_);
4056 assert(col < this->d4_);
4057 assert(range.
start() < (int)this->d2_);
4061 template<
typename T>
4063 typename Array4d<T>::const_reverse_slice_range_iterator
4065 const typename Array4d<T>::size_type row,
const typename Array4d<T>::size_type col,
4068 assert(slab < this->d1_);
4069 assert(row < this->d3_);
4070 assert(col < this->d4_);
4071 assert(range.
start() < (int)this->d2_);
4077 template<
typename T>
4079 typename Array4d<T>::row_range_iterator
4081 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
const slip::Range<int>& range)
4083 assert(slab < this->d1_);
4084 assert(slice < this->d2_);
4085 assert(row < this->d3_);
4087 assert(range.
start() >= 0);
4088 assert(range.
stop() >= 0);
4089 assert(range.
start() < (int)this->d4_);
4090 assert(range.
stop() < (int)this->d4_);
4094 template<
typename T>
4096 typename Array4d<T>::const_row_range_iterator
4098 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4101 assert(slab < this->d1_);
4102 assert(slice < this->d2_);
4103 assert(row < this->d3_);
4105 assert(range.
start() >= 0);
4106 assert(range.
stop() >= 0);
4107 assert(range.
start() < (int)this->d4_);
4108 assert(range.
stop() < (int)this->d4_);
4112 template<
typename T>
4114 typename Array4d<T>::row_range_iterator
4116 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4119 assert(slab < this->d1_);
4120 assert(slice < this->d2_);
4121 assert(row < this->d3_);
4122 assert(range.
start() < (int)this->d4_);
4123 assert(range.
stop() < (int)this->d4_);
4127 template<
typename T>
4129 typename Array4d<T>::const_row_range_iterator
4131 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4134 assert(slab < this->d1_);
4135 assert(slice < this->d2_);
4136 assert(row < this->d3_);
4137 assert(range.
start() < (int)this->d4_);
4138 assert(range.
stop() < (int)this->d4_);
4142 template<
typename T>
4144 typename Array4d<T>::reverse_row_range_iterator
4146 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4149 assert(slab < this->d1_);
4150 assert(slice < this->d2_);
4151 assert(row < this->d3_);
4152 assert(range.
start() < (int)this->d4_);
4156 template<
typename T>
4158 typename Array4d<T>::const_reverse_row_range_iterator
4160 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4163 assert(slab < this->d1_);
4164 assert(slice < this->d2_);
4165 assert(row < this->d3_);
4166 assert(range.
start() < (int)this->d4_);
4170 template<
typename T>
4172 typename Array4d<T>::reverse_row_range_iterator
4174 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4177 assert(slab < this->d1_);
4178 assert(slice < this->d2_);
4179 assert(row < this->d3_);
4180 assert(range.
start() < (int)this->d4_);
4184 template<
typename T>
4186 typename Array4d<T>::const_reverse_row_range_iterator
4188 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type row,
4191 assert(slab < this->d1_);
4192 assert(slice < this->d2_);
4193 assert(row < this->d3_);
4194 assert(range.
start() < (int)this->d4_);
4200 template<
typename T>
4202 typename Array4d<T>::col_range_iterator
4204 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4207 assert(slab < this->d1_);
4208 assert(slice < this->d2_);
4209 assert(col < this->d4_);
4211 assert(range.
start() >= 0);
4212 assert(range.
stop() >= 0);
4213 assert(range.
start() < (int)this->d3_);
4214 assert(range.
stop() < (int)this->d3_);
4219 template<
typename T>
4221 typename Array4d<T>::const_col_range_iterator
4223 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4226 assert(slab < this->d1_);
4227 assert(slice < this->d2_);
4228 assert(col < this->d4_);
4230 assert(range.
start() >= 0);
4231 assert(range.
stop() >= 0);
4232 assert(range.
start() < (int)this->d3_);
4233 assert(range.
stop() < (int)this->d3_);
4238 template<
typename T>
4240 typename Array4d<T>::col_range_iterator
4242 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4245 assert(slab < this->d1_);
4246 assert(slice < this->d2_);
4247 assert(col < this->d4_);
4249 assert(range.
start() >= 0);
4250 assert(range.
stop() >= 0);
4251 assert(range.
start() < (int)this->d3_);
4252 assert(range.
stop() < (int)this->d3_);
4257 template<
typename T>
4259 typename Array4d<T>::const_col_range_iterator
4261 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4264 assert(slab < this->d1_);
4265 assert(slice < this->d2_);
4266 assert(col < this->d4_);
4268 assert(range.
start() >= 0);
4269 assert(range.
stop() >= 0);
4270 assert(range.
start() < (int)this->d3_);
4271 assert(range.
stop() < (int)this->d3_);
4276 template<
typename T>
4278 typename Array4d<T>::reverse_col_range_iterator
4280 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4283 assert(slab < this->d1_);
4284 assert(slice < this->d2_);
4285 assert(col < this->d4_);
4286 assert(range.
start() < (int)this->d3_);
4290 template<
typename T>
4292 typename Array4d<T>::const_reverse_col_range_iterator
4294 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4297 assert(slab < this->d1_);
4298 assert(slice < this->d2_);
4299 assert(col < this->d4_);
4300 assert(range.
start() < (int)this->d3_);
4304 template<
typename T>
4306 typename Array4d<T>::reverse_col_range_iterator
4308 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4311 assert(slab < this->d1_);
4312 assert(slice < this->d2_);
4313 assert(col < this->d4_);
4314 assert(range.
start() < (int)this->d3_);
4318 template<
typename T>
4320 typename Array4d<T>::const_reverse_col_range_iterator
4322 const typename Array4d<T>::size_type slice,
const typename Array4d<T>::size_type col,
4325 assert(slab < this->d1_);
4326 assert(slice < this->d2_);
4327 assert(col < this->d4_);
4328 assert(range.
start() < (int)this->d3_);
4339 template<
typename T>
4346 template<
typename T>
4354 template<
typename T>
4363 template<
typename T>
4372 template<
typename T>
4380 template<
typename T>
4388 template<
typename T>
4397 template<
typename T>
4408 template<
typename T>
4415 template<
typename T>
4423 template<
typename T>
4433 template<
typename T>
4443 template<
typename T>
4451 template<
typename T>
4459 template<
typename T>
4468 template<
typename T>
4479 template<
typename T>
4490 template<
typename T>
4492 typename Array4d<T>::iterator4d_range
4494 const typename Array4d<T>::range& slice_range,
4495 const typename Array4d<T>::range& row_range,
4496 const typename Array4d<T>::range& col_range)
4498 DPoint4d<int> dp(slab_range.iterations()+1,slice_range.iterations()+1,row_range.iterations()+1,
4499 col_range.iterations()+1);
4501 row_range,col_range) + dp);
4505 template<
typename T>
4507 typename Array4d<T>::const_iterator4d_range
4509 const typename Array4d<T>::range& slice_range,
4510 const typename Array4d<T>::range& row_range,
4511 const typename Array4d<T>::range& col_range)
const
4517 template<
typename T>
4519 typename Array4d<T>::const_iterator4d_range
4521 const typename Array4d<T>::range& slice_range,
4522 const typename Array4d<T>::range& row_range,
4523 const typename Array4d<T>::range& col_range)
const
4525 DPoint4d<int> dp(slab_range.iterations()+1,slice_range.iterations()+1,row_range.iterations()+1,
4526 col_range.iterations()+1);
4528 row_range,col_range) + dp);
4531 template<
typename T>
4533 typename Array4d<T>::reverse_iterator4d_range
4535 const typename Array4d<T>::range& slice_range,
4536 const typename Array4d<T>::range& row_range,
4537 const typename Array4d<T>::range& col_range)
4539 DPoint4d<int> dp(1,1,1,0);
4541 slab_range,slice_range,row_range,col_range) - dp);
4544 template<
typename T>
4546 typename Array4d<T>::const_reverse_iterator4d_range
4548 const typename Array4d<T>::range& slice_range,
4549 const typename Array4d<T>::range& row_range,
4550 const typename Array4d<T>::range& col_range)
const
4552 DPoint4d<int> dp(1,1,1,0);
4554 this->last_back_bottom_right(slab_range,slice_range,row_range,col_range)- dp));
4557 template<
typename T>
4559 typename Array4d<T>::reverse_iterator4d_range
4561 const typename Array4d<T>::range& slice_range,
4562 const typename Array4d<T>::range& row_range,
4563 const typename Array4d<T>::range& col_range)
4566 row_range,col_range));
4569 template<
typename T>
4571 typename Array4d<T>::const_reverse_iterator4d_range
4573 const typename Array4d<T>::range& slice_range,
4574 const typename Array4d<T>::range& row_range,
4575 const typename Array4d<T>::range& col_range)
const
4578 row_range,col_range));
4590 template <
typename T>
4592 std::ostream& operator<<(std::ostream & out, const Array4d<T>& a)
4594 for(std::size_t i = 0; i < a.d1_; ++i)
4596 for(std::size_t j = 0; j < a.d2_; ++j)
4598 for(std::size_t k = 0; k < a.d3_; ++k)
4600 for(std::size_t l = 0; l < a.d4_; ++l)
4602 out<<a.data_[i][j][k][l]<<
" ";
4608 out<<
"----" << std::endl << std::endl;
4620 template<
typename T>
4624 assert(this->data_ != 0);
4625 assert(l < this->d1_);
4626 return this->data_[l];
4629 template<
typename T>
4633 assert(this->data_ != 0);
4634 assert(l < this->d1_);
4635 return const_cast<const T** const*
>(this->data_[l]);
4640 template<
typename T>
4642 typename Array4d<T>::reference
4644 const typename Array4d<T>::size_type i,
4645 const typename Array4d<T>::size_type j)
4647 assert(this->data_ != 0);
4648 assert(l < this->d1_);
4649 assert(k < this->d2_);
4650 assert(i < this->d3_);
4651 assert(j < this->d4_);
4652 return this->data_[l][k][i][j];
4655 template<
typename T>
4657 typename Array4d<T>::const_reference
4659 const typename Array4d<T>::size_type i,
4660 const typename Array4d<T>::size_type j)
const
4662 assert(this->data_ != 0);
4663 assert(l < this->d1_);
4664 assert(k < this->d2_);
4665 assert(i < this->d3_);
4666 assert(j < this->d4_);
4667 return this->data_[l][k][i][j];
4671 template<
typename T>
4677 template<
typename T>
4682 template<
typename T>
4687 template<
typename T>
4692 template<
typename T>
4697 template<
typename T>
4702 template<
typename T>
4707 template<
typename T>
4712 template<
typename T>
4717 template<
typename T>
4723 template<
typename T>
4728 template<
typename T>
4736 template<
typename T>
4740 template<
typename T>
4744 assert(this->d1_ == M.d1_);
4745 assert(this->d2_ == M.d2_);
4746 assert(this->d3_ == M.d3_);
4747 assert(this->d4_ == M.d4_);
4748 std::swap_ranges(this->begin(),this->end(),M.
begin());
4757 template<
typename T>
4766 template<
typename T>
4776 template<
typename T>
4778 bool operator<(const Array4d<T>& x,
4781 return std::lexicographical_compare(x.begin(), x.end(),
4782 y.begin(), y.end());
4786 template<
typename T>
4794 template<
typename T>
4796 bool operator<=(const Array4d<T>& x,
4802 template<
typename T>
4818 template<
typename T>
4820 void Array4d<T>::allocate()
4822 if( this->d1_ != 0 && this->d2_ != 0 && this->d3_ != 0 && this->d4_ != 0)
4824 this->data_ =
new T***[this->d1_];
4825 this->data_[0] =
new T**[this->d1_ * this->d2_];
4826 this->data_[0][0] =
new T*[this->d1_ * this->d2_ * this->d3_];
4827 this->data_[0][0][0] =
new T[this->d1_ * this->d2_ * this->d3_ * this->d4_];
4829 for(std::size_t l = 0; l < this->d1_; ++l)
4832 this->data_[l] = this->data_[0] + l * this->d2_;
4833 for(std::size_t k = 0; k < this->d2_; ++k){
4835 this->data_[l][k] = this->data_[0][0] + l * this->d2_ * this->d3_ + k * this->d3_;
4836 for(std::size_t i = 0; i < this->d3_; ++i){
4838 this->data_[l][k][i] = this->data_[0][0][0] + l * this->d2_ * this->d3_ * this->d4_
4839 + k * this->d3_ * this->d4_ + i * this->d4_;
4850 template<
typename T>
4852 void Array4d<T>::desallocate()
4854 if(this->data_ != 0)
4856 delete[] (this->data_[0][0][0]);
4857 delete[] (this->data_[0][0]);
4858 delete[] (this->data_[0]);
4859 delete[] (this->data_);
4863 template<
typename T>
4865 void Array4d<T>::copy_attributes(
const Array4d<T>& rhs)
4867 this->d1_ = rhs.d1_;
4868 this->d2_ = rhs.d2_;
4869 this->d3_ = rhs.d3_;
4870 this->d4_ = rhs.d4_;
4871 this->size_ = rhs.size_;
4879 #endif //SLIP_ARRAY4D_HH
col_iterator col_begin(const size_type slab, const size_type slice, const size_type col)
Returns a read/write iterator that points to the first element of the column column of a given slab s...
reverse_iterator4d rfirst_front_upper_left()
Returns a read/write reverse iterator4d. It points to the last back bottom right element of the Array...
slip::stride_iterator< const_pointer > const_row_range_iterator
bool operator!=(const Array< T > &x, const Array< T > &y)
This is some iterator to iterate a 4d container into a Box area defined by the subscripts of the 4d c...
std::size_t iterations() const
Rerturns the number of iterations of the range.
reverse_row_iterator row_rend(const size_type slab, const size_type slice, const size_type row)
Returns a read/write reverse iterator that points to the first element of the row row of a given slab...
slip::Array4d< unsigned long > Array4d_ul
unsigned long alias
reverse_iterator4d rlast_back_bottom_right()
Returns a read/write reverse iterator4d. It points to past the first front upper left element of the ...
reverse_slice_iterator slice_rend(const size_type slab, const size_type row, const size_type col)
Returns a read/write iterator that points to the one before the first element of the line (slab...
std::reverse_iterator< const_row_range_iterator > const_reverse_row_range_iterator
size_type dim4() const
Returns the number of columns (fourth dimension size) in the Array4d.
iterator4d last_back_bottom_right()
Returns a read/write iterator4d that points to the past the end element of the Array4d. It points to past the end element of the last back bottom right element of the Array4d.
slip::stride_iterator< const_slice_iterator > const_slice_range_iterator
slip::stride_iterator< const_pointer > const_slab_iterator
size_type columns() const
Returns the number of columns (fourth dimension size) in the Array4d.
iterator4d default_iterator
slip::Array4d< unsigned int > Array4d_ui
unsigned int alias
CoordType depth() const
compute the depth of the Box4d (second dimension size).
value_type const * const_pointer
T *** operator[](const size_type l)
This is some iterator to iterate a 4d container into two Range defined by the indices and strides of ...
iterator end()
Returns a read/write iterator that points one past the last element in the Array4d. Iteration is done in ordinary element order.
size_type max_size() const
Returns the maximal size (number of elements) in the Array4d.
self & operator=(const Array4d< T > &rhs)
Assign a Array4d.
This is some iterator to iterate a 4d container into a Box area defined by the subscripts of the 4d c...
row_iterator row_end(const size_type slab, const size_type slice, const size_type row)
Returns a read/write iterator that points to the past-the-end element of the row row of a given slab ...
size_type slabs() const
Returns the number of slabs (first dimension size, called time dimension too) in the Array4d...
slip::stride_iterator< col_iterator > col_range_iterator
Provides a class to modelize 4d points.
std::reverse_iterator< slice_range_iterator > reverse_slice_range_iterator
std::reverse_iterator< const_col_iterator > const_reverse_col_iterator
slip::stride_iterator< const_col_iterator > const_col_range_iterator
std::reverse_iterator< const_iterator4d_range > const_reverse_iterator4d_range
Array4d(const size_type d1, const size_type d2, const size_type d3, const size_type d4, InputIterator first, InputIterator last)
Contructs a Array4d from a range.
slab_iterator slab_end(const size_type slice, const size_type row, const size_type col)
Returns a read/write iterator that points to the one past the end element of the line (slice...
value_type const * const_iterator
slip::Array4d< unsigned short > Array4d_us
unsigned long alias
reverse_slab_iterator slab_rend(const size_type slice, const size_type row, const size_type col)
Returns a read/write iterator that points to the one before the first element of the line (slice...
size_type dim2() const
Returns the number of slices (second dimension size) in the Array4d.
std::reverse_iterator< const_iterator4d > const_reverse_iterator4d
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Array4d. Iteration is done in reverse element order.
reverse_row_iterator row_rbegin(const size_type slab, const size_type slice, const size_type row)
Returns a read/write reverse iterator that points to the last element of the row row of a given slab ...
const_iterator4d const_default_iterator
slab_iterator slab_begin(const size_type slice, const size_type row, const size_type col)
Returns a read/write iterator that points to the first element of the line (slice,row,col) through the slabs in the Array4d. Iteration is done in ordinary element order (increasing slab number).
bool operator>(const Array< T > &x, const Array< T > &y)
slip::iterator4d_box< self > iterator4d
iterator4d first_front_upper_left()
Returns a read/write iterator4d that points to the first element of the Array4d. It points to the fir...
const Array4d< T > const_self
reverse_col_iterator col_rbegin(const size_type slab, const size_type slice, const size_type col)
Returns a read/write reverse iterator that points to the last element of the column column of a given...
std::reverse_iterator< const_iterator > const_reverse_row_iterator
std::reverse_iterator< iterator > reverse_iterator
std::reverse_iterator< col_range_iterator > reverse_col_range_iterator
size_type dim3() const
Returns the number of rows (third dimension size) in the Array4d.
std::reverse_iterator< iterator4d > reverse_iterator4d
Difference of Point4D class, specialization of DPoint<CoordType,DIM> with DIM = 4.
reverse_slab_iterator slab_rbegin(const size_type slice, const size_type row, const size_type col)
Returns a read/write iterator that points to the last element of the line (slice,row,col) through the slabs in the Array4d. Iteration is done in reverse element order (decreasing slab number).
void fill(const T *value)
Fills the container range [begin(),begin()+size()) with a copy of the value array.
reference operator()(const size_type l, const size_type k, const size_type i, const size_type j)
Subscript access to the data contained in the Array4d.
Provides a class to modelize the difference of 4d points.
slip::stride_iterator< slice_iterator > slice_range_iterator
slip::stride_iterator< pointer > col_iterator
void resize(std::size_t d1, std::size_t d2, std::size_t d3, std::size_t d4, const T &val=T())
Resizes a Array4d.
slip::stride_iterator< const_pointer > const_slice_iterator
slip::Array4d< char > Array4d_c
char alias
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
std::reverse_iterator< slice_range_iterator > reverse_slab_range_iterator
bool is_valid() const
Returns true if the range is valid :
SubType start() const
Accessor of the start subscript of the Range.
slip::iterator4d_range< self > iterator4d_range
void fill(const T &value)
Fills the container range [begin(),begin()+size()) with copies of value.
slip::Array4d< unsigned char > Array4d_uc
unsigned char alias
size_type size() const
Returns the number of elements in the Array4d.
std::reverse_iterator< const_slice_iterator > const_reverse_slice_iterator
value_type const & const_reference
This is a four-dimensional dynamic and generic container. This container statisfies the Bidirectionna...
std::reverse_iterator< slice_iterator > reverse_slice_iterator
~Array4d()
Destructor of the Array4d.
slip::stride_iterator< pointer > row_range_iterator
row_iterator row_begin(const size_type slab, const size_type slice, const size_type row)
Returns a read/write iterator that points to the first element of the row row of a given slab slab an...
size_type rows() const
Returns the number of rows (third dimension size) in the Array4d.
std::reverse_iterator< const_col_range_iterator > const_reverse_col_range_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
std::reverse_iterator< iterator > reverse_row_iterator
slip::Array4d< double > Array4d_d
double alias
col_iterator col_end(const size_type slab, const size_type slice, const size_type col)
Returns a read/write iterator that points to the past-the-end element of the column column of a given...
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
reverse_col_iterator col_rend(const size_type slab, const size_type slice, const size_type col)
Returns a read/write reverse iterator that points to the first element of the column column of a give...
slip::stride_iterator< pointer > slice_iterator
size_type dim1() const
Returns the number of slabs (first dimension size, called time dimension too) in the Array4d...
CoordType width() const
compute the width of the Box4d (fourth dimension size).
size_type slices() const
Returns the number of slices (second dimension size) in the Array4d.
Provides a class to manipulate 4d box.
bool empty() const
Returns true if the Array4d is empty. (Thus size() == 0)
size_type cols() const
Returns the number of columns (fourth dimension size) in the Array4d.
Some const iterator to iterate a 4d container into two Range defined by the indices and strides of th...
slip::stride_iterator< slab_iterator > slab_range_iterator
slip::const_iterator4d_box< const_self > const_iterator4d
slip::Array4d< int > Array4d_i
int alias
std::string name() const
Returns the name of the class.
std::reverse_iterator< const_slice_range_iterator > const_reverse_slice_range_iterator
std::reverse_iterator< col_iterator > reverse_col_iterator
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+size()) with a copy of the range [first,last)
slip::stride_iterator< pointer > slab_iterator
int stride() const
Accessor of the stride of the Range.
CoordType duration() const
compute the duration of the Box4d (first dimension size).
slip::stride_iterator< const_slab_iterator > const_slab_range_iterator
std::reverse_iterator< row_range_iterator > reverse_row_range_iterator
ptrdiff_t difference_type
Provides a class to manipulate iterator4d within a slip::Range. It is used to iterate throw 4d contai...
void swap(Array4d &M)
Swaps data with another Array4d.
Provides a class to iterate a 1d range according to a step.
const_pointer const_row_iterator
slip::Array4d< short > Array4d_s
short alias
CoordType height() const
compute the height of the Box4d (third dimension size).
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Array4d...
slip::stride_iterator< const_pointer > const_col_iterator
slice_iterator slice_begin(const size_type slab, const size_type row, const size_type col)
Returns a read/write iterator that points to the first element of the line (slab,row,col) through the slices in the Array4d. Iteration is done in ordinary element order (increasing slice number).
bool operator==(const Array< T > &x, const Array< T > &y)
std::reverse_iterator< iterator4d_range > reverse_iterator4d_range
slip::const_iterator4d_range< const_self > const_iterator4d_range
slip::Array4d< float > Array4d_f
float alias
static const std::size_t DIM
slip::Array4d< long > Array4d_l
long alias
reverse_slice_iterator slice_rbegin(const size_type slab, const size_type row, const size_type col)
Returns a read/write iterator that points to the last element of the line (slab,row,col) through the slices in the Array4d. Iteration is done in reverse element order (decreasing slice number).
Provides a class to manipulate iterator4d within a slip::Box4d. It is used to iterate throw 4d contai...
slice_iterator slice_end(const size_type slab, const size_type row, const size_type col)
Returns a read/write iterator that points to the one past the end element of the line (slab...
Array4d()
Constructs a Array4d.
std::reverse_iterator< const_slab_iterator > const_reverse_slab_iterator
SubType stop() const
Accessor of the stop subscript of the Range.
bool operator>=(const Array< T > &x, const Array< T > &y)
std::reverse_iterator< const_slice_range_iterator > const_reverse_slab_range_iterator
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the Array4d. Iteration is done in ordinary element order.
std::reverse_iterator< slab_iterator > reverse_slab_iterator
friend class boost::serialization::access