susumu.yata
null+****@clear*****
Wed Feb 13 14:20:49 JST 2013
susumu.yata 2013-02-13 14:20:49 +0900 (Wed, 13 Feb 2013) New Revision: 89870284b15d6019a551cfa51e3b15d4acc8297e https://github.com/groonga/grnxx/commit/89870284b15d6019a551cfa51e3b15d4acc8297e Log: Update grnxx::Slice and its tests. Modified files: lib/slice.hpp test/test_slice.cpp Modified: lib/slice.hpp (+13 -5) =================================================================== --- lib/slice.hpp 2013-02-13 13:07:00 +0900 (d897a87) +++ lib/slice.hpp 2013-02-13 14:20:49 +0900 (195a13b) @@ -27,9 +27,13 @@ class Slice { // Create an empty (zero-size) slice. Slice() : ptr_(nullptr), size_(0) {} // Create a slice that refers to a zero-terminated string. - Slice(const char *str) : ptr_(str), size_(std::strlen(str)) {} + Slice(const char *str) + : ptr_(reinterpret_cast<const uint8_t *>(str)), + size_(std::strlen(str)) {} // Create a slice. - Slice(const char *ptr, size_t size) : ptr_(ptr), size_(size) {} + Slice(const void *ptr, size_t size) + : ptr_(static_cast<const uint8_t *>(ptr)), + size_(size) {} // Return true iff *this" is not empty. explicit operator bool() const { @@ -87,12 +91,16 @@ class Slice { } // Return the "n"-th byte of "*this". - char operator[](size_t i) const { + uint8_t operator[](size_t i) const { return ptr_[i]; } // Return the starting address of "*this". - const char *ptr() const { + const void *address() const { + return ptr_; + } + // Return a pointer that refers to the starting address of "*this". + const uint8_t *ptr() const { return ptr_; } // Returns the size of "*this". @@ -101,7 +109,7 @@ class Slice { } private: - const char *ptr_; + const uint8_t *ptr_; size_t size_; }; Modified: test/test_slice.cpp (+3 -4) =================================================================== --- test/test_slice.cpp 2013-02-13 13:07:00 +0900 (b3410fb) +++ test/test_slice.cpp 2013-02-13 14:20:49 +0900 (1c31c21) @@ -24,27 +24,26 @@ void test_constructors() { grnxx::Slice slice; assert(!slice); - assert(!slice.ptr()); assert(slice.size() == 0); const char *empty_str = ""; slice = grnxx::Slice(empty_str); assert(!slice); - assert(slice.ptr() == empty_str); + assert(slice.address() == empty_str); assert(slice.size() == 0); const char *digits = "0123456789"; slice = grnxx::Slice(digits); assert(slice); - assert(slice.ptr() == digits); + assert(slice.address() == digits); assert(slice.size() == 10); slice = grnxx::Slice(digits + 3, 5); assert(slice); - assert(slice.ptr() == digits + 3); + assert(slice.address() == (digits + 3)); assert(slice.size() == 5); } -------------- next part -------------- HTML����������������������������...Download