From 1f6e71272a60e8c77f0967234380928d17afd5ff Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 26 Dec 2012 01:13:36 +0100 Subject: [PATCH] simplify fake config rules table access - since std::map is itself a smart-ptr, there is no need for an indirection - directly use QueryKey as table key --- .../session/query/fake-configrules.cpp | 74 ++++++++----------- .../session/query/fake-configrules.hpp | 18 +++-- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/proc/mobject/session/query/fake-configrules.cpp b/src/proc/mobject/session/query/fake-configrules.cpp index c6c10208c..0b0bff6a8 100644 --- a/src/proc/mobject/session/query/fake-configrules.cpp +++ b/src/proc/mobject/session/query/fake-configrules.cpp @@ -59,15 +59,13 @@ namespace session { namespace { - typedef std::pair AnyPair; + typedef std::pair AnyPair; /** helper to simplify creating mock table entries, wrapped correctly */ template AnyPair entry (Query const& query, typename WrapReturn::Wrapper& obj) { - UNIMPLEMENTED ("generic query-key");////////////////////////////////////////////////////////////////////////////////////////////TODO - return AnyPair ( "TODO"//Query (query).asKey()////////////////////////////////////////////////////////////////////////////////////////////TODO - , any(obj)); + return AnyPair(query, any(obj)); } /** helper especially for creating structural assets from a capability query */ @@ -79,19 +77,8 @@ namespace session { string capabilities (caps); Query query (capabilities); Ptr obj = Struct::retrieve (query); - UNIMPLEMENTED("generic query-key"); -// return AnyPair(query.asKey(), obj);////////////////////////////////////////////////////////////////////////////////////////////TODO + return AnyPair(query, obj); } - - /** shortcut for simply accessing a table entry */ - template - any& - item (PTAB& table, const string& query) - { - UNIMPLEMENTED ("generic Query-key");////////////////////////////////////////////////////////////////////////////////////////////TODO - //return (*table)[Query(query).asKey()];////////////////////////////////////////////////////////////////////////////////////////////TODO - } - } @@ -110,14 +97,14 @@ namespace session { // for baiscpipetest.cpp --------- - answer_->insert (entry_Struct ("stream(video)")); - answer_->insert (entry_Struct ("stream(teststream)")); - item (answer_, "stream(default)") = item (answer_,"stream(video)"); // set up a default stream + answer_.insert (entry_Struct ("stream(video)")); + answer_.insert (entry_Struct ("stream(teststream)")); + item ("stream(default)") = item ("stream(video)"); // set up a default stream - answer_->insert (entry_Struct ("pipe(master), stream(video)")); - item (answer_, "") = item(answer_,"pipe(master), stream(video)");// use as default + answer_.insert (entry_Struct ("pipe(master), stream(video)")); + item ("") = item("pipe(master), stream(video)");// use as default - answer_->insert (entry_Struct ("pipe(ambiance)")); + answer_.insert (entry_Struct ("pipe(ambiance)")); } @@ -134,8 +121,8 @@ namespace session { typedef WrapReturn::Wrapper Ptr; Ptr newPipe (Struct::retrieve.newPipe (pipeID, streamID)); - answer_->insert (entry (q, newPipe)); - return true; // denotes query will now succeed... + answer_.insert (entry (q, newPipe)); + return true; // indicates that the query will now succeed... } /** special case: create a new pipe for a specific stream ID */ @@ -145,7 +132,7 @@ namespace session { typedef WrapReturn::Wrapper Ptr; Ptr newPipe (Struct::retrieve.made4fake (q)); - answer_->insert (entry (q, newPipe)); + answer_.insert (entry (q, newPipe)); return true; } @@ -157,7 +144,7 @@ namespace session { typedef WrapReturn::Wrapper Ptr; Ptr newPP (Struct::retrieve.made4fake (q)); - answer_->insert (entry (q, newPP)); + answer_.insert (entry (q, newPP)); return true; } @@ -195,7 +182,7 @@ namespace session { if (!newTimeline) newTimeline = Struct::retrieve.made4fake (normalisedQuery); // no suitable Timeline found: create and attach new one - answer_->insert (entry (normalisedQuery, newTimeline)); // "learn" the found/created Timeline as new solution + answer_.insert (entry (normalisedQuery, newTimeline)); // "learn" the found/created Timeline as new solution return true; } @@ -230,7 +217,7 @@ namespace session { if (!newSequence) newSequence = Struct::retrieve.made4fake (normalisedQuery); // no suitable found: create and attach new Sequence - answer_->insert (entry (normalisedQuery, newSequence)); // "learn" the found/created new solution + answer_.insert (entry (normalisedQuery, newSequence)); // "learn" the found/created new solution return true; } @@ -240,15 +227,14 @@ namespace session { bool MockTable::set_new_mock_solution (Query const& q, typename WrapReturn::Wrapper& obj) { - UNIMPLEMENTED ("generic query-key");////////////////////////////////////////////////////////////////////////////////////////////TODO -// answer_->erase (q.asKey());////////////////////////////////////////////////////////////////////////////////////////////TODO - answer_->insert (entry (q, obj)); + answer_.erase (q); + answer_.insert (entry (q, obj)); return true; } - // generate the necessary specialisations----------------------------- + // generate the necessary specialisations----------------------------------- template bool MockTable::set_new_mock_solution (Query const&, PPipe&); - + @@ -259,37 +245,37 @@ namespace session { MockTable::MockTable () - : answer_(new Tab()), - isInit_(false) + : answer_() + , isInit_(false) { } - - + + /** this is the (preliminary/mock) implementation * handling queries for objects of a specific type * and with capabilities or properties defined by * the query. The real implementation would require * a rule based system (Ichthyo plans to use YAP Prolog), - * while this dummy implementation simply relpies based + * while this dummy implementation simply replies based * on a table of pre-fabricated objects. Never fails. * @return smart ptr (or similar) holding the object, * maybe an empty smart ptr if not found */ - const any& - MockTable::fetch_from_table_for (const string& queryStr) + any const& + MockTable::fetch_from_table_for (QueryKey const& query) { static const any NOTFOUND; if (!isInit_) fill_mock_table(); - Tab::iterator i = answer_->find (queryStr); - if (i == answer_->end()) + Tab::iterator i = answer_.find (query); + if (i == answer_.end()) return NOTFOUND; else return i->second; } - - + + } // namespace query }}} // namespace proc::mobject::session diff --git a/src/proc/mobject/session/query/fake-configrules.hpp b/src/proc/mobject/session/query/fake-configrules.hpp index 8dee1c10b..c706910bf 100644 --- a/src/proc/mobject/session/query/fake-configrules.hpp +++ b/src/proc/mobject/session/query/fake-configrules.hpp @@ -52,7 +52,6 @@ #include "lib/util.hpp" #include "lib/p.hpp" -#include #include #include #include @@ -123,15 +122,14 @@ namespace session { class MockTable : public proc::ConfigResolver { - typedef std::map Tab; - typedef boost::scoped_ptr PTab; + typedef std::map Tab; - PTab answer_; + Tab answer_; bool isInit_; protected: MockTable (); - const any& fetch_from_table_for (const string& queryStr); + any const& fetch_from_table_for (QueryKey const& query); // special cases.... template @@ -148,6 +146,14 @@ namespace session { private: void fill_mock_table (); + + /** shortcut for simply accessing a table entry */ + template + any& + item (string const& querySpec) + { + return answer_[Query(querySpec)]; + } }; @@ -166,7 +172,7 @@ namespace session { virtual bool resolve (Ret& solution, Query const& q) { - const any& entry = this->fetch_from_table_for ("TODO");//q.asKey());////////////////////////////////////////////////////////////////////////////////////////////TODO + any const& entry = this->fetch_from_table_for(q); if (!isnil (entry)) { Ret const& candidate (any_cast (entry));