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_PLUGIN_DETAIL_PLUGIN_HH_
20 #define IGNITION_PLUGIN_DETAIL_PLUGIN_HH_
21 
22 #include <memory>
23 #include <string>
24 #include <ignition/plugin/Plugin.hh>
25 
26 namespace ignition
27 {
28   namespace plugin
29   {
30     //////////////////////////////////////////////////
31     template <class Interface>
QueryInterface()32     Interface *Plugin::QueryInterface()
33     {
34       return static_cast<Interface*>(
35             this->PrivateQueryInterface(typeid(Interface).name()));
36     }
37 
38     //////////////////////////////////////////////////
39     template <class Interface>
QueryInterface() const40     const Interface *Plugin::QueryInterface() const
41     {
42       return static_cast<const Interface*>(
43             this->PrivateQueryInterface(typeid(Interface).name()));
44     }
45 
46     //////////////////////////////////////////////////
47     template <class Interface>
QueryInterface(const std::string &)48     Interface *Plugin::QueryInterface(const std::string &/*_interfaceName*/)
49     {
50       return this->template QueryInterface<Interface>();
51     }
52 
53     //////////////////////////////////////////////////
54     template <class Interface>
QueryInterface(const std::string &) const55     const Interface *Plugin::QueryInterface(
56         const std::string &/*_interfaceName*/) const
57     {
58       return this->template QueryInterface<Interface>();
59     }
60 
61     //////////////////////////////////////////////////
62     template <class Interface>
QueryInterfaceSharedPtr()63     std::shared_ptr<Interface> Plugin::QueryInterfaceSharedPtr()
64     {
65       Interface *ptr = this->QueryInterface<Interface>();
66       if (ptr)
67         return std::shared_ptr<Interface>(this->PrivateGetInstancePtr(), ptr);
68 
69       return nullptr;
70     }
71 
72     //////////////////////////////////////////////////
73     template <class Interface>
QueryInterfaceSharedPtr() const74     std::shared_ptr<const Interface> Plugin::QueryInterfaceSharedPtr() const
75     {
76       const Interface *ptr = this->QueryInterface<Interface>();
77       if (ptr)
78       {
79         return std::shared_ptr<const Interface>(
80               this->PrivateGetInstancePtr(), ptr);
81       }
82 
83       return nullptr;
84     }
85 
86     //////////////////////////////////////////////////
87     template <class Interface>
QueryInterfaceSharedPtr(const std::string &)88     std::shared_ptr<Interface> Plugin::QueryInterfaceSharedPtr(
89         const std::string &/*_interfaceName*/)
90     {
91       return this->template QueryInterfaceSharedPtr<Interface>();
92     }
93 
94     //////////////////////////////////////////////////
95     template <class Interface>
QueryInterfaceSharedPtr(const std::string &) const96     std::shared_ptr<const Interface> Plugin::QueryInterfaceSharedPtr(
97         const std::string &/*_interfaceName*/) const
98     {
99       return this->template QueryInterfaceSharedPtr<Interface>();
100     }
101 
102     //////////////////////////////////////////////////
103     template <class Interface>
HasInterface() const104     bool Plugin::HasInterface() const
105     {
106       return this->HasInterface(typeid(Interface).name(), false);
107     }
108   }
109 }
110 
111 #endif
112