75 #ifndef SLIP_ARRAY_HPP
76 #define SLIP_ARRAY_HPP
85 #include <boost/serialization/access.hpp>
86 #include <boost/serialization/split_member.hpp>
87 #include <boost/serialization/string.hpp>
88 #include <boost/serialization/complex.hpp>
89 #include <boost/serialization/version.hpp>
109 bool operator<(const Array<T>& x,
117 bool operator<=(const Array<T>& x,
142 template <
typename T>
174 static const std::size_t
DIM = 1;
220 template<
typename InputIterator>
227 std::fill_n(this->
begin(),n,T());
234 Array(
const self& rhs);
665 friend std::ostream& operator<< <>(std::ostream & out,
702 std::fill_n(this->
begin(),size_,value);
723 template<
typename InputIterator>
741 friend bool operator== <>(
const Array<T>& x,
750 friend bool operator!= <>(
const Array<T>& x,
759 friend bool operator< <>(
const Array<T>& x,
768 friend bool operator> <>(
const Array<T>& x,
777 friend bool operator<= <>(
const Array<T>& x,
786 friend bool operator>= <>(
const Array<T>& x,
896 std::string
name()
const;
916 void swap(
self& rhs);
930 void copy_attributes(
const self& rhs);
932 friend class boost::serialization::access;
933 template<
class Archive>
934 void save(Archive & ar,
const unsigned int version)
const
937 for(std::size_t i = 0; i < this->size_; ++i)
942 template<
class Archive>
943 void load(Archive & ar,
const unsigned int version)
948 for(std::size_t i = 0; i < this->size_; ++i)
953 BOOST_SERIALIZATION_SPLIT_MEMBER();
997 std::fill_n(this->data_,this->size_,T());
1000 template<
typename T>
1007 std::fill_n(this->data_,this->size_,val);
1010 template<
typename T>
1017 std::copy(val,val + this->size_, this->data_);
1020 template<
typename T>
1026 std::copy(rhs.data_,rhs.data_ + this->size_,this->data_);
1029 template<
typename T>
1033 this->desallocate();
1036 template<
typename T>
1042 if(this->size_ != rhs.size_)
1044 this->desallocate();
1045 this->copy_attributes(rhs);
1050 std::copy(rhs.data_,rhs.data_ + this->size_,this->data_);
1057 template<
typename T>
1062 if( this->size_ != size)
1064 this->desallocate();
1070 std::fill_n(this->data_,this->size_,val);
1075 template<
typename T>
1082 template<
typename T>
1086 return this->data_ + this->size_;
1089 template<
typename T>
1096 template<
typename T>
1100 return this->data_ + this->size_;
1105 template<
typename T>
1111 assert(range.
start() >= 0);
1112 assert(range.
stop() >= 0);
1113 assert(range.
start() < int(this->size()));
1114 assert(range.
stop() < int(this->size()));
1118 template<
typename T>
1124 return this->begin(range) + (range.
iterations() + 1);
1127 template<
typename T>
1133 assert(range.
start() >= 0);
1134 assert(range.
stop() >= 0);
1135 assert(range.
start() < int(this->size()));
1136 assert(range.
stop() < int(this->size()));
1140 template<
typename T>
1145 return this->begin(range) + (range.
iterations() + 1);
1150 template<
typename T>
1159 template<
typename T>
1165 return this->begin(box) + box.
length();
1168 template<
typename T>
1177 template<
typename T>
1183 return this->begin(box) + box.
length();
1186 template<
typename T>
1193 template<
typename T>
1200 template<
typename T>
1207 template<
typename T>
1215 template<
typename T>
1222 template<
typename T>
1230 template<
typename T>
1238 template<
typename T>
1246 template<
typename T>
1253 template<
typename T>
1261 template<
typename T>
1269 template<
typename T>
1280 template <
typename T>
1288 for(std::size_t n = 0; n < a.size_ - 1; ++n)
1290 out<<a.data_[n]<<
",";
1292 out<<a.data_[a.size_-1];
1303 template <
typename T>
1307 assert(this->data_ != 0);
1308 assert(i < this->size_);
1309 return *(this->data_ + i);
1312 template <
typename T>
1316 assert(this->data_ != 0);
1317 assert(i < this->size_);
1318 return *(this->data_ + i);
1321 template <
typename T>
1325 assert(this->data_ != 0);
1326 assert(i < this->size_);
1327 return *(this->data_ + i);
1330 template <
typename T>
1334 assert(this->data_ != 0);
1335 assert(i < this->size_);
1336 return *(this->data_ + i);
1339 template <
typename T>
1341 typename Array<T>::reference
1344 assert(this->data_ != 0);
1345 assert(p[0] < this->size_);
1346 return *(this->data_ + p[0]);
1349 template <
typename T>
1351 typename Array<T>::const_reference
1354 assert(this->data_ != 0);
1355 assert(p[0] < this->size_);
1356 return *(this->data_ + p[0]);
1359 template<
typename T>
1363 assert(this->data_ != 0);
1365 assert(range.
start() < (int)this->size_);
1366 assert(range.
stop() < (int)this->size_);
1370 return Array<T>(dim,this->begin(range),this->end(range));
1373 template<
typename T>
1379 template <
typename T>
1383 template <
typename T>
1390 template<
typename T>
1394 template<
typename T>
1398 assert(this->size_ == M.size_);
1399 std::swap_ranges(this->begin(),this->end(),M.
begin());
1405 template<
typename T>
1409 if(this->size_ != 0)
1411 this->data_ =
new T[this->size_];
1419 template<
typename T>
1421 void Array<T>::desallocate()
1423 if (this->data_ != 0)
1424 delete[] (this->data_);
1427 template<
typename T>
1429 void Array<T>::copy_attributes(
const Array<T>& rhs)
1431 this->size_ = rhs.size_;
1437 template<
typename T>
1446 template<
typename T>
1458 template<
typename T>
1460 bool operator<(const Array<T>& x,
1463 return std::lexicographical_compare(x.begin(), x.end(),
1464 y.begin(), y.end());
1467 template<
typename T>
1475 template<
typename T>
1477 bool operator<=(const Array<T>& x,
1483 template<
typename T>
1494 #endif //SLIP_ARRAY_HPP
const value_type & const_reference
reference operator()(const size_type n)
Subscript access to the data contained in the Array.
self & operator=(const self &rhs)
Assigns a Array in rhs.
bool empty() const
Returns true if the Array is empty. (Thus size() == 0)
bool operator!=(const Array< T > &x, const Array< T > &y)
std::size_t iterations() const
Rerturns the number of iterations of the range.
self & operator=(const T &value)
Assign all the elements of the Array by value.
slip::Array< short > Array_s
short alias
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Array...
std::string name() const
Returns the name of the class.
const_iterator const_default_iterator
void resize(const size_type size, const T &val=T())
Resizes a Array.
Array(const size_type n, InputIterator first, InputIterator last)
Constructs a Array from a range.
iterator begin()
Returns a read/write iterator that points to the first element in the Array. Iteration is done in ord...
size_type max_size() const
Returns the maximal size (number of elements) in the Array.
slip::stride_iterator< const_pointer > const_iterator_range
ptrdiff_t difference_type
void fill(const T *value)
Fills the container range [begin(),begin()+N) with a copy of the value array.
slip::stride_iterator< pointer > iterator_range
const Array< T > const_self
Array()
Constructs a Array.
bool operator>(const Array< T > &x, const Array< T > &y)
std::reverse_iterator< iterator > reverse_iterator
void fill(const T &value)
Fills the container range [begin(),begin()+N) with copies of value.
slip::Array< char > Array_c
char alias
slip::Array< unsigned char > Array_uc
unsigned char alias
This is a point1d class, a specialized version of Point<CoordType,DIM> with DIM = 1...
iterator end()
Returns a read/write iterator that points one past the last element in the Array. Iteration is done i...
std::reverse_iterator< iterator_range > reverse_iterator_range
This is a Box1d class, a specialized version of slip::Box<CoordType,DIM> with DIM = 1...
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+N) with a copy of the range [first,last) ...
CoordType length() const
compute the length of the Box1d.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
bool is_valid() const
Returns true if the range is valid :
SubType start() const
Accessor of the start subscript of the Range.
iterator default_iterator
void upper_left(const Point< CoordType, 1 > &p1)
Accessor/Mutator of the upper_left point (p1) of Box1d.
std::reverse_iterator< const_iterator_range > const_reverse_iterator_range
slip::Array< long > Array_l
long alias
bool is_consistent() const
verify if the window is consistent, that is to say if the first point p1 has the smaller coordinates ...
slip::Array< int > Array_i
int alias
~Array()
Destructor of the Array.
slip::Array< unsigned long > Array_ul
unsigned long alias
const value_type * const_pointer
void swap(self &rhs)
Swaps data with another Array.
reference operator[](const size_type n)
Subscript access to the data contained in the Array.
slip::Array< unsigned int > Array_ui
unsigned int alias
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
const_pointer const_iterator
slip::Array< unsigned short > Array_us
unsigned long alias
slip::Array< double > Array_d
double alias
int stride() const
Accessor of the stride of the Range.
size_type size() const
Returns the number of elements in the Array.
static const std::size_t DIM
Provides a class to iterate a 1d range according to a step.
std::reverse_iterator< const_iterator > const_reverse_iterator
bool operator==(const Array< T > &x, const Array< T > &y)
This is a linear (one-dimensional) dynamic template container. This container statisfies the RandomAc...
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Array. Iteration is done in reverse element order.
slip::Array< float > Array_f
float alias
Provides a class to manipulate Ranges.
Provides a class to manipulate 1d box.
SubType stop() const
Accessor of the stop subscript of the Range.
bool operator>=(const Array< T > &x, const Array< T > &y)