[Groonga-commit] groonga/grnxx at 5c1eef9 [master] Move logging from array.hpp to array.cpp.

Back to archive index

susumu.yata null+****@clear*****
Wed Jul 3 17:03:53 JST 2013


susumu.yata	2013-07-03 17:03:53 +0900 (Wed, 03 Jul 2013)

  New Revision: 5c1eef9785c31c6d4add7cfd1bc193f93a870627
  https://github.com/groonga/grnxx/commit/5c1eef9785c31c6d4add7cfd1bc193f93a870627

  Message:
    Move logging from array.hpp to array.cpp.

  Modified files:
    lib/grnxx/array.cpp
    lib/grnxx/array.hpp

  Modified: lib/grnxx/array.cpp (+7 -1)
===================================================================
--- lib/grnxx/array.cpp    2013-07-03 13:08:03 +0900 (2c81e02)
+++ lib/grnxx/array.cpp    2013-07-03 17:03:53 +0900 (e33768b)
@@ -17,8 +17,14 @@
 */
 #include "grnxx/array.hpp"
 
+#include "grnxx/exception.hpp"
+#include "grnxx/logger.hpp"
+
 namespace grnxx {
 
-// Nothing to do.
+void ArrayErrorHandler::throw_memory_error() {
+  GRNXX_ERROR() << "new grnxx::Array failed";
+  throw MemoryError();
+}
 
 }  // namespace grnxx

  Modified: lib/grnxx/array.hpp (+7 -30)
===================================================================
--- lib/grnxx/array.hpp    2013-07-03 13:08:03 +0900 (410ec6b)
+++ lib/grnxx/array.hpp    2013-07-03 17:03:53 +0900 (d80cd9f)
@@ -20,12 +20,10 @@
 
 #include "grnxx/features.hpp"
 
-#include <cstring>
 #include <memory>
 #include <new>
 
 #include "grnxx/array_impl.hpp"
-#include "grnxx/logger.hpp"
 #include "grnxx/traits.hpp"
 #include "grnxx/types.hpp"
 
@@ -37,6 +35,11 @@ constexpr uint64_t ARRAY_DEFAULT_PAGE_SIZE            = 1ULL << 16;
 constexpr uint64_t ARRAY_DEFAULT_TABLE_SIZE           = 1ULL << 12;
 constexpr uint64_t ARRAY_DEFAULT_SECONDARY_TABLE_SIZE = 1ULL << 12;
 
+class ArrayErrorHandler {
+ public:
+  static void throw_memory_error();
+};
+
 template <typename T,
           uint64_t PAGE_SIZE = ARRAY_DEFAULT_PAGE_SIZE,
           uint64_t TABLE_SIZE = ARRAY_DEFAULT_TABLE_SIZE,
@@ -59,9 +62,6 @@ class Array {
   // Create an array.
   static Array *create(Storage *storage, uint32_t storage_node_id) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->impl_.create(storage, storage_node_id)) {
       return nullptr;
     }
@@ -72,9 +72,6 @@ class Array {
   static Array *create(Storage *storage, uint32_t storage_node_id,
                        ValueArg default_value) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->impl_.create(storage, storage_node_id, default_value)) {
       return nullptr;
     }
@@ -84,9 +81,6 @@ class Array {
   // Open an array.
   static Array *open(Storage *storage, uint32_t storage_node_id) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->impl_.open(storage, storage_node_id)) {
       return nullptr;
     }
@@ -146,11 +140,7 @@ class Array {
   static Array *create_instance() {
     Array * const array = new (std::nothrow) Array;
     if (!array) {
-      GRNXX_ERROR() << "new grnxx::Array failed: "
-                    << "value_size = " << sizeof(Value)
-                    << ", page_size = " << PAGE_SIZE
-                    << ", table_size = " << TABLE_SIZE
-                    << ", secondary_table_size = " << SECONDARY_TABLE_SIZE;
+      ArrayErrorHandler::throw_memory_error();
     }
     return array;
   }
@@ -183,9 +173,6 @@ class Array<bool, PAGE_SIZE_IN_BITS, TABLE_SIZE, SECONDARY_TABLE_SIZE> {
   // Create an array.
   static Array *create(Storage *storage, uint32_t storage_node_id) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->units_.create(storage, storage_node_id)) {
       return nullptr;
     }
@@ -196,9 +183,6 @@ class Array<bool, PAGE_SIZE_IN_BITS, TABLE_SIZE, SECONDARY_TABLE_SIZE> {
   static Array *create(Storage *storage, uint32_t storage_node_id,
                        ValueArg default_value) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->units_.create(storage, storage_node_id,
                               default_value ? ~Unit(0) : Unit(0))) {
       return nullptr;
@@ -209,9 +193,6 @@ class Array<bool, PAGE_SIZE_IN_BITS, TABLE_SIZE, SECONDARY_TABLE_SIZE> {
   // Open an array.
   static Array *open(Storage *storage, uint32_t storage_node_id) {
     std::unique_ptr<Array> array(create_instance());
-    if (!array) {
-      return nullptr;
-    }
     if (!array->units_.open(storage, storage_node_id)) {
       return nullptr;
     }
@@ -298,11 +279,7 @@ class Array<bool, PAGE_SIZE_IN_BITS, TABLE_SIZE, SECONDARY_TABLE_SIZE> {
   static Array *create_instance() {
     Array * const array = new (std::nothrow) Array;
     if (!array) {
-      GRNXX_ERROR() << "new grnxx::Array failed: "
-                    << "value_size = " << sizeof(Value)
-                    << ", page_size = " << PAGE_SIZE
-                    << ", table_size = " << TABLE_SIZE
-                    << ", secondary_table_size = " << SECONDARY_TABLE_SIZE;
+      ArrayErrorHandler::throw_memory_error();
     }
     return array;
   }
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index