[Groonga-commit] groonga/grnxx at 168cbab [master] Modify grnxx::CommonHeader.

Back to archive index

susumu.yata null+****@clear*****
Mon Jul 8 19:11:03 JST 2013


susumu.yata	2013-07-08 19:11:03 +0900 (Mon, 08 Jul 2013)

  New Revision: 168cbab44d3826ae7dd211714d98c52df9c2d65d
  https://github.com/groonga/grnxx/commit/168cbab44d3826ae7dd211714d98c52df9c2d65d

  Message:
    Modify grnxx::CommonHeader.

  Modified files:
    lib/grnxx/common_header.cpp
    lib/grnxx/common_header.hpp
    lib/grnxx/storage/header.cpp
    lib/grnxx/storage/header.hpp

  Modified: lib/grnxx/common_header.cpp (+14 -0)
===================================================================
--- lib/grnxx/common_header.cpp    2013-07-08 16:17:21 +0900 (4df0e13)
+++ lib/grnxx/common_header.cpp    2013-07-08 19:11:03 +0900 (1339e6a)
@@ -52,4 +52,18 @@ CommonHeader::CommonHeader(const char *format) : format_{}, version_{} {
   std::memcpy(version_, current_version, current_version_length);
 }
 
+Bytes CommonHeader::format() const {
+  if (format_[FORMAT_SIZE - 1] == '\0') {
+    return Bytes(format_);
+  }
+  return Bytes(format_, FORMAT_SIZE);
+}
+
+Bytes CommonHeader::version() const {
+  if (version_[VERSION_SIZE - 1] == '\0') {
+    return Bytes(version_);
+  }
+  return Bytes(version_, VERSION_SIZE);
+}
+
 }  // namespace grnxx

  Modified: lib/grnxx/common_header.hpp (+2 -6)
===================================================================
--- lib/grnxx/common_header.hpp    2013-07-08 16:17:21 +0900 (357275b)
+++ lib/grnxx/common_header.hpp    2013-07-08 19:11:03 +0900 (cd3f0ec)
@@ -37,13 +37,9 @@ class CommonHeader {
   explicit CommonHeader(const char *format);
 
   // Return the format string.
-  Bytes format() const {
-    return Bytes(format_, FORMAT_SIZE);
-  }
+  Bytes format() const;
   // Return the version string.
-  Bytes version() const {
-    return Bytes(version_, VERSION_SIZE);
-  }
+  Bytes version() const;
 
  private:
   char format_[FORMAT_SIZE];

  Modified: lib/grnxx/storage/header.cpp (+3 -6)
===================================================================
--- lib/grnxx/storage/header.cpp    2013-07-08 16:17:21 +0900 (0a2af79)
+++ lib/grnxx/storage/header.cpp    2013-07-08 19:11:03 +0900 (44011f0)
@@ -26,9 +26,7 @@ namespace grnxx {
 namespace storage {
 namespace {
 
-// The format string.
-constexpr char STORAGE_FORMAT[CommonHeader::FORMAT_SIZE] =
-    "grnxx::Storage";
+constexpr char FORMAT_STRING[] = "grnxx::Storage";
 
 }  // namespace
 
@@ -58,12 +56,11 @@ Header::Header()
 }
 
 Header::operator bool() const {
-  return common_header.format() ==
-         Bytes(STORAGE_FORMAT, CommonHeader::FORMAT_SIZE);
+  return common_header.format() == FORMAT_STRING;
 }
 
 void Header::validate() {
-  common_header = CommonHeader(STORAGE_FORMAT);
+  common_header = CommonHeader(FORMAT_STRING);
 }
 
 }  // namespace storage

  Modified: lib/grnxx/storage/header.hpp (+3 -3)
===================================================================
--- lib/grnxx/storage/header.hpp    2013-07-08 16:17:21 +0900 (83fc932)
+++ lib/grnxx/storage/header.hpp    2013-07-08 19:11:03 +0900 (087a1aa)
@@ -74,13 +74,13 @@ struct Header {
   Mutex file_mutex;
   uint8_t reserved_2[88];
 
-  // Initialize the members except "format".
+  // Initialize the members except "common_header".
   Header();
 
-  // Return true if the header seems to be correct.
+  // Return true iff the header seems to be correct.
   explicit operator bool() const;
 
-  // Initialize "format".
+  // Initialize "common_header".
   void validate();
 };
 
-------------- next part --------------
HTML����������������������������...
Download 



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