libcopp  2.2.0
future.h
Go to the documentation of this file.
1 // Copyright 2023 owent
2 
3 #pragma once
4 
5 #include <libcopp/utils/config/libcopp_build_features.h>
6 
7 // clang-format off
8 #include <libcopp/utils/config/stl_include_prefix.h> // NOLINT(build/include_order)
9 // clang-format on
10 #include <list>
11 // clang-format off
12 #include <libcopp/utils/config/stl_include_suffix.h> // NOLINT(build/include_order)
13 // clang-format on
14 
15 #include "libcopp/future/poller.h"
16 
17 LIBCOPP_COPP_NAMESPACE_BEGIN
18 namespace future {
19 
20 template <class T, class TPTR = typename poll_storage_ptr_selector<T>::type>
21 class LIBCOPP_COPP_API_HEAD_ONLY future {
22  public:
27  using ptr_type = typename poller_type::ptr_type;
28 
29  public:
30  future() {}
31  ~future() {}
32 
33  UTIL_FORCEINLINE bool is_ready() const LIBCOPP_MACRO_NOEXCEPT { return poll_data_.is_ready(); }
34 
35  UTIL_FORCEINLINE bool is_pending() const LIBCOPP_MACRO_NOEXCEPT { return poll_data_.is_pending(); }
36 
37  UTIL_FORCEINLINE const value_type *data() const LIBCOPP_MACRO_NOEXCEPT {
38  if (!is_ready()) {
39  return nullptr;
40  }
41 
42  return poll_data_.data();
43  }
44 
45  UTIL_FORCEINLINE value_type *data() LIBCOPP_MACRO_NOEXCEPT {
46  if (!is_ready()) {
47  return nullptr;
48  }
49 
50  return poll_data_.data();
51  }
52 
53  UTIL_FORCEINLINE const ptr_type &raw_ptr() const LIBCOPP_MACRO_NOEXCEPT { return poll_data_.raw_ptr(); }
54  UTIL_FORCEINLINE ptr_type &raw_ptr() LIBCOPP_MACRO_NOEXCEPT { return poll_data_.raw_ptr(); }
55  UTIL_FORCEINLINE const poller_type &poll_data() const LIBCOPP_MACRO_NOEXCEPT { return poll_data_; }
56  UTIL_FORCEINLINE poller_type &poll_data() LIBCOPP_MACRO_NOEXCEPT { return poll_data_; }
57  UTIL_FORCEINLINE void reset_data() { poll_data_.reset(); }
58 
59  template <class U>
61  poll_data_ = std::forward<U>(in);
62  }
63 
64  private:
66 };
67 
68 } // namespace future
69 LIBCOPP_COPP_NAMESPACE_END
UTIL_FORCEINLINE const poller_type & poll_data() const LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:55
UTIL_FORCEINLINE poller_type & poll_data() LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:56
typename poller_type::storage_type storage_type
Definition: future.h:25
UTIL_FORCEINLINE void reset_data(U &&in)
Definition: future.h:60
UTIL_FORCEINLINE value_type * data() LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:45
UTIL_FORCEINLINE ptr_type & raw_ptr() LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:54
UTIL_FORCEINLINE void reset_data()
Definition: future.h:57
UTIL_FORCEINLINE const ptr_type & raw_ptr() const LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:53
poller_type poll_data_
Definition: future.h:65
typename poller_type::value_type value_type
Definition: future.h:26
UTIL_FORCEINLINE bool is_ready() const LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:33
UTIL_FORCEINLINE bool is_pending() const LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:35
typename poller_type::ptr_type ptr_type
Definition: future.h:27
UTIL_FORCEINLINE const value_type * data() const LIBCOPP_MACRO_NOEXCEPT
Definition: future.h:37
typename poll_storage::ptr_type ptr_type
Definition: poller.h:18
typename poll_storage::storage_type storage_type
Definition: poller.h:17
#define UTIL_FORCEINLINE
Definition: future.h:18
std::shared_ptr< cli::cmd_option_value > value_type
Definition: cmd_option.h:50