Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JFileIO.hh
Go to the documentation of this file.
1 #ifndef __JIO__JFILEIO__
2 #define __JIO__JFILEIO__
3 
4 #include <fcntl.h>
5 
6 #include "JIO/JSerialisable.hh"
7 #include "JLang/JFile.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JIO {}
15 namespace JPP { using namespace JIO; }
16 
17 namespace JIO {
18 
19  using JLANG::JFile;
20 
21 
22  /**
23  * Binary input based on a file descriptor.
24  * This class implements the JReader interface.
25  */
26  class JFileReader :
27  public JReader
28  {
29  public:
30  /**
31  * Constructor.
32  *
33  * \param file file
34  */
35  JFileReader(const JFile& file) :
36  in(file)
37  {}
38 
39 
40  /**
41  * Status of reader.
42  *
43  * \return status of this reader
44  */
45  virtual bool getStatus() const override
46  {
47  return in.good();
48  }
49 
50 
51  /**
52  * Read byte array.
53  *
54  * \param buffer pointer to byte array
55  * \param length number of bytes
56  * \return number of bytes read
57  */
58  virtual int read(char* buffer, const int length) override
59  {
60  return in.read(buffer, length);
61  }
62 
63  protected:
65  };
66 
67 
68  /**
69  * Binary output based on a file descriptor.
70  * This class implements the JWriter interface.
71  */
72  class JFileWriter :
73  public JWriter
74  {
75  public:
76  /**
77  * Constructor.
78  *
79  * \param file file
80  */
81  JFileWriter(const JFile& file) :
82  out(file)
83  {}
84 
85 
86  /**
87  * Status of writer.
88  *
89  * \return status of this writer
90  */
91  virtual bool getStatus() const override
92  {
93  return out.good();
94  }
95 
96 
97  /**
98  * Write byte array.
99  *
100  * \param buffer pointer to byte array
101  * \param length number of bytes
102  * \return number of bytes written
103  */
104  virtual int write(const char* buffer, const int length) override
105  {
106  return out.write(buffer, length);
107  }
108 
109  protected:
111  };
112 }
113 
114 #endif
Interface for binary output.
Binary output based on a file descriptor.
Definition: JFileIO.hh:72
JFileWriter(const JFile &file)
Constructor.
Definition: JFileIO.hh:81
virtual int write(const char *buffer, const int length) override
Write byte array.
Definition: JFileIO.hh:104
virtual bool good() const
Check status.
Definition: JFile.hh:124
virtual int read(char *buffer, const int length)
Read data from file.
Definition: JFile.hh:74
The JFile class extends the JAbstractFile class.
Definition: JFile.hh:26
JFileReader(const JFile &file)
Constructor.
Definition: JFileIO.hh:35
virtual int read(char *buffer, const int length) override
Read byte array.
Definition: JFileIO.hh:58
Interface for binary input.
virtual bool getStatus() const override
Status of writer.
Definition: JFileIO.hh:91
Binary input based on a file descriptor.
Definition: JFileIO.hh:26
virtual int write(const char *buffer, const int length)
Write data to file.
Definition: JFile.hh:87
virtual bool getStatus() const override
Status of reader.
Definition: JFileIO.hh:45