[Groonga-commit] groonga/groonga [master] improve geo point inspection format.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 7月 30日 (金) 17:16:33 JST


Kouhei Sutou	2010-07-30 08:16:33 +0000 (Fri, 30 Jul 2010)

  New Revision: 3f30b027c151254970fb18966bca67c70d6986f9

  Log:
    improve geo point inspection format.

  Modified files:
    lib/util.c
    test/unit/core/test-inspect.c

  Modified: lib/util.c (+58 -12)
===================================================================
--- lib/util.c    2010-07-30 04:35:04 +0000 (57d762d)
+++ lib/util.c    2010-07-30 08:16:33 +0000 (62e234f)
@@ -389,6 +389,45 @@ grn_table_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
 }
 
 static grn_rc
+grn_geo_point_inspect_point(grn_ctx *ctx, grn_obj *buf, int point)
+{
+  GRN_TEXT_PUTS(ctx, buf, "(");
+  grn_text_itoa(ctx, buf, point / 1000 / 3600 % 3600);
+  GRN_TEXT_PUTS(ctx, buf, ", ");
+  grn_text_itoa(ctx, buf, point / 1000 / 60 % 60);
+  GRN_TEXT_PUTS(ctx, buf, ", ");
+  grn_text_itoa(ctx, buf, point / 1000 % 60);
+  GRN_TEXT_PUTS(ctx, buf, ", ");
+  grn_text_itoa(ctx, buf, point % 1000);
+  GRN_TEXT_PUTS(ctx, buf, ")");
+}
+
+static grn_rc
+grn_geo_point_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
+{
+  int latitude, longitude;
+
+  GRN_GEO_POINT_VALUE(obj, latitude, longitude);
+
+  GRN_TEXT_PUTS(ctx, buf, "[");
+  GRN_TEXT_PUTS(ctx, buf, "(");
+  grn_text_itoa(ctx, buf, latitude);
+  GRN_TEXT_PUTS(ctx, buf, ",");
+  grn_text_itoa(ctx, buf, longitude);
+  GRN_TEXT_PUTS(ctx, buf, ")");
+
+  GRN_TEXT_PUTS(ctx, buf, " (");
+  grn_geo_point_inspect_point(ctx, buf, latitude);
+  GRN_TEXT_PUTS(ctx, buf, ",");
+  grn_geo_point_inspect_point(ctx, buf, longitude);
+  GRN_TEXT_PUTS(ctx, buf, ")");
+
+  GRN_TEXT_PUTS(ctx, buf, "]");
+
+  return GRN_SUCCESS;
+}
+
+static grn_rc
 grn_record_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
 {
   grn_id id;
@@ -484,18 +523,25 @@ grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
 
   switch (obj->header.type) {
   case GRN_BULK :
-    domain = grn_ctx_at(ctx, obj->header.domain);
-    if (domain) {
-      grn_id type = domain->header.type;
-      grn_obj_unlink(ctx, domain);
-      switch (type) {
-      case GRN_TABLE_HASH_KEY :
-      case GRN_TABLE_PAT_KEY :
-      case GRN_TABLE_NO_KEY :
-        grn_record_inspect(ctx, buffer, obj);
-        return buffer;
-      default :
-        break;
+    switch (obj->header.domain) {
+    case GRN_DB_TOKYO_GEO_POINT :
+    case GRN_DB_WGS84_GEO_POINT :
+      grn_geo_point_inspect(ctx, buffer, obj);
+      return buffer;
+    default :
+      domain = grn_ctx_at(ctx, obj->header.domain);
+      if (domain) {
+        grn_id type = domain->header.type;
+        grn_obj_unlink(ctx, domain);
+        switch (type) {
+        case GRN_TABLE_HASH_KEY :
+        case GRN_TABLE_PAT_KEY :
+        case GRN_TABLE_NO_KEY :
+          grn_record_inspect(ctx, buffer, obj);
+          return buffer;
+        default :
+          break;
+        }
       }
     }
     break;

  Modified: test/unit/core/test-inspect.c (+6 -2)
===================================================================
--- test/unit/core/test-inspect.c    2010-07-30 04:35:04 +0000 (16e5e24)
+++ test/unit/core/test-inspect.c    2010-07-30 08:16:33 +0000 (27c62c4)
@@ -349,7 +349,9 @@ test_geo_point_tokyo(void)
   geo_point_tokyo = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TOKYO_GEO_POINT);
   GRN_GEO_POINT_SET(context, geo_point_tokyo, takane_latitude, takane_longitude);
   inspected = grn_inspect(context, NULL, geo_point_tokyo);
-  cut_assert_equal_string("\"130194581x503802073\"", inspected_string());
+  cut_assert_equal_string("[(130194581,503802073) "
+                          "((36, 9, 54, 581),(139, 56, 42, 73))]",
+                          inspected_string());
 }
 
 void
@@ -363,7 +365,9 @@ test_geo_point_wgs84(void)
   geo_point_wgs84 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_WGS84_GEO_POINT);
   GRN_GEO_POINT_SET(context, geo_point_wgs84, takane_latitude, takane_longitude);
   inspected = grn_inspect(context, NULL, geo_point_wgs84);
-  cut_assert_equal_string("\"130226900x503769900\"", inspected_string());
+  cut_assert_equal_string("[(130226900,503769900) "
+                          "((36, 10, 26, 900),(139, 56, 9, 900))]",
+                          inspected_string());
 }
 
 void




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