79 #ifndef SLIP_ARRAY2D_HPP
80 #define SLIP_ARRAY2D_HPP
96 #include <boost/serialization/access.hpp>
97 #include <boost/serialization/split_member.hpp>
98 #include <boost/serialization/string.hpp>
99 #include <boost/serialization/complex.hpp>
100 #include <boost/serialization/version.hpp>
134 template <
typename T>
137 template <
typename T>
150 bool operator<(const slip::Array2d<T>& x,
158 bool operator<=(const slip::Array2d<T>& x,
188 template <
typename T>
246 static const std::size_t
DIM = 2;
297 template<
typename InputIterator>
302 d1_(d1),d2_(d2),size_(d1*d2)
305 std::fill_n(this->
begin(),this->size_,T());
1884 friend std::ostream& operator<< <>(std::ostream & out,
1925 std::fill_n(this->
begin(),this->size_,value);
1947 template<
typename InputIterator>
1965 friend bool operator== <>(
const Array2d<T>& x,
1974 friend bool operator!= <>(
const Array2d<T>& x,
1983 friend bool operator< <>(
const Array2d<T>& x,
1992 friend bool operator> <>(
const Array2d<T>& x,
2001 friend bool operator<= <>(
const Array2d<T>& x,
2010 friend bool operator>= <>(
const Array2d<T>& x,
2125 std::string
name()
const;
2196 void copy_attributes(
const self& rhs);
2200 template<
class Archive>
2201 void save(Archive & ar,
const unsigned int version)
const
2203 ar & this->d1_ & this->d2_ & this->size_ ;
2204 for(std::size_t i = 0; i < this->size_; ++i)
2209 template<
class Archive>
2210 void load(Archive & ar,
const unsigned int version)
2212 ar & this->d1_ & this->d2_ & this->size_ ;
2213 this->desallocate();
2215 for(std::size_t i = 0; i < this->size_; ++i)
2220 BOOST_SERIALIZATION_SPLIT_MEMBER();
2251 template<
typename T>
2254 d1_(0),d2_(0),size_(0),data_(0)
2257 template<
typename T>
2261 d1_(d1),d2_(d2),size_(d1*d2)
2264 std::fill_n(this->data_[0],this->size_,T());
2267 template<
typename T>
2272 d1_(d1),d2_(d2),size_(d1*d2)
2275 std::fill_n(this->data_[0],this->size_,val);
2278 template<
typename T>
2283 d1_(d1),d2_(d2),size_(d1*d2)
2286 std::copy(val,val + this->size_, this->data_[0]);
2289 template<
typename T>
2292 d1_(rhs.d1_),d2_(rhs.d2_),size_(rhs.size_)
2295 if(this->size_ != 0)
2297 std::copy(rhs.data_[0],rhs.data_[0] + this->size_,this->data_[0]);
2301 template<
typename T>
2307 if( this->d1_ != rhs.d1_ || this->d2_ != rhs.d2_)
2309 this->desallocate();
2310 this->copy_attributes(rhs);
2315 std::copy(rhs.data_[0],rhs.data_[0] + this->size_,this->data_[0]);
2321 template<
typename T>
2327 if( this->d1_ != d1 || this->d2_ != d2 )
2329 this->desallocate();
2332 this->size_ = d1 * d2;
2335 if((this->d1_ != 0) && (this->d2_ != 0))
2337 std::fill_n(this->data_[0],this->size_,val);
2343 template<
typename T>
2347 return this->data_[0];
2350 template<
typename T>
2354 return this->data_[0] + this->size_;
2357 template<
typename T>
2361 return this->data_[0];
2364 template<
typename T>
2368 return this->data_[0] + this->size_;
2372 template<
typename T>
2379 template<
typename T>
2386 template<
typename T>
2394 template<
typename T>
2401 template<
typename T>
2406 assert(row < this->d1_);
2407 return this->data_[row];
2410 template<
typename T>
2412 typename Array2d<T>::const_row_iterator
2415 assert(row < this->d1_);
2416 return this->data_[row];
2419 template<
typename T>
2421 typename Array2d<T>::row_range_iterator
2425 assert(row < this->d1_);
2427 assert(range.
start() >= 0);
2428 assert(range.
stop() >= 0);
2429 assert(range.
start() < (int)this->d2_);
2430 assert(range.
stop() < (int)this->d2_);
2434 template<
typename T>
2436 typename Array2d<T>::const_row_range_iterator
2440 assert(row < this->d1_);
2442 assert(range.
start() >= 0);
2443 assert(range.
stop() >= 0);
2444 assert(range.
start() < (int)this->d2_);
2445 assert(range.
stop() < (int)this->d2_);
2449 template<
typename T>
2451 typename Array2d<T>::col_range_iterator
2455 assert(col < this->d2_);
2457 assert(range.
start() >= 0);
2458 assert(range.
stop() >= 0);
2459 assert(range.
start() < (int)this->d1_);
2460 assert(range.
stop() < (int)this->d1_);
2464 template<
typename T>
2466 typename Array2d<T>::const_col_range_iterator
2470 assert(col < this->d2_);
2472 assert(range.
start() >= 0);
2473 assert(range.
stop() >= 0);
2474 assert(range.
start() < (int)this->d1_);
2475 assert(range.
stop() < (int)this->d1_);
2479 template<
typename T>
2481 typename Array2d<T>::row_iterator
2484 assert(row < this->d1_);
2485 return this->data_[row] + this->d2_;
2488 template<
typename T>
2490 typename Array2d<T>::const_row_iterator
2493 assert(row < this->d1_);
2494 return this->data_[row] + this->d2_;
2497 template<
typename T>
2499 typename Array2d<T>::row_range_iterator
2503 assert(row < this->d1_);
2504 assert(range.
start() < (int)this->d2_);
2505 assert(range.
stop() < (int)this->d2_);
2507 return ++(this->row_begin(row,range) + range.
iterations());
2510 template<
typename T>
2512 typename Array2d<T>::const_row_range_iterator
2516 assert(row < this->d1_);
2517 assert(range.
start() < (int)this->d2_);
2518 assert(range.
stop() < (int)this->d2_);
2520 return ++(this->row_begin(row,range) + range.
iterations());
2523 template<
typename T>
2525 typename Array2d<T>::col_range_iterator
2529 assert(col < this->d2_);
2530 assert(range.
start() < (int)this->d1_);
2531 assert(range.
stop() < (int)this->d1_);
2533 return ++(this->col_begin(col,range) + range.
iterations());
2536 template<
typename T>
2538 typename Array2d<T>::const_col_range_iterator
2542 assert(col < this->d2_);
2543 assert(range.
start() < (int)this->d1_);
2544 assert(range.
stop() < (int)this->d1_);
2546 return ++(this->col_begin(col,range) + range.
iterations());
2549 template<
typename T>
2551 typename Array2d<T>::col_iterator
2554 assert(col < this->d2_);
2558 template<
typename T>
2560 typename Array2d<T>::const_col_iterator
2563 assert(col < this->d2_);
2567 template<
typename T>
2569 typename Array2d<T>::col_iterator
2572 assert(col < this->d2_);
2576 template<
typename T>
2578 typename Array2d<T>::const_col_iterator
2581 assert(col < this->d2_);
2586 template<
typename T>
2588 typename Array2d<T>::reverse_row_iterator
2594 template<
typename T>
2596 typename Array2d<T>::const_reverse_row_iterator
2602 template<
typename T>
2604 typename Array2d<T>::reverse_row_iterator
2610 template<
typename T>
2612 typename Array2d<T>::const_reverse_row_iterator
2619 template<
typename T>
2621 typename Array2d<T>::reverse_col_iterator
2627 template<
typename T>
2629 typename Array2d<T>::const_reverse_col_iterator
2635 template<
typename T>
2637 typename Array2d<T>::reverse_col_iterator
2643 template<
typename T>
2645 typename Array2d<T>::const_reverse_col_iterator
2651 template<
typename T>
2653 typename Array2d<T>::reverse_row_range_iterator
2657 assert(row < this->d1_);
2658 assert(range.
start() < (int)this->d2_);
2662 template<
typename T>
2664 typename Array2d<T>::const_reverse_row_range_iterator
2668 assert(row < this->d1_);
2669 assert(range.
start() < (int)this->d2_);
2674 template<
typename T>
2676 typename Array2d<T>::reverse_col_range_iterator
2680 assert(col < this->d2_);
2681 assert(range.
start() < (int)this->d1_);
2685 template<
typename T>
2687 typename Array2d<T>::const_reverse_col_range_iterator
2691 assert(col < this->d2_);
2692 assert(range.
start() < (int)this->d1_);
2696 template<
typename T>
2698 typename Array2d<T>::reverse_row_range_iterator
2702 assert(row < this->d1_);
2703 assert(range.
start() < (int)this->d2_);
2707 template<
typename T>
2709 typename Array2d<T>::const_reverse_row_range_iterator
2713 assert(row < this->d1_);
2714 assert(range.
start() < (int)this->d2_);
2719 template<
typename T>
2721 typename Array2d<T>::reverse_col_range_iterator
2725 assert(col < this->d2_);
2726 assert(range.
start() < (int)this->d1_);
2730 template<
typename T>
2732 typename Array2d<T>::const_reverse_col_range_iterator
2736 assert(col < this->d2_);
2737 assert(range.
start() < (int)this->d1_);
2742 template<
typename T>
2749 template<
typename T>
2757 template<
typename T>
2766 template<
typename T>
2775 template<
typename T>
2782 template<
typename T>
2790 template<
typename T>
2800 template<
typename T>
2810 template<
typename T>
2819 template<
typename T>
2828 template<
typename T>
2838 template<
typename T>
2849 template<
typename T>
2854 return this->upper_left(range,range);
2857 template<
typename T>
2862 return this->upper_left(range,range);
2865 template<
typename T>
2870 return this->bottom_right(range,range);
2873 template<
typename T>
2878 return this->bottom_right(range,range);
2881 template<
typename T>
2889 template<
typename T>
2897 template<
typename T>
2906 template<
typename T>
2915 template<
typename T>
2923 template<
typename T>
2931 template<
typename T>
2940 template<
typename T>
2949 template<
typename T>
2959 template<
typename T>
2969 template<
typename T>
2978 template<
typename T>
2987 template<
typename T>
2992 return this->rupper_left(range,range);
2995 template<
typename T>
3000 return this->rupper_left(range,range);
3003 template<
typename T>
3008 return this->rbottom_right(range,range);
3011 template<
typename T>
3016 return this->rbottom_right(range,range);
3021 template <
typename T>
3023 std::ostream& operator<<(std::ostream & out, const Array2d<T>& a)
3025 for(std::size_t i = 0; i < a.d1_; ++i)
3027 for(std::size_t j = 0; j < a.d2_; ++j)
3038 template<
typename T>
3040 typename Array2d<T>::pointer
3043 assert(this->data_ != 0);
3044 assert(i < this->size_);
3045 return this->data_[i];
3048 template<
typename T>
3050 typename Array2d<T>::const_pointer
3053 assert(this->data_ != 0);
3054 assert(i < this->size_);
3055 return this->data_[i];
3058 template<
typename T>
3060 typename Array2d<T>::reference
3062 const typename Array2d<T>::size_type j)
3064 assert(this->data_ != 0);
3065 assert(i < this->d1_);
3066 assert(j < this->d2_);
3067 return this->data_[i][j];
3070 template<
typename T>
3072 typename Array2d<T>::const_reference
3074 const typename Array2d<T>::size_type j)
const
3076 assert(this->data_ != 0);
3077 assert(i < this->d1_);
3078 assert(j < this->d2_);
3079 return this->data_[i][j];
3082 template<
typename T>
3084 typename Array2d<T>::reference
3087 assert(this->data_ != 0);
3088 assert(point2d[0] < this->d1_);
3089 assert(point2d[1] < this->d2_);
3090 return this->data_[point2d[0]][point2d[1]];
3093 template<
typename T>
3095 typename Array2d<T>::const_reference
3098 assert(this->data_ != 0);
3099 assert(point2d[0] < this->d1_);
3100 assert(point2d[1] < this->d2_);
3101 return this->data_[point2d[0]][point2d[1]];
3105 template<
typename T>
3111 assert(this->data_ != 0);
3113 assert(row_range.
start() < (int)this->d2_);
3114 assert(row_range.
stop() < (int)this->d2_);
3116 assert(col_range.
start() < (int)this->d1_);
3117 assert(col_range.
stop() < (int)this->d1_);
3118 std::size_t rows = row_range.
iterations() + 1;
3119 std::size_t cols = col_range.
iterations() + 1;
3120 return Array2d<T>(rows,cols,this->upper_left(row_range,col_range),
3121 this->bottom_right(row_range,col_range));
3125 template<
typename T>
3131 template<
typename T>
3136 template<
typename T>
3142 template<
typename T>
3147 template<
typename T>
3152 template<
typename T>
3157 template<
typename T>
3162 template<
typename T>
3171 template<
typename T>
3175 template<
typename T>
3179 assert(this->d1_ == M.d1_);
3180 assert(this->d2_ == M.d2_);
3181 std::swap_ranges(this->begin(),this->end(),M.
begin());
3184 template<
typename T>
3188 this->desallocate();
3191 template<
typename T>
3195 if((this->d1_ != 0) && (this->d2_ != 0))
3197 this->data_ =
new T*[this->d1_];
3200 this->data_[0] =
new T[this->d1_ * this->d2_];
3205 this->data_[i] = this->data_[i - 1] + this->d2_;
3214 template<
typename T>
3216 void Array2d<T>::desallocate()
3218 if(this->data_ != 0)
3220 delete[] (this->data_[0]);
3221 delete[] (this->data_);
3225 template<
typename T>
3227 void Array2d<T>::copy_attributes(
const Array2d<T>& rhs)
3229 this->d1_ = rhs.d1_;
3230 this->d2_ = rhs.d2_;
3231 this->size_ = rhs.d1_ * rhs.d2_;
3236 template<
typename T>
3245 template<
typename T>
3257 template<
typename T>
3259 bool operator<(const Array2d<T>& x,
3262 return std::lexicographical_compare(x.begin(), x.end(),
3263 y.begin(), y.end());
3267 template<
typename T>
3275 template<
typename T>
3277 bool operator<=(const Array2d<T>& x,
3283 template<
typename T>
3294 #endif //SLIP_ARRAY2D_HPP
bool operator!=(const Array< T > &x, const Array< T > &y)
std::size_t iterations() const
Rerturns the number of iterations of the range.
iterator2d upper_left()
Returns a read/write iterator2d that points to the first element of the Array2d. It points to the upp...
Provides a class to modelize the difference of slip::Point2d.
void fill(const T *value)
Fills the container range [begin(),begin()+size()) with a copy of the value array.
CoordType height() const
compute the height of the Box2d.
std::reverse_iterator< const_iterator2d > const_reverse_iterator2d
std::reverse_iterator< const_col_iterator > const_reverse_col_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Provides a class to manipulate 2d box.
slip::iterator2d_box< self > iterator2d
This is some iterator to iterate a 2d container into two Range defined by the indices and strides of ...
Array2d(const size_type d1, const size_type d2, InputIterator first, InputIterator last)
Contructs a Array2d from a range.
Provides a class to manipulate iterator2d within a slip::Box2d. It is used to iterate throw 2d contai...
reverse_iterator2d rupper_left()
Returns a read/write reverse iterator2d. It points to the bottom right element of the Array2d...
iterator2d bottom_right()
Returns a read/write iterator2d that points to the past the end element of the Array2d. It points to past the end element of the bottom right element of the Array2d.
CoordType width() const
compute the width of the Box2d.
reference operator()(const size_type i, const size_type j)
Subscript access to the data contained in the Array2d.
slip::stride_iterator< const_pointer > const_col_iterator
ptrdiff_t difference_type
slip::Array2d< unsigned int > Array2d_ui
unsigned int alias
slip::const_iterator2d_box< const_self > const_iterator2d
size_type max_size() const
Returns the maximal size (number of elements) in the Array2d.
value_type const & const_reference
reverse_iterator2d rbottom_right()
Returns a read/write reverse iterator2d. It points to past the upper left element of the Array2d...
slip::Array2d< short > Array2d_s
short alias
size_type size() const
Returns the number of elements in the Array2d.
friend class boost::serialization::access
bool operator>(const Array< T > &x, const Array< T > &y)
std::reverse_iterator< col_iterator > reverse_col_iterator
slip::stride_iterator< const_pointer > const_row_range_iterator
reverse_col_iterator col_rbegin(const size_type col)
Returns a read/write reverse iterator that points to the last element of the column column in the Arr...
This is a point2d class, a specialized version of Point<CoordType,DIM> with DIM = 2...
~Array2d()
Destructor of the Array2d.
pointer operator[](const size_type i)
Subscript access to the row datas contained in the Array2d.
This is some iterator to iterate a 2d container into a Box area defined by the indices of the 2d cont...
size_type columns() const
Returns the number of columns (second dimension size) in the Array2d.
void resize(const size_type d1, const size_type d2, const T &val=T())
Resizes a Array2d.
slip::Array2d< unsigned long > Array2d_ul
unsigned long alias
slip::Array2d< int > Array2d_i
int alias
size_type dim2() const
Returns the number of columns (second dimension size) in the Array2d.
reverse_row_iterator row_rend(const size_type row)
Returns a read/write reverse iterator that points one past the first element of the row row in the Ar...
self & operator=(const self &rhs)
Assign a Array2d.
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Array2d. Iteration is done in reverse element order.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Difference of Point2D class, specialization of DPoint<CoordType,DIM> with DIM = 2.
bool is_valid() const
Returns true if the range is valid :
SubType start() const
Accessor of the start subscript of the Range.
const Array2d< T > const_self
size_type rows() const
Returns the number of rows (first dimension size) in the Array2d.
col_iterator col_begin(const size_type col)
Returns a read/write iterator that points to the first element of the column column in the Array2d...
slip::Array2d< double > Array2d_d
double alias
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Array2d...
slip::Array2d< long > Array2d_l
long alias
iterator end()
Returns a read/write iterator that points one past the last element in the Array2d. Iteration is done in ordinary element order.
This is some iterator to iterate a 2d container into a slip::Box2d area defined by the indices of the...
slip::stride_iterator< col_iterator > col_range_iterator
std::reverse_iterator< col_range_iterator > reverse_col_range_iterator
void swap(self &M)
Swaps data with another Array.
row_iterator row_begin(const size_type row)
Returns a read/write iterator that points to the first element of the row row in the Array2d...
std::string name() const
Returns the name of the class.
std::reverse_iterator< iterator2d_range > reverse_iterator2d_range
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
iterator2d default_iterator
std::reverse_iterator< const_iterator > const_reverse_row_iterator
slip::Array2d< float > Array2d_f
float alias
std::reverse_iterator< const_col_range_iterator > const_reverse_col_range_iterator
slip::iterator2d_range< self > iterator2d_range
std::reverse_iterator< iterator > reverse_iterator
size_type cols() const
Returns the number of columns (second dimension size) in the Array2d.
const_pointer const_row_iterator
void fill(const T &value)
Fills the container range [begin(),begin()+size()) with copies of value.
bool empty() const
Returns true if the Array2d is empty. (Thus size() == 0)
This is some iterator to iterate a 2d container into two Range defined by the indices and strides of ...
slip::stride_iterator< pointer > row_range_iterator
Array2d()
Constructs a Array2d.
std::reverse_iterator< row_range_iterator > reverse_row_range_iterator
col_iterator col_end(const size_type col)
Returns a read/write iterator that points one past the end element of the column column in the Array2...
const_iterator2d const_default_iterator
slip::stride_iterator< const_col_iterator > const_col_range_iterator
slip::Array2d< char > Array2d_c
char alias
int stride() const
Accessor of the stride of the Range.
row_iterator row_end(const size_type row)
Returns a read/write iterator that points one past the end element of the row row in the Array2d...
slip::const_iterator2d_range< const_self > const_iterator2d_range
Provides a class to modelize 2d points.
Provides a class to iterate a 1d range according to a step.
const_pointer const_iterator
iterator begin()
Returns a read/write iterator that points to the first element in the Array2d. Iteration is done in o...
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+size()) with a copy of the range [first,last)
value_type const * const_pointer
std::reverse_iterator< iterator2d > reverse_iterator2d
bool operator==(const Array< T > &x, const Array< T > &y)
slip::Array2d< unsigned short > Array2d_us
unsigned long alias
static const std::size_t DIM
slip::Array2d< unsigned char > Array2d_uc
unsigned char alias
std::reverse_iterator< iterator > reverse_row_iterator
std::reverse_iterator< const_iterator2d_range > const_reverse_iterator2d_range
std::reverse_iterator< const_row_range_iterator > const_reverse_row_range_iterator
Provides a class to manipulate Ranges.
Provides a class to manipulate iterator2d within a slip::Range. It is used to iterate throw 2d contai...
reverse_row_iterator row_rbegin(const size_type row)
Returns a read/write reverse iterator that points to the last element of the row row in the Array2d...
This is a two-dimensional dynamic and generic container. This container statisfies the Bidirectionnal...
SubType stop() const
Accessor of the stop subscript of the Range.
bool operator>=(const Array< T > &x, const Array< T > &y)
self & operator=(const T &value)
Assign all the elments of the Array2d by value.
size_type dim1() const
Returns the number of rows (first dimension size) in the Array2d.
reverse_col_iterator col_rend(const size_type col)
Returns a read/write reverse iterator that points one past the first element of the column column in ...
slip::stride_iterator< pointer > col_iterator