initial code repo
[stor4nfv.git] / src / ceph / src / include / demangle.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2016 Allen Samuels <allen.samuels@sandisk.com>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #ifndef CEPH_INCLUDE_DEMANGLE
16 #define CEPH_INCLUDE_DEMANGLE
17
18 //// Stole this code from http://stackoverflow.com/questions/281818/unmangling-the-result-of-stdtype-infoname
19 #ifdef __GNUG__
20 #include <cstdlib>
21 #include <memory>
22 #include <cxxabi.h>
23
24 static std::string ceph_demangle(const char* name)
25 {
26   int status = -4; // some arbitrary value to eliminate the compiler warning
27
28   // enable c++11 by passing the flag -std=c++11 to g++
29   std::unique_ptr<char, void(*)(void*)> res {
30     abi::__cxa_demangle(name, NULL, NULL, &status),
31     std::free
32   };
33
34   return (status == 0) ? res.get() : name ;
35 }
36
37 #else
38
39 // does nothing if not g++
40 static std::string demangle(const char* name)
41 {
42   return name;
43 }
44
45 #endif
46
47
48 #endif