types.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
22 #include <gtsam/config.h> // for GTSAM_USE_TBB
23 #include <gtsam/dllexport.h>
24 
25 #include <cstddef>
26 #include <cstdint>
27 #include <exception>
28 #include <string>
29 
30 #ifdef GTSAM_USE_TBB
31 #include <tbb/scalable_allocator.h>
32 #endif
33 
34 #if defined(__GNUC__) || defined(__clang__)
35 #define GTSAM_DEPRECATED __attribute__((deprecated))
36 #elif defined(_MSC_VER)
37 #define GTSAM_DEPRECATED __declspec(deprecated)
38 #else
39 #define GTSAM_DEPRECATED
40 #endif
41 
42 #ifdef GTSAM_USE_EIGEN_MKL_OPENMP
43 #include <omp.h>
44 #endif
45 
46 /* Define macros for ignoring compiler warnings.
47  * Usage Example:
48  * ```
49  * CLANG_DIAGNOSTIC_PUSH_IGNORE("-Wdeprecated-declarations")
50  * GCC_DIAGNOSTIC_PUSH_IGNORE("-Wdeprecated-declarations")
51  * MSVC_DIAGNOSTIC_PUSH_IGNORE(4996)
52  * // ... code you want to suppress deprecation warnings for ...
53  * DIAGNOSTIC_POP()
54  * ```
55  */
56 #define DO_PRAGMA(x) _Pragma (#x)
57 #ifdef __clang__
58 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag) \
59  _Pragma("clang diagnostic push") \
60  DO_PRAGMA(clang diagnostic ignored diag)
61 #else
62 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag)
63 #endif
64 
65 #ifdef __GNUC__
66 # define GCC_DIAGNOSTIC_PUSH_IGNORE(diag) \
67  _Pragma("GCC diagnostic push") \
68  DO_PRAGMA(GCC diagnostic ignored diag)
69 #else
70 # define GCC_DIAGNOSTIC_PUSH_IGNORE(diag)
71 #endif
72 
73 #ifdef _MSC_VER
74 # define MSVC_DIAGNOSTIC_PUSH_IGNORE(code) \
75  _Pragma("warning ( push )") \
76  DO_PRAGMA(warning ( disable : code ))
77 #else
78 # define MSVC_DIAGNOSTIC_PUSH_IGNORE(code)
79 #endif
80 
81 #if defined(__clang__)
82 # define DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
83 #elif defined(__GNUC__)
84 # define DIAGNOSTIC_POP() _Pragma("GCC diagnostic pop")
85 #elif defined(_MSC_VER)
86 # define DIAGNOSTIC_POP() _Pragma("warning ( pop )")
87 #else
88 # define DIAGNOSTIC_POP()
89 #endif
90 
91 namespace gtsam {
92 
94  std::string GTSAM_EXPORT demangle(const char* name);
95 
97  typedef std::uint64_t Key;
98 
101 
103  typedef ptrdiff_t DenseIndex;
104 
105  /* ************************************************************************* */
110  template<typename TEST_TYPE, typename BASIC_TYPE, typename AS_NON_CONST,
111  typename AS_CONST>
112  struct const_selector {
113  };
114 
116  template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
117  struct const_selector<BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
118  typedef AS_NON_CONST type;
119  };
120 
122  template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
123  struct const_selector<const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
124  typedef AS_CONST type;
125  };
126 
127  /* ************************************************************************* */
133  template<typename T, T defaultValue>
136 
138  ValueWithDefault() : value(defaultValue) {}
139 
141  ValueWithDefault(const T& _value) : value(_value) {}
142 
144  T& operator*() { return value; }
145 
147  const T& operator*() const { return value; }
148 
150  operator T() const { return value; }
151  };
152 
153  /* ************************************************************************* */
154 #ifdef __clang__
155 # pragma clang diagnostic push
156 # pragma clang diagnostic ignored "-Wunused-private-field" // Clang complains that previousOpenMPThreads is unused in the #else case below
157 #endif
158 
163  {
165 
166  public:
167 #if defined GTSAM_USE_TBB && defined GTSAM_USE_EIGEN_MKL_OPENMP
170  {
172  }
173 
175  {
177  }
178 #else
181 #endif
182  };
183 
184 #ifdef __clang__
185 # pragma clang diagnostic pop
186 #endif
187 
188 }
189 
190 /* ************************************************************************* */
193 #ifdef NDEBUG
194 #define assert_throw(CONDITION, EXCEPTION) ((void)0)
195 #else
196 #define assert_throw(CONDITION, EXCEPTION) \
197  if (!(CONDITION)) { \
198  throw (EXCEPTION); \
199  }
200 #endif
201 
202 #ifdef _MSC_VER
203 
204 // Define some common g++ functions and macros we use that MSVC does not have
205 
206 #if (_MSC_VER < 1800)
207 
208 #include <cmath>
209 namespace std {
210  template<typename T> inline int isfinite(T a) {
211  return (int)std::isfinite(a); }
212  template<typename T> inline int isnan(T a) {
213  return (int)std::isnan(a); }
214  template<typename T> inline int isinf(T a) {
215  return (int)std::isinf(a); }
216 }
217 
218 #endif
219 
220 #include <cmath>
221 #ifndef M_PI
222 #define M_PI (3.14159265358979323846)
223 #endif
224 #ifndef M_PI_2
225 #define M_PI_2 (M_PI / 2.0)
226 #endif
227 #ifndef M_PI_4
228 #define M_PI_4 (M_PI / 4.0)
229 #endif
230 
231 #endif
232 
233 #ifdef min
234 #undef min
235 #endif
236 
237 #ifdef max
238 #undef max
239 #endif
240 
241 #ifdef ERROR
242 #undef ERROR
243 #endif
244 
245 namespace gtsam {
246 
248  template<typename ...> using void_t = void;
249 
265  template<typename, typename = void_t<>>
266  struct needs_eigen_aligned_allocator : std::false_type {
267  };
268  template<typename T>
270  };
271 
272 }
273 
279 #define GTSAM_MAKE_ALIGNED_OPERATOR_NEW \
280  EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
281  using _eigen_aligned_allocator_trait = void;
282 
288 #define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
289  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
290  using _eigen_aligned_allocator_trait = void;
name
Annotation for function names.
Definition: attr.h:51
gtsam::ValueWithDefault::value
T value
Definition: types.h:135
gtsam::needs_eigen_aligned_allocator
Definition: types.h:266
omp_set_num_threads
void omp_set_num_threads(int num_threads)
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
isnan
#define isnan(X)
Definition: main.h:93
gtsam::void_t
void void_t
Convenience void_t as we assume C++11, it will not conflict the std one in C++17 as this is in gtsam:...
Definition: types.h:248
gtsam::const_selector
Definition: types.h:112
gtsam::ValueWithDefault::operator*
T & operator*()
Definition: types.h:144
gtsam::FactorIndex
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition: types.h:100
isfinite
#define isfinite(X)
Definition: main.h:95
gtsam::ValueWithDefault
Definition: types.h:134
gtsam::TbbOpenMPMixedScope::~TbbOpenMPMixedScope
~TbbOpenMPMixedScope()
Definition: types.h:180
gtsam::ValueWithDefault::ValueWithDefault
ValueWithDefault()
Definition: types.h:138
Eigen::Triplet< double >
omp_get_num_procs
int omp_get_num_procs(void)
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: SFMdata.h:40
gtsam::demangle
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
gtsam::DenseIndex
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:103
std
Definition: BFloat16.h:88
gtsam::ValueWithDefault::operator*
const T & operator*() const
Definition: types.h:147
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
gtsam::ValueWithDefault::ValueWithDefault
ValueWithDefault(const T &_value)
Definition: types.h:141
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::TbbOpenMPMixedScope
Definition: types.h:162
gtsam::const_selector< BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST >::type
AS_NON_CONST type
Definition: types.h:118
gtsam::const_selector< const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST >::type
AS_CONST type
Definition: types.h:124
gtsam::TbbOpenMPMixedScope::previousOpenMPThreads
int previousOpenMPThreads
Definition: types.h:164
omp_get_num_threads
int omp_get_num_threads(void)
gtsam::TbbOpenMPMixedScope::TbbOpenMPMixedScope
TbbOpenMPMixedScope()
Definition: types.h:179
isinf
#define isinf(X)
Definition: main.h:94


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:37