File: Compiler.h

package info (click to toggle)
pentobi 18.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,912 kB
  • sloc: cpp: 26,729; javascript: 907; xml: 49; sh: 35; makefile: 21; java: 11
file content (66 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//-----------------------------------------------------------------------------
/** @file libboardgame_base/Compiler.h
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#ifndef LIBBOARDGAME_BASE_COMPILER_H
#define LIBBOARDGAME_BASE_COMPILER_H

#include <string>
#include <typeinfo>
#if defined __GNUC__ && __has_include(<cxxabi.h>)
#include <cstdlib>
#include <cxxabi.h>
#endif

namespace libboardgame_base {

using namespace std;

//-----------------------------------------------------------------------------

#ifdef __GNUC__
#define LIBBOARDGAME_FORCE_INLINE inline __attribute__((always_inline))
#elif defined _MSC_VER
#define LIBBOARDGAME_FORCE_INLINE inline __forceinline
#else
#define LIBBOARDGAME_FORCE_INLINE inline
#endif

#ifdef __GNUC__
#define LIBBOARDGAME_NOINLINE __attribute__((noinline))
#elif defined _MSC_VER
#define LIBBOARDGAME_NOINLINE __declspec(noinline)
#else
#define LIBBOARDGAME_NOINLINE
#endif

#if defined __GNUC__ && ! defined __ICC &&  ! defined __clang__
#define LIBBOARDGAME_FLATTEN __attribute__((flatten))
#else
#define LIBBOARDGAME_FLATTEN
#endif

template<typename T>
string get_type_name(const T& t)
{
#if defined __GNUC__ && __has_include(<cxxabi.h>)
    int status;
    char* name_ptr = abi::__cxa_demangle(typeid(t).name(), nullptr, nullptr,
                                         &status);
    if (status == 0)
    {
        string result(name_ptr);
        free(name_ptr);
        return result;
    }
#endif
    return typeid(t).name();
}

//-----------------------------------------------------------------------------

} // namespace libboardgame_base

#endif // LIBBOARDGAME_BASE_COMPILER_H