NCBI C++ ToolKit
plugin_manager_store.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CORELIB___PLUGIN_MANAGER_STORE__HPP
2 #define CORELIB___PLUGIN_MANAGER_STORE__HPP
3 
4 /* $Id: plugin_manager_store.hpp 45925 2010-06-01 18:08:33Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Anatoliy Kuznetsov
30  *
31  * File Description:
32  *
33  */
34 
36 #include <corelib/ncbimtx.hpp>
37 #include <typeinfo>
38 
40 
42 {
43 public:
44  typedef string TKey;
46 
47  static SSystemFastMutex& GetMutex(void);
48 
49  static TObject* GetBase(const TKey& key);
50  static void PutBase(const TKey& key, TObject* pm);
51 
52  static void ReportKeyConflict(const TKey& key,
53  const TObject* old_pm,
54  const type_info& new_pm_type);
55 };
56 
57 template<class Interface>
59 {
60 public:
63  typedef Interface TInterface;
65 
66  static TPluginManager* Get(void)
67  {
69  }
70 
71  static TPluginManager* Get(const string& key)
72  {
73  TPluginManagerBase* pm_base;
74  {{
77  if ( !pm_base ) {
78  pm_base = new TPluginManager;
80  _TRACE("CPluginManagerGetter<>::Get(): "
81  "created new instance: "<< key);
82  }
83  _ASSERT(pm_base);
84  }}
85  TPluginManager* pm = dynamic_cast<TPluginManager*>(pm_base);
86  if ( !pm ) {
88  ReportKeyConflict(key, pm_base, typeid(TPluginManager));
89  }
90  _ASSERT(pm);
91  return pm;
92  }
93 };
94 
95 
96 #if 1
97 /// deprecated interface to CPluginManager
98 ///
99 /// @note
100 /// We need a separate class here to make sure singleton instatiates
101 /// only once (and in the correct DLL)
102 ///
104 {
105 public:
106 
107  /// Utility class to get plugin manager from the store
108  /// If it is not there, class will create and add new instance
109  /// to the store.
110  ///
111  /// @note
112  /// Created plugin manager should be considered under-constructed
113  /// since it has no regisitered entry points or dll resolver.
114  template<class TInterface>
115  struct CPMMaker
116  {
118 
119  static
121  {
123  }
124 
125  /// @param pm_name
126  /// Storage name for plugin manager
127  static
128  CPluginManager<TInterface>* Get(const string& pm_name)
129  {
131  }
132  };
133 
134 };
135 #endif
136 
137 
138 template<typename TInterface, typename TEntryPoint>
139 inline
140 void RegisterEntryPoint(TEntryPoint plugin_entry_point)
141 {
142  typedef CPluginManager<TInterface> TPluginManager;
144  _ASSERT(manager);
145  manager->RegisterWithEntryPoint(plugin_entry_point);
146 }
147 
148 
150 
151 #endif /* CORELIB___PLUGIN_MANAGER_STORE__HPP */
CInterfaceVersion<> –.
static void ReportKeyConflict(const TKey &key, const TObject *old_pm, const type_info &new_pm_type)
static TObject * GetBase(const TKey &key)
static void PutBase(const TKey &key, TObject *pm)
static SSystemFastMutex & GetMutex(void)
static TPluginManager * Get(const string &key)
CPluginManager< TInterface > TPluginManager
CPluginManagerGetterImpl::TObject TPluginManagerBase
static TPluginManager * Get(void)
CPluginManagerGetterImpl::TKey TPluginManagerKey
deprecated interface to CPluginManager
CPluginManager<> –.
CRef –.
Definition: ncbiobj.hpp:618
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1283
CBioseq_Base_Info & GetBase(CTSE_Info &tse, const CBioObjectId &id)
const struct ncbi::grid::netcache::search::fields::KEY key
Multi-threading – mutexes; rw-locks; semaphore.
Plugin manager (using class factory paradigm).
void RegisterEntryPoint(TEntryPoint plugin_entry_point)
Utility class to get plugin manager from the store If it is not there, class will create and add new ...
static CPluginManager< TInterface > * Get(void)
CPluginManager< TInterface > TPluginManager
static CPluginManager< TInterface > * Get(const string &pm_name)
#define _ASSERT
Modified on Sat Apr 13 11:44:17 2024 by modify_doxy.py rev. 669887