#ifndef __JIO__JIOTOOLKIT__ #define __JIO__JIOTOOLKIT__ #include "JLang/JException.hh" #include "JIO/JFileStreamIO.hh" #include "JIO/JSTDIO.hh" /** * \file * Auxiliary methods for binary I/O. * \author mdejong */ namespace JIO {} namespace JPP { using namespace JIO; } namespace JIO { using JLANG::JFileOpenException; using JLANG::JFileReadException; /** * Load object from input file. * * \param file_name file name * \param object object to be read */ template inline void load(const char* file_name, T& object) { JFileStreamReader in(file_name); if (!in) { THROW(JFileOpenException, "Error opening file " << file_name); } in.load(object); if (!in) { THROW(JFileReadException, "Error reading file " << file_name); } in.close(); } /** * Store object to output file. * * \param file_name file name * \param object object to be written */ template inline void store(const char* file_name, const T& object) { JFileStreamWriter out(file_name); if (!out) { THROW(JFileOpenException, "Error opening file " << file_name); } out.store(object); out.close(); } } #endif