.. _program_listing_file__tmp_ws_src_osrf_testing_tools_cpp_osrf_testing_tools_cpp_include_osrf_testing_tools_cpp_demangle.hpp: Program Listing for File demangle.hpp ===================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/osrf_testing_tools_cpp/osrf_testing_tools_cpp/include/osrf_testing_tools_cpp/demangle.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2015 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OSRF_TESTING_TOOLS_CPP__DEMANGLE_HPP_ #define OSRF_TESTING_TOOLS_CPP__DEMANGLE_HPP_ #ifndef _WIN32 // Includes for abi::__cxa_demangle. #include #include #include #endif #include #include namespace osrf_testing_tools_cpp { std::string demangle_str(const std::string & mangled_typeid_name) { #if !defined(_WIN32) int status = 0; std::unique_ptr res { abi::__cxa_demangle(mangled_typeid_name.c_str(), NULL, NULL, &status), std::free }; return (status == 0) ? res.get() : mangled_typeid_name; #else return mangled_typeid_name; #endif } template std::string demangle(const T & instance) { (void)instance; // Cannot do demangling if on Windows or if we want to avoid memory allocation. #if !defined(_WIN32) std::string mangled_typeid_name = typeid(T).name(); return demangle_str(mangled_typeid_name); #else return typeid(T).name(); #endif } } // namespace osrf_testing_tools_cpp #endif // OSRF_TESTING_TOOLS_CPP__DEMANGLE_HPP_