[Groonga-commit] groonga/grnxx at cb16014 [new_data_types] Remove old implementations.

Back to archive index

susumu.yata null+****@clear*****
Thu Nov 6 23:54:17 JST 2014


susumu.yata	2014-11-06 23:54:17 +0900 (Thu, 06 Nov 2014)

  New Revision: cb16014e8d6776bffe17ab915a5a87af3ef350d5
  https://github.com/groonga/grnxx/commit/cb16014e8d6776bffe17ab915a5a87af3ef350d5

  Message:
    Remove old implementations.

  Removed files:
    include/grnxx/types/datum.hpp
    include/grnxx/types/geo_point.hpp
    include/grnxx/types/string.hpp
    include/grnxx/types/traits.hpp

  Deleted: include/grnxx/types/datum.hpp (+0 -138) 100644
===================================================================
--- include/grnxx/types/datum.hpp    2014-11-06 23:46:26 +0900 (499cb5e)
+++ /dev/null
@@ -1,138 +0,0 @@
-#ifndef GRNXX_TYPES_DATUM_HPP
-#define GRNXX_TYPES_DATUM_HPP
-
-#include "grnxx/types/base_types.hpp"
-#include "grnxx/types/constants.hpp"
-#include "grnxx/types/data_types.hpp"
-#include "grnxx/types/geo_point.hpp"
-#include "grnxx/types/string.hpp"
-#include "grnxx/types/vector.hpp"
-
-namespace grnxx {
-
-class Datum {
- public:
-  // The default constructor does nothing.
-  Datum() = default;
-
-  Datum(Bool value)
-      : type_(BOOL_DATA),
-        bool_(value) {}
-  Datum(Int value)
-      : type_(INT_DATA),
-        int_(value) {}
-  Datum(Float value)
-      : type_(FLOAT_DATA),
-        float_(value) {}
-  Datum(GeoPoint value)
-      : type_(GEO_POINT_DATA),
-        geo_point_(value) {}
-  Datum(Text value)
-      : type_(TEXT_DATA),
-        text_(value) {}
-  // Disable implicit conversion from const char * to Bool.
-  Datum(const char *) = delete;
-  Datum(Vector<Bool> value)
-      : type_(BOOL_VECTOR_DATA),
-        bool_vector_(value) {}
-  Datum(Vector<Int> value)
-      : type_(INT_VECTOR_DATA),
-        int_vector_(value) {}
-  Datum(Vector<Float> value)
-      : type_(FLOAT_VECTOR_DATA),
-        float_vector_(value) {}
-  Datum(Vector<GeoPoint> value)
-      : type_(GEO_POINT_VECTOR_DATA),
-        geo_point_vector_(value) {}
-  Datum(Vector<Text> value)
-      : type_(TEXT_VECTOR_DATA),
-        text_vector_(value) {}
-
-  // Return the data type.
-  DataType type() const {
-    return type_;
-  }
-
-  // Force the specified interpretation.
-  Bool force_bool() const {
-    return bool_;
-  }
-  Int force_int() const {
-    return int_;
-  }
-  Float force_float() const {
-    return float_;
-  }
-  GeoPoint force_geo_point() const {
-    return geo_point_;
-  }
-  Text force_text() const {
-    return text_;
-  }
-  Vector<Bool> force_bool_vector() const {
-    return bool_vector_;
-  }
-  Vector<Int> force_int_vector() const {
-    return int_vector_;
-  }
-  Vector<Float> force_float_vector() const {
-    return float_vector_;
-  }
-  Vector<GeoPoint> force_geo_point_vector() const {
-    return geo_point_vector_;
-  }
-  Vector<Text> force_text_vector() const {
-    return text_vector_;
-  }
-
-  // Force the specified interpretation.
-  void force(Bool *value) const {
-    *value = bool_;
-  }
-  void force(Int *value) const {
-    *value = int_;
-  }
-  void force(Float *value) const {
-    *value = float_;
-  }
-  void force(GeoPoint *value) const {
-    *value = geo_point_;
-  }
-  void force(Text *value) const {
-    *value = text_;
-  }
-  void force(Vector<Bool> *value) const {
-    *value = bool_vector_;
-  }
-  void force(Vector<Int> *value) const {
-    *value = int_vector_;
-  }
-  void force(Vector<Float> *value) const {
-    *value = float_vector_;
-  }
-  void force(Vector<GeoPoint> *value) const {
-    *value = geo_point_vector_;
-  }
-  void force(Vector<Text> *value) const {
-    *value = text_vector_;
-  }
-
- private:
-  DataType type_;
-  union {
-    Bool bool_;
-    Int int_;
-    Float float_;
-    GeoPoint geo_point_;
-    Text text_;
-    Vector<Bool> bool_vector_;
-    Vector<Int> int_vector_;
-    Vector<Float> float_vector_;
-    Vector<GeoPoint> geo_point_vector_;
-    Vector<Text> text_vector_;
-  };
-};
-
-}  // namespace grnxx
-
-#endif  // GRNXX_TYPES_DATUM_HPP

  Deleted: include/grnxx/types/geo_point.hpp (+0 -57) 100644
