/////////////////////////////////////////////////////////////////////////////
//! object.cc --- definitions for root of SIMLIB class hierarchy
//
// SIMLIB version: 2.18
// Date: 2004-11-07
//
// Copyright (c) 1991-2004 Petr Peringer
//
// This library is licensed under GNU Library GPL. See the file COPYING.
//
//
// this module contains implementation of base class SimObject
//
#include "simlib.h"
#include "internal.h"
////////////////////////////////////////////////////////////////////////////
SIMLIB_IMPLEMENTATION
////////////////////////////////////////////////////////////////////////////
// static flag for IsAllocated()
static bool SimObject_allocated = false;
////////////////////////////////////////////////////////////////////////////
//! allocate memory for object
//
void *SimObject::operator new(unsigned size) {
// dprintf(("SimObject::operator new(%u) = %p ", size, ptr));
// try {
void *ptr = ::new char[size]; // global operator new
// }catch(...) { SIMLIB_error(MemoryError); }
if(!ptr) // we expect old behavior of new
SIMLIB_error(MemoryError);
SimObject_allocated = true; // update flag
return ptr;
}
////////////////////////////////////////////////////////////////////////////
//! free memory
//
void SimObject::operator delete(void *ptr) {
// dprintf(("SimObject::operator delete(%p) ", ptr));
if ((static_cast<SimObject*>(ptr))->IsAllocated())
::operator delete(ptr); // free memory
}
////////////////////////////////////////////////////////////////////////////
//! constructor
//
SimObject::SimObject() :
_name(0),
_flags(0)
{
// dprintf(("SimObject::SimObject() this=%p ", this));
if(SimObject_allocated) {
SimObject_allocated = false;
_flags |= _ALLOCATED;
}
}
////////////////////////////////////////////////////////////////////////////
//! virtual destructor
//
SimObject::~SimObject()
{
// dprintf(("SimObject::~SimObject() this=%p ", this));
}
////////////////////////////////////////////////////////////////////////////
//! set the name of object
//
void SimObject::SetName(const char *name)
{
_name = name;
}
////////////////////////////////////////////////////////////////////////////
//! get the name of object
//
const char *SimObject::Name()
{
if(_name==0) return ""; // no name
return _name;
}
////////////////////////////////////////////////////////////////////////////
//! print object's info
//
void SimObject::Output()
{
Print("SimObject: this=%p, name=%s\n", this, Name()); // default
}
// end
syntax highlighted by Code2HTML, v. 0.9.1