Skip to content
Snippets Groups Projects
Commit 4b4f4350 authored by Benedikt Engel's avatar Benedikt Engel
Browse files

build works (Yippie)

parent 1b7ebdf2
No related branches found
No related tags found
2 merge requests!452Resolve "Fluxio results and errors",!449Fluxio preliminary release
Pipeline #19013 passed
#include <stdexcept>
namespace armarx {
namespace skills {
template<typename T, typename E = std::exception>
class Result {
private: bool success_; T result_; E error_; //maybe even an error list for a better stacktrace
public:
Result(const T& res) : success_(true), result_(res) {}
Result(const E& err) : success_(false), error_(err) {}
bool isSuccess() const {
return success_;
}
T getResult() const {
if (!success_) {
throw std::logic_error("Result is not successful");
}
return result_;
}
E getError() const {
if (success_) {
throw std::logic_error("Result does not contain an error");
}
return error_;
}
};
}
}
\ No newline at end of file
#include <stdexcept> #include <stdexcept>
#include <memory>
namespace armarx { namespace armarx
namespace skills { {
namespace skills
template<typename T, typename E = std::exception> {
class Result {
template <typename T, typename E = std::exception>
class Result
{
private: private:
bool success_; const bool success;
T result_; const std::shared_ptr<const T> result;
E error_; const std::shared_ptr<const E> error;
public: public:
Result(const T& res) : success_(true), result_(res) {} Result(const T& res) : success(true), result(std::make_shared<const T>(res)), error(nullptr)
{
}
Result(const E& err) : success_(false), error_(err) {} Result(const E& err) : success(false), result(nullptr), error(std::make_shared<const E>(err))
{
}
bool isSuccess() const {} bool isSuccess() const
{
return success;
}
T getResult() const {} T getResult() const
{
if (!success)
{
throw std::logic_error("Result is not successful");
}
return *result;
}
E getError() const {} E getError() const
{
if (success)
{
throw std::logic_error("Result does not contain an error");
}
return *error;
}
}; };
} }
} }
...@@ -223,14 +223,14 @@ namespace armarx ...@@ -223,14 +223,14 @@ namespace armarx
IceUtil::Optional<skills::manager::dto::FluxioSkill> IceUtil::Optional<skills::manager::dto::FluxioSkill>
SkillManagerComponentPluginUser::getSkill(const std::string& id, const Ice::Current& current) SkillManagerComponentPluginUser::getSkill(const std::string& id, const Ice::Current& current)
{ {
auto skill = this->plugin->getSkill(id); auto result = this->plugin->getSkill(id);
if (skill.has_value()) if (result.isSuccess())
{ {
const auto& s = skill->toManagerIce(); const auto& skill = result.getResult().toManagerIce();
if (s.has_value()) if (skill.has_value())
{ {
return *s; return *skill;
} }
} }
return {}; return {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment