implement another builder function; adapt OutputDesignation

This commit is contained in:
Fischlurch 2012-12-11 04:45:18 +01:00
parent 602a04c4b5
commit 1bde72cccf
4 changed files with 49 additions and 17 deletions

View file

@ -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<RES>()
{
return Query<RES>(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<class RES>
typename Query<RES>::Builder
Query<RES>::rebuild() const

View file

@ -60,7 +60,7 @@ namespace asset {
PPipe
Pipe::query (Query<Pipe> 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);
}

View file

@ -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<STRU>::catFolder());

View file

@ -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 <boost/functional/hash.hpp>
#include <cstdlib>
@ -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<asset::Pipe> 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<asset::Pipe>
build_corresponding_sourceQuery (Query<asset::Pipe> const& query4pipe)
{
Query<asset::Pipe> srcQuery = query4pipe;
// removeTerm (SEQNR_PREDICATE, srcQuery);////////////////////////////////////////////////////////////////////////////////////////////TODO
UNIMPLEMENTED ("Query remolding");////////////////////////////////////////////////////////////////////////////////////////////TODO
return srcQuery;
return query4pipe.rebuild()
.removeTerm (SEQNR_PREDICATE);
}
}