libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
macro.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
12 #ifndef _QI_MACRO_HPP_
13 #define _QI_MACRO_HPP_
14 
15 
16 
17 #include <qi/preproc.hpp>
18 
19 // Deprecated
20 #if defined(__GNUC__) && !defined(QI_NO_API_DEPRECATED)
21 # define QI_API_DEPRECATED __attribute__((deprecated))
22 #elif defined(_MSC_VER) && !defined(QI_NO_API_DEPRECATED)
23 # define QI_API_DEPRECATED __declspec(deprecated)
24 #else
25 # define QI_API_DEPRECATED
26 #endif
27 
28 
29 #if defined(__GNUC__)
30 # define QI_NORETURN __attribute__((noreturn))
32 #elif defined(_MSC_VER)
33 # define QI_NORETURN __declspec(noreturn)
35 #else
36 # define QI_NORETURN
37 #endif
38 
39 // Mark compilers supporting variable length array (VLA)
40 #if defined(__GNUC__) && !defined(__clang__)
41 # define QI_HAS_VARIABLE_LENGTH_ARRAY 1
42 #else
43 # define QI_HAS_VARIABLE_LENGTH_ARRAY 0
44 #endif
45 
46 // For shared library
47 
48 
66 #define QI_LIB_API(libname) _QI_LIB_API(BOOST_PP_CAT(libname, _EXPORTS), BOOST_PP_CAT(libname, _STATIC_BUILD))
67 
68 #define _QI_LIB_API(IS_BUILDING_LIB, IS_LIB_STATIC_BUILD) \
69  QI_LIB_API_NORMALIZED(_QI_IS_ONE_OR_EMPTY(BOOST_PP_CAT(_ , IS_BUILDING_LIB)), _QI_IS_ONE_OR_EMPTY(BOOST_PP_CAT(_, IS_LIB_STATIC_BUILD)))
70 
71 // Each platform must provide a QI_LIB_API_NORMALIZED(isBuilding, isStatic)
72 #if defined _WIN32 || defined __CYGWIN__
73 # define QI_EXPORT_API __declspec(dllexport)
74 # define QI_IMPORT_API __declspec(dllimport)
75 # define QI_LIB_API_NORMALIZED(exporting, isstatic) BOOST_PP_CAT(BOOST_PP_CAT(_QI_LIB_API_NORMALIZED_, exporting), isstatic)
76 # define _QI_LIB_API_NORMALIZED_00 QI_IMPORT_API
77 # define _QI_LIB_API_NORMALIZED_10 QI_EXPORT_API
78 # define _QI_LIB_API_NORMALIZED_11
79 # define _QI_LIB_API_NORMALIZED_01
80 #elif __GNUC__ >= 4
81 # define QI_EXPORT_API __attribute__ ((visibility("default")))
82 # define QI_IMPORT_API QI_EXPORT_API
83 # define QI_LIB_API_NORMALIZED(a, b) QI_EXPORT_API
84 #else
85 # define QI_IMPORT_API
86 # define QI_EXPORT_API
87 # define QI_LIB_API_NORMALIZED(a, b)
88 #endif
89 
90 
92 // Macros adapted from opencv2.2
93 #if defined(_MSC_VER)
94  #define QI_DO_PRAGMA(x) __pragma(x)
95  #define __ALSTR2__(x) #x
96  #define __ALSTR1__(x) __ALSTR2__(x)
97  #define _ALMSVCLOC_ __FILE__ "("__ALSTR1__(__LINE__)") : "
98  #define QI_MSG_PRAGMA(_msg) QI_DO_PRAGMA(message (_ALMSVCLOC_ _msg))
99 #elif defined(__GNUC__)
100  #define QI_DO_PRAGMA(x) _Pragma (#x)
101  #define QI_MSG_PRAGMA(_msg) QI_DO_PRAGMA(message (_msg))
102 #else
103  #define QI_DO_PRAGMA(x)
104  #define QI_MSG_PRAGMA(_msg)
105 #endif
106 
108 
109 // Use this macro to generate compiler warnings.
110 #if defined(QI_NO_COMPILER_WARNING)
111 # define QI_COMPILER_WARNING(x)
112 #else
113 # define QI_COMPILER_WARNING(x) QI_MSG_PRAGMA("Warning: " #x)
114 #endif
115 
116 // Deprecate a header, add a message to explain what user should do
117 #if !defined(WITH_DEPRECATED) || defined(QI_NO_DEPRECATED_HEADER)
118 # define QI_DEPRECATED_HEADER(x)
119 #else
120 # define QI_DEPRECATED_HEADER(x) QI_MSG_PRAGMA("\
121 This file includes at least one deprecated or antiquated ALDEBARAN header \
122 which may be removed without further notice in the next version. \
123 Please consult the changelog for details. " #x)
124 #endif
125 
126 
127 #ifdef __cplusplus
128 namespace qi {
129  template <typename T>
130  struct IsClonable;
131 };
132 #endif
133 
134 #define QI_DEPRECATE_MACRO(name) \
135  QI_COMPILER_WARNING(name macro is deprecated.)
136 
137 // This macro is deprecated, use boost::noncopyable instead
138 #define QI_DISALLOW_COPY_AND_ASSIGN(type) \
139  QI_DEPRECATE_MACRO(QI_DISALLOW_COPY_AND_ASSIGN) \
140  type(type const &); \
141  void operator=(type const &); \
142  typedef int _qi_not_clonable; \
143  template<typename U> friend struct ::qi::IsClonable
144 
145 
146 #if defined(__GNUC__)
147 # define QI_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
148 #else
149 # define QI_WARN_UNUSED_RESULT
150 #endif
151 
152 #if defined(__GNUC__)
153 # define QI_ATTR_UNUSED __attribute__((unused))
154 #else
155 # define QI_ATTR_UNUSED
156 #endif
157 
158 #define QI_UNUSED(x)
159 
160 // A macro to append the line number of the parent macro usage, to define a
161 // function in or a variable and avoid name collision.
162 #define _QI_UNIQ_DEF_LEVEL2(A, B) A ## __uniq__ ## B
163 #define _QI_UNIQ_DEF_LEVEL1(A, B) _QI_UNIQ_DEF_LEVEL2(A, B)
164 #define QI_UNIQ_DEF(A) _QI_UNIQ_DEF_LEVEL1(A, __LINE__)
165 
166 
167 #endif // _QI_MACRO_HPP_