PLearn 0.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Types | Private Member Functions
PLearn::ParentableObject Class Reference

Object which maintains a "parent" pointer as part of an object graph. More...

#include <ParentableObject.h>

Inheritance diagram for PLearn::ParentableObject:
Inheritance graph
[legend]
Collaboration diagram for PLearn::ParentableObject:
Collaboration graph
[legend]

List of all members.

Public Types

enum  ParentKind { AnyParent, WeakParent, UniqueParent }
 Kind of parenting relationship; see class help for details. More...

Public Member Functions

 ParentableObject (bool adoptive_parent=false, ParentKind=WeakParent)
 Default constructor.
Objectparent ()
 Accessor for parent object.
const Objectparent () const
virtual void updateChildrensParent (Object *parent)
 Function that actually does the heavy work of traversing the descendants and setting _their_ backpointers to point to the specified parent.
virtual void setParent (Object *parent)
 Setter for the parent object; virtual since "transparent parentables" might wish to forward it to children.
virtual void checkParent () const
 After the m_parent field of a child has been set, this function is called so that the child has a chance to check the parent (e.g.
virtual ParentableObjectdeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()
static void declareMethods (RemoteMethodMap &rmm)
 Declare the methods that are remote-callable.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Attributes

Objectm_parent
 Backpointer to parent.
bool m_adoptive_parent
 If true, don't set the subobjects' parent to this.
ParentKind m_parent_kind
 The kind of parent.

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 Simply call updateChildrensParent with this.

Detailed Description

Object which maintains a "parent" pointer as part of an object graph.

The purpose of ParentableObject is to facilitate the building of complex graphs of Objects. The basic ideas are as follows:

In other words, this class both provides the backpointer in an object graph, and provides the mechanism to update the backpointer according to arbitrary forward pointers (as long as the forward pointers are accessible as options through an ObjectOptionsIterator.)

We want some objects to be able to HAVE A PARENT (hence be a ParentableObject), but not to act as the parent for somebody else. They are 'adoptive', since they are not the biological parents of their children. An option can be specified upon construction of Parentable object that disables the parent-setting aspect, i.e. none of its subobjects can have this as their parent. This is useful if some subobjects are pointed to by multiple ParentableObjects, and we want to control who gets to be the legitimate parent.

Each ParentableObject can be marked with the kind of parent it wants. The following kinds are supported:

Definition at line 93 of file ParentableObject.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 95 of file ParentableObject.h.


Member Enumeration Documentation

Kind of parenting relationship; see class help for details.

Enumerator:
AnyParent 
WeakParent 
UniqueParent 

Definition at line 99 of file ParentableObject.h.


Constructor & Destructor Documentation

PLearn::ParentableObject::ParentableObject ( bool  adoptive_parent = false,
ParentKind  pk = WeakParent 
)

Default constructor.

Definition at line 85 of file ParentableObject.cc.

    : m_parent(0), m_adoptive_parent(adoptive_parent), m_parent_kind(pk)
{ }

Member Function Documentation

string PLearn::ParentableObject::_classname_ ( ) [static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

OptionList & PLearn::ParentableObject::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

RemoteMethodMap & PLearn::ParentableObject::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

bool PLearn::ParentableObject::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

StaticInitializer ParentableObject::_static_initializer_ & PLearn::ParentableObject::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

void PLearn::ParentableObject::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 90 of file ParentableObject.cc.

References PLearn::Object::build(), and build_().

Referenced by PLearn::TypedParentableObject< ParentT >::build(), and PLearn::TransparentParentable::build().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ParentableObject::build_ ( ) [private]

Simply call updateChildrensParent with this.

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 125 of file ParentableObject.cc.

References updateChildrensParent().

Referenced by build().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ParentableObject::checkParent ( ) const [virtual]

After the m_parent field of a child has been set, this function is called so that the child has a chance to check the parent (e.g.

dynamic type checking). By default it just asserts that there is a parent.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 203 of file ParentableObject.cc.

References m_parent, and PLASSERT.

Referenced by declareMethods(), and updateChildrensParent().

Here is the caller graph for this function:

void PLearn::ParentableObject::declareMethods ( RemoteMethodMap rmm) [static]

Declare the methods that are remote-callable.

Reimplemented from PLearn::Object.

Definition at line 103 of file ParentableObject.cc.

References PLearn::Object::_getRemoteMethodMap_(), checkParent(), PLearn::declareMethod(), PLearn::RemoteMethodMap::inherited(), parent(), and setParent().

{
    // Insert a backpointer to remote methods; note that this
    // different than for declareOptions()
    rmm.inherited(inherited::_getRemoteMethodMap_());

    declareMethod(
        rmm, "getParent", (const Object* (ParentableObject::*)() const)&ParentableObject::parent,
        (BodyDoc("Return the parent object")));

    declareMethod(
        rmm, "setParent", &ParentableObject::setParent,
        (BodyDoc("Setter for the parent object"),
         ArgDoc ("parent", "Pointer to the new parent of this object")));

    declareMethod(
        rmm, "checkParent", &ParentableObject::checkParent,
        (BodyDoc("After the m_parent field of a child has been set, this function is\n"
                 "called so that the child has a chance to check the parent (e.g. dynamic\n"
                 "type checking).  By default it just asserts that there is a parent.")));
}

Here is the call graph for this function:

static const PPath& PLearn::ParentableObject::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 133 of file ParentableObject.h.

:
ParentableObject * PLearn::ParentableObject::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 83 of file ParentableObject.cc.

void PLearn::ParentableObject::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TransparentParentable.

Definition at line 96 of file ParentableObject.cc.

References PLearn::deepCopyField(), m_parent, and PLearn::Object::makeDeepCopyFromShallowCopy().

Referenced by PLearn::TransparentParentable::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

Here is the caller graph for this function:

Object* PLearn::ParentableObject::parent ( ) [inline]

Accessor for parent object.

Reimplemented in PLearn::TypedParentableObject< ParentT >.

Definition at line 112 of file ParentableObject.h.

References m_parent.

Referenced by declareMethods(), setParent(), and PLearn::TransparentParentable::updateChildrensParent().

{ return m_parent; }

Here is the caller graph for this function:

const Object* PLearn::ParentableObject::parent ( ) const [inline]

Reimplemented in PLearn::TypedParentableObject< ParentT >.

Definition at line 113 of file ParentableObject.h.

References m_parent.

{ return m_parent; }
void PLearn::ParentableObject::setParent ( Object parent) [virtual]

Setter for the parent object; virtual since "transparent parentables" might wish to forward it to children.

Reimplemented in PLearn::TransparentParentable.

Definition at line 150 of file ParentableObject.cc.

References AnyParent, PLearn::Object::classname(), PLearn::endl(), PLearn::left(), m_parent, m_parent_kind, parent(), PLERROR, UniqueParent, and WeakParent.

Referenced by declareMethods(), PLearn::TransparentParentable::setParent(), and updateChildrensParent().

{
    if (m_parent == parent)
        return;

    // Behave appropriately according to the type of parent we want
    switch (m_parent_kind) {
    case AnyParent:
        break;
        
    case WeakParent:
        if (m_parent) {
            MODULE_LOG << "Object at " << ((void*)this)
                       << " (" << left(classname(),30) << ") "
                       << " ignoring candidate weak parent " << ((void*)parent)
                       << " (" << (parent? parent->classname() : string("NULL")) << ") "
                       << endl;
            return;
        }
        break;
        
    case UniqueParent:
        if (m_parent)         // Because of test above, m_parent != parent
            PLERROR("ParentableObject::setParent: for object at 0x%p (%s),\n"
                    "trying to override existing parent at 0x%p (%s) with\n"
                    "new parent at 0x%p (%s) -- parenting mode set to UniqueParent.",
                    (void*)this, classname().c_str(),
                    (void*)m_parent, m_parent->classname().c_str(),
                    (void*)parent, (parent? parent->classname().c_str() : "NULL"));
        break;
    }

    // Do some logging
    if (m_parent) {
        MODULE_LOG << "Object at " << ((void*)this)
                   << " (" << left(classname(),30) << ") "
                   << " getting parent " << ((void*)parent)
                   << " (" << (parent? parent->classname() : string("NULL")) << ") "
                   << " overriding previous " << ((void*)m_parent)
                   << " (" << m_parent->classname() << ") "
                   << endl;
    }
    else {
        MODULE_LOG << "Object at " << ((void*)this)
                   << " (" << left(classname(),30) << ") "
                   << " getting parent " << ((void*)parent)
                   << " (" << (parent? parent->classname() : string("NULL")) << ") "
                   << endl;
    }
    
    m_parent = parent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ParentableObject::updateChildrensParent ( Object parent) [virtual]

Function that actually does the heavy work of traversing the descendants and setting _their_ backpointers to point to the specified parent.

Reimplemented in PLearn::TransparentParentable.

Definition at line 130 of file ParentableObject.cc.

References checkParent(), m_adoptive_parent, PLearn::OptionBase::nonparentable, and setParent().

Referenced by build_(), and PLearn::TransparentParentable::updateChildrensParent().

{
    if (! m_adoptive_parent) {
        // Set the backpointers of sub-objects under the current object to
        // this.  Skip nonparentable options.
        for (ObjectOptionsIterator it(this), end ; it != end  ; ++it)
        {
            if (it.getCurrentOptionFlags() & OptionBase::nonparentable)
                continue;
            
            if (const ParentableObject* cpo = dynamic_cast<const ParentableObject*>(*it)) {
                ParentableObject* po = const_cast<ParentableObject*>(cpo);
                po->setParent(parent);
                if (parent)
                    po->checkParent();
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::Object.

Reimplemented in PLearn::TypedParentableObject< ParentT >, and PLearn::TransparentParentable.

Definition at line 133 of file ParentableObject.h.

If true, don't set the subobjects' parent to this.

Definition at line 149 of file ParentableObject.h.

Referenced by updateChildrensParent().

The kind of parent.

Definition at line 152 of file ParentableObject.h.

Referenced by setParent().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines