GCF LOGO VCL LOGO

This class allows representation of the result of a process and/or function. More...

#include <GCF3/GCFGlobal>

Public Member Functions

 Result ()
 
 Result (bool val)
 
 Result (bool val, const QString &code, const QString &msg=QString(), const QVariant &data=QVariant())
 
 Result (const Result &other)
 
bool isSuccess () const
 
QString code () const
 
QString message () const
 
QVariant data () const
 
Resultoperator= (const Result &other)
 
Resultoperator= (bool val)
 
bool operator== (const Result &other) const
 
QString toString () const
 

Detailed Description

This class can be used to capture in one object the following

  • success/failure flag
  • error code and error message in case of failure
  • data in case of success

This class can be used as a return data-type in almost any function, specially functions that return true/false. The benefit of using this class in such a function is that you can return a error code+message incase of failure and concrete result in case of success.

Example:

GCF::Result divide(const double a, const double b)
{
if(b == 0)
return GCF::Result(false, "DIV_BY_ZERO", "b is ZERO");
const double retVal = a/b;
return GCF::Result(true, QString(), QString(), retVal);
}

This would allow the caller of your method to get a sense of what went wrong, incase of an error.

Example:

GCF::Result result = ::divide(20, 0);
if(!result)
QMessageBox::information(..., "Error", result.message());
else
....

Constructor & Destructor Documentation

GCF::Result::Result ( )

Default constructor. Constructs result with success-flag as false.

GCF::Result::Result ( bool  val)

Constructs result with success-flag as val.

Parameters
valsuccess-flag of the result
GCF::Result::Result ( bool  val,
const QString &  code,
const QString &  msg = QString(),
const QVariant &  data = QVariant() 
)

Constructs a result from the given parameters

Parameters
valsuccess-flag of the result
codeerorr-code of the result
msgerror-message of the result
datadata (or result) of the result
GCF::Result::Result ( const Result other)

Copy constructor

Member Function Documentation

bool GCF::Result::isSuccess ( ) const
Returns
success-flag of the result
QString GCF::Result::code ( ) const
Returns
error code of the result, if isSuccess() returns false. Empty string otherwise.
QString GCF::Result::message ( ) const
Returns
error message of the result, if isSuccess() returns false. Empty string otherwise.
QVariant GCF::Result::data ( ) const
Returns
data of the result, if isSuccess() return true. Invalid QVariant otherwise.
GCF::Result & GCF::Result::operator= ( const Result other)

Assignment operator

GCF::Result & GCF::Result::operator= ( bool  val)

Assignment operator

bool GCF::Result::operator== ( const Result other) const

Comparison operator

QString GCF::Result::toString ( ) const
Returns
a string representation of the result.
Note
operator<< on QDebug has been overloaded to print into debug output string representations of GCF::Result. So you can stream this object into qDebug(). Example:
GCF::Result result = ...
qDebug() << result;