From c9be372aa2f8d02c56b30592e4318ed2f65b1fc0 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Fri, 17 Sep 2010 21:10:19 +0900 Subject: [PATCH] =?utf8?q?sized=5Fptr.hpp,=20sized=5Fcharbuf.hpp:=20operat?= =?utf8?q?or=20=3D=3D()=20=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/memory/sized_ptr.hpp | 41 ++++++++++++++++++++++++++ roast/include/roast/str/sized_charbuf.hpp | 49 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/roast/include/roast/memory/sized_ptr.hpp b/roast/include/roast/memory/sized_ptr.hpp index 3056fbe9..01401fc5 100644 --- a/roast/include/roast/memory/sized_ptr.hpp +++ b/roast/include/roast/memory/sized_ptr.hpp @@ -36,6 +36,47 @@ namespace roast T* p = new T [ size + margin ]; memcpy(p,ptr,sizeof(T) * size); } + + ////////////////////////////////////////////////////////////////////// + + bool operator == ( const sized_ptr_& other ) const + { + if ( size > other.size ) + return 1; + if ( size < other.size ) + return -1; + /*if ( this->size != other.size ) + return *(this->ptr) - other.*/ + //T* p1 = ptr; + //T* p2 = other.ptr; + const unsigned char* p1 = (const unsigned char*)ptr; + const unsigned char* p2 = (const unsigned char*)other.ptr; + + const unsigned char* p_end1 = (const unsigned char*)ptr + size; + const unsigned char* p_end2 = (const unsigned char*)other.ptr + other.size; + for( ; ; p1++, p2++ ) + { + if ( p1 == p_end1 ) + return 0; + /* + //if ( p1 == ptr+size ) + if ( p1 == p_end1 && p2 == p_end2 ) + return 0; + if ( p1 == p_end1 ) + return *p1; + //if ( p2 == other.ptr+size ) + if ( p2 == p_end2 ) + return -(*p1); + */ + + //////////// + + int temp = ( *p1 - *p2 ); + if ( temp != 0 ) + return temp; + } + return 0; + } }; template <> struct sized_ptr_ diff --git a/roast/include/roast/str/sized_charbuf.hpp b/roast/include/roast/str/sized_charbuf.hpp index 5f7cd694..a0fc34d2 100644 --- a/roast/include/roast/str/sized_charbuf.hpp +++ b/roast/include/roast/str/sized_charbuf.hpp @@ -49,6 +49,55 @@ namespace roast { return ::std::string(ptr, size); } + + int operator == ( const sized_ccharbuf& other ) const + { + //return _Base::operator ==(s); + + const char* p1 = ptr; + const char* p2 = other.ptr; + + const char* p_end1 = ptr + size; + const char* p_end2 = other.ptr + other.size; + for( ; ; p1++, p2++ ) + { + //if ( p1 == ptr+size ) + if ( p1 == p_end1 && p2 == p_end2 ) + return 0; + if ( p1 == p_end1 ) + return *p1; + //if ( p2 == other.ptr+size ) + if ( p2 == p_end2 ) + return -(*p1); + + //////////// + + int temp = ( *p1 - *p2 ); + if ( temp != 0 ) + return temp; + } + } + int operator == ( const char* s ) const + { + T* p1 = ptr; + T* p2 = s; + for( ; ; p1++, p2++ ) + { + if ( p1 == ptr+size && *p2 == '\0' ) + return 0; + if ( p1 == ptr+size ) + return *p2; + if ( *p2 == '\0' ) + return -(*p1); + + //////////// + + int temp = ( *p1 - *p2 ); + if ( temp != 0 ) + return temp; + } + return 0; + } }; } -- 2.11.0