Gazebo Common

API Reference

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