Detailed Description
The PResult class represents the result returned by most of Papillon functions; this class is used to replace standard integer error code.
This class leverages numerical error codes by adding additional information when it can be useful.
A PResult object is mainly a stack of messages; each message contains:
- A numerical code (can be undefined)
- A string message (can be an empty string)
The class is as light as possible. For example, it does not perform memory allocation when you just want to return Ok (success) without any message associated with.
PResult are value types. When a PResult is assigned to another object, it is copied.
#include <PResult.h>
Member Enumeration Documentation
◆ EReturnCode
enum PResult::EReturnCode |
All the available return codes.
Constructor & Destructor Documentation
◆ PResult() [1/4]
|
inline |
◆ PResult() [2/4]
|
explicit |
Constructs a result from a return code.
◆ PResult() [3/4]
|
explicit |
Constructs a result from a return code and a message.
◆ PResult() [4/4]
PResult::PResult | ( | const PResult & | other | ) |
Constructs a deep copy of other.
◆ ~PResult()
PResult::~PResult | ( | ) |
Destroys this object.
Member Function Documentation
◆ Error()
Constructs a generic error from the specified message.
Error code is E_ERROR.
◆ ErrorBadArgument()
Constructs a "bad argument" error from the specified message.
Error code is E_ERROR_BAD_ARGUMENT.
◆ ErrorBadCast()
|
static |
Constructs a bad cast error from the specified class ids.
Error code is E_ERROR_BAD_CAST.
◆ ErrorBadPluginParameters()
Constructs a "bad plugin parameters" error from the specified message.
Error code is E_ERROR_BAD_PLUGIN_PARAMETER.
◆ ErrorBadURIFormat()
Constructs a "failed to checkout a license" error for the specified product.
Error code is E_ERROR_BAD_URI_FORMAT.
◆ ErrorDeserialisationBadClassId()
|
static |
Constructs a bad class id deserialisation error from the specified message.
Error code is E_ERROR_SERIALISATION_BAD_CLASS_ID.
◆ ErrorDeserialisationReadFailed()
|
static |
Constructs a read failed deserialisation error from the specified message.
Error code is E_ERROR_SERIALISATION_READ_FAILED.
◆ ErrorDeserialisationUnsupportedFormat()
|
static |
Constructs a unsupported format deserialisation error from the specified class id and format.
Error code is E_ERROR_DESERIALISATION_UNSUPPORTED_FORMAT.
◆ ErrorDeserializationBadClassId()
|
static |
DEPRECATED: use PResult::ErrorDeserialisationBadClassId() instead (renaming).
Constructs a bad class id deserialisation error from the specified message. Error code is E_ERROR_SERIALISATION_BAD_CLASS_ID.
◆ ErrorDeserializationReadFailed()
|
static |
DEPRECATED: use PResult::ErrorDeserialisationReadFailed() instead (renaming).
Constructs a read failed deserialisation error from the specified message. Error code is E_ERROR_SERIALISATION_READ_FAILED.
◆ ErrorDeserializationUnsupportedFormat()
|
static |
DEPRECATED: use PResult::ErrorDeserialisationUnsupportedFormat() instead (renaming).
Constructs a unsupported format deserialisation error from the specified class id and format. Error code is E_ERROR_DESERIALISATION_UNSUPPORTED_FORMAT.
◆ ErrorDestringifyNotSupported()
|
static |
Constructs a "destringify not supported" error.
Error code is E_DESTRINGIFY_NOT_SUPPORTED.
◆ ErrorEndOfFile()
Constructs a "end-of-file" error from the specified message.
Error code is E_ERROR_END_OF_FILE.
◆ ErrorEndOfStream()
Constructs a "end of stream" error from the specified message.
Error code is E_ERROR_END_OF_STREAM.
◆ ErrorFailedToCheckOutLicense()
|
static |
Constructs a "failed to checkout a license" error for the specified product.
Error code is E_ERROR_FAILED_TO_CHECKOUT_LICENSE.
◆ ErrorFileNotFound()
Constructs a "file not found" error from the specified filename.
Error code is E_ERROR_FILE_NOT_FOUND.
◆ ErrorInvalidState()
Constructs a "invalid state" error from the specified message.
Error code is E_ERROR_INVALID_STATE.
◆ ErrorNullPointer()
Constructs a "NULL pointer" error from the specified message.
Error code is E_ERROR_NULL_POINTER.
◆ ErrorOpenFileForReading()
Constructs a "unable to open file for reading" error from the specified filename.
Error code is E_ERROR_OPEN_FILE_FOR_READING.
◆ ErrorOpenFileForWriting()
Constructs a "unable to open file for writing" error from the specified filename.
Error code is E_ERROR_OPEN_FILE_FOR_WRITING.
◆ ErrorSerialisation()
|
static |
Constructs a serialisation error from the specified class id.
Error code is E_ERROR_SERIALISATION.
◆ ErrorSerialisationUnsupportedFormat()
|
static |
Constructs a unsupported format serialisation error from the specified class id and format.
Error code is E_ERROR_SERIALISATION_UNSUPPORTED_FORMAT.
◆ ErrorSerialization()
|
static |
DEPRECATED: use PResult::ErrorSerialisation() instead (renaming).
Constructs a serialisation error from the specified class id. Error code is E_ERROR_SERIALISATION.
◆ ErrorSerializationUnsupportedFormat()
|
static |
DEPRECATED: use PResult::ErrorSerialisationUnsupportedFormat() instead (renaming).
Constructs a unsupported format serialisation error from the specified class id and format. Error code is E_ERROR_SERIALISATION_UNSUPPORTED_FORMAT.
◆ ErrorServerDown()
Constructs a "server down" error from the specified message.
Error code is E_ERROR_SERVER_DOWN.
◆ ErrorStreamClosed()
Constructs a "stream closed" error from the specified message.
Error code is E_ERROR_STREAM_CLOSED.
◆ ErrorStreamInvalidated()
Constructs a "stream invalidated" error from the specified message.
Error code is E_ERROR_STREAM_INVALIDATED.
◆ ErrorStreamKicked()
Constructs a "stream kicked" error from the specified message.
Error code is E_ERROR_STREAM_KICKED.
◆ ErrorStreamNotAvailable()
Constructs a "stream not available" error from the specified message.
Error code is E_ERROR_STREAM_NOT_AVAILABLE.
◆ ErrorStreamNotFound()
Constructs a "stream not found" error from the specified message.
Error code is E_ERROR_STREAM_NOT_FOUND.
◆ ErrorTimeout()
Constructs a "timeout" error from the specified message.
Error code is E_ERROR_TIMEOUT.
◆ ErrorUnhandledCase()
Constructs a "Unhandled case" error from the specified message.
Error code is E_ERROR_UNHANDLED_CASE.
◆ Failed()
|
inline |
◆ GetCode()
EReturnCode PResult::GetCode | ( | ) | const |
Returns the code associated with this result.
◆ GetErrorMessage()
PString PResult::GetErrorMessage | ( | ) | const |
Returns the message associated with this result.
◆ IsEndOfStream()
bool PResult::IsEndOfStream | ( | ) | const |
Returns true if the type of this error is PResult::E_ERROR_END_OF_STREAM, false otherwise.
◆ IsFalse()
bool PResult::IsFalse | ( | ) | const |
Returns true if the code of this result is E_FALSE, false otherwise.
- See also
- Ok()
◆ LogErrorIfAny() [1/2]
PResult& PResult::LogErrorIfAny | ( | const PString & | prefix = PString::Empty() , |
int32 | lineNumber = 0 , |
||
const PString & | filename = PString::Empty() |
||
) |
Logs the error message associated with this result if any (level PLog::E_LEVEL_ERROR).
Returns this result itself, for chaining.
Example:
◆ LogErrorIfAny() [2/2]
|
inline |
◆ LogErrorIfAny2() [1/2]
PResult& PResult::LogErrorIfAny2 | ( | int32 | lineNumber1, |
const PString & | filename1, | ||
const PString & | prefix = PString::Empty() , |
||
papillon::int32 | lineNumber2 = 0 , |
||
const PString & | filename2 = PString::Empty() |
||
) |
◆ LogErrorIfAny2() [2/2]
|
inline |
◆ Ok()
bool PResult::Ok | ( | ) | const |
Returns true if the code of this result is E_OK, false otherwise.
- See also
- Failed()
◆ operator bool()
|
inline |
◆ operator!()
|
inline |
◆ operator=()
◆ operator==()
bool PResult::operator== | ( | const PResult & | other | ) | const |
Returns true if this object is the same instance than other, false otherwise.
◆ OrDie()
void PResult::OrDie | ( | const PString & | prefix = PString::Empty() , |
int32 | lineNumber = 0 , |
||
const PString & | filename = PString::Empty() |
||
) | const |
◆ Pop()
PResult& PResult::Pop | ( | ) |
Removes the message on top of this stack and returns this for chaining.
Do nothing if the stack of messages is empty.
◆ PrependErrorMessage()
Prepends the message of this result with the specified message if it is an error and returns this for chaining.
Do nothing if this result is OK or E_ERROR_BAD_MEMORY_ALLOCATION.
◆ Push()
Pushes the specified result on top on this one and returns this for chaining.
If the result is itself a stack of messages, then append the two stacks.
◆ Read()
PResult PResult::Read | ( | PByteStream & | is, |
papillon::ESerialisationFormat | format = papillon::E_BINARY_FORMAT |
||
) |
Reads this object from the bytes stream retrieved from the specified input stream (deserialisation).
This date is set to invalid if any error occurs. Returns PResult::C_OK if success, another result otherwise.
- See also
- Write()
- IsValid()
◆ Size()
papillon::int32 PResult::Size | ( | ) | const |
Returns the size of the stack of messages.
Returns 1 if PResult::C_OK.
◆ ToString()
PString PResult::ToString | ( | ) | const |
Returns a string representation of this object.
◆ Write()
PResult PResult::Write | ( | PByteStream & | os, |
ESerialisationFormat | format = papillon::E_BINARY_FORMAT |
||
) | const |
Writes this object to the specified output stream (serialisation).
Returns PResult::C_OK if success, another result otherwise.
- See also
- Read()
Friends And Related Function Documentation
◆ operator<<
|
friend |
Writes a string representation of this object to the specified std::ostream.
Member Data Documentation
◆ C_ERROR_NO_PRIVATE_IMPLEMENTATION
|
static |
◆ C_ERROR_NOT_SUPPORTED
|
static |
◆ C_ERROR_NOT_YET_IMPLEMENTED
|
static |
◆ C_ERROR_NULL_OBJECT
|
static |
◆ C_ERROR_SERIALISATION_NOT_SUPPORTED
|
static |
◆ C_ERROR_UNKNOWN
|
static |
◆ C_FALSE
|
static |