Xpace
remote.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file remote/remote.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_REMOTE_H
13 #define XPACE_REMOTE_H
14 
15 #include <vector>
16 
17 #include "base/types.h"
18 
19 namespace Xpace
20 {
21  namespace Remote
22  {
23  /// String does NOT own its buffer
25  {
26  /// @param len the number of chars in the buffer
27  /// @param b the buffer
28  String
29  (size_t len = 0,
30  uint16* b = 0) :
31  bufferLength(len),
32  buffer(b)
33  {
34  }
35 
36  /// @param s a 0-terminated string
37  String
38  (uint16* s) :
39  bufferLength(str16len(s)),
40  buffer(s)
41  {
42  }
43 
44  const size_t bufferLength;
45  uint16 *const buffer;
46 
47  static
48  size_t str16len
49  (uint16* s)
50  {
51  size_t ret(0);
52  while (*s++)
53  ++ret;
54  return ret;
55  }
56  };
57 
58  /// Does NOT own its buffer
60  {
61  /// @param s the number of char in the buffer
62  /// @param b the buffer
63  intArray
64  (size_t len,
65  int64 *const b) :
66  bufferLength(len),
67  buffer(b)
68  {
69  }
70 
71  const size_t bufferLength;
72  int64 *const buffer;
73  };
74 
75  /// ============================= REFERENCE LIST ==========
76 
77  // A reference list - a search result
79  {
80  public:
81  void destroy
82  ();
83 
84  /// @return true iff the list is empty
85  virtual bool operator!
86  ()
87  const
88  = 0;
89 
90  /// @return number of refs in the list
91  virtual uint64 getCount
92  ()
93  const
94  = 0;
95 
96  /// return numbers of siblings at levels in the list
97  /// N.B could be quite slow
98  /// @param atLevel if (atLevel[n] != 0), count siblings at level n
99  /// @retval atLevel fill in the number of siblings at level n
100  /// @return number of distinct siblings in the list
101  virtual void getSiblingCount
102  (intArray* atLevel)
103  = 0;
104 
105  /// get a range of references
106  /// @retval ret array of references
107  /// @param start start of range
108  /// @param size number of values (e.g., document num, paragraph, sentence) to return for each ref
109  /// @return number of references (not values) in retval
110  virtual size_t getRefs
111  (intArray* ret,
112  uint64 start,
113  uint size = 1)
114  = 0;
115 
116  /// this list AND another list
117  /// @param rhs the other list
118  virtual void opAnd
119  (RefList* rhs)
120  = 0;
121 
122  /// this list OR another list
123  /// @param rhs the other list
124  virtual void opOr
125  (RefList* rhs)
126  = 0;
127 
128  /// invert this list
129  virtual void opNot
130  ()
131  = 0;
132 
133  /// does the list contain this ref?
134  /// N.B. Could be quite slow
135  /// @param ref the reference, e.g. [56789, 2, 1]
136  /// @return true iff list contains the ref
137  virtual bool hasRef
138  (const intArray& ref)
139  = 0;
140 
141  protected:
142  RefList
143  ()
144  {
145  }
146 
147  virtual ~RefList
148  ()
149  {
150  }
151 
152  private:
153  RefList
154  (const RefList&);
155  RefList& operator=
156  (const RefList&);
157  };
158 
159  // ============================== INDEX ===================
160 
161  /// An index
163  {
164  public:
165  /// destroy an index
166  /// @param the index to destroy
167  void destroy
168  ();
169 
170  /// @return true iff this index is empty
171  virtual bool operator!
172  ()
173  const
174  = 0;
175 
176  /// @retval this index's configuration
177  virtual void getConfig
178  (String*)
179  const
180  = 0;
181 
182  /// @return the number of terms in this index
183  virtual uint64 getTermCount
184  ()
185  const
186  = 0;
187 
188  /// get a range of terms in the index
189  /// @retval the range of terms, e.g., "<term val="AK" count="4321"/><term val="AL" count="5432">"
190  /// @param start start of range
191  /// @count number of terms to get
192  /// @return number of terms gotten
193  virtual size_t getTerms
194  (String*,
195  uint64 start,
196  size_t count)
197  const
198  = 0;
199 
200  /// do a search
201  /// @param query
202  /// @throw XML_Error
203  /// @return a pointer to the search result
204  virtual RefList* search
205  (const String& query)
206  const
207  = 0;
208 
209  protected:
210  Index
211  ()
212  {
213  }
214 
215  virtual ~Index
216  ()
217  {
218  }
219 
220  private:
221  Index
222  (const Index&);
223  Index& operator=
224  (const Index&);
225  };
226 
227  // ============================== INDEX_LIST ==============
228 
229  /// A list of indexes
231  {
232  public:
233  /// Create an index list
234  /// @param config - must have a "index_list" tag
235  static
236  IndexList* create
237  (const String& config);
238 
239  /// Destroy an index list
240  /// @param the list to destroy
241  void destroy
242  ();
243 
244  /// @return the number of indexes in the list
245  virtual size_t getCount
246  ()
247  const
248  = 0;
249 
250  /// open an index by number
251  /// @param indexNum the index to get
252  /// @param config - use this config where possible
253  /// @return a pointer to the Index; 0 if there is no index
254  virtual Index* openIndex
255  (uint indexNum,
256  const String& config = String())
257  = 0;
258 
259  /// open an index by name
260  /// @retval indexNum fillin the index's number
261  /// @param name the index to get
262  /// @param config - use this config where possible
263  /// @return a pointer to the Index; 0 if there is no index
264  virtual Index* openIndex
265  (uint* indexNum,
266  const String& name,
267  const String& config = String())
268  = 0;
269 
270  /// do a search
271  /// @param query; includes index names TODO - define syntax
272  /// @return a pointer to the search result
273  virtual RefList* search
274  (const String& query)
275  = 0;
276 
277  protected:
278  IndexList
279  ()
280  {
281  }
282 
283  virtual ~IndexList
284  ()
285  {
286  }
287 
288  private:
289  IndexList
290  (const IndexList&);
291  IndexList& operator=
292  (const IndexList&);
293  };
294 
295  // ============================== DATA STORE ==============
296 
297  /// A data store
299  {
300  public:
301  /// @param config - must have a "store" tag
302  static
303  Store* create
304  (const String& config);
305 
306  void destroy
307  ();
308 
309  /// get the Store's Class Tree
310  /// @retval an XML representation of the Class Tree
311  /// @param siblingPos list of sibling numbers: start here
312  /// @retval siblingPos fillin with next
313  /// @param showMore leave stubs for unreturned subtrees
314  /// @param maxNodes no more nodes than this
315  /// @param maxDepth no deeper than this
316  /// @return true iff tree continues
317  virtual bool getClassTree
318  (String*,
319  intArray* siblingPos,
320  bool showMore = true,
321  uint maxNodes = 0,
322  uint maxDepth = 0)
323  = 0;
324 
325  /// convert an XML stub to a sibling pos and a byte pos
326  /// @retval siblingPos the siblings
327  /// @param the XML stub
328  /// @return true iff the stub was valid
329  static bool convertStub
330  (intArray* siblingPos,
331  const String& stub);
332 
333  virtual ~Store
334  ()
335  {
336  }
337 
338  protected:
339  Store
340  ()
341  {
342  }
343 
344  private:
345  Store
346  (const Store&);
347  Store& operator=
348  (const Store&);
349  };
350 
351  // ============================== CONTENT =================
352 
353  /// Data from a Store, possibly filtered with a RefList
355  {
356  public:
357  /// @param store content comes from here
358  /// @param refList get only content from these refs
359  static
360  Content* create
361  (const Store* store,
362  const RefList* refList = 0);
363 
364  void destroy
365  ();
366 
367  /// get a range of content
368  /// @retval something like “<count>2<><Symbol>DWTI<><Date>20000505<><end>0,2<>\0”
369  /// @param siblingPos list of sibling numbers: start here, go no deeper than siblingPos.bufferSize
370  /// @retval siblingPos list of sibling numbers: fillin with next
371  /// @param charPos start here (within a node)
372  /// @retval charPos fillin next (within a node)
373  /// @param fullNodes don't break a node due to size.bufferSize (if possible)
374  /// @param showMore leave stubs for unreturned subtrees
375  /// @param maxNodes retrieve no more than this many nodes
376  /// @return the number of chars filled in
377  virtual size_t get
378  (String* ret,
379  intArray* siblingPos,
380  size_t* bytePos,
381  bool fullNodes = true,
382  bool showMore = true,
383  uint maxNodes = 0)
384  = 0;
385 
386  /// convert an XML stub to a sibling pos and a byte pos
387  /// @retval siblingPos the siblings
388  /// @retval bytePos the bytes
389  /// @param the XML stub
390  /// @return true iff the stub was valid
391  static bool convertStub
392  (intArray* siblingPos,
393  size_t* bytePos,
394  const String& stub);
395 
396  protected:
397  Content
398  ()
399  {
400  }
401 
402  virtual ~Content
403  ()
404  {
405  }
406 
407  private:
408  Content
409  (const Content&);
410  Content& operator=
411  (const Content&);
412  };
413 
414  #if (defined TESTING || !defined NDEBUG) && !defined DOCUMENTATION
415  void XPACE_EXPORT testRemoteIndexes
416  (const String& config,
417  uint checks);
418 
419  void XPACE_EXPORT testRemoteStore
420  (const String& config);
421  #endif
422 
423  } // namespace Remote
424 } // namespace Xpace
425 
426 #endif
427 
A low-level data holder.
Definition: types_c.h:82
An index.
Definition: remote.h:162
unsigned int uint
Definition: types.h:75
String does NOT own its buffer.
Definition: remote.h:24
uint const Xpace_Char8 size_t len
Definition: table_c.h:180
const size_t bufferLength
Definition: remote.h:44
uint16 *const buffer
Definition: remote.h:45
A list of indexes.
Definition: remote.h:230
unsigned long long uint64
Definition: types.h:87
const Xpace_Char16 * name
Sink callbacks for table data.
Definition: table_c.h:141
A data store.
Definition: remote.h:298
long long int64
Definition: types.h:86
int64 *const buffer
Definition: remote.h:72
Does NOT own its buffer.
Definition: remote.h:59
Data from a Store, possibly filtered with a RefList.
Definition: remote.h:354
const size_t bufferLength
Definition: remote.h:71
unsigned short uint16
Definition: types.h:83
Xpace project main namespace
Definition: datetime.h:18
============================= REFERENCE LIST ==========
Definition: remote.h:78

current as of Wed Jun 10 2026 12:00:05