[Groonga-commit] groonga/grnxx at 08aabf8 [master] Add grnxx::CommonHeader.

Back to archive index

susumu.yata null+****@clear*****
Mon Jul 8 16:05:27 JST 2013


susumu.yata	2013-07-08 16:05:27 +0900 (Mon, 08 Jul 2013)

  New Revision: 08aabf846295046c11a46bedca562a9e60ab5264
  https://github.com/groonga/grnxx/commit/08aabf846295046c11a46bedca562a9e60ab5264

  Message:
    Add grnxx::CommonHeader.

  Added files:
    lib/grnxx/common_header.cpp
    lib/grnxx/common_header.hpp
  Modified files:
    lib/grnxx/Makefile.am

  Modified: lib/grnxx/Makefile.am (+2 -0)
===================================================================
--- lib/grnxx/Makefile.am    2013-07-08 12:37:28 +0900 (cfd2ae6)
+++ lib/grnxx/Makefile.am    2013-07-08 16:05:27 +0900 (0909220)
@@ -18,6 +18,7 @@ libgrnxx_la_SOURCES =			\
 	backtrace.cpp			\
 	broken_down_time.cpp		\
 	charset.cpp			\
+	common_header.cpp		\
 	duration.cpp			\
 	errno.cpp			\
 	geo_point.cpp			\
@@ -44,6 +45,7 @@ libgrnxx_include_HEADERS =		\
 	broken_down_time.hpp		\
 	bytes.hpp			\
 	charset.hpp			\
+	common_header.hpp		\
 	duration.hpp			\
 	errno.hpp			\
 	exception.hpp			\

  Added: lib/grnxx/common_header.cpp (+55 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/common_header.cpp    2013-07-08 16:05:27 +0900 (4df0e13)
@@ -0,0 +1,55 @@
+/*
+  Copyright (C) 2012-2013  Brazil, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include "grnxx/common_header.hpp"
+
+#include <cstring>
+
+#include "grnxx/exception.hpp"
+#include "grnxx/grnxx.hpp"
+#include "grnxx/logger.hpp"
+
+namespace grnxx {
+
+CommonHeader::CommonHeader(const char *format) : format_{}, version_{} {
+  // Copy the format string.
+  if (!format) {
+    GRNXX_ERROR() << "invalid format: format = nullptr";
+    throw LogicError();
+  }
+  const std::size_t format_length = std::strlen(format);
+  if (format_length >= FORMAT_SIZE) {
+    GRNXX_ERROR() << "too long format: format = " << format;
+    throw LogicError();
+  }
+  std::memcpy(format_, format, format_length);
+
+  // Copy the current version string.
+  const char * const current_version = Grnxx::version();
+  if (!current_version) {
+    GRNXX_ERROR() << "invalid version: current_version = nullptr";
+    throw LogicError();
+  }
+  const std::size_t current_version_length = std::strlen(current_version);
+  if (current_version_length >= VERSION_SIZE) {
+    GRNXX_ERROR() << "too long version: current_version = " << current_version;
+    throw LogicError();
+  }
+  std::memcpy(version_, current_version, current_version_length);
+}
+
+}  // namespace grnxx

  Added: lib/grnxx/common_header.hpp (+55 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/common_header.hpp    2013-07-08 16:05:27 +0900 (357275b)
@@ -0,0 +1,55 @@
+/*
+  Copyright (C) 2012-2013  Brazil, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef GRNXX_COMMON_HEADER_HPP
+#define GRNXX_COMMON_HEADER_HPP
+
+#include "grnxx/features.hpp"
+
+#include "grnxx/bytes.hpp"
+#include "grnxx/types.hpp"
+
+namespace grnxx {
+
+class CommonHeader {
+ public:
+  // Buffer size for "format_" and "version_".
+  static constexpr size_t FORMAT_SIZE  = 64;
+  static constexpr size_t VERSION_SIZE = 32;
+
+  // Trivial default constructor.
+  CommonHeader() = default;
+  // Create a common header with "format" and the current version.
+  explicit CommonHeader(const char *format);
+
+  // Return the format string.
+  Bytes format() const {
+    return Bytes(format_, FORMAT_SIZE);
+  }
+  // Return the version string.
+  Bytes version() const {
+    return Bytes(version_, VERSION_SIZE);
+  }
+
+ private:
+  char format_[FORMAT_SIZE];
+  char version_[VERSION_SIZE];
+};
+
+}  // namespace grnxx
+
+#endif  // GRNXX_COMMON_HEADER_HPP
-------------- next part --------------
HTML����������������������������...
Download 



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