From cc66f2b0d095e4f4b528e73cf576493cb7837b6e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 20 May 2009 03:36:12 +0200 Subject: [PATCH] preliminary placement index impl started. Basically I need this simple framework to be able to write tests, which enables me to flesh out the API, which in turn is a prerequisite for defining the PlacementRef --- src/proc/Makefile.am | 1 + src/proc/asset/media.hpp | 3 +- src/proc/mobject/placement-index.cpp | 81 +++++++++++++++++++ src/proc/mobject/placement-index.hpp | 73 ++++++++++------- src/proc/mobject/placement-ref.hpp | 1 + .../proc/mobject/placement-index-test.cpp | 33 +++++++- 6 files changed, 157 insertions(+), 35 deletions(-) create mode 100644 src/proc/mobject/placement-index.cpp diff --git a/src/proc/Makefile.am b/src/proc/Makefile.am index a79f07183..45de208b0 100644 --- a/src/proc/Makefile.am +++ b/src/proc/Makefile.am @@ -93,6 +93,7 @@ liblumiprocmobject_la_SOURCES = \ $(liblumiprocmobject_la_srcdir)/mobject.cpp \ $(liblumiprocmobject_la_srcdir)/parameter.cpp \ $(liblumiprocmobject_la_srcdir)/paramprovider.cpp \ + $(liblumiprocmobject_la_srcdir)/placement-index.cpp \ $(liblumiprocmobject_la_srcdir)/placement.cpp diff --git a/src/proc/asset/media.hpp b/src/proc/asset/media.hpp index b73a619e9..0cff14f7c 100644 --- a/src/proc/asset/media.hpp +++ b/src/proc/asset/media.hpp @@ -44,8 +44,7 @@ -namespace asset - { +namespace asset { class Clip; class Media; diff --git a/src/proc/mobject/placement-index.cpp b/src/proc/mobject/placement-index.cpp new file mode 100644 index 000000000..03eaba0ba --- /dev/null +++ b/src/proc/mobject/placement-index.cpp @@ -0,0 +1,81 @@ +/* + PlacementIndex - tracking individual Placements and their relations + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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-index.cpp + ** + ** simple hash based implementation. Proof-of-concept + ** and for fleshing out the API + ** + ** @todo change PlacementIndex into an interface and create a separated implementation class + ** @see PlacementRef + ** @see PlacementIndex_test + ** + */ + + +#include "proc/mobject/placement-index.hpp" + +//#include +//using boost::str; + +namespace mobject { + + + class PlacementIndex::Table + { + public: + Table () + { } + + size_t + size() const + { + UNIMPLEMENTED ("PlacementIndex datastructure"); + return 0; + } + + }; + + + /** */ + + + size_t + PlacementIndex::size() const + { + return pTab_->size() - 1; + } + + + + /** @internal factory function for creating a placement index for tests. + */ + shared_ptr + createPlacementIndex () + { + return shared_ptr (new PlacementIndex()); + } + + + +} // namespace mobject diff --git a/src/proc/mobject/placement-index.hpp b/src/proc/mobject/placement-index.hpp index f33f482d0..c5d401358 100644 --- a/src/proc/mobject/placement-index.hpp +++ b/src/proc/mobject/placement-index.hpp @@ -36,15 +36,18 @@ //#include "pre.hpp" //#include "proc/mobject/session/locatingpin.hpp" //#include "proc/asset/pipe.hpp" +#include "proc/mobject/placement.hpp" #include "proc/mobject/placement-ref.hpp" -//#include +#include +#include #include namespace mobject { -// using std::tr1::shared_ptr; + using std::tr1::shared_ptr; + using boost::scoped_ptr; using std::vector; @@ -53,37 +56,49 @@ namespace mobject { */ class PlacementIndex { - public: - typedef Placement PlacementMO; - typedef PlacementRef PRef; - typedef PRef::ID ID; - - PlacementMO& find (ID) const; - - template - Placement& find (PRef::IDp) const; - - PlacementMO& getScope (PlacementMO&) const; - PlacementMO& getScope (ID) const; - - vector getReferrers (ID) const; - - - /** diagnostic: number of indexed entries */ - size_t size() const; - - - /* == mutating operations == */ - - ID insert (PlacementMO& newObj, PlacementMO& targetScope); - bool remove (PlacementMO&); - bool remove (ID); + class Table; + + scoped_ptr pTab_; + + public: + typedef Placement PlacementMO; + typedef PlacementRef PRef; + typedef PRef::ID ID; + + PlacementMO& find (ID) const; + + template + Placement& find (PRef::IDp) const; + + PlacementMO& getScope (PlacementMO&) const; + PlacementMO& getScope (ID) const; + + vector getReferrers (ID) const; + + + /** retrieve the logical root scope */ + PlacementMO& getRoot() const; + + /** diagnostic: number of indexed entries */ + size_t size() const; + bool contains (PlacementMO&) const; + + + /* == mutating operations == */ + + ID insert (PlacementMO& newObj, PlacementMO& targetScope); + bool remove (PlacementMO&); + bool remove (ID); }; - ////////////////TODO currently just fleshing out the API; probably have to split off an impl.class - + ////////////////TODO currently just fleshing out the API; probably have to split off an impl.class; but for now a PImpl is sufficient... + /** preliminary helper for creating a placement index (instance). + * @todo integrate this into the session and provide an extra factory for tests + */ + shared_ptr + createPlacementIndex() ; } // namespace mobject diff --git a/src/proc/mobject/placement-ref.hpp b/src/proc/mobject/placement-ref.hpp index ea86f1beb..eb94005bd 100644 --- a/src/proc/mobject/placement-ref.hpp +++ b/src/proc/mobject/placement-ref.hpp @@ -50,6 +50,7 @@ namespace mobject { */ class PlacementRef { + public: /** * */ diff --git a/tests/components/proc/mobject/placement-index-test.cpp b/tests/components/proc/mobject/placement-index-test.cpp index efd345ae9..5664a7e6f 100644 --- a/tests/components/proc/mobject/placement-index-test.cpp +++ b/tests/components/proc/mobject/placement-index-test.cpp @@ -25,8 +25,9 @@ //#include "proc/asset/media.hpp" //#include "proc/mobject/session.hpp" //#include "proc/mobject/session/edl.hpp" -//#include "proc/mobject/session/testclip.hpp" +#include "proc/mobject/session/testclip.hpp" #include "proc/mobject/placement.hpp" +#include "proc/mobject/placement-index.hpp" //#include "proc/mobject/explicitplacement.hpp" //#include "lib/util.hpp" @@ -41,10 +42,10 @@ using std::string; namespace mobject { -namespace session { namespace test { using asset::VIDEO; + using session::test::TestClip; @@ -58,12 +59,36 @@ namespace test { */ class PlacementIndex_test : public Test { + typedef shared_ptr PIdx; virtual void run (Arg) { + PIdx index (createPlacementIndex()); + ASSERT (index); + /////////////////////////////////TODO - } + checkSimpleInsert (index); + } + + void + checkSimpleInsert (PIdx index) + { + PMO clip = TestClip::create(); +// PMO& root = index->getRoot(); + + ASSERT (0 == index->size()); +// ASSERT (!index->contains (clip)); + +// index->insert (clip, root); + ASSERT (1 == index->size()); +// ASSERT ( index->contains (clip)); + +// index->remove(clip); + ASSERT (0 == index->size()); +// ASSERT (!index->contains (clip)); +// ASSERT ( index->contains (root)); + } }; @@ -71,4 +96,4 @@ namespace test { LAUNCHER (PlacementIndex_test, "unit session"); -}}} // namespace mobject::session::test +}} // namespace mobject::test