PIVX Core  5.6.99
P2P Digital Currency
operationresult.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PIVX_OPERATIONRESULT_H
6 #define PIVX_OPERATIONRESULT_H
7 
8 #include "optional.h"
9 #include <string>
10 
12 {
13 private:
14  bool m_res{false};
16 
17 public:
18  OperationResult(bool _res, const std::string& _error) : m_res(_res), m_error(_error) { }
19  OperationResult(bool _res) : m_res(_res) { }
20 
21  std::string getError() const { return (m_error ? *m_error : ""); }
22  bool getRes() const { return m_res; }
23  explicit operator bool() const { return m_res; }
24 };
25 
26 inline OperationResult errorOut(const std::string& errorStr)
27 {
28  return OperationResult(false, errorStr);
29 }
30 
31 
32 template <class T>
34 {
35 private:
37 public:
39  explicit CallResult(T _obj) : OperationResult(true), m_obj_res(_obj) { }
40  explicit CallResult(const std::string& error) : OperationResult(false, error) { }
41  const Optional<T>& getObjResult() const { return m_obj_res; }
42 };
43 
44 
45 #endif // PIVX_OPERATIONRESULT_H
true
Definition: bls_dkg.cpp:153
false
Definition: bls_dkg.cpp:151
const Optional< T > & getObjResult() const
Optional< T > m_obj_res
CallResult(T _obj)
CallResult(const std::string &error)
std::string getError() const
OperationResult(bool _res, const std::string &_error)
Optional< std::string > m_error
OperationResult(bool _res)
bool getRes() const
#define T(expected, seed, data)
OperationResult errorOut(const std::string &errorStr)
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
bool error(const char *fmt, const Args &... args)
Definition: system.h:77