Gazebo Common

API Reference

3.17.0
gz/common/SpecializedPlugin.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 #ifndef GZ_COMMON_SPECIALIZEDPLUGIN_HH_
18 #define GZ_COMMON_SPECIALIZEDPLUGIN_HH_
19 
20 #include <memory>
21 
22 #include "gz/common/Plugin.hh"
23 
24 namespace ignition
25 {
26  namespace common
27  {
28  // Forward declarations
29  namespace detail { template <class, class> class ComposePlugin; }
30  struct PluginInfo;
31 
32  // Forward declaration of the variadic template SpecializedPlugin class.
33  template <class... OtherSpecInterfaces>
35 
67  template <class SpecInterface>
68  class SpecializedPlugin<SpecInterface> : public virtual Plugin
69  {
70  // -------------------- Public API ---------------------
71 
72  // Inherit function overloads
73  public: using Plugin::QueryInterface;
74  public: using Plugin::QueryInterfaceSharedPtr;
75  public: using Plugin::HasInterface;
76 
77  // Documentation inherited
78  public: template <class Interface>
79  Interface *QueryInterface();
80 
81  // Documentation inherited
82  public: template <class Interface>
83  const Interface *QueryInterface() const;
84 
85  // Documentation inherited
86  public: template <class Interface>
87  std::shared_ptr<Interface> QueryInterfaceSharedPtr();
88 
89  // Documentation inherited
90  public: template <class Interface>
91  std::shared_ptr<const Interface> QueryInterfaceSharedPtr() const;
92 
93  // Documentation inherited
94  public: template <class Interface>
95  bool HasInterface() const;
96 
97 
98  // -------------------- Private API ---------------------
99 
100  // Declare friendship
101  template <class...> friend class SpecializedPlugin;
102  template <class, class> friend class detail::ComposePlugin;
103  template <class> friend class TemplatePluginPtr;
104 
106  private: SpecializedPlugin();
107 
112  private: template <class T> struct type { };
113 
118  private: template <class Interface>
119  Interface *PrivateQueryInterface(type<Interface> _type);
120 
125  private: SpecInterface *PrivateQueryInterface(
126  type<SpecInterface> _type);
127 
132  private: template <class Interface>
133  const Interface *PrivateQueryInterface(type<Interface> _type)
134  const;
135 
140  private: const SpecInterface *PrivateQueryInterface(
141  type<SpecInterface> _type) const;
142 
147  private: template <class Interface>
148  bool PrivateHasInterface(type<Interface> _type) const;
149 
154  private: bool PrivateHasInterface(type<SpecInterface> _type) const;
155 
157  private: const Plugin::InterfaceMap::iterator
158  privateSpecializedInterfaceIterator;
159 
160  // Dev note (MXG): The privateSpecializedInterfaceIterator object must be
161  // available to the user during their compile time, so it cannot be hidden
162  // using PIMPL. The iterator is const because it must always point to the
163  // same entry throughout its entire lifecycle.
164  };
165  }
166 }
167 
168 #include "gz/common/detail/SpecializedPlugin.hh"
169 
170 #endif
friend class TemplatePluginPtr
Definition: gz/common/SpecializedPlugin.hh:103
Forward declarations for the common classes.
STL class.
friend class SpecializedPlugin
Definition: gz/common/SpecializedPlugin.hh:101
bool HasInterface() const
Returns true if this Plugin has the specified type of interface. Note that this function only works w...
Definition: gz/common/SpecializedPlugin.hh:34
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...
Definition: gz/common/Plugin.hh:38