Gazebo Common

API Reference

5.7.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 #ifndef IGNITION_COMMON_PLUGIN_HH_
19 #define IGNITION_COMMON_PLUGIN_HH_
20 
21 #include <memory>
22 #include <map>
23 #include <string>
24 
26 #include <gz/common/Export.hh>
27 #include <gz/utils/SuppressWarning.hh>
28 
29 namespace gz
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: GZ_DEPRECATED(5) 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 
176  public: using InterfaceMap = std::map<std::string, void*>;
177 
180  private: InterfaceMap::iterator PrivateGetOrCreateIterator(
181  const std::string &_interfaceName);
182 
183  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
185  private: const std::unique_ptr<PluginPrivate> dataPtr;
186  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
187 
189  public: virtual ~Plugin();
190  };
191  }
192 }
193 
194 #include "ignition/common/detail/Plugin.hh"
195 
196 #endif