Ignition Common

API Reference

3.0.0
detail/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_COMMON_DETAIL_PLUGIN_HH_
20 #define IGNITION_COMMON_DETAIL_PLUGIN_HH_
21 
22 #include <memory>
23 #include <string>
25 
26 namespace ignition
27 {
28  namespace common
29  {
31  template <class Interface>
33  {
34  return static_cast<Interface*>(
35  this->PrivateGetInterface(Interface::IGNCOMMONInterfaceName));
36  }
37 
39  template <class Interface>
40  const Interface *Plugin::QueryInterface() const
41  {
42  return static_cast<const Interface*>(
43  this->PrivateGetInterface(Interface::IGNCOMMONInterfaceName));
44  }
45 
47  template <class Interface>
48  Interface *Plugin::QueryInterface(const std::string &_interfaceName)
49  {
50  return static_cast<Interface*>(
51  this->PrivateGetInterface(_interfaceName));
52  }
53 
55  template <class Interface>
56  const Interface *Plugin::QueryInterface(
57  const std::string &_interfaceName) const
58  {
59  return static_cast<const Interface*>(
60  this->PrivateGetInterface(_interfaceName));
61  }
62 
64  template <class Interface>
66  {
67  return this->QueryInterfaceSharedPtr<Interface>(
68  Interface::IGNCOMMONInterfaceName);
69  }
70 
72  template <class Interface>
74  {
75  return this->QueryInterfaceSharedPtr<Interface>(
76  Interface::IGNCOMMONInterfaceName);
77  }
78 
80  template <class Interface>
82  const std::string &_interfaceName)
83  {
84  Interface *ptr = this->QueryInterface<Interface>(_interfaceName);
85  if (ptr)
86  return std::shared_ptr<Interface>(this->PrivateGetInstancePtr(), ptr);
87 
88  return nullptr;
89  }
90 
92  template <class Interface>
94  const std::string &_interfaceName) const
95  {
96  const Interface *ptr = this->QueryInterface<Interface>(_interfaceName);
97  if (ptr)
98  return std::shared_ptr<Interface>(this->PrivateGetInstancePtr(), ptr);
99 
100  return nullptr;
101  }
102 
104  template <class Interface>
105  bool Plugin::HasInterface() const
106  {
107  return this->HasInterface(Interface::IGNCOMMONInterfaceName);
108  }
109  }
110 }
111 
112 #endif
STL class.
bool HasInterface() const
Returns true if this Plugin has the specified type of interface. Note that this function only works w...
Definition: detail/Plugin.hh:105
Interface * QueryInterface()
Get an interface of the specified type. Note that this function only works when the Interface type is...
Definition: detail/Plugin.hh:32
Forward declarations for the common classes.
std::shared_ptr< Interface > QueryInterfaceSharedPtr()
Get the requested interface as a std::shared_ptr. Note that this function only works when the Interfa...
Definition: detail/Plugin.hh:65