1 | /* |
2 | * util.hpp |
3 | * |
4 | * Created on: Nov 20, 2014 |
5 | * Author: Pietro Incardona |
6 | */ |
7 | |
8 | #ifndef UTIL_DEBUG_HPP |
9 | #define UTIL_DEBUG_HPP |
10 | |
11 | #include <memory> |
12 | #include <string> |
13 | #include <cstdlib> |
14 | |
15 | /*! \brief check that two array match |
16 | * |
17 | * check that two array match |
18 | * |
19 | * \param ptr1 Point to array 1 |
20 | * \param ptr2 Pointer to array 2 |
21 | * \param sz Size of the array |
22 | * |
23 | */ |
24 | |
25 | template<typename T> void boost_check_array(const T * ptr1, const T * ptr2, size_t sz) |
26 | { |
27 | // Check the array |
28 | for (size_t i = 0 ; i < sz ; i++) |
29 | { |
30 | BOOST_REQUIRE_EQUAL(ptr1[i],ptr2[i]); |
31 | } |
32 | } |
33 | |
34 | #include <typeinfo> |
35 | |
36 | #include <cxxabi.h> |
37 | |
38 | /*! \brief typeid().name() return a mangled name this function demangle it creating a more readable type string |
39 | * |
40 | * \param mangle string |
41 | * |
42 | * \return demangled string |
43 | */ |
44 | static inline std::string demangle(const char* name) { |
45 | |
46 | int status = -4; // some arbitrary value to eliminate the compiler warning |
47 | |
48 | // enable c++11 by passing the flag -std=c++11 to g++ |
49 | std::unique_ptr<char, void(*)(void*)> res { |
50 | abi::__cxa_demangle(name, NULL, NULL, &status), |
51 | std::free |
52 | }; |
53 | |
54 | return (status==0) ? res.get() : name ; |
55 | } |
56 | |
57 | #endif |
58 | |