BazisLib::ActionStatus Class Reference

Represents an action status (error code & auxillary info). More...

#include <status.h>

List of all members.

Classes

class  ErrorRecord

Public Member Functions

 ActionStatus ()
CommonErrorType GetErrorCode ()
bool Successful ()
bool operator== (CommonErrorType error)
bool operator!= (CommonErrorType error)
String GetErrorText ()
String ProduceDebugDump ()
String GetMostInformativeText ()

Private Member Functions

void AttachError (CommonErrorType Result, const String::value_type *file, unsigned line, const String::value_type *Function, bool SubStatus)
 ActionStatus (CommonErrorType Result, const String::value_type *file, unsigned line, const String::value_type *Function)

Static Private Member Functions

static String FormatErrorCode (CommonErrorType code)

Private Attributes

CommonErrorType m_Result
std::list< ErrorRecordm_ErrorRecords

Friends

static friend ActionStatus _MAKE_STATUS (CommonErrorType ErrorType, const String::value_type *pszFile, unsigned Line, const String::value_type *pszFunction)
static friend void _ASSIGN_STATUS (ActionStatus *pStatus, CommonErrorType Error, const String::value_type *pszFile, unsigned Line, const String::value_type *pszFunction)
static friend void _ASSIGN_SUBSTATUS (ActionStatus *pStatus, ActionStatus &Source, CommonErrorType Error, const String::value_type *pszFile, unsigned Line, const String::value_type *pszFunction)


Detailed Description

Represents an action status (error code & auxillary info).

This class is an abstraction for such things as HRESULT in Win32, NTSTATUS in DDK and errno in Unix. If a method wants to return the status of its call, it can do it in two ways:

The main feature of ActionStatus is that in the debug build of the library it supports storing full information about file names and line numbers that caused the errors. However, in the release build the ActionStatus object is represented as a simple DWORD that fits in a single register. That way, it produces almost no overhead in the release build (if you use it as a return value, up to 4 additional instructions will be required to transfer it via stack due to calling convention, however, in case of inline calls, the optimizer will put the status to a register). You cannot create initialized ActionStatus objects directly to return a status code. Instead, use the ASSIGN_STATUS() and MAKE_STATUS() macros. That macros ensure that the debug version will put current file name & line number into the error object. Here is an example:

ActionStatus Test1()
{
	...
	return MAKE_STATUS(UnknownError);
}

void *Test2(ActionStatus *pStatus = NULL)
{
	if (...)
	{
		ASSIGN_STATUS(pStatus, FileNotFound);
		return NULL;
	}
	ActionStatus status = Test1();
	if (!Test1())
	{
		ASSIGN_STATUS(pStatus, status);
--- OR ---
		ASSIGN_SUBSTATUS(pStatus, status, SomeDetailedErrorCode);
		return NULL;
	}
	ASSIGN_STATUS(pStatus, Success);
	return ...;
}
		
As a result, you may simply call the ActionStatus::ProduceDebugDump() method to get a dump like this:
The parameter is incorrect. in: CreateSomething (at e:\projects\cvsed\bzslib\tests\filetest\filetest.cpp, line 104)
Invalid pointer in: SomeOtherFunction (at e:\projects\cvsed\bzslib\tests\filetest\filetest.cpp, line 111)
	
Simply include such output in your error messages in the debug version and save plenty of time in finding errors.

Constructor & Destructor Documentation

BazisLib::ActionStatus::ActionStatus ( CommonErrorType  Result,
const String::value_type *  file,
unsigned  line,
const String::value_type *  Function 
) [inline, private]

Here is the call graph for this function:

BazisLib::ActionStatus::ActionStatus (  )  [inline]


Member Function Documentation

void BazisLib::ActionStatus::AttachError ( CommonErrorType  Result,
const String::value_type *  file,
unsigned  line,
const String::value_type *  Function,
bool  SubStatus 
) [inline, private]

static String BazisLib::ActionStatus::FormatErrorCode ( CommonErrorType  code  )  [static, private]

CommonErrorType BazisLib::ActionStatus::GetErrorCode (  )  [inline]

String BazisLib::ActionStatus::GetErrorText (  )  [inline]

Here is the call graph for this function:

String BazisLib::ActionStatus::GetMostInformativeText (  )  [inline]

Here is the call graph for this function:

bool BazisLib::ActionStatus::operator!= ( CommonErrorType  error  )  [inline]

bool BazisLib::ActionStatus::operator== ( CommonErrorType  error  )  [inline]

String BazisLib::ActionStatus::ProduceDebugDump (  )  [inline]

Here is the call graph for this function:

bool BazisLib::ActionStatus::Successful (  )  [inline]


Friends And Related Function Documentation

static friend void _ASSIGN_STATUS ( ActionStatus pStatus,
CommonErrorType  Error,
const String::value_type *  pszFile,
unsigned  Line,
const String::value_type *  pszFunction 
) [friend]

static friend void _ASSIGN_SUBSTATUS ( ActionStatus pStatus,
ActionStatus Source,
CommonErrorType  Error,
const String::value_type *  pszFile,
unsigned  Line,
const String::value_type *  pszFunction 
) [friend]

static friend ActionStatus _MAKE_STATUS ( CommonErrorType  ErrorType,
const String::value_type *  pszFile,
unsigned  Line,
const String::value_type *  pszFunction 
) [friend]


Member Data Documentation


The documentation for this class was generated from the following file:
SourceForge.net Logo