www.cemf.ir
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( rdHdr )
69  {
70  if( auto ptrIS = inStream(); ptrIS )
71  {
72  if(!readHeader(ptrIS()))return false;
73  ptrIS.reset(nullptr);
74  }
75  else
76  {
78  "could not open file " << path() <<endl;
79  return false;
80  }
81  }
82 
83  if( auto ptrIS = inStream(); ptrIS )
84  {
85  if(!read(ptrIS(), rdHdr))return false;
86 
87  }
88  else
89  {
91  "could not open file " << path() <<endl;
92  return false;
93  }
94  }
95 
96  return true;
97 }
98 
99 
101 {
102  if(implyWrite())
103  {
104  if(auto ptrOS = outStream(); ptrOS )
105  {
106  return write(ptrOS());
107  }
108  else
109  {
111  "error in opening file "<< path() <<endl;
112  return false;
113  }
114  }
115 
116  return true;
117 }
118 
119 
120 bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
121 {
122  if(rdHdr)
123  {
124  if(!readHeader(is))return false;
125  }
126  return object_->read_object_t(is);
127 }
128 
129 
131 {
132  if(this->readWriteHeader())
133  writeHeader(os, typeName());
134 
135  return (object_->write_object_t(os) && writeSeparator(os));
136 }
pFlow::IOobject::write
bool write() const
Definition: IOobject.cpp:100
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)
Add newline and flush stream.
Definition: iOstream.hpp:320
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