PResult Class Reference

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.

Definition at line 159 of file PResult.h.

#include <PResult.h>

Member Enumeration Documentation

◆ EReturnCode

All the available return codes.

Enumerator
E_OK 
E_ERROR_BAD_MEMORY_ALLOCATION 
E_FALSE 
E_ERROR 
E_ERROR_UNKNOWN 
E_ERROR_BAD_CAST 
E_ERROR_NOT_YET_IMPLEMENTED 
E_ERROR_NOT_SUPPORTED 
E_ERROR_NO_PRIVATE_IMPLEMENTATION 
E_ERROR_NULL_POINTER 
E_ERROR_SERIALISATION 
E_ERROR_SERIALISATION_NOT_SUPPORTED 
E_ERROR_SERIALISATION_UNSUPPORTED_FORMAT 
E_ERROR_DESERIALISATION_READ_FAILED 
E_ERROR_DESERIALISATION_BAD_CLASS_ID 
E_ERROR_DESERIALISATION_UNSUPPORTED_VERSION 
E_ERROR_DESERIALISATION_UNSUPPORTED_FORMAT 
E_ERROR_BAD_ARGUMENT 
E_ERROR_INVALID_STATE 
E_ERROR_UNHANDLED_CASE 
E_ERROR_FILE_NOT_FOUND 
E_ERROR_END_OF_FILE 
E_ERROR_OPEN_FILE_FOR_WRITING 
E_ERROR_OPEN_FILE_FOR_READING 
E_ERROR_BAD_PLUGIN_PARAMETER 
E_ERROR_FAILED_TO_CHECKOUT_LICENSE 
E_ERROR_BAD_URI_FORMAT 
E_ERROR_END_OF_STREAM 
E_ERROR_STREAM_NOT_FOUND 
E_ERROR_SERVER_DOWN 
E_ERROR_STREAM_NOT_AVAILABLE 
E_ERROR_STREAM_CLOSED 
E_ERROR_STREAM_INVALIDATED 
E_ERROR_STREAM_KICKED 
E_ERROR_TIMEOUT 
E_ERROR_FAILED_TO_CHECK_LICENSE 
E_ERROR_INVALID_LICENSE 
E_ERROR_LICENSE_EXPIRED 
E_ERROR_DESTRINGIFY_NOT_SUPPORTED 
E_ERROR_UNDEFINED 

Definition at line 165 of file PResult.h.

Constructor & Destructor Documentation

◆ PResult() [1/4]

PResult::PResult ( )
inline

Constructs a empty result, same as SUCCESS.

Definition at line 253 of file PResult.h.

◆ PResult() [2/4]

PResult::PResult ( EReturnCode  code)
explicit

Constructs a result from a return code.

◆ PResult() [3/4]

PResult::PResult ( EReturnCode  code,
const PString message 
)
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()

static PResult PResult::Error ( const PString errorMessage)
static

Constructs a generic error from the specified message.

Error code is E_ERROR.

◆ ErrorBadArgument()

static PResult PResult::ErrorBadArgument ( const PString message)
static

Constructs a "bad argument" error from the specified message.

Error code is E_ERROR_BAD_ARGUMENT.

◆ ErrorBadCast()

static PResult PResult::ErrorBadCast ( papillon::classid  fromClassId,
papillon::classid  toClassId 
)
static

Constructs a bad cast error from the specified class ids.

Error code is E_ERROR_BAD_CAST.

◆ ErrorBadPluginParameters()

static PResult PResult::ErrorBadPluginParameters ( const PString message)
static

Constructs a "bad plugin parameters" error from the specified message.

Error code is E_ERROR_BAD_PLUGIN_PARAMETER.

◆ ErrorBadURIFormat()

static PResult PResult::ErrorBadURIFormat ( const PString message)
static

Constructs a "failed to checkout a license" error for the specified product.

Error code is E_ERROR_BAD_URI_FORMAT.

◆ ErrorDeserialisationBadClassId()

static PResult PResult::ErrorDeserialisationBadClassId ( )
static

Constructs a bad class id deserialisation error from the specified message.

Error code is E_ERROR_SERIALISATION_BAD_CLASS_ID.

◆ ErrorDeserialisationReadFailed()

static PResult PResult::ErrorDeserialisationReadFailed ( )
static

Constructs a read failed deserialisation error from the specified message.

