Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cursor-factory.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2 -*- */
2 /* Copyright(C) 2011 Brazil
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License version 2.1 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public
14  License along with this library; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "cursor-factory.hpp"
19 #include "id-cursor.hpp"
20 #include "key-cursor.hpp"
21 #include "prefix-cursor.hpp"
22 #include "predictive-cursor.hpp"
23 
24 #include <new>
25 
26 namespace grn {
27 namespace dat {
28 
30  const void *min_ptr, UInt32 min_length,
31  const void *max_ptr, UInt32 max_length,
32  UInt32 offset,
33  UInt32 limit,
34  UInt32 flags) {
35  GRN_DAT_THROW_IF(PARAM_ERROR, &trie == NULL);
36 
37  const UInt32 cursor_type = flags & CURSOR_TYPE_MASK;
38  switch (cursor_type) {
39  case ID_RANGE_CURSOR: {
40  IdCursor *cursor = new (std::nothrow) IdCursor;
41  GRN_DAT_THROW_IF(MEMORY_ERROR, cursor == NULL);
42  try {
43  cursor->open(trie, String(min_ptr, min_length),
44  String(max_ptr, max_length), offset, limit, flags);
45  } catch (...) {
46  delete cursor;
47  throw;
48  }
49  return cursor;
50  }
51  case KEY_RANGE_CURSOR: {
52  KeyCursor *cursor = new (std::nothrow) KeyCursor;
53  GRN_DAT_THROW_IF(MEMORY_ERROR, cursor == NULL);
54  try {
55  cursor->open(trie, String(min_ptr, min_length),
56  String(max_ptr, max_length), offset, limit, flags);
57  } catch (...) {
58  delete cursor;
59  throw;
60  }
61  return cursor;
62  }
63  case PREFIX_CURSOR: {
64  PrefixCursor *cursor = new (std::nothrow) PrefixCursor;
65  GRN_DAT_THROW_IF(MEMORY_ERROR, cursor == NULL);
66  try {
67  cursor->open(trie, String(max_ptr, max_length), min_length,
68  offset, limit, flags);
69  } catch (...) {
70  delete cursor;
71  throw;
72  }
73  return cursor;
74  }
75  case PREDICTIVE_CURSOR: {
76  PredictiveCursor *cursor = new (std::nothrow) PredictiveCursor;
77  GRN_DAT_THROW_IF(MEMORY_ERROR, cursor == NULL);
78  try {
79  cursor->open(trie, String(min_ptr, min_length),
80  offset, limit, flags);
81  } catch (...) {
82  delete cursor;
83  throw;
84  }
85  return cursor;
86  }
87  default: {
88  GRN_DAT_THROW(PARAM_ERROR, "unknown cursor type");
89  }
90  }
91 }
92 
93 } // namespace dat
94 } // namespace grn