Face Engine SDK  5.14.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 <type_traits>
6 #include <utility>
7 #include <cassert>
8 
9 namespace fsdk
10 {
21  template<
22  typename R,
23  typename V,
24  class Enable = void>
25  struct ResultValue: Result<R> {};
26 
27  template<
28  typename R,
29  typename V>
30  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value>::type>
31  : Result<R>
32  {
34  typedef R EnumType;
35 
37  typedef V ValueType;
38 
42  ResultValue(R result) noexcept
43  : Result<R>(result)
44  {}
45 
50  ResultValue(R result, const V& value) noexcept
51  : Result<R>(result)
52  , m_value(value)
53  {}
54 
59  ResultValue(R result, V&& value) noexcept
60  : Result<R>(result)
61  , m_value(std::move(value))
62  {}
63 
68  const V& getValue() const noexcept {
69  assert(this->isOk() && "Acessing value of erroneous result.");
70  return m_value;
71  }
72 
79  V&& takeValue() noexcept {
80  return std::move(m_value);
81  }
82 
87  const V* operator -> () const noexcept {
88  return &getValue();
89  }
90 
91  protected:
92  V m_value;
93  };
94 
104  template<
105  typename R,
106  typename V>
107  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value == false>::type>
108  : Result<R>
109  {
111  typedef R EnumType;
112 
114  typedef V ValueType;
115 
119  ResultValue(R result) noexcept
120  : Result<R>(result)
121  {}
122 
127  ResultValue(R result, V&& value) noexcept
128  : Result<R>(result)
129  , m_value(std::move(value))
130  {}
131 
136  const V& getValue() const noexcept {
137  assert(this->isOk() && "Acessing value of erroneous result.");
138  return m_value;
139  }
140 
147  V&& takeValue() noexcept {
148  return std::move(m_value);
149  }
150 
155  const V* operator -> () const noexcept {
156  return &getValue();
157  }
158 
159  protected:
161  };
162 
173  template<
174  typename R,
175  typename V>
176  inline ResultValue<R,
177  typename std::remove_const<typename std::remove_reference<V>::type>::type>
178  makeResultValue(R result, V&& value) noexcept {
179  return ResultValue<R,
180  typename std::remove_const<typename std::remove_reference<V>::type>::type>(
181  result,
182  std::forward<V>(value));
183  }
184 }
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:147
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:59
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
ResultValue(R result, const V &value) noexcept
Initializes result.
Definition: ResultValue.h:50
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:68
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:79
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:136
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:178
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:25
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:127
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:42
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:119
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:63