FluxioResult.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <memory>
4
#include <stdexcept>
5
6
namespace
armarx
7
{
8
namespace
skills
9
{
10
11
template
<
typename
T,
typename
E = std::exception>
12
class
Result
13
{
14
private
:
15
const
bool
success;
16
const
std::shared_ptr<const T> result;
17
const
std::shared_ptr<const E> error;
18
19
public
:
20
Result
(
const
T
& res) :
21
success(true), result(
std
::
make_shared
<const
T
>(res)), error(nullptr)
22
{
23
}
24
25
Result
(
const
E& err) :
26
success(false), result(nullptr), error(
std
::
make_shared
<const E>(err))
27
{
28
}
29
30
bool
31
isSuccess
()
const
32
{
33
return
success;
34
}
35
36
T
37
getResult
()
const
38
{
39
if
(!success)
40
{
41
throw
std::logic_error(
"Result is not successful"
);
42
}
43
return
*result;
44
}
45
46
E
47
getError
()
const
48
{
49
if
(success)
50
{
51
throw
std::logic_error(
"Result does not contain an error"
);
52
}
53
return
*error;
54
}
55
};
56
}
// namespace skills
57
}
// namespace armarx
T
float T
Definition
UnscentedKalmanFilterTest.cpp:38
armarx::skills::Result::Result
Result(const E &err)
Definition
FluxioResult.h:25
armarx::skills::Result::getResult
T getResult() const
Definition
FluxioResult.h:37
armarx::skills::Result::getError
E getError() const
Definition
FluxioResult.h:47
armarx::skills::Result::isSuccess
bool isSuccess() const
Definition
FluxioResult.h:31
armarx::skills::Result::Result
Result(const T &res)
Definition
FluxioResult.h:20
armarx::skills
This file is part of ArmarX.
Definition
PeriodicUpdateWidget.cpp:12
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition
ArmarXTimeserver.cpp:28
armarx::make_shared
auto make_shared(Args &&... args)
Definition
ManagedIceObject.h:92
std
Definition
Application.h:67
RobotAPI
libraries
skills
core
FluxioResult.h
Generated by
1.13.2