[Groonga-commit] groonga/grnxx at b032b14 [master] Add operator bool() to grnxx::StorageOptions.

Back to archive index

susumu.yata null+****@clear*****
Mon May 13 19:03:10 JST 2013


susumu.yata	2013-05-13 19:03:10 +0900 (Mon, 13 May 2013)

  New Revision: b032b14cdcdcd9bf99d03343f974f00731ca5e36
  https://github.com/groonga/grnxx/commit/b032b14cdcdcd9bf99d03343f974f00731ca5e36

  Message:
    Add operator bool() to grnxx::StorageOptions.

  Modified files:
    lib/grnxx/storage.cpp
    lib/grnxx/storage.hpp
    lib/grnxx/storage/storage_impl.cpp

  Modified: lib/grnxx/storage.cpp (+1 -1)
===================================================================
--- lib/grnxx/storage.cpp    2013-05-13 18:43:07 +0900 (463cd7c)
+++ lib/grnxx/storage.cpp    2013-05-13 19:03:10 +0900 (9af0541)
@@ -81,7 +81,7 @@ StorageOptions::StorageOptions()
       max_num_files(MAX_NUM_FILES_DEFAULT),
       root_size(ROOT_SIZE_DEFAULT) {}
 
-bool StorageOptions::is_valid() const {
+StorageOptions::operator bool() const {
   if ((max_file_size < MAX_FILE_SIZE_LOWER_LIMIT) ||
       (max_file_size > MAX_FILE_SIZE_UPPER_LIMIT)) {
     return false;

  Modified: lib/grnxx/storage.hpp (+8 -4)
===================================================================
--- lib/grnxx/storage.hpp    2013-05-13 18:43:07 +0900 (081f3e8)
+++ lib/grnxx/storage.hpp    2013-05-13 19:03:10 +0900 (e7de31a)
@@ -76,8 +76,13 @@ struct StorageOptions {
   // Initialize the members with the default parameters.
   StorageOptions();
 
+  // Return true iff the options are valid.
+  explicit operator bool() const;
+  // TODO: Obsolete. Use operator bool() instead.
   // Return true if the parameters are valid.
-  bool is_valid() const;
+  bool is_valid() const {
+    return static_cast<bool>(*this);
+  }
 };
 
 StringBuilder &operator<<(StringBuilder &builder,
@@ -95,11 +100,10 @@ class StorageNode {
   explicit operator bool() const {
     return header_ != nullptr;
   }
-
+  // TODO: Obsolete. Use operator bool() instead.
   // Return true iff "header_" != nullptr.
-  // TODO: To be removed, use operator bool instead.
   bool is_valid() const {
-    return header_ != nullptr;
+    return static_cast<bool>(*this);
   }
 
   // Return the ID.

  Modified: lib/grnxx/storage/storage_impl.cpp (+2 -2)
===================================================================
--- lib/grnxx/storage/storage_impl.cpp    2013-05-13 18:43:07 +0900 (a60aad8)
+++ lib/grnxx/storage/storage_impl.cpp    2013-05-13 19:03:10 +0900 (80ba2c9)
@@ -88,7 +88,7 @@ StorageImpl::~StorageImpl() {}
 
 StorageImpl *StorageImpl::create(const char *path, StorageFlags flags,
                                  const StorageOptions &options) {
-  if (!options.is_valid()) {
+  if (!options) {
     GRNXX_ERROR() << "invalid argument: options = " << options;
     return nullptr;
   }
@@ -131,7 +131,7 @@ StorageImpl *StorageImpl::open_or_create(const char *path, StorageFlags flags,
     GRNXX_ERROR() << "invalid argument: path = nullptr";
     return nullptr;
   }
-  if (!options.is_valid()) {
+  if (!options) {
     GRNXX_ERROR() << "invalid argument: options = " << options;
     return nullptr;
   }
-------------- next part --------------
HTML����������������������������...
Download 



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