NDEVR
API Documentation
macros.h
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#ifdef ANDROID
51# define g2o_isnan(x) isnan(x)
52# define g2o_isinf(x) isinf(x)
53# define g2o_isfinite(x) isfinite(x)
54#else
55# define g2o_isnan(x) std::isnan(x)
56# define g2o_isinf(x) std::isinf(x)
57# define g2o_isfinite(x) std::isfinite(x)
58#endif
59
60// MSVC on Windows
61#elif defined _MSC_VER
62# define __PRETTY_FUNCTION__ __FUNCTION__
63
74# define G2O_ATTRIBUTE_CONSTRUCTOR(f) \
75 __pragma(section(".CRT$XCU",read)) \
76 static void __cdecl f(void); \
77 __declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
78 static void __cdecl f(void)
79
80# define G2O_ATTRIBUTE_UNUSED
81# define G2O_ATTRIBUTE_FORMAT12
82# define G2O_ATTRIBUTE_FORMAT23
83# define G2O_ATTRIBUTE_WARNING(func) func
84# define G2O_ATTRIBUTE_DEPRECATED(func) func
85
86#include <float.h>
87#include <cmath>
88# define g2o_isinf(x) (std::isinf(x))
89
90// unknown compiler
91#else
92# ifndef __PRETTY_FUNCTION__
93# define __PRETTY_FUNCTION__ ""
94# endif
95# define G2O_ATTRIBUTE_CONSTRUCTOR(func) func
96# define G2O_ATTRIBUTE_UNUSED
97# define G2O_ATTRIBUTE_FORMAT12
98# define G2O_ATTRIBUTE_FORMAT23
99# define G2O_ATTRIBUTE_WARNING(func) func
100# define G2O_ATTRIBUTE_DEPRECATED(func) func
101
102#include <math.h>
103#define g2o_isnan(x) isNaN(x)
104#define g2o_isinf(x) isinf(x)
105#define g2o_isfinite(x) isfinite(x)
106
107#endif
108
109// some macros that are only useful for c++
110#ifdef __cplusplus
111
112#define G2O_FSKIP_LINE(f) \
113 {char c=' ';while(c != '\n' && f.good() && !(f).eof()) (f).get(c);}
114
115#ifndef PVAR
116 #define PVAR(s) \
117 #s << " = " << (s) << std::flush
118#endif
119
120#ifndef PVARA
121#define PVARA(s) \
122 #s << " = " << RAD2DEG(s) << "deg" << std::flush
123#endif
124
125#ifndef FIXED
126#define FIXED(s) \
127 std::fixed << s << std::resetiosflags(std::ios_base::fixed)
128#endif
129
130#endif // __cplusplus
131
132#endif