===================================================================
--- include/grnxx/types/geo_point.hpp    2014-11-06 23:46:26 +0900 (113a2d1)
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef GRNXX_TYPES_GEO_POINT_HPP
-#define GRNXX_TYPES_GEO_POINT_HPP
-
-#include "grnxx/types/geo_point.hpp"
-
-namespace grnxx {
-
-class GeoPoint {
- public:
-  // The default constructor does nothing.
-  GeoPoint() = default;
-  GeoPoint(Int latitude, Int longitude)
-      : latitude_(),
-        longitude_() {
-    if ((latitude < DEGREES(-90)) || (latitude > DEGREES(90)) ||
-        (longitude < DEGREES(-180)) || (longitude >= DEGREES(180))) {
-      // Fix an out-of-range value.
-      fix(&latitude, &longitude);
-    }
-    // The south pole or the north pole.
-    if ((latitude == DEGREES(-90)) || (latitude == DEGREES(90))) {
-      longitude = 0;
-    }
-    latitude_ = static_cast<int32_t>(latitude);
-    longitude_ = static_cast<int32_t>(longitude);
-  }
-
-  bool operator==(const GeoPoint &arg) const {
-    return (latitude_ == arg.latitude_) && (longitude_ == arg.longitude_);
-  }
-  bool operator!=(const GeoPoint &arg) const {
-    return (latitude_ != arg.latitude_) || (longitude_ != arg.longitude_);
-  }
-
-  Int latitude() const {
-    return latitude_;
-  }
-  Int longitude() const {
-    return longitude_;
-  }
-
- private:
-  int32_t latitude_;   // Latitude in milliseconds.
-  int32_t longitude_;  // Longitude in milliseconds.
-
-  // Return "value" degrees in milliseconds.
-  static constexpr Int DEGREES(Int value) {
-    return value * 60 * 60 * 1000;
-  }
-
-  // Fix an out-of-range value.
-  static void fix(Int *latitude, Int *longitude);
-};
-
-}  // namespace grnxx
-
-#endif  // GRNXX_TYPES_GEO_POINT_HPP

  Deleted: include/grnxx/types/string.hpp (+0 -426) 100644
