susumu.yata
null+****@clear*****
Tue Dec 16 10:43:27 JST 2014
susumu.yata 2014-11-17 16:10:44 +0900 (Mon, 17 Nov 2014) New Revision: 34d3ab67bb93ba121676f646a31f570c7e89231a https://github.com/groonga/grnxx/commit/34d3ab67bb93ba121676f646a31f570c7e89231a Message: Add Vector<GeoPoint>. (#109) Modified files: include/grnxx/data_types/vector/geo_point.hpp Modified: include/grnxx/data_types/vector/geo_point.hpp (+58 -1) =================================================================== --- include/grnxx/data_types/vector/geo_point.hpp 2014-11-17 15:59:14 +0900 (55251db) +++ include/grnxx/data_types/vector/geo_point.hpp 2014-11-17 16:10:44 +0900 (db787e1) @@ -12,10 +12,67 @@ template <typename T> class Vector; template <> class Vector<GeoPoint> { public: - // TODO + Vector() = default; + ~Vector() = default; + + constexpr Vector(const Vector &) = default; + Vector &operator=(const Vector &) = default; + + constexpr Vector(const GeoPoint *data, size_t size) + : data_(data), + size_(size) {} + explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {} + + const GeoPoint &operator[](size_t i) const { + return data_[i]; + } + constexpr const GeoPoint *data() const { + return data_; + } + constexpr Int size() const { + return size_; + } + + constexpr bool is_empty() const { + return size_.value() == 0; + } + constexpr bool is_na() const { + return size_.is_na(); + } + + // TODO: The behavior of N/A in vector is not fixed yet (#107). + Bool operator==(const Vector &rhs) const { + Bool has_equal_size = (size_ == rhs.size_); + if (has_equal_size.is_true()) { + return Bool(std::memcmp(data_, rhs.data_, + sizeof(GeoPoint) * size_.value()) == 0); + } + return has_equal_size; + } + // TODO: The behavior of N/A in vector is not fixed yet (#107). + Bool operator!=(const Vector &rhs) const { + Bool has_not_equal_size = (size_ != rhs.size_); + if (has_not_equal_size.is_false()) { + return Bool(std::memcmp(data_, rhs.data_, + sizeof(GeoPoint) * size_.value()) != 0); + } + return has_not_equal_size; + } + static constexpr DataType type() { return GEO_POINT_VECTOR_DATA; } + + static constexpr Vector empty() { + return Vector(nullptr, 0); + } + static constexpr Vector na() { + return Vector(NA()); + } + + private: + const GeoPoint *data_; + Int size_; }; using GeoPointVector = Vector<GeoPoint>; -------------- next part -------------- HTML����������������������������... Descargar