g2o
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 
68 # define G2O_ATTRIBUTE_CONSTRUCTOR(f) \
69  __pragma(section(".CRT$XCU",read)) \
70  static void __cdecl f(void); \
71  __declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
72  static void __cdecl f(void)
73 
74 # define G2O_ATTRIBUTE_UNUSED
75 # define G2O_ATTRIBUTE_FORMAT12
76 # define G2O_ATTRIBUTE_FORMAT23
77 # define G2O_ATTRIBUTE_WARNING(func) func
78 # define G2O_ATTRIBUTE_DEPRECATED(func) func
79 
80 #include <float.h>
81 
82 # define g2o_isnan(x) _isnan(x)
83 # define g2o_isinf(x) (_finite(x) == 0)
84 # define g2o_isfinite(x) (_finite(x) != 0)
85 
86 // unknown compiler
87 #else
88 # ifndef __PRETTY_FUNCTION__
89 # define __PRETTY_FUNCTION__ ""
90 # endif
91 # define G2O_ATTRIBUTE_CONSTRUCTOR(func) func
92 # define G2O_ATTRIBUTE_UNUSED
93 # define G2O_ATTRIBUTE_FORMAT12
94 # define G2O_ATTRIBUTE_FORMAT23
95 # define G2O_ATTRIBUTE_WARNING(func) func
96 # define G2O_ATTRIBUTE_DEPRECATED(func) func
97 
98 #include <math.h>
99 #define g2o_isnan(x) isnan(x)
100 #define g2o_isinf(x) isinf(x)
101 #define g2o_isfinite(x) isfinite(x)
102 
103 #endif
104 
105 // some macros that are only useful for c++
106 #ifdef __cplusplus
107 
108 #define G2O_FSKIP_LINE(f) \
109  {char c=' ';while(c != '\n' && f.good() && !(f).eof()) (f).get(c);}
110 
111 #ifndef PVAR
112  #define PVAR(s) \
113  #s << " = " << (s) << std::flush
114 #endif
115 
116 #ifndef PVARA
117 #define PVARA(s) \
118  #s << " = " << RAD2DEG(s) << "deg" << std::flush
119 #endif
120 
121 #ifndef FIXED
122 #define FIXED(s) \
123  std::fixed << s << std::resetiosflags(std::ios_base::fixed)
124 #endif
125 
126 #endif // __cplusplus
127 
128 #endif