# PhasicFlow: src/phasicFlow/repository/IOobject/IOobject.hpp Source File

IOobject.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 __IOobject_hpp__
#define __IOobject_hpp__
#include "IOfileHeader.hpp"
namespace pFlow
{
class repository;
class IOobject
:
public IOfileHeader
{
private:
class iObject
{
public:
virtual ~iObject()=default;
// - clone
virtual uniquePtr<iObject> clone() const = 0;
virtual word typeName()const = 0;
virtual bool read_object_t(iIstream& is) = 0;
virtual bool write_object_t(iOstream& os)const = 0;
};
template<typename dataType>
class object_t
:
public iObject
{
public:
dataType data_;
public:
template<typename... Args,
typename = std::enable_if_t<!std::is_constructible<object_t, Args&&...>::value>>
object_t(Args&&... args)
:
data_(std::forward<Args>(args)...)
{}
// cunstruct by copying data
object_t(const dataType& data): data_(data){}
// construct by moving data
//object_t(dataType&& data): data_(std::move(data)){}
virtual uniquePtr<iObject> clone() const
{
return makeUnique<object_t>(*this);
}
virtual word typeName()const
{
return data_.typeName();
}
virtual bool read_object_t(iIstream& is)
{
return data_.read(is);
}
virtual bool write_object_t(iOstream& os)const
{
return data_.write(os);
}
};
protected:
// underlaying data object
uniquePtr<iObject> object_;
public:
// - typeinfo
word typeName()const
{
return object_->typeName();
}
// - construct from components, transfer the ownership of iObject (object_t) to the
// onwner and read the object from file
IOobject(const objectFile& objf, const repository* owner, uniquePtr<iObject>&& obj );
// - construct from components, transfer the ownership of IOobject to the owner (no read happens)
IOobject(const objectFile& objf, const repository* owner, uniquePtr<IOobject>&& obj);
// - copy construct
IOobject(const IOobject& src)=delete;
// - move construct
IOobject(IOobject&& src) = default;
// - make object from components, considering no owner for this object, and
// read from file
// Args are the arguments of object constructor
template<typename T, typename... Args>
static auto make(const objectFile& objf, Args&&... args);
// - construct object_t with the Args as the arguments of object constructor
template<typename T, typename... Args>
static auto make_object_t(Args&&... args);
// - is object valid
bool isObjectValid()const;
// - ref to data object
template<typename T>
auto& getObject();
// - const ref to data object
template<typename T>
const auto& getObject()const;
// - read from file
bool read(bool rdHdr = true);
// - write to file
bool write() const;
// - read from istream
bool read(iIstream& is, bool rdHdr = true);
// - write to istream
bool write(iOstream& os) const;
};
}
#include "IOobjectTemplates.cpp"
#endif //__IOobject_hpp__
pFlow::IOobject::write
bool write() const
Definition: IOobject.cpp:83
pFlow::IOobject::iObject::read_object_t
virtual bool read_object_t(iIstream &is)=0
pFlow::IOobject::object_t::object_t
object_t(const dataType &data)
Definition: IOobject.hpp:77
pFlow::IOobject::iObject::clone
virtual uniquePtr< iObject > clone() const =0
pFlow::IOobject::object_t
Definition: IOobject.hpp:60
IOobjectTemplates.cpp
pFlow::IOobject::object_t::object_t
object_t(Args &&... args)
Definition: IOobject.hpp:71
pFlow::IOobject::IOobject
IOobject(const objectFile &objf, const repository *owner, uniquePtr< iObject > &&obj)
Definition: IOobject.cpp:26
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::IOobject::iObject::typeName
virtual word typeName() const =0
pFlow::IOobject::object_t::clone
virtual uniquePtr< iObject > clone() const
Definition: IOobject.hpp:83
pFlow::IOobject::getObject
auto & getObject()
Definition: IOobjectTemplates.cpp:42
pFlow::IOobject::isObjectValid
bool isObjectValid() const
Definition: IOobject.cpp:58
pFlow
Definition: demComponent.hpp:28
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::IOobject::object_
uniquePtr< iObject > object_
Definition: IOobject.hpp:110
pFlow::IOobject::make_object_t
static auto make_object_t(Args &&... args)
Definition: IOobjectTemplates.cpp:35
pFlow::IOobject::iObject
Definition: IOobject.hpp:42
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::IOobject::object_t::read_object_t
virtual bool read_object_t(iIstream &is)
Definition: IOobject.hpp:93
pFlow::IOfileHeader::owner
const repository * owner() const
Definition: IOfileHeader.hpp:78
pFlow::IOobject::object_t::write_object_t
virtual bool write_object_t(iOstream &os) const
Definition: IOobject.hpp:98
pFlow::IOobject::read
bool read(bool rdHdr=true)
Definition: IOobject.cpp:63
pFlow::objectFile
Definition: objectFile.hpp:33
IOfileHeader.hpp
pFlow::IOobject::object_t::typeName
virtual word typeName() const
Definition: IOobject.hpp:88
pFlow::IOobject::object_t::data_
dataType data_
Definition: IOobject.hpp:65
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::IOobject::make
static auto make(const objectFile &objf, Args &&... args)
Definition: IOobjectTemplates.cpp:23
pFlow::repository
Definition: repository.hpp:34
pFlow::IOobject::iObject::~iObject
virtual ~iObject()=default
pFlow::IOobject::iObject::write_object_t
virtual bool write_object_t(iOstream &os) const =0
pFlow::IOobject::typeName
word typeName() const
Definition: IOobject.hpp:116
pFlow::iOstream
Definition: iOstream.hpp:53