From: Mikko Rasa Date: Mon, 27 Nov 2006 19:22:34 +0000 (+0000) Subject: Add a shortcut function for loading something from a file. X-Git-Tag: 1.0~31 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=47597fd1b0b11c915466dd7f3f1281906442377c;p=libs%2Fdatafile.git Add a shortcut function for loading something from a file. --- diff --git a/source/loader.h b/source/loader.h index 6e9c4f8..c6936f9 100644 --- a/source/loader.h +++ b/source/loader.h @@ -6,6 +6,7 @@ Distributed under the LGPL #ifndef MSP_PARSER_LOADER_H_ #define MSP_PARSER_LOADER_H_ +#include #include #include #include "parser.h" @@ -205,6 +206,18 @@ private: } }; +template +void load(T &obj, const std::string &fn) +{ + std::ifstream in(fn.c_str()); + if(!in) + throw Exception("Couldn't open "+fn); + + Parser parser(in, fn); + typename T::Loader loader(obj); + loader.load(parser); +} + } // namespace Parser } // namespace Msp