1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2011-2016 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#pragma once
20
21#include "cursor.hpp"
22
23namespace grn {
24namespace dat {
25
26class Trie;
27
28class GRN_DAT_API IdCursor : public Cursor {
29 public:
30 IdCursor();
31 ~IdCursor();
32
33 void open(const Trie &trie,
34 const String &min_str,
35 const String &max_str,
36 UInt32 offset = 0,
37 UInt32 limit = MAX_UINT32,
38 UInt32 flags = 0);
39
40 void open(const Trie &trie,
41 UInt32 min_id,
42 UInt32 max_id,
43 UInt32 offset = 0,
44 UInt32 limit = MAX_UINT32,
45 UInt32 flags = 0);
46
47 void close();
48
49 const Key &next();
50
51 UInt32 offset() const {
52 return offset_;
53 }
54 UInt32 limit() const {
55 return limit_;
56 }
57 UInt32 flags() const {
58 return flags_;
59 }
60
61 private:
62 const Trie *trie_;
63 UInt32 offset_;
64 UInt32 limit_;
65 UInt32 flags_;
66
67 UInt32 cur_;
68 UInt32 end_;
69 UInt32 count_;
70
71 IdCursor(const Trie &trie, UInt32 offset, UInt32 limit, UInt32 flags);
72
73 UInt32 fix_flags(UInt32 flags) const;
74 void init(UInt32 min_id, UInt32 max_id);
75 void swap(IdCursor *cursor);
76
77 // Disallows copy and assignment.
78 IdCursor(const IdCursor &);
79 IdCursor &operator=(const IdCursor &);
80};
81
82} // namespace dat
83} // namespace grn
84