#ifndef glas_sparse_strided_view_hpp #define glas_sparse_strided_view_hpp #include #include #include #include #include #include namespace glas { // dense_view for a SparseVectorExpression template class sparse_strided_view { public: typedef typename SparseVectorExpression::nnz_type size_type ; // VectorExpression typedef typename SparseVectorExpression::value_type value_type ; // VectorExpression typedef typename SparseVectorExpression::const_reference const_reference ; // VectorExpression typedef typename boost::mpl::if_< is_vector_collection< SparseVectorExpression >, typename boost::mpl::if_< boost::is_const< SparseVectorExpression >, value_type const &, value_type & >::type, const_reference >::type reference ; // Collection typedef SparseVectorExpression source_type ; // View typedef value_type const * const_iterator ; // StridedVectorCollection typedef typename boost::mpl::if_< boost::is_const< SparseVectorExpression >, const_iterator, value_type * >::type iterator ; // StridedVectorCollection // typedef typename boost::add_const::type const_source_type ; typedef typename boost::mpl::if_< boost::is_const , boost::mpl::vector< strided_vector_expression_concept > , boost::mpl::vector< strided_vector_collection_concept > >::type concept_type ; public: /// requirement of View sparse_strided_view( source_type& s ) : source_( s ) {} /// requirement of Assignable sparse_strided_view( sparse_strided_view const& v ) : source_( v.source_ ) {} /// requirement of Assignable sparse_strided_view& operator=( sparse_strided_view const& v ) { // Call assign function return *this ; } /// requirement of EqualityComparable bool operator==(sparse_strided_view const & that) { size_type size = size() ; for(size_type i = 0 ; i < size ; ++i ) if ( that[i] != (*this)[i] ) return false ; return true ; } /// requirement of EqualityComparable bool operator!=(sparse_strided_view const & that) { return !((*this)==that) ; } /// requirement of VectorExpression size_type size() const { return source_.nnz() ; } /// requirement of VectorExpression const_reference operator[]( size_type i ) const { return *(begin()+i) ; } /// requirement of VectorCollection reference operator[]( size_type i ) { return *(begin()+i) ; } /// requirement of VectorExpression const_reference operator()( size_type i ) const { return *(begin()+i) ; } /// requirement of VectorCollection reference operator()( size_type i ) { return *(begin()+i) ; } /// required by View source_type& source() { return source_ ; } /// required by StridedVectorExpression ptrdiff_t stride() const { return 1 ; } /// required by StridedVectorExpression /// It takes the address of the first element in the vector because the /// iterator is not guaranteed to be a pointer. const_iterator begin() const { return & source_.value_vector()[0] ; } /// required by StridedVectorCollection iterator begin() { return & source_.value_vector()[0] ; } /// required by StridedVectorExpression const_iterator end() const { return & source_.value_vector()[size()-1] ; } /// required by StridedVectorCollection iterator end() { return & source_.value_vector()[size()-1] ; } public: source_type& source_ ; } ; } #endif // glas_view_sparse_strided_view_hpp