Face Engine SDK  4.6.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 <type_traits>
4 
5 namespace fsdk
6 {
17  template<
18  typename R,
19  typename V,
20  class Enable = void>
21  struct ResultValue: Result<R> {};
22 
23  template<
24  typename R,
25  typename V>
26  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value>::type>
27  : Result<R>
28  {
30  typedef R EnumType;
31 
33  typedef V ValueType;
34 
38  ResultValue(R result) noexcept
39  : Result<R>(result)
40  {}
41 
46  ResultValue(R result, const V& value) noexcept
47  : Result<R>(result)
48  , m_value(value)
49  {}
50 
55  ResultValue(R result, V&& value) noexcept
56  : Result<R>(result)
57  , m_value(std::move(value))
58  {}
59 
64  const V& getValue() const noexcept {
65  assert(this->isOk() && "Acessing value of erroneous result.");
66  return m_value;
67  }
68 
75  V&& takeValue() noexcept {
76  return std::move(m_value);
77  }
78 
83  const V* operator -> () const noexcept {
84  return &getValue();
85  }
86 
87  protected:
88  V m_value;
89  };
90 
100  template<
101  typename R,
102  typename V>
103  struct ResultValue<R, V, typename std::enable_if<std::is_copy_constructible<V>::value == false>::type>
104  : Result<R>
105  {
107  typedef R EnumType;
108 
110  typedef V ValueType;
111 
115  ResultValue(R result) noexcept
116  : Result<R>(result)
117  {}
118 
123  ResultValue(R result, V&& value) noexcept
124  : Result<R>(result)
125  , m_value(std::move(value))
126  {}
127 
132  const V& getValue() const noexcept {
133  assert(this->isOk() && "Acessing value of erroneous result.");
134  return m_value;
135  }
136 
143  V&& takeValue() noexcept {
144  return std::move(m_value);
145  }
146 
151  const V* operator -> () const noexcept {
152  return &getValue();
153  }
154 
155  protected:
157  };
158 
169  template<
170  typename R,
171  typename V>
172  inline ResultValue<R,
173  typename std::remove_const<typename std::remove_reference<V>::type>::type>
174  makeResultValue(R result, V&& value) noexcept {
175  return ResultValue<R,
176  typename std::remove_const<typename std::remove_reference<V>::type>::type>(
177  result,
178  std::forward<V>(value));
179  };
180 }
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:143
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:55
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
ResultValue(R result, const V &value) noexcept
Initializes result.
Definition: ResultValue.h:46
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:64
V && takeValue() noexcept
Gets result value as rvalue.
Definition: ResultValue.h:75
const V & getValue() const noexcept
Gets result value.
Definition: ResultValue.h:132
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:174
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
ResultValue(R result, V &&value) noexcept
Initializes result.
Definition: ResultValue.h:123
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:38
ResultValue(R result) noexcept
Initializes result.
Definition: ResultValue.h:115
bool isOk() const noexcept
Checks for a success.
Definition: Result.h:63