Lumiera  0.pre.03
»edit your freedom«
query-util.hpp
Go to the documentation of this file.
1 /*
2  QUERY-UTIL.hpp - support for working with terms and queries
3 
4  Copyright (C)
5  2008, 2012 Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
20 #ifndef LIB_QUERY_UTIL_H
21 #define LIB_QUERY_UTIL_H
22 
23 
24 #include "lib/symbol.hpp"
25 #include "lib/meta/util.hpp"
26 
27 #include <typeinfo>
28 #include <string>
29 
30 
31 namespace lib {
32 
33  using lib::Symbol;
34  using lib::Literal;
35  using std::string;
36 
37 
38 
39 
40 
41 
42  namespace query {
43 
48  void normaliseID (string& id);
49 
50 
55  uint countPred (const string&);
56 
57 
58  string extractID (Symbol, string const& termString);
59 
60  string removeTerm (Symbol, string& queryString);
61  bool hasTerm (Symbol sym, string const& queryString);
62 
63  string appendTerms (string const& pred1, string const& pred2);
64 
65 
66  template<typename TY>
67  const string
68  buildTypeID()
69  {
70  string typeID {util::typeStr<TY>()};
71  normaliseID (typeID);
72  return typeID;
73  }
74 
75 
76 
77  }} // namespace lib::query
78 #endif
uint countPred(const string &q)
count the top-level predicates in the query string.
Definition: query-util.cpp:137
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:52
Simple and lightweight helpers for metaprogramming and type detection.
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
Implementation namespace for support and library code.
string appendTerms(string const &pred1, string const &pred2)
Definition: query-util.cpp:152
string extractID(Symbol sym, const string &termString)
(preliminary) helper: instead of really parsing and evaluating the terms, just do a regular expressio...
Definition: query-util.cpp:92
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Marker types to indicate a literal string and a Symbol.
string removeTerm(Symbol sym, string &queryString)
(preliminary) helper: cut a term with the given symbol.
Definition: query-util.cpp:109