summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/htword/WordCursorOne.h
blob: 133ef59c3c02c2758dafda172ca069edd7d08274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
// WordCursorOne.h
//
// NAME
// 
// search and retrieve entries in a WordListOne object.
//
// SYNOPSIS
// 
// #include <WordList.h>
//
// int callback(WordList *, WordDBCursor& , const WordReference *, Object &)
// {
//    ...
// }
//
// Object* data = ...
//
// WordList *words = ...;
//
// WordCursor *search = words->Cursor(callback, data);
// WordCursor *search = words->Cursor(WordKey("word <UNDEF> <UNDEF>"));
// WordCursor *search = words->Cursor(WordKey("word <UNDEF> <UNDEF>"), callback, data);
// WordCursor *search = words->Cursor(WordKey());
//
// ...
//
// if(search->Walk() == NOTOK) bark;
// List* results = search->GetResults();
//
// search->WalkInit();
// if(search->WalkNext() == OK)
//   dosomething(search->GetFound());
// search->WalkFinish();
// 
// DESCRIPTION
// 
// WordCursorOne is a WordCursor derived class that implements search
// in a WordListOne object. It currently is the only derived class of
// the WordCursor object. Most of its behaviour is described in the
// WordCursor manual page, only the behaviour specific to WordCursorOne
// is documented here.
//
//
// END
//
// Part of the ht://Dig package   <http://www.htdig.org/>
// Copyright (c) 1999-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: WordCursorOne.h,v 1.4 2004/05/28 13:15:26 lha Exp $
//

#ifndef _WordCursorOne_h_
#define _WordCursorOne_h_

#ifndef SWIG
#include "htString.h"
#include "WordKey.h"
#include "WordDB.h"
#include "WordCursor.h"

class WordList;
class WordDBCursor;
#endif /* SWIG */

class WordCursorOne : public WordCursor
{
 public:
#ifndef SWIG
  //-
  // Private constructor. Creator of the object must then call Initialize()
  // prior to using any other methods.
  //
  WordCursorOne(WordList *words);
  //-
  // Private constructor. See WordList::Cursor method with same prototype for
  // description.
  //
  WordCursorOne(WordList *words, wordlist_walk_callback_t callback, Object * callback_data);
  //-
  // Private constructor. See WordList::Cursor method with same prototype for
  // description.
  //
  WordCursorOne(WordList *words, const WordKey &searchKey, int action = HTDIG_WORDLIST_WALKER);
  //-
  // Private constructor. See WordList::Cursor method with same prototype for
  // description.
  //
  WordCursorOne(WordList *words, const WordKey &searchKey, wordlist_walk_callback_t callback, Object * callback_data);
#endif /* SWIG */
  virtual ~WordCursorOne() {
    if(cursor) delete cursor;
  }
  virtual void Clear();
  virtual void ClearInternal();
  virtual void ClearResult();

  virtual inline int ContextSave(String& buffer) const { found.Get(buffer); return OK; }
  virtual int ContextRestore(const String& buffer);

#ifndef SWIG
  virtual int Walk();
#endif /* SWIG */
  virtual int WalkInit();
  virtual int WalkRewind();
  virtual int WalkNext();
#ifndef SWIG
  virtual int WalkNextStep();
#endif /* SWIG */
  virtual int WalkFinish();
  //
  // Find out if cursor should better jump to the next possible key
  // (DB_SET_RANGE) instead of sequential iterating (DB_NEXT).  If it
  // is decided that jump is a better move : cursor_set_flags =
  // DB_SET_RANGE key = calculated next possible key Else do nothing
  // Return OK if skipping successfull.  Returns WORD_WALK_ATEND if no
  // more possible match, reached the maximum. Returns
  // WORD_WALK_FAILED on general failure, occurs if called and no
  // skipping necessary.
  // 
  int SkipUselessSequentialWalking();

  virtual int Seek(const WordKey& patch);

#ifndef SWIG
  virtual int Get(String& bufferout) const;
  inline String Get() const { String tmp; Get(tmp); return tmp; }

 protected:

  int Initialize(WordList *nwords, const WordKey &nsearchKey, wordlist_walk_callback_t ncallback, Object * ncallback_data, int naction);

  //
  // Internal state
  //
  //
  // The actual Berkeley DB cursor.
  //
  WordDBCursor* cursor;
  //
  // The latest retrieved key and data
  //
  String key;
  String data;
  //
  // The shorted prefix key computed from searchKey
  //
  WordKey prefixKey;
  //
  // WalkNext leap is either DB_NEXT or DB_SET_RANGE.
  //
  int cursor_get_flags;
  //
  // True if search key is a prefix key
  //
  int searchKeyIsSameAsPrefix;
#endif /* SWIG */
};

#endif /* _WordCursorOne_h_ */