#ifndef __JIO__JFILEIO__ #define __JIO__JFILEIO__ #include #include "JIO/JSerialisable.hh" #include "JLang/JFile.hh" /** * \author mdejong */ namespace JIO {} namespace JPP { using namespace JIO; } namespace JIO { using JLANG::JFile; /** * Binary input based on a file descriptor. * This class implements the JReader interface. */ class JFileReader : public JReader { public: /** * Constructor. * * \param file file */ JFileReader(const JFile& file) : in(file) {} /** * Status of reader. * * \return status of this reader */ virtual bool getStatus() const override { return in.good(); } /** * Read byte array. * * \param buffer pointer to byte array * \param length number of bytes * \return number of bytes read */ virtual int read(char* buffer, const int length) override { return in.read(buffer, length); } protected: JFile in; }; /** * Binary output based on a file descriptor. * This class implements the JWriter interface. */ class JFileWriter : public JWriter { public: /** * Constructor. * * \param file file */ JFileWriter(const JFile& file) : out(file) {} /** * Status of writer. * * \return status of this writer */ virtual bool getStatus() const override { return out.good(); } /** * Write byte array. * * \param buffer pointer to byte array * \param length number of bytes * \return number of bytes written */ virtual int write(const char* buffer, const int length) override { return out.write(buffer, length); } protected: JFile out; }; } #endif