activating an MObject ref implemented, passes compiler

This commit is contained in:
Fischlurch 2010-01-13 04:38:12 +01:00
parent e9d641babd
commit 71428ccf6f
3 changed files with 48 additions and 24 deletions

View file

@ -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<MO>& getPlacement();
Placement<MO>& 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<MO> 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<MO> newRef (pRefID);
if (newRef.isValid()
&& pRef_ != newRef )
{
PlacementRef<MO> 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<typename MOX>
MORef&
activate (MORef<MOX> const& oRef)
{
return activate (oRef.getPlacement().getID());
}
/* == diagnostics == */
size_t

View file

@ -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<Y*> (get());
}
/** extend shared ownership to the given smart-ptr
* @note never throws
*/
template<class Y>
void
extendOwnershipTo (shared_ptr<Y>& target) const
{
REQUIRE (isCompatible<Y>());
target = static_pointer_cast<Y>(*this);
}
operator string() const ;
size_t use_count() const { return _SmartPtr::use_count(); }

View file

@ -199,10 +199,8 @@ namespace test {
MORef<MObject> rM;
MORef<Clip> 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.....!!!!!