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> 24 #include "ignition/common/Plugin.hh" 25 26 namespace ignition 27 { 28 namespace common 29 { 30 ////////////////////////////////////////////////// 31 template <class Interface> QueryInterface()32 Interface *Plugin::QueryInterface() 33 { 34 return static_cast<Interface*>( 35 this->PrivateGetInterface(Interface::IGNCOMMONInterfaceName)); 36 } 37 38 ////////////////////////////////////////////////// 39 template <class Interface> QueryInterface() const40 const Interface *Plugin::QueryInterface() const 41 { 42 return static_cast<const Interface*>( 43 this->PrivateGetInterface(Interface::IGNCOMMONInterfaceName)); 44 } 45 46 ////////////////////////////////////////////////// 47 template <class Interface> QueryInterface(const std::string & _interfaceName)48 Interface *Plugin::QueryInterface(const std::string &_interfaceName) 49 { 50 return static_cast<Interface*>( 51 this->PrivateGetInterface(_interfaceName)); 52 } 53 54 ////////////////////////////////////////////////// 55 template <class Interface> QueryInterface(const std::string & _interfaceName) const56 const Interface *Plugin::QueryInterface( 57 const std::string &_interfaceName) const 58 { 59 return static_cast<const Interface*>( 60 this->PrivateGetInterface(_interfaceName)); 61 } 62 63 ////////////////////////////////////////////////// 64 template <class Interface> QueryInterfaceSharedPtr()65 std::shared_ptr<Interface> Plugin::QueryInterfaceSharedPtr() 66 { 67 return this->QueryInterfaceSharedPtr<Interface>( 68 Interface::IGNCOMMONInterfaceName); 69 } 70 71 ////////////////////////////////////////////////// 72 template <class Interface> QueryInterfaceSharedPtr() const73 std::shared_ptr<const Interface> Plugin::QueryInterfaceSharedPtr() const 74 { 75 return this->QueryInterfaceSharedPtr<Interface>( 76 Interface::IGNCOMMONInterfaceName); 77 } 78 79 ////////////////////////////////////////////////// 80 template <class Interface> QueryInterfaceSharedPtr(const std::string & _interfaceName)81 std::shared_ptr<Interface> Plugin::QueryInterfaceSharedPtr( 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 91 ////////////////////////////////////////////////// 92 template <class Interface> QueryInterfaceSharedPtr(const std::string & _interfaceName) const93 std::shared_ptr<const Interface> Plugin::QueryInterfaceSharedPtr( 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 103 ////////////////////////////////////////////////// 104 template <class Interface> HasInterface() const105 bool Plugin::HasInterface() const 106 { 107 return this->HasInterface(Interface::IGNCOMMONInterfaceName); 108 } 109 } 110 } 111 112 #endif 113