LongPort OpenAPI C++ SDK
async_result.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 #include "status.hpp"
6 
7 namespace longport {
8 
9 template<typename Ctx, typename T>
11 {
12 private:
13  Ctx ctx_;
14  Status status_;
15  const T* data_;
16 
17 public:
18  AsyncResult(Ctx ctx, Status status, const T* data)
19  : ctx_(ctx)
20  , status_(std::move(status))
21  , data_(data)
22  {
23  }
24 
25  inline operator bool() { return status_.is_ok(); }
26  inline const T* operator->() const { return data_; }
27  inline const Status& status() const { return status_; }
28 
29  inline const Ctx& context() { return ctx_; }
30 
32  inline bool is_ok() const { return status_.is_ok(); }
33 
35  inline bool is_err() const { return status_.is_err(); }
36 };
37 
38 template<typename Ctx, typename T>
39 using AsyncCallback = std::function<void(AsyncResult<Ctx, T>)>;
40 
41 } // namespace longport
Definition: status.hpp:9
bool is_ok() const
Returns true if no errors occurs.
bool is_err() const
Returns true if an errors occurs.
Definition: async_result.hpp:7
std::function< void(AsyncResult< Ctx, T >)> AsyncCallback
Definition: async_result.hpp:39
Definition: async_result.hpp:11
const Ctx & context()
Definition: async_result.hpp:29
AsyncResult(Ctx ctx, Status status, const T *data)
Definition: async_result.hpp:18
const T * operator->() const
Definition: async_result.hpp:26
bool is_err() const
Returns true if an errors occurs.
Definition: async_result.hpp:35
const Status & status() const
Definition: async_result.hpp:27
bool is_ok() const
Returns true if no errors occurs.
Definition: async_result.hpp:32