diff --git a/CMakeLists.txt b/CMakeLists.txt index d0346cafc04ae218fac0a32052d54de32387426a..9e36d84aa7b5f4488b41df751c27c714957e68a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ SET(${PROJECT_NAME}_HEADERS include/eigenpy/stride.hpp include/eigenpy/ref.hpp include/eigenpy/details/rvalue_from_python_data.hpp + include/eigenpy/version.hpp ) LIST(APPEND ${PROJECT_NAME}_HEADERS @@ -133,6 +134,7 @@ SET(${PROJECT_NAME}_SOURCES src/angle-axis.cpp src/quaternion.cpp src/geometry-conversion.cpp + src/version.cpp ) ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS}) diff --git a/include/eigenpy/fwd.hpp b/include/eigenpy/fwd.hpp index d4469498887e3d2e6d787ff58ab2a27d4fc74902..702b7d435254205003bf797445bf223b632d9f77 100644 --- a/include/eigenpy/fwd.hpp +++ b/include/eigenpy/fwd.hpp @@ -6,6 +6,8 @@ #ifndef __eigenpy_fwd_hpp__ #define __eigenpy_fwd_hpp__ +#include "eigenpy/config.hpp" + #include <boost/python.hpp> #include <Eigen/Core> diff --git a/include/eigenpy/version.hpp b/include/eigenpy/version.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ca389bf65075b1c3e6b6abe737850ab0b576c8e0 --- /dev/null +++ b/include/eigenpy/version.hpp @@ -0,0 +1,38 @@ +// +// Copyright (c) 2019 INRIA +// + +#ifndef __eigenpy_version_hpp__ +#define __eigenpy_version_hpp__ + +#include "eigenpy/config.hpp" + +#include <string> + +namespace eigenpy +{ + + /// + /// \brief Returns the current version of EigenPy as a string using + /// the following standard: + /// EIGENPY_MINOR_VERSION.EIGENPY_MINOR_VERSION.EIGENPY_PATCH_VERSION + /// + std::string printVersion(const std::string & delimiter = "."); + + /// + /// \brief Checks if the current version of EigenPy is at least the version provided + /// by the input arguments. + /// + /// \param[in] major_version Major version to check. + /// \param[in] minor_version Minor version to check. + /// \param[in] patch_version Patch version to check. + /// + /// \returns true if the current version of EigenPy is greater than the version provided + /// by the input arguments. + /// + bool checkVersionAtLeast(unsigned int major_version, + unsigned int minor_version, + unsigned int patch_version); +} + +#endif // __eigenpy_version_hpp__ diff --git a/src/eigenpy.cpp b/src/eigenpy.cpp index 9d7490e3875d0acc464f7a8477babeea575575e2..0b55ad6d29cf8e373d1345e84e45b692ae7b82b3 100644 --- a/src/eigenpy.cpp +++ b/src/eigenpy.cpp @@ -4,6 +4,7 @@ */ #include "eigenpy/eigenpy.hpp" +#include "eigenpy/version.hpp" namespace eigenpy { @@ -12,6 +13,13 @@ namespace eigenpy void enableEigenPy() { using namespace Eigen; + + bp::scope().attr("__version__") = eigenpy::printVersion(); + bp::scope().attr("__raw_version__") = bp::str(EIGENPY_VERSION); + bp::def("checkVersionAtLeast",&eigenpy::checkVersionAtLeast, + bp::args("major_version","minor_version","patch_version"), + "Checks if the current version of EigenPy is at least the version provided by the input arguments."); + Exception::registerException(); bp::def("setNumpyType",&NumpyType::setNumpyType, diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 0000000000000000000000000000000000000000..96887634e5f3f28e67dc0d3d220d08f637c41b06 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,30 @@ +// +// Copyright (c) 2019 INRIA +// + +#include "eigenpy/config.hpp" +#include "eigenpy/version.hpp" + +#include <sstream> + +namespace eigenpy +{ + + std::string printVersion(const std::string & delimiter) + { + std::ostringstream oss; + oss + << EIGENPY_MAJOR_VERSION << delimiter + << EIGENPY_MINOR_VERSION << delimiter + << EIGENPY_PATCH_VERSION; + return oss.str(); + } + + bool checkVersionAtLeast(unsigned int major_version, + unsigned int minor_version, + unsigned int patch_version) + { + return EIGENPY_VERSION_AT_LEAST(major_version,minor_version,patch_version); + } + +}