X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floader.h;h=c6936f96f6eef5869f62ffe3ed9307f34038dd2c;hb=47597fd1b0b11c915466dd7f3f1281906442377c;hp=2fe0292bff01d5a6cdbab98e387daf0bbfab309e;hpb=26ab6b6a9e1c1eae7190135d762df8b37c3c60f9;p=libs%2Fdatafile.git diff --git a/source/loader.h b/source/loader.h index 2fe0292..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" @@ -172,6 +173,9 @@ protected: void add(const std::string &k, T L::*p) { actions.insert(typename ActionMap::value_type(k, new LoadValue(p))); } + void add(const std::string &k) + { actions.insert(ActionMap::value_type(k, 0)); } + template void load_sub(S &s) { load_sub(s); } @@ -196,11 +200,24 @@ private: ActionMap::iterator j=actions.find(st.keyword); if(j==actions.end()) throw Exception(st.get_location()+": Unknown keyword '"+st.keyword+"'"); - j->second->execute(*this, st); + if(j->second) + j->second->execute(*this, st); cur_st=0; } }; +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