/[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 1481 - (hide annotations) (download) (as text)
Wed Nov 14 23:42:15 2007 UTC (16 years, 6 months ago) by senoner
File MIME type: text/x-c++hdr
File size: 4695 byte(s)
* win32 port work in progress:
* - implemented win32 support in the following classes:
* Thread, Condition, Mutex, Path, LscpServer
* - lscp.y use DONTCARE instead of VOID
*  (a win32 symbol defined)
* - completed win32 editor plugin loader

1 schoenebeck 1374 /***************************************************************************
2     * *
3     * Copyright (C) 2007 Christian Schoenebeck *
4     * *
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     virtual InstrumentEditor* Create() = 0;
50     virtual void Destroy(InstrumentEditor* pEditor) = 0;
51     };
52    
53     template<class PluginClass_T>
54     class InnerFactoryTemplate : public InnerFactory {
55     public:
56     virtual InstrumentEditor* Create() {
57     return new PluginClass_T();
58     }
59    
60     virtual void Destroy(InstrumentEditor* pEditor) {
61     delete pEditor;
62     }
63     };
64    
65     template<class PluginClass_T>
66     class InnerFactoryRegistrator {
67     public:
68     InnerFactoryRegistrator() {
69     InnerFactoryTemplate<PluginClass_T>* pInnerFactory =
70     new InnerFactoryTemplate<PluginClass_T>();
71     InstrumentEditor* pEditor = pInnerFactory->Create();
72     if (InnerFactories.count(pEditor->Name())) {
73     pInnerFactory->Destroy(pEditor);
74     delete pInnerFactory;
75     } else {
76     InnerFactories[pEditor->Name()] = pInnerFactory;
77     pInnerFactory->Destroy(pEditor);
78     }
79     }
80    
81     ~InnerFactoryRegistrator() {
82     InnerFactoryTemplate<PluginClass_T> innerFactory;
83     InstrumentEditor* pEditor = innerFactory.Create();
84     if (InnerFactories.count(pEditor->Name())) {
85     InnerFactory* pZombie =
86     InnerFactories[pEditor->Name()];
87     InnerFactories.erase(pEditor->Name());
88     if (pZombie) delete pZombie;
89     }
90     innerFactory.Destroy(pEditor);
91     }
92     };
93    
94     static InstrumentEditor* Create(String InstrumentEditorName) throw (Exception);
95     static void Destroy(InstrumentEditor* pInstrumentEditor) throw (Exception);
96     static std::vector<String> AvailableEditors();
97     static String AvailableEditorsAsString();
98     static std::vector<String> MatchingEditors(String sTypeName, String sTypeVersion);
99     static void LoadPlugins();
100     static void ClosePlugins();
101    
102     protected:
103     static std::map<String, InnerFactory*> InnerFactories;
104     static bool bPluginsLoaded;
105     static std::list<void*> LoadedDLLs;
106     };
107    
108     } // namespace LinuxSampler
109    
110     #endif // LS_INSTRUMENT_EDITOR_FACTORY_H

  ViewVC Help
Powered by ViewVC