diff --git a/src/common/advice/binding.hpp b/src/common/advice/binding.hpp index 89cdda460..39904a7c9 100644 --- a/src/common/advice/binding.hpp +++ b/src/common/advice/binding.hpp @@ -78,7 +78,7 @@ #include "lib/error.hpp" #include "lib/symbol.hpp" #include "lib/hash-value.h" -#include "common/query.hpp" +#include "lib/query-util.hpp" #include #include @@ -231,7 +231,7 @@ namespace advice { inline Binding const& Binding::addTypeGuard() { - atoms_.insert (Atom ("advice.type."+lumiera::query::buildTypeID())); + atoms_.insert (Atom ("advice.type."+lib::query::buildTypeID())); return *this; } diff --git a/src/common/query.hpp b/src/common/query.hpp index 0b4065d82..a645777ed 100644 --- a/src/common/query.hpp +++ b/src/common/query.hpp @@ -21,8 +21,8 @@ */ -#ifndef LIB_QUERY_H -#define LIB_QUERY_H +#ifndef LUMIERA_QUERY_H +#define LUMIERA_QUERY_H #include "lib/bool-checkable.hpp" @@ -288,37 +288,5 @@ namespace lumiera { - namespace query { - - /** ensure standard format for a given id string. - * Trim, sanitise and ensure the first letter is lower case. - * @note modifies the given string ref in place - */ - void normaliseID (string& id); - - - /** count the top-level predicates in the query string. - * usable for ordering queries, as more predicates usually - * mean more conditions, i.e. more constriction - */ - uint countPred (const string&); - - - const string extractID (Symbol, const string& termString); - - const string removeTerm (Symbol, string& termString); - - - template - const string - buildTypeID() - { - string typeID (typeid(TY).name()); - normaliseID (typeID); - return typeID; - } - - - -}} // namespace lumiera::query +} // namespace lumiera #endif diff --git a/src/common/query/defs-registry.hpp b/src/common/query/defs-registry.hpp index 6f849f0c4..bc6dce4b1 100644 --- a/src/common/query/defs-registry.hpp +++ b/src/common/query/defs-registry.hpp @@ -44,6 +44,7 @@ #include "lib/util.hpp" #include "lib/util-foreach.hpp" #include "lib/sync-classlock.hpp" +#include "lib/query-util.hpp" #include "common/query.hpp" #include @@ -95,7 +96,7 @@ namespace query { weak_ptr objRef; Record (const Query& q, const P& obj) - : degree (lumiera::query::countPred ("TODO")),//q)),////////////////////////////////////////////////////////////////////////////////////////////TODO + : degree (lib::query::countPred ("TODO")),//q)),////////////////////////////////////////////////////////////////////////////////////////////TODO query (q), objRef (obj) { diff --git a/src/common/query/query-resolver.cpp b/src/common/query/query-resolver.cpp index 60b7a6a45..e784a3993 100644 --- a/src/common/query/query-resolver.cpp +++ b/src/common/query/query-resolver.cpp @@ -30,6 +30,8 @@ namespace lumiera { /* generate vtables here... */ + Goal::~Goal() { } + Resolution::~Resolution() { } QueryResolver::~QueryResolver() { } diff --git a/src/lib/query-util.cpp b/src/lib/query-util.cpp index f5d2fe93f..7a29f3c39 100644 --- a/src/lib/query-util.cpp +++ b/src/lib/query-util.cpp @@ -21,9 +21,9 @@ * *****************************************************/ -#include "lib/util.hpp" -#include "lib/symbol.hpp" +#include "lib/error.hpp" #include "lib/query-util.hpp" +#include "lib/util.hpp" #include #include @@ -39,7 +39,7 @@ using util::contains; using util::isnil; -namespace lumiera { +namespace lib { namespace query { namespace { // local definitions @@ -139,11 +139,5 @@ namespace lumiera { } } // namespace query - - - Goal::~Goal() { } - - - -} // namespace lumiera +} // namespace lib diff --git a/src/lib/query-util.hpp b/src/lib/query-util.hpp index 1d0a09a23..81e6deae4 100644 --- a/src/lib/query-util.hpp +++ b/src/lib/query-util.hpp @@ -25,266 +25,19 @@ #define LIB_QUERY_UTIL_H -#include "lib/bool-checkable.hpp" -#include "lib/typed-counter.hpp" -#include "lib/iter-adapter.hpp" -#include "lib/nocopy.hpp" #include "lib/symbol.hpp" -#include "lib/util.hpp" -#include -#include #include -#include #include namespace lib { - using lib::IxID; using lib::Symbol; using lib::Literal; - using util::unConst; - using boost::lexical_cast; using std::string; -#ifdef false /////////////////////////////////////////////////////////////////////WIP - /* ==== common definitions for rule based queries ==== */ - - class Goal; - class Resolution; - class QueryResolver; - - /** Allow for taking ownership of a result set */ - typedef std::tr1::shared_ptr PReso; - - - - /** - * Query ABC: unspecific goal for resolution or retrieval. - * Goal elements are used within the backbone of a generic query system - * to access individual resolution mechanisms based on an internal classification - * of the type of query. - */ - class Goal - : util::no_copy_by_client - { - public: - virtual ~Goal() ; - - enum Kind - { GENERIC = 0 - , DISCOVERY - }; - - struct QueryID - { - Kind kind; - IxID type; - }; - - QueryID const& - getQID() const - { - return id_; - } - - - /** - * Single Solution, possibly part of a result set. - * A pointer-like object, usually to be down-casted - * to a specifically typed Query::Cursor - * @see Resolution - */ - class Result - : public lib::BoolCheckable - { - void* cur_; - - protected: - void point_at(void* p) { cur_ = p; } - - template - RES& - access() - { - REQUIRE (cur_); - return *reinterpret_cast (cur_); - } - - public: - bool isValid() const { return bool(cur_); } - - Result() : cur_(0) { } ///< create an NIL result - }; - - - - protected: - QueryID id_; - - Goal (QueryID qid) - : id_(qid) - { } - - }; - - - inline bool - operator== (Goal::QueryID const& id1, Goal::QueryID const& id2) - { - return id1.kind == id2.kind - && id1.type == id2.type; - } - - inline bool - operator!= (Goal::QueryID const& id1, Goal::QueryID const& id2) - { - return ! (id1 == id2); - } - - - - /** Context used for generating type-IDs to denote - * the specific result types of issued queries */ - typedef lib::TypedContext ResultType; - - template - inline IxID - getResultTypeID() ///< @return unique ID denoting result type RES - { - return ResultType::ID::get(); - } - - - - - /** - * Generic interface to express a query - * for specifically typed result elements - * providing some capabilities or fulfilling - * some properties. This is a generic umbrella - * for several kinds of queries and provides a - * mechanism for uniform usage of various - * resolution mechanisms. - * - * Any query bears an internal type classification and can be - * represented in a common syntactical form based on predicate logic. - * Query instances are created by some facilities allowing to query for objects. - * These query providers \em do know the specific kind (type) of query to expose. - * While client code uses these queries only by reference, there is the possibility - * to involve a generic QueryResolver, which -- behind the scenes -- manages a registry - * of specific resolution mechanisms. This way, clients may retrieve a set of results, - * each representing a possible solution to the posed query. - * - * @note until really integrating a rules based system - * this is largely dummy placeholder implementation. - * Some more specific query resolvers are available already, - * so, depending on the circumstances the actual resolution might be - * substantial or just a fake. - * @warning especially the classical resolution-type queries are just - * faked and use the given query-string as-is, without any normalisation. - * Moreover, as especially the fake-configrules match by string comparison, - * this may led to unexpected mis-matches. - */ - template - class Query - : public Goal - { - protected: - static QueryID - defineQueryTypeID (Kind queryType = Goal::GENERIC) - { - QueryID id = {queryType, getResultTypeID() }; - return id; - } - - class Builder; - - public: - Query() - : Goal (defineQueryTypeID()) - { } - - explicit - Query (string querySpec) - : Goal (defineQueryTypeID(Goal::GENERIC)) - { - UNIMPLEMENTED("how to issue generic queries");////////////////////////////////////////////////////////////////////////////////////////////TODO - } - - static Builder - build (Kind queryType = Goal::GENERIC); - - - /* results retrieval */ - class Cursor - : public Goal::Result - { - public: - typedef RES value_type; - typedef RES& reference; - typedef RES* pointer; - - RES& operator* () { return access(); } - RES* operator->() { return & access(); } - - void point_at(RES* r){ Goal::Result::point_at(r);} - void point_at(RES& r){ Goal::Result::point_at(&r);} - }; - - - typedef lib::IterAdapter iterator; - - iterator operator() (QueryResolver const& resolver) const; - iterator resolveBy (QueryResolver const& resolver) const; - - friend size_t - hash_value (Query const& q) - { - UNIMPLEMENTED("generic standard representation");////////////////////////////////////////////////////////////////////////////////////////////TODO - } - - friend bool - operator== (Query const& q1, Query const& q2) - { - UNIMPLEMENTED("how to define equality on queries");////////////////////////////////////////////////////////////////////////////////////////////TODO - } - - protected: - Query (QueryID qID) - : Goal (qID) - { } - - friend class Builder; - - }; - - - - - /** - * Helper for establishing, - * reworking and remolding queries. - */ - template - class Query::Builder - { - string predicateForm_; - - public: - - const string - asKey() const - { - return "type(" - + lexical_cast (getResultTypeID()) - + "), "+predicateForm_; - } - - }; -#endif /////////////////////////////////////////TODO diff --git a/src/proc/asset/struct-factory-impl.hpp b/src/proc/asset/struct-factory-impl.hpp index e6fa6308b..36241e789 100644 --- a/src/proc/asset/struct-factory-impl.hpp +++ b/src/proc/asset/struct-factory-impl.hpp @@ -51,6 +51,7 @@ #include "proc/asset/struct-scheme.hpp" +#include "lib/query-util.hpp" #include "lib/symbol.hpp" #include "lib/error.hpp" #include "lib/util.hpp" @@ -70,7 +71,7 @@ namespace asset { using util::contains; using lumiera::Query; using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY; - using lumiera::query::extractID; + using lib::query::extractID; using proc::mobject::Session; using proc::mobject::MObject; diff --git a/src/proc/asset/struct.cpp b/src/proc/asset/struct.cpp index cebb9a344..9a9d5eade 100644 --- a/src/proc/asset/struct.cpp +++ b/src/proc/asset/struct.cpp @@ -29,6 +29,7 @@ #include "lib/util.hpp" #include "lib/symbol.hpp" +#include "lib/query-util.hpp" #include "include/logging.h" #include "common/query.hpp" @@ -37,7 +38,7 @@ using boost::format; using lib::Symbol; -using lumiera::query::normaliseID; +using lib::query::normaliseID; using lumiera::query::QueryHandler; using proc::ConfigResolver; diff --git a/src/proc/mobject/output-designation.cpp b/src/proc/mobject/output-designation.cpp index d3de0891a..f4f813fe7 100644 --- a/src/proc/mobject/output-designation.cpp +++ b/src/proc/mobject/output-designation.cpp @@ -39,6 +39,8 @@ #include "lib/error.hpp" #include "lib/symbol.hpp" +#include "lib/query-util.hpp" +#include "common/query/query-resolver.hpp" #include "proc/mobject/mobject.hpp" #include "proc/mobject/placement-ref.hpp" #include "proc/mobject/output-designation.hpp" @@ -50,8 +52,8 @@ using lumiera::Symbol; using lumiera::query::QueryHandler; -using lumiera::query::removeTerm; -using lumiera::query::extractID; +using lib::query::removeTerm; +using lib::query::extractID; using proc::ConfigResolver; using lib::HashVal; diff --git a/src/proc/mobject/session/query/fake-configrules.cpp b/src/proc/mobject/session/query/fake-configrules.cpp index 7f7bfc274..dd3421de9 100644 --- a/src/proc/mobject/session/query/fake-configrules.cpp +++ b/src/proc/mobject/session/query/fake-configrules.cpp @@ -27,9 +27,9 @@ #include "proc/mobject/session/track.hpp" #include "proc/asset/procpatt.hpp" #include "proc/asset/pipe.hpp" +#include "lib/query-util.hpp" #include "common/query.hpp" - #include "include/logging.h" #include "lib/symbol.hpp" #include "lib/util.hpp" @@ -52,8 +52,8 @@ namespace session { using asset::ProcPatt; using asset::PProcPatt; -// using lumiera::query::extractID; - using lumiera::query::removeTerm; +// using lib::query::extractID; + using lib::query::removeTerm; namespace { diff --git a/src/proc/mobject/session/query/fake-configrules.hpp b/src/proc/mobject/session/query/fake-configrules.hpp index 48f582a49..e9bd0e50d 100644 --- a/src/proc/mobject/session/query/fake-configrules.hpp +++ b/src/proc/mobject/session/query/fake-configrules.hpp @@ -42,6 +42,7 @@ #include "proc/mobject/session.hpp" #include "proc/config-resolver.hpp" +#include "lib/query-util.hpp" #include "lib/util.hpp" #include "lib/p.hpp" @@ -67,8 +68,8 @@ namespace session { using lib::P; using lumiera::Query; - using lumiera::query::removeTerm; //////////////TODO better use Query::Builder - using lumiera::query::extractID; ///////////////TODO dto + using lib::query::removeTerm; //////////////TODO better use Query::Builder + using lib::query::extractID; ///////////////TODO dto using lumiera::query::isFakeBypass; /////////TODO placeholder until there is a real resolution engine using util::contains; diff --git a/tests/components/proc/asset/basicpipetest.cpp b/tests/components/proc/asset/basicpipetest.cpp index 7ce280d0b..b0634f2f5 100644 --- a/tests/components/proc/asset/basicpipetest.cpp +++ b/tests/components/proc/asset/basicpipetest.cpp @@ -30,6 +30,7 @@ #include "proc/assetmanager.hpp" #include "proc/mobject/session.hpp" #include "proc/asset/asset-diagnostics.hpp" +#include "lib/query-util.hpp" #include "common/query.hpp" #include @@ -48,7 +49,7 @@ namespace test { using mobject::Session; using lumiera::Query; - using lumiera::query::normaliseID; + using lib::query::normaliseID; diff --git a/tests/components/proc/mobject/session/defs-manager-impl-test.cpp b/tests/components/proc/mobject/session/defs-manager-impl-test.cpp index 3c598cc84..e69fd72d7 100644 --- a/tests/components/proc/mobject/session/defs-manager-impl-test.cpp +++ b/tests/components/proc/mobject/session/defs-manager-impl-test.cpp @@ -31,6 +31,7 @@ #include "proc/assetmanager.hpp" #include "proc/mobject/session.hpp" #include "proc/streamtype.hpp" +#include "lib/query-util.hpp" #include "common/query.hpp" #include @@ -54,7 +55,7 @@ namespace test { using lumiera::Query; using lumiera::query::QueryHandler; - using lumiera::query::normaliseID; + using lib::query::normaliseID; using proc::ConfigResolver; diff --git a/tests/components/proc/mobject/session/defs-manager-test.cpp b/tests/components/proc/mobject/session/defs-manager-test.cpp index a3b260f02..f3f941cd8 100644 --- a/tests/components/proc/mobject/session/defs-manager-test.cpp +++ b/tests/components/proc/mobject/session/defs-manager-test.cpp @@ -24,6 +24,7 @@ #include "lib/test/run.hpp" #include "lib/symbol.hpp" #include "lib/util.hpp" +#include "lib/query-util.hpp" #include "common/query.hpp" #include "proc/asset.hpp" @@ -55,7 +56,7 @@ namespace test { using asset::PPipe; using asset::Struct; using lumiera::Query; - using lumiera::query::normaliseID; + using lib::query::normaliseID; /** shortcut: run just a query diff --git a/tests/components/proc/mobject/session/defs-registry-impl-test.cpp b/tests/components/proc/mobject/session/defs-registry-impl-test.cpp index e54024d83..a9208082a 100644 --- a/tests/components/proc/mobject/session/defs-registry-impl-test.cpp +++ b/tests/components/proc/mobject/session/defs-registry-impl-test.cpp @@ -87,6 +87,8 @@ namespace test { } + using lib::query::test::garbage_query; + diff --git a/tests/lib/query/query-utils-test.cpp b/tests/lib/query/query-utils-test.cpp index ddb13210b..ccd60e2e4 100644 --- a/tests/lib/query/query-utils-test.cpp +++ b/tests/lib/query/query-utils-test.cpp @@ -24,15 +24,13 @@ #include "lib/test/run.hpp" #include "lib/util.hpp" #include "lib/util-foreach.hpp" - +#include "lib/query-util.hpp" #include "lib/cmdline.hpp" -#include "common/query.hpp" #include "query/querydiagnostics.hpp" #include #include -using lumiera::Query; using lib::Cmdline; using util::isnil; using util::contains; @@ -46,7 +44,7 @@ using std::endl; -namespace lumiera { +namespace lib { namespace query { namespace test{ diff --git a/tests/lib/query/querydiagnostics.hpp b/tests/lib/query/querydiagnostics.hpp index d2718c6bf..ddcad83ef 100644 --- a/tests/lib/query/querydiagnostics.hpp +++ b/tests/lib/query/querydiagnostics.hpp @@ -21,8 +21,8 @@ */ -#ifndef LUMIERA_QUERY_TEST_QUERYDIAGNOSTICS_H -#define LUMIERA_QUERY_TEST_QUERYDIAGNOSTICS_H +#ifndef LIB_QUERY_TEST_QUERYDIAGNOSTICS_H +#define LIB_QUERY_TEST_QUERYDIAGNOSTICS_H #include "lib/format-string.hpp" @@ -33,7 +33,7 @@ using std::rand; -namespace lumiera { +namespace lib { namespace query{ namespace test { @@ -72,5 +72,5 @@ namespace test { -}}} // namespace lumiera::query::test +}}} // namespace lib::query::test #endif diff --git a/tests/lib/subsystem-runner-test.cpp b/tests/lib/subsystem-runner-test.cpp index 36fda3495..725ce6413 100644 --- a/tests/lib/subsystem-runner-test.cpp +++ b/tests/lib/subsystem-runner-test.cpp @@ -26,10 +26,10 @@ #include "common/subsys.hpp" #include "common/subsystem-runner.hpp" #include "common/option.hpp" -#include "common/query.hpp" #include "lib/symbol.hpp" #include "backend/thread-wrapper.hpp" +#include "lib/query-util.hpp" #include "lib/error.hpp" #include "lib/util.hpp" #include "lib/sync.hpp" @@ -43,7 +43,7 @@ using util::isnil; using util::cStr; using test::Test; using lib::Literal; -using lumiera::query::extractID; +using lib::query::extractID; using backend::Thread; @@ -52,7 +52,7 @@ namespace test { namespace { // private test classes and data... - using lumiera::query::extractID; + using lib::query::extractID; /** limit for the randomly selected duration of * subsystem's running phase (milliseconds) */