From 1a46db860901db31f8abd10c36cc694f72af9f16 Mon Sep 17 00:00:00 2001 From: Fabian Peller <fabian.peller-konrad@kit.edu> Date: Thu, 12 Oct 2023 18:06:54 +0200 Subject: [PATCH] strugled with operators. Added operator<= --- .../libraries/skills/core/ProviderID.cpp | 12 ++++++--- .../libraries/skills/core/ProviderID.h | 9 +++---- .../RobotAPI/libraries/skills/core/Skill.cpp | 27 ++++++++++++------- source/RobotAPI/libraries/skills/core/Skill.h | 4 ++- .../libraries/skills/core/SkillID.cpp | 8 +++++- .../RobotAPI/libraries/skills/core/SkillID.h | 1 + 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/source/RobotAPI/libraries/skills/core/ProviderID.cpp b/source/RobotAPI/libraries/skills/core/ProviderID.cpp index 83330c897..990898f38 100644 --- a/source/RobotAPI/libraries/skills/core/ProviderID.cpp +++ b/source/RobotAPI/libraries/skills/core/ProviderID.cpp @@ -19,7 +19,7 @@ namespace armarx bool ProviderID::operator==(const ProviderID& other) const { - return providerName == other.providerName; + return toString() == other.toString(); } bool @@ -34,6 +34,12 @@ namespace armarx return toString() < other.toString(); } + bool + ProviderID::operator<=(const ProviderID& other) const + { + return toString() <= other.toString(); + } + ProviderID ProviderID::FromIce(const manager::dto::ProviderID& s) { @@ -59,9 +65,9 @@ namespace armarx } std::string - ProviderID::toString(const std::string& prefix) const + ProviderID::toString() const { - return (prefix.empty() ? std::string("") : (prefix + PREFIX_SEPARATOR)) + providerName; + return providerName; } } // namespace skills diff --git a/source/RobotAPI/libraries/skills/core/ProviderID.h b/source/RobotAPI/libraries/skills/core/ProviderID.h index 3597c291f..10079220b 100644 --- a/source/RobotAPI/libraries/skills/core/ProviderID.h +++ b/source/RobotAPI/libraries/skills/core/ProviderID.h @@ -15,10 +15,6 @@ namespace armarx class ProviderID { public: - static const constexpr char* PREFIX_SEPARATOR = "->"; - - std::string providerName; - ProviderID() = default; ProviderID(const skills::SkillID& skillid); ProviderID(const std::string& pName); @@ -26,6 +22,7 @@ namespace armarx bool operator==(const ProviderID& other) const; bool operator!=(const ProviderID& other) const; bool operator<(const ProviderID& other) const; + bool operator<=(const ProviderID& other) const; manager::dto::ProviderID toManagerIce() const; callback::dto::ProviderID toCallbackIce() const; @@ -33,7 +30,9 @@ namespace armarx static ProviderID FromIce(const manager::dto::ProviderID&); static ProviderID FromIce(const callback::dto::ProviderID&); - std::string toString(const std::string& prefix = "") const; + std::string toString() const; + + std::string providerName; }; std::ostream& operator<<(std::ostream& os, const ProviderID& id); diff --git a/source/RobotAPI/libraries/skills/core/Skill.cpp b/source/RobotAPI/libraries/skills/core/Skill.cpp index 754aac8ed..7d8d9b9c8 100644 --- a/source/RobotAPI/libraries/skills/core/Skill.cpp +++ b/source/RobotAPI/libraries/skills/core/Skill.cpp @@ -160,14 +160,24 @@ namespace armarx } void - Skill::checkWhetherSkillShouldTerminate(const std::string& abortedMessage) + Skill::throwIfSkillShouldTerminate(const std::function<void()>& do_before, + const std::string& abortedMessage) + { + if (shouldSkillTerminate()) + { + do_before(); + throwIfSkillShouldTerminate(abortedMessage); + } + } + + void + Skill::throwIfSkillShouldTerminate(const std::string& abortedMessage) { if (stopped) { - std::string message = abortedMessage.empty() - ? std::string("The skill '" + getSkillId().toString() + - "' was asked to stop.") - : abortedMessage; + std::string message = + std::string("The skill '" + getSkillId().toString() + "' was asked to stop."); + message += abortedMessage.empty() ? "" : " Additional message: " + abortedMessage; throw error::SkillAbortedException(message); return; @@ -175,10 +185,9 @@ namespace armarx if (timeoutReached) { - std::string message = abortedMessage.empty() - ? std::string("The skill '" + getSkillId().toString() + - "' reached timeout.") - : abortedMessage; + std::string message = + std::string("The skill '" + getSkillId().toString() + "' reached timeout."); + message += abortedMessage.empty() ? "" : " Additional message: " + abortedMessage; ARMARX_WARNING << message; throw error::SkillFailedException(message); diff --git a/source/RobotAPI/libraries/skills/core/Skill.h b/source/RobotAPI/libraries/skills/core/Skill.h index 249b38d6e..ff3cf1e82 100644 --- a/source/RobotAPI/libraries/skills/core/Skill.h +++ b/source/RobotAPI/libraries/skills/core/Skill.h @@ -123,7 +123,9 @@ namespace armarx } protected: - void checkWhetherSkillShouldTerminate(const std::string& abortedMessage = ""); + void throwIfSkillShouldTerminate(const std::string& abortedMessage = ""); + void throwIfSkillShouldTerminate(const std::function<void()>& do_before, + const std::string& abortedMessage = ""); static MainResult MakeSucceededResult(aron::data::DictPtr data = nullptr); static MainResult MakeFailedResult(); diff --git a/source/RobotAPI/libraries/skills/core/SkillID.cpp b/source/RobotAPI/libraries/skills/core/SkillID.cpp index 3213183d0..fea0eca31 100644 --- a/source/RobotAPI/libraries/skills/core/SkillID.cpp +++ b/source/RobotAPI/libraries/skills/core/SkillID.cpp @@ -25,7 +25,7 @@ namespace armarx bool SkillID::operator==(const SkillID& other) const { - return providerId == other.providerId && skillName == other.skillName; + return this->toString() == other.toString(); } bool @@ -40,6 +40,12 @@ namespace armarx return toString() < other.toString(); } + bool + SkillID::operator<=(const SkillID& other) const + { + return toString() <= other.toString(); + } + SkillID SkillID::FromIce(const manager::dto::SkillID& s) { diff --git a/source/RobotAPI/libraries/skills/core/SkillID.h b/source/RobotAPI/libraries/skills/core/SkillID.h index 1ae18aec6..5d0da2a67 100644 --- a/source/RobotAPI/libraries/skills/core/SkillID.h +++ b/source/RobotAPI/libraries/skills/core/SkillID.h @@ -26,6 +26,7 @@ namespace armarx bool operator==(const SkillID& other) const; bool operator!=(const SkillID& other) const; bool operator<(const SkillID& other) const; + bool operator<=(const SkillID& other) const; bool isFullySpecified() const -- GitLab