===================================================================
--- include/grnxx/types/string.hpp    2014-11-06 23:46:26 +0900 (f27353a)
+++ /dev/null
@@ -1,426 +0,0 @@
-#ifndef GRNXX_TYPES_STRING_HPP
-#define GRNXX_TYPES_STRING_HPP
-
-#include <cstring>
-
-#include "grnxx/types/base_types.hpp"
-
-namespace grnxx {
-
-// Reference to a byte string.
-class StringCRef {
- public:
-  // The default constructor does nothing.
-  StringCRef() = default;
-  // Refer to a zero-terminated string.
-  StringCRef(const char *arg) : data_(arg), size_(std::strlen(arg)) {}
-  // Refer to an arbitrary byte string.
-  StringCRef(const char *data, Int size) : data_(data), size_(size) {}
-
-  // Return the "i"-th byte.
-  const char &operator[](Int i) const {
-    return data_[i];
-  }
-
-  // Return the address.
-  const char *data() const {
-    return data_;
-  }
-  // Return the number of bytes.
-  Int size() const {
-    return size_;
-  }
-
-  // Compare a strings.
-  bool operator==(const StringCRef &arg) const {
-    return (size_ == arg.size_) && (std::memcmp(data_, arg.data_, size_) == 0);
-  }
-  bool operator!=(const StringCRef &arg) const {
-    return (size_ != arg.size_) || (std::memcmp(data_, arg.data_, size_) != 0);
-  }
-  bool operator<(const StringCRef &arg) const {
-    Int min_size = size_ < arg.size_ ? size_ : arg.size_;
-    int result = std::memcmp(data_, arg.data_, min_size);
-    return (result < 0) || ((result == 0) && (size_ < arg.size_));
-  }
-  bool operator>(const StringCRef &arg) const {
-    Int min_size = size_ < arg.size_ ? size_ : arg.size_;
-    int result = std::memcmp(data_, arg.data_, min_size);
-    return (result > 0) || ((result == 0) && (size_ > arg.size_));
-  }
-  bool operator<=(const StringCRef &arg) const {
-    Int min_size = size_ < arg.size_ ? size_ : arg.size_;
-    int result = std::memcmp(data_, arg.data_, min_size);
-    return (result < 0) || ((result == 0) && (size_ <= arg.size_));
-  }
-  bool operator>=(const StringCRef &arg) const {
-    Int min_size = size_ < arg.size_ ? size_ : arg.size_;
-    int result = std::memcmp(data_, arg.data_, min_size);
-    return (result > 0) || ((result == 0) && (size_ >= arg.size_));
-  }
-
-  // Compare a string with a zero-terminated string.
-  bool operator==(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if ((arg[i] == '\0') || (data_[i] != arg[i])) {
-        return false;
-      }
-    }
-    return arg[size_] == '\0';
-  }
-  bool operator!=(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if ((arg[i] == '\0') || (data_[i] != arg[i])) {
-        return true;
-      }
-    }
-    return arg[size_] != '\0';
-  }
-  bool operator<(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if (arg[i] == '\0') {
-        return false;
-      }
-      if (data_[i] != arg[i]) {
-        return static_cast<unsigned char>(data_[i]) <
-               static_cast<unsigned char>(arg[i]);
-      }
-    }
-    return arg[size_] != '\0';
-  }
-  bool operator>(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if (arg[i] == '\0') {
-        return true;
-      }
-      if (data_[i] != arg[i]) {
-        return static_cast<unsigned char>(data_[i]) >
-               static_cast<unsigned char>(arg[i]);
-      }
-    }
-    return false;
-  }
-  bool operator<=(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if (arg[i] == '\0') {
-        return false;
-      }
-      if (data_[i] != arg[i]) {
-        return static_cast<unsigned char>(data_[i]) <
-               static_cast<unsigned char>(arg[i]);
-      }
-    }
-    return true;
-  }
-  bool operator>=(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if (arg[i] == '\0') {
-        return true;
-      }
-      if (data_[i] != arg[i]) {
-        return static_cast<unsigned char>(data_[i]) >
-               static_cast<unsigned char>(arg[i]);
-      }
-    }
-    return arg[size_] == '\0';
-  }
-
-  // Return true if "*this" starts with "arg".
-  bool starts_with(const StringCRef &arg) const {
-    if (size_ < arg.size_) {
-      return false;
-    }
-    return std::memcmp(data_, arg.data_, arg.size_) == 0;
-  }
-  bool starts_with(const char *arg) const {
-    for (Int i = 0; i < size_; ++i) {
-      if (arg[i] == '\0') {
-        return true;
-      } else if (data_[i] != arg[i]) {
-        return false;
-      }
-    }
-    return arg[size_] == '\0';
-  }
-
-  // Return true if "*this" ends with "arg".
-  bool ends_with(const StringCRef &arg) const {
-    if (size_ < arg.size_) {
-      return false;
-    }
-    return std::memcmp(data_ + size_ - arg.size_, arg.data_, arg.size_) == 0;
-  }
-  bool ends_with(const char *arg) const {
-    return ends_with(StringCRef(arg));
-  }
-
- private:
-  const char *data_;
-  Int size_;
-};
-
-// Compare a null-terminated string with a string.
-inline bool operator==(const char *lhs, const StringCRef &rhs) {
-  return rhs == lhs;
-}
-inline bool operator!=(const char *lhs, const StringCRef &rhs) {
-  return rhs != lhs;
-}
-inline bool operator<(const char *lhs, const StringCRef &rhs) {
-  return rhs > lhs;
-}
-inline bool operator>(const char *lhs, const StringCRef &rhs) {
-  return rhs < lhs;
-}
-inline bool operator<=(const char *lhs, const StringCRef &rhs) {
-  return rhs >= lhs;
-}
-inline bool operator>=(const char *lhs, const StringCRef &rhs) {
-  return rhs <= lhs;
-}
-
-using Text = StringCRef;
-
-class String {
- public:
-  String() : buf_(), size_(0), capacity_(0) {}
-  ~String() {}
-
-  String(String &&arg)
-      : buf_(std::move(arg.buf_)),
-        size_(arg.size_),
-        capacity_(arg.capacity_) {
-    arg.size_ = 0;
-    arg.capacity_ = 0;
-  }
-
-  String &operator=(String &&arg) {
-    buf_ = std::move(arg.buf_);
-    size_ = arg.size_;
-    capacity_ = arg.capacity_;
-    arg.size_ = 0;
-    arg.capacity_ = 0;
-    return *this;
-  }
-
-  operator StringCRef() const {
-    return ref();
-  }
-
-  StringCRef ref(Int offset = 0) const {
-    return StringCRef(buf_.get() + offset, size_ - offset);
-  }
-  StringCRef ref(Int offset, Int size) const {
-    return StringCRef(buf_.get() + offset, size);
-  }
-
-  char &operator[](Int i) {
-    return buf_[i];
-  }
-  const char &operator[](Int i) const {
-    return buf_[i];
-  }
-
-  char &front() {
-    return buf_[0];
-  }
-  const char &front() const {
-    return buf_[0];
-  }
-
-  char &back() {
-    return buf_[size_ - 1];
-  }
-  const char &back() const {
-    return buf_[size_ - 1];
-  }
-
-  char *data() {
-    return buf_.get();
-  }
-  const char *data() const {
-    return buf_.get();
-  }
-
-  Int size() const {
-    return size_;
-  }
-  Int capacity() const {
-    return capacity_;
-  }
-
-  bool reserve(Error *error, Int new_size) {
-    if (new_size <= capacity_) {
-      return true;
-    }
-    return resize_buf(error, new_size);
-  }
-
-  bool assign(Error *error, const StringCRef &arg) {
-    if (arg.size() > capacity_) {
-      if (!resize_buf(error, arg.size())) {
-        return false;
-      }
-    }
-    std::memcpy(buf_.get(), arg.data(), arg.size());
-    size_ = arg.size();
-    return true;
-  }
-  bool assign(Error *error, const char *data, Int size) {
-    return assign(error, StringCRef(data, size));
-  }
-
-  bool resize(Error *error, Int new_size) {
-    if (new_size > capacity_) {
-      if (!resize_buf(error, new_size)) {
-        return false;
-      }
-    }
-    size_ = new_size;
-    return true;
-  }
-  bool resize(Error *error, Int new_size, char value) {
-    if (new_size > capacity_) {
-      if (!resize_buf(error, new_size)) {
-        return false;
-      }
-    }
-    if (new_size > size_) {
-      std::memset(buf_.get() + size_, value, new_size - size_);
-    }
-    size_ = new_size;
-    return true;
-  }
-
-  void clear() {
-    size_ = 0;
-  }
-
-  bool push_back(Error *error, char value) {
-    if (size_ == capacity_) {
-      if (!resize_buf(error, size_ + 1)) {
-        return false;
-      }
-    }
-    buf_[size_] = value;
-    ++size_;
-    return true;
-  }
-  void pop_back() {
-    --size_;
-  }
-
-  bool append(Error *error, const StringCRef &arg) {
-    if ((size_ + arg.size()) > capacity_) {
-      if ((arg.data() >= buf_.get()) && (arg.data() < (buf_.get() + size_))) {
-        // Note that "arg" will be deleted in resize_buf() if "arg" is a part
-        // of "*this".
-        return append_overlap(error, arg);
-      } else if (!resize_buf(error, (size_ + arg.size()))) {
-        return false;
-      }
-    }
-    std::memcpy(buf_.get() + size_, arg.data(), arg.size());
-    size_ += arg.size();
-    return true;
-  }
-  bool append(Error *error, const char *data, Int size) {
-    return append(error, StringCRef(data, size));
-  }
-
-  void swap(Int i, Int j) {
-    char temp = buf_[i];
-    buf_[i] = buf_[j];
-    buf_[j] = temp;
-  }
-
-  // Compare a strings.
-  bool operator==(const StringCRef &arg) const {
-    return ref() == arg;
-  }
-  bool operator!=(const StringCRef &arg) const {
-    return ref() != arg;
-  }
-  bool operator<(const StringCRef &arg) const {
-    return ref() < arg;
-  }
-  bool operator>(const StringCRef &arg) const {
-    return ref() > arg;
-  }
-  bool operator<=(const StringCRef &arg) const {
-    return ref() <= arg;
-  }
-  bool operator>=(const StringCRef &arg) const {
-    return ref() >= arg;
-  }
-
-  // Compare a string with a zero-terminated string.
-  bool operator==(const char *arg) const {
-    return ref() == arg;
-  }
-  bool operator!=(const char *arg) const {
-    return ref() != arg;
-  }
-  bool operator<(const char *arg) const {
-    return ref() < arg;
-  }
-  bool operator>(const char *arg) const {
-    return ref() > arg;
-  }
-  bool operator<=(const char *arg) const {
-    return ref() <= arg;
-  }
-  bool operator>=(const char *arg) const {
-    return ref() >= arg;
-  }
-
-  // Return true if "*this" starts with "arg".
-  bool starts_with(const StringCRef &arg) const {
-    return ref().starts_with(arg);
-  }
-  bool starts_with(const char *arg) const {
-    return ref().starts_with(arg);
-  }
-
-  // Return true if "*this" ends with "arg".
-  bool ends_with(const StringCRef &arg) const {
-    return ref().ends_with(arg);
-  }
-  bool ends_with(const char *arg) const {
-    return ref().ends_with(arg);
-  }
-
- private:
-  unique_ptr<char[]> buf_;
-  Int size_;
-  Int capacity_;
-
-  // Assume new_size > capacity_.
-  bool resize_buf(Error *error, Int new_size);
-  // Resize the internal buffer and append a part of "*this".
-  bool append_overlap(Error *error, const StringCRef &arg);
-};
-
-// Compare a null-terminated string with a string.
-inline bool operator==(const char *lhs, const String &rhs) {
-  return rhs == lhs;
-}
-inline bool operator!=(const char *lhs, const String &rhs) {
-  return rhs != lhs;
-}
-inline bool operator<(const char *lhs, const String &rhs) {
-  return rhs > lhs;
-}
-inline bool operator>(const char *lhs, const String &rhs) {
-  return rhs < lhs;
-}
-inline bool operator<=(const char *lhs, const String &rhs) {
-  return rhs >= lhs;
-}
-inline bool operator>=(const char *lhs, const String &rhs) {
-  return rhs <= lhs;
-}
-
-}  // namespace grnxx
-
-#endif  // GRNXX_TYPES_STRING_HPP

  Deleted: include/grnxx/types/traits.hpp (+0 -105) 100644
