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) Lumiera.org
5  2008, 2012 Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
29 #ifndef LIB_QUERY_UTIL_H
30 #define LIB_QUERY_UTIL_H
31 
32 
33 #include "lib/symbol.hpp"
34 #include "lib/meta/util.hpp"
35 
36 #include <typeinfo>
37 #include <string>
38 
39 
40 namespace lib {
41 
42  using lib::Symbol;
43  using lib::Literal;
44  using std::string;
45 
46 
47 
48 
49 
50 
51  namespace query {
52 
57  void normaliseID (string& id);
58 
59 
64  uint countPred (const string&);
65 
66 
67  string extractID (Symbol, string const& termString);
68 
69  string removeTerm (Symbol, string& queryString);
70  bool hasTerm (Symbol sym, string const& queryString);
71 
72  string appendTerms (string const& pred1, string const& pred2);
73 
74 
75  template<typename TY>
76  const string
77  buildTypeID()
78  {
79  string typeID {util::typeStr<TY>()};
80  normaliseID (typeID);
81  return typeID;
82  }
83 
84 
85 
86  }} // namespace lib::query
87 #endif
uint countPred(const string &q)
count the top-level predicates in the query string.
Definition: query-util.cpp:146
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:61
Simple and lightweight helpers for metaprogramming and type detection.
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Implementation namespace for support and library code.
string appendTerms(string const &pred1, string const &pred2)
Definition: query-util.cpp:161
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:101
Token or Atom with distinct identity.
Definition: symbol.hpp:126
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:118