Face Engine SDK  5.21.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ResultValue.h
1 #pragma once
2 
3 #include <fsdk/Types/Result.h>
4 
5 #include <cassert>
6 #include <type_traits>
7 #include <utility>
8 
9 namespace fsdk {
20  template <typename R, typename V, class Enable = void>
21  struct ResultValue : Result<R> {};
22 
23  template <typename R, typename V>
24  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value>::type> : Result<R> {
26  typedef R EnumType;
27 
29  typedef V ValueType;
30 
34  ResultValue(R result) noexcept
35  : Result<R>(result)
36  , m_value{} {
37  }
38 
43  ResultValue(R result, const V& value) noexcept
44  : Result<R>(result)
45  , m_value(value) {
46  }
47 
52  ResultValue(R result, V&& value) noexcept
53  : Result<R>(result)
54  , m_value(std::move(value)) {
55  }
56 
61  const V& getValue() const noexcept {
62  assert(this->isOk() && "Acessing value of erroneous result.");
63  return m_value;
64  }
65 
72  V&& takeValue() noexcept {
73  return std::move(m_value);
74  }
75 
80  const V* operator->() const noexcept {
81  return &getValue();
82  }
83 
84  protected:
85  V m_value;
86  };
87 
97  template <typename R, typename V>
98  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value == false>::type> :
99  Result<R> {
101  typedef R EnumType;
102 
104  typedef V ValueType;
105 
109  ResultValue(R result) noexcept
110  : Result<R>(result)
111  , m_value{} {
112  }
113 
118  ResultValue(R result, V&& value) noexcept
119  : Result<R>(result)
120  , m_value(std::move(value)) {
121  }
122 
127  const V& getValue() const noexcept {
128  assert(this->isOk() && "Acessing value of erroneous result.");
129  return m_value;
130  }
131 
138  V&& takeValue() noexcept {
139  return std::move(m_value);
140  }
141 
146  const V* operator->() const noexcept {
147  return &getValue();
148  }
149 
150  protected:
152  };
153 
164  template <typename R, typename V>
166  makeResultValue(R result, V&& value) noexcept {
168  result,
169  std::forward<V>(value));
170  }
171 } // namespace fsdk
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:138
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:52
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
ResultValue(R result, const V &value) noexcept
Initializes result.
Definition: ResultValue.h:43
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:61
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:72
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:127
ResultValue< R, typename std::remove_const< typename std::remove_reference< V >::type >::type > makeResultValue(R result, V &&value) noexcept
Addon for Result to output some value aside the result.
Definition: ResultValue.h:166
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
const V * operator->() const noexcept
Gets result value.
Definition: ResultValue.h:146
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:118
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:34
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:109
const V * operator->() const noexcept
Gets result value.
Definition: ResultValue.h:80
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:62