www.cemf.ir
span.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __span_hpp__
22 #define __span_hpp__
23 
24 #include "types.hpp"
25 #include "iOstream.hpp"
26 
27 namespace pFlow {
28 
29 
30 template<typename T>
31 class span
32 {
33 
34 public:
35 
36  using iterator = T*;
37 
38  using constIterator = const T*;
39 
40  using reference = T&;
41 
42  using constReference = const T&;
43 
44  using valueType = T;
45 
46  using pointer = T*;
47 
48  using constPointer = const T*;
49 
50 protected:
51 
52  T* data_ = nullptr;
53 
55 
56 public:
57 
58  TypeInfoTemplateNV11("span", T);
59 
62  span() = default;
63 
64 
67  : data_(data), size_(size)
68  {}
69 
72  span(const span&) = default;
73 
76  span& operator=(const span&) = default;
77 
80  span(span&&) = default;
81 
84  span& operator=(span&) = default;
85 
86 
88  bool empty() const
89  {
90  return size_ == 0;
91  }
92 
94  T* data() const
95  {
96  return data_;
97  }
98 
101  uint32 size() const
102  {
103  return size_;
104  }
105 
109  {
110  return data_;
111  }
112 
116  {
117  return data_;
118  }
119 
123  {
124  return data_ + size_;
125  }
126 
130  {
131  return data_ + size_;
132  }
133 
136  {
137  return data_[i];
138  }
139 
141  const T& operator[](uint32 i)const
142  {
143  return data_[i];
144  }
145 
148  {
149  return data_[i];
150  }
151 
153  const T& operator[](int32 i)const
154  {
155  return data_[i];
156  }
157 
158 };
159 
160 /*template<typename T, typename... properties, template<class, class...> class Container>
161 size_t makeSpan(Container<T, properties...>& container)
162 {
163  return span<T>(container.data(), container.size());
164 }
165 
166 template<typename T, typename... properties, template<class, class...> class Container>
167 size_t makeSpan(const Container<T, properties...>& container)
168 {
169  return span<T>(
170  const_cast<T*>(container.data()),
171  container.size());
172 }*/
173 
174 
175 template<typename T>
176 inline
178 {
179  auto el = sizeof(T);
180  return span<char>(
181  reinterpret_cast<char*>(s.data()),
182  s.size()*el);
183 }
184 
185 template<typename T>
186 inline
188 {
189  auto el = sizeof(T);
190  return span<const char>(
191  reinterpret_cast<const char*>(s.data()),
192  s.size()*el);
193 }
194 
195 /*template<typename T, template<class> class Container>
196 span<T> makeSpan(Container<T>& container)
197 {
198  return span<T>(container.data(), container.size());
199 }
200 
201 template<typename T, template<class> class Container>
202 span<T> makeSpan(const Container<T>& container)
203 {
204  return span<T>(
205  const_cast<T*>(container.data()),
206  container.size());
207 }*/
208 
209 
210 
211 
212 
213 
214 } // pFlow
215 
216 #endif //__span_hpp__
pFlow::span
Definition: span.hpp:31
pFlow::span::constPointer
const T * constPointer
Definition: span.hpp:48
pFlow::span::constIterator
const T * constIterator
Definition: span.hpp:38
types.hpp
pFlow::span::operator[]
INLINE_FUNCTION_HD T & operator[](uint32 i)
Definition: span.hpp:135
pFlow::span::operator[]
const INLINE_FUNCTION_HD T & operator[](int32 i) const
Definition: span.hpp:153
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::span::size
INLINE_FUNCTION_HD uint32 size() const
Returns the number of elements in the span.
Definition: span.hpp:101
pFlow::span::data_
T * data_
Definition: span.hpp:52
pFlow::span::empty
INLINE_FUNCTION_HD bool empty() const
Definition: span.hpp:88
pFlow
Definition: demGeometry.hpp:27
pFlow::span::span
INLINE_FUNCTION_HD span()=default
Constructor.
pFlow::span::cbegin
INLINE_FUNCTION_HD constIterator cbegin() const
Returns an iterator to the beginning of the span.
Definition: span.hpp:115
pFlow::span::begin
INLINE_FUNCTION_HD constIterator begin() const
Returns an iterator to the beginning of the span.
Definition: span.hpp:108
pFlow::span::pointer
T * pointer
Definition: span.hpp:46
pFlow::span::TypeInfoTemplateNV11
TypeInfoTemplateNV11("span", T)
pFlow::span::operator[]
INLINE_FUNCTION_HD T & operator[](int32 i)
Definition: span.hpp:147
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::span::operator=
INLINE_FUNCTION_HD span & operator=(const span &)=default
assignment
pFlow::span::iterator
T * iterator
Definition: span.hpp:36
pFlow::span::valueType
T valueType
Definition: span.hpp:44
pFlow::span::cend
INLINE_FUNCTION_HD constIterator cend() const
Returns an iterator to one past the end of the span.
Definition: span.hpp:129
pFlow::span::data
INLINE_FUNCTION_HD T * data() const
Definition: span.hpp:94
pFlow::span::reference
T & reference
Definition: span.hpp:40
pFlow::charSpan
span< char > charSpan(span< T > s)
Definition: span.hpp:177
pFlow::span::span
INLINE_FUNCTION_HD span(T *data, uint32 size)
Definition: span.hpp:66
pFlow::span::constReference
const T & constReference
Definition: span.hpp:42
pFlow::span::size_
uint32 size_
Definition: span.hpp:54
iOstream.hpp
pFlow::span::operator[]
const INLINE_FUNCTION_HD T & operator[](uint32 i) const
Definition: span.hpp:141
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::span::end
INLINE_FUNCTION_HD constIterator end() const
Returns an iterator to one past the end of the span.
Definition: span.hpp:122