IOobject.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #include "IOobject.hpp"
22 #include "repository.hpp"
23 
24 
26 (
27  const objectFile& objf,
28  const repository* owner,
29  uniquePtr<iObject>&& obj
30 )
31 :
32  IOfileHeader(objf, owner),
33  object_(obj.release())
34 {
35 
36  if(!read(this->readWriteHeader()))
37  {
39  "error in reading " << name() << " from path " << path()<<endl;
40  fatalExit;
41  }
42 }
43 
44 
46 (
47  const objectFile& objf,
48  const repository* owner,
50 )
51 :
52  IOfileHeader(objf, owner),
53  object_( obj->object_.release())
54 {
55 }
56 
57 
59 {
60  return object_.get() != nullptr;
61 }
62 
63 bool pFlow::IOobject::read(bool rdHdr)
64 {
65 
66  if( implyRead() )
67  {
68  if( auto ptrIS = inStream(); ptrIS )
69  {
70  return read( ptrIS(), rdHdr);
71  }
72  else
73  {
75  "could not open file " << path() <<endl;
76  return false;
77  }
78  }
79  return true;
80 }
81 
82 
84 {
85  if(implyWrite())
86  {
87  if(auto ptrOS = outStream(); ptrOS )
88  {
89  return write(ptrOS());
90  }
91  else
92  {
94  "error in opening file "<< path() <<endl;
95  return false;
96  }
97  }
98 
99  return true;
100 }
101 
102 
103 bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
104 {
105  if(rdHdr)
106  {
107  if(!readHeader(is))return false;
108  }
109  return object_->read_object_t(is);
110 }
111 
112 
114 {
115  if(this->readWriteHeader())
116  writeHeader(os, typeName());
117 
118  return (object_->write_object_t(os) && writeSeparator(os));
119 }
pFlow::IOobject::write
bool write() const
Definition: IOobject.cpp:83
fatalExit
#define fatalExit
Definition: error.hpp:57
IOobject.hpp
warningInFunction
#define warningInFunction
Definition: error.hpp:55
pFlow::IOobject::IOobject
IOobject(const objectFile &objf, const repository *owner, uniquePtr< iObject > &&obj)
Definition: IOobject.cpp:26
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::IOobject::isObjectValid
bool isObjectValid() const
Definition: IOobject.cpp:58
repository.hpp
pFlow::IOobject::object_
uniquePtr< iObject > object_
Definition: IOobject.hpp:110
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::IOobject::read
bool read(bool rdHdr=true)
Definition: IOobject.cpp:63
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::repository
Definition: repository.hpp:34
pFlow::iOstream
Definition: iOstream.hpp:53