libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/graph/node_factory.hpp
Go to the documentation of this file.
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_OBJECTFACTORY_H
00024 #define PSYNTH_OBJECTFACTORY_H
00025 
00026 #include <psynth/graph/node.hpp>
00027 
00028 #define PSYNTH_DECLARE_NODE_FACTORY( T, name )\
00029     class T ## _factory : public ::psynth::graph::node_factory  \
00030     {                                                           \
00031     public:                                                     \
00032         psynth::graph::node* create (const audio_info& info)    \
00033         {                                                       \
00034             return new T (info);                                \
00035         }                                                       \
00036                                                                 \
00037         void destroy (psynth::graph::node* obj)                 \
00038         {                                                       \
00039             delete obj;                                         \
00040         }                                                       \
00041         const char* get_name () {                               \
00042             return name;                                        \
00043         }                                                       \
00044     };                                                          \
00045 T ## _factory& get_ ## T ## _factory();
00046 
00047 #define PSYNTH_DEFINE_NODE_FACTORY( T )\
00048 T ## _factory& get_ ## T ## _factory ()\
00049 {\
00050     static T ## _factory s_factory;\
00051     return s_factory;\
00052 }
00053 
00054 namespace psynth
00055 {
00056 namespace graph
00057 {
00058 
00059 class node_factory
00060 {
00061 public:
00062 
00063     virtual const char* get_name () = 0;
00064     virtual node* create (const audio_info& m_info) = 0;
00065     virtual void destroy (node* nod) = 0;
00066 };
00067 
00068 } /* namespace graph */
00069 } /* namespace psynth */
00070 
00071 #endif /* PSYNTH_OBJECTFACTORY_H */