www.cemf.ir
fileStream.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 // based on OpenFOAM stream, with some modifications/simplifications
21 // to be tailored to our needs
22 
23 
24 #ifndef __fileStream_hpp__
25 #define __fileStream_hpp__
26 
27 
28 #include <fstream>
29 
30 #include "fileSystem.hpp"
31 #include "uniquePtr.hpp"
32 
33 namespace pFlow
34 {
35 
44 {
45 protected:
46 
49 
52 
53  bool binary_ = false;
54 
55  bool append_ = false;
56 
58  void openInFile(const fileSystem& path);
59 
61  void openOutFile(const fileSystem& path);
62 
64  void close();
65 
66 public:
67 
69 
71  fileStream( const fileSystem& path, bool outStream = false, bool binary = false, bool append = false);
72 
74  fileStream(const fileStream&)= delete;
75 
77  fileStream& operator=(const fileStream&)=delete;
78 
80  virtual ~fileStream()
81  {
82  close();
83  }
84 
85 
87 
89  std::ifstream& inStream();
90 
92  std::ofstream& outStream();
93 };
94 
95 }
96 
97 #endif
pFlow::fileStream::outStream_
uniquePtr< std::ofstream > outStream_
out file stream
Definition: fileStream.hpp:51
pFlow::fileStream::append_
bool append_
Definition: fileStream.hpp:55
pFlow::fileStream::openInFile
void openInFile(const fileSystem &path)
open input file
Definition: fileStream.cpp:27
pFlow::fileStream::close
void close()
close streams
Definition: fileStream.cpp:106
pFlow::fileStream::operator=
fileStream & operator=(const fileStream &)=delete
No assignment.
pFlow::fileStream::~fileStream
virtual ~fileStream()
Destructor.
Definition: fileStream.hpp:80
fileSystem.hpp
pFlow
Definition: demGeometry.hpp:27
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::fileStream::outStream
std::ofstream & outStream()
Access output file stream.
Definition: fileStream.cpp:148
uniquePtr.hpp
pFlow::fileStream::binary_
bool binary_
Definition: fileStream.hpp:53
pFlow::fileStream::inStream_
uniquePtr< std::ifstream > inStream_
in file stream
Definition: fileStream.hpp:48
pFlow::fileStream
Creates and manages an input/output file stream with specified format.
Definition: fileStream.hpp:43
pFlow::uniquePtr< std::ifstream >
pFlow::fileStream::fileStream
fileStream(const fileSystem &path, bool outStream=false, bool binary=false, bool append=false)
From file path and input type and format.
Definition: fileStream.cpp:120
pFlow::fileStream::openOutFile
void openOutFile(const fileSystem &path)
open output file
Definition: fileStream.cpp:58
pFlow::fileStream::inStream
std::ifstream & inStream()
Access input file stream.
Definition: fileStream.cpp:143