X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Floader.h;h=57481cff28d36fca44b19db0c91784e7ecc54573;hp=0c1dda2cc776db8d293b8696ba6e0e4739aab016;hb=215e719d0ef85f748898660d15d01e77ac551de9;hpb=a582163d380833b1370ba067a1fd0ad5c2984723 diff --git a/source/loader.h b/source/loader.h index 0c1dda2..57481cf 100644 --- a/source/loader.h +++ b/source/loader.h @@ -44,24 +44,50 @@ See also classes BasicLoader and BasicLoader2. class Loader { private: - /** - Loads data from a statement. - */ - void load(const Statement &st); + typedef std::map ActionMap; + + ActionMap actions; + const Statement *cur_st; +protected: + Loader(): cur_st(0) { } public: - /** - Loads statements from a parser. - */ + virtual ~Loader(); + + /** Loads statements from a parser. */ void load(Parser &p); - virtual ~Loader(); +private: + /** Loads data from a statement. */ + void load(const Statement &st); + + /** Processes a single statement */ + void load_statement(const Statement &st); + protected: - Loader(): cur_st(0) { } + /** Loads a sub-object from the statement being processed. The Loader class + of the sub-object is automatically used. */ + template + void load_sub(S &s) + { + typename S::Loader ldr(s); + load_sub_with(ldr); + } + + /** Loads a sub-object from the statement being processed with an extra + parameter for the Loader. The Loader class of the sub-object is + automatically used. */ + template + void load_sub(S &s, T &p) + { + typename S::Loader ldr(s, p); + load_sub_with(ldr); + } - /** - Adds a keyword that is loaded with a zero-argument function. - */ + /** Processes the current statement's substatements with another Loader. */ + void load_sub_with(Loader &); + + /** Adds a keyword that is loaded by calling a function. */ template void add(const std::string &k, void (L::*func)()) { add(k, new LoaderFunc0(func)); } @@ -86,9 +112,7 @@ protected: void add(const std::string &k, void (L::*func)(A0, A1, A2, A3, A4)) { add(k, new LoaderFunc5(func)); } - /** - Adds a keyword that is loaded into a variable of the loaded object. - */ + /** Adds a keyword that is loaded into a member of the loaded object. */ template void add(const std::string &k, T0 L::*p0) { add(k, new LoadValue1(p0)); } @@ -97,44 +121,17 @@ protected: void add(const std::string &k, T0 L::*p0, T1 L::*p1) { add(k, new LoadValue2(p0, p1)); } - /** - Adds a keyword that is recognized but ignored. - */ + /** Adds a keyword that is recognized but ignored. */ void add(const std::string &k) { add(k, 0); } - /** - Loads a sub-object from the statement being processed. The Loader class of - the sub-object is automatically used. - */ - template - void load_sub(S &s) - { - typename S::Loader ldr(s); - load_sub_with(ldr); - } - - /** - Loads a sub-object from the statement being processed with an extra parameter - for the Loader. The Loader class of the sub-object is automatically used. - */ - template - void load_sub(S &s, T &p) - { - typename S::Loader ldr(s, p); - load_sub_with(ldr); - } - - /** - Processes the current statement's substatements with another Loader. - */ - void load_sub_with(Loader &); +private: + void add(const std::string &, LoaderAction *); - /** - Returns the source of the statement being processed. This can be used to - implement relative paths in include-like statements. Note that the source - may not necessarily be a file. - */ +protected: + /** Returns the source of the statement being processed. This can be used + to implement relative paths in include-like statements. Note that the + source may not necessarily be a file. */ const std::string &get_source() const { if(!cur_st) @@ -143,14 +140,6 @@ protected: } virtual void finish() { } -private: - typedef std::map ActionMap; - - ActionMap actions; - const Statement *cur_st; - - void add(const std::string &, LoaderAction *); - void load_statement(const Statement &st); };