# PhasicFlow: src/phasicFlow/containers/span/span.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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;
uint32 size_ = 0;
public:
TypeInfoTemplateNV11("span", T);
INLINE_FUNCTION_HD
span() = default;
INLINE_FUNCTION_HD
span(T* data, uint32 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&&) = default;
INLINE_FUNCTION_HD
span& operator=(span&) = default;
INLINE_FUNCTION_HD
bool empty() const
{
return size_ == 0;
}
INLINE_FUNCTION_HD
T* data() const
{
return data_;
}
INLINE_FUNCTION_HD
uint32 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[](uint32 i)
{
return data_[i];
}
INLINE_FUNCTION_HD
const T& operator[](uint32 i)const
{
return data_[i];
}
INLINE_FUNCTION_HD
T& operator[](int32 i)
{
return data_[i];
}
INLINE_FUNCTION_HD
const T& operator[](int32 i)const
{
return data_[i];
}
};
/*template<typename T, typename... properties, template<class, class...> class Container>
size_t makeSpan(Container<T, properties...>& container)
{
return span<T>(container.data(), container.size());
}
template<typename T, typename... properties, template<class, class...> class Container>
size_t makeSpan(const Container<T, properties...>& container)
{
return span<T>(
const_cast<T*>(container.data()),
container.size());
}*/
template<typename T>
inline
span<char> charSpan(span<T> s)
{
auto el = sizeof(T);
return span<char>(
reinterpret_cast<char*>(s.data()),
s.size()*el);
}
template<typename T>
inline
span<const char> charSpan(span<const T> s)
{
auto el = sizeof(T);
return span<const char>(
reinterpret_cast<const char*>(s.data()),
s.size()*el);
}
/*template<typename T, template<class> class Container>
span<T> makeSpan(Container<T>& container)
{
return span<T>(container.data(), container.size());
}
template<typename T, template<class> class Container>
span<T> makeSpan(const Container<T>& container)
{
return span<T>(
const_cast<T*>(container.data()),
container.size());
}*/
} // pFlow
#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