Tizen WASM Player
Tizen TV WebAssembly Media Player extension allowing for a low-level elementary media stream playback.
common.h
Go to the documentation of this file.
1 // Copyright 2020 Samsung Electronics
2 // TizenTV Emscripten extensions are available under two separate licenses, the
3 // MIT license and the University of Illinois/NCSA Open Source License. Both
4 // these licenses can be found in the LICENSE file.
5 
6 #ifndef INCLUDE_SAMSUNG_WASM_COMMON_H_
7 #define INCLUDE_SAMSUNG_WASM_COMMON_H_
8 
9 #include <chrono>
10 
12 
13 namespace samsung {
14 namespace wasm {
15 
18 template <class T>
19 struct Result {
22  T value;
23 
26 
28  explicit operator bool() const noexcept;
29 
31  T& operator*();
32 
34  const T& operator*() const;
35 
37  T* operator->();
38 
40  const T* operator->() const;
41 };
42 
44 template <>
45 struct Result<void> {
47 
48  explicit operator bool() const noexcept;
49 };
51 
53 using Seconds = std::chrono::duration<double>;
54 
55 template <class T>
56 Result<T>::operator bool() const noexcept {
57  return static_cast<bool>(Result<void>{operation_result});
58 }
59 
60 inline Result<void>::operator bool() const noexcept {
61  return operation_result == OperationResult::kSuccess;
62 }
63 
64 template <class T>
66  return const_cast<T&>(static_cast<const Result<T>*>(this)->operator*());
67 }
68 
69 template <class T>
70 const T& Result<T>::operator*() const {
71  return value;
72 }
73 
74 template <class T>
76  return const_cast<T*>(static_cast<const Result<T>*>(this)->operator->());
77 }
78 
79 template <class T>
80 const T* Result<T>::operator->() const {
81  return &value;
82 }
83 
84 } // namespace wasm
85 } // namespace samsung
86 
87 #endif // INCLUDE_SAMSUNG_WASM_COMMON_H_
An operation ended successfully.
std::chrono::duration< double > Seconds
Default duration type used throughout the API.
Definition: common.h:53
T & operator*()
Returns Result<T>::value. Defined if T is not void.
Definition: common.h:65
T * operator->()
Accesses Result<T>::value. Defined if T is not void.
Definition: common.h:75
OperationResult
Enumerates possible outcomes of WASM function calls.
OperationResult operation_result
Operation result.
Definition: common.h:25