[Groonga-mysql-commit] mroonga/mroonga [master] experimental: create PathMapper

Back to archive index

null+****@clear***** null+****@clear*****
2012年 3月 19日 (月) 17:46:05 JST


Kouhei Sutou	2012-03-19 17:46:05 +0900 (Mon, 19 Mar 2012)

  New Revision: 5da5fb9a3bb419721367ece3f677fb4ab7c38a21

  Log:
    experimental: create PathMapper
    
    * mrn_db_path_gen() -> PathMapper.db_path()
    * mrn_db_name_gen() -> PathMapper.db_name()

  Added files:
    lib/Makefile.am
    lib/mrn_path_mapper.cpp
    lib/mrn_path_mapper.hpp
    test/unit/test_mrn_path_mapper.cpp
  Modified files:
    Makefile.am
    configure.ac
    test/unit/Makefile.am

  Modified: Makefile.am (+2 -1)
===================================================================
--- Makefile.am    2012-03-19 16:13:20 +0900 (c294263)
+++ Makefile.am    2012-03-19 17:46:05 +0900 (51eacf7)
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = 1.9.7
 
 LOCALES = ja
 
-AM_CPPFLAGS = $(MYSQL_INC) $(GROONGA_CFLAGS) $(MYSQL_VERSION_CFLAGS)
+AM_CPPFLAGS = $(MYSQL_INC) $(GROONGA_CFLAGS) $(MYSQL_VERSION_CFLAGS) -I$(top_srcdir)/lib
 ACLOCAL_AMFLAGS = $$ACLOCAL_ARGS
 
 noinst_HEADERS =				\
@@ -41,6 +41,7 @@ libmroonga_a_CFLAGS      = $(AM_CFLAGS) $(MYSQL_CFLAGS)
 libmroonga_a_SOURCES     = $(sources)
 
 SUBDIRS =					\
+	lib					\
 	test					\
 	doc					\
 	tools					\

  Modified: configure.ac (+1 -0)
