Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
view.h
Go to the documentation of this file.
1#pragma once
2
3#include "tensor_traits.h"
4
5namespace dg
6{
7
8
43template<class ThrustVector >
44struct View
45{
46 using iterator = std::conditional_t<std::is_const<ThrustVector>::value,
47 typename ThrustVector::const_iterator,
48 typename ThrustVector::iterator>;
49 using const_iterator = typename ThrustVector::const_iterator;
50 using pointer = std::conditional_t<std::is_const<ThrustVector>::value,
51 typename ThrustVector::const_pointer,
52 typename ThrustVector::pointer>;
53 using const_pointer = typename ThrustVector::const_pointer;
55 View( void): m_ptr(), m_size(0){}
56
63 template<class OtherView>
64 View( OtherView& src): m_ptr(src.data()), m_size(src.size()){}
65
67 template<class InputIterator>
68 View( InputIterator data, unsigned size): m_ptr(pointer(data)),m_size(size){ }
69
79 template<class InputIterator>
80 void construct( InputIterator data, unsigned size)
81 {
82 m_ptr = pointer(data);
83 m_size = size;
84 }
85
90 pointer data() const {
91 return m_ptr;
92 }
97 iterator begin() const{
98 return iterator(m_ptr);
99 }
105 return const_iterator(m_ptr);
106 }
111 iterator end() const{
112 return iterator(m_ptr + m_size);
113 }
119 return const_iterator(m_ptr + m_size);
120 }
125 unsigned size() const{
126 return m_size;
127 }
128
133 void swap( View& src){
134 std::swap( m_ptr, src.m_ptr);
135 std::swap( m_size, src.m_size);
136 }
137 private:
138 pointer m_ptr;
139 unsigned m_size;
140};
141
146template<class ThrustVector>
153
154}//namespace dg
typename TensorTraits< std::decay_t< Vector > >::execution_policy get_execution_policy
Definition tensor_traits.h:49
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
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:149
get_execution_policy< ThrustVector > execution_policy
Definition view.h:151
The vector traits.
Definition tensor_traits.h:38
Indicate thrust/std - like behaviour.
Definition vector_categories.h:88
A vector view class, usable in dg functions.
Definition view.h:45
std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_iterator, typename ThrustVector::iterator > iterator
Definition view.h:46
View(OtherView &src)
Construct from another View or Vector.
Definition view.h:64
unsigned size() const
Get the size.
Definition view.h:125
typename ThrustVector::const_iterator const_iterator
Definition view.h:49
iterator end() const
Iterator to the end.
Definition view.h:111
View(void)
Initialize empty view.
Definition view.h:55
void swap(View &src)
Swap pointer and size with another View.
Definition view.h:133
const_iterator cbegin() const
const Iterator to the beginning
Definition view.h:104
pointer data() const
Constant Reference of the pointer.
Definition view.h:90
iterator begin() const
Iterator to the beginning.
Definition view.h:97
void construct(InputIterator data, unsigned size)
Construct view from pointer and size.
Definition view.h:80
const_iterator cend() const
const Iterator to the end
Definition view.h:118
View(InputIterator data, unsigned size)
Construct view from pointer and size.
Definition view.h:68
typename ThrustVector::const_pointer const_pointer
Definition view.h:53
std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_pointer, typename ThrustVector::pointer > pointer
Definition view.h:50