From 384539f7cc9feaa7ef7cee385cce472c6966c843 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 27 Apr 2009 00:24:16 +0200 Subject: Adding ue1 --- ue1/imgsynth/cscriptparser.h | 181 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 ue1/imgsynth/cscriptparser.h (limited to 'ue1/imgsynth/cscriptparser.h') diff --git a/ue1/imgsynth/cscriptparser.h b/ue1/imgsynth/cscriptparser.h new file mode 100644 index 0000000..01bb953 --- /dev/null +++ b/ue1/imgsynth/cscriptparser.h @@ -0,0 +1,181 @@ +/** + * @module cscriptparser + * @author Manuel Mausz, 0728348 + * @brief class for parsing simple scriptfiles + * @date 17.04.2009 + */ + +#ifndef CSCRIPTPARSER_H +#define CSCRIPTPARSER_H + +#include +#include +#include +#include +#include "cfile.h" + +/** + * @class CScriptparser + * + * Parses a simple line based scriptfile with some limitations: + * first function (starting a block) must be a read-command, + * last must be a write-command (ending this block). + * + * read- and write-commands have hard coded parameters, number#1 being a filetype. + * Classes handling certain filetypes must be of type CFile. + * Custom functions will be passed to CFile::callFunc(). + * + * On error ParserError will be thrown. + */ +class CScriptparser +{ + public: + /** + * @class ParserError + * @brief Exception thrown by CScriptparser + */ + class ParserError : public std::invalid_argument { + public: + /** + * @method ParserError + * @brief Default exception ctor + * @param what message to pass along + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + ParserError(const std::string& what) + : std::invalid_argument(what), m_line("") + {} + + /** + * @method ParserError + * @brief Custom exception ctor + * @param what message to pass along + * @param line scriptline which is currently being parsed + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + ParserError(const std::string& what, const std::string& line) + : std::invalid_argument(what), m_line(line) + {} + + /** + * @method ~ParserError + * @brief Default dtor + * @param - + * @return - + * @globalvars none + * @exception not allowed + * @conditions none + */ + ~ParserError() throw() + {} + + /** + * @method getLine + * @brief returns reference to currently parsed scriptline (if set) + * @return reference to currently parsed scriptline (maybe empty string) + * @globalvars none + * @exception none + * @conditions none + */ + const std::string &getLine() + { + return m_line; + } + + private: + /* members*/ + std::string m_line; + }; + + /** + * @method CScriptparser + * @brief Default ctor + * @param scriptfile filename of script to parse + * @return - + * @globalvars none + * @exception bad_alloc + * @conditions none + */ + CScriptparser(const std::string& scriptfile); + + /** + * @method ~CScriptparser + * @brief Default dtor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + ~CScriptparser(); + + /** + * @method parse + * @brief Start parsing the scriptfile + * @param - + * @return - + * @globalvars none + * @exception ParserError + * @conditions none + */ + void parse(); + + protected: + /** + * @method callFunc + * @brief Delegates the function and its parameters to the correct + * method (internal or handler) + * @param func function name + * @param funcparams function parameters as list + * @return - + * @globalvars none + * @exception ParserError + * @conditions none + */ + void callFunc(const std::string& func, const std::list& funcparams); + + /** + * @method read + * @brief Handles/wrappes read-command. according to the filetype the + * read-method of the corresponding handler will be called inside. + * @param funcparams function parameters as list + * @return - + * @globalvars none + * @exception ParserError + * @conditions none + * + * Scriptfile syntax: read(, ) + */ + void read(std::list funcparams); + + /** + * @method write + * @brief Handles/wrappes write-command. according to the filetype the + * write-method of the corresponding handler will be called inside. + * @param funcparams function parameters as list + * @return - + * @globalvars none + * @exception ParserError + * @conditions none + * + * Scriptfile syntax: write(, ) + */ + void write(std::list funcparams); + + private: + /* members */ + std::set m_handlers; + std::string m_scriptfile; + std::string m_curline; + CFile *m_handler; +}; + +#endif + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3