Error code is E_ERROR_SERIALISATION_READ_FAILED.

◆ ErrorDeserialisationUnsupportedFormat()

static PResult PResult::ErrorDeserialisationUnsupportedFormat ( papillon::ESerialisationFormat  format)
static

Constructs a unsupported format deserialisation error from the specified class id and format.

Error code is E_ERROR_DESERIALISATION_UNSUPPORTED_FORMAT.

◆ ErrorDeserializationBadClassId()

static PResult PResult::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 PResult PResult::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 PResult PResult::ErrorDeserializationUnsupportedFormat ( papillon::ESerialisationFormat  format)
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 PResult PResult::ErrorDestringifyNotSupported ( )
static

Constructs a "destringify not supported" error.

Error code is E_DESTRINGIFY_NOT_SUPPORTED.

◆ ErrorEndOfFile()

static PResult PResult::ErrorEndOfFile ( const PString message)
static

Constructs a "end-of-file" error from the specified message.

Error code is E_ERROR_END_OF_FILE.

◆ ErrorEndOfStream()

static PResult PResult::ErrorEndOfStream ( const PString message)
static

Constructs a "end of stream" error from the specified message.

Error code is E_ERROR_END_OF_STREAM.

◆ ErrorFailedToCheckOutLicense()

static PResult PResult::ErrorFailedToCheckOutLicense ( const PString productName,
const PString productVersion,
const PString message 
)
static

Constructs a "failed to checkout a license" error for the specified product.

Error code is E_ERROR_FAILED_TO_CHECKOUT_LICENSE.

◆ ErrorFileNotFound()

static PResult PResult::ErrorFileNotFound ( const PString filename)
static

Constructs a "file not found" error from the specified filename.

Error code is E_ERROR_FILE_NOT_FOUND.

◆ ErrorInvalidState()

static PResult PResult::ErrorInvalidState ( const PString message)
static

Constructs a "invalid state" error from the specified message.

Error code is E_ERROR_INVALID_STATE.

◆ ErrorNullPointer()

static PResult PResult::ErrorNullPointer ( const PString errorMessage)
static

Constructs a "NULL pointer" error from the specified message.

Error code is E_ERROR_NULL_POINTER.

◆ ErrorOpenFileForReading()

static PResult PResult::ErrorOpenFileForReading ( const PString filename)
static

Constructs a "unable to open file for reading" error from the specified filename.

Error code is E_ERROR_OPEN_FILE_FOR_READING.

◆ ErrorOpenFileForWriting()

static PResult PResult::ErrorOpenFileForWriting ( const PString filename)
static

Constructs a "unable to open file for writing" error from the specified filename.

Error code is E_ERROR_OPEN_FILE_FOR_WRITING.

◆ ErrorSerialisation()

static PResult PResult::ErrorSerialisation ( )
static

Constructs a serialisation error from the specified class id.

Error code is E_ERROR_SERIALISATION.

◆ ErrorSerialisationUnsupportedFormat()

static PResult PResult::ErrorSerialisationUnsupportedFormat ( papillon::ESerialisationFormat  format)
static

Constructs a unsupported format serialisation error from the specified class id and format.

Error code is E_ERROR_SERIALISATION_UNSUPPORTED_FORMAT.

◆ ErrorSerialization()

static PResult PResult::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 PResult PResult::ErrorSerializationUnsupportedFormat ( papillon::ESerialisationFormat  format)
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()

static PResult PResult::ErrorServerDown ( const PString message)
static

Constructs a "server down" error from the specified message.

Error code is E_ERROR_SERVER_DOWN.

◆ ErrorStreamClosed()

static PResult PResult::ErrorStreamClosed ( const PString message)
static

Constructs a "stream closed" error from the specified message.

Error code is E_ERROR_STREAM_CLOSED.

◆ ErrorStreamInvalidated()

static PResult PResult::ErrorStreamInvalidated ( const PString message)
static

Constructs a "stream invalidated" error from the specified message.

Error code is E_ERROR_STREAM_INVALIDATED.

◆ ErrorStreamKicked()

static PResult PResult::ErrorStreamKicked ( const PString message)
static

Constructs a "stream kicked" error from the specified message.

Error code is E_ERROR_STREAM_KICKED.

◆ ErrorStreamNotAvailable()

static PResult PResult::ErrorStreamNotAvailable ( const PString message)
static

