Branch data Line data Source code
1 : : /* brass_spellingwordslist.h: A termlist containing all words which are spelling targets.
2 : : *
3 : : * Copyright (C) 2005,2008,2009 Olly Betts
4 : : * Copyright (C) 2007 Lemur Consulting Ltd
5 : : *
6 : : * This program is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU General Public License as
8 : : * published by the Free Software Foundation; either version 2 of the
9 : : * License, or (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_HGUARD_BRASS_SPELLINGWORDSLIST_H
22 : : #define XAPIAN_HGUARD_BRASS_SPELLINGWORDSLIST_H
23 : :
24 : : #include "alltermslist.h"
25 : : #include "database.h"
26 : : #include "brass_spelling.h"
27 : :
28 : : class BrassCursor;
29 : :
30 : : class BrassSpellingWordsList : public AllTermsList {
31 : : /// Copying is not allowed.
32 : : BrassSpellingWordsList(const BrassSpellingWordsList &);
33 : :
34 : : /// Assignment is not allowed.
35 : : void operator=(const BrassSpellingWordsList &);
36 : :
37 : : /// Keep a reference to our database to stop it being deleted.
38 : : Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database;
39 : :
40 : : /** A cursor which runs through the spelling table reading termnames from
41 : : * the keys.
42 : : */
43 : : BrassCursor * cursor;
44 : :
45 : : /** The term frequency of the term at the current position.
46 : : *
47 : : * If this value is zero, then we haven't read the term frequency or
48 : : * collection frequency for the current term yet. We need to call
49 : : * read_termfreq() to read these.
50 : : */
51 : : mutable Xapian::termcount termfreq;
52 : :
53 : : /// Read and cache the term frequency.
54 : : void read_termfreq() const;
55 : :
56 : : public:
57 : 5 : BrassSpellingWordsList(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
58 : : BrassCursor * cursor_)
59 : 5 : : database(database_), cursor(cursor_), termfreq(0) {
60 : : // Seek to the entry before the first key with a "W" prefix, so the
61 : : // first next() will advance us to the first such entry.
62 : 5 : cursor->find_entry(std::string("W", 1));
63 : 5 : }
64 : :
65 : : /// Destructor.
66 : : ~BrassSpellingWordsList();
67 : :
68 : : /** Returns the current termname.
69 : : *
70 : : * Either next() or skip_to() must have been called before this
71 : : * method can be called.
72 : : */
73 : : std::string get_termname() const;
74 : :
75 : : /** Returns the term frequency of the current term.
76 : : *
77 : : * Either next() or skip_to() must have been called before this
78 : : * method can be called.
79 : : */
80 : : Xapian::doccount get_termfreq() const;
81 : :
82 : : /** Returns the collection frequency of the current term.
83 : : *
84 : : * Either next() or skip_to() must have been called before this
85 : : * method can be called.
86 : : */
87 : : Xapian::termcount get_collection_freq() const;
88 : :
89 : : /// Advance to the next term in the list.
90 : : TermList * next();
91 : :
92 : : /// Advance to the first term which is >= tname.
93 : : TermList * skip_to(const std::string &tname);
94 : :
95 : : /// True if we're off the end of the list
96 : : bool at_end() const;
97 : : };
98 : :
99 : : #endif /* XAPIAN_HGUARD_BRASS_SPELLINGWORDSLIST_H */
|