diff --git a/include/aidge/utils/Deprecated.hpp b/include/aidge/utils/Deprecated.hpp index 92cd190c799238993f53d1d39df58e03869ccd97..5e73849a2f35d9a91e68140e7e13bdfb50cfdd66 100644 --- a/include/aidge/utils/Deprecated.hpp +++ b/include/aidge/utils/Deprecated.hpp @@ -43,19 +43,36 @@ static std::string camelToSnakeCase(const std::string &camelCase) { #define DEPRECATED_PYBIND(oldName, newName) \ /* Under PYBIND, if Python is initialized, convert names to snake_case */ \ if (Py_IsInitialized()) { \ - deprecatedFuncNameStr = toSnakeCase(deprecatedFuncNameStr); \ - newFuncNameStr = toSnakeCase(newFuncNameStr); \ + deprecatedFuncNameStr = camelToSnakeCase(oldName); \ + newFuncNameStr = camelToSnakeCase(newName); \ } #else -#define DEPRECATED_PYBIND(oldName, newName) {} -#endif +#define DEPRECATED_PYBIND(oldName, newName) do {} while (0) +#endif // PYBIND +// For the C++ interface without Python overrides. #define DEPRECATED(newFuncName) \ do { \ std::string deprecatedFuncNameStr(__func__); \ std::string newFuncNameStr(newFuncName); \ - DEPRECATED_PYBIND(oldName, newName); \ - Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", deprecatedFuncNameStr, newFuncNameStr); \ + DEPRECATED_PYBIND(deprecatedFuncNameStr, newFuncName); \ + Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", \ + deprecatedFuncNameStr, newFuncNameStr); \ + } while (0) + +// For the case when you want to provide Python-specific override names. +// If PYBIND is detected (and Python is initialized), then the names will be +// replaced as follows: +// deprecatedFuncNameStr = camelToSnakeCase(pybindNewOverridedName) +// newFuncNameStr = camelToSnakeCase(pybindOldOverridedName) +#define DEPRECATED_WITH_PYBIND_OVERRIDES(newFuncName, pybindNewOverridedName, pybindOldOverridedName) \ + do { \ + std::string deprecatedFuncNameStr(__func__); \ + std::string newFuncNameStr(newFuncName); \ + /* Swap the order of the override names here */ \ + DEPRECATED_PYBIND(pybindNewOverridedName, pybindOldOverridedName); \ + Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", \ + deprecatedFuncNameStr, newFuncNameStr); \ } while (0) #endif // AIDGE_UTILS_DEPRECATED_H_ \ No newline at end of file