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 
54  label size_ = 0;
55 
56 public:
57 
58  TypeInfoTemplateNV("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&&) = delete;
81 
84  span& operator=(span&) = delete;
85 
86 
88  bool empty() const
89  {
90  return size_ == 0;
91  }
92 
94  T* data() const
95  {
96  return data_;
97  }
98 
101  label 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[](int32 i)const
142  {
143  return data_[i];
144  }
145 
148  {
149  return data_[i];
150  }
151 
153  const T& operator[](label i)const
154  {
155  return data_[i];
156  }
157 
158 };
159 
160 template<typename T>
161 inline
163 {
164  os << token::BEGIN_LIST;
165  for(size_t i=0; i<s.size(); i++)
166  {
167  os << s[i]<<token::NL;
168  }
169 
170  os << token::END_LIST;
171 
172  os.check(FUNCTION_NAME);
173 
174  return os;
175 }
176 
177 } // pFlow
178 
179 #endif //__span_hpp__
pFlow::span
Definition: span.hpp:31
pFlow::span::size
INLINE_FUNCTION_HD label size() const
Returns the number of elements in the span.
Definition: span.hpp:101
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[]
const INLINE_FUNCTION_HD T & operator[](int32 i) const
Definition: span.hpp:141
pFlow::token::NL
@ NL
Newline [isspace].
Definition: token.hpp:86
pFlow::span::data_
T * data_
Definition: span.hpp:52
pFlow::span::empty
INLINE_FUNCTION_HD bool empty() const
Definition: span.hpp:88
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::span::operator[]
INLINE_FUNCTION_HD T & operator[](label i)
Definition: span.hpp:147
pFlow
Definition: demComponent.hpp:28
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
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::operator[]
INLINE_FUNCTION_HD T & operator[](int32 i)
Definition: span.hpp:135
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::span::operator=
INLINE_FUNCTION_HD span & operator=(const span &)=default
assignment
pFlow::span::iterator
T * iterator
Definition: span.hpp:36
pFlow::token::END_LIST
@ END_LIST
End list [isseparator].
Definition: token.hpp:90
pFlow::span::valueType
T valueType
Definition: span.hpp:44
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
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::span::span
INLINE_FUNCTION_HD span(T *data, label size)
Definition: span.hpp:66
pFlow::span::operator[]
const INLINE_FUNCTION_HD T & operator[](label i) const
Definition: span.hpp:153
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.hpp:89
pFlow::span::size_
label size_
Definition: span.hpp:54
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::span::constReference
const T & constReference
Definition: span.hpp:42
iOstream.hpp
pFlow::span::TypeInfoTemplateNV
TypeInfoTemplateNV("span", T)
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::span::end
INLINE_FUNCTION_HD constIterator end() const
Returns an iterator to one past the end of the span.
Definition: span.hpp:122