Lumiera  0.pre.03
»edit your freedom«
query-text.hpp
Go to the documentation of this file.
1 /*
2  QUERY-TEXT.hpp - syntactical standard representation for queries
3 
4  Copyright (C)
5  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 
35 #ifndef LIB_QUERY_TEXT_H
36 #define LIB_QUERY_TEXT_H
37 
38 #include "lib/error.hpp"
39 #include "lib/hash-value.h"
40 #include "lib/query-util.hpp"
41 #include "lib/util.hpp"
42 
43 #include <string>
44 
45 namespace lib {
46 
47  using lib::HashVal;
48  using std::string;
49 
61  class QueryText
62  {
63  string definition_;
64 
65 
66  public:
67  QueryText() { }
68 
69  QueryText (string const& syntacticRepr)
70  : definition_ (normalise (syntacticRepr))
71  { }
72 
73  // using default copy/assignment
74 
75  operator string() const
76  {
77  return definition_;
78  }
79 
80 
81  bool
82  empty() const
83  {
84  return definition_.empty();
85  }
86 
87  bool
88  hasAtom (string const& predSymbol)
89  {
90  return util::contains (definition_, predSymbol);
91  }
92 
100  uint
102  {
103  return query::countPred (definition_);
104  }
105 
106  private:
107  string normalise (string const& rawDefinition);
108 
109 
110  friend bool
111  operator== (QueryText const& q1, QueryText const& q2)
112  {
113  return q1.definition_ == q2.definition_;
114  }
115  friend bool
116  operator< (QueryText const& q1, QueryText const& q2)
117  {
118  return q1.definition_ < q2.definition_;
119  }
120 
121  friend HashVal hash_value (QueryText const& entry);
122  };
123 
124 
125 } // namespace lib
126 #endif /*LIB_QUERY_TEXT_H*/
Utilities to support working with predicate queries.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
string normalise(string const &rawDefinition)
Parse, verify and normalise the raw query definition.
Definition: query-text.cpp:37
friend HashVal hash_value(QueryText const &entry)
support using queries in hashtables.
Definition: query-text.cpp:52
Implementation namespace for support and library code.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Lumiera error handling (C++ interface).
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
uint degree_of_constriction() const
synthetic total order to classify query definitions.
Definition: query-text.hpp:101
Syntactical query representation.
Definition: query-text.hpp:61