#ifndef GSL_UBLAS_STORAGE_ADAPTORS_HPP_ #define GSL_UBLAS_STORAGE_ADAPTORS_HPP_ #include #include #include #include #include namespace boost { namespace numeric { namespace ublas { template class array_handle: public storage_array > { typedef array_handle self_type; public: typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef T value_type; typedef const T& const_reference; typedef T& reference; typedef const T* const_pointer; typedef T* pointer; // Construction and destruction BOOST_UBLAS_INLINE array_handle (): size_ (0), data_ (new value_type [0]) {} explicit BOOST_UBLAS_INLINE array_handle (size_type size): size_ (size),data_ (new value_type [size]) {} BOOST_UBLAS_INLINE array_handle (size_type size, const value_type &init): size_ (size), data_ (new value_type [size]) { std::fill (data_, data_ + size_, init); } BOOST_UBLAS_INLINE array_handle (size_type size, pointer data): size_ (size), data_ (data) {} BOOST_UBLAS_INLINE array_handle (const array_handle &a): storage_array (), size_ (a.size_), data_ (a.data_) {} BOOST_UBLAS_INLINE ~array_handle () {} public: BOOST_UBLAS_INLINE size_type size () const { return size_; } // Element access BOOST_UBLAS_INLINE const_reference operator [] (size_type i) const { BOOST_UBLAS_CHECK (i < size_, bad_index ()); return data_ [i]; } BOOST_UBLAS_INLINE reference operator [] (size_type i) { BOOST_UBLAS_CHECK (i < size_, bad_index ()); return data_ [i]; } // Assignment BOOST_UBLAS_INLINE array_handle& operator = (const array_handle &a) { if (this != &a) { if( this->size_ != a.size_) { std::cerr << "operator= of array_handle is only for equal sized matrices" << std::endl; std::exit(1); } std::copy (a.data_, a.data_ + a.size_, data_); } return *this; } typedef const_pointer const_iterator; BOOST_UBLAS_INLINE const_iterator begin () const { return data_; } BOOST_UBLAS_INLINE const_iterator end () const { return data_ + size_; } typedef pointer iterator; BOOST_UBLAS_INLINE iterator begin () { return data_; } BOOST_UBLAS_INLINE iterator end () { return data_ + size_; } // Reverse iterators typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_iterator; BOOST_UBLAS_INLINE const_reverse_iterator rbegin () const { return const_reverse_iterator (end ()); } BOOST_UBLAS_INLINE const_reverse_iterator rend () const { return const_reverse_iterator (begin ()); } BOOST_UBLAS_INLINE reverse_iterator rbegin () { return reverse_iterator (end ()); } BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); } private: size_type size_; pointer data_; }; } // namespace ublas } //namespace numeric } // namespace boost #endif /*GSL_UBLAS_STORAGE_ADAPTORS_HPP_*/