xapian-core  1.4.19
pretty.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2010,2011,2012,2014,2016 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef XAPIAN_INCLUDED_PRETTY_H
22 #define XAPIAN_INCLUDED_PRETTY_H
23 
24 #include <list>
25 #include <map>
26 #include <ostream>
27 #include <string>
28 #include <vector>
29 
30 #include "xapian/intrusive_ptr.h"
31 #include "xapian/types.h"
32 
33 template<class S>
34 struct PrettyOStream {
36  S & os;
37 
38  PrettyOStream(S & os_) : os(os_) { }
39  template<typename T> PrettyOStream & operator|(const T & t) {
40  os << ", ";
41  return *this << t;
42  }
43 };
44 
45 struct Literal {
46  const char * _lit;
47  explicit Literal(const char * lit) : _lit(lit) { }
48  explicit Literal(const std::string & s) : _lit(s.c_str()) { }
49 };
50 
52 template<class S, class T>
53 inline PrettyOStream<S> &
54 operator<<(PrettyOStream<S> &ps, const T & t)
55 {
56  ps.os << t;
57  return ps;
58 }
59 
67 template<class S>
68 inline PrettyOStream<S> &
69 operator<<(PrettyOStream<S> &ps, const Literal & t)
70 {
71  ps.os << t._lit;
72  return ps;
73 }
74 
75 template<class S, class T>
76 inline PrettyOStream<S> &
77 operator<<(PrettyOStream<S> &ps, const T * t)
78 {
79  if (!t) {
80  ps.os << "NULL";
81  return ps;
82  }
83  ps.os << '&';
84  return ps << *t;
85 }
86 
87 template<class S, class T>
88 inline PrettyOStream<S> &
89 operator<<(PrettyOStream<S> &ps, const T ** t)
90 {
91  ps.os << (void*)t;
92  return ps;
93 }
94 
95 template<class S>
96 inline PrettyOStream<S> &
97 operator<<(PrettyOStream<S> &ps, const void * t)
98 {
99  ps.os << "(void*)" << t;
100  return ps;
101 }
102 
103 // FIXME: We probably don't want to inline this, but need to arrange to
104 // put it somewhere sane out-of-line.
105 inline void write_ch(std::ostream & os, unsigned char ch)
106 {
107  if (ch < 32 || ch >= 127) {
108  os << '\\';
109  if (ch >= 7 && ch <= 13) {
110  os << "abtnvfr"[ch - 7];
111  } else {
112  os << char('0' | (ch >> 6));
113  os << char('0' | ((ch >> 3) & 7));
114  os << char('0' | (ch & 7));
115  }
116  } else if (ch == '\\') {
117  os << "\\\\";
118  } else if (ch == '"') {
119  os << "\\\"";
120  } else {
121  os << ch;
122  }
123 }
124 
125 template<class S>
126 inline PrettyOStream<S> &
127 operator<<(PrettyOStream<S> &ps, const char * str)
128 {
129  ps.os << '"';
130  while (*str) {
131  write_ch(ps.os, *str++);
132  }
133  ps.os << '"';
134  return ps;
135 }
136 
137 template<class S>
138 inline PrettyOStream<S> &
139 operator<<(PrettyOStream<S> &ps, const std::string & str)
140 {
141  ps.os << '"';
142  for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) {
143  write_ch(ps.os, *i);
144  }
145  ps.os << '"';
146  return ps;
147 }
148 
149 template<class S>
150 inline PrettyOStream<S> &
151 operator<<(PrettyOStream<S> &ps, std::string &)
152 {
153  ps.os << "std::string&";
154  return ps;
155 }
156 
157 template<class S>
158 inline PrettyOStream<S> &
159 operator<<(PrettyOStream<S> &ps, std::string *)
160 {
161  ps.os << "std::string*";
162  return ps;
163 }
164 
165 template<class S>
166 inline PrettyOStream<S> &
167 operator<<(PrettyOStream<S> &ps, unsigned char ch)
168 {
169  ps.os << '\'';
170  if (ch < 32 || ch >= 127) {
171  ps.os << '\\';
172  if (ch >= 7 && ch <= 13) {
173  ps.os << "abtnvfr"[ch - 7];
174  } else if (ch == '\0') {
175  ps.os << "\\0";
176  } else {
177  ps.os << "0123456789abcdef"[ch >> 4];
178  ps.os << "0123456789abcdef"[ch & 0x0f];
179  }
180  } else if (ch == '\\') {
181  ps.os << "\\\\";
182  } else if (ch == '\'') {
183  ps.os << "\\'";
184  } else {
185  ps.os << ch;
186  }
187  ps.os << '\'';
188  return ps;
189 }
190 
191 template<class S>
192 inline PrettyOStream<S> &
193 operator<<(PrettyOStream<S> &ps, bool b)
194 {
195  ps.os << (b ? "true" : "false");
196  return ps;
197 }
198 
199 /*
200 template<class S>
201 inline PrettyOStream<S> &
202 operator<<(PrettyOStream<S> &ps, bool &)
203 {
204  ps.os << "bool&";
205  return ps;
206 }
207 */
208 
209 template<class S>
210 inline PrettyOStream<S> &
211 operator<<(PrettyOStream<S> &ps, Xapian::termcount * p)
212 {
213  ps.os << "(Xapian::termcount*)" << (void*)p;
214  return ps;
215 }
216 
217 template<class S, typename T>
218 inline PrettyOStream<S> &
219 operator<<(PrettyOStream<S> &ps, std::list<T> &) {
220  ps.os << "std::list&";
221  return ps;
222 }
223 
224 template<class S, typename T>
225 inline PrettyOStream<S> &
226 operator<<(PrettyOStream<S> &ps, const std::list<T> &) {
227  ps.os << "std::list";
228  // FIXME: could show first up to N elements.
229  return ps;
230 }
231 
232 template<class S, typename K, typename V>
233 inline PrettyOStream<S> &
234 operator<<(PrettyOStream<S> &ps, std::map<K, V> *) {
235  ps.os << "std::map*";
236  return ps;
237 }
238 
239 template<class S, typename K, typename V>
240 inline PrettyOStream<S> &
241 operator<<(PrettyOStream<S> &ps, std::map<K, V> &) {
242  ps.os << "std::map&";
243  return ps;
244 }
245 
246 template<class S, typename K, typename V>
247 inline PrettyOStream<S> &
248 operator<<(PrettyOStream<S> &ps, const std::map<K, V> & m) {
249  ps.os << "std::map(" << m.size() << ')';
250  // FIXME: could show first up to N elements.
251  return ps;
252 }
253 
254 template<class S, typename T>
255 inline PrettyOStream<S> &
256 operator<<(PrettyOStream<S> &ps, const std::vector<T> & v) {
257  ps.os << "std::vector(" << v.size() << ')';
258  // FIXME: could show first up to N elements.
259  return ps;
260 }
261 
262 namespace Xapian {
263  class ExpandDecider;
264  class LatLongMetric;
265  class MatchDecider;
266  class Registry;
267  class Weight;
268  namespace Internal {
269  class AndContext;
270  class ExpandStats;
271  class ExpandWeight;
272  class OrContext;
273  }
274 }
275 
276 namespace Glass {
277  class RootInfo;
278 }
279 
280 class ChertCursor;
281 class ChertDatabase;
282 class ChertTable;
283 class GlassCursor;
284 class GlassDatabase;
286 class GlassTable;
287 
288 #define XAPIAN_PRETTY_AS_CLASSNAME(C)\
289 template<class S>\
290 inline PrettyOStream<S> &\
291 operator<<(PrettyOStream<S> &ps, const C &) {\
292  ps.os << #C;\
293  return ps;\
294 }
295 
313 
314 template<class S>
315 inline PrettyOStream<S> &
316 operator<<(PrettyOStream<S> &ps, const Xapian::Weight *p) {
317  ps.os << "(Xapian:Weight*)" << (const void*)p;
318  return ps;
319 }
320 
321 class RemoteConnection;
322 
323 template<class S>
324 inline PrettyOStream<S> &
325 operator<<(PrettyOStream<S> &ps, const RemoteConnection &) {
326  ps.os << "RemoteConnection";
327  return ps;
328 }
329 
330 #include "backends/database.h"
331 
332 template<class S>
333 inline PrettyOStream<S> &
334 operator<<(PrettyOStream<S> &ps, const Xapian::Database::Internal *p) {
335  ps.os << "(Database::Internal*)" << (const void*)p;
336  return ps;
337 }
338 
339 template<class S, class T>
340 inline PrettyOStream<S> &
341 operator<<(PrettyOStream<S> &ps, Xapian::Internal::intrusive_ptr<const T> t) {
342  ps.os << "intrusive_ptr->";
343  return ps << t;
344 }
345 
346 #endif // XAPIAN_INCLUDED_PRETTY_H
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
void write_ch(std::ostream &os, unsigned char ch)
Definition: pretty.h:105
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
typedefs for Xapian
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: chert_cursor.h:66
const char * _lit
Definition: pretty.h:46
PrettyOStream(S &os_)
Definition: pretty.h:38
Class managing a Btree table in a Glass database.
Definition: glass_table.h:430
Base class for databases.
Definition: database.h:56
Class managing a Btree table in a Chert database.
Definition: chert_table.h:347
Virtual base class for expand decider functor.
Definition: expanddecider.h:37
Literal(const std::string &s)
Definition: pretty.h:48
Literal(const char *lit)
Definition: pretty.h:47
Class for calculating ESet term weights.
Definition: expandweight.h:114
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Definition: pretty.h:45
Registry for user subclasses.
Definition: registry.h:47
S & os
The std::ostream object we&#39;re outputting to.
Definition: pretty.h:36
Base class for calculating distances between two lat/long coordinates.
Definition: geospatial.h:303
string str(int value)
Convert int to std::string.
Definition: str.cc:90
A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree s...
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: glass_cursor.h:147
Base class for matcher decision functor.
Definition: enquire.h:118
PrettyOStream & operator|(const T &t)
Definition: pretty.h:39
#define XAPIAN_PRETTY_AS_CLASSNAME(C)
Definition: pretty.h:288
A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree s...
Collates statistics while calculating term weight in an ESet.
Definition: expandweight.h:37
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
Abstract base class for weighting schemes.
Definition: weight.h:35