[Groonga-commit] groonga/grnxx [master] Move grnxx::alpha::GeoPoint from map.hpp to geo_point.hpp.

Back to archive index

susumu.yata null+****@clear*****
Thu Apr 11 10:35:37 JST 2013


susumu.yata	2013-04-11 10:35:37 +0900 (Thu, 11 Apr 2013)

  New Revision: 310532ea155aace88fc4bcc83102ada5bec3a721
  https://github.com/groonga/grnxx/commit/310532ea155aace88fc4bcc83102ada5bec3a721

  Message:
    Move grnxx::alpha::GeoPoint from map.hpp to geo_point.hpp.

  Added files:
    lib/grnxx/alpha/geo_point.cpp
    lib/grnxx/alpha/geo_point.hpp
  Modified files:
    lib/grnxx/alpha/Makefile.am
    lib/grnxx/alpha/map.hpp

  Modified: lib/grnxx/alpha/Makefile.am (+2 -0)
===================================================================
--- lib/grnxx/alpha/Makefile.am    2013-04-09 18:20:00 +0900 (16f9358)
+++ lib/grnxx/alpha/Makefile.am    2013-04-11 10:35:37 +0900 (fb4537f)
@@ -9,11 +9,13 @@ libgrnxx_alpha_la_LDFLAGS = @AM_LTLDFLAGS@
 
 libgrnxx_alpha_la_SOURCES =		\
 	double_array.cpp		\
+	geo_point.cpp			\
 	map.cpp				\
 	sample.cpp
 
 libgrnxx_alpha_includedir = ${includedir}/grnxx/alpha
 libgrnxx_alpha_include_HEADERS =	\
 	double_array.hpp		\
+	geo_point.hpp			\
 	map.hpp				\
 	sample.hpp

  Added: lib/grnxx/alpha/geo_point.cpp (+29 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/alpha/geo_point.cpp    2013-04-11 10:35:37 +0900 (93070ba)
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 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/alpha/geo_point.hpp"
+
+namespace grnxx {
+namespace alpha {
+
+StringBuilder &GeoPoint::write_to(StringBuilder &builder) const {
+  return builder << "{ latitude = " << point_.latitude
+                 << ", longitude = " << point_.longitude << " }";
+}
+
+}  // namespace alpha
+}  // namespace grnxx

  Added: lib/grnxx/alpha/geo_point.hpp (+94 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/alpha/geo_point.hpp    2013-04-11 10:35:37 +0900 (be75e39)
@@ -0,0 +1,94 @@
+/*
+  Copyright (C) 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_ALPHA_GEO_POINT_HPP
+#define GRNXX_ALPHA_GEO_POINT_HPP
+
+#include "grnxx/basic.hpp"
+#include "grnxx/string_builder.hpp"
+
+namespace grnxx {
+namespace alpha {
+
+// Latitude and longitude (lat/long).
+union GeoPoint {
+ public:
+  // The default constructor does not initialize lat/long.
+  GeoPoint() = default;
+  // Copy lat/long as uint64_t to force atomic copy.
+  GeoPoint(const GeoPoint &x) : value_(x.value_) {}
+  // Copy lat/long.
+  GeoPoint(int32_t latitude, int32_t longitude)
+    : point_{ latitude, longitude } {}
+
+  // Assign lat/long as uint64_t to force atomic assignment.
+  GeoPoint &operator=(const GeoPoint &x) {
+    value_ = x.value_;
+    return *this;
+  }
+
+  // Get the latitude.
+  int32_t latitude() const {
+    return point_.latitude;
+  }
+  // Get the longitude.
+  int32_t longitude() const {
+    return point_.longitude;
+  }
+  // Get lat/long as uint64_t.
+  uint64_t value() const {
+    return value_;
+  }
+
+  // Set the latitude.
+  void set_latitude(int32_t x) {
+    point_.latitude = x;
+  }
+  // Set the longitude.
+  void set_longitude(int32_t x) {
+    point_.longitude = x;
+  }
+  // Set lat/long as uint64_t.
+  void set_value(uint64_t x) {
+    value_ = x;
+  }
+
+  StringBuilder &write_to(StringBuilder &builder) const;
+
+ private:
+  struct Point {
+    int32_t latitude;
+    int32_t longitude;
+  } point_;
+  uint64_t value_;
+};
+
+inline bool operator==(const GeoPoint &lhs, const GeoPoint &rhs) {
+  return lhs.value() == rhs.value();
+}
+inline bool operator!=(const GeoPoint &lhs, const GeoPoint &rhs) {
+  return lhs.value() != rhs.value();
+}
+
+inline StringBuilder &operator<<(StringBuilder &builder, const GeoPoint &x) {
+  return x.write_to(builder);
+}
+
+}  // namespace alpha
+}  // namespace grnxx
+
+#endif  // GRNXX_ALPHA_GEO_POINT_HPP

  Modified: lib/grnxx/alpha/map.hpp (+1 -39)
===================================================================
--- lib/grnxx/alpha/map.hpp    2013-04-09 18:20:00 +0900 (fc74938)
+++ lib/grnxx/alpha/map.hpp    2013-04-11 10:35:37 +0900 (b5d798e)
@@ -18,51 +18,13 @@
 #ifndef GRNXX_ALPHA_MAP_HPP
 #define GRNXX_ALPHA_MAP_HPP
 
+#include "grnxx/alpha/geo_point.hpp"
 #include "grnxx/io/pool.hpp"
 #include "grnxx/slice.hpp"
 
 namespace grnxx {
 namespace alpha {
 
-class GeoPoint {
- public:
-  GeoPoint() = default;
-  GeoPoint(int32_t latitude, int32_t longitude)
-    : value_((static_cast<uint64_t>(latitude) << LATITUDE_BITS) |
-             (static_cast<uint64_t>(longitude) << LONGITUDE_BITS)) {}
-
-  bool operator==(GeoPoint rhs) const {
-    return value_ == rhs.value_;
-  }
-  bool operator!=(GeoPoint rhs) const {
-    return value_ != rhs.value_;
-  }
-
-  int32_t latitude() const {
-    return static_cast<int32_t>((value_ & LATITUDE_MASK) >> LATITUDE_BITS);
-  }
-  int32_t longitude() const {
-    return static_cast<int32_t>((value_ & LONGITUDE_MASK) >> LONGITUDE_BITS);
-  }
-
-  void set_latitude(int32_t latitude) {
-    value_ = (value_ & LONGITUDE_MASK) |
-             (static_cast<uint64_t>(latitude) << LATITUDE_BITS);
-  }
-  void set_longitude(int32_t longitude) {
-    value_ = (value_ & LATITUDE_MASK) |
-             (static_cast<uint64_t>(longitude) << LONGITUDE_BITS);
-  }
-
- private:
-  uint64_t value_;
-
-  static constexpr uint64_t LATITUDE_MASK  = 0xFFFFFFFFULL;
-  static constexpr uint8_t  LATITUDE_BITS  = 0;
-  static constexpr uint64_t LONGITUDE_MASK = 0xFFFFFFFFULL << 32;
-  static constexpr uint8_t  LONGITUDE_BITS = 32;
-};
-
 enum MapType : int32_t {
   MAP_UNKNOWN      = 0,
   MAP_ARRAY        = 1,  // Test implementation.
-------------- next part --------------
HTML����������������������������...
Download 



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