diff --git a/src/common/query.hpp b/src/common/query.hpp index e3bd1f537..0794bd4a0 100644 --- a/src/common/query.hpp +++ b/src/common/query.hpp @@ -218,12 +218,20 @@ namespace lumiera { } class Builder; - - Query (QueryID qID) - : Goal (qID) + + explicit + Query (QueryID typeID) + : Goal (typeID) , def_(this->buildSyntacticRepresentation()) { } + Query (QueryID typeID, string querySpec) + : Goal (defineQueryTypeID(typeID.kind)) + , def_(querySpec) + { + REQUIRE (this->getQID().type == typeID.type); + } + friend class Builder; @@ -309,7 +317,17 @@ namespace lumiera { public: + /** when done with defining or reworking the query, + * the result may be retrieved by type conversion */ + operator Query() + { + return Query(typeID_, predicateForm_); + } + + /** @return a string representation usable for hashing + * @note includes the type parameter of the underlying query + */ string asKey() const { @@ -319,15 +337,34 @@ namespace lumiera { } + /** extract an ID term defined as (single) parameter for the given predicate. + * E.g. when using the query "foo(a), bar(b)", \c extractID("bar") returns "b" + * @param predicate symbol of the predicate to investigate + * @warning preliminary implementation + */ string extractID (Symbol predicate) const { return lib::query::extractID (predicate, this->predicateForm_); } + + /** remove the first term from this query definition, + * which matches the given predicate symbol + * @warning preliminary implementation + */ + Builder& + removeTerm (Symbol termPredicate) + { + lib::query::removeTerm(termPredicate, this->predicateForm_); + return *this; + } + }; + + template typename Query::Builder Query::rebuild() const diff --git a/src/proc/asset/pipe.cpp b/src/proc/asset/pipe.cpp index d1e49c2c1..3ddf6b04b 100644 --- a/src/proc/asset/pipe.cpp +++ b/src/proc/asset/pipe.cpp @@ -60,7 +60,7 @@ namespace asset { PPipe Pipe::query (Query const& properties) { - UNIMPLEMENTED ("maybe provide a direct way to query, based on a predicate string?");//////////////////////////////////TODO + //////////////////////////////////////////////////TODO maybe provide a direct way to query, based on a predicate string? return Struct::retrieve (properties); } diff --git a/src/proc/asset/struct-factory-impl.hpp b/src/proc/asset/struct-factory-impl.hpp index b828413c4..2c22b976f 100644 --- a/src/proc/asset/struct-factory-impl.hpp +++ b/src/proc/asset/struct-factory-impl.hpp @@ -67,6 +67,7 @@ namespace asset { using boost::format; using lib::Symbol; + using util::uNum; using util::isnil; using util::contains; using lumiera::Query; @@ -88,11 +89,6 @@ namespace asset { Symbol genericIdSymbol ("id"); Symbol seqNrPredicate ("ord"); - inline uint - asNumber (string const& spec) - { - return abs(std::atoi (spec.c_str())); - } // returns 0 in case of unparseable number } @@ -130,7 +126,7 @@ namespace asset { // does the query actually demand the Nth instance/element? string seqID = query.extractID (seqNrPredicate); - if (!isnil (seqID) && 1 < asNumber(seqID)) + if (!isnil (seqID) && 1 < uNum(seqID)) nameID += "."+seqID; Category cat (STRUCT, StructTraits::catFolder()); diff --git a/src/proc/mobject/output-designation.cpp b/src/proc/mobject/output-designation.cpp index f4f813fe7..582ce02df 100644 --- a/src/proc/mobject/output-designation.cpp +++ b/src/proc/mobject/output-designation.cpp @@ -46,6 +46,7 @@ #include "proc/mobject/output-designation.hpp" #include "proc/mobject/output-mapping.hpp" #include "proc/config-resolver.hpp" +#include "lib/util.hpp" #include #include @@ -56,6 +57,7 @@ using lib::query::removeTerm; using lib::query::extractID; using proc::ConfigResolver; using lib::HashVal; +using util::uNum; namespace proc { namespace mobject { @@ -182,18 +184,15 @@ namespace mobject { uint is_defaults_query_with_channel (Query const& query4pipe) { - string seqNr = "TODO";//extractID (SEQNR_PREDICATE, query4pipe);////////////////////////////////////////////////////////////////////////////////////////////TODO - UNIMPLEMENTED ("Query remolding");////////////////////////////////////////////////////////////////////////////////////////////TODO - return abs(std::atoi (seqNr.c_str())); // also 0 in case of an invalid number + string seqNr = query4pipe.extractID (SEQNR_PREDICATE); + return uNum (seqNr); // defaults to 0 in case of an invalid number } Query build_corresponding_sourceQuery (Query const& query4pipe) { - Query srcQuery = query4pipe; -// removeTerm (SEQNR_PREDICATE, srcQuery);////////////////////////////////////////////////////////////////////////////////////////////TODO - UNIMPLEMENTED ("Query remolding");////////////////////////////////////////////////////////////////////////////////////////////TODO - return srcQuery; + return query4pipe.rebuild() + .removeTerm (SEQNR_PREDICATE); } }