Gazebo Plugin

API Reference

1.2.1
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_PLUGIN_PLUGIN_HH_
20#define IGNITION_PLUGIN_PLUGIN_HH_
21
22#include <memory>
23#include <map>
24#include <string>
25
26#include <ignition/utilities/SuppressWarning.hh>
27
28#include <ignition/plugin/Export.hh>
30
31namespace ignition
32{
33 namespace plugin
34 {
35 // Forward declaration
36 namespace detail {
37 template <class, class> class ComposePlugin;
38 template <class> class SelectSpecializers;
39 }
40 class EnablePluginFromThis;
41 class WeakPluginPtr;
42
43 class IGNITION_PLUGIN_VISIBLE Plugin
44 {
45 // -------------------- Public API ---------------------
46
62 public: template <class Interface>
63 Interface *QueryInterface();
64
66 public: template <class Interface>
67 const Interface *QueryInterface() const;
68
71 public: template <class Interface>
72 IGN_DEPRECATED(0.0)
73 Interface *QueryInterface(const std::string &/*_interfaceName*/);
74
77 public: template <class Interface>
78 IGN_DEPRECATED(0.0)
79 const Interface *QueryInterface(
80 const std::string &/*_interfaceName*/) const;
81
99 public: template <class Interface>
100 std::shared_ptr<Interface> QueryInterfaceSharedPtr();
101
104 public: template <class Interface>
105 std::shared_ptr<const Interface> QueryInterfaceSharedPtr() const;
106
109 public: template <class Interface>
110 IGN_DEPRECATED(0.0)
111 std::shared_ptr<Interface> QueryInterfaceSharedPtr(
112 const std::string &/*_interfaceName*/);
113
116 public: template <class Interface>
117 IGN_DEPRECATED(0.0)
118 std::shared_ptr<const Interface> QueryInterfaceSharedPtr(
119 const std::string &/*_interfaceName*/) const;
120
124 public: template <class Interface>
125 bool HasInterface() const;
126
140 public: bool HasInterface(const std::string &_interfaceName,
141 const bool _demangled = true) const;
142
146 public: const std::string *Name() const;
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 template <class> friend class detail::SelectSpecializers;
155 friend class WeakPluginPtr;
156
160 protected: Plugin();
161
163 private: void *PrivateQueryInterface(
164 const std::string &_interfaceName) const;
165
167 private: void PrivateCopyPluginInstance(const Plugin &_other) const;
168
174 private: void PrivateCopyPluginInstance(
175 const ConstInfoPtr &_info,
176 const std::shared_ptr<void> &_instancePtr) const;
177
183 private: void PrivateCreatePluginInstance(
184 const ConstInfoPtr &_info,
185 const std::shared_ptr<void> &_dlHandlePtr) const;
186
189 private: const std::shared_ptr<void> &PrivateGetInstancePtr() const;
190
192 private: const ConstInfoPtr &PrivateGetInfoPtr() const;
193
199 public: using InterfaceMap = std::map<std::string, void*>;
200
203 private: InterfaceMap::iterator PrivateGetOrCreateIterator(
204 const std::string &_interfaceName);
205
206 class Implementation;
207 IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
209 private: const std::unique_ptr<Implementation> dataPtr;
210 IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
211
213 public: virtual ~Plugin();
214 };
215 }
216}
217
218#include "ignition/plugin/detail/Plugin.hh"
219
220#endif
EnablePluginFromThis is an optional base class which can be inherited by Plugin classes....
Definition: EnablePluginFromThis.hh:41
Definition: Plugin.hh:44
bool HasInterface(const std::string &_interfaceName, const bool _demangled=true) const
Checks if this Plugin has the specified type of interface.
const Interface * QueryInterface() const
const-qualified version of QueryInterface<Interface>()
std::shared_ptr< Interface > QueryInterfaceSharedPtr()
Get the requested interface as a std::shared_ptr. The template argument Interface must exactly match ...
std::shared_ptr< const Interface > QueryInterfaceSharedPtr() const
Same as QueryInterfaceSharedPtr<Interface>(), but it returns a std::shared_ptr to a const-qualified I...
const Interface * QueryInterface(const std::string &) const
const-qualified version of QueryInterface<Interface>(std::string)
const std::string * Name() const
Gets the name of this Plugin.
std::shared_ptr< const Interface > QueryInterfaceSharedPtr(const std::string &) const
Same as QueryInterfaceSharedPtr<Interface>(std::string), but it returns a std::shared_ptr to a const-...
friend class EnablePluginFromThis
Definition: Plugin.hh:154
friend class SpecializedPlugin
Definition: Plugin.hh:151
virtual ~Plugin()
Virtual destructor.
std::shared_ptr< Interface > QueryInterfaceSharedPtr(const std::string &)
This version of QueryInterfaceSharedPtr has been deprecated in favor of the version that does not tak...
friend class WeakPluginPtr
Definition: Plugin.hh:155
Plugin()
Default constructor. This is kept protected to discourage users from instantiating them directly....
Interface * QueryInterface(const std::string &)
This function has been deprecated in favor of the version of QueryInterface which does not take a std...
Interface * QueryInterface()
Get an interface of the specified type, if it is provided by this plugin.
bool HasInterface() const
Checks if this Plugin has the specified type of interface.
Definition: SpecializedPlugin.hh:37
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the igni...
Definition: PluginPtr.hh:53
WeakPluginPtr is a non-reference-holding smart pointer for a Plugin. WeakPluginPtr is analogous to st...
Definition: WeakPluginPtr.hh:40
Definition: EnablePluginFromThis.hh:26
STL namespace.