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 
40 
41  real time_ = 0.0;
42 
44 
45  bool openStream();
46 
47  virtual bool writeHeader();
48 
49 public:
50 
51  vtkFile(const fileSystem dir, const word& bName, real time);
52 
53  virtual ~vtkFile() = default;
54 
56  {
57  if(!oStream_)
58  {
59  if(!openStream())
60  {
62  " error in opening vtkFile "<< fileName() <<endl;
63  fatalExit;
64  }
65  }
66  return oStream_();
67  }
68 
69  inline explicit operator bool() const
70  {
71  if(!oStream_)return false;
72  if(oStream_().fail())return false;
73  return true;
74  }
75 
76  inline bool operator!()const
77  {
78  if( !oStream_) return true;
79  if( oStream_().fail() )return true;
80 
81  return false;
82  }
83 
84  virtual fileSystem fileName()const;
85 
86 };
87 
88 }
89 
90 #endif //__vtkFile_hpp__
pFlow::vtkFile::dirPath_
fileSystem dirPath_
Definition: vtkFile.hpp:37
pFlow::vtkFile
Definition: vtkFile.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::vtkFile::baseName_
word baseName_
Definition: vtkFile.hpp:39
types.hpp
pFlow::vtkFile::fileName
virtual fileSystem fileName() const
Definition: vtkFile.cpp:70
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::vtkFile::openStream
bool openStream()
Definition: vtkFile.cpp:24
pFlow::vtkFile::writeHeader
virtual bool writeHeader()
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
fileSystem.hpp
pFlow
Definition: demComponent.hpp:28
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::vtkFile::time_
real time_
Definition: vtkFile.hpp:41
uniquePtr.hpp
pFlow::vtkFile::operator!
bool operator!() const
Definition: vtkFile.hpp:76
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::vtkFile::vtkFile
vtkFile(const fileSystem dir, const word &bName, real time)
Definition: vtkFile.cpp:49
streams.hpp
pFlow::oFstream
Definition: oFstream.hpp:36
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::vtkFile::oStream_
uniquePtr< oFstream > oStream_
Definition: vtkFile.hpp:43
pFlow::vtkFile::~vtkFile
virtual ~vtkFile()=default
pFlow::vtkFile::operator()
oFstream & operator()()
Definition: vtkFile.hpp:55