From c7794e7cbfe86b1db1a0a283ddffcec51c72cc49 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 28 Nov 2010 02:16:39 +0100 Subject: [PATCH] rewrite to retrieve default-pipe query from the defintion context --- src/proc/mobject/output-mapping.hpp | 70 +++++++++++-------- .../proc/mobject/output-mapping-test.cpp | 6 ++ 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/proc/mobject/output-mapping.hpp b/src/proc/mobject/output-mapping.hpp index 871698e36..642a04664 100644 --- a/src/proc/mobject/output-mapping.hpp +++ b/src/proc/mobject/output-mapping.hpp @@ -120,6 +120,8 @@ namespace mobject { * - a functor \c DEF::output usable as function pipe-ID --> Target * - the concrete output-functor also defines the concrete Target type, * which will be returned when accessing the OutputMapping + * - a function \c DEF::buildQuery(sourcePipeID) yielding a defaults querry, + * to be issued in case of accessing a non existant mapping */ template class OutputMapping @@ -245,25 +247,9 @@ namespace mobject { /* === Map-style access for clients === */ - Resolver - operator[] (PId sourcePipeID) - { - if (!contains (table_, sourcePipeID)) - { - UNIMPLEMENTED ("how to resolve"); - } - return buildResolutionWrapper (sourcePipeID); - } - - Resolver - operator[] (PPipe const& pipe) - { - REQUIRE (pipe); - return (*this) [pipe->getID()]; - } - - Resolver - operator[] (Query const& query4pipe); + Resolver operator[] (PId sourcePipeID); + Resolver operator[] (PPipe const& pipe); + Resolver operator[] (Query const& query4pipe); @@ -283,6 +269,10 @@ namespace mobject { }; + + + /* ===== Implementation details ===== */ + namespace _mapping { /** yield a suitable table slot for this query */ @@ -293,6 +283,28 @@ namespace mobject { } + template + inline typename OutputMapping::Resolver + OutputMapping::operator[] (PId sourcePipeID) + { + if (!contains (table_, sourcePipeID)) + { + // issue a defaults query to resolve this mapping first + Query query4pipe = DEF::buildQuery (sourcePipeID); + table_[sourcePipeID] = _mapping::resolveQuery (query4pipe); + } + return buildResolutionWrapper (sourcePipeID); + } + + + template + inline typename OutputMapping::Resolver + OutputMapping::operator[] (PPipe const& pipe) + { + REQUIRE (pipe); + return (*this) [pipe->getID()]; + } + /** determine an OutputMapping by resolving a complex query, * instead of just picking a mapped pipe (which is the default usage). @@ -312,17 +324,17 @@ namespace mobject { * if in doubt. */ template - typename OutputMapping::Resolver + inline typename OutputMapping::Resolver OutputMapping::operator[] (Query const& query4pipe) - { - HashVal hash4query = _mapping::slot (query4pipe); - if (!contains (table_, hash4query)) - // need to resolve this query first - table_[hash4query] = _mapping::resolveQuery (query4pipe); - - ENSURE (contains (table_, hash4query)); - return buildResolutionWrapper (hash4query); - } + { + HashVal hash4query = _mapping::slot (query4pipe); + if (!contains (table_, hash4query)) + // need to resolve this query first + table_[hash4query] = _mapping::resolveQuery (query4pipe); + + ENSURE (contains (table_, hash4query)); + return buildResolutionWrapper (hash4query); + } } // namespace mobject diff --git a/tests/components/proc/mobject/output-mapping-test.cpp b/tests/components/proc/mobject/output-mapping-test.cpp index a2b5b298c..9fac1322a 100644 --- a/tests/components/proc/mobject/output-mapping-test.cpp +++ b/tests/components/proc/mobject/output-mapping-test.cpp @@ -74,6 +74,12 @@ namespace test { { return Pipe::lookup(target)->ident.name; } + + Query + buildQuery (PID sourcePipeID) + { + UNIMPLEMENTED ("fabricate defaults query for unit-test"); + } }; typedef OutputMapping Mapping;