/* * Copyright (c) 2002, Stefan Farfeleder * $Id: objhandle.h,v 1.2 2002/09/19 10:42:02 stefan Exp $ */ #ifndef JFK_OBJHANDLE_H #define JFK_OBJHANDLE_H #include "object_s.h" namespace JFK { namespace server { /* A handle class for a JFK::server::object. It uses the refcnt member to * decide when to free it. */ class objhandle { public: objhandle() : o(NULL) {} objhandle(object* obj) : o(gethandle(obj)) {} objhandle(const objhandle& oh) : o(gethandle(oh.o)) {} ~objhandle() { freehandle(o); } /* Return a handle to a *copied* object. */ objhandle clone() const { return o->clone(); } object* p() const { return o; } object* operator->() const { return p(); } operator object*() const { return p(); } operator bool() const { return o != NULL; } objhandle& operator=(const objhandle& oh); /* Copy the content of the object controlled by 'oh' into ours. */ void assign(const objhandle oh); private: object* gethandle(object* obj); void freehandle(object* obj); object *o; }; } } #endif