Gazebo Plugin

API Reference

2.0.3
gz/plugin/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 
18 
19 #ifndef GZ_PLUGIN_SPECIALIZEDPLUGIN_HH_
20 #define GZ_PLUGIN_SPECIALIZEDPLUGIN_HH_
21 
22 #include <memory>
23 #include "gz/plugin/Plugin.hh"
24 
25 namespace gz
26 {
27  namespace plugin
28  {
29  // Forward declarations
30  namespace detail {
31  template <class, class> class ComposePlugin;
32  template <class> class SelectSpecializers;
33  }
34 
35  // Forward declaration of the variadic template SpecializedPlugin class.
36  template <class... OtherSpecInterfaces>
38 
64  template <class SpecInterface>
65  class SpecializedPlugin<SpecInterface> : public virtual Plugin
66  {
67  // -------------------- Public API ---------------------
68 
69  // Inherit function overloads
70  public: using Plugin::QueryInterface;
71  public: using Plugin::QueryInterfaceSharedPtr;
72  public: using Plugin::HasInterface;
73 
74  // Documentation inherited
75  public: template <class Interface>
76  Interface *QueryInterface();
77 
78  // Documentation inherited
79  public: template <class Interface>
80  const Interface *QueryInterface() const;
81 
82  // Documentation inherited
83  public: template <class Interface>
84  std::shared_ptr<Interface> QueryInterfaceSharedPtr();
85 
86  // Documentation inherited
87  public: template <class Interface>
88  std::shared_ptr<const Interface> QueryInterfaceSharedPtr() const;
89 
90  // Documentation inherited
91  public: template <class Interface>
92  bool HasInterface() const;
93 
94 
95  // -------------------- Private API ---------------------
96 
97  // Declare friendship
98  template <class...> friend class SpecializedPlugin;
99  template <class, class> friend class detail::ComposePlugin;
100  template <class> friend class detail::SelectSpecializers;
101  template <class> friend class TemplatePluginPtr;
102 
107  private: template <class T> struct type { };
108 
113  private: template <class Interface>
114  Interface *PrivateQueryInterface(type<Interface>);
115 
120  private: SpecInterface *PrivateQueryInterface(type<SpecInterface>);
121 
126  private: template <class Interface>
127  const Interface *PrivateQueryInterface(type<Interface>) const;
128 
133  private: const SpecInterface *PrivateQueryInterface(
134  type<SpecInterface>) const;
135 
140  private: template <class Interface>
141  bool PrivateHasInterface(type<Interface>) const;
142 
147  private: bool PrivateHasInterface(type<SpecInterface>) const;
148 
149  // Dev note (MXG): The privateSpecializedInterfaceIterator object must be
150  // available to the user during their compile time, so it cannot be hidden
151  // using PIMPL. The iterator is const because it must always point to the
152  // same entry throughout its entire lifecycle.
154  private:
155  const Plugin::InterfaceMap::iterator privateSpecializedInterfaceIterator;
156 
158  protected: SpecializedPlugin();
159  };
160  }
161 }
162 
163 #include "gz/plugin/detail/SpecializedPlugin.hh"
164 
165 #endif