74 #ifndef LUMIERA_QUERY_H 75 #define LUMIERA_QUERY_H 87 #include <boost/lexical_cast.hpp> 88 #include <boost/operators.hpp> 102 using boost::lexical_cast;
144 QueryID(Kind k =EMPTY, IxID t=1)
168 void point_at(
void* p) { cur_ = p; }
170 template<
typename RES>
175 return *
reinterpret_cast<RES*
> (cur_);
179 explicit operator bool()
const {
return isValid(); }
180 bool isValid()
const {
return bool(cur_); }
200 return id1.kind < id2.kind
201 ||(id1.kind == id2.kind && id1.type < id2.type);
207 return id1.kind == id2.kind
208 && id1.type == id2.type;
214 return not (id1 == id2);
224 template<
typename RES>
287 defineQueryTypeID (Kind queryType = Goal::GENERIC)
289 QueryID id(queryType, getResultTypeID<RES>());
306 WARN (query,
"internal query not outfitted with a suitable query definition");
307 return string(
"bottom");
315 if (isnil(this->def_))
316 def_ = this->buildSyntacticRepresentation();
325 , def_(genericQuerySpec)
329 :
Goal (defineQueryTypeID(typeID.kind))
332 REQUIRE (this->getQID().type == typeID.type);
335 friend class Builder;
340 :
Goal (defineQueryTypeID(Goal::EMPTY))
344 Query (
string querySpec)
345 :
Goal (defineQueryTypeID(Goal::GENERIC))
351 static Builder build (Kind queryType = Goal::GENERIC);
352 Builder rebuild()
const;
354 string extractID (
Symbol predicate)
const;
355 bool usesPredicate (
Symbol predicate)
const;
364 typedef RES value_type;
365 typedef RES& reference;
366 typedef RES* pointer;
368 RES& operator* () {
return access<RES>(); }
369 RES* operator->() {
return & access<RES>(); }
371 void point_at(RES* r){ Goal::Result::point_at(r);}
372 void point_at(RES& r){ Goal::Result::point_at(&r);}
383 hash_value (
Query const& q)
398 : boost::totally_ordered<QueryKey>
408 ENSURE (!isnil(def_));
422 REQUIRE (getResultTypeID<RES>() == id_.type);
429 return "kind=" + lexical_cast<
string>(id_.kind)
430 +
",type=" + lexical_cast<string>(id_.type)
431 +
",def=" + string(def_);
435 getQueryString()
const 450 return Goal::EMPTY == id_.kind;
457 uint d1 = q1.degree();
458 uint d2 = q2.degree();
460 ||(d1 == d2 && ( q1.def_ < q2.def_
461 ||(q1.def_ == q2.def_ && q1.id_ < q2.id_)));
467 return q1.def_ == q2.def_;
473 return taggedHash (hash_value(q.def_), q.id_);
489 string predicateForm_;
493 , predicateForm_(baseDef)
496 friend class Query<RES>;
515 + lexical_cast<
string> (getResultTypeID<RES>())
516 +
"), "+predicateForm_;
528 return lib::query::extractID (predicate, this->predicateForm_);
539 lib::query::removeTerm(termPredicate, this->predicateForm_);
544 withConditions (
string additionalQueryPredicates)
546 this->predicateForm_ =
547 lib::query::appendTerms(this->predicateForm_, additionalQueryPredicates);
552 prependConditions (
string additionalQueryPredicates)
554 this->predicateForm_ =
555 lib::query::appendTerms(additionalQueryPredicates, this->predicateForm_);
560 fromText (
string queryPredicates)
562 this->predicateForm_ = queryPredicates;
575 return Builder(defineQueryTypeID (queryType));
583 return Builder(this->id_, getQueryDefinition());
597 return this->rebuild().extractID (predicate);
605 return lib::query::hasTerm(predicate, getQueryDefinition());
618 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 created by copy-construction (or move construction), but may be not reassigned thereafter.
Hash value types and utilities.
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.