21#ifndef CCGSL_BLOCK_HPP
22#define CCGSL_BLOCK_HPP
24#include<gsl/gsl_block.h>
29#ifdef __GXX_EXPERIMENTAL_CXX0X__
30#include<initializer_list>
66 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
85#ifdef __GXX_EXPERIMENTAL_CXX0X__
90 block( std::initializer_list<double> initializer_list ){
91 size_t const n = initializer_list.size();
94 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
103 for(
auto x : initializer_list ){ *p = x; ++p; }
163#ifdef __GXX_EXPERIMENTAL_CXX0X__
169 std::swap(
count, v.count );
170 v.ccgsl_pointer =
nullptr;
178 block( std::move( v ) ).swap( *
this );
230 for(
size_t i = 0; i <
min; ++i ){
233 if( t < u )
return true;
234 if( u < t )
return false;
237 return size < v_size;
257 for(
size_t i = 0; i <
min; ++i ){
260 if( t > u )
return true;
261 if( u > t )
return false;
264 return size > v_size;
322 template<
typename container,
typename content,
bool reverse>
class iterator_base {
354 static content something = 0;
359 }
else if(
v->ccgsl_pointer == 0 ){
373 return *(
v->ccgsl_pointer->data +
position);
385 }
else if(
v->ccgsl_pointer == 0 ){
399 return v->ccgsl_pointer->data +
position;
409 static content something = 0;
414 }
else if(
v->ccgsl_pointer == 0 ){
429 return *(
v->ccgsl_pointer->data + p);
439 if(
v == 0 or i.
v == 0 ){
442 }
else if(
v->ccgsl_pointer == 0 or i.
v->ccgsl_pointer == 0 ){
447 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
448 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
481 if(
v == 0 or i.
v == 0 ){
486 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
487 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
503 }
else if(
v->ccgsl_pointer == 0 ){
520 }
else if(
v->ccgsl_pointer == 0 ){
537 }
else if(
v->ccgsl_pointer == 0 ){
685 if( this->
v == 0 or i.
v == 0 ){
694 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
723 if( this->
v == 0 or i.
v == 0 ){
729 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
871 if( this->
v == 0 or i.
v == 0 ){
880 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
921 if( this->
v == 0 or i.
v == 0 ){
927 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
956 if( this->
v == 0 or i.
v == 0 ){
962 gsl_error(
"trying to take difference of iterators for different blocks", __FILE__, __LINE__,
1050 if(
ccgsl_pointer == 0 ) gsl_error(
"null block", __FILE__, __LINE__, GSL_EFAULT );
1058 if(
ccgsl_pointer == 0 ) gsl_error(
"null block", __FILE__, __LINE__, GSL_EFAULT );
1124 static double something = 0;
1130#ifndef GSL_RANGE_CHECK_OFF
1147 static double something = 0;
1153#ifndef GSL_RANGE_CHECK_OFF
1195#ifdef __GXX_EXPERIMENTAL_CXX0X__
A class template for the const iterators.
const_iterator_t< reverse > operator--(int)
The postfix – operator.
const_iterator_t< reverse > operator+(difference_type const n) const
The + operator.
iterator_base< blockconst, double, reverse >::difference_type difference_type
Difference type.
bool operator!=(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
const_iterator_t & operator=(const_iterator_t< reverse > const &i)
We can assign one output iterator from another.
bool operator==(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
const_iterator_t()
The default constructor.
bool operator<(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
const_iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
const_iterator_t(iterator_t< reverse > const &i)
A copy constructor.
const_iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
difference_type operator-(iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
const_iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
const_iterator_t< reverse > operator++(int)
The postfix ++ operator.
const_iterator_t(block const *v, difference_type position)
This constructor allows block to create non-default iterators.
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
const_iterator_t< reverse > & operator++()
The prefix ++ operator.
const_iterator_t< reverse > & operator--()
The prefix – operator.
The container must have iterator types.
reference operator*() const
Dereference the pointer.
value_type & reference
An iterator must have a reference type.
void decrement()
Decrement the iterator.
bool operator<(iterator_base< container, content, reverse > const &i) const
The < operator is used to compare iterators.
reference operator[](difference_type const n) const
Get element at i + n by reference ([] operator).
value_type * pointer
An iterator must have a pointer typea.
std::random_access_iterator_tag iterator_category
An iterator must have an iterator category.
void shift(difference_type const n)
Shift iterator n places.
bool operator==(iterator_base< container, content, reverse > const &i) const
The == operator.
double value_type
An iterator must have a value type.
void increment()
Increment the iterator.
difference_type position
Mark position of iterator within block.
bool operator!=(iterator_base< container, content, reverse > const &i) const
The != operator.
difference_type operator-(iterator_base< container, content, reverse > const &i) const
The - operator: find distance between two iterators.
ptrdiff_t difference_type
An iterator must have a difference_type.
container * v
Store a pointer to a block we can iterate over: 0 if no block.
iterator_base()
The iterator is default constructible.
pointer operator->() const
Dereference the pointer.
iterator_base(container *v, difference_type position)
This constructor allows block to create non-default iterators.
A class template for the two non-const iterators.
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
iterator_t< reverse > operator++(int)
The postfix ++ operator.
difference_type operator-(iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
iterator_t< reverse > & operator--()
The prefix – operator.
iterator_t(block *v, difference_type position)
This constructor allows block to create non-default iterators.
iterator_t< reverse > operator+(difference_type const n) const
The + operator.
iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
iterator_t< reverse > operator--(int)
The postfix – operator.
iterator_t< reverse > & operator++()
The prefix ++ operator.
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
iterator_base< block, double, reverse >::difference_type difference_type
Difference type.
iterator_t()
The default constructor.
iterator_t< reverse > & operator=(iterator_t< reverse > const &i)
We can assign one output iterator from another.
iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
This class handles vectors as shared handles.
bool operator<=(block const &v) const
A container needs to define an ordering for sorting.
const_reverse_iterator rend() const
Get iterator pointing beyond last block element.
block(std::initializer_list< double > initializer_list)
Could construct from a std::initializer_list in C++11.
gsl_block * get() const
Get the gsl_block.
bool unique() const
Find if this is the only object sharing the gsl_block.
size_t * count
The shared reference count.
block & operator=(block &&v)
Move operator.
~block()
The destructor only deletes the pointers if count reaches zero.
block clone() const
The clone function.
const_iterator_t< true > const_reverse_iterator
The const_reverse_iterator type.
iterator begin()
Get iterator pointing to first block element.
double const & operator[](size_t const n) const
Get element at position n by reference ([] operator).
value_type * pointer
A container must have a pointer type.
bool operator==(block const &v) const
Two block objects are identically equal if their elements are identical.
void swap(block &v)
Swap two block objects.
value_type & reference
A container must have a reference type.
block()
The default constructor is only really useful for assigning to.
const_reverse_iterator rbegin() const
Get iterator pointing to first block element.
double const * data() const
Give access to the data block.
block(block &&v)
Move constructor.
bool operator>=(block const &v) const
A container needs to define an ordering for sorting.
block(size_t const n)
The default constructor creates a new block with n elements.
block(block const &v)
The copy constructor.
size_type max_size() const
The max size (number of elements) of the block.
const_iterator::difference_type difference_type
A container must have a difference_type.
value_type const & const_reference
A container must have a constant reference type.
bool empty() const
Find if the block is empty.
bool operator!=(block const &v) const
Two block objects are different equal if their elements are not identical.
size_t size_type
A container must have a size_type.
reverse_iterator rend()
Get iterator pointing beyond last block element.
size_type size() const
The size (number of elements) of the block.
double & operator[](size_t const n)
Get element at position n by reference ([] operator).
size_t use_count() const
Find how many block objects share this pointer.
reverse_iterator rbegin()
Get iterator pointing to first block element.
double * data()
Give access to the data block.
const_iterator begin() const
Get iterator pointing to first block element.
gsl_block * ccgsl_pointer
The shared pointer.
block(gsl_block *v)
Could construct from a gsl_block.
value_type const * const_pointer
A container must have a constant pointer type.
bool operator>(block const &v) const
A container needs to define an ordering for sorting.
void reset()
Stop sharing ownership of the shared pointer.
iterator_t< false > iterator
The iterator type.
bool operator<(block const &v) const
A container needs to define an ordering for sorting.
iterator end()
Get iterator pointing beyond last block element.
double value_type
A container must have a value_type.
iterator_t< true > reverse_iterator
The reverse_iterator type.
const_iterator end() const
Get iterator pointing beyond last block element.
block & operator=(block const &v)
The assignment operator.
const_iterator_t< false > const_iterator
The const_iterator type.
@ GSL_EFAILED
generic failure
@ GSL_EINVAL
invalid argument supplied by user
@ GSL_EFAULT
invalid pointer
int min(movstat::end_t const endtype, vector const &x, vector &y, workspace &w)
C++ version of gsl_movstat_min().
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
gsl_sf_result result
Typedef for gsl_sf_result.
The gsl package creates an interface to the GNU Scientific Library for C++.