===================================================================
--- configure.ac    2012-03-19 16:13:20 +0900 (5dad7a9)
+++ configure.ac    2012-03-19 17:46:05 +0900 (6098e02)
@@ -297,6 +297,7 @@ CXXFLAGS="$CXXFLAGS -Werror -fno-implicit-templates -fno-exceptions -fno-rtti -f
 
 AC_CONFIG_FILES([
   Makefile
+  lib/Makefile
   test/Makefile
   test/unit/Makefile
   test/sql/Makefile

  Added: lib/Makefile.am (+12 -0) 100644
===================================================================
--- /dev/null
+++ lib/Makefile.am    2012-03-19 17:46:05 +0900 (b5f5428)
@@ -0,0 +1,12 @@
+AM_CPPFLAGS =					\
+	$(MYSQL_INC)				\
+	$(GROONGA_CFLAGS)			\
+	$(MYSQL_VERSION_CFLAGS)			\
+	-I$(top_srcdir)
+
+noinst_LTLIBRARIES =				\
+	libmroonga.la
+
+libmroonga_la_SOURCES =				\
+	mrn_path_mapper.cpp			\
+	mrn_path_mapper.hpp

  Added: lib/mrn_path_mapper.cpp (+75 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrn_path_mapper.cpp    2012-03-19 17:46:05 +0900 (2e2eb2b)
@@ -0,0 +1,75 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2010 Tetsuro IKEDA
+  Copyright(C) 2011-2012 Kentoku SHIBA
+  Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "mrn_path_mapper.hpp"
+
+#include <string.h>
+
+namespace mrn {
+  PathMapper::PathMapper(const char *mysql_path)
+    : mysql_path_(mysql_path) {
+  }
+
+  /**
+   * "./${db}/${table}"                              ==> "${db}.mrn"
+   * "./${db}/"                                      ==> "${db}.mrn"
+   * "/tmp/mysql-test/var/tmp/mysqld.1/#sql27c5_1_0" ==>
+   *   "/tmp/mysql-test/var/tmp/mysqld.1/#sql27c5_1_0.mrn"
+   */
+  const char *PathMapper::db_path() {
+    if (strncmp(mysql_path_, "./", 2) == 0) {
+      int i = 2, j = 0, len;
+      len = strlen(mysql_path_);
+      while (mysql_path_[i] != '/' && i < len) {
+        db_path_[j++] = mysql_path_[i++];
+      }
+      db_path_[j] = '\0';
+    } else {
+      strcpy(db_path_, mysql_path_);
+    }
+    strcat(db_path_, MRN_DB_FILE_SUFFIX);
+    return db_path_;
+  }
+
+  /**
+   * "./${db}/${table}"                              ==> "${db}"
+   * "./${db}/"                                      ==> "${db}"
+   * "/tmp/mysql-test/var/tmp/mysqld.1/#sql27c5_1_0" ==>
+   *   "/tmp/mysql-test/var/tmp/mysqld.1/#sql27c5_1_0"
+   */
+  const char *PathMapper::db_name() {
+    if (strncmp(mysql_path_, "./", 2) == 0) {
+      int i = 2, j = 0, len;
+      len = strlen(mysql_path_);
+      while (mysql_path_[i] != '/' && i < len) {
+        db_name_[j++] = mysql_path_[i++];
+      }
+      db_name_[j] = '\0';
+    } else {
+      strcpy(db_name_, mysql_path_);
+    }
+    return db_name_;
+  }
+}

  Added: lib/mrn_path_mapper.hpp (+40 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrn_path_mapper.hpp    2012-03-19 17:46:05 +0900 (d24a3af)
@@ -0,0 +1,40 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2010 Tetsuro IKEDA
+  Copyright(C) 2010-2012 Kentoku SHIBA
+  Copyright(C) 2011-2012 Kouhei Sutou <kou****@clear*****>
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifndef MRN_PATH_MAPPER_HPP_
+#define MRN_PATH_MAPPER_HPP_
+
+#include "mrn_sys.h"
+
+namespace mrn {
+  class PathMapper {
+  public:
+    PathMapper(const char* mysql_path);
+    const char* db_path();
+    const char* db_name();
+  private:
+    const char* mysql_path_;
+    char db_path_[MRN_MAX_PATH_SIZE];
+    char db_name_[MRN_MAX_PATH_SIZE];
+  };
+}
+
+#endif /* MRN_PATH_MAPPER_HPP_ */

  Modified: test/unit/Makefile.am (+13 -4)
===================================================================
--- test/unit/Makefile.am    2012-03-19 16:13:20 +0900 (fbb7ec0)
+++ test/unit/Makefile.am    2012-03-19 17:46:05 +0900 (1214cf1)
@@ -1,11 +1,14 @@
 if WITH_CUTTER
-noinst_LTLIBRARIES = test_mrn_sys.la
+noinst_LTLIBRARIES =				\
+	test_mrn_sys.la				\
+	test_mrn_path_mapper.la
 endif
 
 AM_CPPFLAGS =					\
 	$(GROONGA_CFLAGS)			\
-	$(CPPCUTTER_CFLAGS)
-AM_INCLUDES = -I$(top_srcdir)
+	$(CPPCUTTER_CFLAGS)			\
+	-I$(top_srcdir)				\
+	-I$(top_srcdir)/lib
 ACLOCAL_AMFLAGS = $$ACLOCAL_ARGS
 
 DEFS          = @DEFS@
@@ -17,7 +20,7 @@ LDFLAGS =					\
 	-no-undefined
 
 LIBS =						\
-	$(CUTTER_LIBS)				\
+	$(CPPCUTTER_LIBS)			\
 	$(GROONGA_LIBS)				\
 	$(MECAB_LIBS)
 
@@ -26,3 +29,9 @@ EXTERNAL_SRC = ../../mrn_sys.c
 test_mrn_sys_la_SOURCES =			\
 	$(EXTERNAL_SRC)				\
 	test_mrn_sys.cpp
+
+test_mrn_path_mapper_la_SOURCES =		\
+	test_mrn_path_mapper.cpp
+
+test_mrn_path_mapper_la_LIBADD =		\
+	$(top_builddir)/lib/libmroonga.la

  Added: test/unit/test_mrn_path_mapper.cpp (+62 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/test_mrn_path_mapper.cpp    2012-03-19 17:46:05 +0900 (91ed87a)
@@ -0,0 +1,62 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2012 Kouhei Sutou <kou****@clear*****>
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <string.h>
+#include <cppcutter.h>
+
+#include <mrn_path_mapper.hpp>
+
+namespace test_mrn_path_mapper {
+  namespace db_path {
+    void test_normal_db() {
+      mrn::PathMapper mapper("./db/");
+      cppcut_assert_equal("db.mrn", mapper.db_path());
+    }
+
+    void test_normal_table() {
+      mrn::PathMapper mapper("./db/table");
+      cppcut_assert_equal("db.mrn", mapper.db_path());
+    }
+
+    void test_temporary_table() {
+      mrn::PathMapper mapper("/tmp/mysqld.1/#sql27c5_1_0");
+      cppcut_assert_equal("/tmp/mysqld.1/#sql27c5_1_0.mrn",
+                          mapper.db_path());
+    }
+  }
+
+  namespace db_name {
+    void test_normal_db() {
+      mrn::PathMapper mapper("./db/");
+      cppcut_assert_equal("db", mapper.db_name());
+    }
+
+    void test_normal_table() {
+      mrn::PathMapper mapper("./db/table");
+      cppcut_assert_equal("db", mapper.db_name());
+    }
+
+    void test_temporary_table() {
+      mrn::PathMapper mapper("/tmp/mysqld.1/#sql27c5_1_0");
+      cppcut_assert_equal("/tmp/mysqld.1/#sql27c5_1_0",
+                          mapper.db_name());
+    }
+  }
+}
+




Groonga-mysql-commit メーリングリストの案内
Back to archive index