integrate (placeholder) query definition
effectively this joins the two existing lines of "Query" classes into one systematic representation Next step would be to move all mutation operations over to the Query::Builder
This commit is contained in:
parent
5b2668a17c
commit
8630e888a5
3 changed files with 67 additions and 22 deletions
|
|
@ -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 RES>
|
||||
class Query<RES>::Builder
|
||||
{
|
||||
QueryID typeID_;
|
||||
string predicateForm_;
|
||||
|
||||
Builder (QueryID kind, string baseDef ="")
|
||||
: typeID_(kind)
|
||||
, predicateForm_(baseDef)
|
||||
{ }
|
||||
|
||||
friend class Query<RES>;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
const string
|
||||
|
|
@ -281,12 +309,9 @@ namespace lumiera {
|
|||
+ lexical_cast<string> (getResultTypeID<RES>())
|
||||
+ "), "+predicateForm_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace lumiera
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue