g2o
Loading...
Searching...
No Matches
macros.h
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27#ifndef G2O_MACROS_H
28#define G2O_MACROS_H
29
30#ifndef DEG2RAD
31#define DEG2RAD(x) ((x)*0.01745329251994329575)
32#endif
33
34#ifndef RAD2DEG
35#define RAD2DEG(x) ((x)*57.29577951308232087721)
36#endif
37
38// GCC the one and only
39#if defined(__GNUC__)
40#define G2O_ATTRIBUTE_CONSTRUCTOR(func) \
41 static void func(void) __attribute__((constructor)); \
42 static void func(void)
43
44#define G2O_ATTRIBUTE_UNUSED __attribute__((unused))
45#define G2O_ATTRIBUTE_FORMAT12 __attribute__((format(printf, 1, 2)))
46#define G2O_ATTRIBUTE_FORMAT23 __attribute__((format(printf, 2, 3)))
47#define G2O_ATTRIBUTE_WARNING(func) func __attribute__((warning))
48#define G2O_ATTRIBUTE_DEPRECATED(func) func __attribute__((deprecated))
49
50#define g2o_isnan(x) std::isnan(x)
51#define g2o_isinf(x) std::isinf(x)
52#define g2o_isfinite(x) std::isfinite(x)
53
54// MSVC on Windows
55#elif defined _MSC_VER
56#define __PRETTY_FUNCTION__ __FUNCTION__
57
70#define G2O_ATTRIBUTE_CONSTRUCTOR(f) \
71 __pragma(section(".CRT$XCU", read)) static void __cdecl f(void); \
72 __declspec(allocate(".CRT$XCU")) void(__cdecl * f##_)(void) = f; \
73 static void __cdecl f(void)
74
75#define G2O_ATTRIBUTE_UNUSED
76#define G2O_ATTRIBUTE_FORMAT12
77#define G2O_ATTRIBUTE_FORMAT23
78#define G2O_ATTRIBUTE_WARNING(func) func
79#define G2O_ATTRIBUTE_DEPRECATED(func) func
80
81#include <float.h>
82
83#define g2o_isnan(x) _isnan(x)
84#define g2o_isinf(x) (_finite(x) == 0)
85#define g2o_isfinite(x) (_finite(x) != 0)
86
87// unknown compiler
88#else
89#ifndef __PRETTY_FUNCTION__
90#define __PRETTY_FUNCTION__ ""
91#endif
92#define G2O_ATTRIBUTE_CONSTRUCTOR(func) func
93#define G2O_ATTRIBUTE_UNUSED
94#define G2O_ATTRIBUTE_FORMAT12
95#define G2O_ATTRIBUTE_FORMAT23
96#define G2O_ATTRIBUTE_WARNING(func) func
97#define G2O_ATTRIBUTE_DEPRECATED(func) func
98
99#include <math.h>
100#define g2o_isnan(x) isnan(x)
101#define g2o_isinf(x) isinf(x)
102#define g2o_isfinite(x) isfinite(x)
103
104#endif
105
106// some macros that are only useful for c++
107#ifdef __cplusplus
108
109#ifndef PVAR
110#define PVAR(s) #s << " = " << (s) << std::flush
111#endif
112
113#ifndef FIXED
114#define FIXED(s) std::fixed << s << std::resetiosflags(std::ios_base::fixed)
115#endif
116
117#endif // __cplusplus
118
119#endif