Gazebo Common

API Reference

4.7.0
gz/common/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 <gz/common/config.hh>
27 #include <gz/common/Export.hh>
29 
30 namespace ignition
31 {
32  namespace common
33  {
34  // Forward declarations
35  struct PluginInfo;
36  class PluginPrivate;
37  namespace detail { template <class, class> class ComposePlugin; }
38 
39  class IGNITION_COMMON_VISIBLE Plugin
40  {
41  // -------------------- Public API ---------------------
42 
56  public: template <class Interface>
57  Interface *QueryInterface();
58 
60  public: template <class Interface>
61  const Interface *QueryInterface() const;
62 
82  public: template <class Interface>
83  Interface *QueryInterface(const std::string &_interfaceName);
84 
87  public: template <class Interface>
88  const Interface *QueryInterface(
89  const std::string &_interfaceName) const;
90 
96  public: template <class Interface>
97  std::shared_ptr<Interface> QueryInterfaceSharedPtr();
98 
101  public: template <class Interface>
102  std::shared_ptr<const Interface> QueryInterfaceSharedPtr() const;
103 
123  public: template <class Interface>
124  std::shared_ptr<Interface> QueryInterfaceSharedPtr(
125  const std::string &_interfaceName);
126 
129  public: template <class Interface>
130  std::shared_ptr<const Interface> QueryInterfaceSharedPtr(
131  const std::string &_interfaceName) const;
132 
138  public: template <class Interface>
139  bool HasInterface() const;
140 
146  public: bool HasInterface(const std::string &_interfaceName) const;
147 
148 
149  // -------------------- Private API -----------------------
150 
151  template <class> friend class TemplatePluginPtr;
152  template <class...> friend class SpecializedPlugin;
153  template <class, class> friend class detail::ComposePlugin;
154 
157  private: Plugin();
158 
160  private: void *PrivateGetInterface(
161  const std::string &_interfaceName) const;
162 
164  private: void PrivateCopyPluginInstance(const Plugin &_other) const;
165 
167  private: void PrivateSetPluginInstance(const PluginInfo *_info) const;
168 
171  private: const std::shared_ptr<void>& PrivateGetInstancePtr() const;
172 
178 
181  private: InterfaceMap::iterator PrivateGetOrCreateIterator(
182  const std::string &_interfaceName);
183 
186  private: const std::unique_ptr<PluginPrivate> dataPtr;
188 
190  public: virtual ~Plugin();
191  };
192  }
193 }
194 
195 #include "gz/common/detail/Plugin.hh"
196 
197 #endif
Forward declarations for the common classes.
STL class.
STL class.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
friend class SpecializedPlugin
Definition: gz/common/Plugin.hh:152
Holds info required to construct a plugin.
Definition: gz/common/PluginInfo.hh:40
virtual ~Plugin()
Virtual destructor.
bool HasInterface() const
Returns true if this Plugin has the specified type of interface. Note that this function only works w...
STL class.
std::shared_ptr< Interface > QueryInterfaceSharedPtr()
Get the requested interface as a std::shared_ptr. Note that this function only works when the Interfa...
Interface * QueryInterface()
Get an interface of the specified type. Note that this function only works when the Interface type is...
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the igni...
Definition: gz/common/PluginPtr.hh:54
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
Definition: gz/common/Plugin.hh:39