Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/refcount.hh File Reference

Defines and inline implements RefCount. More...

Go to the source code of this file.

Namespaces

Defines


Detailed Description

Defines and inline implements RefCount.

Definition in file refcount.hh.


Define Documentation

#define pREF type,
ptr,
value,
body   ) 
 

Value:

{ type ptr = value; \
                                       try { body; if(ptr) (ptr)->release(); \
                                       } catch(...) { if(ptr) (ptr)->release(); throw; } }
Deprecated:
Use vRef
Parameters:
type the pointer type (Foo*) of the referred-to object
ptr the variable that will be used in this lexical block
value the value assigned to the named variable, this should be is where refcounted object is acquired
body relevant code that operates on the variable
Please note that pREF and rREF have been deprecated in favor of the vRef smart pointer template! However they still show up from time to time in the code...

This macro defines a lexical scope in which you have a reference to a reference-counted object. The purpose of this macro is to simplify tracking the acquire/release pair in the most common case of accessing a refcounted object by calling release() for you when you're clearly done accessing the refcounted object. This example should make it clearer:

    pREF(Sphere*, sphere, MetaObject::meta_cast<Sphere*>(MetaFactory::createLocalObject(&ls, typeid(Sphere).name(), 0));,
         sphere->setAccessControl(&NoPropertyAccessControl::static_NoPropertyAccessControl);
         sphere->setMaterial("#FF0000");
         // more sphere->setSomething(); method calls
         model->insertChild(-1, "ball", sphere);
        );
This macro evaluates to the following (edited for readability):
    {
        Sphere* sphere = MetaObject::meta_cast<Sphere*>(MetaFactory::createLocalObject(&ls, typeid(Sphere).name(), 0));
        try {
            sphere->setAccessControl(&NoPropertyAccessControl::static_NoPropertyAccessControl);
            sphere->setMaterial("#FF0000");
            // more sphere->setSomething(); method calls
            model->insertChild(-1, "ball", sphere);
            if(sphere) sphere->release();
        } catch(exception x) {
            if(sphere) sphere->release();
            throw;
        }
    }
Note:
In this example, a new sphere object is allocated, it's state is set, and then it is (implicitly) released. Because the object has been inserted into another Vobject ("model") it will not be deleted. If it had not been acquired by another section of the program, closing this block (calling release()) would cause "sphere" to be deleted. Also note that acquire() should be called by the function RETURNING the value, so if you receive a refcounted object you should assume that the count has already been incremented. Note that if you do get a NULL assigned to your variable, it will detect that and not try to release, so you can use these macros with methods that may return '0' on error. You are only responsible for calling release() when you are done if you are not using this macro. Exceptions which inherit from the base class 'exception' will be caught, the refcount released appropriately, and re-thrown. If you 'return', 'continue', 'break', 'goto' or otherwise jump to another part of your program while in one of these macro blocks, release() WILL NOT get called. Finally, if you get an error that looks like "macro `pREF' used with too many (#) args", this means the compiler has probably gotten confused on a statement like this:
    int foo, bar, baz;
If this is the case, to un-confuse the compiler you need to seperate out each variable declaration.
    int foo;
    int bar;
    int baz;

Definition at line 114 of file refcount.hh.

Referenced by ExtrapolatedRemoteProperty::addExtrapolationListener(), RemoteProperty::asyncRead(), LocalSite::checkScheduleHoldsSite(), RemoteLogin::doRequestLogin(), VOS::RemoteVobject::findChild(), BufferedRemoteProperty::flush(), VOS::RemoteVobject::getParents(), RemoteProperty::getRawLength(), VOS::RemoteVobject::getTypes(), LocalLogin::handleLoginChallengeReply(), LocalLogin::handleRequestLogin(), RemoteLogin::handleRequestLoginChallenge(), LocalImage2D::initialize(), VOS::RemoteVobject::insertChild(), LocalSound::pause(), LocalSound::play(), RemoteProperty::readRaw(), VOS::RemoteVobject::removeChildListener(), ExtrapolatedRemoteProperty::removeExtrapolationListener(), VOS::RemoteVobject::removeParentListener(), VOS::RemoteVobject::removeTypeListener(), LocalSound::resume(), VOS::RemoteStreamSite::runScript(), VOS::RemoteSocketSite::secureConnection(), ExtrapolatedLocalProperty::sendMessage(), VOS::LocalSocketSite::sendMessage(), ExtrapolatedRemoteProperty::set(), VOS::RemoteVobject::setChild(), and LocalSound::stop().

#define rREF type,
ptr,
value,
body   ) 
 

Value:

{ type ptr = value; \
                                       try { body; (ptr).release(); \
                                       } catch(...) { (ptr).release(); throw; } }
Like pREF, only the value is a C++ reference (Foo&) instead of a pointer (Foo*).

Definition at line 111 of file refcount.hh.

Referenced by ExtrapolatedRemoteProperty::addExtrapolationListener(), RemoteProperty::asyncRead(), RemoteLogin::doRequestLogin(), VOS::RemoteVobject::findChild(), VOS::VobjectImplementation::findObject(), VOS::RemoteVobject::findObject(), BufferedRemoteProperty::flush(), Metadata::get_author(), Metadata::get_author_datatype(), Metadata::get_author_url(), Metadata::get_author_url_datatype(), Metadata::get_comment(), Metadata::get_comment_datatype(), Metadata::get_copyright(), Metadata::get_copyright_datatype(), Metadata::get_creation_time(), Metadata::get_creation_time_datatype(), Metadata::get_description(), Metadata::get_description_datatype(), Metadata::get_language(), Metadata::get_language_datatype(), Metadata::get_modification_time(), Metadata::get_modification_time_datatype(), Metadata::get_title(), Metadata::get_title_datatype(), Metadata::get_version(), Metadata::get_version_datatype(), Talkative::get_voice(), Talkative::get_voice_datatype(), Hypercard::getDescription(), A3DL::Viewpoint::getFOV(), Image2D::getImage(), Image2D::getImageDatatype(), Image2D::getImageLength(), Sound::getImmediate(), Sound::getLoop(), Image2D::getOrientation(), A3DL::Viewpoint::getOrientation(), VOS::RemoteVobject::getParents(), Image2D::getPosition(), A3DL::Viewpoint::getPosition(), RemoteProperty::getRawLength(), Image2D::getScaling(), Sound::getSound(), Sound::getSoundDatatype(), Sound::getSoundLength(), A3DL::Light::getStatic(), Text::getText(), Text::getTextDatatype(), Hypercard::getTitle(), A3DL::Viewpoint::getTitle(), VOS::RemoteVobject::getTypes(), LocalLogin::handleLoginChallengeReply(), LocalLogin::handleRequestLogin(), RemoteLogin::handleRequestLoginChallenge(), LocalImage2D::initialize(), VOS::RemoteVobject::insertChild(), VOS::Vobject::operator==(), RemoteProperty::readRaw(), VOS::RemoteVobject::removeChildListener(), ExtrapolatedRemoteProperty::removeExtrapolationListener(), VOS::RemoteVobject::removeParentListener(), VOS::RemoteVobject::removeTypeListener(), VOS::RemoteSocketSite::secureConnection(), ExtrapolatedLocalProperty::sendMessage(), VOS::RemoteVobject::sendMessage(), VOS::LocalSocketSite::sendMessage(), ExtrapolatedRemoteProperty::set(), VOS::RemoteVobject::setChild(), VOS::RemoteSite::setChild(), Hypercard::setLink(), and Property::setProperty().


Generated on Tue Aug 12 03:55:48 2003 for Interreality Project - VOS by doxygen 1.3.2