Discontinuous Galerkin Library
#include "dg/algorithm.h"
view.h
Go to the documentation of this file.
1#pragma once
2
3#include <cusp/array1d.h>
4#include "tensor_traits.h"
5
6namespace dg
7{
8
9
41template<class ThrustVector >
42struct View
43{
44 using iterator = std::conditional_t<std::is_const<ThrustVector>::value,
45 typename ThrustVector::const_iterator,
46 typename ThrustVector::iterator>;
47 using const_iterator = typename ThrustVector::const_iterator;
48 using pointer = std::conditional_t<std::is_const<ThrustVector>::value,
49 typename ThrustVector::const_pointer,
50 typename ThrustVector::pointer>;
51 using const_pointer = typename ThrustVector::const_pointer;
53 View( void): m_ptr(), m_size(0){}
54
61 template<class OtherView>
62 View( OtherView& src): m_ptr(src.data()), m_size(src.size()){}
63
65 template<class InputIterator>
66 View( InputIterator data, unsigned size): m_ptr(pointer(data)),m_size(size){ }
67
77 template<class InputIterator>
78 void construct( InputIterator data, unsigned size)
79 {
80 m_ptr = pointer(data);
81 m_size = size;
82 }
83
88 pointer data() const {
89 return m_ptr;
90 }
95 iterator begin() const{
96 return iterator(m_ptr);
97 }
103 return const_iterator(m_ptr);
104 }
109 iterator end() const{
110 return iterator(m_ptr + m_size);
111 }
117 return const_iterator(m_ptr + m_size);
118 }
123 unsigned size() const{
124 return m_size;
125 }
126
131 void swap( View& src){
132 std::swap( m_ptr, src.m_ptr);
133 std::swap( m_size, src.m_size);
134 }
135 private:
136 pointer m_ptr;
137 unsigned m_size;
138};
139
144template<class ThrustVector>
145struct TensorTraits< View<ThrustVector>>
146{
150};
151
152}//namespace dg
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
typename TensorTraits< std::decay_t< Vector > >::execution_policy get_execution_policy
Definition: tensor_traits.h:42
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
get_value_type< ThrustVector > value_type
Definition: view.h:147
get_execution_policy< ThrustVector > execution_policy
Definition: view.h:149
The vector traits.
Definition: tensor_traits.h:31
Indicate thrust/std - like behaviour.
Definition: vector_categories.h:88
A vector view class, usable in dg functions.
Definition: view.h:43
View(OtherView &src)
Construct from another View or Vector.
Definition: view.h:62
unsigned size() const
Get the size.
Definition: view.h:123
typename ThrustVector::const_iterator const_iterator
Definition: view.h:47
iterator end() const
Iterator to the end.
Definition: view.h:109
View(void)
Initialize empty view.
Definition: view.h:53
void swap(View &src)
Swap pointer and size with another View.
Definition: view.h:131
const_iterator cbegin() const
const Iterator to the beginning
Definition: view.h:102
pointer data() const
Constant Reference of the pointer.
Definition: view.h:88
std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_iterator, typename ThrustVector::iterator > iterator
Definition: view.h:46
iterator begin() const
Iterator to the beginning.
Definition: view.h:95
void construct(InputIterator data, unsigned size)
Construct view from pointer and size.
Definition: view.h:78
const_iterator cend() const
const Iterator to the end
Definition: view.h:116
std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_pointer, typename ThrustVector::pointer > pointer
Definition: view.h:50
View(InputIterator data, unsigned size)
Construct view from pointer and size.
Definition: view.h:66
typename ThrustVector::const_pointer const_pointer
Definition: view.h:51