diff --git a/src/common/query.hpp b/src/common/query.hpp index a645777ed..27d666693 100644 --- a/src/common/query.hpp +++ b/src/common/query.hpp @@ -28,6 +28,7 @@ #include "lib/bool-checkable.hpp" #include "lib/typed-counter.hpp" #include "lib/iter-adapter.hpp" +#include "lib/query-text.hpp" #include "lib/nocopy.hpp" #include "lib/symbol.hpp" #include "lib/util.hpp" @@ -70,10 +71,11 @@ namespace lumiera { : util::no_copy_by_client { public: - virtual ~Goal() ; + virtual ~Goal(); ///< this is a marker baseclass enum Kind - { GENERIC = 0 + { EMPTY = 0 + , GENERIC = 1 , DISCOVERY }; @@ -191,6 +193,9 @@ namespace lumiera { class Query : public Goal { + /** generic syntactical definition */ + lib::QueryText def_; + protected: static QueryID defineQueryTypeID (Kind queryType = Goal::GENERIC) @@ -199,23 +204,45 @@ namespace lumiera { return id; } + /** + * Extension point for specific kinds of queries + * to generate a generic definition from some specialised + * internal representation. + * @return a complete definition of this query in predicate form + */ + virtual lib::QueryText + buildSyntacticRepresentation() + { + return this->def_; + } + class Builder; + + Query (QueryID qID) + : Goal (qID) + , def_(this->buildSyntacticRepresentation()) + { } + + friend class Builder; + public: Query() - : Goal (defineQueryTypeID()) + : Goal (defineQueryTypeID(Goal::EMPTY)) { } explicit Query (string querySpec) : Goal (defineQueryTypeID(Goal::GENERIC)) - { - UNIMPLEMENTED("how to issue generic queries");////////////////////////////////////////////////////////////////////////////////////////////TODO - } + , def_(querySpec) + { } static Builder build (Kind queryType = Goal::GENERIC); + Builder + rebuild() const; + /* results retrieval */ class Cursor @@ -242,22 +269,14 @@ namespace lumiera { friend size_t hash_value (Query const& q) { - UNIMPLEMENTED("generic standard representation");////////////////////////////////////////////////////////////////////////////////////////////TODO + return hash_value (q.def_); } friend bool operator== (Query const& q1, Query const& q2) { - UNIMPLEMENTED("how to define equality on queries");////////////////////////////////////////////////////////////////////////////////////////////TODO + return q1.def_ == q2.def_; } - - protected: - Query (QueryID qID) - : Goal (qID) - { } - - friend class Builder; - }; @@ -270,8 +289,17 @@ namespace lumiera { template class Query::Builder { + QueryID typeID_; string predicateForm_; + Builder (QueryID kind, string baseDef ="") + : typeID_(kind) + , predicateForm_(baseDef) + { } + + friend class Query; + + public: const string @@ -281,12 +309,9 @@ namespace lumiera { + lexical_cast (getResultTypeID()) + "), "+predicateForm_; } - }; - - } // namespace lumiera #endif diff --git a/src/lib/query-text.cpp b/src/lib/query-text.cpp index 6a4a8b3f6..41705cfce 100644 --- a/src/lib/query-text.cpp +++ b/src/lib/query-text.cpp @@ -44,6 +44,18 @@ namespace lib { } // internal details + /** Parse, verify and normalise the raw query definition + * @warning right now (2012) we don't normalise at all + * @todo when integrating a real resolution engine, we + * need to parse and verify the given string. + */ + string + QueryText::normalise (string const& rawDefinition) + { + return rawDefinition; + } + + /** support using queries in hashtables. * @warning right now (2012) the dummy implementation of QueryText * doesn't normalise the query in any way, which makes the diff --git a/src/lib/query-text.hpp b/src/lib/query-text.hpp index c40c86680..42441a388 100644 --- a/src/lib/query-text.hpp +++ b/src/lib/query-text.hpp @@ -74,9 +74,8 @@ namespace lib { public: QueryText() { } - explicit - QueryText (string const& syntacticRepr) : - definition_ (syntacticRepr) + QueryText (string const& syntacticRepr) + : definition_ (normalise (syntacticRepr)) { } // using default copy/assignment @@ -99,6 +98,15 @@ namespace lib { return util::contains (definition_, predSymbol); } + private: + string normalise (string const& rawDefinition); + + + friend bool + operator== (QueryText const& q1, QueryText const& q2) + { + return q1.definition_ == q2.definition_; + } friend HashVal hash_value (QueryText const& entry); };