Commits

Martin Felis committed cb17389

introduced API versions (current is 1.0.0)

  • Participants
  • Parent commits d8320a8

Comments (0)

Files changed (7)

File doc/Mainpage.h

  *
  * \section recent_changes Recent Changes :
  * <ul>
+ * <li> 29. January 2013: added code for \ref api_version_checking</li>
  * <li> 18. June 2012: added support of \ref luamodel_introduction</li>
  * <li> 01. June 2012: added support of \ref joint_models_fixed</li>
  * <li> 14. May 2012: fixed Body constructor as reported by Maxime Reis</li>

File examples/luamodel/example_luamodel.cc

 using namespace RigidBodyDynamics::Math;
 
 int main (int argc, char* argv[]) {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	Model* model = NULL;
 
 	model = new Model();

File examples/simple/example.cc

 using namespace RigidBodyDynamics::Math;
 
 int main (int argc, char* argv[]) {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	Model* model = NULL;
 
 	unsigned int body_a_id, body_b_id, body_c_id;
 
 #include "Contacts.h"
 
-namespace RigidBodyDynamics {
-	/** Prints version information to standard output */
-	void rbdl_print_version();
-}
+/** \defgroup api_version_checking API Version Checking
+ * @{
+ *
+ * This documentation was created for API version 1.0.0.
+ */
+
+/** Returns the API version at compile time of the library. */
+int rbdl_get_api_version();
+
+/** Ensures whether the RBDL library we are linking against is compatible
+ * with the the version we have from rbdl.h.
+ *
+ * To perform the check run:
+ * \code
+ *   rbdl_check_api_version(API_VERSION);
+ * \endcode
+ *
+ * This function will abort if compatibility is not met or warn if you run
+ * a version that might not be entirely compatible.
+ *
+ * In most cases you want to specify a specific version to ensure you are
+ * using a compatible version. To do so replace API_VERSION by a
+ * value of the form 0xAABBCC where AA is the major, BB the minor, and CC
+ * the patch version in hex-format, e.g:
+ *
+ * \code
+ *   rbdl_check_api_version(0x020A0C);
+ * \endcode
+ * 
+ * Would abort if the API major version is not 2 (= 0x02), warn if the
+ * linked minor version is not 10 (= 0x0A). The patch version 12 (= 0x12)
+ * does not have an influence on compatibility.
+ */
+void rbdl_check_api_version(int version);
+
+/** Prints version information to standard output */
+void rbdl_print_version();
+
+/** @} */
 
 #endif /* _RBDL_H */

File src/rbdl_config.h.cmake

 #ifndef _RBDLCONFIG_H
 #define _RBDLCONFIG_H
 
+#define RBDL_API_VERSION 0x010000
+
 #cmakedefine RBDL_USE_SIMPLE_MATH
 #cmakedefine RBDL_ENABLE_LOGGING
 #cmakedefine RBDL_BUILD_REVISION "@RBDL_BUILD_REVISION@"

File src/rbdl_version.cc

 #include <rbdl_config.h>
 
 #include <iostream>
+#include <sstream>
 #include <string>
+#include <cstdlib>
 
-namespace RigidBodyDynamics {
+int rbdl_get_api_version() {
+	static int compile_version = RBDL_API_VERSION;
+	return compile_version;
+}
+
+void rbdl_check_api_version(int version) {
+	int compile_version = rbdl_get_api_version();
+
+	int compile_major = (compile_version & 0xff0000) >> 16;
+	int compile_minor = (compile_version & 0x00ff00) >> 8;
+	int compile_patch = (compile_version & 0x0000ff);
+
+	std::ostringstream compile_version_string("");
+	compile_version_string << compile_major << "." << compile_minor << "." << compile_patch;
+
+	int version_major = (version & 0xff0000) >> 16;
+	int version_minor = (version & 0x00ff00) >> 8;
+	int version_patch = (version & 0x0000ff);
+
+	std::ostringstream link_version_string ("");
+	link_version_string << version_major << "." << version_minor << "." << version_patch;
+
+	if (version_major != compile_major) {
+		std::cerr << "Error: trying to link against an incompatible RBDL library." << std::endl;
+		std::cerr << "The library version is: " << compile_version_string.str() << " but rbdl_config.h is version " << link_version_string.str() << std::endl;
+		abort();
+	} else if (version_minor != compile_minor) {
+		std::cout << "Warning: RBDL library is of version " << compile_version_string.str() << " but rbdl_config.h is from version " << link_version_string.str() << std::endl;
+	}
+}
 
 void rbdl_print_version() {
-	std::cout << "RigidBodyDynamicsLibrary version:" << std::endl
-		<< "  revision     : " << RBDL_BUILD_REVISION
+	int compile_version = rbdl_get_api_version();
+
+	int compile_major = (compile_version & 0xff0000) >> 16;
+	int compile_minor = (compile_version & 0x00ff00) >> 8;
+	int compile_patch = (compile_version & 0x0000ff);
+
+	std::ostringstream compile_version_string("");
+	compile_version_string << compile_major << "." << compile_minor << "." << compile_patch;
+
+	std::cout << "RBDL version:" << std::endl
+		<< "  API version  : " << compile_version_string.str() << std::endl;
+
+	if (std::string("unknown") != RBDL_BUILD_REVISION) {
+		std::cout << "  revision     : " << RBDL_BUILD_REVISION 
 		<< " (branch: " << RBDL_BUILD_BRANCH << ")" << std::endl
-		<< "  build type   : " << RBDL_BUILD_TYPE << std::endl
+		<< "  build type   : " << RBDL_BUILD_TYPE << std::endl;
+	}
+
 #ifdef RBDL_ENABLE_LOGGING
-		<< "  logging      : on (warning: reduces performance!)" << std::endl
+	std::cout << "  logging      : on (warning: reduces performance!)" << std::endl;
 #else
-		<< "  logging      : off" << std::endl
+	std::cout << "  logging      : off" << std::endl;
 #endif
 #ifdef RBDL_USE_SIMPLE_MATH
-		<< "  simplemath   : on (warning: reduces performance!)" << std::endl
+	std::cout << "  simplemath   : on (warning: reduces performance!)" << std::endl;
 #else
-		<< "  simplemath   : off" << std::endl
+	std::cout << "  simplemath   : off" << std::endl;
 #endif
+
 #ifdef BUILD_ADDON_LUAMODEL
-		<< "  luamodel     : on" << std::endl;
+	std::cout << "  luamodel     : on" << std::endl;
 #else
-	  << "  luamodel     : off" << std::endl;
+	std::cout << "  luamodel     : off" << std::endl;
 #endif
-		;
 
 	std::string build_revision (RBDL_BUILD_REVISION);
 	if (build_revision == "unknown") {
 		std::cout << std::endl << "Version information incomplete: to enable version information re-build" << std::endl << "library from valid repository and enable RBDL_STORE_VERSION." << std::endl;
 	}
 }
-
-}

File tests/main.cc

 
 int main (int argc, char *argv[])
 {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	if (argc > 1) {
 		std::string arg (argv[1]);
 	
 		if (arg == "-v" || arg == "--version")
-			RigidBodyDynamics::rbdl_print_version();
+			rbdl_print_version();
 	}
 
 	return UnitTest::RunAllTests ();