#ifndef __JTOOLS__JDRIVER__ #define __JTOOLS__JDRIVER__ #include #include #include "JLang/JStreamAvailable.hh" #include "JLang/JBool.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { using JLANG::JBool; /** * Auxiliary class to load and store objects. */ template class JDriver { private: /** * Load object without input. * * \param option I/O option * \return pointer to newly loaded object */ static inline JClass_t* load(JLANG::JBool option) { return new JClass_t(); } /** * Load object without input. * * \param in input stream * \param option I/O option * \return pointer to newly loaded object */ static inline JClass_t* load(std::istream& in, JLANG::JBool option) { return load(option); } /** * Load object with input. * * \param in input stream * \param option I/O option * \return pointer to newly loaded object */ static inline JClass_t* load(std::istream& in, JLANG::JBool option) { JClass_t* p = load(JLANG::JBool()); in >> *p; if (in.fail()) { delete p; p = NULL; } return p; } /** * Store object without output. * This implementation doesn't do anything. * * \param out output stream * \param option I/O option * \param p pointer to object */ static inline void store(std::ostream& out, const JClass_t* p, JBool option) {} /** * Store object with output. * * \param out output stream * \param option I/O option * \param p pointer object */ static inline void store(std::ostream& out, const JClass_t* p, JBool option) { if (p != NULL) { out << *p; } } public: /** * Load object. * * \return pointer to newly loaded object */ static inline JClass_t* load() { return load(JLANG::JBool::has_istream>()); } /** * Load object. * * \param in input stream * \return pointer to newly loaded object */ static inline JClass_t* load(std::istream& in) { return load(in, JBool::has_istream>()); } /** * Store object. * * \param out output stream * \param p pointer to object */ template static inline void store(std::ostream& out, const T* p) { store(out, dynamic_cast(p), JLANG::JBool::has_ostream>()); } }; } #endif