|
From: James W. W. <os...@jw...> - 2004-12-29 04:57:01
|
In the course of improving text 3DMF reading, I'm going to introduce a
simple C++ wrapper class for a Quesa object. (One could make such a
wrapper using boost::intrusive_pointer, but I didn't think we would
want to require Boost.) Since this class could be useful for users of
Quesa as well as in the implementation, I'm wondering whether I should
put it in the SDK rather than in the source hierarchy?
Here's the interface. Comments follow.
class CQ3ObjectRef
{
public:
// default constructor
CQ3ObjectRef()
: mObject( NULL ) {}
// copy constructor
CQ3ObjectRef( const CQ3ObjectRef& inOther );
// constructor from a Quesa object
// Note: assumes it is given a new reference
explicit CQ3ObjectRef( TQ3SharedObject inObject )
: mObject( inObject ) {}
// destructor
~CQ3ObjectRef();
// assignment operator
CQ3ObjectRef& operator=( const CQ3ObjectRef& inOther );
void swap( CQ3ObjectRef& ioOther );
bool isvalid() const { return mObject != NULL; }
TQ3SharedObject get() const { return mObject; }
private:
TQ3SharedObject mObject;
};
Notes:
* This object can be used in STL containers.
* All methods will have inline definitions.
* No methods throw exceptions.
* I tried to keep it simple, so I did not provide release() or reset()
functions. In place of myob.reset( newref ) one can write myob =
CObjectRef(newRef), and in place of
TQ3Object x = myob.release();
one can write
TQ3Object x = Q3Shared_GetReference( myob.get() );
--
<http://www.jwwalker.com/>
|