dune-fem  2.4.1-rc
binarystreams.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_BINARYSTREAMS_HH
2 #define DUNE_FEM_BINARYSTREAMS_HH
3 
5 
6 namespace 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  {
59  typedef StandardInStream BaseType;
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
std::ofstream * file_
standard file stream
Definition: binarystreams.hh:50
input stream reading from a given std::istream
Definition: standardstreams.hh:194
std::istream & openFile(const std::string &filename)
Definition: binarystreams.hh:81
BinaryFileInStream(const std::string &filename)
constructor
Definition: binarystreams.hh:69
constructor
Definition: binarystreams.hh:15
std::ifstream * file_
standard file stream
Definition: binarystreams.hh:92
output stream writing into a given std::ostream
Definition: standardstreams.hh:59
Definition: coordinate.hh:4
BinaryFileOutStream(const std::string &filename)
constructor
Definition: binarystreams.hh:27
~BinaryFileInStream()
destructor deleteing file stream
Definition: binarystreams.hh:75
constructor
Definition: binarystreams.hh:56
~BinaryFileOutStream()
destructor deleteing file stream
Definition: binarystreams.hh:33
std::ostream & openFile(const std::string &filename)
Definition: binarystreams.hh:38