From 61eaf3722b7a2f7f2820dd2a58b60d41f035d5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Arroyo?= Date: Fri, 24 May 2024 11:17:54 -0500 Subject: [PATCH] Fix windows warnings (#199) (#258) * Fix windows warnings (#199) * Fix windows warnings Signed-off-by: Nate Koenig * Fix more windows warnings Signed-off-by: Nate Koenig * Added string include Signed-off-by: Nate Koenig --------- Signed-off-by: Nate Koenig Signed-off-by: Nate Koenig Co-authored-by: Nate Koenig * Include vector Signed-off-by: Crola1702 --------- Signed-off-by: Nate Koenig Signed-off-by: Nate Koenig Signed-off-by: Crola1702 Co-authored-by: Nate Koenig Co-authored-by: Nate Koenig --- plugins/joy_to_twist/JoyToTwist.cc | 51 ++++++++---- plugins/joy_to_twist/JoyToTwist.hh | 6 +- src/Manager.hh | 2 +- src/vendor/backward.hpp | 120 +++++++++++++++-------------- 4 files changed, 102 insertions(+), 77 deletions(-) diff --git a/plugins/joy_to_twist/JoyToTwist.cc b/plugins/joy_to_twist/JoyToTwist.cc index ccbc118e..1c1d550e 100644 --- a/plugins/joy_to_twist/JoyToTwist.cc +++ b/plugins/joy_to_twist/JoyToTwist.cc @@ -19,10 +19,11 @@ #include #ifndef _WIN32 #include -#else - #endif +#include +#include + #include #include #include @@ -48,6 +49,22 @@ void setVectorFromString(const std::string &_str, } } +////////////////////////////////////////////////// +// String to vector helper function. +void setVectorFromString(const std::string &_str, + gz::math::Vector3i &_v) +{ + std::string str = gz::common::trimmed(_str); + + std::vector parts = gz::common::split(str, " "); + if (parts.size() == 3) + { + _v.X(std::stoi(parts[0])); + _v.Y(std::stoi(parts[1])); + _v.Z(std::stoi(parts[2])); + } +} + ///////////////////////////////////////////////// JoyToTwist::JoyToTwist() : Plugin() @@ -129,18 +146,21 @@ void JoyToTwist::OnJoy(const ignition::msgs::Joy &_msg) if (this->enableTurboButton >= 0 && _msg.buttons(this->enableTurboButton)) { cmdVelMsg.mutable_linear()->set_x( - _msg.axes(this->axisLinear.X()) * this->scaleLinearTurbo.X()); + _msg.axes(this->axisLinear.X()) * this->scaleLinearTurbo.X()); cmdVelMsg.mutable_linear()->set_y( - _msg.axes(this->axisLinear.Y()) * this->scaleLinearTurbo.Y()); + _msg.axes(this->axisLinear.Y()) * this->scaleLinearTurbo.Y()); cmdVelMsg.mutable_linear()->set_z( - _msg.axes(this->axisLinear.Z()) * this->scaleLinearTurbo.Z()); + _msg.axes(this->axisLinear.Z()) * this->scaleLinearTurbo.Z()); cmdVelMsg.mutable_angular()->set_x( - _msg.axes(this->axisAngular.X()) * this->scaleAngularTurbo.X()); + _msg.axes(static_cast(this->axisAngular.X())) * + this->scaleAngularTurbo.X()); cmdVelMsg.mutable_angular()->set_y( - _msg.axes(this->axisAngular.Y()) * this->scaleAngularTurbo.Y()); + _msg.axes(static_cast(this->axisAngular.Y())) * + this->scaleAngularTurbo.Y()); cmdVelMsg.mutable_angular()->set_z( - _msg.axes(this->axisAngular.Z()) * this->scaleAngularTurbo.Z()); + _msg.axes(static_cast(this->axisAngular.Z())) * + this->scaleAngularTurbo.Z()); this->cmdVelPub.Publish(cmdVelMsg); this->sentDisableMsg = false; @@ -149,18 +169,21 @@ void JoyToTwist::OnJoy(const ignition::msgs::Joy &_msg) else if (_msg.buttons(this->enableButton)) { cmdVelMsg.mutable_linear()->set_x( - _msg.axes(this->axisLinear.X()) * this->scaleLinear.X()); + _msg.axes(this->axisLinear.X()) * this->scaleLinear.X()); cmdVelMsg.mutable_linear()->set_y( - _msg.axes(this->axisLinear.Y()) * this->scaleLinear.Y()); + _msg.axes(this->axisLinear.Y()) * this->scaleLinear.Y()); cmdVelMsg.mutable_linear()->set_z( - _msg.axes(this->axisLinear.Z()) * this->scaleLinear.Z()); + _msg.axes(this->axisLinear.Z()) * this->scaleLinear.Z()); cmdVelMsg.mutable_angular()->set_x( - _msg.axes(this->axisAngular.X()) * this->scaleAngular.X()); + _msg.axes(static_cast(this->axisAngular.X())) * + this->scaleAngular.X()); cmdVelMsg.mutable_angular()->set_y( - _msg.axes(this->axisAngular.Y()) * this->scaleAngular.Y()); + _msg.axes(static_cast(this->axisAngular.Y())) * + this->scaleAngular.Y()); cmdVelMsg.mutable_angular()->set_z( - _msg.axes(this->axisAngular.Z()) * this->scaleAngular.Z()); + _msg.axes(static_cast(this->axisAngular.Z())) * + this->scaleAngular.Z()); this->cmdVelPub.Publish(cmdVelMsg); this->sentDisableMsg = false; diff --git a/plugins/joy_to_twist/JoyToTwist.hh b/plugins/joy_to_twist/JoyToTwist.hh index 517e802e..39ae6ebf 100644 --- a/plugins/joy_to_twist/JoyToTwist.hh +++ b/plugins/joy_to_twist/JoyToTwist.hh @@ -92,9 +92,9 @@ namespace ignition private: int enableButton = 0; private: int enableTurboButton = -1; - private: ignition::math::Vector3d axisLinear{1.0, 0.0, 0.0}; - private: ignition::math::Vector3d scaleLinear{0.5, 0.0, 0.0}; - private: ignition::math::Vector3d scaleLinearTurbo{0.5, 0.0, 0.0}; + private: gz::math::Vector3i axisLinear{1, 0, 0}; + private: gz::math::Vector3d scaleLinear{0.5, 0.0, 0.0}; + private: gz::math::Vector3d scaleLinearTurbo{0.5, 0.0, 0.0}; private: ignition::math::Vector3d axisAngular{0.0, 0.0, 0.0}; private: ignition::math::Vector3d scaleAngular{0.0, 0.0, 0.5}; diff --git a/src/Manager.hh b/src/Manager.hh index a44a22a7..9e7d33d9 100644 --- a/src/Manager.hh +++ b/src/Manager.hh @@ -54,7 +54,7 @@ namespace ignition /// \brief Private data pointer. // IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING private: std::unique_ptr dataPtr; - // IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING + // IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING }; } } diff --git a/src/vendor/backward.hpp b/src/vendor/backward.hpp index c39a599e..af92de36 100644 --- a/src/vendor/backward.hpp +++ b/src/vendor/backward.hpp @@ -51,13 +51,13 @@ // You can define one of the following (or leave it to the auto-detection): // // #define BACKWARD_SYSTEM_LINUX -// - specialization for linux +// - specialization for linux // // #define BACKWARD_SYSTEM_DARWIN -// - specialization for Mac OS X 10.5 and later. +// - specialization for Mac OS X 10.5 and later. // // #define BACKWARD_SYSTEM_UNKNOWN -// - placebo implementation, does nothing. +// - placebo implementation, does nothing. // #if defined(BACKWARD_SYSTEM_LINUX) #elif defined(BACKWARD_SYSTEM_DARWIN) @@ -132,9 +132,9 @@ // - object filename // - function name // - source filename -// - line and column numbers -// - source code snippet (assuming the file is accessible) -// - variables name and values (if not optimized out) +// - line and column numbers +// - source code snippet (assuming the file is accessible) +// - variables name and values (if not optimized out) // - You need to link with the lib "dw": // - apt-get install libdw-dev // - g++/clang++ -ldw ... @@ -144,8 +144,8 @@ // - object filename // - function name // - source filename -// - line numbers -// - source code snippet (assuming the file is accessible) +// - line numbers +// - source code snippet (assuming the file is accessible) // - You need to link with the lib "bfd": // - apt-get install binutils-dev // - g++/clang++ -lbfd ... @@ -191,8 +191,8 @@ #include #include #ifdef __ANDROID__ -// Old Android API levels define _Unwind_Ptr in both link.h and -// unwind.h Rename the one in link.h as we are not going to be using +// Old Android API levels define _Unwind_Ptr in both link.h and +// unwind.h Rename the one in link.h as we are not going to be using // it #define _Unwind_Ptr _Unwind_Ptr_Custom #include @@ -320,7 +320,9 @@ #include typedef SSIZE_T ssize_t; +#ifndef NOMINMAX #define NOMINMAX +#endif #include #include @@ -1129,14 +1131,14 @@ class TraceResolverLinuxImpl // Now we get in symbol_info: // .dli_fname: - // pathname of the shared object that contains the address. + // pathname of the shared object that contains the address. // .dli_fbase: - // where the object is loaded in memory. + // where the object is loaded in memory. // .dli_sname: - // the name of the nearest symbol to trace.addr, we expect a - // function name. + // the name of the nearest symbol to trace.addr, we expect a + // function name. // .dli_saddr: - // the exact address corresponding to .dli_sname. + // the exact address corresponding to .dli_sname. if (symbol_info.dli_sname) { trace.object_function = demangle(symbol_info.dli_sname); @@ -1218,47 +1220,47 @@ class TraceResolverLinuxImpl trace.inliners = backtrace_inliners(fobj, *details_selected); #if 0 - if (trace.inliners.size() == 0) { - // Maybe the trace was not inlined... or maybe it was and we - // are lacking the debug information. Let's try to make the - // world better and see if we can get the line number of the - // function (trace.source.function) now. - // - // We will get the location of where the function start (to be - // exact: the first instruction that really start the - // function), not where the name of the function is defined. - // This can be quite far away from the name of the function - // btw. - // - // If the source of the function is the same as the source of - // the trace, we cannot say if the trace was really inlined or - // not. However, if the filename of the source is different - // between the function and the trace... we can declare it as - // an inliner. This is not 100% accurate, but better than - // nothing. - - if (symbol_info.dli_saddr) { - find_sym_result details = find_symbol_details(fobj, - symbol_info.dli_saddr, - symbol_info.dli_fbase); - - if (details.found) { - ResolvedTrace::SourceLoc diy_inliner; - diy_inliner.line = details.line; - if (details.filename) { - diy_inliner.filename = details.filename; - } - if (details.funcname) { - diy_inliner.function = demangle(details.funcname); - } else { - diy_inliner.function = trace.source.function; - } - if (diy_inliner != trace.source) { - trace.inliners.push_back(diy_inliner); - } - } - } - } + if (trace.inliners.size() == 0) { + // Maybe the trace was not inlined... or maybe it was and we + // are lacking the debug information. Let's try to make the + // world better and see if we can get the line number of the + // function (trace.source.function) now. + // + // We will get the location of where the function start (to be + // exact: the first instruction that really start the + // function), not where the name of the function is defined. + // This can be quite far away from the name of the function + // btw. + // + // If the source of the function is the same as the source of + // the trace, we cannot say if the trace was really inlined or + // not. However, if the filename of the source is different + // between the function and the trace... we can declare it as + // an inliner. This is not 100% accurate, but better than + // nothing. + + if (symbol_info.dli_saddr) { + find_sym_result details = find_symbol_details(fobj, + symbol_info.dli_saddr, + symbol_info.dli_fbase); + + if (details.found) { + ResolvedTrace::SourceLoc diy_inliner; + diy_inliner.line = details.line; + if (details.filename) { + diy_inliner.filename = details.filename; + } + if (details.funcname) { + diy_inliner.function = demangle(details.funcname); + } else { + diy_inliner.function = trace.source.function; + } + if (diy_inliner != trace.source) { + trace.inliners.push_back(diy_inliner); + } + } + } + } #endif } @@ -3434,9 +3436,9 @@ class SourceFile { lines_t &get_lines(unsigned line_start, unsigned line_count, lines_t &lines) { using namespace std; // This function make uses of the dumbest algo ever: - // 1) seek(0) - // 2) read lines one by one and discard until line_start - // 3) read line one by one until line_start + line_count + // 1) seek(0) + // 2) read lines one by one and discard until line_start + // 3) read line one by one until line_start + line_count // // If you are getting snippets many time from the same file, it is // somewhat a waste of CPU, feel free to benchmark and propose a