libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/base/option_conf.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2007, 2009 Juan Pedro BolĂ­var Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 #ifndef PSYNTH_OPTIONCONF_H
00032 #define PSYNTH_OPTIONCONF_H
00033 
00034 #include <sstream>
00035 
00036 #include <psynth/base/arg_parser.hpp>
00037 #include <psynth/base/config.hpp>
00038 
00039 namespace psynth
00040 {
00041 namespace base
00042 {
00043 
00050 template <class T>
00051 class option_conf : public option
00052 {
00053     conf_node& m_node;
00054     
00055 public:
00060     option_conf(conf_node& node) :
00061         m_node(node) {}
00062 
00067     bool parse(const char* arg)
00068     {
00069         T val;
00070         std::istringstream str(arg);
00071         str >> val;
00072         m_node.set(val);
00073         
00074         return true;
00075     }
00076 };
00077 
00081 template <>
00082 class option_conf<std::string> : public option
00083 {
00084     conf_node& m_node;
00085     
00086 public:
00091     option_conf(conf_node& node) :
00092         m_node(node) {}
00093 
00098     bool parse(const char* arg)
00099     {
00100         m_node.set (std::string(arg));
00101         return true;
00102     }
00103 };
00104 
00111 template<class T>
00112 class option_conf_value : public option
00113 {
00114 public:
00120     option_conf_value(const T& val, conf_node& node) :
00121         m_val(val), m_node(node) {}
00122 
00127     bool parse()
00128     {
00129         m_node.set(m_val);
00130         return true;
00131     }
00132 
00133 private:
00134     T m_val;
00135     conf_node& m_node;
00136 };
00137 
00138 } /* namespace base */
00139 } /* namespace psynth */
00140 
00141 #endif /* PSYNTH_OPTION_CONF_H */