.. _program_listing_file_include_eigenpy_deprecation-policy.hpp: Program Listing for File deprecation-policy.hpp =============================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/eigenpy/deprecation-policy.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (C) 2020 INRIA // Copyright (C) 2024 LAAS-CNRS, INRIA // #ifndef __eigenpy_deprecation_hpp__ #define __eigenpy_deprecation_hpp__ #include "eigenpy/fwd.hpp" namespace eigenpy { enum class DeprecationType { DEPRECATION, FUTURE }; namespace detail { inline PyObject *deprecationTypeToPyObj(DeprecationType dep) { switch (dep) { case DeprecationType::DEPRECATION: return PyExc_DeprecationWarning; case DeprecationType::FUTURE: return PyExc_FutureWarning; default: // The switch handles all cases explicitly, this should never be // triggered. throw std::invalid_argument( "Undefined DeprecationType - this should never be triggered."); } } } // namespace detail template struct deprecation_warning_policy : BasePolicy { using result_converter = typename BasePolicy::result_converter; using argument_package = typename BasePolicy::argument_package; deprecation_warning_policy(const std::string &warning_msg) : BasePolicy(), m_what(warning_msg) {} std::string what() const { return m_what; } const BasePolicy *derived() const { return static_cast(this); } template bool precall(const ArgPackage &args) const { PyErr_WarnEx(detail::deprecationTypeToPyObj(deprecation_type), m_what.c_str(), 1); return derived()->precall(args); } protected: const std::string m_what; }; template struct deprecated_function : deprecation_warning_policy { deprecated_function(const std::string &msg = "This function has been marked as deprecated, and " "will be removed in the future.") : deprecation_warning_policy(msg) {} }; template struct deprecated_member : deprecation_warning_policy { deprecated_member(const std::string &msg = "This attribute or method has been marked as " "deprecated, and will be removed in the future.") : deprecation_warning_policy(msg) {} }; } // namespace eigenpy #endif // ifndef __eigenpy_deprecation_hpp__