From 71428ccf6f010b80d5a17f053d5b456e31389c19 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 13 Jan 2010 04:38:12 +0100 Subject: [PATCH] activating an MObject ref implemented, passes compiler --- src/proc/mobject/mobject-ref.hpp | 42 +++++++++++++++---- src/proc/mobject/placement.hpp | 12 ++++++ .../proc/mobject/mobject-ref-test.cpp | 18 +------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/proc/mobject/mobject-ref.hpp b/src/proc/mobject/mobject-ref.hpp index 0dd45ef6f..17bb483b6 100644 --- a/src/proc/mobject/mobject-ref.hpp +++ b/src/proc/mobject/mobject-ref.hpp @@ -80,12 +80,17 @@ namespace mobject { MO* operator-> () const { - REQUIRE (smPtr_.get(), "Lifecycle-Error"); + REQUIRE (pRef_ && smPtr_, "Lifecycle-Error: not activated"); ENSURE (INSTANCEOF (MO, smPtr_.get())); return smPtr_.operator-> (); } - Placement& getPlacement(); + Placement& getPlacement() const + { + REQUIRE (pRef_ && smPtr_, "Lifecycle-Error: not activated"); + ENSURE (INSTANCEOF (MO, smPtr_.get())); + return *pRef_; + } /* === Lifecycle === */ @@ -100,9 +105,9 @@ namespace mobject { MORef& activate (Placement const& placement) { - ASSERT (placement); - pRef_ = placement; // STRONG exception safe - smPtr_.swap (placement); // never throws + ASSERT (placement.isValid()); + pRef_ = placement; // STRONG exception safe + placement.extendOwnershipTo(smPtr_); // never throws return *this; } @@ -120,15 +125,36 @@ namespace mobject { MORef& activate (REF const& pRefID) { - if (pRefID != pRef_) + PlacementRef newRef (pRefID); + if (newRef.isValid() + && pRef_ != newRef ) { - PlacementRef newRef (pRefID); - ASSERT (newRef); return activate (*newRef); // STRONG exception safe } else return *this; } + /** build and activate an MObject reference based on + * an existing reference of the same pointee type + * @note STRONG exception safety guarantee + * @throws error::Invalid when the referred placement + * isn't known to the current session's PlacementIndex + */ + MORef& + activate (MORef const& oRef) + { + return activate (oRef.getPlacement()); + } + + template + MORef& + activate (MORef const& oRef) + { + return activate (oRef.getPlacement().getID()); + } + + + /* == diagnostics == */ size_t diff --git a/src/proc/mobject/placement.hpp b/src/proc/mobject/placement.hpp index 1ebb966ac..878b2d08a 100644 --- a/src/proc/mobject/placement.hpp +++ b/src/proc/mobject/placement.hpp @@ -84,6 +84,7 @@ namespace mobject { class ExplicitPlacement; using std::tr1::shared_ptr; + using std::tr1::static_pointer_cast; using lib::HashIndexed; @@ -149,6 +150,17 @@ namespace mobject { return 0 != dynamic_cast (get()); } + /** extend shared ownership to the given smart-ptr + * @note never throws + */ + template + void + extendOwnershipTo (shared_ptr& target) const + { + REQUIRE (isCompatible()); + target = static_pointer_cast(*this); + } + operator string() const ; size_t use_count() const { return _SmartPtr::use_count(); } diff --git a/tests/components/proc/mobject/mobject-ref-test.cpp b/tests/components/proc/mobject/mobject-ref-test.cpp index 1f0587a80..4c19041f7 100644 --- a/tests/components/proc/mobject/mobject-ref-test.cpp +++ b/tests/components/proc/mobject/mobject-ref-test.cpp @@ -199,10 +199,8 @@ namespace test { MORef rM; MORef rC; -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rM.activate (p1); rC.activate (p2); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (rM && rC); ASSERT (!(rM == rC) && !(rC == rM)); ASSERT ( (rM != rC) && (rC != rM)); @@ -227,9 +225,7 @@ namespace test { ASSERT (!(rC == p1.getID()) ); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! - rC.activate (p1); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! + rC.activate (pRef1); ASSERT ( (rM == rC) && (rC == rM)); ASSERT (!(rM != rC) && !(rC != rM)); @@ -271,27 +267,21 @@ namespace test { ASSERT (!rMO); ASSERT (0 == rMO.use_count()); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rMO.activate(p1); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (rMO); ASSERT (rMO->getMedia()->getFilename() == "test-1"); ASSERT (3 == rMO.use_count()); ASSERT (3 == p1.use_count()); ASSERT (2 == p2.use_count()); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rMO.activate(p2); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (rMO); ASSERT (rMO->getMedia()->getFilename() == "test-2"); ASSERT (3 == rMO.use_count()); ASSERT (2 == p1.use_count()); ASSERT (3 == p2.use_count()); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rMO.activate(p2); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (3 == rMO.use_count()); rMO.close(); @@ -314,23 +304,19 @@ namespace test { ASSERT (0 == rClip.use_count()); ASSERT (0 == rSub1.use_count()); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rMObj.activate(luid); -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (3 == rMObj.use_count()); ASSERT (0 == rClip.use_count()); ASSERT (0 == rSub1.use_count()); -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! rClip.activate(rMObj); // attach on existing MObjectRef -#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! ASSERT (4 == rMObj.use_count()); ASSERT (4 == rClip.use_count()); ASSERT (0 == rSub1.use_count()); // impossible, because Clip isn't a subclass of TestSubMO1: -#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! VERIFY_ERROR (INVALID_PLACEMENTREF, rSub1.activate(luid) ); +#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!! // VERIFY_ERROR (INVALID_PLACEMENTREF, rSub1 = rMObj ); #endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!!