2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/PluginManager.h
24 * Plugin management template
27 #ifndef __xmltooling_plugin_h__
28 #define __xmltooling_plugin_h__
30 #include <xmltooling/base.h>
31 #include <xmltooling/exceptions.h>
36 #if defined (_MSC_VER)
37 #pragma warning( push )
38 #pragma warning( disable : 4250 4251 )
41 namespace xmltooling {
44 * Template for management/access to plugins constructed based on a Key type
45 * and arbitrary parameters.
47 * @param T class of plugin to manage
48 * @param Key the key for type lookup
49 * @param Params parameters for plugin construction
51 template <class T, class Key, typename Params> class PluginManager
57 /** Factory function for plugin. */
58 typedef T* Factory(const Params&);
61 * Registers the factory for a given type.
63 * @param type the key to the plugin type
64 * @param factory the factory function for the plugin type
66 void registerFactory(const Key& type, typename PluginManager::Factory* factory) {
72 * Unregisters the factory for a given type.
74 * @param type the key to the plugin type
76 void deregisterFactory(const Key& type) {
81 * Unregisters all registered factories.
83 void deregisterFactories() {
88 * Builds a new instance of a plugin of a given type, configuring it
89 * with the supplied parameters.
91 * @param type the key to the plugin type
92 * @param p parameters to configure plugin
93 * @return the constructed plugin
95 T* newPlugin(const Key& type, const Params& p) {
96 typename std::map<Key, typename PluginManager::Factory*>::const_iterator i=m_map.find(type);
98 throw UnknownExtensionException("Unknown plugin type.");
103 std::map<Key, typename PluginManager::Factory*> m_map;
108 #if defined (_MSC_VER)
109 #pragma warning( pop )
112 #endif /* __xmltooling_plugin_h__ */