Skip to content
Snippets Groups Projects
Commit 4cd6d30f authored by Maxence Naud's avatar Maxence Naud Committed by Maxence Naud
Browse files

[Add] Deprecation MACRO working for bothC++ and Python binding

parent 1fcaee4b
No related branches found
No related tags found
1 merge request!354[Add] Deprecation system
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_UTILS_DEPRECATED_H_
#define AIDGE_UTILS_DEPRECATED_H_
#include <string>
#include <cctype>
#ifdef PYBIND
#include <pybind11/pybind11.h>
#endif
#include "aidge/utils/Log.hpp"
#ifdef PYBIND
namespace py = pybind11;
static std::string camelToSnakeCase(const std::string &camelCase) {
std::string snake;
snake.reserve(camelCase.size() + 2); // slightly bigger buffer
for (std::size_t i = 0; i < camelCase.size(); ++i) {
char ch = camelCase[i];
if (std::isupper(static_cast<unsigned char>(ch))) {
snake.push_back('_');
snake.push_back(std::tolower(static_cast<unsigned char>(ch)));
} else {
snake.push_back(ch);
}
}
return snake;
}
#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); \
}
#else
#define DEPRECATED_PYBIND(oldName, newName) {}
#endif
#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); \
} while (0)
#endif // AIDGE_UTILS_DEPRECATED_H_
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment