Merge pull request #105 from PhasicFlow/develop

dataIO modified for virtual constructor
This commit is contained in:
Hamidreza Norouzi 2024-04-24 18:06:06 +03:30 committed by GitHub
commit 04fb9c8c36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 100 additions and 7 deletions

View File

@ -28,7 +28,7 @@ Licence:
#include "span.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
#include "createDataIO.hpp"
#include "dataIO.hpp"
#include "pFlowProcessors.hpp"
namespace pFlow
@ -82,7 +82,7 @@ bool writeSpan(
const IOPattern& iop)
{
auto ioPtr = createDataIO<T>(pFlowProcessors().localRunTypeName(), iop);
auto ioPtr = dataIO<T>::create(iop);
if(!ioPtr)
{
@ -141,7 +141,7 @@ bool readStdVector
const IOPattern& iop
)
{
auto ioPtr = createDataIO<T>(pFlowProcessors().localRunTypeName(), iop);
auto ioPtr = dataIO<T>::create(iop);
if(!ioPtr)
{

View File

@ -258,3 +258,32 @@ bool pFlow::dataIO<T>::readData
}
}
template<typename T>
pFlow::uniquePtr<pFlow::dataIO<T>>
pFlow::dataIO<T>::create(const IOPattern& iop)
{
word dataIOType = angleBracketsNames2(
"dataIO",
getTypeName<T>(),
pFlowProcessors().localRunTypeName());
if(IOPatternvCtorSelector_.search(dataIOType))
{
return IOPatternvCtorSelector_[dataIOType](iop);
}
else
{
printKeys
(
fatalError << "Ctor Selector "<< dataIOType << " does not exist. \n"
<<"Avaiable ones are: \n\n"
,
IOPatternvCtorSelector_
);
fatalExit;
}
return nullptr;
}

View File

@ -28,6 +28,8 @@ Licence:
#include "IOPattern.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
#include "virtualConstructor.hpp"
#include "pFlowProcessors.hpp"
@ -98,6 +100,14 @@ public:
virtual ~dataIO() = default;
create_vCtor
(
dataIO,
IOPattern,
(const IOPattern& iop),
(iop)
);
/// Write data to the end of file from all processors.
/// This method should be called from all processors.
bool writeData(iOstream& os, span<T> data);
@ -106,6 +116,9 @@ public:
iIstream& is,
std::vector<T>& data);
static
uniquePtr<dataIO> create(const IOPattern& iop);
};
template<typename T>
@ -123,6 +136,6 @@ iOstream& operator<<(iOstream& os, const span<T>& s)
}
#include "dataIOTemplate.cpp"
#include "dataIO.cpp"
#endif

View File

@ -30,6 +30,12 @@ class dataIORegular
:
public dataIO<T>
{
public:
using DataIORegularType = dataIORegular<T>;
using DataIOType = dataIO<T>;
protected:
bool gatherData(span<T> data ) override
@ -41,7 +47,7 @@ protected:
public:
TypeInfo("dataIO<regular>");
TypeInfoTemplate111("dataIO",T,"regular");
dataIORegular(const IOPattern& iop)
:
@ -58,6 +64,13 @@ public:
~dataIORegular() = default;
add_vCtor
(
DataIOType,
DataIORegularType,
IOPattern
);
};

View File

@ -0,0 +1,38 @@
#include "types.hpp"
#include "dataIO.hpp"
#include "dataIORegular.hpp"
template class pFlow::dataIO<pFlow::uint8>;
template class pFlow::dataIORegular<pFlow::uint8>;
template class pFlow::dataIO<pFlow::int8>;
template class pFlow::dataIORegular<pFlow::int8>;
template class pFlow::dataIO<pFlow::int32>;
template class pFlow::dataIORegular<pFlow::int32>;
template class pFlow::dataIO<pFlow::int64>;
template class pFlow::dataIORegular<pFlow::int64>;
template class pFlow::dataIO<pFlow::uint32>;
template class pFlow::dataIORegular<pFlow::uint32>;
template class pFlow::dataIO<pFlow::uint64>;
template class pFlow::dataIORegular<pFlow::uint64>;
template class pFlow::dataIO<pFlow::real>;
template class pFlow::dataIORegular<pFlow::real>;
template class pFlow::dataIO<pFlow::realx3>;
template class pFlow::dataIORegular<pFlow::realx3>;
template class pFlow::dataIO<pFlow::realx4>;
template class pFlow::dataIORegular<pFlow::realx4>;
template class pFlow::dataIO<pFlow::word>;
template class pFlow::dataIORegular<pFlow::word>;
/*template class pFlow::dataIO<char>;
template class pFlow::dataIORegular<char>;*/