From 5b48b9f864d683abc69719f4350461cda7bdb4f5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 17 Apr 2010 01:56:14 +0200 Subject: [PATCH] fix a regression regarding struct-asset naming scheme --- src/proc/asset/entry-id.hpp | 6 +- src/proc/asset/struct-factory-impl.hpp | 8 +-- src/proc/asset/struct-scheme.hpp | 90 +++++++++++++++++--------- src/proc/asset/struct.cpp | 35 ---------- tests/42query.tests | 2 +- tests/lib/query/query-utils-test.cpp | 2 +- wiki/renderengine.html | 4 +- 7 files changed, 72 insertions(+), 75 deletions(-) diff --git a/src/proc/asset/entry-id.hpp b/src/proc/asset/entry-id.hpp index 451000931..3f736892e 100644 --- a/src/proc/asset/entry-id.hpp +++ b/src/proc/asset/entry-id.hpp @@ -202,14 +202,14 @@ namespace asset { Asset::Ident getIdent() const { - Category cat (STRUCT, idi::StructTraits::catFolder); + Category cat (STRUCT, idi::StructTraits::catFolder()); return Asset::Ident (this->getSym(), cat); } static idi::HashVal getTypeHash() { - return hash_value (Category (STRUCT, idi::StructTraits::catFolder)); + return hash_value (Category (STRUCT, idi::StructTraits::catFolder())); } @@ -237,7 +237,7 @@ namespace asset { operator string () const { - return "ID<"+idi::StructTraits::idSymbol+">-"+EntryID::getSym(); + return "ID<"+idi::StructTraits::idSymbol()+">-"+EntryID::getSym(); } friend ostream& operator<< (ostream& os, EntryID const& id) { return os << string(id); } diff --git a/src/proc/asset/struct-factory-impl.hpp b/src/proc/asset/struct-factory-impl.hpp index 0fe969261..82050fc5e 100644 --- a/src/proc/asset/struct-factory-impl.hpp +++ b/src/proc/asset/struct-factory-impl.hpp @@ -99,7 +99,7 @@ namespace asset { // does the query somehow specify the desired name-ID? string nameID = extractID (genericIdSymbol, query); if (isnil (nameID)) - nameID = extractID (StructTraits::idSymbol, query); + nameID = extractID (StructTraits::idSymbol(), query); if (isnil (nameID)) { // no name-ID contained in the query... @@ -107,15 +107,15 @@ namespace asset { static int i=0; static format namePattern ("%s.%d"); static format predPattern ("%s(%s), "); - nameID = str(namePattern % StructTraits::namePrefix % (++i) ); + nameID = str(namePattern % StructTraits::namePrefix() % (++i) ); name.insert(0, - str(predPattern % StructTraits::idSymbol % nameID )); + str(predPattern % StructTraits::idSymbol() % nameID )); } ENSURE (!isnil (name)); ENSURE (!isnil (nameID)); ENSURE (contains (name, nameID)); - Category cat (STRUCT, StructTraits::catFolder); + Category cat (STRUCT, StructTraits::catFolder()); return Asset::Ident (name, cat ); ///////////////////////TICKET #565 the ID field should be just the ID, the query should go into a dedicated "capabilities" field. } diff --git a/src/proc/asset/struct-scheme.hpp b/src/proc/asset/struct-scheme.hpp index 588b01551..c8e0d09a4 100644 --- a/src/proc/asset/struct-scheme.hpp +++ b/src/proc/asset/struct-scheme.hpp @@ -36,30 +36,14 @@ #define ASSET_STRUCT_SCHEME_H -//#include "proc/mobject/session.hpp" -//#include "proc/mobject/mobject.hpp" - #include "lib/symbol.hpp" -//#include "lib/error.hpp" -//#include "lib/util.hpp" - -//#include - -#include -using boost::format; -/////////////////////////////////////////////////////////TODO needs to be pushed down into a *.cpp #include -//using mobject::Session; -//using mobject::MObject; +/////////////////////////////////////////////////////////TICKET #166 : needs to be pushed down into a *.cpp +#include +using boost::format; -using lib::Symbol; -//using util::isnil; -//using util::contains; -//using asset::Query; -//using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY; -//using lumiera::query::extractID; namespace mobject { namespace session { @@ -77,28 +61,76 @@ namespace asset{ class Timeline; class Sequence; + namespace idi { - // structural asset ID scheme ///////////////////////////////////////////////////////////TICKET #565 + using lib::Symbol; + + + + /* ==== structural asset ID scheme ==== */ /////////////////////////////////////////////TICKET #565 : better organisation of this naming scheme template struct StructTraits { - static Symbol namePrefix; - static Symbol catFolder; - static Symbol idSymbol; + static Symbol namePrefix(); + static Symbol catFolder(); + static Symbol idSymbol(); }; - // Note: individual defaults are defined in stuct.cpp + + ///////////////////////////////////////////////////////////////////////////////////////////TICKET #581 intending to abandon asset::Track in favour of a plain EntryID + template<> struct StructTraits + { + static Symbol namePrefix() { return "track"; } + static Symbol catFolder() { return "tracks";} + static Symbol idSymbol() { return "track"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "track"; } + static Symbol catFolder() { return "tracks";} + static Symbol idSymbol() { return "track"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "clip"; } + static Symbol catFolder() { return "clips";} + static Symbol idSymbol() { return "clip"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "pipe"; } + static Symbol catFolder() { return "pipes";} + static Symbol idSymbol() { return "pipe"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "patt"; } + static Symbol catFolder() { return "build-templates";} + static Symbol idSymbol() { return "procPatt"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "tL"; } + static Symbol catFolder() { return "timelines";} + static Symbol idSymbol() { return "timeline"; } + }; + template<> struct StructTraits + { + static Symbol namePrefix() { return "seq"; } + static Symbol catFolder() { return "sequences";} + static Symbol idSymbol() { return "sequence"; } + }; /* catch-all defaults */ template - Symbol StructTraits::idSymbol = typeid(X).name(); ////////////////////TICKET #583 this default works but is ugly + Symbol StructTraits::idSymbol() { return typeid(X).name(); } ////////////////////TICKET #583 this default works but is ugly template - Symbol StructTraits::catFolder = StructTraits::idSymbol; + Symbol StructTraits::catFolder(){ return idSymbol(); } template - Symbol StructTraits::namePrefix = StructTraits::idSymbol; + Symbol StructTraits::namePrefix(){return idSymbol(); } @@ -109,9 +141,9 @@ namespace asset{ { static uint i=0; static format namePattern ("%s.%03d"); - /////////////////////////////////////////////////////////TODO needs to be pushed down into a *.cpp + ////////////////////////////////////////////////////////////////////////////////TICKET #166 : needs to be pushed down into a *.cpp - return str(namePattern % StructTraits::namePrefix % (++i) ); + return str(namePattern % StructTraits::namePrefix() % (++i) ); } diff --git a/src/proc/asset/struct.cpp b/src/proc/asset/struct.cpp index 387d8b3bf..128745279 100644 --- a/src/proc/asset/struct.cpp +++ b/src/proc/asset/struct.cpp @@ -155,39 +155,4 @@ namespace asset { template PSequence StructFactory::operator() (const Query& query); - - - /* ======= struct asset naming scheme ======== */ - - ///////////////////////////////////////////////////////////////////////////////////////////TICKET #565 better organisation for the asset::Struct naming scheme - ///////////////////////////////////////////////////////////////////////////////////////////TICKET #581 intending to abandon asset::Track in favour of a plain EntryID - template<> Symbol StructTraits::namePrefix = "track"; - template<> Symbol StructTraits::catFolder = "tracks"; - template<> Symbol StructTraits::idSymbol = "track"; - - template<> Symbol StructTraits::namePrefix = "track"; - template<> Symbol StructTraits::catFolder = "tracks"; - template<> Symbol StructTraits::idSymbol = "track"; - - template<> Symbol StructTraits::namePrefix = "clip"; - template<> Symbol StructTraits::catFolder = "clips"; - template<> Symbol StructTraits::idSymbol = "clip"; - - template<> Symbol StructTraits::namePrefix = "pipe"; - template<> Symbol StructTraits::catFolder = "pipes"; - template<> Symbol StructTraits::idSymbol = "pipe"; - - template<> Symbol StructTraits::namePrefix = "patt"; - template<> Symbol StructTraits::catFolder = "build-templates"; - template<> Symbol StructTraits::idSymbol = "procPatt"; - - template<> Symbol StructTraits::namePrefix = "tL"; - template<> Symbol StructTraits::catFolder = "timelines"; - template<> Symbol StructTraits::idSymbol = "timeline"; - - template<> Symbol StructTraits::namePrefix = "seq"; - template<> Symbol StructTraits::catFolder = "sequences"; - template<> Symbol StructTraits::idSymbol = "sequence"; - - } // namespace asset diff --git a/tests/42query.tests b/tests/42query.tests index 98983c3b0..717f0bde7 100644 --- a/tests/42query.tests +++ b/tests/42query.tests @@ -12,7 +12,7 @@ END TEST "normalise ID" QueryUtils_test normaliseID < -
+
[<img[Advice solution|uml/fig141573.png]]
 
 
@@ -556,7 +556,7 @@ In order to find matches and provide advice solutions, the advice system maintai
 This is the tricky part of the whole advice system implementation. A naive implementation will quickly degenerate in performance, as costs are of order ~AdviceProvisions * ~AdviceRequests * (average number of binding terms). But contrary to the standard solutions for rules based systems (either forward or backward chaining), in this case here always complete binding sets are to be matched, which allows to reduce the effort.
 
 !!!solution idea
-The binding patterns are organised by //predicate symbol and the lists are normalised.// A simple normalisation could be lexicographic ordering of the predicate symbols. Then the resulting representation can be //hashed.// When all predicates are constant, match can be found by hashtable lookup, otherwise, in case some predicates contain variable arguments ({{red{planned extension}}}), the lookup is followed by an unification. For this to work, we'll have to include the arity into the predicate symbols used in the first matching stage. Moreover, we'll create a //matching closure// (functor object), internally holding the arguments for unification. This approach allows for //actual interpretation of the arguments.// It is conceivable that in special cases we'll get multiple instances of the same predicate, just with different arguments. The unification of these terms needs to consider each possible pairwise combination (cartesian product) &mdash; but working out the details of the implementation can safely be deferred until we'll actually hit such a special situation, thanks to the implementation by a functor.
+The binding patterns are organised by //predicate symbol and the lists are normalised.// A simple normalisation could be lexicographic ordering of the predicate symbols. Then the resulting representation can be //hashed.// When all predicates are constant, a match can be detected by hashtable lookup, otherwise, in case some of the predicates contain variable arguments ({{red{planned extension}}}), the lookup is followed by an unification. For this to work, we'll have to include the arity into the predicate symbols used in the first matching stage. Moreover, we'll create a //matching closure// (functor object), internally holding the arguments for unification. This approach allows for //actual interpretation of the arguments.// It is conceivable that in special cases we'll get multiple instances of the same predicate, just with different arguments. The unification of these terms needs to consider each possible pairwise combination (cartesian product) &mdash; but working out the details of the implementation can safely be deferred until we'll actually hit such a special situation, thanks to the implementation by a functor.
 
 Fortunately, the calculation of this normalised patterns can be separated completely from the actual matching. Indeed, we don't even need to store the binding patterns at all within the binding index &mdash; storing the hash value is sufficient (and in case of patterns with arguments we'll attach the matching closure functor). Yet still we need to store a marker for each successful match, together with back-links, in order to handle changing and retracting of advice.