DUNE-FEM (unstable)

binarystreams.hh
1#ifndef DUNE_FEM_BINARYSTREAMS_HH
2#define DUNE_FEM_BINARYSTREAMS_HH
3
4#include <dune/fem/io/streams/standardstreams.hh>
5
6namespace Dune
7{
8
9 namespace Fem
10 {
11
16 {
19
20 // make copy constructor private because of the file pointers
22 public:
27 explicit BinaryFileOutStream ( const std::string &filename )
28 : BaseType( openFile( filename ) )
29 {
30 }
31
34 {
35 delete file_; file_ = 0;
36 }
37 protected:
38 std::ostream& openFile( const std::string& filename )
39 {
40 // init file
41 file_ = new std::ofstream( filename.c_str(), std::ios::binary );
42
43 if( ! (*file_) )
44 DUNE_THROW( Dune::IOError, "Unable to open file: " << filename );
45
46 return *file_;
47 }
48
50 std::ofstream* file_;
51 };
52
57 {
60
61 // make copy constructor private because of the pointers
63
64 public:
69 explicit BinaryFileInStream ( const std::string &filename )
70 : BaseType( openFile( filename ) )
71 {
72 }
73
76 {
77 delete file_; file_ = 0;
78 }
79
80 protected:
81 std::istream& openFile( const std::string& filename )
82 {
83 file_ = (new std::ifstream( filename.c_str(), std::ios::binary ));
84
85 if( ! (*file_) )
86 DUNE_THROW( Dune::IOError, "Unable to open file: " << filename );
87
88 return *file_;
89 }
90
92 std::ifstream* file_;
93 };
94
95 } // namespace Fem
96
97} // namespace Dune
98
99#endif // #ifndef DUNE_FEM_BINARYSTREAMS_HH
Definition: binarystreams.hh:57
BinaryFileInStream(const std::string &filename)
constructor
Definition: binarystreams.hh:69
std::ifstream * file_
standard file stream
Definition: binarystreams.hh:92
~BinaryFileInStream()
destructor deleteing file stream
Definition: binarystreams.hh:75
Definition: binarystreams.hh:16
~BinaryFileOutStream()
destructor deleteing file stream
Definition: binarystreams.hh:33
BinaryFileOutStream(const std::string &filename)
constructor
Definition: binarystreams.hh:27
std::ofstream * file_
standard file stream
Definition: binarystreams.hh:50
input stream reading from a given std::istream
Definition: standardstreams.hh:202
output stream writing into a given std::ostream
Definition: standardstreams.hh:61
Default exception class for I/O errors.
Definition: exceptions.hh:231
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)