2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/PluginManager.h
20 * Plugin management template
23 #ifndef __xmltooling_plugin_h__
24 #define __xmltooling_plugin_h__
26 #include <xmltooling/base.h>
27 #include <xmltooling/exceptions.h>
32 #if defined (_MSC_VER)
33 #pragma warning( push )
34 #pragma warning( disable : 4250 4251 )
37 namespace xmltooling {
40 * Template for management/access to plugins constructed based on a Key type
41 * and arbitrary parameters.
43 * @param T class of plugin to manage
44 * @param Key the key for type lookup
45 * @param Params parameters for plugin construction
47 template <class T, class Key, typename Params> class PluginManager
53 /** Factory function for plugin. */
54 typedef T* Factory(const Params&);
57 * Registers the factory for a given type.
59 * @param type the key to the plugin type
60 * @param factory the factory function for the plugin type
62 void registerFactory(const Key& type, typename PluginManager::Factory* factory) {
68 * Unregisters the factory for a given type.
70 * @param type the key to the plugin type
72 void deregisterFactory(const Key& type) {
77 * Unregisters all registered factories.
79 void deregisterFactories() {
84 * Builds a new instance of a plugin of a given type, configuring it
85 * with the supplied parameters.
87 * @param type the key to the plugin type
88 * @param p parameters to configure plugin
89 * @return the constructed plugin
91 T* newPlugin(const Key& type, const Params& p) {
92 typename std::map<Key, typename PluginManager::Factory*>::const_iterator i=m_map.find(type);
94 throw UnknownExtensionException("Unknown plugin type.");
99 std::map<Key, typename PluginManager::Factory*> m_map;
104 #if defined (_MSC_VER)
105 #pragma warning( pop )
108 #endif /* __xmltooling_plugin_h__ */