#ifndef __JLANG__JACCESSIBLESTREAM__ #define __JLANG__JACCESSIBLESTREAM__ #include #include "JLang/JAccessible.hh" #include "JLang/JException.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Accessible input stream. * * This class is a simple wrapper around the std::ifstream class. * It implements the JAccessible interface. */ class JAccessibleInputStream : protected std::ifstream, public virtual JAccessible { public: /** * Default constructor. */ JAccessibleInputStream() {} /** * Constructor. * * \param file_name file name */ JAccessibleInputStream(const char* file_name) { open(file_name); } /** * Check is file is open. * * \return true if open; else false */ virtual bool is_open() const { return std::ifstream::is_open(); } /** * Open file. * * \param file_name file name */ virtual void open(const char* file_name) { std::ifstream::open(file_name); if (!this->is_open()) { Throw(JFileOpenException(std::string("Error opening file ") + file_name)); } } /** * Close file. */ virtual void close() { std::ifstream::close(); } }; /** * Accessible output stream. * * This class is a simple wrapper around the std::ofstream class. * It class implements the JAccessible interface. */ class JAccessibleOutputStream : protected std::ofstream, public virtual JAccessible { public: /** * Default constructor. */ JAccessibleOutputStream() {} /** * Constructor. * * \param file_name file name */ JAccessibleOutputStream(const char* file_name) { open(file_name); } /** * Check is file is open. * * \return true if open; else false */ virtual bool is_open() const { return std::ofstream::is_open(); } /** * Open file. * * \param file_name file name */ virtual void open(const char* file_name) { std::ofstream::open(file_name); if (!this->is_open()) { Throw(JFileOpenException(std::string("Error opening file ") + file_name)); } } /** * Close file. */ virtual void close() { std::ofstream::close(); } }; } #endif