class CorCheckValid class for checking instance validity
| | checkOk ( const void* aThisPtr, const char* aFile, int aLine ) checks if this instance is still OK |
| | CorCheckValid () c'tor |
| | ~CorCheckValid () d'tor |
| | $Id: CorCheckValid |
class for checking instance validity
SYNOPSIS
#include <CorCheckValid.h>
CorCheckValid myClass;
DESCRIPTION
This class serves three roles:
o It asserts if member functions are called through a null pointer.
o It asserts if an instance is destructed twice.
o It asserts if member functions are called on a rubbish pointer
MyClass* c = 0;
c->somefunc(); << Bang
Note that classes check themselves. It is not up to the users of the class to do anything, or even to know about the checking.
Sadly the overhead is permanent, it cannot be removed in release code as the danger of linking development and non-development libraries is too great. (i.e the classes would be different sizes)
Luckily there are just two simple macros to handle all of the work.
There is absolutely no code inserted into member functions not compiled with -DEBUG (except the constructos and destructors, where a tiny amount of code is inserted).
CAUTIONS
There is a two byte overhead in each instance that uses the
checker so it is only sensible for larger classes such as containers.
EXAMPLES
In your classes definition add the line
COR_CHECKVALID_CLASS;
Typically this would go in the private section right at the bottom, it is of no interest to the end user. (If class is a base class then put it at the end of the protected section so derived class can check themselves.)
#include <CorCheckValid.h>
class MyClass {
public:
Myclass();
int doit();
protected:
int mydata;
COR_CHECKVALID_CLASS;
};
In each memeber function add the macro call COR_CHECKVALID; right at the top of the function
int MyClass::doit() {
COR_CHECKVALID;
..
}
CorCheckValid()
~CorCheckValid()
void checkOk( const void* aThisPtr, const char* aFile, int aLine )
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de