Constructs a "stream not available" error from the specified message.

Error code is E_ERROR_STREAM_NOT_AVAILABLE.

◆ ErrorStreamNotFound()

static PResult PResult::ErrorStreamNotFound ( const PString message)
static

Constructs a "stream not found" error from the specified message.

Error code is E_ERROR_STREAM_NOT_FOUND.

◆ ErrorTimeout()

static PResult PResult::ErrorTimeout ( const PString message)
static

Constructs a "timeout" error from the specified message.

Error code is E_ERROR_TIMEOUT.

◆ ErrorUnhandledCase()

static PResult PResult::ErrorUnhandledCase ( const PString message)
static

Constructs a "Unhandled case" error from the specified message.

Error code is E_ERROR_UNHANDLED_CASE.

◆ Failed()

bool PResult::Failed ( ) const
inline

Returns true if the code of this result is not E_OK (failure), false otherwise.

See also
Ok()

Definition at line 537 of file PResult.h.

◆ 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:

PResult ret = myObject.DoSomething().LogErrorIfAny();
See also
Ok()
Failed()

◆ LogErrorIfAny() [2/2]

const PResult& PResult::LogErrorIfAny ( const PString prefix = "",
papillon::int32  lineNumber = 0,
const PString filename = PString::Empty() 
) const
inline

Definition at line 559 of file PResult.h.

◆ 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]

const PResult& PResult::LogErrorIfAny2 ( papillon::int32  lineNumber1,
const PString filename1,
const PString prefix = PString::Empty(),
papillon::int32  lineNumber2 = 0,
const PString filename2 = PString::Empty() 
) const
inline

Definition at line 566 of file PResult.h.

◆ Ok()

bool PResult::Ok ( ) const

Returns true if the code of this result is E_OK, false otherwise.

See also
Failed()

◆ operator bool()

PResult::operator bool ( ) const
inline

Enables a PResult object to be cast to boolean easily.

Definition at line 490 of file PResult.h.

◆ operator!()

bool PResult::operator! ( ) const
inline

Enables a PResult object to be cast to boolean easily.

Definition at line 485 of file PResult.h.

◆ operator=()

PResult& PResult::operator= ( const PResult other)

Performs a deep copy of other to this object.

◆ 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

Logs the error message associated with this result (level FATAL) and exits the application if this result is any error.

See also
Ok()
Failed()

◆ 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()

PResult& PResult::PrependErrorMessage ( const PString message)

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()

PResult& PResult::Push ( const PResult result)

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<<

PAPILLON_API_CORE std::ostream& operator<< ( std::ostream &  os,
const PResult obj 
)
friend

Writes a string representation of this object to the specified std::ostream.

Member Data Documentation

◆ C_ERROR_NO_PRIVATE_IMPLEMENTATION

const PResult PResult::C_ERROR_NO_PRIVATE_IMPLEMENTATION
static

A constant holding the "no implementation" result.

Definition at line 243 of file PResult.h.

◆ C_ERROR_NOT_SUPPORTED

const PResult PResult::C_ERROR_NOT_SUPPORTED
static

A constant holding the "not supported" result.

Definition at line 238 of file PResult.h.

◆ C_ERROR_NOT_YET_IMPLEMENTED

const PResult PResult::C_ERROR_NOT_YET_IMPLEMENTED
static

A constant holding the "not yet implemented" result.

Definition at line 233 of file PResult.h.

◆ C_ERROR_NULL_OBJECT

const PResult PResult::C_ERROR_NULL_OBJECT
static

A constant holding the "NULL object" result.

Definition at line 228 of file PResult.h.

◆ C_ERROR_SERIALISATION_NOT_SUPPORTED

const PResult PResult::C_ERROR_SERIALISATION_NOT_SUPPORTED
static

A constant holding the "serialisation not supported" result.

Definition at line 248 of file PResult.h.

◆ C_ERROR_UNKNOWN

const PResult PResult::C_ERROR_UNKNOWN
static

A constant holding the "unknown error" result.

Definition at line 223 of file PResult.h.

◆ C_FALSE

const PResult PResult::C_FALSE
static

A constant holding the "false" result (not necessary an error).

Definition at line 218 of file PResult.h.

◆ C_OK

const PResult PResult::C_OK
static

A constant holding the "success" result.

Definition at line 213 of file PResult.h.