Crocoddyl
Loading...
Searching...
No Matches
deprecate.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2020-2021, University of Edinburgh, CNRS, INRIA
5// Copyright note valid unless otherwise stated in individual files.
6// All rights reserved.
8
9#ifndef CROCODDYL_CORE_UTILS_DEPRECATE_HPP_
10#define CROCODDYL_CORE_UTILS_DEPRECATE_HPP_
11
12// Helper to deprecate functions and methods
13// See
14// https://blog.samat.io/2017/02/27/Deprecating-functions-and-methods-in-Cplusplus/
15// For C++14
16#if __cplusplus >= 201402L
17#if defined(__has_cpp_attribute)
18#if __has_cpp_attribute(deprecated)
19#define DEPRECATED(msg, func) [[deprecated(msg)]] func
20#endif
21#endif
22// For everyone else
23#else
24#ifdef __GNUC__
25#define DEPRECATED(msg, func) func __attribute__((deprecated(msg)))
26#elif defined(_MSC_VER)
27#define DEPRECATED(msg, func) __declspec(deprecated(msg)) func
28#endif
29#endif
30
50#if defined(__GNUC__) || defined(__clang__)
51#define CROCODDYL_PRAGMA(x) _Pragma(#x)
52
58#define CROCODDYL_PRAGMA_MESSAGE(the_message) \
59 CROCODDYL_PRAGMA(GCC message #the_message)
60
66#define CROCODDYL_PRAGMA_WARNING(the_message) \
67 CROCODDYL_PRAGMA(GCC warning #the_message)
68
74#define CROCODDYL_PRAGMA_DEPRECATED(the_message) \
75 CROCODDYL_PRAGMA_WARNING(Deprecated : #the_message)
76
77#ifndef CROCODDYL_IGNORE_DEPRECATED_HEADER
84#define CROCODDYL_PRAGMA_DEPRECATED_HEADER(old_header, new_header) \
85 CROCODDYL_PRAGMA_WARNING( \
86 Deprecated header file : old_header has been replaced by \
87 new_header.\n Please use new_header instead of old_header.)
88#else
89#define CROCODDYL_PRAGMA_DEPRECATED_HEADER(old_header, new_header)
90#endif // CROCODDYL_IGNORE_DEPRECATED_HEADER
91
92#ifndef CROCODDYL_IGNORE_DEPRECATED_HEADER
98#define CROCODDYL_PRAGMA_TO_BE_REMOVED_HEADER(remove_header) \
99 CROCODDYL_PRAGMA_WARNING( \
100 Deprecated header file : remove_header has now been \
101 deprecated.\n It would be removed in the upcoming releases.)
102#else
103#define CROCODDYL_PRAGMA_TO_BE_REMOVED_HEADER(remove_header)
104#endif // CROCODDYL_IGNORE_TO_BE_REMOVED_HEADER
105#endif // defined(__GNUC__) || defined(__clang__)
106
123#if defined(_MSC_VER) // Microsoft Visual C++
124#define CROCODDYL_DISABLE_WARNING_DEPRECATED \
125 __pragma(warning(push)) __pragma(warning(disable : 4996))
126#define CROCODDYL_ENABLE_WARNING_DEPRECATED __pragma(warning(pop))
127#elif defined(__clang__) || defined(__GNUC__) // Clang or GCC
128#define DO_PRAGMA(X) _Pragma(#X)
129#define CROCODDYL_DISABLE_WARNING_DEPRECATED \
130 DO_PRAGMA(GCC diagnostic push) \
131 DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
132#define CROCODDYL_ENABLE_WARNING_DEPRECATED DO_PRAGMA(GCC diagnostic pop)
133#else // Unknown compilers — macros do nothing
134#define CROCODDYL_DISABLE_WARNING_DEPRECATED
135#define CROCODDYL_ENABLE_WARNING_DEPRECATED
136#endif
137
138#endif // CROCODDYL_CORE_UTILS_DEPRECATE_HPP_