2009-05-09 03:08:38 +02:00
|
|
|
/*
|
|
|
|
|
PLACEMENT-REF.hpp - generic reference to an individual placement added to 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 placement-ref.hpp
|
|
|
|
|
**
|
|
|
|
|
** @see Placement
|
|
|
|
|
** @see PlacementRef_test
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-02 03:31:52 +02:00
|
|
|
#ifndef MOBJECT_PLACEMENT_REF_H
|
|
|
|
|
#define MOBJECT_PLACEMENT_REF_H
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
//#include "pre.hpp"
|
|
|
|
|
//#include "proc/mobject/session/locatingpin.hpp"
|
|
|
|
|
//#include "proc/asset/pipe.hpp"
|
2009-06-06 04:23:11 +02:00
|
|
|
#include "proc/mobject/placement.hpp"
|
2009-05-09 03:08:38 +02:00
|
|
|
|
|
|
|
|
//#include <tr1/memory>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace mobject {
|
|
|
|
|
|
|
|
|
|
// using std::tr1::shared_ptr;
|
2009-05-09 17:32:29 +02:00
|
|
|
|
2009-05-09 03:08:38 +02:00
|
|
|
|
2009-06-02 03:31:52 +02:00
|
|
|
class MObject;
|
|
|
|
|
|
2009-06-06 06:18:37 +02:00
|
|
|
// see placement-index.cpp
|
|
|
|
|
Placement<MObject> &
|
|
|
|
|
fetch_PlachementIndex(Placement<MObject>::ID const&) ;
|
|
|
|
|
|
|
|
|
|
|
2009-05-09 03:08:38 +02:00
|
|
|
/**
|
|
|
|
|
*/
|
2009-06-02 03:31:52 +02:00
|
|
|
template<class MO =MObject>
|
2009-05-09 03:08:38 +02:00
|
|
|
class PlacementRef
|
|
|
|
|
{
|
2009-06-06 04:23:11 +02:00
|
|
|
typedef Placement<MO> PlacementMO;
|
|
|
|
|
typedef Placement<MObject>::ID _ID; ////TODO: superfluous...
|
|
|
|
|
typedef Placement<MObject>::Id<MO> _Id;
|
|
|
|
|
|
|
|
|
|
_Id id_;
|
|
|
|
|
|
2009-05-20 03:36:12 +02:00
|
|
|
public:
|
2009-05-09 17:32:29 +02:00
|
|
|
/**
|
2009-06-06 04:23:11 +02:00
|
|
|
* Creating a PlacementRef from a compatible reference source.
|
|
|
|
|
* Any source allowing to infer a \em compatible mobject::Placement
|
|
|
|
|
* is accepted. Here, compatibility is decided based on the run time
|
|
|
|
|
* type of the pointee, in comparison to the template parameter Y.
|
|
|
|
|
* In any case, for this ctor to succeed, the provided ref or ID
|
|
|
|
|
* needs to be resolvable to a placement by the implicit PlacementIndex
|
|
|
|
|
* facility used by all PlacementRef instances (typically the Session).
|
|
|
|
|
* @note there is no default ctor, a reference source is mandatory.
|
|
|
|
|
* @param refID reference resolvable to a placement via Index, especially
|
|
|
|
|
* - an existing Placement
|
|
|
|
|
* - just an Placement::ID
|
|
|
|
|
* - a plain LUID
|
|
|
|
|
* @throw error::Invalid on incompatible run time type of the resolved ID
|
2009-05-09 17:32:29 +02:00
|
|
|
*/
|
2009-06-06 04:23:11 +02:00
|
|
|
template<class Y>
|
|
|
|
|
explicit
|
|
|
|
|
PlacementRef (Y const& refID)
|
|
|
|
|
: id_(recast (refID))
|
|
|
|
|
{
|
|
|
|
|
validate(id_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlacementRef (PlacementRef const& r) ///< copy ctor
|
|
|
|
|
: id_(r.id_)
|
|
|
|
|
{
|
|
|
|
|
validate(id_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class X>
|
|
|
|
|
PlacementRef (PlacementRef<X> const& r) ///< extended copy ctor, when type X is assignable to MO
|
|
|
|
|
: id_(r.id_)
|
|
|
|
|
{
|
|
|
|
|
validate(id_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PlacementRef&
|
|
|
|
|
operator= (PlacementRef const& r)
|
|
|
|
|
{
|
|
|
|
|
validate(r.id_);
|
|
|
|
|
id_ = r.id_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class X>
|
|
|
|
|
PlacementRef&
|
|
|
|
|
operator= (PlacementRef<X> const& r)
|
|
|
|
|
{
|
|
|
|
|
validate(r.id_);
|
|
|
|
|
id_ = r.id_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Y>
|
|
|
|
|
PlacementRef&
|
|
|
|
|
operator= (Y const& refID)
|
|
|
|
|
{
|
|
|
|
|
validate (recast (refID));
|
|
|
|
|
id_ = recast (refID);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* == forwarding smart-ptr operations == */
|
|
|
|
|
|
|
|
|
|
PlacementMO& operator*() const { return access(id_); } ///< dereferencing fetches referred Placement from Index
|
|
|
|
|
|
|
|
|
|
MO* operator->() const { return access(id_); } ///< provide access to pointee API by smart-ptr chaining
|
|
|
|
|
|
|
|
|
|
operator string() const { return access(id_).operator string(); }
|
|
|
|
|
size_t use_count() const { return access(id_).use_count(); }
|
|
|
|
|
|
|
|
|
|
////////////////TODO more operations to come....
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static void
|
|
|
|
|
validate (_Id rId)
|
|
|
|
|
{
|
|
|
|
|
if (!access(rId).isCompatible<MO>())
|
|
|
|
|
throw error::Invalid(LUMIERA_ERROR_INVALID_PLACEMENTREF);
|
|
|
|
|
}
|
2009-05-13 03:46:08 +02:00
|
|
|
|
2009-06-06 04:23:11 +02:00
|
|
|
static _Id const&
|
|
|
|
|
recast (_ID const& someID)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<_Id const&> (someID);
|
|
|
|
|
}
|
2009-05-09 17:32:29 +02:00
|
|
|
|
2009-06-06 04:23:11 +02:00
|
|
|
static _Id const&
|
|
|
|
|
recast (const LumieraUid luid)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (luid);
|
|
|
|
|
return reinterpret_cast<_Id const&> (*luid);
|
|
|
|
|
}
|
2009-06-06 06:18:37 +02:00
|
|
|
|
|
|
|
|
static PlacementMO&
|
|
|
|
|
access (_Id placementID)
|
|
|
|
|
{
|
|
|
|
|
Placement<MObject> & pla (fetch_PlachementIndex (placementID)); // may throw
|
|
|
|
|
REQUIRE (pla);
|
|
|
|
|
ASSERT (pla.isCompatible<MO>());
|
|
|
|
|
return static_cast<PlacementMO&> (pla);
|
|
|
|
|
}
|
2009-05-09 03:08:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mobject
|
|
|
|
|
#endif
|