65 #ifndef LUMIERA_QUERY_H 66 #define LUMIERA_QUERY_H 69 #include "lib/hash-combine.hpp" 78 #include <boost/lexical_cast.hpp> 79 #include <boost/operators.hpp> 93 using boost::lexical_cast;
135 QueryID(Kind k =EMPTY, IxID t=1)
159 void point_at(
void* p) { cur_ = p; }
161 template<
typename RES>
166 return *
reinterpret_cast<RES*
> (cur_);
170 explicit operator bool()
const {
return isValid(); }
171 bool isValid()
const {
return bool(cur_); }
191 return id1.kind < id2.kind
192 ||(id1.kind == id2.kind && id1.type < id2.type);
198 return id1.kind == id2.kind
199 && id1.type == id2.type;
205 return not (id1 == id2);
215 template<
typename RES>
278 defineQueryTypeID (Kind queryType = Goal::GENERIC)
280 QueryID id(queryType, getResultTypeID<RES>());
297 WARN (query,
"internal query not outfitted with a suitable query definition");
298 return string(
"bottom");
306 if (isnil(this->def_))
307 def_ = this->buildSyntacticRepresentation();
316 , def_(genericQuerySpec)
320 :
Goal (defineQueryTypeID(typeID.kind))
323 REQUIRE (this->getQID().type == typeID.type);
326 friend class Builder;
331 :
Goal (defineQueryTypeID(Goal::EMPTY))
335 Query (
string querySpec)
336 :
Goal (defineQueryTypeID(Goal::GENERIC))
342 static Builder build (Kind queryType = Goal::GENERIC);
343 Builder rebuild()
const;
345 string extractID (
Symbol predicate)
const;
346 bool usesPredicate (
Symbol predicate)
const;
355 typedef RES value_type;
356 typedef RES& reference;
357 typedef RES* pointer;
359 RES& operator* () {
return access<RES>(); }
360 RES* operator->() {
return & access<RES>(); }
362 void point_at(RES* r){ Goal::Result::point_at(r);}
363 void point_at(RES& r){ Goal::Result::point_at(&r);}
374 hash_value (
Query const& q)
389 : boost::totally_ordered<QueryKey>
399 ENSURE (!isnil(def_));
413 REQUIRE (getResultTypeID<RES>() == id_.type);
420 return "kind=" + lexical_cast<
string>(id_.kind)
421 +
",type=" + lexical_cast<string>(id_.type)
422 +
",def=" + string(def_);
426 getQueryString()
const 441 return Goal::EMPTY == id_.kind;
448 uint d1 = q1.degree();
449 uint d2 = q2.degree();
451 ||(d1 == d2 && ( q1.def_ < q2.def_
452 ||(q1.def_ == q2.def_ && q1.id_ < q2.id_)));
458 return q1.def_ == q2.def_;
464 return taggedHash (hash_value(q.def_), q.id_);
480 string predicateForm_;
484 , predicateForm_(baseDef)
487 friend class Query<RES>;
506 + lexical_cast<
string> (getResultTypeID<RES>())
507 +
"), "+predicateForm_;
519 return lib::query::extractID (predicate, this->predicateForm_);
530 lib::query::removeTerm(termPredicate, this->predicateForm_);
535 withConditions (
string additionalQueryPredicates)
537 this->predicateForm_ =
538 lib::query::appendTerms(this->predicateForm_, additionalQueryPredicates);
543 prependConditions (
string additionalQueryPredicates)
545 this->predicateForm_ =
546 lib::query::appendTerms(additionalQueryPredicates, this->predicateForm_);
551 fromText (
string queryPredicates)
553 this->predicateForm_ = queryPredicates;
566 return Builder(defineQueryTypeID (queryType));
574 return Builder(this->id_, getQueryDefinition());
588 return this->rebuild().extractID (predicate);
596 return lib::query::hasTerm(predicate, getQueryDefinition());
609 return QueryKey (this->id_, getQueryDefinition());
Query ABC: unspecific goal for resolution or retrieval.
Utilities to support working with predicate queries.
Creating series of type-based contexts.
std::shared_ptr< Resolution > PReso
Allow to take and transfer ownership of a result set.
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
virtual lib::QueryText buildSyntacticRepresentation() const
Extension point to generate a generic query definition on demand.
Helper template(s) for creating Lumiera Forward Iterators.
lib::QueryText getQueryDefinition() const
access the complete syntactical representation of this query.
inline string literal This is a marker type to indicate that
void combine(size_t &combinedHash, size_t additionalHash)
meld the additional hash value into the given base hash value.
Builder & removeTerm(Symbol termPredicate)
remove the first term from this query definition, which matches the given predicate symbol ...
A generic syntactical representation for all kinds of queries.
lib::TypedContext< Goal::Result > ResultType
Context used for generating type-IDs to denote the specific result types of issued queries...
size_t taggedHash(size_t hash, Goal::QueryID typeID)
includes the QueryID type distinction into the given hash value
string extractID(Symbol predicate) const
extract an ID term defined as (single) parameter for the given predicate.
Token or Atom with distinct identity.
lib::QueryText def_
generic syntactical definition
Mix-Ins to allow or prohibit various degrees of copying and cloning.
virtual ~Goal()
this is a marker baseclass
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Wrapper for indexing and ordering.
Result()
create an NIL result
Types marked with this mix-in may be duplicated by copy-construction, yet may not be moved or transfe...
Lumiera public interface.
QueryKey()
the empty or bottom query key
Provide type-IDs for a specific context.
uint degree_of_constriction() const
synthetic total order to classify query definitions.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Helper for establishing, reworking and remolding queries.
Syntactical query representation.
string extractID(Symbol predicate) const
convenience shortcut to extract a desired name-ID.
Single Solution, possibly part of a result set.