Ignition Common

API Reference

3.5.0
Plugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 
19 #ifndef IGNITION_COMMON_PLUGIN_HH_
20 #define IGNITION_COMMON_PLUGIN_HH_
21 
22 #include <memory>
23 #include <map>
24 #include <string>
25 
26 #include <ignition/common/Export.hh>
28 
29 namespace ignition
30 {
31  namespace common
32  {
33  // Forward declarations
34  struct PluginInfo;
35  class PluginPrivate;
36  namespace detail { template <class, class> class ComposePlugin; }
37 
38  class IGNITION_COMMON_VISIBLE Plugin
39  {
40  // -------------------- Public API ---------------------
41 
55  public: template <class Interface>
56  Interface *QueryInterface();
57 
59  public: template <class Interface>
60  const Interface *QueryInterface() const;
61 
81  public: template <class Interface>
82  Interface *QueryInterface(const std::string &_interfaceName);
83 
86  public: template <class Interface>
87  const Interface *QueryInterface(
88  const std::string &_interfaceName) const;
89 
95  public: template <class Interface>
96  std::shared_ptr<Interface> QueryInterfaceSharedPtr();
97 
100  public: template <class Interface>
101  std::shared_ptr<const Interface> QueryInterfaceSharedPtr() const;
102 
122  public: template <class Interface>
123  std::shared_ptr<Interface> QueryInterfaceSharedPtr(
124  const std::string &_interfaceName);
125 
128  public: template <class Interface>
129  std::shared_ptr<const Interface> QueryInterfaceSharedPtr(
130  const std::string &_interfaceName) const;
131 
137  public: template <class Interface>
138  bool HasInterface() const;
139 
145  public: bool HasInterface(const std::string &_interfaceName) const;
146 
147 
148  // -------------------- Private API -----------------------
149 
150  template <class> friend class TemplatePluginPtr;
151  template <class...> friend class SpecializedPlugin;
152  template <class, class> friend class detail::ComposePlugin;
153 
156  private: Plugin();
157 
159  private: void *PrivateGetInterface(
160  const std::string &_interfaceName) const;
161 
163  private: void PrivateCopyPluginInstance(const Plugin &_other) const;
164 
166  private: void PrivateSetPluginInstance(const PluginInfo *_info) const;
167 
170  private: const std::shared_ptr<void>& PrivateGetInstancePtr() const;
171 
177 
180  private: InterfaceMap::iterator PrivateGetOrCreateIterator(
181  const std::string &_interfaceName);
182 
185  private: const std::unique_ptr<PluginPrivate> dataPtr;
187 
189  public: virtual ~Plugin();
190  };
191  }
192 }
193 
194 #include "ignition/common/detail/Plugin.hh"
195 
196 #endif
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the Plug...
Definition: PluginPtr.hh:53
Definition: Plugin.hh:38
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
friend class SpecializedPlugin
Definition: Plugin.hh:151
STL class.
STL class.
Holds info required to construct a plugin.
Definition: PluginInfo.hh:38
Forward declarations for the common classes.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64