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) Lumiera.org
5  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 
44 #ifndef LIB_QUERY_TEXT_H
45 #define LIB_QUERY_TEXT_H
46 
47 #include "lib/error.hpp"
48 #include "lib/hash-value.h"
49 #include "lib/query-util.hpp"
50 #include "lib/util.hpp"
51 
52 #include <string>
53 
54 namespace lib {
55 
56  using lib::HashVal;
57  using std::string;
58 
70  class QueryText
71  {
72  string definition_;
73 
74 
75  public:
76  QueryText() { }
77 
78  QueryText (string const& syntacticRepr)
79  : definition_ (normalise (syntacticRepr))
80  { }
81 
82  // using default copy/assignment
83 
84  operator string() const
85  {
86  return definition_;
87  }
88 
89 
90  bool
91  empty() const
92  {
93  return definition_.empty();
94  }
95 
96  bool
97  hasAtom (string const& predSymbol)
98  {
99  return util::contains (definition_, predSymbol);
100  }
101 
109  uint
111  {
112  return query::countPred (definition_);
113  }
114 
115  private:
116  string normalise (string const& rawDefinition);
117 
118 
119  friend bool
120  operator== (QueryText const& q1, QueryText const& q2)
121  {
122  return q1.definition_ == q2.definition_;
123  }
124  friend bool
125  operator< (QueryText const& q1, QueryText const& q2)
126  {
127  return q1.definition_ < q2.definition_;
128  }
129 
130  friend HashVal hash_value (QueryText const& entry);
131  };
132 
133 
134 } // namespace lib
135 #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:46
friend HashVal hash_value(QueryText const &entry)
support using queries in hashtables.
Definition: query-text.cpp:61
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:56
uint degree_of_constriction() const
synthetic total order to classify query definitions.
Definition: query-text.hpp:110
Syntactical query representation.
Definition: query-text.hpp:70