Skip to content
Snippets Groups Projects
Commit 2ee56ee4 authored by sbund's avatar sbund
Browse files

Added C++ demangler in Utils/TypeInfo.hh

parent cd13c99d
No related branches found
No related tags found
No related merge requests found
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Definition of non-inline non-template functions
#include "TypeInfo.hh"
//#include "TypeInfo.ih"
// Custom includes
#include "malloc.h"
#define HAVE_DECL_BASENAME 1
#include "impl/demangle.h"
//#include "TypeInfo.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
// WARNING: This is completely g++ and libiberty dependent. The demangling
// interface isn't even explicitly exportet from libiberty. However, it is
// *EXTREMELY* helpful for debugging ...
prefix_ std::string satcom::lib::prettyName(std::type_info const & type)
{
char const * mangled = type.name();
char * demangled = ::cplus_demangle(mangled,DMGL_TYPES|DMGL_AUTO);
std::string name (demangled ? demangled : mangled);
if (demangled)
::free(demangled);
return name;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "TypeInfo.mpp"
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HH_TypeInfo_
#define HH_TypeInfo_ 1
// Custom includes
#include <string>
#include <typeinfo>
//#include "TypeInfo.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace satcom {
namespace lib {
std::string prettyName(std::type_info const & type);
}}
///////////////////////////////hh.e////////////////////////////////////////
//#include "TypeInfo.cci"
//#include "TypeInfo.ct"
//#include "TypeInfo.cti"
//#include "TypeInfo.mpp"
#endif
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Unit tests
//#include "TypeInfo.test.hh"
//#include "TypeInfo.test.ih"
// Custom includes
#include "TypeInfo.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace test {
struct Base {
virtual ~Base() {}
};
template <class C, unsigned N>
struct Foo : public Base
{};
enum Blub { A, B, C };
}
BOOST_AUTO_UNIT_TEST(prettyName)
{
typedef test::Foo< test::Foo<test::Blub, 1>, 10> TestType;
TestType ob;
test::Base const & baseOb(ob);
BOOST_CHECK_EQUAL( satcom::lib::prettyName(typeid(int)), "int");
BOOST_CHECK_EQUAL( satcom::lib::prettyName(typeid(baseOb)), "test::Foo<test::Foo<test::Blub, 1>, 10>" );
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment