From 834509b18eb6a415b003f5619db1d00eef3605a8 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 26 Jun 2024 10:10:03 +0200 Subject: [PATCH] [clang-tidy] --- .../mementar/API/mementar/ActionsPublisher.h | 6 ++-- .../API/mementar/OccasionsPublisher.h | 4 +-- include/mementar/RosInterface.h | 2 +- include/mementar/compat/ros.h | 8 ++++- .../EpisodicTree/ArchivedLeafNode.h | 2 +- .../core/Occasions/OccasionsManager.h | 1 - include/mementar/core/feeder/FeederEcho.h | 2 +- src/API/mementar/ActionsPublisher.cpp | 6 ++-- src/API/mementar/OccasionsPublisher.cpp | 4 +-- src/API/mementar/OccasionsSubscriber.cpp | 4 +-- src/RosInterface.cpp | 4 +-- src/compat/ros.cpp | 1 + .../EpisodicTree/ArchivedLeafNode.cpp | 5 ++-- .../EpisodicTree/CompressedLeafNode.cpp | 4 +-- .../binaryManagement/BitFileGenerator.cpp | 30 +++++++++---------- .../binaryManagement/BitFileGetter.cpp | 10 +++---- src/core/Occasions/OccasionsManager.cpp | 8 ++--- src/graphical/mementarGUI/mementargui.cpp | 8 +++-- src/graphical/timeline/TimelineDrawer.cpp | 1 - src/nodes/mementar_multi.cpp | 9 +++--- 20 files changed, 61 insertions(+), 58 deletions(-) diff --git a/include/mementar/API/mementar/ActionsPublisher.h b/include/mementar/API/mementar/ActionsPublisher.h index 9e3f057..503b09a 100644 --- a/include/mementar/API/mementar/ActionsPublisher.h +++ b/include/mementar/API/mementar/ActionsPublisher.h @@ -13,10 +13,10 @@ namespace mementar { explicit ActionsPublisher(const std::string& name = ""); void insert(const std::string& name, time_t start_stamp = time(nullptr), time_t end_stamp = 0); - void insert(const std::string& name, compat::mem_ros::Time start_stamp = compat::mem_ros::Node::get().currentTime(), compat::mem_ros::Time end_stamp = compat::mem_ros::Time(0)); + void insert(const std::string& name, const compat::mem_ros::Time& start_stamp = compat::mem_ros::Node::get().currentTime(), const compat::mem_ros::Time& end_stamp = compat::mem_ros::Time(0)); void insertEnd(const std::string& name, time_t end_stamp = time(nullptr)); - void insertEnd(const std::string& name, compat::mem_ros::Time end_stamp = compat::mem_ros::Node::get().currentTime()); + void insertEnd(const std::string& name, const compat::mem_ros::Time& end_stamp = compat::mem_ros::Node::get().currentTime()); /// @brief Register a callback function to get notifications from the feeder. /// @param callback is the callback function taking a string. @@ -29,7 +29,7 @@ namespace mementar { compat::mem_ros::Subscriber feeder_notif_sub_; void publish(const std::string& name, time_t start_stamp, time_t end_stamp); - void publish(const std::string& name, compat::mem_ros::Time start_stamp, compat::mem_ros::Time end_stamp); + void publish(const std::string& name, const compat::mem_ros::Time& start_stamp, const compat::mem_ros::Time& end_stamp); void feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg); }; diff --git a/include/mementar/API/mementar/OccasionsPublisher.h b/include/mementar/API/mementar/OccasionsPublisher.h index 6c869b9..818e12c 100644 --- a/include/mementar/API/mementar/OccasionsPublisher.h +++ b/include/mementar/API/mementar/OccasionsPublisher.h @@ -14,7 +14,7 @@ namespace mementar { public: OccasionsPublisher(const std::string& name = ""); - void insert(const Fact& fact, mementar::compat::mem_ros::Time stamp = compat::mem_ros::Node::get().currentTime()); + void insert(const Fact& fact, const mementar::compat::mem_ros::Time& stamp = compat::mem_ros::Node::get().currentTime()); void insert(const Fact& fact, time_t end_stamp); /// @brief Register a callback function to get notifications from the feeder. @@ -27,7 +27,7 @@ namespace mementar { compat::mem_ros::Publisher pub_; compat::mem_ros::Subscriber feeder_notif_sub_; - void publish(const std::string& str, mementar::compat::mem_ros::Time stamp = compat::mem_ros::Node::get().currentTime()); + void publish(const std::string& str, const mementar::compat::mem_ros::Time& stamp = compat::mem_ros::Node::get().currentTime()); void publish(const std::string& str, time_t end_stamp); void feederNotificationCallback(const compat::mem_ros::MessageWrapper& msg); diff --git a/include/mementar/RosInterface.h b/include/mementar/RosInterface.h index 901b2ec..dfde046 100644 --- a/include/mementar/RosInterface.h +++ b/include/mementar/RosInterface.h @@ -98,7 +98,7 @@ namespace mementar { return (onto_name.empty()) ? "/ontologenius/" + topic_name : "/ontologenius/" + topic_name + "/" + onto_name; } - double rosTime2Double(double s, int ns); + double rosTime2Double(double s, uint32_t ns); }; } // namespace mementar diff --git a/include/mementar/compat/ros.h b/include/mementar/compat/ros.h index 8061143..1862435 100644 --- a/include/mementar/compat/ros.h +++ b/include/mementar/compat/ros.h @@ -163,9 +163,15 @@ namespace mementar::compat { class Time : public RosTime { public: +#if MEME_ROS_VERSION == 1 Time(uint32_t sec, uint32_t nsec) : RosTime(sec, nsec) {} explicit Time(double t) : RosTime((uint32_t)t, (uint32_t)((t - std::floor(t)) * 1'000'000'000.)) {} +#elif MEME_ROS_VERSION == 2 + Time(uint32_t sec, uint32_t nsec) : RosTime((int32_t)sec, nsec) {} + + explicit Time(double t) : RosTime((int32_t)t, (uint32_t)((t - std::floor(t)) * 1'000'000'000.)) {} +#endif Time(const RosTime& time) : RosTime(time) {} // do not put it as explicit @@ -174,7 +180,7 @@ namespace mementar::compat { #if MEME_ROS_VERSION == 1 return sec; #elif MEME_ROS_VERSION == 2 - return RosTime::seconds(); + return (uint32_t)RosTime::seconds(); #endif } diff --git a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h index c0ea810..f1ec04c 100644 --- a/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h +++ b/include/mementar/core/LtManagement/EpisodicTree/ArchivedLeafNode.h @@ -48,7 +48,7 @@ namespace mementar { std::vector compressed_childs_; std::vector archived_childs_; std::vector archived_sessions_tree_; - std::vector archived_sessions_timeout_; // ms + std::vector archived_sessions_timeout_; // ms std::vector modified_; SoftPoint::Ttime earlier_key_; diff --git a/include/mementar/core/Occasions/OccasionsManager.h b/include/mementar/core/Occasions/OccasionsManager.h index 30f72d9..58f8fba 100644 --- a/include/mementar/core/Occasions/OccasionsManager.h +++ b/include/mementar/core/Occasions/OccasionsManager.h @@ -26,7 +26,6 @@ namespace mementar { bool isRunning() const { return run_; } private: - onto::OntologyManipulator* onto_; Subscription subscription_; std::atomic run_; diff --git a/include/mementar/core/feeder/FeederEcho.h b/include/mementar/core/feeder/FeederEcho.h index 29936d1..8315815 100644 --- a/include/mementar/core/feeder/FeederEcho.h +++ b/include/mementar/core/feeder/FeederEcho.h @@ -41,7 +41,7 @@ namespace mementar { ros_msg.subject = message->subject_; ros_msg.predicat = message->predicat_; ros_msg.object = message->object_; - ros_msg.added = message->add_ ? 1 : 0; + ros_msg.added = message->add_; feeder_echo_pub_.publish(ros_msg); } echo_messages_.clear(); diff --git a/src/API/mementar/ActionsPublisher.cpp b/src/API/mementar/ActionsPublisher.cpp index 9d9eb55..d073b8d 100644 --- a/src/API/mementar/ActionsPublisher.cpp +++ b/src/API/mementar/ActionsPublisher.cpp @@ -17,7 +17,7 @@ namespace mementar { publish(name, start_stamp, end_stamp); } - void ActionsPublisher::insert(const std::string& name, compat::mem_ros::Time start_stamp, compat::mem_ros::Time end_stamp) + void ActionsPublisher::insert(const std::string& name, const compat::mem_ros::Time& start_stamp, const compat::mem_ros::Time& end_stamp) { publish(name, start_stamp, end_stamp); } @@ -27,7 +27,7 @@ namespace mementar { publish(name, 0, end_stamp); } - void ActionsPublisher::insertEnd(const std::string& name, compat::mem_ros::Time end_stamp) + void ActionsPublisher::insertEnd(const std::string& name, const compat::mem_ros::Time& end_stamp) { publish(name, compat::mem_ros::Time(0), end_stamp); } @@ -41,7 +41,7 @@ namespace mementar { pub_.publish(msg); } - void ActionsPublisher::publish(const std::string& name, compat::mem_ros::Time start_stamp, compat::mem_ros::Time end_stamp) + void ActionsPublisher::publish(const std::string& name, const compat::mem_ros::Time& start_stamp, const compat::mem_ros::Time& end_stamp) { compat::MementarAction msg; msg.name = name; diff --git a/src/API/mementar/OccasionsPublisher.cpp b/src/API/mementar/OccasionsPublisher.cpp index 514897a..fd7a776 100644 --- a/src/API/mementar/OccasionsPublisher.cpp +++ b/src/API/mementar/OccasionsPublisher.cpp @@ -13,7 +13,7 @@ namespace mementar { feeder_notif_sub_(name.empty() ? "mementar/feeder_notifications" : "mementar/feeder_notifications/" + name, 1000, &OccasionsPublisher::feederNotificationCallback, this) {} - void OccasionsPublisher::insert(const Fact& fact, compat::mem_ros::Time stamp) + void OccasionsPublisher::insert(const Fact& fact, const compat::mem_ros::Time& stamp) { publish(fact(), stamp); } @@ -23,7 +23,7 @@ namespace mementar { publish(fact(), stamp); } - void OccasionsPublisher::publish(const std::string& str, compat::mem_ros::Time stamp) + void OccasionsPublisher::publish(const std::string& str, const compat::mem_ros::Time& stamp) { compat::StampedString msg; msg.data = str; diff --git a/src/API/mementar/OccasionsSubscriber.cpp b/src/API/mementar/OccasionsSubscriber.cpp index 3ba5693..d4df69a 100644 --- a/src/API/mementar/OccasionsSubscriber.cpp +++ b/src/API/mementar/OccasionsSubscriber.cpp @@ -70,7 +70,7 @@ namespace mementar { } if(done) - ids_.erase(ids_.begin() + i); + ids_.erase(ids_.begin() + (int)i); else i++; } @@ -84,7 +84,7 @@ namespace mementar { if(it != ids_.end()) { callback_(Fact(msg.data)); - if(msg.last != 0) + if(msg.last) ids_.erase(it); } } diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 4642bb1..c9844fa 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -165,7 +165,7 @@ namespace mementar { * ****************/ - double RosInterface::rosTime2Double(double s, int ns) + double RosInterface::rosTime2Double(double s, uint32_t ns) { ns = ns / 100000000; double res = (double)ns / 10.; @@ -181,7 +181,7 @@ namespace mementar { void RosInterface::knowledgeCallback(const compat::mem_ros::MessageWrapper& msg) { - feeder_.storeFact(msg->data, std::time(nullptr)); + feeder_.storeFact(msg->data, (SoftPoint::Ttime)std::time(nullptr)); } void RosInterface::stampedKnowledgeCallback(const compat::mem_ros::MessageWrapper& msg) diff --git a/src/compat/ros.cpp b/src/compat/ros.cpp index 36f9bd8..0f9d32c 100644 --- a/src/compat/ros.cpp +++ b/src/compat/ros.cpp @@ -1,6 +1,7 @@ #include "mementar/compat/ros.h" #include +#include namespace mementar::compat::mem_ros { diff --git a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp index 6b19d9e..411ff08 100644 --- a/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/ArchivedLeafNode.cpp @@ -24,11 +24,10 @@ namespace mementar { order_(order), earlier_key_(0), ask_for_new_tree_(false), - running_(false) + running_(true) { loadStoredData(); - running_ = true; session_cleaner_ = std::move(std::thread(&ArchivedLeafNode::clean, this)); } @@ -400,7 +399,7 @@ namespace mementar { if(cpt-- == 0) { cpt = rate; - SoftPoint::Ttime now = std::time(nullptr); + time_t now = std::time(nullptr); for(size_t i = 0; i < archived_sessions_timeout_.size(); i++) { if((archived_sessions_tree_[i] != nullptr) && diff --git a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp index b37fdc3..663bba9 100644 --- a/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp +++ b/src/core/LtManagement/EpisodicTree/CompressedLeafNode.cpp @@ -57,7 +57,7 @@ namespace mementar { if(compressed_sessions_tree_[i] != nullptr) { if(modified_[i]) - compressed_childs_[i] = std::move(CompressedLeaf(compressed_sessions_tree_[i], directory_)); + compressed_childs_[i] = CompressedLeaf(compressed_sessions_tree_[i], directory_); delete compressed_sessions_tree_[i]; } Display::percent((++leafs_cpt) * 100 / nb_leafs); @@ -467,7 +467,7 @@ namespace mementar { { mut_.lock(); if(modified_[i]) - compressed_childs_[i] = std::move(CompressedLeaf(compressed_sessions_tree_[i], directory_)); + compressed_childs_[i] = CompressedLeaf(compressed_sessions_tree_[i], directory_); delete compressed_sessions_tree_[i]; compressed_sessions_tree_[i] = nullptr; mut_.unlock(); diff --git a/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp index 87fb3aa..2be916b 100644 --- a/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp +++ b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGenerator.cpp @@ -20,12 +20,12 @@ namespace mementar { int8_t to_add = (int8_t)type_1_size_; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; value >>= (uint8_t)added; - to_add -= (int8_t)added; + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -45,12 +45,12 @@ namespace mementar { int8_t to_add = (int8_t)type_2_size_; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; value >>= (uint8_t)added; - to_add -= (int8_t)added; + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -70,12 +70,12 @@ namespace mementar { int8_t to_add = (int8_t)type_3_size_; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; value >>= (uint8_t)added; - to_add -= (int8_t)added; + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -95,12 +95,12 @@ namespace mementar { int8_t to_add = (int8_t)type_4_size_; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; value >>= (uint8_t)added; - to_add -= (int8_t)added; + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -120,12 +120,12 @@ namespace mementar { int8_t to_add = (int8_t)size; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; value >>= (uint8_t)added; - to_add -= (int8_t)added; + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -145,7 +145,7 @@ namespace mementar { for(uint32_t i = 1 << (size - 1); i > 0; i >>= 1) { if((value & i) != 0) - data_[major_index_] |= (1 << minor_index_); + data_[major_index_] |= (1 << minor_index_); // NOLINT minor_index_++; if(minor_index_ > 7) @@ -162,12 +162,12 @@ namespace mementar { int8_t to_add = 7; do { - data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); + data_[major_index_] |= ((value & ~(0xffffffff << to_add)) << minor_index_); // NOLINT const uint8_t added = 8 - minor_index_; - value >>= added; // NOLINT - to_add -= (int8_t)added; + value >>= added; // NOLINT + to_add -= (int8_t)added; // NOLINT if(to_add >= 0) { if(data_.size() <= ++major_index_) @@ -184,7 +184,7 @@ namespace mementar { void BitFileGenerator::writeBitTrue() { - data_[major_index_] |= (1 << minor_index_); + data_[major_index_] |= (1 << minor_index_); // NOLINT if((7 - minor_index_) != 0) { ++minor_index_; diff --git a/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp index a1d8c91..05e01ec 100644 --- a/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp +++ b/src/core/LtManagement/archiving_compressing/binaryManagement/BitFileGetter.cpp @@ -28,7 +28,7 @@ namespace mementar { const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; - to_get -= (int8_t)getted; + to_get -= (int8_t)getted; // NOLINT if(to_get > 0) { current_data_ = data_[++major_index_]; @@ -61,7 +61,7 @@ namespace mementar { const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; - to_get -= (int8_t)getted; + to_get -= (int8_t)getted; // NOLINT if(to_get > 0) { current_data_ = data_[++major_index_]; @@ -94,7 +94,7 @@ namespace mementar { const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; - to_get -= (int8_t)getted; + to_get -= (int8_t)getted; // NOLINT if(to_get > 0) { current_data_ = data_[++major_index_]; @@ -127,7 +127,7 @@ namespace mementar { const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; - to_get -= (int8_t)getted; + to_get -= (int8_t)getted; // NOLINT if(to_get > 0) { current_data_ = data_[++major_index_]; @@ -160,7 +160,7 @@ namespace mementar { const uint8_t getted = (minor_index_ + to_get > 7) ? 8 - minor_index_ : to_get; - to_get -= (int8_t)getted; + to_get -= (int8_t)getted; // NOLINT if(to_get > 0) { current_data_ = data_[++major_index_]; diff --git a/src/core/Occasions/OccasionsManager.cpp b/src/core/Occasions/OccasionsManager.cpp index 2cae4af..2baff8d 100644 --- a/src/core/Occasions/OccasionsManager.cpp +++ b/src/core/Occasions/OccasionsManager.cpp @@ -12,8 +12,7 @@ namespace mementar { OccasionsManager::OccasionsManager(const std::string& name) - : onto_(nullptr), - run_(false), + : run_(false), pub_((name.empty()) ? "occasions" : "occasions/" + name, 1000), sub_service_( name.empty() ? "subscribe" : "subscribe/" + name, @@ -26,8 +25,7 @@ namespace mementar { } OccasionsManager::OccasionsManager(onto::OntologyManipulator* onto, const std::string& name) - : onto_(onto), - subscription_(onto), + : subscription_(onto), run_(false), pub_((name.empty()) ? "occasions" : "occasions/" + name, 1000), sub_service_(name.empty() ? "subscribe" : "subscribe/" + name, &OccasionsManager::subscribeCallback, this), @@ -55,7 +53,7 @@ namespace mementar { compat::MementarOccasion msg; msg.id = (int)id; msg.data = triplet.toString(); - msg.last = subscription_.isFinished(id) ? 1 : 0; + msg.last = subscription_.isFinished(id); pub_.publish(msg); } } diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index ce8a3d9..4cbb087 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -1,12 +1,15 @@ #include "mementar/graphical/mementarGUI/mementargui.h" +#include +#include #include -#include #include #include #include #include +#include "mementar/API/mementar/Fact.h" +#include "mementar/API/mementar/TimelineManipulator.h" #include "mementar/API/mementar/TimelinesManipulator.h" #include "mementar/compat/ros.h" #include "mementar/graphical/mementarGUI/QLineEditExtended.h" @@ -16,7 +19,6 @@ #include "qobject.h" #include "qobjectdefs.h" #include "qpushbutton.h" -#include "qtextcursor.h" #include "qwidget.h" #include "ui_mementargui.h" @@ -327,7 +329,7 @@ void MementarGUI::currentTabChangedSlot(int tab_id) void MementarGUI::addInstanceSlot() { std::string param = ui_->manager_instance_name_editline->text().toStdString(); - std::string inst_name = param; + const std::string& inst_name = param; std::regex base_regex("(.*)=(.*)"); std::smatch base_match; diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index 6221120..dcb21f2 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -1,6 +1,5 @@ #include "mementar/graphical/timeline/TimelineDrawer.h" -#include #include #include #include diff --git a/src/nodes/mementar_multi.cpp b/src/nodes/mementar_multi.cpp index 0a36198..c87018b 100644 --- a/src/nodes/mementar_multi.cpp +++ b/src/nodes/mementar_multi.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -92,10 +91,10 @@ bool managerHandle(mementar::compat::mem_ros::ServiceWrapperparam); + auto* tmp = new mementar::RosInterface(params.parameters_.at("directory").getFirst(), + params.parameters_.at("config").getFirst(), + 10, + req->param); interfaces[req->param] = tmp; std::thread th(&mementar::RosInterface::run, tmp);