vmobject.h
mud++0.33/src/vmobject.h · 1.9 KB
From the archive mud++0.33.tar.gz
Download the archive « Back to the archive contents
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp-list@mailhost.net
------------------------------------------------------------------------------
vmobject.h
*/
#ifndef _VMOBJECT_H
#define _VMOBJECT_H
#include "vmtypes.h"
#include "garbcoll.h"
#include "erratum.h"
#define IN_C_WORLD (1 << 30)
class VMObject
{
private:
int ref_count;
public:
VMObject() :
ref_count(0)
{
toCWorld();
GC_register(this);
}
VMObject( VMObject & ) :
ref_count(0)
{
toCWorld();
GC_register(this);
}
virtual ~VMObject()
{
#ifdef GARBAGE_COLLECTOR_DEBUG
if ( !gc_working_now )
Error::dump("Object deleted outside of GC");
if ( ref_count != 0 )
Error::dump("Object collected with nonzero reference count");
#endif
}
virtual vmtype getVMType() { return VMT_VMOBJECT; }
void fromCWorld() { ref_count &= ~IN_C_WORLD; }
void toCWorld() { ref_count |= IN_C_WORLD; }
void fordelete() { fromCWorld(); }
bool inCWorld() { return (ref_count & IN_C_WORLD); }
void getHandle() { ref_count++; return; }
void freeHandle() { ref_count--; }
int getRefCount() { return ref_count; }
int getCleanRefCount() { return (ref_count & ~IN_C_WORLD); }
const char * getVMTypeName() { return vmtype_table[getVMType()].name; }
};
#endif