From fa31f3736e33f0c590f72ce66ef93645fdc896c6 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 6 Jun 2009 04:23:11 +0200 Subject: [PATCH] WIP some details regarding PlacementRef --- src/proc/mobject/placement-index.hpp | 7 +- src/proc/mobject/placement-ref.hpp | 99 +++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/proc/mobject/placement-index.hpp b/src/proc/mobject/placement-index.hpp index 9afccdcf4..8e26f598b 100644 --- a/src/proc/mobject/placement-index.hpp +++ b/src/proc/mobject/placement-index.hpp @@ -80,11 +80,12 @@ namespace mobject { /** retrieve the logical root scope */ - PlacementMO& getRoot() const; + PlacementMO& getRoot() const; /** diagnostic: number of indexed entries */ - size_t size() const; - bool contains (PlacementMO&) const; + size_t size() const; + bool contains (PlacementMO const&) const; + bool contains (ID const&) const; /* == mutating operations == */ diff --git a/src/proc/mobject/placement-ref.hpp b/src/proc/mobject/placement-ref.hpp index 5f5e8baf5..a667d2882 100644 --- a/src/proc/mobject/placement-ref.hpp +++ b/src/proc/mobject/placement-ref.hpp @@ -36,6 +36,7 @@ //#include "pre.hpp" //#include "proc/mobject/session/locatingpin.hpp" //#include "proc/asset/pipe.hpp" +#include "proc/mobject/placement.hpp" //#include @@ -52,12 +53,108 @@ namespace mobject { template class PlacementRef { + typedef Placement PlacementMO; + typedef Placement::ID _ID; ////TODO: superfluous... + typedef Placement::Id _Id; + + _Id id_; + public: /** - * + * 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 */ + template + explicit + PlacementRef (Y const& refID) + : id_(recast (refID)) + { + validate(id_); + } + + PlacementRef (PlacementRef const& r) ///< copy ctor + : id_(r.id_) + { + validate(id_); + } + + template + PlacementRef (PlacementRef 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 + PlacementRef& + operator= (PlacementRef const& r) + { + validate(r.id_); + id_ = r.id_; + return *this; + } + + template + 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()) + throw error::Invalid(LUMIERA_ERROR_INVALID_PLACEMENTREF); + } + + static _Id const& + recast (_ID const& someID) + { + return static_cast<_Id const&> (someID); + } + + static _Id const& + recast (const LumieraUid luid) + { + REQUIRE (luid); + return reinterpret_cast<_Id const&> (*luid); + } };