[Groonga-commit] groonga/groonga [master] added grn::dat::CursorFactory and fixed a bug of grn::dat::KeyCursor.

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2011年 6月 27日 (月) 11:36:43 JST


Susumu Yata	2011-06-27 02:36:43 +0000 (Mon, 27 Jun 2011)

  New Revision: 50f3709cca9509e017115870300d9d52fbaccc55

  Log:
    added grn::dat::CursorFactory and fixed a bug of grn::dat::KeyCursor.

  Added files:
    lib/dat/cursor-factory.cpp
    lib/dat/cursor-factory.hpp
  Modified files:
    lib/dat/Makefile.am
    lib/dat/key-cursor.cpp

  Modified: lib/dat/Makefile.am (+2 -0)
===================================================================
--- lib/dat/Makefile.am    2011-06-27 00:26:52 +0000 (176feb0)
+++ lib/dat/Makefile.am    2011-06-27 02:36:43 +0000 (d66403e)
@@ -4,6 +4,7 @@ DEFS += -D_REENTRANT $(GRN_DEFS)
 
 libgrndat_la_SOURCES =				\
 	common-prefix-search-cursor.cpp		\
+	cursor-factory.cpp			\
 	id-cursor.cpp				\
 	key-cursor.cpp				\
 	predictive-search-cursor.cpp		\
@@ -14,6 +15,7 @@ noinst_HEADERS =				\
 	block.hpp				\
 	check.hpp				\
 	common-prefix-search-cursor.hpp		\
+	cursor-factory.hpp			\
 	cursor.hpp				\
 	dat.hpp					\
 	header.hpp				\

  Added: lib/dat/cursor-factory.cpp (+73 -0) 100644
===================================================================
--- /dev/null
+++ lib/dat/cursor-factory.cpp    2011-06-27 02:36:43 +0000 (d22515b)
@@ -0,0 +1,73 @@
+#include "cursor-factory.hpp"
+#include "id-cursor.hpp"
+#include "key-cursor.hpp"
+#include "common-prefix-search-cursor.hpp"
+#include "predictive-search-cursor.hpp"
+
+namespace grn {
+namespace dat {
+
+Cursor *CursorFactory::open(const Trie &trie,
+                            const void *min_ptr, UInt32 min_length,
+                            const void *max_ptr, UInt32 max_length,
+                            UInt32 offset,
+                            UInt32 limit,
+                            UInt32 flags) {
+  const UInt32 cursor_type = flags & CURSOR_TYPE_MASK;
+  switch (cursor_type) {
+    case ID_RANGE_CURSOR: {
+      IdCursor *cursor = new IdCursor;
+      try {
+        cursor->open(trie, min_ptr, min_length, max_ptr, max_length,
+                     offset, limit, flags);
+      } catch (...) {
+        delete cursor;
+        throw;
+      }
+      return cursor;
+    }
+    case KEY_RANGE_CURSOR: {
+      KeyCursor *cursor = new KeyCursor;
+      try {
+        cursor->open(trie, min_ptr, min_length, max_ptr, max_length,
+                     offset, limit, flags);
+      } catch (...) {
+        delete cursor;
+        throw;
+      }
+      return cursor;
+    }
+    case COMMON_PREFIX_CURSOR: {
+      CommonPrefixSearchCursor *cursor = new CommonPrefixSearchCursor;
+      try {
+        cursor->open(trie, max_ptr, min_length, max_length,
+                     offset, limit, flags);
+      } catch (...) {
+        delete cursor;
+        throw;
+      }
+      return cursor;
+    }
+    case PREDICTIVE_CURSOR: {
+      PredictiveSearchCursor *cursor = new PredictiveSearchCursor;
+      try {
+        cursor->open(trie, min_ptr, min_length,
+                     offset, limit, flags);
+      } catch (...) {
+        delete cursor;
+        throw;
+      }
+      return cursor;
+    }
+    default: {
+      GRN_DAT_PARAM_ERROR_IF((cursor_type != ID_RANGE_CURSOR) &&
+                             (cursor_type != KEY_RANGE_CURSOR) &&
+                             (cursor_type != COMMON_PREFIX_CURSOR) &&
+                             (cursor_type != PREDICTIVE_CURSOR));
+    }
+  }
+  return NULL;
+}
+
+}  // namespace grn
+}  // namespace dat

  Added: lib/dat/cursor-factory.hpp (+28 -0) 100644
===================================================================
--- /dev/null
+++ lib/dat/cursor-factory.hpp    2011-06-27 02:36:43 +0000 (6e632fa)
@@ -0,0 +1,28 @@
+#ifndef GRN_DAT_CURSOR_FACTORY_H
+#define GRN_DAT_CURSOR_FACTORY_H
+
+#include "cursor.hpp"
+#include "trie.hpp"
+
+namespace grn {
+namespace dat {
+
+class CursorFactory {
+ public:
+  static Cursor *open(const Trie &trie,
+                      const void *min_ptr, UInt32 min_length,
+                      const void *max_ptr, UInt32 max_length,
+                      UInt32 offset = 0,
+                      UInt32 limit = UINT32_MAX,
+                      UInt32 flags = 0);
+
+ private:
+  // Disallows copy and assignment.
+  CursorFactory(const CursorFactory &);
+  CursorFactory &operator=(const CursorFactory &);
+};
+
+}  // namespace grn
+}  // namespace dat
+
+#endif  // GRN_DAT_CURSOR_FACTORY_H

  Modified: lib/dat/key-cursor.cpp (+4 -5)
===================================================================
--- lib/dat/key-cursor.cpp    2011-06-27 00:26:52 +0000 (90c8d72)
+++ lib/dat/key-cursor.cpp    2011-06-27 02:36:43 +0000 (b66bc64)
@@ -10,7 +10,7 @@ KeyCursor::KeyCursor()
     : trie_(NULL),
       offset_(0),
       limit_(UINT32_MAX),
-      flags_(PREDICTIVE_CURSOR),
+      flags_(KEY_RANGE_CURSOR),
       buf_(),
       count_(0),
       max_count_(0),
@@ -22,7 +22,6 @@ KeyCursor::~KeyCursor() {
   close();
 }
 
-
 void KeyCursor::open(const Trie &trie,
                      const void *min_ptr, UInt32 min_length,
                      const void *max_ptr, UInt32 max_length,
@@ -43,7 +42,7 @@ void KeyCursor::close() {
   trie_ = NULL;
   offset_ = 0;
   limit_ = UINT32_MAX;
-  flags_ = PREDICTIVE_CURSOR;
+  flags_ = KEY_RANGE_CURSOR;
   buf_.clear();
   count_ = 0;
   max_count_ = 0;
@@ -70,8 +69,8 @@ bool KeyCursor::next(Key *key) {
 UInt32 KeyCursor::fix_flags(UInt32 flags) const {
   const UInt32 cursor_type = flags & CURSOR_TYPE_MASK;
   GRN_DAT_PARAM_ERROR_IF((cursor_type != 0) &&
-                         (cursor_type != PREDICTIVE_CURSOR));
-  flags |= PREDICTIVE_CURSOR;
+                         (cursor_type != KEY_RANGE_CURSOR));
+  flags |= KEY_RANGE_CURSOR;
 
   const UInt32 cursor_order = flags & CURSOR_ORDER_MASK;
   GRN_DAT_PARAM_ERROR_IF((cursor_order != 0) &&




Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る