susumu.yata
null+****@clear*****
Tue Jul 23 13:23:05 JST 2013
susumu.yata 2013-07-23 13:23:05 +0900 (Tue, 23 Jul 2013) New Revision: 7c5ae7c6d81aba68bf04d6d747748daad1446fe5 https://github.com/groonga/grnxx/commit/7c5ae7c6d81aba68bf04d6d747748daad1446fe5 Message: Add grnxx::map::CommonHeader. Added files: lib/grnxx/map/common_header.cpp lib/grnxx/map/common_header.hpp Modified files: lib/grnxx/map/Makefile.am Modified: lib/grnxx/map/Makefile.am (+2 -0) =================================================================== --- lib/grnxx/map/Makefile.am 2013-07-22 16:21:07 +0900 (dc73aca) +++ lib/grnxx/map/Makefile.am 2013-07-23 13:23:05 +0900 (296bff7) @@ -18,6 +18,7 @@ libgrnxx_map_la_SOURCES = \ array_map.cpp \ bytes_array.cpp \ bytes_pool.cpp \ + common_header.cpp \ cursor_impl.cpp \ double_array.cpp \ hash_table.cpp \ @@ -30,6 +31,7 @@ libgrnxx_map_include_HEADERS = \ array_map.hpp \ bytes_array.hpp \ bytes_pool.hpp \ + common_header.hpp \ cursor_impl.hpp \ double_array.hpp \ hash_table.hpp \ Added: lib/grnxx/map/common_header.cpp (+38 -0) 100644 =================================================================== --- /dev/null +++ lib/grnxx/map/common_header.cpp 2013-07-23 13:23:05 +0900 (a5cb0a6) @@ -0,0 +1,38 @@ +/* + 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/map/common_header.hpp" + +namespace grnxx { +namespace map { +namespace { + +// Implementations are defined in a namespace "grnxx::map". +constexpr char FORMAT_PREFIX[] = "grnxx::map::"; + +} // namespace + +CommonHeader::CommonHeader(const char *format, MapType type) + : common_header_(format), + type_(type) {} + +CommonHeader::operator bool() const { + return common_header_.format().starts_with(FORMAT_PREFIX); +} + +} // namespace map +} // namespace grnxx Added: lib/grnxx/map/common_header.hpp (+57 -0) 100644 =================================================================== --- /dev/null +++ lib/grnxx/map/common_header.hpp 2013-07-23 13:23:05 +0900 (aef4a60) @@ -0,0 +1,57 @@ +/* + 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_MAP_HEADER_HPP +#define GRNXX_MAP_HEADER_HPP + +#include "grnxx/bytes.hpp" +#include "grnxx/common_header.hpp" +#include "grnxx/map.hpp" + +namespace grnxx { +namespace map { + +class CommonHeader { + public: + // Create a common header with "format", the current version, and "type". + CommonHeader(const char *format, MapType type); + + // Return true iff the header seems to be correct. + explicit operator bool() const; + + // Return the format string. + Bytes format() const { + return common_header_.format(); + } + // Return the version string. + Bytes version() const { + return common_header_.version(); + } + // Return the implementation type. + MapType type() const { + return type_; + } + + private: + grnxx::CommonHeader common_header_; + MapType type_; +}; + +} // namespace map +} // namespace grnxx + +#endif // GRNXX_MAP_HEADER_HPP -------------- next part -------------- HTML����������������������������...Download