SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Block.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
68 
75 #ifndef SLIP_BLOCK_HPP
76 #define SLIP_BLOCK_HPP
77 
78 #include <iterator>
79 #include <iostream>
80 #include <cstddef>
81 #include "Range.hpp"
82 #include "stride_iterator.hpp"
83 
84 #include <boost/serialization/access.hpp>
85 #include <boost/serialization/split_member.hpp>
86 #include <boost/serialization/string.hpp>
87 #include <boost/serialization/complex.hpp>
88 #include <boost/serialization/version.hpp>
89 
90 namespace slip
91 {
92 
93 template <class T, std::size_t N>
94 struct block;
95 
96 template <typename T, std::size_t N>
97 std::ostream& operator<<(std::ostream & out,
98  const block<T,N>& b);
99 
100 template <typename T, std::size_t N>
101 bool operator==(const block<T,N>& x,
102  const block<T,N>& y);
103 
104 template <typename T, std::size_t N>
105 bool operator!=(const block<T,N>& x,
106  const block<T,N>& y);
107 
108 template <typename T, std::size_t N>
109 bool operator<(const block<T,N>& x,
110  const block<T,N>& y);
111 
112 template <typename T, std::size_t N>
113 bool operator>(const block<T,N>& x,
114  const block<T,N>& y);
115 
116 template <typename T, std::size_t N>
117 bool operator<=(const block<T,N>& x,
118  const block<T,N>& y);
119 
120 template <typename T, std::size_t N>
121 bool operator>=(const block<T,N>& x,
122  const block<T,N>& y);
123 
129  /* @} end of Containers group */
130 
143 template <class T, std::size_t N>
144 struct block{
145 
146  typedef block<T,N> self;
147  typedef T value_type;
148  typedef value_type* pointer;
149  typedef const value_type* const_pointer;
151  typedef const value_type& const_reference;
152 
153  typedef ptrdiff_t difference_type;
154  typedef std::size_t size_type;
155 
156  typedef pointer iterator;
158 
161 
162  typedef std::reverse_iterator<iterator> reverse_iterator;
163  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
164 
165  typedef std::reverse_iterator<iterator_range> reverse_iterator_range;
166  typedef std::reverse_iterator<const_iterator_range> const_reverse_iterator_range;
167 
168  //default iterator of the container
171 
172  static const std::size_t SIZE = N;
173  static const std::size_t DIM = 1;
174 
179 
180 
189  iterator begin(){return this->data;}
190 
191 
200  const_iterator begin() const {return this->data;}
201 
210  iterator end(){return this->data + N;}
211 
220  const_iterator end() const {return this->data + N;}
221 
231 
241 
251 
252 
262 
282  {
283  assert(range.is_valid());
284  assert(range.start() >= 0);
285  assert(range.stop() >= 0);
286  assert(range.start() < int(this->size()));
287  assert(range.stop() < int(this->size()));
288  return iterator_range(this->begin() + range.start(),range.stride());
289  }
290 
310  {
311  assert(range.is_valid());
312  assert(range.start() >= 0);
313  assert(range.stop() >= 0);
314  assert(range.start() < int(this->size()));
315  assert(range.stop() < int(this->size()));
316  return const_iterator_range(this->begin() + range.start(),range.stride());
317  }
318 
337  {
338  return this->begin(range) + (range.iterations() + 1);
339  }
340 
360  {
361  return this->begin(range) + (range.iterations() + 1);
362  }
363 
364  //
384  {
385  return reverse_iterator_range(this->end(range));
386  }
387 
407  {
408  return const_reverse_iterator_range(this->end(range));
409  }
410 
411 
430  {
431  return reverse_iterator_range(this->begin(range));
432  }
433 
453  {
454  return const_reverse_iterator_range(this->begin(range));
455  }
456 
457 
458 
459 
466 
472  friend std::ostream& operator<< <>(std::ostream & out,
473  const block<T,N>& b);
474 
482 
489  {
490  if(this != &rhs)
491  {
492  std::copy(rhs.begin(),rhs.end(),this->begin());
493  }
494  return *this;
495  }
496 
502  block<T,N>& operator=(const T& val)
503  {
504  this->fill(val);
505  return *this;
506  }
507 
512  void fill(const T& value)
513  {
514  std::fill_n(this->begin(),N,value);
515  }
516 
522  void fill(const T* value)
523  {
524  std::copy(value,value + N, this->begin());
525  }
526 
535  template<typename InputIterator>
536  void fill(InputIterator first,
537  InputIterator last)
538  {
539  std::copy(first,last, this->begin());
540  }
553  friend bool operator== <>(const block<T,N>& x,
554  const block<T,N>& y);
555 
562  friend bool operator!= <>(const block<T,N>& x,
563  const block<T,N>& y);
564 
571  friend bool operator< <>(const block<T,N>& x,
572  const block<T,N>& y);
573 
580  friend bool operator> <>(const block<T,N>& x,
581  const block<T,N>& y);
582 
589  friend bool operator<= <>(const block<T,N>& x,
590  const block<T,N>& y);
591 
598  friend bool operator>= <>(const block<T,N>& x,
599  const block<T,N>& y);
600 
601 
620  reference operator[](const size_type n){return *(this->data + n);}
621 
633  const_reference operator[](const size_type n) const {return *(this->data + n);}
634 
646  reference operator()(const size_type n) {return *(this->data + n);}
647 
648 
660  const_reference operator()(const size_type n) const {return *(this->data + n);}
661 
662 
663 
669  size_type size() const {return N;}
670 
674  size_type max_size() const {return size_type(-1)/sizeof(value_type);}
675 
679  bool empty() const {return N == 0;}
680 
688  void swap(block& x)
689  {
690  std::swap_ranges(this->begin(),this->end(),x.begin());
691  }
692 
694  T data[N];
695 
696 private:
697 friend class boost::serialization::access;
698  template<class Archive>
699  void save(Archive & ar, const unsigned int version) const
700  {
701  ar & data;
702  }
703  template<class Archive>
704  void load(Archive & ar, const unsigned int version)
705  {
706  ar & data;
707  }
708  BOOST_SERIALIZATION_SPLIT_MEMBER()
709 };
710 
711 }//slip::
712 
713 namespace slip
714 {
716  /* @{ */
717 template <typename T, std::size_t N>
718 std::ostream& operator<<(std::ostream & out,
719  const block<T,N>& b)
720  {
721  out<<"(";
722  if(N > std::size_t(1))
723  for(std::size_t n = 0; n != N - 1; ++n)
724  {
725  out<<b.data[n]<<",";
726  }
727  out<<b.data[N-1];
728  out<<")";
729  return out;
730  }
731  /* @} */
733  /* @{ */
734 template <typename T, std::size_t N>
735 inline
736 bool operator==(const block<T,N>& x,
737  const block<T,N>& y)
738 {
739  return ( x.size() == y.size()
740  && std::equal(x.begin(),x.end(),y.begin()));
741 }
742 
743 template <typename T, std::size_t N>
744 inline
745 bool operator!=(const block<T,N>& x,
746  const block<T,N>& y)
747 {
748  return !(x == y);
749 }
750 
751 /* @} */
753  /* @{ */
754 template <typename T, std::size_t N>
755 inline
756 bool operator<(const block<T,N>& x,
757  const block<T,N>& y)
758 {
759  return std::lexicographical_compare(x.begin(), x.end(),
760  y.begin(), y.end());
761 }
762 
763 
764 template <typename T, std::size_t N>
765 inline
766 bool operator>(const block<T,N>& x,
767  const block<T,N>& y)
768 {
769  return (y < x);
770 }
771 
772 
773 template <typename T, std::size_t N>
774 inline
775 bool operator<=(const block<T,N>& x,
776  const block<T,N>& y)
777 {
778  return !(y < x);
779 }
780 
781 
782 template <typename T, std::size_t N>
783 inline
784 bool operator>=(const block<T,N>& x,
785  const block<T,N>& y)
786 {
787  return !(x < y);
788 }
789 /* @} */
790 }//slip::
791 
792 #endif //SLIP_BLOCK_HPP
iterator begin()
Returns a read/write iterator that points to the first element in the block. Iteration is done in ord...
Definition: Block.hpp:189
block< T, N > & operator=(const T &val)
Assigns all the element of the block by val.
Definition: Block.hpp:502
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
std::size_t iterations() const
Rerturns the number of iterations of the range.
Definition: Range.hpp:305
const_iterator_range begin(const slip::Range< int > &range) const
Returns a read-only (constant) iterator_range that points the first element within the Range...
Definition: Block.hpp:309
const_iterator_range end(const slip::Range< int > &range) const
Returns a read-only (constant) iterator_range that points one past the last element in the block...
Definition: Block.hpp:359
void swap(block &x)
Swaps data with another block.
Definition: Block.hpp:688
const_reference operator()(const size_type n) const
Subscript access to the data contained in the block.
Definition: Block.hpp:660
std::reverse_iterator< const_iterator_range > const_reverse_iterator_range
Definition: Block.hpp:166
const_reverse_iterator rend() const
Returns a read-only (constant) reverse iterator that points to one before the first element in the bl...
Definition: Block.hpp:261
size_type max_size() const
Returns the largest possible block.
Definition: Block.hpp:674
slip::stride_iterator< const_pointer > const_iterator_range
Definition: Block.hpp:160
const value_type * const_pointer
Definition: Block.hpp:149
static const std::size_t DIM
Definition: Block.hpp:173
slip::stride_iterator< pointer > iterator_range
Definition: Block.hpp:159
T data[N]
Data array storage of the block.
Definition: Block.hpp:694
iterator default_iterator
Definition: Block.hpp:169
const_iterator begin() const
Returns a read-only (constant) iterator that points to the first element in the block. Iteration is done in ordinary element order.
Definition: Block.hpp:200
block< T, N > & operator=(const block< T, N > &rhs)
Assigns all the element of the block by the block rhs.
Definition: Block.hpp:488
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
const_iterator const_default_iterator
Definition: Block.hpp:170
reference operator[](const size_type n)
Subscript access to the data contained in the block.
Definition: Block.hpp:620
pointer iterator
Definition: Block.hpp:156
iterator_range begin(const slip::Range< int > &range)
Returns a read/write iterator_range that points the first element within the Range. Iteration is done in ordinary element order according to the Range.
Definition: Block.hpp:281
reverse_iterator_range rbegin(const slip::Range< int > &range)
Returns a read/write reverse_iterator_range that points the end element within the Range...
Definition: Block.hpp:383
const_reference operator[](const size_type n) const
Subscript access to the data contained in the block.
Definition: Block.hpp:633
void fill(const T *value)
Fills the container range [begin(),begin()+N) with a copy of the value array.
Definition: Block.hpp:522
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the block...
Definition: Block.hpp:250
const_reverse_iterator rbegin() const
Returns a read-only (constant) reverse iterator that points to the last element in the block...
Definition: Block.hpp:240
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Definition: copy_ext.hpp:177
reverse_iterator_range rend(const slip::Range< int > &range)
Returns a read/write reverse_iterator_range that points one previous the first element in the Range...
Definition: Block.hpp:429
bool is_valid() const
Returns true if the range is valid :
Definition: Range.hpp:322
SubType start() const
Accessor of the start subscript of the Range.
Definition: Range.hpp:284
iterator end()
Returns a read/write iterator that points one past the last element in the block. Iteration is done i...
Definition: Block.hpp:210
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the block. Iteration is done in reverse element order.
Definition: Block.hpp:230
value_type * pointer
Definition: Block.hpp:148
value_type & reference
Definition: Block.hpp:150
const_reverse_iterator_range rbegin(const slip::Range< int > &range) const
Returns a read-only (constant) reverse_iterator_range that points the end element within the Range...
Definition: Block.hpp:406
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
ptrdiff_t difference_type
Definition: Block.hpp:153
std::reverse_iterator< iterator > reverse_iterator
Definition: Block.hpp:162
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+N) with a copy of the range [first,last) ...
Definition: Block.hpp:536
void fill(const T &value)
Fills the container range [begin(),begin()+N) with copies of value.
Definition: Block.hpp:512
const_pointer const_iterator
Definition: Block.hpp:157
T value_type
Definition: Block.hpp:147
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: Block.hpp:163
size_type size() const
Returns the number of elements in the block.
Definition: Block.hpp:669
int stride() const
Accessor of the stride of the Range.
Definition: Range.hpp:298
std::size_t size_type
Definition: Block.hpp:154
Provides a class to iterate a 1d range according to a step.
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
const_reverse_iterator_range rend(const slip::Range< int > &range) const
Returns a read-only (constant) reverse_iterator_range that points one previous the first element in t...
Definition: Block.hpp:452
const_iterator end() const
Returns a read-only (constant) iterator that points one past the last element in the block...
Definition: Block.hpp:220
bool empty() const
Returns true if the block is empty. (Thus size == 0)
Definition: Block.hpp:679
iterator_range end(const slip::Range< int > &range)
Returns a read/write iterator_range that points one past the last element in the block. Iteration is done in ordinary element order according to the Range.
Definition: Block.hpp:336
Provides a class to manipulate Ranges.
const value_type & const_reference
Definition: Block.hpp:151
SubType stop() const
Accessor of the stop subscript of the Range.
Definition: Range.hpp:291
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
static const std::size_t SIZE
Definition: Block.hpp:172
reference operator()(const size_type n)
Subscript access to the data contained in the block.
Definition: Block.hpp:646
std::reverse_iterator< iterator_range > reverse_iterator_range
Definition: Block.hpp:165
This is a linear (one-dimensional) static container. This container statisfies the RandomAccessContai...
Definition: Block.hpp:94