|
libpsynth 0.2.1
|
00001 00012 /* 00013 * Copyright (C) 2009 Juan Pedro BolĂvar Puente 00014 * 00015 * This program is free software: you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation, either version 3 of the License, or 00018 * (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00027 * 00028 */ 00029 00030 #ifndef PSYNTH_BASE_FACTORY_HPP_ 00031 #define PSYNTH_BASE_FACTORY_HPP_ 00032 00033 #include <psynth/base/type_traits.hpp> 00034 00035 namespace psynth 00036 { 00037 namespace base 00038 { 00039 00040 template <class BasePtr, typename ...Args> 00041 class factory_base 00042 { 00043 public: 00044 typedef typename pointee<BasePtr>::type base_type; 00045 typedef BasePtr pointer_type; 00046 00047 virtual ~factory_base () {}; 00048 virtual BasePtr create (Args... args) = 0; 00049 00050 BasePtr operator () (Args... args) 00051 { 00052 return this->create (std::forward<Args> (args)...); 00053 } 00054 }; 00055 00056 template <class BasePtr, class Concrete, typename ...Args> 00057 class factory : public factory_base <BasePtr, Args...> 00058 { 00059 public: 00060 typedef Concrete concrete_type; 00061 00062 BasePtr create (Args... args) 00063 { 00064 return BasePtr (new concrete_type (std::forward<Args> (args) ...)); 00065 } 00066 }; 00067 00068 } /* namespace base */ 00069 } /* namespace psynth */ 00070 00071 #endif /* PSYNTH_BASE_FACTORY_HPP_ */
1.7.4