2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
21 #ifndef __STG_SGCONF_PARSERS_H__
22 #define __STG_SGCONF_PARSERS_H__
27 typedef void (*FUNC0)();
32 typedef void (*type)(T);
38 virtual PARSER_STATE parse(int, char **, CONFIG&) = 0;
42 class PARAM_PARSER : public PARSER
45 PARAM_PARSER(T& var) : m_var(var) {}
46 virtual PARSER_STATE parse(int argc, char ** argv, CONFIG& config)
48 std::istringstream stream(argv[0]);
51 state.argc = argc - 1;
52 state.argv = argv + 1;
53 state.config = config;
65 FUNC0_PARSER(FUNC0 func) : m_func(func) {}
66 virtual PARSER_STATE parse(int argc, char ** argv, CONFIG& config)
70 state.argc = argc - 1;
71 state.argv = argv + 1;
72 state.config = config;
85 FUNC1_PARSER(typename FUNC1<T>::type func, const T & arg) : m_func(func), m_arg(arg) {}
86 virtual PARSER_STATE parse(int argc, char ** argv, CONFIG& config)
90 state.argc = argc - 1;
91 state.argv = argv + 1;
92 state.config = config;
98 typename FUNC1<T>::type m_func;
105 typedef PARSER_STATE (* FUNC)(int, char **, CONFIG&);
107 template <typename T>
108 void add(const std::string & shortToken,
109 const std::string & fullToken,
113 void add<void>(const std:string & shortToken,
114 const std::string & fullToken,
116 template <typename V>
117 void add<void>(const std:string & shortToken,
118 const std::string & fullToken,
119 FUNC1 func, const V& v);