MyraMath
FileStreams.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_IO_FILESTREAMS_H
7 #define MYRAMATH_IO_FILESTREAMS_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
15 #include <myramath/io/Streams.h>
16 #include <fstream>
17 
18 namespace myra {
19 
22  {
23  public:
24 
26  FileOutputStream (const std::string& filename)
27  { out.open(filename.c_str(), std::ofstream::binary); }
28 
30  FileOutputStream (const char* filename)
31  { out.open(filename, std::ofstream::binary); }
32 
34  virtual void write_binary (const char* p, size_t n)
35  { out.write(p,n); }
36 
38  void close()
39  { out.close(); }
40 
41  private:
42 
43  // Underlying file being written.
44  std::ofstream out;
45 
46  };
47 
50  {
51  public:
52 
54  FileInputStream (const std::string& filename)
55  { in.open(filename, std::ifstream::binary); }
56 
58  FileInputStream (const char* filename)
59  { in.open(filename, std::ifstream::binary); }
60 
62  virtual void read_binary (char* p, size_t n)
63  { in.read(p,n); }
64 
66  void close()
67  { in.close(); }
68 
69  private:
70 
71  // Underlying file being read.
72  std::ifstream in;
73 
74  };
75 
76 } // namespace
77 
78 #endif
FileOutputStream(const char *filename)
Opens a file for writing.
Definition: FileStreams.h:30
void close()
Closes underlying file.
Definition: FileStreams.h:38
An InputStream that thinly wraps a std::ifstream, for reading from files.
Definition: FileStreams.h:49
Definition: syntax.dox:1
Abstraction layer, serializable objects write themselves to these.
Definition: Streams.h:39
Abstraction layer, deserializable objects read themselves from these.
Definition: Streams.h:47
FileOutputStream(const std::string &filename)
Opens a file for writing.
Definition: FileStreams.h:26
An OutputStream that thinly wraps a std::ofstream, for writing to files.
Definition: FileStreams.h:21
void close()
Closes underlying file.
Definition: FileStreams.h:66
FileInputStream(const std::string &filename)
Opens a file for reading.
Definition: FileStreams.h:54
FileInputStream(const char *filename)
Opens a file for reading.
Definition: FileStreams.h:58
virtual void write_binary(const char *p, size_t n)
Writes to underlying file.
Definition: FileStreams.h:34
Bases classes for binary input/output streams.
virtual void read_binary(char *p, size_t n)
Writes to underlying file.
Definition: FileStreams.h:62