===================================================================
--- include/grnxx/types/traits.hpp    2014-11-06 23:46:26 +0900 (a7d8097)
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef GRNXX_TYPES_TRAITS_HPP
-#define GRNXX_TYPES_TRAITS_HPP
-
-#include "grnxx/types/base_types.hpp"
-#include "grnxx/types/constants.hpp"
-#include "grnxx/types/data_types.hpp"
-#include "grnxx/types/geo_point.hpp"
-#include "grnxx/types/string.hpp"
-
-namespace grnxx {
-
-template <typename T> struct TypeTraits;
-
-template <> struct TypeTraits <Bool> {
-  static DataType data_type() {
-    return BOOL_DATA;
-  }
-  static Bool default_value() {
-    return false;
-  }
-};
-
-template <> struct TypeTraits <Int> {
-  static DataType data_type() {
-    return INT_DATA;
-  }
-  static Int default_value() {
-    return 0;
-  }
-};
-
-template <> struct TypeTraits <Float> {
-  static DataType data_type() {
-    return FLOAT_DATA;
-  }
-  static Float default_value() {
-    return 0.0;
-  }
-};
-
-template <> struct TypeTraits <GeoPoint> {
-  static DataType data_type() {
-    return GEO_POINT_DATA;
-  }
-  static GeoPoint default_value() {
-    return GeoPoint(0, 0);
-  }
-};
-
-template <> struct TypeTraits <Text> {
-  static DataType data_type() {
-    return TEXT_DATA;
-  }
-  static Text default_value() {
-    return Text("", 0);
-  }
-};
-template <> struct TypeTraits <Vector<Bool>> {
-  static DataType data_type() {
-    return BOOL_VECTOR_DATA;
-  }
-  static Vector<Bool> default_value() {
-    return Vector<Bool>(0, 0);
-  }
-};
-
-template <> struct TypeTraits <Vector<Int>> {
-  static DataType data_type() {
-    return INT_VECTOR_DATA;
-  }
-  static Vector<Int> default_value() {
-    return Vector<Int>(nullptr, 0);
-  }
-};
-
-template <> struct TypeTraits <Vector<Float>> {
-  static DataType data_type() {
-    return FLOAT_VECTOR_DATA;
-  }
-  static Vector<Float> default_value() {
-    return Vector<Float>(nullptr, 0);
-  }
-};
-
-template <> struct TypeTraits <Vector<GeoPoint>> {
-  static DataType data_type() {
-    return GEO_POINT_VECTOR_DATA;
-  }
-  static Vector<GeoPoint> default_value() {
-    return Vector<GeoPoint>(nullptr, 0);
-  }
-};
-
-template <> struct TypeTraits <Vector<Text>> {
-  static DataType data_type() {
-    return TEXT_VECTOR_DATA;
-  }
-  static Vector<Text> default_value() {
-    return Vector<Text>(nullptr, 0);
-  }
-};
-
-}  // namespace grnxx
-
-#endif  // GRNXX_TYPES_TRAITS_HPP
-------------- next part --------------
HTML����������������������������...
Download 



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