17#ifndef INCLUDED_RMQT_RESULT
18#define INCLUDED_RMQT_RESULT
20#include <bsl_functional.h>
21#include <bsl_memory.h>
22#include <bsl_ostream.h>
23#include <bsl_string.h>
25namespace BloombergLP {
28typedef enum { TIMEOUT = 408 } ReturnCodes;
36template <
typename T =
void>
41 typedef void (
Result::*BoolType)()
const;
42 void thisTypeDoesNotSupportComparisons()
const {}
49 explicit Result(
const bsl::string&
error,
int resultCode = -1)
52 , d_resultCode(resultCode)
61 const bsl::string&
error = bsl::string(),
65 , d_resultCode(resultCode)
71 const bsl::shared_ptr<T>&
value()
const {
return d_value; }
75 const bsl::string&
error()
const {
return d_error; }
83 operator BoolType()
const
85 return d_resultCode == 0 ? &Result::thisTypeDoesNotSupportComparisons
89 bsl::ostream& operator<<(bsl::ostream& os)
91 os <<
"VALUE: " << (d_value ? d_value :
"null") <<
"\n";
93 os <<
"ERROR: " <<
error();
99 bsl::shared_ptr<T> d_value;
110 typedef void (
Result::*BoolType)()
const;
111 void thisTypeDoesNotSupportComparisons()
const {}
120 explicit Result(
const bsl::string&
error,
int resultCode = -1)
122 , d_resultCode(resultCode)
126 const bsl::string&
error()
const {
return d_error; }
127 int returnCode()
const {
return d_resultCode; }
129 operator BoolType()
const
131 return d_resultCode == 0 ? &Result::thisTypeDoesNotSupportComparisons
135 bsl::ostream& operator<<(bsl::ostream& os)
const
138 os <<
"ERROR: " <<
error();
149template <
typename T,
typename U>
150bool operator!=(
const Result<T>& lhs,
const U&)
152 lhs.thisTypeDoesNotSupportComparisons();
156template <
typename T,
typename U>
157bool operator==(
const Result<T>& lhs,
const U&)
159 lhs.typeTypeDoesNotSupportComparisons();
163typedef bsl::function<void(
const bsl::string& errorText,
int errorCode)>
A result of an operation.
Definition: rmqt_result.h:37
Result(const bsl::shared_ptr< T > &value, const bsl::string &error=bsl::string(), int resultCode=0)
Definition: rmqt_result.h:60
const bsl::shared_ptr< T > & value() const
Definition: rmqt_result.h:71
const bsl::string & error() const
Definition: rmqt_result.h:75
Result(const bsl::string &error, int resultCode=-1)
Constructs an error result.
Definition: rmqt_result.h:49
int returnCode() const
Definition: rmqt_result.h:79