# PhasicFlow: src/phasicFlow/containers/Vector/stdVectorHelper.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.

stdVectorHelper.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 __stdVectorHelper_hpp__
#define __stdVectorHelper_hpp__
#include <vector>
#include <algorithm>
#include "span.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
#include "dataIO.hpp"
#include "pFlowProcessors.hpp"
namespace pFlow
{
template <class T>
class noConstructAllocator
: public std::allocator<T>
{
public:
using std::allocator<T>::allocator;
template <class U, class... Args> void construct(U*, Args&&...) {}
};
template<typename T>
using vecAllocator = std::allocator<T>;
template<typename T>
inline
span<T> makeSpan(std::vector<T>& container)
{
return span<T>(container.data(), container.size());
}
template<typename T>
inline
span<T> makeSpan(const std::vector<T>& container)
{
return span<T>(
const_cast<T*>(container.data()),
container.size());
}
template<typename T>
inline
bool writeSpan(
iOstream& os,
span<T> sp)
{
return writeDataAsciiBinary(os, sp);
}
template<typename T>
inline
bool writeSpan(
iOstream& os,
span<T> sp,
const IOPattern& iop)
{
auto ioPtr = dataIO<T>::create(iop);
if(!ioPtr)
{
fatalErrorInFunction;
return false;
}
if(!ioPtr().writeData(os, sp))
{
fatalErrorInFunction;
return false;
}
return true;
}
template<typename T, typename Allocator>
bool writeStdVector
(
iOstream& os,
const std::vector<T,Allocator>& vec
)
{
auto sp = makeSpan(vec);
return writeSpan(os, sp);
}
template<typename T, typename Allocator>
bool writeStdVector
(
iOstream& os,
const std::vector<T,Allocator>& vec,
const IOPattern& iop
)
{
auto sp = makeSpan(vec);
return writeSpan(os, sp, iop);
}
template<typename T, typename Allocator>
bool readStdVector
(
iIstream& is,
std::vector<T,Allocator>& vec
)
{
return readDataAsciiBinary(is, vec);
}
template<typename T, typename Allocator>
bool readStdVector
(
iIstream& is,
std::vector<T,Allocator>& vec,
const IOPattern& iop
)
{
auto ioPtr = dataIO<T>::create(iop);
if(!ioPtr)
{
fatalErrorInFunction;
return false;
}
if(!ioPtr().readData(is, vec))
{
fatalErrorInFunction;
return false;
}
return true;
}
template<typename T, typename Allocator>
iOstream& operator<<( iOstream& os, const std::vector<T,Allocator>& vec)
{
if(!writeStdVector(os, vec))
{
fatalErrorInFunction;
fatalExit;
}
return os;
}
template<typename T, typename Allocator>
iIstream& operator>>(iIstream& is, std::vector<T,Allocator>& vec)
{
if( !readStdVector(is,vec))
{
fatalErrorInFunction;
fatalExit;
}
return is;
}
} // pFlow
#endif
pFlow::span
Definition: span.hpp:31
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::writeDataAsciiBinary
bool writeDataAsciiBinary(iOstream &os, span< T > data)
Definition: dataIO.cpp:22
pFlow::readStdVector
bool readStdVector(iIstream &is, std::vector< T, Allocator > &vec)
Definition: stdVectorHelper.hpp:126
iIstream.hpp
pFlow::noConstructAllocator::construct
void construct(U *, Args &&...)
Definition: stdVectorHelper.hpp:45
pFlow::dataIO::create
static uniquePtr< dataIO > create(const IOPattern &iop)
Definition: dataIO.cpp:263
pFlow::vecAllocator
std::allocator< T > vecAllocator
Definition: stdVectorHelper.hpp:49
pFlow
Definition: demGeometry.hpp:27
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::readDataAsciiBinary
bool readDataAsciiBinary(iIstream &is, std::vector< T > &data)
Definition: dataIO.cpp:80
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::noConstructAllocator
Definition: stdVectorHelper.hpp:39
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::writeSpan
bool writeSpan(iOstream &os, span< T > sp)
Definition: stdVectorHelper.hpp:70
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
dataIO.hpp
pFlowProcessors.hpp
iOstream.hpp
pFlow::makeSpan
span< T > makeSpan(std::vector< T > &container)
Definition: stdVectorHelper.hpp:53
span.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::writeStdVector
bool writeStdVector(iOstream &os, const std::vector< T, Allocator > &vec)
Definition: stdVectorHelper.hpp:103