www.cemf.ir
vtkFile.hpp
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 #ifndef __vtkFile_hpp__
22 #define __vtkFile_hpp__
23 
24 #include "types.hpp"
25 #include "uniquePtr.hpp"
26 #include "fileSystem.hpp"
27 #include "streams.hpp"
28 
29 namespace pFlow
30 {
31 
32 
33 class vtkFile
34 {
35 protected:
36 
38 
39  bool binary_ = false;
40 
41  bool append_=false;
42 
43  real time_ = 0.0;
44 
46 
48 
49  bool openStream(bool wHeader);
50 
51  virtual bool writeHeader();
52 
53 public:
54 
55  vtkFile(
56  const fileSystem dir,
57  const word& bName,
58  real time,
59  bool bnry,
60  bool append = false);
61 
62  virtual ~vtkFile() = default;
63 
65  {
66  if(!oStream_)
67  {
68  if(!openStream(!append_))
69  {
71  " error in opening vtkFile "<< fileName() <<endl;
72  fatalExit;
73  }
74  }
75  return oStream_();
76  }
77 
78  inline explicit operator bool() const
79  {
80  if(!oStream_)return false;
81  if(oStream_().fail())return false;
82  return true;
83  }
84 
85  inline bool operator!()const
86  {
87  if( !oStream_) return true;
88  if( oStream_().fail() )return true;
89 
90  return false;
91  }
92 
93  inline
94  bool binary()const
95  {
96  return binary_;
97  }
98 
99  virtual fileSystem fileName()const;
100 
101 };
102 
103 }
104 
105 #endif //__vtkFile_hpp__
pFlow::vtkFile::dirPath_
fileSystem dirPath_
Definition: vtkFile.hpp:45
pFlow::vtkFile
Definition: vtkFile.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::vtkFile::baseName_
word baseName_
Definition: vtkFile.hpp:47
types.hpp
pFlow::vtkFile::binary
bool binary() const
Definition: vtkFile.hpp:94
pFlow::vtkFile::fileName
virtual fileSystem fileName() const
Definition: vtkFile.cpp:79
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::vtkFile::binary_
bool binary_
Definition: vtkFile.hpp:39
pFlow::vtkFile::vtkFile
vtkFile(const fileSystem dir, const word &bName, real time, bool bnry, bool append=false)
Definition: vtkFile.cpp:54
pFlow::vtkFile::writeHeader
virtual bool writeHeader()
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
fileSystem.hpp
pFlow
Definition: demGeometry.hpp:27
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::vtkFile::time_
real time_
Definition: vtkFile.hpp:43
uniquePtr.hpp
pFlow::vtkFile::operator!
bool operator!() const
Definition: vtkFile.hpp:85
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::vtkFile::openStream
bool openStream(bool wHeader)
Definition: vtkFile.cpp:24
pFlow::vtkFile::append_
bool append_
Definition: vtkFile.hpp:41
streams.hpp
pFlow::oFstream
Output file stream to send binary or ascii data to a file.
Definition: oFstream.hpp:38
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::vtkFile::oStream_
uniquePtr< oFstream > oStream_
Definition: vtkFile.hpp:37
pFlow::vtkFile::~vtkFile
virtual ~vtkFile()=default
pFlow::vtkFile::operator()
oFstream & operator()()
Definition: vtkFile.hpp:64