/[svn]/linuxsampler/trunk/src/plugins/InstrumentEditorFactory.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/plugins/InstrumentEditorFactory.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2503 - (hide annotations) (download) (as text)
Sat Jan 11 14:05:17 2014 UTC (10 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4799 byte(s)
* Minor C++11 compliance fixes (caused compilation errors
  on some recent compilers).

1 schoenebeck 1374 /***************************************************************************
2     * *
3 schoenebeck 2503 * Copyright (C) 2007 - 2014 Christian Schoenebeck *
4 schoenebeck 1374 * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the Free Software *
17     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18     * MA 02111-1307 USA *
19     ***************************************************************************/
20    
21     #ifndef LS_INSTRUMENT_EDITOR_FACTORY_H
22     #define LS_INSTRUMENT_EDITOR_FACTORY_H
23    
24     #include <map>
25     #include <vector>
26     #include <list>
27    
28     #include "../common/Exception.h"
29     #include "InstrumentEditor.h"
30    
31 senoner 1481 #if defined(WIN32)
32     # define REGISTER_INSTRUMENT_EDITOR(PluginClass) \
33     extern "C" __declspec(dllexport) void* \
34     createInstrumentEditorInnerFactory() { \
35     return new LinuxSampler::InstrumentEditorFactory::InnerFactoryTemplate<PluginClass>(); \
36     }
37     #else
38     # define REGISTER_INSTRUMENT_EDITOR(PluginClass) \
39 schoenebeck 1374 LinuxSampler::InstrumentEditorFactory::InnerFactoryRegistrator<PluginClass> \
40     __auto_register_instrument_editor__##PluginClass;
41 senoner 1481 #endif
42 schoenebeck 1374
43     namespace LinuxSampler {
44    
45     class InstrumentEditorFactory {
46     public:
47     class InnerFactory {
48     public:
49 schoenebeck 2503 virtual ~InnerFactory() {}
50 schoenebeck 1374 virtual InstrumentEditor* Create() = 0;
51     virtual void Destroy(InstrumentEditor* pEditor) = 0;
52     };
53    
54     template<class PluginClass_T>
55     class InnerFactoryTemplate : public InnerFactory {
56     public:
57     virtual InstrumentEditor* Create() {
58     return new PluginClass_T();
59     }
60    
61     virtual void Destroy(InstrumentEditor* pEditor) {
62     delete pEditor;
63     }
64     };
65    
66     template<class PluginClass_T>
67     class InnerFactoryRegistrator {
68     public:
69     InnerFactoryRegistrator() {
70     InnerFactoryTemplate<PluginClass_T>* pInnerFactory =
71     new InnerFactoryTemplate<PluginClass_T>();
72     InstrumentEditor* pEditor = pInnerFactory->Create();
73     if (InnerFactories.count(pEditor->Name())) {
74     pInnerFactory->Destroy(pEditor);
75     delete pInnerFactory;
76     } else {
77     InnerFactories[pEditor->Name()] = pInnerFactory;
78     pInnerFactory->Destroy(pEditor);
79     }
80     }
81    
82     ~InnerFactoryRegistrator() {
83     InnerFactoryTemplate<PluginClass_T> innerFactory;
84     InstrumentEditor* pEditor = innerFactory.Create();
85     if (InnerFactories.count(pEditor->Name())) {
86     InnerFactory* pZombie =
87     InnerFactories[pEditor->Name()];
88     InnerFactories.erase(pEditor->Name());
89     if (pZombie) delete pZombie;
90     }
91     innerFactory.Destroy(pEditor);
92     }
93     };
94    
95     static InstrumentEditor* Create(String InstrumentEditorName) throw (Exception);
96     static void Destroy(InstrumentEditor* pInstrumentEditor) throw (Exception);
97     static std::vector<String> AvailableEditors();
98     static String AvailableEditorsAsString();
99     static std::vector<String> MatchingEditors(String sTypeName, String sTypeVersion);
100     static void LoadPlugins();
101     static void ClosePlugins();
102    
103     protected:
104     static std::map<String, InnerFactory*> InnerFactories;
105     static bool bPluginsLoaded;
106     static std::list<void*> LoadedDLLs;
107 persson 1897
108     private:
109     static bool LoadPlugins(String plugindir);
110 schoenebeck 1374 };
111    
112     } // namespace LinuxSampler
113    
114     #endif // LS_INSTRUMENT_EDITOR_FACTORY_H

  ViewVC Help
Powered by ViewVC