|
libpsynth 0.2.1
|
00001 /*************************************************************************** 00002 * * 00003 * PSYCHOSYNTH * 00004 * =========== * 00005 * * 00006 * Copyright (C) Juan Pedro Bolivar Puente 2008 * 00007 * * 00008 * This program is free software: you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation, either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00020 * * 00021 ***************************************************************************/ 00022 00023 #ifndef PSYNTH_WORLD_NODE_CREATOR_H 00024 #define PSYNTH_WORLD_NODE_CREATOR_H 00025 00026 #include <list> 00027 #include <string> 00028 #include <iostream> 00029 #include <psynth/world/world.hpp> 00030 00031 namespace psynth 00032 { 00033 00034 class node_factory_manager; 00035 class audio_info; 00036 class node; 00037 00038 class world_node_creator 00039 { 00040 class param_maker_base 00041 { 00042 public: 00043 virtual ~param_maker_base () {} 00044 virtual void apply (world_node& obj, const std::string& par) = 0; 00045 virtual param_maker_base* clone () const = 0; 00046 }; 00047 00048 template <class T> 00049 class param_maker : public param_maker_base 00050 { 00051 T m_val; 00052 00053 public: 00054 param_maker (const T& val) : 00055 m_val(val) {} 00056 00057 void apply (world_node & obj, const std::string& par) { 00058 obj.set_param (par, m_val); 00059 } 00060 00061 void set (const T& val) { 00062 m_val = val; 00063 } 00064 00065 param_maker_base* clone () const { 00066 return new param_maker <T> (m_val); 00067 } 00068 }; 00069 00070 typedef std::list<std::pair<std::string, param_maker_base*> > param_maker_list; 00071 00072 param_maker_list m_param; 00073 std::string m_name; 00074 00075 void destroy (); 00076 void copy (const world_node_creator& obj); 00077 param_maker_base* find (const std::string& name); 00078 00079 public: 00080 world_node_creator () {} 00081 00082 world_node_creator (const world_node_creator& obj) { 00083 copy (obj); 00084 } 00085 00086 ~world_node_creator () { 00087 destroy (); 00088 }; 00089 00090 world_node_creator& operator= (const world_node_creator& obj) { 00091 if (this != &obj) { 00092 destroy (); 00093 copy (obj); 00094 } 00095 return *this; 00096 } 00097 00098 world_node create (world& table); 00099 00100 void set_name (const std::string& name) { 00101 m_name = name; 00102 } 00103 00104 template<class T> 00105 void add_param (const std::string& name, const T& value) { 00106 m_param.push_back (std::make_pair (std::string(name), 00107 (param_maker_base*) 00108 new param_maker<T>(value))); 00109 } 00110 00111 template<class T> 00112 void set_param (const std::string& name, const T& value) { 00113 param_maker<T>* param = (param_maker<T>*) find(name); 00114 if (param) param->set(value); 00115 else add_param (name, value); 00116 }; 00117 00118 void clear () { 00119 destroy (); 00120 } 00121 }; 00122 00123 } /* namespace psynth */ 00124 00125 #endif /* PSYNTH_OBJECTCREATOR_H */
1.7.4