2009-06-02 03:31:52 +02:00
|
|
|
/*
|
|
|
|
|
MOBJECT-REF.hpp - active external reference to an MObject within the Session
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file mobject-ref.hpp
|
2010-01-12 00:44:47 +01:00
|
|
|
** A reference handle pointing at an MObject, attached (placed) to the session.
|
|
|
|
|
** Allows client code to access both the object and the placement, even from a
|
|
|
|
|
** separate Layer or from within plugin code.
|
|
|
|
|
**
|
2009-06-02 03:31:52 +02:00
|
|
|
** @see MObject
|
|
|
|
|
** @see Session
|
|
|
|
|
** @see PlacementRef
|
|
|
|
|
** @see PlacementIndex
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MOBJECT_MOBJECT_REF_H
|
|
|
|
|
#define MOBJECT_MOBJECT_REF_H
|
|
|
|
|
|
|
|
|
|
//#include "pre.hpp"
|
|
|
|
|
//#include "proc/mobject/session/locatingpin.hpp"
|
|
|
|
|
//#include "proc/asset/pipe.hpp"
|
|
|
|
|
#include "lib/handle.hpp"
|
|
|
|
|
#include "proc/mobject/placement.hpp"
|
|
|
|
|
#include "proc/mobject/placement-ref.hpp"
|
|
|
|
|
|
|
|
|
|
//#include <tr1/memory>
|
|
|
|
|
|
2009-06-07 00:45:55 +02:00
|
|
|
///////////////////////////////////////////TODO: define an C-API representation here, make the header multilingual!
|
2009-06-02 03:31:52 +02:00
|
|
|
|
|
|
|
|
namespace mobject {
|
|
|
|
|
|
|
|
|
|
// using std::tr1::shared_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An active (smart-ptr like) external reference
|
|
|
|
|
* to a specifically placed MObject "instance" within the session.
|
2010-01-12 00:44:47 +01:00
|
|
|
* Implemented as a smart-ptr sharing ownership of the pointee MObject
|
|
|
|
|
* with the corresponding placement within the session. Additionally,
|
|
|
|
|
* a PlacementRef is incorporated, allowing to re-access this placement
|
|
|
|
|
* with the help of PlacementIndex within the current session.
|
2009-06-02 03:31:52 +02:00
|
|
|
*/
|
|
|
|
|
template<class MO =MObject>
|
|
|
|
|
class MORef
|
|
|
|
|
: public lib::Handle<MO>
|
|
|
|
|
{
|
2009-06-09 09:05:19 +02:00
|
|
|
typedef lib::Handle<MO> _Par;
|
2009-06-02 03:31:52 +02:00
|
|
|
|
2009-06-09 09:05:19 +02:00
|
|
|
PlacementRef<MO> pRef_; ////////////////////////////////////////////////////////////////////TODO: how to create an "inactive" PlacementRef???
|
|
|
|
|
|
|
|
|
|
using _Par::smPtr_;
|
2009-06-02 03:31:52 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
MO*
|
|
|
|
|
operator-> () const
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (smPtr_.get(), "Lifecycle-Error");
|
|
|
|
|
ENSURE (INSTANCEOF (MO, smPtr_.get()));
|
2009-06-09 09:05:19 +02:00
|
|
|
return smPtr_.operator-> ();
|
2009-06-02 03:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Placement<MO>& getPlacement();
|
|
|
|
|
|
2009-06-06 04:04:33 +02:00
|
|
|
|
2009-06-02 03:31:52 +02:00
|
|
|
/* === Lifecycle === */
|
|
|
|
|
|
|
|
|
|
/** activate an MObject reference, based on an existing placement,
|
|
|
|
|
* which needs to be contained (added to) the session. After checking
|
2009-06-06 04:04:33 +02:00
|
|
|
* the validity of the placement, this MObjectRef shares ownership
|
2009-06-02 03:31:52 +02:00
|
|
|
* of the referred MObject with the denoted placement.
|
2009-06-06 04:04:33 +02:00
|
|
|
* @note STRONG exception safety guarantee
|
2009-06-02 03:31:52 +02:00
|
|
|
* @see #close() for detaching this MObjectRef
|
|
|
|
|
*/
|
|
|
|
|
MORef&
|
|
|
|
|
activate (Placement<MO> const& placement)
|
|
|
|
|
{
|
2009-06-06 04:04:33 +02:00
|
|
|
ASSERT (placement);
|
|
|
|
|
pRef_ = placement; // STRONG exception safe
|
|
|
|
|
smPtr_.swap (placement); // never throws
|
2009-06-02 03:31:52 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** build and activate an MObject reference, based on anything
|
|
|
|
|
* which might be assigned to an PlarementRef<MO> :
|
|
|
|
|
* - any Placement
|
|
|
|
|
* - any Placement-ID
|
|
|
|
|
* - any Placement-Ref
|
|
|
|
|
* - a plain LUID
|
|
|
|
|
* @throws error::Invalid when the (directly or indirectly
|
|
|
|
|
* referred placement isn't known to the session PlacementIndex,
|
|
|
|
|
* or when the placement actually found has an incompatible dynamic type
|
|
|
|
|
*/
|
|
|
|
|
template<typename REF>
|
|
|
|
|
MORef&
|
|
|
|
|
activate (REF const& pRefID)
|
|
|
|
|
{
|
2009-06-06 04:04:33 +02:00
|
|
|
if (pRefID != pRef_)
|
|
|
|
|
{
|
|
|
|
|
PlacementRef<MO> newRef (pRefID);
|
|
|
|
|
ASSERT (newRef);
|
|
|
|
|
return activate (*newRef); // STRONG exception safe
|
|
|
|
|
}
|
|
|
|
|
else return *this;
|
2009-06-02 03:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-08 03:59:01 +01:00
|
|
|
|
2010-01-12 01:48:55 +01:00
|
|
|
/* == diagnostics == */
|
|
|
|
|
size_t
|
|
|
|
|
use_count() const
|
|
|
|
|
{
|
|
|
|
|
return pRef_.use_count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-08 03:59:01 +01:00
|
|
|
/* == equality comparisons == */
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
|
|
|
|
bool
|
2010-01-13 03:29:57 +01:00
|
|
|
operator== (MORef<MOX> const& oRef) const
|
2010-01-08 03:59:01 +01:00
|
|
|
{
|
2010-01-13 03:29:57 +01:00
|
|
|
return oRef == this->pRef_;
|
2010-01-08 03:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
|
|
|
|
bool
|
2010-01-13 03:29:57 +01:00
|
|
|
operator!= (MORef<MOX> const& oRef) const
|
2010-01-08 03:59:01 +01:00
|
|
|
{
|
2010-01-13 03:29:57 +01:00
|
|
|
return oRef != this->pRef_;
|
2010-01-08 03:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
2010-01-13 03:29:57 +01:00
|
|
|
friend bool
|
|
|
|
|
operator== (MORef const& oRef, PlacementRef<MOX> const& pRef)
|
|
|
|
|
{
|
|
|
|
|
return oRef.pRef_ == pRef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
|
|
|
|
friend bool
|
|
|
|
|
operator!= (MORef const& oRef, PlacementRef<MOX> const& pRef)
|
|
|
|
|
{
|
|
|
|
|
return oRef.pRef_ != pRef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
|
|
|
|
friend bool
|
|
|
|
|
operator== (PlacementRef<MOX> const& pRef, MORef const& oRef)
|
|
|
|
|
{
|
|
|
|
|
return pRef == oRef.pRef_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class MOX>
|
|
|
|
|
friend bool
|
|
|
|
|
operator!= (PlacementRef<MOX> const& pRef, MORef const& oRef)
|
|
|
|
|
{
|
|
|
|
|
return pRef != oRef.pRef_;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 03:59:01 +01:00
|
|
|
bool
|
2010-01-13 03:29:57 +01:00
|
|
|
operator== (PlacementMO::ID const& pID) const
|
2010-01-08 03:59:01 +01:00
|
|
|
{
|
2010-01-13 03:29:57 +01:00
|
|
|
return PlacementMO::ID (pRef_) == pID;
|
2010-01-08 03:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2010-01-13 03:29:57 +01:00
|
|
|
operator!= (PlacementMO::ID const& pID) const
|
2010-01-08 03:59:01 +01:00
|
|
|
{
|
2010-01-13 03:29:57 +01:00
|
|
|
return PlacementMO::ID (pRef_) != pID;
|
2010-01-08 03:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-02 03:31:52 +02:00
|
|
|
};
|
|
|
|
|
////////////////TODO currently just fleshing out the API....
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef MORef<MObject> MObjectRef;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mobject
|
|
|
|
|
#endif
|