Index: objects/object_calcer.h =================================================================== --- objects/object_calcer.h +++ objects/object_calcer.h @@ -78,12 +78,14 @@ void ref(); void deref(); + std::vector mparents; + // we keep track of our children, so algorithms can easily walk over // the dependency graph.. - std::vector mchildren; ObjectCalcer(); + ObjectCalcer( const std::vector& parents ); public: /** * a calcer should call this to register itself as a child of this @@ -103,13 +105,13 @@ /** * Returns the child ObjectCalcer's of this ObjectCalcer. */ - std::vector children() const; + const std::vector& children() const; virtual ~ObjectCalcer(); /** * Returns the parent ObjectCalcer's of this ObjectCalcer. */ - virtual std::vector parents() const = 0; + const virtual std::vector& parents() const; /** * Returns the ObjectImp of this ObjectCalcer. */ @@ -183,7 +185,6 @@ class ObjectTypeCalcer : public ObjectCalcer { - std::vector mparents; const ObjectType* mtype; ObjectImp* mimp; public: @@ -200,7 +201,6 @@ ~ObjectTypeCalcer(); const ObjectImp* imp() const Q_DECL_OVERRIDE; - std::vector parents() const Q_DECL_OVERRIDE; void calc( const KigDocument& doc ) Q_DECL_OVERRIDE; /** @@ -249,7 +249,6 @@ const ObjectImp* imp() const Q_DECL_OVERRIDE; void calc( const KigDocument& doc ) Q_DECL_OVERRIDE; - std::vector parents() const Q_DECL_OVERRIDE; /** * Set the ObjectImp of this ObjectConstCalcer to the given @@ -277,7 +276,6 @@ : public ObjectCalcer { ObjectImp* mimp; - ObjectCalcer* mparent; int mpropgid; /* * The following two variables are used for a caching @@ -305,7 +303,6 @@ ~ObjectPropertyCalcer(); const ObjectImp* imp() const Q_DECL_OVERRIDE; - std::vector parents() const Q_DECL_OVERRIDE; void calc( const KigDocument& doc ) Q_DECL_OVERRIDE; ObjectCalcer* parent() const; Index: objects/object_calcer.cc =================================================================== --- objects/object_calcer.cc +++ objects/object_calcer.cc @@ -42,8 +42,13 @@ ObjectTypeCalcer::ObjectTypeCalcer( const ObjectType* type, const std::vector& parents, bool sort ) - : mparents( ( sort )?type->sortArgs( parents ):parents ), mtype( type ), mimp( 0 ) + : ObjectCalcer( parents ), mtype( type ), mimp( 0 ) { + if ( sort ) + { + mparents = type->sortArgs( mparents ); + } + std::for_each( mparents.begin(), mparents.end(), std::bind2nd( std::mem_fun( &ObjectCalcer::addChild ), this ) ); } @@ -71,12 +76,6 @@ { } -std::vector ObjectConstCalcer::parents() const -{ - // we have no parents.. - return std::vector(); -} - void ObjectCalcer::ref() { ++refcount; @@ -102,11 +101,6 @@ return mimp; } -std::vector ObjectTypeCalcer::parents() const -{ - return mparents; -} - void ObjectCalcer::addChild( ObjectCalcer* c ) { mchildren.push_back( c ); @@ -135,16 +129,17 @@ } ObjectPropertyCalcer::ObjectPropertyCalcer( ObjectCalcer* parent, const char* pname ) - : mimp( 0 ), mparent( parent ), mparenttype( 0 ) + : mimp( 0 ), mparenttype( 0 ) { - mparent->addChild( this ); - mpropgid = mparent->imp()->getPropGid( pname ); + mparents.push_back( parent ); + mparents.front()->addChild( this ); + mpropgid = mparents.front()->imp()->getPropGid( pname ); } ObjectPropertyCalcer::ObjectPropertyCalcer( ObjectCalcer* parent, int propid, bool islocal ) - : mimp( 0 ), mparent( parent ), mparenttype( 0 ) + : mimp( 0 ), mparenttype( 0 ) { - mparent->addChild( this ); + mparents.front()->addChild( this ); if ( islocal ) { mpropgid = parent->imp()->getPropGid( parent->imp()->propertiesInternalNames()[propid] ); @@ -155,36 +150,30 @@ ObjectPropertyCalcer::~ObjectPropertyCalcer() { - mparent->delChild( this ); + mparents.front()->delChild( this ); delete mimp; } const ObjectImp* ObjectPropertyCalcer::imp() const { return mimp; } -std::vector ObjectPropertyCalcer::parents() const -{ - std::vector ret; - ret.push_back( mparent ); - return ret; -} - void ObjectPropertyCalcer::calc( const KigDocument& doc ) { + const ObjectCalcer* sole_parent = mparents.front(); //if ( mparenttype != mparent->imp()->type() ) - if ( mparenttype == 0 || *mparenttype != typeid( *(mparent->imp()) ) ) + if ( mparenttype == 0 || *mparenttype != typeid( *( sole_parent->imp() ) ) ) { - mpropid = mparent->imp()->getPropLid( mpropgid ); + mpropid = sole_parent->imp()->getPropLid( mpropgid ); // mparenttype = mparent->imp()->type(); - mparenttype = &typeid( *(mparent->imp()) ); + mparenttype = &typeid( *( sole_parent->imp() ) ); // printf ("changing type, new type: %s\n", mparenttype->internalName()); } ObjectImp* n; if ( mpropid >= 0 ) { - n = mparent->imp()->property( mpropid, doc ); + n = sole_parent->imp()->property( mpropid, doc ); } else n = new InvalidImp; delete mimp; mimp = n; @@ -197,16 +186,21 @@ return ret; } -std::vector ObjectCalcer::children() const +const std::vector& ObjectCalcer::children() const { return mchildren; } +const std::vector& ObjectCalcer::parents() const +{ + return mparents; +} + const ObjectImpType* ObjectPropertyCalcer::impRequirement( ObjectCalcer*, const std::vector& ) const { - int proplid = mparent->imp()->getPropLid( mpropgid ); - return mparent->imp()->impRequirementForProperty( proplid ); + int proplid = mparents.front()->imp()->getPropLid( mpropgid ); + return mparents.front()->imp()->impRequirementForProperty( proplid ); } const ObjectImpType* ObjectConstCalcer::impRequirement( @@ -296,11 +290,16 @@ ObjectCalcer* ObjectPropertyCalcer::parent() const { - return mparent; + return mparents.front(); } ObjectCalcer::ObjectCalcer() - : refcount( 0 ) + : refcount( 0 ), mparents( 0 ) +{ +} + +ObjectCalcer::ObjectCalcer( const std::vector& parents ) + : refcount( 0 ), mparents( parents ) { } @@ -321,9 +320,9 @@ bool ObjectPropertyCalcer::isDefinedOnOrThrough( const ObjectCalcer* o ) const { - return o == mparent && - mparent->imp()->isPropertyDefinedOnOrThroughThisImp( - mparent->imp()->getPropLid( mpropgid ) ); + return o == mparents.front() && + mparents.front()->imp()->isPropertyDefinedOnOrThroughThisImp( + mparents.front()->imp()->getPropLid( mpropgid ) ); } bool ObjectTypeCalcer::isDefinedOnOrThrough( const ObjectCalcer* o ) const @@ -342,7 +341,7 @@ int ObjectPropertyCalcer::propLid() const { - return mparent->imp()->getPropLid( mpropgid ); + return mparents.front()->imp()->getPropLid( mpropgid ); } int ObjectPropertyCalcer::propGid() const