home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
CLASS.ZIP
/
OBJECT.CC
< prev
next >
Wrap
Text File
|
1993-02-14
|
4KB
|
177 lines
#include "object.h"
#include "memory.h"
object::object(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling object(%x)\n", this);
#endif
bSuccessfullConstructed = TRUE;
DosCreateMutexSem((unsigned char*)0, &hMtxAccess, 0, FALSE);
}
object::~object(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling ~object(%x)\n", this);
#endif
DosCloseMutexSem(hMtxAccess);
}
void *object::operator new(unsigned int iSize)
{ unsigned int *pObject;
if (!(pObject = malloc(iSize + sizeof(unsigned int))))
return (void *)0;
*pObject = iSize;
memset(pObject += 1, 0, iSize);
return (void*)pObject;
}
void object::operator delete(void *pObject)
{ unsigned int *pSize;
memset(pObject, 0, *(pSize = ((unsigned int*)pObject - 1)));
free(pSize);
}
void construct::doSomething(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::doSomething(%x)\n", this);
#endif SHOWCALLS
}
// Only if init() is direct called
void construct::destructAll()
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::destructAll(%x)\n", this);
#endif SHOWCALLS
if (bSuccessfullConstructed)
{ destructPre();
destruct();
destructPost();
}
}
void construct::run(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::run(%x)\n", this);
#endif SHOWCALLS
#ifdef DEBUG
fprintf(stderr, "this->doSomething() = %x\n", &this->doSomething);
#endif
if (init())
{ printFileLine();
#ifdef DEBUG
fprintf(stderr, "doSomething() = %x\n", &this->doSomething);
#endif
doSomething();
printFileLine();
destructAll();
}
#ifdef SHOWCALLS
fprintf(stderr, "Leaving construct::run(%x)\n", this);
#endif SHOWCALLS
}
Boolean construct::init(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::init(%x)\n", this);
#endif SHOWCALLS
#ifdef DEBUG
fprintf(stderr, "this->doSomething() = %x\n", &this->doSomething);
#endif
if (bSuccessfullConstructed)
{ if (initPre())
if (create())
{
#ifdef SHOWCALLS
fprintf(stderr,"Calling initPost(%x) inside construct::init(%x)\n", this, this);
#endif
if (initPost())
return TRUE;
else
{ destruct();
destructPost();
bSuccessfullConstructed = FALSE;
return FALSE;
}
}
else
{ destructPost();
bSuccessfullConstructed = FALSE;
return FALSE;
}
else
{ bSuccessfullConstructed = FALSE;
return FALSE;
}
}
else
{ bSuccessfullConstructed = FALSE;
return FALSE;
}
}
Boolean construct::initPre(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::initPre(%x)\n", this);
#endif SHOWCALLS
return TRUE;
}
Boolean construct::create(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::create(%x)\n", this);
#endif SHOWCALLS
return TRUE;
}
Boolean construct::initPost(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::initPost(%x)\n", this);
#endif SHOWCALLS
return TRUE;
}
void construct::destructPost(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::destructPost(%x)\n", this);
#endif SHOWCALLS
}
void construct::destructPre(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::destructPre(%x)\n", this);
#endif SHOWCALLS
}
void construct::destruct(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "construct::destruct(%x)\n", this);
#endif SHOWCALLS
}