# PhasicFlow: src/phasicFlow/containers/span/span.hpp Source File

span.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __span_hpp__
#define __span_hpp__
#include "types.hpp"
#include "iOstream.hpp"
namespace pFlow {
template<typename T>
class span
{
public:
using iterator = T*;
using constIterator = const T*;
using reference = T&;
using constReference = const T&;
using valueType = T;
using pointer = T*;
using constPointer = const T*;
protected:
T* data_ = nullptr;
label size_ = 0;
public:
TypeInfoTemplateNV("span", T);
INLINE_FUNCTION_HD
span() = default;
INLINE_FUNCTION_HD
span(T* data, label size)
: data_(data), size_(size)
{}
INLINE_FUNCTION_HD
span(const span&) = default;
INLINE_FUNCTION_HD
span& operator=(const span&) = default;
INLINE_FUNCTION_HD
span(span&&) = delete;
INLINE_FUNCTION_HD
span& operator=(span&) = delete;
INLINE_FUNCTION_HD
bool empty() const
{
return size_ == 0;
}
INLINE_FUNCTION_HD
T* data() const
{
return data_;
}
INLINE_FUNCTION_HD
label size() const
{
return size_;
}
INLINE_FUNCTION_HD
constIterator begin() const
{
return data_;
}
INLINE_FUNCTION_HD
constIterator cbegin() const
{
return data_;
}
INLINE_FUNCTION_HD
constIterator end() const
{
return data_ + size_;
}
INLINE_FUNCTION_HD
constIterator cend() const
{
return data_ + size_;
}
INLINE_FUNCTION_HD
T& operator[](int32 i)
{
return data_[i];
}
INLINE_FUNCTION_HD
const T& operator[](int32 i)const
{
return data_[i];
}
INLINE_FUNCTION_HD
T& operator[](label i)
{
return data_[i];
}
INLINE_FUNCTION_HD
const T& operator[](label i)const
{
return data_[i];
}
};
template<typename T>
inline
iOstream& operator<<(iOstream& os, const span<T>& s)
{
os << token::BEGIN_LIST;
for(size_t i=0; i<s.size(); i++)
{
os << s[i]<<token::NL;
}
os << token::END_LIST;
os.check(FUNCTION_NAME);
return os;
}
} // pFlow
#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