diff --git a/CMakeLists.txt b/CMakeLists.txt index d5aaba63f7c9e3d12c3bf0fba0be7273d3b6ce3b..0364047e68859cb7936333de281e1da3ea20d53f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,6 @@ if(WITH_MKLDNN) list(APPEND EXTERNAL_LIBS ${MKLDNN_LIB}) endif() -add_subdirectory(bsl) add_subdirectory(ullib) add_subdirectory(configure) add_subdirectory(mempool) diff --git a/bsl/AutoBuffer.h b/bsl/AutoBuffer.h deleted file mode 100644 index b208eb343b7f3ae92bde3fe5153fd381b614a1cf..0000000000000000000000000000000000000000 --- a/bsl/AutoBuffer.h +++ /dev/null @@ -1,1050 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_auto_buffer.h,v 1.9 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file AutoBuffer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/02 12:15:49 - * @version $Revision: 1.9 $ - * @brief - * - **/ -#ifndef __BSL_AUTO_BUFFER_H_ -#define __BSL_AUTO_BUFFER_H_ -#include -#include -#include -#include -#include -#include "bsl/utils/bsl_memcpy.h" -#include "bsl/pool/bsl_pool.h" - - -namespace bsl{ - /** - * @brief 类似于auto_ptr但更加安全的字符串缓冲区类 - * - * 该类的一大特点是不会抛出异常。在内存不足的时候,该类会截断字符串并置"被截断位"。 - * AutoBuffer对象自行管理一片用于表示字符串的缓冲区,并提供方法追加各种类型对象。 - * 若内存不足时,内存容量将番倍,若申请新内存失败,将填满旧内存,而且使truncated()方法返回true。 - */ - class AutoBuffer{ - public: - /** - * @brief 构造函数 - * - * 可传入__capacity参数指定预分配的内存空间。如__capacity==0没有动态内存分配。 - * 初始化内存池,默认不使用内存池,即直接malloc和free - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] __capacity : size_t - * @see - * @author chenxm - * @date 2009/02/04 17:39:57 - **/ - explicit AutoBuffer( size_t __capacity = DEFAULT_CAPACITY ) - :_size(0), _capacity(__capacity), _truncated(false), _str(NULL), - _mempool(NULL) { - if ( __capacity != 0 ){ - _str = static_cast(_mempool == NULL ? - malloc(_capacity + 1) : _mempool->malloc(_capacity + 1)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - } - - /** - * @brief 使用allocator的构造函数 - * - * 可传入__capacity参数指定预分配的内存空间。如__capacity==0没有动态内存分配。 - * 可传入pool参数指定使用的内存池 - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] pool : mempool& - * @param [in] __capacity : size_t - * @see - * @author liaoshangbin - * @date 2010/7/29 12:06:16 - **/ - explicit AutoBuffer( mempool& pool, size_t __capacity = DEFAULT_CAPACITY ) - :_size(0), _capacity(__capacity), _truncated(false), _str(NULL), _mempool(&pool) { - if ( __capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity + 1) : _mempool->malloc(_capacity + 1)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - } - - /** - * @brief 把另一AutoBuffer的内存转移到本AutoBuffer(另一AutoBuffer会被清空),O(1)复杂度 - * 因为不同AutoBuffer使用的内存池会有不同 - * 先释放自身_str的内存,然后_str指向other._str浅复制字符串, - * 自身的_mempool指向other._mempool,这样_mempool还是处理_str这块内存 - * 后清空other._str,other成为空的AutoBuffer还可以继续使用 - * - * @param [in] other : AutoBuffer& - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 17:45:30 - **/ - AutoBuffer& transfer_from ( AutoBuffer& other ){ - if ( &other != this ){ - if ( _str ){ - _mempool == NULL ? free( _str) : _mempool->free( _str, _capacity+1 ); - } - _size = other._size; - _capacity = other._capacity; - _truncated = other._truncated; - _str = other._str; - _mempool = other._mempool; - other._size = 0; - other._capacity = 0; - other._truncated= false; - other._str = NULL; - } - return *this; - } - - /** - * @brief 交换两AutoBuffer内容,O(1)复杂度 - * - * @param [in] other : AutoBuffer& - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:15 - **/ - void swap( AutoBuffer& other ){ - std::swap( _str, other._str ); - std::swap( _size, other._size ); - std::swap( _capacity, other._capacity ); - std::swap( _truncated, other._truncated ); - std::swap( _mempool, other._mempool ); - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 18:14:47 - **/ - ~AutoBuffer( ){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity + 1 ); - } - } - - /** - * @brief AutoBuffer长度。不包括最后的'\0' - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:56 - **/ - size_t size() const{ - return _size; - } - - /** - * @brief AutoBuffer当前容量。保证容量>=长度。当容量不足时,容量会自动增长。 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:15:23 - **/ - size_t capacity() const { - return _capacity; - } - - /** - * @brief 返回AutoBuffer是否为空 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:26 - **/ - bool empty() const { - return _size == 0; - } - - /** - * @brief 返回AutoBuffer是否为满 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:39 - **/ - bool full() const { - return _size == _capacity; - } - - /** - * @brief 返回AutoBuffer是否发生了截断 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:58 - **/ - bool truncated() const { - return _truncated; - } - - /** - * @brief 返回AutoBuffer内容的C风格字符串表示。O(1)复杂度 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:17:26 - **/ - const char * c_str() const { - if ( _str ){ - return _str; - }else{ - return ""; - } - } - - /** - * @brief 清空内容 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:12 - **/ - void clear() { - if ( _str && _capacity ){ - _str[0] = '\0'; - } - _size = 0; - } - - /** - * @brief 手动扩大内存容量 - * - * @param [in] __capacity : size_t - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:34 - **/ - bool reserve( size_t __capacity ) { - if ( __capacity > _capacity ){ - if ( __capacity < _capacity * 2 ){ - __capacity = _capacity * 2; - } - - char * _new = static_cast(_mempool == NULL ? - malloc(__capacity + 1) : _mempool->malloc(__capacity + 1)); - if ( !_new ){ - return false; - } - - if ( _str ){ - xmemcpy( _new, _str, _size + 1 ); - _mempool == NULL ? free( _str) : _mempool->free( _str, _capacity + 1); - } - - _str = _new; - _capacity = __capacity; - } - return true; - } - - /** - * @brief 追加另一个AutoBuffer - * - * @param [in] other : const AutoBuffer& - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:49:30 - **/ - AutoBuffer& operator << (const AutoBuffer& other){ - return push( other._str, other._size ); - } - - /** - * @brief 追加一个std::string,不包含c_str()中结尾的'\0' - * - * @param [in] str : const std::string & - * @return AutoBuffer& operator - * @retval - * @see - * @author chenyanling - * @date 2011/09/20 13:18:30 - **/ - AutoBuffer& operator << (const std::string& str){ - return push( str.c_str(),str.length() ); - } - - - /** - * @brief 追加布尔值 - * - * @param [in] b : bool - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:27:49 - **/ - AutoBuffer& operator << (bool b){ - if ( b ){ - return push( TRUE_LITERAL, TRUE_LITERAL_LEN ); - }else{ - return push( FALSE_LITERAL, FALSE_LITERAL_LEN ); - } - } - - /** - * @brief 追加字符,忽略'\0' - * - * @param [in] c : char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:03 - **/ - AutoBuffer& operator << (char c){ - if ( c == '\0' ){ - return *this; - } - if ( _size == _capacity ){ //full - reserve( _size + 1 ); //may fail, make best effort. - } - if ( _size < _capacity ){ - _str[_size] = c; - _str[++_size] = '\0'; - _truncated = false; - }else{ - _truncated = true; - } - return *this; - } - - /** - * @brief 追加有符号8位整数 - * - * @param [in] uc : signed char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:47:27 - **/ - AutoBuffer& operator << (signed char sc){ - return pushf( "%hhd", sc ); - } - - /** - * @brief 追加无符号8位整数 - * - * @param [in] uc : unsigned char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:22 - **/ - AutoBuffer& operator << (unsigned char uc){ - return pushf( "%hhu", uc ); - } - - /** - * @brief 追加宽字符 - * - * @param [in] wc : wchar_t - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:38 - **/ - AutoBuffer& operator << (wchar_t wc){ - if ( wc == 0 ){ - return *this; - } -#if __GNUC__ <= 2 - wchar_t ws[] = { wc, 0 }; - return pushf( "%ls", ws ); -#else - return pushf( "%lc", wc ); -#endif - } - - /** - * @brief 追加宽字符串 - * - * @param [in] ws : const wchar_t* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:56 - **/ - AutoBuffer& operator << (const wchar_t *ws){ - if ( ws != NULL ){ - pushf( "%ls", ws ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加short型整数 - * - * @param [in] i : short - * @return AutoBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:35:32 - **/ - AutoBuffer& operator << (short i) { - return pushf( "%hd", i ); - } - - /** - * @brief 追加unsigned short型整数 - * - * @param [in] i : unsigned short - * @return AutoBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:42:27 - **/ - AutoBuffer& operator << (unsigned short i) { - return pushf( "%hu", i ); - } - - /** - * @brief 追加int型整数 - * - * @param [in] i : int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:10 - **/ - AutoBuffer& operator << (int i){ - return pushf( "%d", i ); - } - - /** - * @brief 追加unsigned int型整数 - * - * @param [in] i : unsigned int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:24 - **/ - AutoBuffer& operator << (unsigned int i){ - return pushf( "%u", i ); - } - - /** - * @brief 追加long int型整数 - * - * @param [in] i : long int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:44 - **/ - AutoBuffer& operator << (long int i){ - return pushf( "%ld", i ); - } - - /** - * @brief 追加unsigned long int型整数 - * - * @param [in] i : unsigned long int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:58 - **/ - AutoBuffer& operator << (unsigned long int i){ - return pushf( "%lu", i ); - } - - /** - * @brief 追加字符串 - * - * @param [in] cstr : const char* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:26 - **/ - AutoBuffer& operator << (const char* cstr ){ - if ( cstr != NULL ){ - push( cstr, strlen(cstr) ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加long long型整数 - * - * @param [in] ll : long long - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:34 - **/ - AutoBuffer& operator << (long long ll){ - return pushf( "%lld", ll ); - } - - /** - * @brief 追加unsigned long long型整数 - * - * @param [in] ll : unsigned long long - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:44 - **/ - AutoBuffer& operator << (unsigned long long ll){ - return pushf( "%llu", ll ); - } - - /** - * @brief 追加double型浮点数 - * - * @param [in] n : double - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:59 - **/ - AutoBuffer& operator << (double n){ - return pushf( "%lg", n ); - } - - /** - * @brief 追加long double型浮点数 - * - * @param [in] n : long double - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:19 - **/ - AutoBuffer& operator << (long double n){ - return pushf( "%Lg", n ); - } - - /** - * @brief 追加指针字面值 - * - * @param [in] p : void* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:53:41 - **/ - AutoBuffer& operator << (void *p){ - return pushf( "%p", p ); - } - - /** - * @brief 追加另一个AutoBuffer - * - * @param [in] other : const AutoBuffer& - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:54:00 - **/ - AutoBuffer& push(const AutoBuffer& other){ - return push( other._str, other._size ); - } - - /** - * @brief 追加布尔值 - * - * @param [in] b : bool - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:46 - **/ - AutoBuffer& push(bool b){ - if ( b ){ - return push( TRUE_LITERAL, TRUE_LITERAL_LEN ); - }else{ - return push( FALSE_LITERAL, FALSE_LITERAL_LEN ); - } - } - - /** - * @brief 追加字符,忽略'\0' - * - * @param [in] c : char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:58 - **/ - AutoBuffer& push(char c){ - if ( c == '\0' ){ - return *this; - } - if ( _size == _capacity ){ //full - reserve( _size + 1 ); //may fail - } - if ( _size < _capacity ){ - _str[_size] = c; - _str[++_size] = '\0'; - _truncated = false; - }else{ - _truncated = true; - } - return *this; - } - - /** - * @brief 追加有符号8位整数 - * - * @param [in] uc : signed char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:52:42 - **/ - AutoBuffer& push(signed char sc){ - return pushf("%hhd", sc); - } - - /** - * @brief 追加无符号8位整数 - * - * @param [in] uc : unsigned char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:39:33 - **/ - AutoBuffer& push(unsigned char uc){ - return pushf("%hhu", uc); - } - - /** - * @brief 追加多个字符,忽略'\0' - * - * @param [in] count : int - * @param [in] c : char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm / zhujianwei - * @date 2009/02/04 18:40:04 / mod. by zhjw at 2010/09/21 - **/ - AutoBuffer& push(size_t count, char c){ - if ( c != '\0' ){ - if ( count > _capacity - _size ){ //full - count = (count <= size_t(-1) - _size) ? count : (size_t(-1) - _size); //limit the size - if( !reserve( _size + count ) ){ - //reserve fail - count = _capacity - _size; - _truncated = true; - }else{ - _truncated = false; - } - } - if ( count ){ - //str != NULL - memset( _str + _size, c, count ); - _str[ _size+=count ] = '\0'; - } - } - return *this; - } - - /** - * @brief 追加宽字符,忽略'\0' - * - * @param [in] wc : wchar_t - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:40:37 - **/ - AutoBuffer& push(wchar_t wc){ - if ( wc == 0 ){ - return *this; - } -#if __GNUC__ <= 2 - wchar_t ws[] = { wc, 0 }; - return pushf( "%ls", ws ); -#else - return pushf( "%lc", wc ); -#endif - } - - /** - * @brief 追加宽字符串,忽略'\0' - * - * @param [in] ws : const wchar_t* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:40:58 - **/ - AutoBuffer& push(const wchar_t * ws){ - if ( ws != NULL ){ - pushf( "%ls", ws ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加short型整数 - * - * @param [in] i : short - * @return AutoBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:43:58 - **/ - AutoBuffer& push(short i) { - return pushf( "%hd", i ); - } - - /** - * @brief 追加unsigned short型整数 - * - * @param [in] i : unsigned short - * @return AutoBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:44:41 - **/ - AutoBuffer& push(unsigned short i) { - return pushf( "%hu", i ); - } - - /** - * @brief 追加int型整数 - * - * @param [in] i : int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:22 - **/ - AutoBuffer& push(int i){ - return pushf( "%d", i ); - } - - /** - * @brief 追加unsigned int型整数 - * - * @param [in] i : unsigned int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:36 - **/ - AutoBuffer& push(unsigned int i){ - return pushf( "%u", i ); - } - - /** - * @brief 追加long int型整数 - * - * @param [in] i : long int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:50 - **/ - AutoBuffer& push(long int i){ - return pushf( "%ld", i ); - } - - /** - * @brief 追加unsigned long int型整数 - * - * @param [in] i : unsigned long int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:00 - **/ - AutoBuffer& push(unsigned long int i){ - return pushf( "%lu", i ); - } - - /** - * @brief 追加字符串 - * - * @param [in] cstr : const char* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:15 - **/ - AutoBuffer& push(const char* cstr ){ - if ( cstr != NULL ){ - push( cstr, strlen(cstr) ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加字符串子串 - * - * 调用者必须保证strlen(cstr) >= sub_str_len,否则行为未定义 - * - * @param [in] cstr : const char* - * @param [in] sub_str_len : size_t - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:28 - **/ - AutoBuffer& push(const char* cstr, size_t sub_str_len ); - - /** - * @brief 追加long long型整数 - * - * @param [in] ll : long long - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:47 - **/ - AutoBuffer& push(long long ll ){ - return pushf( "%lld", ll ); - } - - /** - * @brief 追加unsigned long long型整数 - * - * @param [in] ll : unsigned long long - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:23 - **/ - AutoBuffer& push(unsigned long long ll ){ - return pushf( "%llu", ll ); - } - - /** - * @brief 追加double型浮点数 - * - * @param [in] n : double - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:39 - **/ - AutoBuffer& push( double n ){ - return pushf( "%lg", n ); - } - - /** - * @brief 追加long double型浮点数 - * - * @param [in] n : long double - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:52 - **/ - AutoBuffer& push( long double n ){ - return pushf( "%Lg", n ); - } - - /** - * @brief 追加void *字符串 - * - * @param [in] p : void* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/04/12 01:33:41 - **/ - AutoBuffer& push( void *p ){ - return pushf( "%p", p ); - } - - //attrbute can only be put at function declarations until g++ 3 - /** - * @brief 以类似printf()语法追加字符串 - * - * @param [in] format : const char* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:44:19 - **/ - AutoBuffer& pushf( const char *format, ... ) __attribute__ ((format (printf, 2, 3) )); - - /** - * @brief 以类似vprintf()语法追加字符串 - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:44:53 - **/ - AutoBuffer& vpushf( const char *format, va_list ap ); - - - public: - /** - * @brief 默认AutoBuffer的字符串容量 - * - **/ - static const int DEFAULT_CAPACITY = 64; - /** - * @brief 布尔型true的字面值 - * - **/ - static const char * const TRUE_LITERAL; - /** - * @brief 布尔型false的字面值 - * - **/ - static const char * const FALSE_LITERAL; - - private: - /** - * @brief 复制构造函数 - * - **/ - AutoBuffer( const AutoBuffer& other ); - /** - * @brief 复制赋值运算符 - * - **/ - AutoBuffer& operator = ( const AutoBuffer& ); - /** - * @brief AutoBuffer的长度 - * - **/ - size_t _size; - /** - * @brief AutoBuffer的容量 - * - **/ - size_t _capacity; - /** - * @brief 最近一次操作是否发生截断 - * - **/ - bool _truncated; - /** - * @brief AutoBuffer的内部字符串缓冲区 - * - **/ - char * _str; - /** - * @brief 布尔型true的字面值长度 - * - **/ - static const size_t TRUE_LITERAL_LEN; - /** - * @brief 布尔型false的字面值长度 - * - **/ - static const size_t FALSE_LITERAL_LEN; - - /** - * @brief 当前使用的内存池的指针 - * - **/ - mempool* _mempool; - - }; - -} //namespace bsl; - - -#endif //__BSL_AUTO_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/BCLOUD b/bsl/BCLOUD deleted file mode 100644 index da8d92b249190b1f4b373be278b26aacc35870e6..0000000000000000000000000000000000000000 --- a/bsl/BCLOUD +++ /dev/null @@ -1,79 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -COMPILER('gcc482') - -#Preprocessor flags. -#CPPFLAGS(r'-D_GNU_SOURCE -D__STDC_LIMIT_MACROS') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -#CXXFLAGS(' -g -pipe -W -Wall -fPIC') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -#INCPATHS('. ./include $OUT/include') -#INCPATHS('../../') - -#libs which need to link with -#LIBS('$OUT/lib/libbsl.a') -#LIBS('$OUT/so/libbsl.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -#user_sources=GLOB("*.c *.cpp *.cc *.idl") - -#release headers -HEADERS('*.h', '$INC/bsl') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -OUTPUT('BCLOUD.lib2-64', '$OUT/') - -#bin -#Application('bsl', Sources(user_sources)) - -#UT -#UTApplication('bsl', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -#StaticLibrary('bsl', Sources(user_sources)) -#StaticLibrary('bsl', PreBuilt(True)) - -#.so -#SharedLibrary('bsl', Sources(user_sources)) -#SharedLibrary('bsl', PreBuilt(True)) - -#sub directory -Directory('utils') -Directory('alloc') -Directory('archive') -Directory('containers') -Directory('pool') -Directory('buffer') -Directory('exception') -Directory('check_cast') -Directory('ResourcePool') -Directory('var/interface') -Directory('var/utils') -Directory('var/implement') - diff --git a/bsl/BCLOUD.lib2-64 b/bsl/BCLOUD.lib2-64 deleted file mode 100644 index b221c28ef3a218fb3ebc1b6311a601d9d172f7be..0000000000000000000000000000000000000000 --- a/bsl/BCLOUD.lib2-64 +++ /dev/null @@ -1,19 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -#工作路径. -WORKROOT('../../') - -HEADERS('include/*', '$INC') - -StaticLibrary('bsl', PreBuilt(True)) -StaticLibrary('bsl_archive', PreBuilt(True)) -StaticLibrary('bsl_buffer', PreBuilt(True)) -StaticLibrary('bsl_check_cast', PreBuilt(True)) -StaticLibrary('bsl_exception', PreBuilt(True)) -StaticLibrary('bsl_pool', PreBuilt(True)) -StaticLibrary('bsl_ResourcePool', PreBuilt(True)) -StaticLibrary('bsl_utils', PreBuilt(True)) -StaticLibrary('bsl_var', PreBuilt(True)) -StaticLibrary('bsl_var_implement', PreBuilt(True)) -StaticLibrary('bsl_var_utils', PreBuilt(True)) diff --git a/bsl/BinBuffer.h b/bsl/BinBuffer.h deleted file mode 100644 index 867ae70d2e5fe98485b972222dd3a6edab76d13b..0000000000000000000000000000000000000000 --- a/bsl/BinBuffer.h +++ /dev/null @@ -1,573 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_bin_buffer.h,v 1.0 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - /** - * @file bsl_bin_buffer.h - * @author liaoshangbin(liaoshangbin@baidu.com) - * @date 2010/07/31 13:46:02 / 2010/10/15 modified by zhujianwei - * @version $Revision: 1.0 $ - * @brief - * - **/ - -#ifndef __BSL_BIN_BUFFER_H_ -#define __BSL_BIN_BUFFER_H_ -#include -#include -#include -#include -#include -#include "bsl/utils/bsl_memcpy.h" -#include "bsl/pool/bsl_pool.h" - - - -namespace bsl{ - /** - * @brief 读入数据,并按二进制进行存储 - * - * 该类的一大特点是不会抛出异常。在内存不足的时候,该类会截断字符串并置"被截断位"。 - * BinBuffer对象通过字节对齐方式自行管理一片用于表示字符串的缓冲区,并提供方法追加各种类型对象。 - * 若内存不足时,内存容量将翻倍,若申请新内存失败,将填满旧内存, - * 而且使truncated()方法返回true,ever_truncated()返回true。 - */ - class BinBuffer{ - public: - /** - * @brief 构造函数 - * - * 可传入capacity参数指定预分配的内存空间。如capacity==0没有动态内存分配。 - * 可传入pack参数指定默认字节对齐值,pack要求为2的整数幂并且<=MAX_PACK - * 否则_pack=DEFAULT_PACK - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] capacity : size_t - * @param [in] pack : size_t - * @see - * @author liaoshangbin - * @date 2010/7/29 12:05:10 - **/ - explicit BinBuffer( size_t cap = DEFAULT_CAPACITY, size_t pack = DEFAULT_PACK) - :_size(0), _capacity(cap), _pack(pack), - _truncated(false), _ever_truncated(false), _str(NULL), _mempool(NULL) { - if ( _capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity) : _mempool->malloc(_capacity)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - if(!(pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two(pack))){ - _pack = DEFAULT_PACK; - } - } - - /** - * @brief 使用allocator的构造函数 - * - * 可传入capacity参数指定预分配的内存空间。如capacity==0没有动态内存分配。 - * 可传入pool参数指定使用的内存池 - * 可传入pack参数指定默认字节对齐值,pack要求为2的整数幂并且<=MAX_PACK - * 否则_pack=DEFAULT_PACK - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] pool : mempool& - * @param [in] capacity : size_t - * @param [in] pack : size_t - * @see - * @author - * @date 2010/7/29 12:06:16 - **/ - explicit BinBuffer( - mempool& pool, - size_t cap = DEFAULT_CAPACITY, - size_t pack = DEFAULT_PACK - ) - :_size(0), _capacity(cap), _pack(pack), - _truncated(false), _ever_truncated(false), _str(NULL), _mempool(&pool) { - if ( _capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity) : _mempool->malloc(_capacity)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - if(!(pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two(pack))) { - _pack = DEFAULT_PACK; - } - } - - /** - * @brief 把另一BinBuffer的内存转移到本BinBuffer(另一BinBuffer会被清空),O(1)复杂度 - * 因为不同BinBuffer使用的内存池会有不同 - * 先释放自身_str的内存,然后_str指向other._str浅复制字符串, - * 自身的_mempool指向other._mempool,这样_mempool还是处理_str这块内存 - * 最后清空other._str,other成为空的BinBuffer还可以继续使用 - * - * @param [in] other : BinBuffer& - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 17:45:30 - **/ - BinBuffer& transfer_from ( BinBuffer& other ){ - if ( &other != this ){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - _size = other._size; - _capacity = other._capacity; - _pack = other._pack; - _truncated = other._truncated; - _ever_truncated = other._ever_truncated; - _str = other._str; - _mempool = other._mempool; - other._size = 0; - other._capacity = 0; - other._pack = DEFAULT_PACK; - other._truncated= false; - other._ever_truncated = false; - other._str = NULL; - } - return *this; - } - - /** - * @brief 交换两BinBuffer内容,O(1)复杂度 - * - * @param [in] other : BinBuffer& - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:15 - **/ - void swap( BinBuffer& other ){ - std::swap( _str, other._str ); - std::swap( _size, other._size ); - std::swap( _capacity, other._capacity ); - std::swap( _pack, other._pack ); - std::swap( _truncated, other._truncated ); - std::swap( _ever_truncated, other._ever_truncated ); - std::swap( _mempool, other._mempool ); - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 18:14:47 - **/ - ~BinBuffer(){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - } - - /** - * @brief BinBuffer长度 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:56 - **/ - size_t size() const{ - return _size; - } - - /** - * @brief BinBuffer当前容量。保证容量>=长度。当容量不足时,容量会自动增长。 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:15:23 - **/ - size_t capacity() const { - return _capacity; - } - - /** - * @brief 返回BinBuffer是否为空 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:26 - **/ - bool empty() const { - return _size == 0; - } - - /** - * @brief 返回BinBuffer是否为满 - * - * @return bool - * @retval - * @see - * @author - * @date - **/ - bool full() const { - return _size == _capacity; - } - - /** - * @brief 返回BinBuffer最近一次操作是否发生了截断 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:58 - **/ - bool truncated() const { - return _truncated; - } - - /** - * @brief 返回BinBuffer到目前为止是否发生了截断 - * - * @return bool - * @retval - * @see - * @author liaoshangbin - * @date 2010/07/31 14:49:24 - **/ - bool ever_truncated() const { - return _ever_truncated; - } - - /** - * @brief 返回BinBuffer内容的C风格字符串表示。O(1)复杂度 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:17:26 - **/ - const char * data() const { - if ( _str ){ - return _str; - }else{ - return ""; - } - } - - /** - * @brief 清空内容 - * - * @return void - * @retval - * @see - * @author liaoshangbin - * @date - **/ - void clear() { - if ( _size ){ - _str[0] = '\0'; - } - _size = 0; - } - - /** - * @brief 手动扩大内存容量 - * - * @param [in] __capacity : size_t - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:34 - **/ - bool reserve( size_t cap ) { - if ( cap > _capacity ){ - if ( cap < _capacity * 2 ){ - cap = _capacity * 2; - } - - char * _new = static_cast(_mempool == NULL ? - malloc(cap) :_mempool->malloc(cap)); - if ( !_new ){ - return false; - } - - if ( _str ){ - xmemcpy( _new, _str, _size ); - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - - _str = _new; - _capacity = cap; - } - - return true; - } - - /** - * @brief 追加另一个BinBuffer,other按照min(other.get_pack(), this->_pack)字节对齐 - * - * @param [in] other : const BinBuffer& - * @return BinBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:49:30 - **/ - BinBuffer& operator << (const BinBuffer& other){ - size_t pack = other.get_pack(); - pack = pack < _pack ? pack : _pack; - _size = (_size + pack - 1) & (~(pack-1)); - return push( other.data(), other.size() ); - } - - /** - * @brief 处理数值类型 - * bool,signed char,unsigned char,short,unsigned short,int - * unsigned int,long int,unsigned long int,long long - * unsigned long lont,double,long double - * - * wchar_t:可输入任意的宽字符,包括'\0' - * char:可输入任意的字符,包括'\0' - * - * @param [in] value : _Tp - * @return BinBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/20 12:23:07 - **/ - template - BinBuffer& operator << ( _Tp value ) { - return push_bin_data( &value, sizeof(value) ); - } - - /** - * @brief 追加另一个BinBuffer,新的BinBuffer按照min(other.get_pack(), this->_pack)字节对齐 - * - * @param [in] other : const BinBuffer& - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:54:00 - **/ - BinBuffer& push(const BinBuffer& other){ - size_t pack = other.get_pack(); - pack = pack > _pack ? pack : _pack; - _size = (_size + pack - 1) & (~(pack-1)); - return push( other.data(), other._size ); - } - - /** - * @brief 处理数值类型 - * bool,signed char,unsigned char,short,unsigned short,int - * unsigned int,long int,unsigned long int,long long - * unsigned long lont,double,long double - * - * wchar_t:可输入任意的宽字符,包括'\0' - * char:可输入任意的字符,包括'\0' - * - * @param [in] value : _Tp - * @return BinBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/20 12:23:07 - **/ - template - BinBuffer& push( _Tp value ) { - return push_bin_data( &value, sizeof(value) ); - } - - /** - * @brief 追加多个任意字符 - * - * @param [in] count : int - * @param [in] c : char - * @return BinBuffer& - * @retval - * @see - * @author chenxm / zhujianwei - * @date 2009/02/04 18:40:04 / mod. by zhjw at 2010/09/21 - **/ - BinBuffer& push( size_t count, char c){ - if ( count > _capacity - _size ){ //full - count = (count <= size_t(-1) - _size) ? count : (size_t(-1) - _size); //limit the size - if( !reserve( _size + count ) ){ - //reserve fail - count = _capacity - _size; - _truncated = true; - _ever_truncated = true; - }else{ - _truncated = false; - } - } - if ( count ){ - //str != NULL - memset( _str + _size, c, count ); - _size += count; - } - return *this; - } - - /** - * @brief 追加len长度的数据 - * - * 调用者必须保证data指向的数据长度不大于len,否则行为未定义 - * - * @param [in] data_ : const void* - * @param [in] len : size_t - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:28 - **/ - BinBuffer& push(const void* data_, size_t len ); - - /** - * @brief 自定义字节对齐值 - * 返回值为true表示设置成功,false表示设置失败 - * - * @param [in] pack : size_t - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 17:46:41 - **/ - bool set_pack( size_t pack ) { - if ( pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two( pack ) ) { - _pack = pack; - return true; - } - return false; - } - - /** - * @brief 返回自定义字节对齐值 - * - * @param - * @return size_t - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/03 10:48:18 - **/ - size_t get_pack() const { - return _pack; - } - - public: - /** - * @brief 默认容量大小 - */ - static const size_t DEFAULT_CAPACITY = 64; - /** - * @brief 默认字节对齐值 - */ - static const size_t DEFAULT_PACK = 4; - /** - * @brief 默认最大字节对齐值 - */ - static const size_t DEFAULT_MAX_PACK = 64; - - private: - /** - * @brief 复制构造函数 - */ - BinBuffer( const BinBuffer& other ); - /** - * @brief 复制赋值运算符 - */ - BinBuffer& operator = ( const BinBuffer& ); - /** - * @brief 判断一个整数是否为2的整数幂 - * - * @param [in] n : int - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 15:55:57 - **/ - inline bool is_power_two(size_t n) { - return (((n)&(n-1))==0); - } - /** - * @brief 数值型数据通过此函数插入到buffer中 - * - * @param [in] data : const void* - * @param [in] len : size_t - * @return BinBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 17:50:09 - **/ - BinBuffer& push_bin_data( const void* data_, size_t len ) { - // 根据_pack计算_size的起始位置 - size_t len_ = (len < _pack) ? len : _pack; - _size = (_size + len_ - 1) & (~(len_ - 1)); - // push函数注意如果内存无法分配时调整_size大小 - return push( data_, len ); - } - - /** - * @brief BinBuffer的长度 - */ - size_t _size; - /** - * @brief BinBuffer的容量 - */ - size_t _capacity; - /** - * @brief 自定义字节对齐值 - */ - size_t _pack; - /** - * @brief 最近一次操作是否发生截断 - */ - bool _truncated; - /** - * @brief 到目前为止是否发现截断 - */ - bool _ever_truncated; - /** - * @brief BinBuffer的内部字符串缓冲区 - */ - char * _str; - - /** - * @brief 当前使用的内存池的指针 - * - **/ - mempool* _mempool; - - }; - -} //namespace bsl; - - -#endif //__BSL_AUTO_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/CMakeLists.txt b/bsl/CMakeLists.txt deleted file mode 100644 index 36954eff6873f027e7586d9d6eadaf840d9c719f..0000000000000000000000000000000000000000 --- a/bsl/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/ - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/ && cp ${CMAKE_CURRENT_LIST_DIR}/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/ - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/utils && cp ${CMAKE_CURRENT_LIST_DIR}/utils/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/utils - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/alloc && cp ${CMAKE_CURRENT_LIST_DIR}/alloc/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/alloc - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/archive && cp ${CMAKE_CURRENT_LIST_DIR}/archive/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/archive - # COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/containers && cp ${CMAKE_CURRENT_LIST_DIR}/containers/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/containers - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/check_cast && cp ${CMAKE_CURRENT_LIST_DIR}/check_cast/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/check_cast - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/ResourcePool && cp ${CMAKE_CURRENT_LIST_DIR}/ResourcePool/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/ResourcePool - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/var/ && cp ${CMAKE_CURRENT_LIST_DIR}/var/utils/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/var/ - COMMAND cp ${CMAKE_CURRENT_LIST_DIR}/var/interface/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/var/ - COMMAND cp ${CMAKE_CURRENT_LIST_DIR}/var/implement/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/var/ - COMMAND cp ${CMAKE_CURRENT_LIST_DIR}/check_cast/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl - COMMAND cp ${CMAKE_CURRENT_LIST_DIR}/ResourcePool/*.h ${CMAKE_CURRENT_BINARY_DIR}/include/bsl/ - ) -add_custom_target(copy_bsl_headers - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/include/) - -include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) -add_subdirectory(utils) -add_subdirectory(alloc) -add_subdirectory(archive) -add_subdirectory(containers) -add_subdirectory(pool) -add_subdirectory(buffer) -add_subdirectory(exception) -add_subdirectory(check_cast) -add_subdirectory(ResourcePool) -add_subdirectory(var/interface) -add_subdirectory(var/utils) -add_subdirectory(var/implement) -add_library(bsl) -add_dependencies(bsl utils alloc archive containers pool buffer exception - check_cast ResourcePool interface var_utils implement) -target_link_libraries(bsl - buffer utils archive pool exception check_cast - ResourcePool var_utils implement) diff --git a/bsl/README b/bsl/README deleted file mode 100644 index 4b812d66ff21140a15b2d95abe04ae5fcd9a1074..0000000000000000000000000000000000000000 --- a/bsl/README +++ /dev/null @@ -1,8 +0,0 @@ -32位编译比如加入如下参数: -D_XOPEN_SOURE=500 -D_GNU_SOURCE -ftemplate-depth-128 - -参考wiki - http://com.baidu.com/twiki/bin/view/Main/ComBSLIntroduct - - -demo 路径 - cvspath: opencode/bsl_demo/ diff --git a/bsl/ResourcePool/BCLOUD b/bsl/ResourcePool/BCLOUD deleted file mode 100644 index 52396eef9148e512a8933ba85b8b5f59143f99c5..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/BCLOUD +++ /dev/null @@ -1,65 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DVAR_DEBUG_FLAG -DBSL_VERSION=\"bsl1.1.0.0\" -DBSL_CVSTAG=\"bsl_1-1-0-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') - -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libexception.a') -#LIBS('$OUT/so/libexception.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('bsl_wrappers.h bsl_wrappers_config.h', '$INC/bsl/ResourcePool') -HEADERS('*.h', '$INC/bsl/') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('ResourcePool', Sources(user_sources)) - -#UT -#UTApplication('ResourcePool', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_ResourcePool', Sources(user_sources)) - -#sub directory -#Directory('demo') - diff --git a/bsl/ResourcePool/CMakeLists.txt b/bsl/ResourcePool/CMakeLists.txt deleted file mode 100644 index 07332096546258b87f8b201fe80670302c6ee8c1..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -FILE(GLOB ResourcePool_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(ResourcePool ${ResourcePool_srcs}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/ResourcePool/Makefile b/bsl/ResourcePool/Makefile deleted file mode 100644 index 3b314e57bdaaa7c51b28eecf80084957a807e437..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = ../var -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_ENTRANCES = ResourcePool.h ShallowCopyString.h - -PROVIDE_HEADS = $(wildcard *.h) - -PROVIDE_OBJECTS = ResourcePool.o ShallowCopyString.o - -PROVIDE_LIB = bsl_ResourcePool - -DEPEND_HEADS = $(PROVIDE_HEADS) - -DEPEND_OBJECTS = - -DEPEND_LIBS = - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -##### OVERWRITE ##### - -OUTPUT_HEAD_PATH= $(BSL_ROOT)/output/include/bsl/ResourcePool - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### -check_cast_generated.h: check_cast.py - ./$^ > $@ - - diff --git a/bsl/ResourcePool/ResourcePool.cpp b/bsl/ResourcePool/ResourcePool.cpp deleted file mode 100644 index ef023c23199f8ed9377dc275074cf2e60d789791..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/ResourcePool.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ResourcePool.cpp,v 1.5 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - -/** - * @file ResourcePool.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/06 11:14:09 - * @version $Revision: 1.5 $ - * @brief - * - **/ - -#include -#include "bsl/ResourcePool.h" - -namespace bsl{ - - /** - * @brief 清理所有受托管的资源 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 15:34:03 - **/ - void ResourcePool::reset(){ - for (block_list_node_t *p_node = _p_alloc_object_list; - NULL != p_node; - p_node = p_node->p_next ){ - for( alloc_object_info_t* p_item = p_node->data + p_node->current; - p_item >= p_node->data; - --p_item ){ - p_item->destructor(p_item->p_object, _mempool); - } - } - _clear_info_list(_p_alloc_object_list); - for (block_list_node_t *p_node = _p_alloc_array_list; - NULL != p_node; - p_node = p_node->p_next ){ - for( alloc_array_info_t* p_item = p_node->data + p_node->current; - p_item >= p_node->data; - --p_item ){ - p_item->destructor(p_item->begin, p_item->end, _mempool); - } - } - _clear_info_list(_p_alloc_array_list); - - for (block_list_node_t *p_node = _p_attach_object_list; - NULL != p_node; - p_node = p_node->p_next ){ - for( attach_object_info_t* p_item = p_node->data + p_node->current; - p_item >= p_node->data; - --p_item ){ - p_item->destructor(p_item->p_object); - } - } - _clear_info_list(_p_attach_object_list); - for (block_list_node_t *p_node = _p_attach_array_list; - NULL != p_node; - p_node = p_node->p_next ){ - for( attach_array_info_t* p_item = p_node->data + p_node->current; - p_item >= p_node->data; - --p_item ){ - p_item->destructor(p_item->begin, p_item->end); - } - } - _clear_info_list(_p_attach_array_list); - } - - const char * ResourcePool::_vprintf( - alloc_array_info_t& info, - size_t hint_capacity, - const char *format, - va_list ap - ){ - //参数检查 - size_t size = hint_capacity + 1; - char* str = static_cast(_mempool.malloc(size)); - if ( !str ){ - throw bsl::BadAllocException()< allocator_type; - - /** - * @brief 清理单个资源/对象的回调函数指针 - * - * 该回调函数以资源指针(如FILE*)/对象地址作为参数,没有返回值 - * ng_wrappers.h有针对常见资源的实现,建议尽量使用ng_wrappers.h的实现 - */ - typedef void( *object_destructor_t )(void * p_object); - - /** - * @brief 清理资源数组、对象数组的回调函数指针 - * - * 该回调函数以数组的首址、尾址(=首址+数组大小)作为参数,没有返回值。 - */ - typedef void( *array_destructor_t )(void * begin, void * end); - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2008/08/12 18:07:42 - **/ - ResourcePool() - :_syspool(), - _mempool(_syspool), - _p_attach_object_list(NULL), - _p_attach_array_list(NULL), - _p_alloc_object_list(NULL), - _p_alloc_array_list(NULL){} - - /** - * @brief 使用allocator的构造函数。 - * - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/09 17:52:35 - **/ - explicit ResourcePool( mempool& pool ) - :_mempool(pool), - _p_attach_object_list(NULL), - _p_attach_array_list(NULL), - _p_alloc_object_list(NULL), - _p_alloc_array_list(NULL){} - - /** - * @brief 析构函数 - * - * 资源池析构时,会调用destroy_all()方法。 - * - * @see destroy_all() - * @author chenxm - * @date 2008/08/12 18:08:06 - **/ - ~ResourcePool(){ - reset(); - } - - allocator_type get_allocator() const { - return allocator_type(&_mempool); - } - - /** - * @brief 返回ResourcePool的内存池对象 - * - * @param - * @return mempool& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/04 16:41:40 - **/ - - mempool& get_mempool() const { - return _mempool; - } - - /** - * @brief 使资源池托管资源的方法。 - * - * 清理函数将会在destroy_all()被调用或资源池析构时被自动调用。 - * - * 注: - * 可以的话,尽量使用create_xxx()方法或clone_xxx()方法,以降低出错的可能性 - * 如果已经把资源attach到资源池,无论如何也不要试图自行释放资源! - * 若destructor == NULL 本函数简单地忽略该请求(既然没事情要干,也没必要做记录了) - * 若data == NULL 本函数不做特别处理(NULL会被传递给destructor) - * 如果在创建过程中发生了异常(内存不足,非常罕有但仍有可能),资源会立刻被清理 - * - * @param [in] data : void* 资源指针/对象地址 - * @param [in] destructor : object_destructor_t 清理资源的回调函数/析构对象的方法 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 18:09:38 - **/ - void attach( void * p_object, object_destructor_t destructor ){ - if ( NULL != destructor ){ - try{ - attach_object_info_t& info = _push_info(_p_attach_object_list); //throw - info.p_object = p_object; - info.destructor = destructor; - }catch(...){ - destructor( p_object ); - throw; - } - } - } - - - /** - * - * @brief 使资源池托管资源数组/对象数组的方法。 - * - * 清理函数将会在destroy_all()被调用或资源池析构时被自动调用。 - * - * 注: - * 可以的话,尽量使用create_xxx()方法或clone_xxx()方法,以降低出错的可能性 - * 如果已经把资源attach到资源池,无论如何也不要试图自行释放资源! - * 若destructor == NULL 本函数简单地忽略该请求(既然没事情要干,也没必要做记录了) - * 若begin == end 本函数不做特别处理(NULL会被传递给destructor) - * 如果在创建过程中发生了异常(内存不足,非常罕有但仍有可能),资源会立刻被清理 - * - * @param [in] begin : void* - * @param [in] end : void* - * @param [in] destructor : array_destructor_t - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 19:49:11 - **/ - void attach_array( void *begin, void *end, array_destructor_t destructor ){ - if ( NULL != destructor ){ - try{ - attach_array_info_t& info = _push_info(_p_attach_array_list); //throw - info.begin = begin; - info.end = end; - info.destructor = destructor; - }catch(...){ - destructor( begin, end ); - throw; - } - } - } - - /** - * @brief 调用T类型的默认构造函数,创建一个T对象,该对象已被资源池托管 - * - * @return T& - * @retval 被创建对象的引用 - * @see - * @author chenxm - * @date 2008/08/12 19:51:31 - **/ - template - T& create(){ - return _create_object( DefaultCtor() ); - } - - template - T* createp(){ - try{ - return &_create_object( DefaultCtor() ); - }catch(...){ - return NULL; - } - } - - /** - * @brief 调用T类型的单参数构造函数(特别地,当T_arg = T时,为复制构造函数),创建一个对象,该对象已被资源池托管。 - * - * @param [in] __arg : const T_arg& - * @return T& - * @retval 被创建对象的引用 - * @see - * @author chenxm - * @date 2008/08/12 19:53:25 - **/ - template - T& create(const T_arg& arg_){ - return _create_object( OneConstArgCtor(arg_) ); - } - - /** - * @brief 调用T类型的单参数构造函数,创建一个对象,该对象已被资源池托管。 - * - * @param [in] __arg : const T_arg& - * @return T& - * @retval 被创建对象的引用 - * @see - * @author chenxm - * @date 2008/08/12 19:53:25 - **/ - template - T& createn(T_arg& arg_){ - return _create_object( OneArgCtor(arg_) ); - } - - /** - * @brief 不抛异常,返回指针的接口 - * - * NOTE:不抛异常可能更符合C程序员的习惯,但 - * - * @param [in] arg_ : const T_arg& - * @return T* - * @retval - * @see - * @author chenxm - * @date 2009/09/27 17:55:02 - **/ - template - T* createp(const T_arg& arg_){ - try{ - return &_create_object( OneConstArgCtor(arg_) ); - }catch(...){ - return NULL; - } - } - /** - * @brief 双参数构造 - * - * @param [in] arg1 : const T_arg1& - * @param [in] arg2 : const T_arg2& - * @return T& - * @retval 新构造的受托管对象的引用 - * @see - * @author chenxm - * @date 2008/09/19 15:10:01 - **/ - template - T& create( const T_arg1& arg1, const T_arg2& arg2 ){ - return _create_object( TwoConstArgCtor(arg1,arg2) ); - } - - template - T* createp( const T_arg1& arg1, const T_arg2& arg2 ){ - try{ - return &_create_object( TwoConstArgCtor(arg1,arg2) ); - }catch(...){ - return NULL; - } - } - - /** - * @brief 三参数构造 - * - * 目前构造需要执行两遍构造函数(多参构造与复制构造),将来需求大时可以优化一下 - * - * @param [in] arg1 : const T_arg1& - * @param [in] arg2 : const T_arg2& - * @param [in] arg3 : const T_arg3& - * @return T& - * @retval 新构造的受托管对象的引用 - * @see - * @author chenxm - * @date 2008/09/19 15:10:01 - **/ - template - T& create( const T_arg1& arg1, const T_arg2& arg2, const T_arg3 arg3 ){ - return _create_object( - ThreeConstArgCtor(arg1, arg2, arg3) - ); - } - - template - T* createp( const T_arg1& arg1, const T_arg2& arg2, const T_arg3 arg3 ){ - try{ - return &_create_object( - ThreeConstArgCtor(arg1, arg2, arg3) - ); - }catch(...){ - return NULL; - } - } - /** - * @brief 四参数构造 - * - * 目前构造需要执行两遍构造函数(多参构造与复制构造),将来需求大时可以优化一下 - * - * @param [in] arg1 : const T_arg1& - * @param [in] arg2 : const T_arg2& - * @param [in] arg3 : const T_arg3& - * @param [in] arg4 : const T_arg4& - * @return T& - * @retval 新构造的受托管对象的引用 - * @see - * @author chenxm - * @date 2008/09/19 15:10:01 - **/ - template - T& create( - const T_arg1& arg1, - const T_arg2& arg2, - const T_arg3 arg3, - const T_arg4 arg4 - ){ - return _create_object( - FourConstArgCtor( - arg1, - arg2, - arg3, - arg4 - ) ); - } - - template - T* createp( - const T_arg1& arg1, - const T_arg2& arg2, - const T_arg3 arg3, - const T_arg4 arg4 - ){ - try{ - return &_create_object( - FourConstArgCtor( - arg1, - arg2, - arg3, - arg4 - ) ); - }catch(...){ - return NULL; - } - } - - /** - * @brief 调用T类型的默认构造函数,创建一个长度为n的T对象数组,该对象数组已被资源池托管 - * - * @param [in] n : int - * @return T* - * @retval 被创建的对象数组的首址 - * @see - * @author chenxm - * @date 2008/08/12 19:55:45 - **/ - template - T* create_array( size_t n ){ - T *begin = NULL; - //抛异常表示info都分配不了,没什么可回滚的。 - alloc_array_info_t& info = _push_info(_p_alloc_array_list); //throw - try{ - begin = static_cast(_mempool.malloc( n * sizeof(T) )); //throw - if ( !begin ){ - throw bsl::BadAllocException() - <(begin, begin + n); //throw (by user code) - info.begin = begin; - info.end = begin + n; - info.destructor = _s_destroy_and_deallocate_array; - return begin; - }catch(...){ - //回滚为对象数组分配的内存 - _mempool.free( begin, n * sizeof(T) ); - throw; - } - }catch(...){ - //回滚info的分配 - _pop_info(_p_alloc_array_list); - throw; - } - } - - /** - * @brief 调用T类型的单参数构造函数(特别地,当T_arg = T时,为复制构造函数),创建一个长度为n的对象数组,该对象数组已被资源池托管。 - * - * @param [in] n : int - * @param [in] __arg : const T_arg& - * @return T* - * @retval 被创建的对象数组的首址 - * @see - * @author chenxm - * @date 2008/08/12 19:56:58 - **/ - template - T* create_array( size_t n, const T_arg& __arg ){ - T *begin = NULL; - //抛异常表示info都分配不了,没什么可回滚的。 - alloc_array_info_t& info = _push_info(_p_alloc_array_list); //throw - try{ - begin = static_cast(_mempool.malloc( n * sizeof(T) )); //throw - if ( !begin ){ - throw bsl::BadAllocException() - <(begin, begin + n, &__arg); //throw (by user code) - info.begin = begin; - info.end = begin + n; - info.destructor = _s_destroy_and_deallocate_array; - return begin; - }catch(...){ - //回滚为对象数组分配的内存 - _mempool.free( begin, n * sizeof(T) ); - throw; - } - }catch(...){ - //回滚info的分配 - _pop_info(_p_alloc_array_list); - throw; - } - } - - /** - * @brief 创建一个大小为bytes字节的未初始化空间。该空间已被资源池托管。 - * - * @param [in] bytes : int - * @return void* - * @retval 被创建的空间的首址 - * @see - * @author chenxm - * @date 2008/08/12 19:58:56 - **/ - void * create_raw( size_t bytes ){ - alloc_array_info_t& info = _push_info(_p_alloc_array_list); //throw - try{ - char * res = static_cast(_mempool.malloc( bytes )); //throw - if ( !res ){ - throw bsl::BadAllocException() - < - T& clone(const T& src){ - return create(src); - } - - /** - * @brief 通过复制构造函数,创建一个T对象数组的副本,该副本已被资源池托管。 - * - * 注:如果谁敢复制一个void数组还问我为什么编译不过的话,我一定会打他的PP - * - * @param [in] src : const T* 被复制的对象数组的首址 - * @param [in] n : int 被复制的对象数组的长度 - * @return T* - * @retval 被创建的对象数组的首址 - * @see - * @author chenxm - * @date 2008/08/12 20:02:11 - **/ - template - T* clone_array(const T* src, size_t n){ - T *begin = NULL; - //抛异常表示info都分配不了,没什么可回滚的。 - alloc_array_info_t& info = _push_info(_p_alloc_array_list); //throw - try{ - begin = static_cast(_mempool.malloc(n*sizeof(T))); //throw - if ( !begin ){ - throw bsl::BadAllocException() - <; - return begin; - }catch(...){ - //回滚为对象数组分配的内存 - _mempool.free(begin, n*sizeof(T)); - throw; - } - }catch(...){ - //回滚info的分配 - _pop_info(_p_alloc_array_list); - throw; - } - } - - /** - * @brief 使用直接内存复制方式创建一个大小为bytes字节的空间的副本。该副本已被资源池托管。 - * - * @param [in] p : void* - * @param [in] bytes : int - * @return void* - * @retval - * @see - * @author chenxm - * @date 2008/08/13 11:15:20 - **/ - void * clone_raw( const void * src, size_t bytes ){ - void * res = create_raw( bytes ); - return xmemcpy( res, src, bytes ); - } - - /** - * @brief 创建一个C风格字符串的副本,该副本已被资源池托管。 - * - * @param [in] src_str : const char* 被复制的C风格字符串首址 - * @return char* - * @retval 被创建的C风格字符串的首址 - * @see - * @author chenxm - * @date 2008/08/09 16:06:58 - **/ - char * clone_cstring(const char * src_str ){ - size_t size = strlen(src_str) + 1; - void * res = clone_raw( src_str, size ); //throw - return static_cast(res); - } - - /** - * @brief 创建一个C风格字符串或其子串的副本,该副本已被资源池托管。 - * - * 注意:若sub_str_len > strlen(src_str),本方法行为未定义。 - * - * @param [in] src_str : const char* - * @param [in] sub_str_len : size_t - * @return char* - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:26:43 - **/ - char * clone_cstring(const char * src_str, size_t sub_str_len ){ - char * res = static_cast(clone_raw( src_str, sub_str_len + 1 )); //throw - res[sub_str_len] = 0; - return res; - } - - /** - * @brief 通过类似printf()的语法生成受托管的字符串。 - * - * 在目前的实现里,crcprintf(...)相当于crcprintf_hint( 63, ... ) - * - * @param [in] format : const char* - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 15:30:58 - **/ - const char * crcprintf( const char * format, ... )__attribute__ ((format (printf, 2, 3) )); - - /** - * @brief 通过类似printf()的语法生成受托管的字符串。预分配不少于hint_capacity+1字节的空间以提高效率。 - * - * @param [in] hint_capacity : size_t - * @param [in] format : const char* - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 15:31:50 - **/ - const char * crcprintf_hint( - size_t hint_capacity, - const char * format, - ... - )__attribute__ ((format (printf, 3, 4) )); - - /** - * @brief 通过类似vprintf()语法生成受托管的字符串 - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return const char* - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/04 10:10:34 - **/ - const char * vcrcprintf( const char * format, va_list ap ); - - /** - * @brief 通过类似vprintf()的语法生成受托管的字符串。预分配不少于hint_capacity+1字节的空间以提高效率。 - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return const char* - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/04 10:43:02 - **/ - const char * vcrcprintf_hint( size_t hint_capacity, const char * format, va_list ap ); - - - - /** - * @brief 清理所有受托管的资源 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 15:34:03 - **/ - void reset(); - - private: - static const size_t _S_ITEMS_PER_NODE = 64; - - /** - * @brief 清理单个资源/对象,并通过alloc_回收内存的回调函数指针 - * - */ - typedef void( *alloc_object_destructor_t )(void * p_object, mempool& pool ); - - /** - * @brief 清理资源数组、对象数组,并通过alloc_回收内存的回调函数指针 - * - * 该回调函数以数组的首址、尾址(=首址+数组大小)作为参数,没有返回值。 - */ - typedef void( *alloc_array_destructor_t )(void * begin, void * end, mempool& pool ); - - /** - * @brief 记录通过attach()托管的单个资源/对象信息的结构体(不用dealloc) - * - * - */ - struct attach_object_info_t{ - void *p_object; - object_destructor_t destructor; - }; - - /** - * @brief 记录通过attach()托管的资源数组/对象数组信息的结构体(不用dealloc) - * - * - */ - struct attach_array_info_t{ - void *begin; - void *end; - array_destructor_t destructor; - }; - - /** - * @brief 记录资源池新建的单个资源/对象信息的结构体(需要dealloc) - * - * - */ - struct alloc_object_info_t{ - void *p_object; - alloc_object_destructor_t destructor; - }; - - /** - * @brief 记录资源池新建的资源数组/对象数组信息的结构体(需要dealloc) - * - * - */ - struct alloc_array_info_t{ - void *begin; - void *end; - alloc_array_destructor_t destructor; - }; - - template - struct block_list_node_t{ - block_list_node_t *p_next; - size_t current; - info_t data[_S_ITEMS_PER_NODE]; - }; - - /** - * @brief 默认构造函数 - * - */ - //构造函数仿函数,相当于lambda表达式 - template - class DefaultCtor{ - public: - void operator ()( T* ptr ) const { - new(ptr) T(); - } - }; - - /** - * @brief 单参数构造函数 - * - */ - template - class OneArgCtor{ - public: - OneArgCtor( ArgT& arg ) - :_arg(arg){} - void operator ()( T* ptr ) const { - new(ptr) T(_arg); - } - private: - ArgT& _arg; - }; - - /** - * @brief 单参数构造函数 - * - */ - template - class OneConstArgCtor{ - public: - OneConstArgCtor( const ArgT& arg ) - :_arg(arg) {} - void operator ()( T* ptr ) const { - new(ptr) T(_arg); - } - private: - const ArgT& _arg; - }; - - /** - * @brief 双参数构造 - * - */ - template - class TwoConstArgCtor{ - public: - TwoConstArgCtor( const Arg1T& arg1, const Arg2T& arg2 ) - :_arg1(arg1), _arg2(arg2) {} - void operator ()( T* ptr ) const { - new(ptr) T(_arg1, _arg2); - } - private: - const Arg1T& _arg1; - const Arg2T& _arg2; - }; - /** - * @brief 三参数构造 - * - */ - template - class ThreeConstArgCtor{ - public: - ThreeConstArgCtor( const Arg1T& arg1, const Arg2T& arg2, const Arg3T& arg3 ) - :_arg1(arg1), _arg2(arg2), _arg3(arg3) {} - void operator ()( T* ptr ) const { - new(ptr) T(_arg1, _arg2, _arg3); - } - private: - const Arg1T& _arg1; - const Arg2T& _arg2; - const Arg3T& _arg3; - }; - /** - * @brief 四参数构造 - * - */ - template - class FourConstArgCtor{ - public: - FourConstArgCtor( - const Arg1T& arg1, - const Arg2T& arg2, - const Arg3T& arg3, - const Arg4T& arg4 - ) - :_arg1(arg1), _arg2(arg2), _arg3(arg3), _arg4(arg4) {} - void operator ()( T* ptr ) const { - new(ptr) T(_arg1, _arg2, _arg3, _arg4); - } - private: - const Arg1T& _arg1; - const Arg2T& _arg2; - const Arg3T& _arg3; - const Arg4T& _arg4; - }; - - public: - template - T& _create_object( const CtorT& ctor ){ - T *p_object = NULL; - //抛异常表示info都分配不了,没什么可回滚的。 - alloc_object_info_t& info = _push_info(_p_alloc_object_list); //throw - //抛异常表示对象空间分配不了,回滚info的分配。 - try{ - p_object = static_cast(_mempool.malloc(sizeof(T))); - if ( !p_object ){ - throw bsl::BadAllocException() - <; - return *p_object; - }catch(...){ - //回滚对象空间的分配 - _mempool.free( p_object, sizeof(T) ); - throw; - } - }catch(...){ - //回滚对象空间的分配 - _pop_info(_p_alloc_object_list); - throw; - } - } - - private: - template - T* _create_array( size_t n, const ArrayCtorT& ctor ){ - T *begin = NULL; - //抛异常表示info都分配不了,没什么可回滚的。 - alloc_array_info_t& info = _push_info(_p_alloc_array_list); //throw - try{ - begin = static_cast(_mempool.malloc( n * sizeof(T) )); //throw - if ( !begin ){ - throw bsl::BadAllocException() - <(begin, begin + n); - ctor(begin, begin+n); //throw (by user code) - info.begin = begin; - info.end = begin + n; - info.destructor = _s_destroy_and_deallocate_array; - return begin; - }catch(...){ - //回滚为对象数组分配的内存 - _mempool.free( begin, n * sizeof(T) ); - throw; - } - }catch(...){ - //回滚info的分配 - _pop_info(_p_alloc_array_list); - throw; - } - } - /** - * @brief 追加一个新项 - * - * 插入成功后,返回可以写入的新项。 - * 如果块链中的一个块被写满,该函数会申请一个新块。调用之后_p_list_head会指向新块。 - * 若发生内存不足,会抛出mempool指定的异常。 - * 该函数要求info_t不需要构造(C风格struct) - * - * @param [in/out] _p_list_head : block_list_node_t* & - * @param [in] _alloc : allocator_type& - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/04/06 23:03:24 - **/ - template - info_t& _push_info( block_list_node_t *& p_list_head ){ - if ( NULL!=p_list_head && p_list_head->current < _S_ITEMS_PER_NODE - 1 ){ - ++ p_list_head->current; //如果块链未满,只增加计数器 - return p_list_head->data[p_list_head->current]; - }else{ - typedef block_list_node_t node_t; - node_t* p_tmp = static_cast(_mempool.malloc(sizeof(node_t))); //throw - if ( !p_tmp ){ - throw bsl::BadAllocException() - <p_next = p_list_head; - p_tmp->current= 0; - p_list_head = p_tmp; - return p_list_head->data[0]; - } - } - - /** - * @brief 回滚最新追加的项 - * - * @param [in] _p_list_head : block_list_node_t* & - * @param [in] _alloc : allocator_type& - * @return info_t& - * @retval - * @see - * @author chenxm - * @date 2009/04/09 18:33:55 - **/ - template - void _pop_info( block_list_node_t *& p_list_head ){ - if ( p_list_head->current > 0 ){ - -- p_list_head->current; //如果块链不为空,只减少计数器 - }else{ - block_list_node_t* p_tmp = p_list_head; - p_list_head = p_list_head->p_next; - _mempool.free(p_tmp, sizeof(block_list_node_t)); - } - } - - /** - * @brief 释放整个块链表。 - * 函数执行后,p_list_head会被置为NULL。 - * 该函数具有无抛掷保证。 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/04/06 23:08:12 - **/ - template - void _clear_info_list(block_list_node_t *& p_list_head ){ - while( NULL != p_list_head ){ - block_list_node_t *p_tmp = p_list_head; - p_list_head = p_list_head->p_next; - _mempool.free(p_tmp, sizeof(block_list_node_t)); - } - } - - /** - * @brief 资源池对象不可复制 - * - * 用户不应以任何方式创建资源池对象的副本。 - * - * @param [in] other : const ResourcePool& - * @see - * @author chenxm - * @date 2008/08/06 20:32:53 - **/ - ResourcePool( const ResourcePool& other); - - /** - * @brief ResourcePool不可赋值 - * - * 用户不应该以任何方式对ResourcePool赋值 - * - * @return ResourcePool& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/07 00:06:26 - **/ - ResourcePool& operator = ( const ResourcePool& ); - - /** - * @brief 各种rcprintf的实现函数 - * - * @param [in] info : alloc_array_info_t& - * @param [in] hint_capacity : size_t - * @param [in] format : const char* - * @param [in] ap : va_list - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/04/12 00:47:34 - **/ - const char * _vprintf( - alloc_array_info_t& info, - size_t hint_capacity, - const char *format, - va_list ap - ); - /** - * @brief 通过空间分配器释放内存的C风格包裹函数 - * @param [in] begin : void* 被释放的内存块的首址 - * @param [in] end : void* 被释放的内存块的尾址 - * @param [in] alloc_ : allocator_type& 空间分配器 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:43:49 - **/ - static void _s_deallocate( void * begin, void * end, mempool& pool ){ - pool.free( begin, static_cast(end) - static_cast(begin) ); - } - - /** - * @brief destroy(void*)和deallocate(void*, allocator_type&)的组合 - * - * @param [in] p_object : void* - * @return void - * @retval - * @see destroy(void*) - * @see deallocate(void*) - * @author chenxm - * @date 2008/08/12 20:46:56 - **/ - template - static void _s_destroy_and_deallocate( void * p_object, mempool& pool ){ - static_cast(p_object)->~T(); - pool.free(p_object, sizeof(T)); - } - - /** - * @brief destroy_array(void*, void*)和deallocate(void*)的组合 - * - * @param [in] begin : void* - * @param [in] end : void* - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:48:04 - **/ - template - static void _s_destroy_and_deallocate_array( void * begin, void * end, mempool& pool ){ - __BSL_DESTROY(static_cast(begin), static_cast(end)); // this method will be specially optimized to the type which has trivial destructor; - pool.free(begin, static_cast(end) - static_cast(begin) ); - } - - /** - * @brief 封装了::malloc()和::free()的简单mempool - * - * 默认构造的ResourcePool 使用该Pool - */ - syspool _syspool; - - /** - * @brief 当前使用的空间适配器的引用 - * - */ - mempool& _mempool; - /** - * @brief 维护通过attach()托管的单个对象信息的块链表(不需回收内存) - * - * - */ - block_list_node_t *_p_attach_object_list; - /** - * @brief 维护通过attach()托管的对象数组信息的块链表(不需回收内存) - * - * - */ - block_list_node_t *_p_attach_array_list; - /** - * @brief 维护单个对象信息的块链表 - * - * - */ - block_list_node_t *_p_alloc_object_list; - /** - * @brief 维护对象数组信息的块链表 - * - * - */ - block_list_node_t *_p_alloc_array_list; - - - }; - -} // namespace bsl -#endif //__RESOURCEPOOL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/ResourcePool/ShallowCopyString.cpp b/bsl/ResourcePool/ShallowCopyString.cpp deleted file mode 100644 index cc4ca55c3b5878f1c73cf004b51f9c65f3771309..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/ShallowCopyString.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: ShallowCopyString.cpp,v 1.2 2009/06/15 06:29:04 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file ShallowCopyString.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/05/10 22:52:45 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include "ShallowCopyString.h" - -namespace bsl{ -// const char ShallowCopyString::_S_EMPTY_CS[] = ""; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/ResourcePool/ShallowCopyString.h b/bsl/ResourcePool/ShallowCopyString.h deleted file mode 100644 index 4278afcd6839dc3fb332fd803612d9effcd1fda7..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/ShallowCopyString.h +++ /dev/null @@ -1,418 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ShallowCopyString.h,v 1.3 2009/06/15 06:29:04 chenxm Exp $ - * - **************************************************************************/ - -/** - * @file ShallowCopyString.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/08 09:08:18 - * @version $Revision: 1.3 $ - * @brief - * - **/ - -#ifndef __SHALLOWCOPYSTRING_H_ -#define __SHALLOWCOPYSTRING_H_ -#include -#include -#include "bsl/exception/bsl_exception.h" -#include "bsl/containers/string/bsl_string.h" - -namespace bsl{ - - class ShallowCopyString{ - public: - typedef char value_type; - typedef size_t size_type; - typedef long difference_type; - typedef value_type & reference; - typedef const reference const_reference; - typedef value_type * pointer; - typedef const pointer const_pointer; - typedef pointer iterator; - typedef const_pointer const_iterator; -#if __GNUC__ <= 2 - typedef string_char_traits traits_type; -#else - typedef std::char_traits traits_type; -#endif - //ctors and dtors - - /** - * @brief 默认构造函数 - * - * 默认构造的ShallowCopyString表示空串。 - * @param [in] str : const char* - * @see - * @author chenxm - * @date 2008/08/08 11:02:09 - **/ - ShallowCopyString() - : _str(_S_EMPTY_CS()), _length(0){} - - /** - * @brief 隐式构造函数 - * - * 该函数把C风格字符串转化为ShallowCopyString。 - * - * 该方法时间复杂度为O(1),长度被懒惰求值。(直到size()方法第一次被调用) - * - * @param [in] str : const char* - * @see - * @author chenxm - * @date 2009/04/10 17:57:28 - **/ - ShallowCopyString( const char * str ) - : _str(str), _length(npos) { - if ( NULL == str ){ - throw NullPointerException()<& - * @return template - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:44:58 - **/ - template - ShallowCopyString( const bsl::basic_string& bsl_str ) - : _str(bsl_str.c_str()), _length(bsl_str.length()) {}; - - /** - * @brief 使用AutoBuffer构造ShallowCopyString - * - * @param [in] buf : const bsl::AutoBuffer& - * @see - * @author chenxm - * @date 2009/04/14 21:46:07 - **/ - ShallowCopyString( const bsl::AutoBuffer& buf ) - : _str(buf.c_str()), _length(buf.size()){} - - /** - * @brief 复制构造函数 - * - * @param [in] sstr : const ShallowCopyString& - * @see - * @author chenxm - * @date 2009/04/14 21:46:22 - **/ - ShallowCopyString( const ShallowCopyString& sstr ) - : _str(sstr._str), _length(sstr._length) {} - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/04/14 21:46:51 - **/ - ~ShallowCopyString() { - //do nothing - } - - void clear(){ - _str = _S_EMPTY_CS(); - _length = 0; - } - // getters - /** - * @brief 返回C风格字符串 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:47:17 - **/ - const char * c_str() const { - return _str; - } - - /** - * @brief 返回字符串长度 - * - * 若字符串使用ShallowCopyString(const char *)构造并且本函数从未调用过,时间复杂为度O(strlen(this->c_str())),否则为O(1) - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:55:58 - **/ - size_t size() const { - if ( _length == npos ){ - const_cast(_length) = strlen(_str); - } - return _length; - } - - /** - * @brief 返回size() - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:59:39 - **/ - size_t length() const { - return size(); - } - - /** - * @brief 返回size() - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/04/14 21:59:48 - **/ - size_t capacity() const { - return size(); - } - - /** - * @brief 返回第idx个字符 - * - * 注:本函数不检查idx的合法性 - * @param [in] idx : size_t - * @return char[] - * @retval - * @see - * @author chenxm - * @date 2009/04/14 22:00:06 - **/ - char operator []( size_t idx ) const { - return _str[idx]; - } - - /** - * @brief 返回第idx个字符 - * - * 本函数检查idx合法性,若idx>=this->size(),抛出bsl::OutOfBoundException - * @param [in] idx : size_t - * @return char - * @retval - * @see - * @author chenxm - * @date 2009/04/14 22:00:50 - **/ - char at( size_t idx ) const { - if ( idx < this->size() ){ - return _str[idx]; - } - throw bsl::OutOfBoundException()<0 - * 若两字符串首字母不相同,或字符串地址相同,该函数时间复杂度为O(1) - * - * - * @param [in] other : const ShallowCopyString& - * @return int - * @retval - * @see - * @author chenxm - * @date 2009/04/14 22:02:31 - **/ - int compare( const ShallowCopyString& other ) const { - if ( _str[0] != other._str[0] ){ - return traits_type::lt(_str[0], other._str[0]) ? -1 : 1; - } - if ( _str == other._str ){ - return 0; //对于ShallowCopyString来说这是有可能的。 - } - size_t min_size = std::min( size() , other.size() ); - int ret = memcmp( _str, other._str, min_size ); - if ( ret == 0 ){ - if (_length > other._length) { - return 1; - } else if (_length == other._length) { - return 0; - } else { - return -1; - } - }else{ - return ret; - } - } - - //comparers - //因为const char *转换为ShallowCopyString是O(1)的,ShallowCopyString与一个随机的C字符串比较也是平均O(1)的(预判断第一字节),所以不专门对C字符串做比较函数了。 - friend inline bool operator == (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) == 0; - } - - friend inline bool operator != (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) != 0; - } - - friend inline bool operator < (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) < 0; - } - - friend inline bool operator > (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) > 0; - } - - friend inline bool operator <= (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) <= 0; - } - - friend inline bool operator >= (const ShallowCopyString& sstr1, const ShallowCopyString& sstr2){ - return sstr1.compare( sstr2 ) >= 0; - } - - /** - * @brief 输出到输出流 - * - * @param [in] os : std::ostream& - * @param [in] sstr : const ShallowCopyString& - * @return friend inline std::ostream& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/14 22:14:58 - **/ - friend inline std::ostream& operator << ( std::ostream& os, const ShallowCopyString& sstr ){ - return os << sstr._str ; - } - - static const size_t npos = static_cast(-1); - - private: - const char * _str; - size_t _length; - - static const char *_S_EMPTY_CS(){ - static const char ret[] = ""; - return ret; - }; - }; -} // namespace bsl - -/** - * @brief 定义bsl::ShallowCopyString追加到bsl::AutoBuffer的运算符 - * - * @param [in] buf : bsl::AutoBuffer& - * @param [in] str : bsl::ShallowCopyString& - * @return bsl::AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/05/09 01:59:57 -**/ -inline bsl::AutoBuffer& operator <<( bsl::AutoBuffer& buf, bsl::ShallowCopyString& str ){ - return buf.push(str.c_str(), str.length()); -} - -#if __GNUC__ >=3 -namespace __gnu_cxx{ -#else -namespace std{ -#endif - /** - * @brief 针对__gnu_cxx::hash编写的hasher - * - * 使用与const char*相同的hash算法。 - */ - template<> - struct hash{ - size_t operator()(const bsl::ShallowCopyString& str ) const { - return __stl_hash_string(str.c_str()); - } - }; -} // namespace __gnu_cxx/std - -namespace bsl{ - /** - * @brief 针对bsl::xhash编写的hasher - * - * 使用与const char*相同的hash算法。 - */ - template<> - struct xhash{ - size_t operator()(const bsl::ShallowCopyString& str ) const { - return __bsl_hash_string(str.c_str()); - } - }; -} // namespace bsl - -#endif //__SHALLOWCOPYSTRING_H_ -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/ResourcePool/bsl_wrappers.h b/bsl/ResourcePool/bsl_wrappers.h deleted file mode 100644 index dd20a4a38076d9c9f0f937f0eb8bd0d3d3fe9a89..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/bsl_wrappers.h +++ /dev/null @@ -1,352 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_wrappers.h,v 1.2 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - -/** - * @file bsl_wrappers.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/06 00:24:12 - * @version $Revision: 1.2 $ - * @brief 该文件定义了大量的函数包裹器,把各种具有C++特色的函数,如构造函数、析构函数、new运算符、delete运算符、模版函数等,包装成简单的C风格函数的类型。从而可以用作函数指针,或向后兼容C风格的函数接口 - * - * - * “把一切龌龊的实现都包藏起来,从此C程序员也可以很开心地玩C++了” - * - * 注:不建议对C++不熟悉者修改本文件的代码 - * - **/ - -#ifndef __BSL_WRAPPERS_H_ -#define __BSL_WRAPPERS_H_ - -#include -#include -#include -#include "bsl/ResourcePool/bsl_wrappers_config.h" - -/** - * @brief 定义这个宏可以跳过POD的初始化(清零) - * - * 定义这个宏可以模仿malloc()和placement operator new的行为,并提高分配POD数组的速度 - * 不定义这个宏可以模仿calloc(), 普通operator new,STL容器的行为。 - */ -//#define BSL_CONFIG_SKIP_POD_INITIALIAZION - -/** - * @brief 定义这个宏可以在构造对象数组时使用默认构造函数而非复制构造函数 - * - * 定义这个宏可以模仿operator new的行为 - * 不定义这个宏可以模仿STL容器的行为 - */ -//#define BSL_CONFIG_DO_NOT_COPY_FOR_DEFAULT_CONSTRUCTION - -namespace bsl{ - /** - * @brief construct(void*)函数的辅助函数,当T类型拥有平凡的构造函数时被调用 - * - * 注:内部使用,用户不应直接调用该函数。 - * - * @param [in] p_object : void* - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/07 10:48:10 - **/ - template - inline void __construct_aux(void * p_object, __BSL_TRUE_TYPE__){ -#ifndef BSL_CONFIG_SKIP_POD_INITIALIAZION - *static_cast(p_object) = 0; -#endif - } - - /** - * @brief construct(void*)函数的辅助函数,当T类型拥有非平凡的构造函数时被调用 - * - * 注:内部使用,用户不应直接调用该函数。 - * - * @param [in/out] p_object : void* - * @return template inline void - * @retval - * @see - * @author chenxm - * @date 2008/08/07 10:48:30 - **/ - template - inline void __construct_aux(void * p_object, __BSL_FALSE_TYPE__){ - ::new(p_object) T(); - } - - /** - * @brief T类型默认构造函数的C风格包裹函数 - * - * - */ - template - inline void construct(void * p_object){ - typedef __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(T) __is_POD; - __construct_aux(p_object, __is_POD() ); - } - /** - * @brief T类型单参数构造函数(特别地,当T_arg = T时,为复制构造函数)的C风格包裹函数 - * - * - */ - template - inline void construct(void * p_object, const void * p_arg ){ - new(p_object) T(*static_cast(p_arg)); - } - - /** - * @brief T类型析构函数的C风格包裹函数 - * - * @param [in] p_object : void* - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:29:56 - **/ - template - inline void destroy(void * p_object){ - static_cast(p_object)->~T(); - } - - /** - * @brief construct_array(void*,void*)函数的辅助函数,当T类型拥有非平凡的构造函数时被调用 - * - * 注:内部使用,用户不应直接调用该函数。 - * @param [in] begin : void* - * @param [in] end : void* - * @return template inline void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:29:47 - **/ - template - inline void __construct_array_aux( void * begin, void * end, __BSL_FALSE_TYPE__){ -#ifndef BSL_CONFIG_DO_NOT_COPY_FOR_DEFAULT_CONSTRUCTION - std::uninitialized_fill( static_cast(begin), static_cast(end), T() ); -#else - ::new(begin) T[static_cast(end) - static_cast(begin)]; -#endif - } - - /** - * @brief construct_array(void*,void*)函数的辅助函数,当T类型拥有平凡的构造函数时被调用 - * - * 注:内部使用,用户不应直接调用该函数。 - * @param [in] begin : void* - * @param [in] end : void* - * @return template inline void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:31:31 - **/ - template - inline void __construct_array_aux( void * begin, void * end, __BSL_TRUE_TYPE__){ -#ifndef BSL_CONFIG_SKIP_POD_INITIALIAZION - memset(begin, 0, static_cast(end) - static_cast(begin) ); -#endif - } - - /** - * @brief 调用T类型默认构造函数构造对象数组的C风格包裹函数 - * - * @param [in] begin : void* 对象数组的首址 - * @param [in] end : void* 对象数组的尾址(=首址+数组大小) - * @return template inline void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:31:36 - **/ - template - inline void construct_array(void * begin, void * end ){ - typedef __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(T) __is_POD; - __construct_array_aux( begin, end, __is_POD() ); - } - - /** - * @brief 调用T类型单参数构造函数(特别地,当T_arg = T时,为复制构造函数)构造对象数组的C风格包裹函数, - * - * @param [in] begin : void* 对象数组的首址 - * @param [in] end : void* 对象数组的尾址(=首址+数组大小) - * @return template inline void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:31:36 - **/ - template - inline void construct_array(void * begin, void * end, const void * src ){ - std::uninitialized_fill( static_cast(begin), static_cast(end), *static_cast(src) ); // this method will be specially optimized to POD; - } - - /** - * @brief destroy_array(void *, void *)的辅助函数,当当前g++版本不支持type-traits,或未在bsl_wrappers_config.h中定义的时候使用 - * - * @param [in] begin : T* T类型对象数组的首址 - * @param [in] end : T* T类型对象数组的尾址(=首址+数组大小) - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:38:18 - **/ - template - inline void default_destroy_array(T* begin, T* end){ - while( begin != end ){ - (begin ++) -> ~T(); - } - } - - /** - * @brief 销毁T类型对象数组的C风格包裹函数 - * - * @param [in] begin : void* T类型对象数组的首址 - * @param [in] end : void* T类型对象数组的尾址(=首址+数组大小) - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:42:11 - **/ - template - inline void destroy_array( void * begin, void * end ){ - __BSL_DESTROY(static_cast(begin), static_cast(end)); // this method will be specially optimized to the type which has trivial destructor; - } - - /** - * @brief 通过Alloc类型空间分配器释放内存的C风格包裹函数 - * 若该段内存不可由Alloc类对象释放或( end - begin ) % sizeof(Alloc::value_type) != 0,则结果未定义 - * @param [in] begin : void* 被释放的内存块的首址 - * @param [in] end : void* 被释放的内存块的尾址 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:43:49 - **/ - template - inline void deallocate( void * begin, void * end ){ - typedef typename Alloc::value_type value_t; - value_t * vt_begin = static_cast(begin); - value_t * vt_end = static_cast(end); - Alloc().deallocate( vt_begin, vt_end - vt_begin ); - } - - /** - * @brief destroy(void*)和deallocate(void*)的组合 - * - * @param [in] p_object : void* - * @return void - * @retval - * @see destroy(void*) - * @see deallocate(void*) - * @author chenxm - * @date 2008/08/12 20:46:56 - **/ - template - inline void destroy_and_deallocate( void * p_object ){ - static_cast(p_object)->~T(); - typedef typename Alloc::template rebind::other T_Alloc; - T_Alloc().deallocate(static_cast(p_object), 1); - } - - /** - * @brief destroy_array(void*, void*)和deallocate(void*)的组合 - * - * @param [in] begin : void* - * @param [in] end : void* - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:48:04 - **/ - template - inline void destroy_and_deallocate_array( void * begin, void * end ){ - __BSL_DESTROY(static_cast(begin), static_cast(end)); // this method will be specially optimized to the type which has trivial destructor; - typedef typename Alloc::template rebind::other T_Alloc; - T_Alloc().deallocate(static_cast(begin), static_cast(end) - static_cast(begin) ); - } - - /** - * @brief ::operator delete的C风格包裹函数 - * - * @param [in] object : void* 对象地址 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:49:02 - **/ - template - inline void bsl_delete(void * object ){ - delete static_cast(object); - } - - /** - * @brief ::operator delete[]的C风格包裹函数 - * - * @param [in] array : void* 对象数组首址 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:50:10 - **/ - template - inline void bsl_delete_array( void * array ){ - delete[] static_cast(array); - } - - /** - * @brief 系统函数free(void*)的C风格包裹函数,提供调试支持 - * - * 在BSL中,建议使用该函数,而非系统函数free(void*) - * - * @param [in] data : void* - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:51:32 - **/ - inline void bsl_free( void *data){ -#ifdef BSL_DEBUG_FLAG - // 输出调试信息 - std::cerr<<"memory "<(data)); - } - -} //namespace bsl -#endif //__BSL_WRAPPERS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/ResourcePool/bsl_wrappers_config.h b/bsl/ResourcePool/bsl_wrappers_config.h deleted file mode 100644 index 2ed6e6348f87d8397afd65653f8e9493684a99f6..0000000000000000000000000000000000000000 --- a/bsl/ResourcePool/bsl_wrappers_config.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_wrappers_config.h,v 1.2 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_wrappers_config.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/11 11:32:53 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#ifndef __BSL_WRAPPERS_CONFIG_H_ -#define __BSL_WRAPPERS_CONFIG_H_ - -#if __GNUC__ == 2 && __GNUC_MINOR__ == 96 - #define __BSL_TRUE_TYPE__ __true_type - #define __BSL_FALSE_TYPE__ __false_type - #define __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(_TYPE_) typename __type_traits<_TYPE_>::has_trivial_default_constructor - #define __BSL_DESTROY std::destroy - -#elif __GNUC__ == 3 && __GNUC_MINOR__ == 4 - #define __BSL_TRUE_TYPE__ __true_type - #define __BSL_FALSE_TYPE__ __false_type - #define __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(_TYPE_) typename __type_traits<_TYPE_>::has_trivial_default_constructor - #define __BSL_DESTROY std::_Destroy - -#elif __GNUC__ >= 4 - //enjoy std::tr1! - #include - #define __BSL_TRUE_TYPE__ std::tr1::true_type - #define __BSL_FALSE_TYPE__ std::tr1::false_type - #define __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(_TYPE_) typename std::tr1::has_trivial_constructor<_TYPE_> - #define __BSL_DESTROY std::_Destroy - -#else //使用最保守的做法 - #ifndef BSL_CONFIG_NO_TYPE_TRAITS_WARNIBSL - #warning type-traits support not implemented for the current g++ version. Default implementation is used. Add related configuration to bsl_wrappers_config.h to add type-traits support. Disable this wanring by defining marco BSL_CONFIG_NO_TYPE_TRAITS_WARNIBSL. - #endif //BSL_CONFIG_NO_TYPE_TRAITS_WARNIBSL - - namespace bsl{ - typedef struct __bsl_true_type__{} __bsl_true_type__; - typedef struct __bsl_false_type__{} __bsl_false_type__; - } - - #define __BSL_TRUE_TYPE__ __bsl_true_type__ - #define __BSL_FALSE_TYPE__ __bsl_false_type__ - #define __BSL_HAS_TRIVIAL_DEFAULT_CONSTRUCTOR(_TYPE_) __BSL_FALSE_TYPE__ - #define __BSL_DESTROY default_destroy_array - -#endif // #if __GNUC__ - -#endif //__BSL_WRAPPERS_CONFIG_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/alloc/BCLOUD b/bsl/alloc/BCLOUD deleted file mode 100644 index 874a9b57598a549a842e4084e013004dae879138..0000000000000000000000000000000000000000 --- a/bsl/alloc/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -#CPPFLAGS(r'-D_GNU_SOURCE -D__STDC_LIMIT_MACROS') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -#CXXFLAGS(' -g -pipe -W -Wall -fPIC') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -#INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/liballoc.a') -#LIBS('$OUT/so/liballoc.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -#user_sources=GLOB("*.c *.cpp *.cc *.idl") - -#release headers -HEADERS('*.h', '$INC/bsl/alloc') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('alloc', Sources(user_sources)) - -#UT -#UTApplication('alloc', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -#StaticLibrary('alloc', Sources(user_sources)) -#StaticLibrary('alloc', PreBuilt(True)) - -#.so -#SharedLibrary('alloc', Sources(user_sources)) -#SharedLibrary('alloc', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/alloc/CMakeLists.txt b/bsl/alloc/CMakeLists.txt deleted file mode 100644 index 2bdd443daf3a9160c1ab94c29c4f12ad0b84ec1b..0000000000000000000000000000000000000000 --- a/bsl/alloc/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) -add_custom_target(alloc) diff --git a/bsl/alloc/Makefile b/bsl/alloc/Makefile deleted file mode 100644 index 8d3a3ba59f210a9d9fd5a5a838a37dd6933dd8e4..0000000000000000000000000000000000000000 --- a/bsl/alloc/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -BSL=../ -OUTINC=$(BSL)/output/include/bsl/alloc -all : - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp *.h $(OUTINC) - -clean : - rm -rf $(OUTINC) diff --git a/bsl/alloc/allocator.h b/bsl/alloc/allocator.h deleted file mode 100644 index 8ecb506c16ee0813906a0f1250c573e51c8f441b..0000000000000000000000000000000000000000 --- a/bsl/alloc/allocator.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: allocator.h,v 1.2 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file allocator.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/22 17:41:08 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __ALLOCATOR_H_ -#define __ALLOCATOR_H_ - - -#include -#include -#include - - - -#endif //__ALLOCATOR_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/alloc/bsl_alloc.h b/bsl/alloc/bsl_alloc.h deleted file mode 100644 index d1536540a04ba5cf82a36fa3fefb11b7eb80a71f..0000000000000000000000000000000000000000 --- a/bsl/alloc/bsl_alloc.h +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************** -created: 2008/06/27 -created: 27:6:2008 14:05 -filename: xalloc.h - -2010/10/15 modified by zhujianwei - -author: xiaowei -mail: xiaowei@baidu.com - -purpose: -*********************************************************************/ - -#ifndef BSL_ALLOC_H__ -#define BSL_ALLOC_H__ - -#include -#include -#include -#include -#include -#include -namespace bsl -{ -/** -* @brief An allocator that uses malloc. -* -* This is precisely the allocator defined in the C++ Standard. -* - all allocation calls malloc -* - all deallocation calls free -*/ - -template < typename _Tp > -class bsl_alloc -{ -public: - typedef size_t size_type; - #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - typedef std::ptrdiff_t difference_type; - #else - typedef ptrdiff_t difference_type; - #endif - typedef _Tp *pointer; - typedef const _Tp *const_pointer; - typedef _Tp & reference; - typedef const _Tp & const_reference; - typedef _Tp value_type; - typedef bsl_alloc<_Tp> pool_type; - - template < typename _Tp1 > - struct rebind { - typedef bsl_alloc < _Tp1 > other; - }; - - static const bool recycle_space;// = false; //在alloc析构的时候,是否释放空间 - static const bool thread_safe;// = true; //空间分配器是否线程安全 - - bsl_alloc() { - create(); - } - - bsl_alloc(const bsl_alloc &) { - create(); - } - - template < typename _Tp1 > - bsl_alloc(const bsl_alloc < _Tp1 > &) { - create(); - } - - ~bsl_alloc() { - destroy(); - } - - pointer address(reference __x) const { - return &__x; - } - - const_pointer address(const_reference __x) const { - return &__x; - } - - //NB:__n is permitted to be 0. The C++ standard says nothing - // about what the return value is when __n == 0. - pointer allocate(size_type __n, const void * = 0) { - pointer __ret = static_cast < _Tp * >(malloc(__n * sizeof(_Tp))); - return __ret; - } - - pointer reallocate(size_type __n, void * ptr = 0) { - if (ptr == NULL) { - return allocate(__n, ptr); - } - return static_cast < _Tp * >(realloc(ptr, __n * sizeof(_Tp))); - } - - //__p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type) { - free(static_cast < void *>(__p)); - } - - size_type max_size() const { - return size_t(-1) / sizeof(_Tp); - } - - //_GLIBCXX_RESOLVE_LIB_DEFECTS - //402. wrong new expression in[some_] allocator: : construct - void construct(pointer __p, const _Tp & __val) { - ::new(__p) value_type(__val); - } - - void destroy(pointer __p) { - __p->~ _Tp(); - } - - int create() { - return 0; - } - - int destroy() { - return 0; - } - - void swap (bsl_alloc<_Tp> &) { - } - - int merge(bsl_alloc<_Tp> &){ - return 0; - } - - value_type * getp(pointer __p) const { return __p; } -}; - -template < typename _Tp > -inline bool operator == (const bsl_alloc < _Tp > &, const bsl_alloc < _Tp > &) { - return true; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator == (const bsl_alloc <_Tp > &, const _Alloc2 &) { - return false; -} - -template < typename _Tp > -inline bool operator != (const bsl_alloc < _Tp > &, const bsl_alloc < _Tp > &) { - return false; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator != (const bsl_alloc <_Tp > &, const _Alloc2 &) { - return true; -} - -template -const bool bsl_alloc<_Tp>::recycle_space = false; -template -const bool bsl_alloc<_Tp>::thread_safe = true; - -} - -#endif // xalloc_h__ diff --git a/bsl/alloc/bsl_cpsalloc.h b/bsl/alloc/bsl_cpsalloc.h deleted file mode 100644 index c4f2aa2e618d152012d82af925b9036836140a9c..0000000000000000000000000000000000000000 --- a/bsl/alloc/bsl_cpsalloc.h +++ /dev/null @@ -1,178 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_cpsalloc.h,v 1.7 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_cpsalloc.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/21 14:36:17 / 2010/10/19 modified by zhujianwei - * @version $Revision: 1.7 $ - * @brief - * - **/ - - -#ifndef __BSL_CPSALLOC_H_ -#define __BSL_CPSALLOC_H_ - -#include - -namespace bsl -{ -/** -* @brief An allocator that uses malloc. -* -* This is precisely the allocator defined in the C++ Standard. -* - all allocation calls malloc -* - all deallocation calls free -*/ - -template < class _Alloc > -class bsl_cpsalloc -{ - static const unsigned long DATAQSIZE = 1024UL * 16UL; -public: - typedef _Alloc _Base; - typedef typename _Base::pool_type pool_type; - typedef typename _Base::size_type size_type; - typedef typename _Base::difference_type difference_type; - typedef unsigned int pointer; - typedef const unsigned int const_pointer; - typedef typename _Base::reference reference; - typedef typename _Base::const_reference const_reference; - typedef typename _Base::value_type value_type; - typedef bsl_cpsalloc<_Alloc> _Self; - - template - struct rebind { - private: - typedef typename _Base::template rebind<_Tp1>::other other_alloc; - public: - typedef bsl_cpsalloc other; - }; - - static const bool recycle_space;// = true; //在alloc析构的时候,是否释放空间 - static const bool thread_safe;// = false; //空间分配器是否线程安全 - - union data_t - { - data_t *next; - char data[sizeof(value_type)]; - }; - - bsl::deque _free; - bsl::deque _deque; - - bsl_cpsalloc() { - create(); - } - - bsl_cpsalloc(const bsl_cpsalloc &) { - create(); - } - - template < typename _Tp1 > - bsl_cpsalloc(const bsl_cpsalloc < _Tp1 > &) { - create(); - } - - ~bsl_cpsalloc() { - destroy(); - } - -#if 0 - pointer address(reference __x) const { - return &__x; - } - - const_pointer address(const_reference __x) const { - return &__x; - } -#endif - - //NB:__n is permitted to be 0. The C++ standard says nothing - // about what the return value is when __n == 0. - pointer allocate(size_type __n, const void * = 0) { - if (__n > 1) return 0; - if (_free.size() > 0) { - pointer p = _free.front(); - _free.pop_front(); - return p; - } - _deque.push_back(data_t()); - return _deque.size(); - } - - //__p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type) { - _free.push_back(__p); - } - - size_type max_size() const { - return size_t(-1) / sizeof(value_type); - } - - //_GLIBCXX_RESOLVE_LIB_DEFECTS - //402. wrong new expression in[some_] allocator: : construct - void construct(pointer __p, const value_type & __val) { - ::new(getp(__p)) value_type(__val); - } - - void destroy(pointer __p) { - getp(__p)->~ value_type(); - } - - int create() { - return 0; - } - - int destroy() { - _free.destroy(); - _deque.destroy(); - return 0; - } - - void swap (_Self &__self) { - _free.swap(__self._free); - _deque.swap(__self._deque); - } - - value_type * getp(pointer __p) const { - return (value_type *)(_deque[__p-1].data); - } -}; - -template < typename _Tp > -inline bool operator == (const bsl_cpsalloc < _Tp > &, const bsl_cpsalloc < _Tp > &) { - return false; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator == (const bsl_cpsalloc <_Tp > &, const _Alloc2 &) { - return false; -} - -template < typename _Tp > -inline bool operator != (const bsl_cpsalloc < _Tp > &, const bsl_cpsalloc < _Tp > &) { - return true; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator != (const bsl_cpsalloc <_Tp > &, const _Alloc2 &) { - return true; -} - -template -const bool bsl_cpsalloc<_Alloc>::recycle_space = true; -template -const bool bsl_cpsalloc<_Alloc>::thread_safe = false; -} - -#endif //__BSL_CPSALLOC_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/alloc/bsl_sample_alloc.h b/bsl/alloc/bsl_sample_alloc.h deleted file mode 100644 index 4f4707a55c86ee7aebe793c3f4bc59333db8e425..0000000000000000000000000000000000000000 --- a/bsl/alloc/bsl_sample_alloc.h +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_sample_alloc.h,v 1.5 2009/04/07 06:35:53 xiaowei Exp $ - * - **************************************************************************/ - -/** - * @file bsl_sample_alloc.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/12 14:24:41 / 2010/10/18 modified by zhujianwei - * @version $Revision: 1.5 $ - * @brief - * - **/ - -/* - * - * 用来优化分定长块 - * - */ - - -#ifndef __BSL_SAMPLE_ALLOC_H_ -#define __BSL_SAMPLE_ALLOC_H_ - -#include - -namespace bsl -{ -/* - * 这个是容器内部,如果需要优化大块内存分配 - * 可以调用这个模版重新获取内存 - * 属于容器内部数据 - * 链表和hash可能用得到 - * - */ - -/** - * 只能管理内存 - */ - -template -class bsl_sample_alloc -{ -public: - typedef _Alloc _Base; - typedef typename _Base::pool_type pool_type; - typedef typename _Base::size_type size_type; - typedef typename _Base::difference_type difference_type; - typedef typename _Base::pointer pointer; - typedef typename _Base::const_pointer const_pointer; - typedef typename _Base::reference reference; - typedef typename _Base::const_reference const_reference; - typedef typename _Base::value_type value_type; - typedef bsl_sample_alloc<_Alloc, _Items> self; - - union node_type - { - char value[sizeof(value_type)]; - node_type *next; - }; - - struct large_type - { - large_type *next; - node_type data[_Items]; - }; - - typedef typename _Base::template rebind::other large_alloc; - template - struct rebind { - private: - typedef typename _Base::template rebind<_Tp1>::other other_alloc; - public: - typedef bsl_sample_alloc other; - }; - - static const bool recycle_space;// = true; - static const bool thread_safe;// = false; - -public: - - bsl_sample_alloc() { - create(); - } - - bsl_sample_alloc(const bsl_sample_alloc<_Alloc, _Items> & ) { - create(); - } - - ~bsl_sample_alloc() { - destroy(); - } - - inline pointer allocate(size_type, void * = 0) { - //if (__n < 2) { - if (_freelst) { - node_type *tmp = _freelst; - _freelst = _freelst->next; - return (pointer)tmp->value; - } - if (_blknum == 0 || _lg == 0) { - large_type *lg = _alloc.allocate(1); - if (lg == 0) return 0; - _blknum = _Items; - lg->next = _lg; - _lg = lg; - } - return (pointer)_lg->data[--_blknum].value; - //} - //return _pool.allocate(__n, ptr); - return 0; - } - - inline void deallocate(pointer ptr, size_type ) { - //if (__n < 2) { - ((node_type *)ptr)->next = _freelst; - _freelst = (node_type *)ptr; - //} else { - // _pool.deallocate(ptr, __n); - //} - } - -private: - large_alloc _alloc; - //pool_type _pool; - large_type * _lg; - node_type *_freelst; - size_type _blknum; - -public: - void swap(self & __other) { - _alloc.swap(__other._alloc); - std::swap(_lg, __other._lg); - std::swap(_freelst, __other._freelst); - std::swap(_blknum, __other._blknum); - } - - void merge( self & __other){ - node_type *tmp = (node_type*)&_freelst; - while(tmp->next) - tmp = tmp->next; - if(__other._lg) - { - for(size_type i = 0; i < __other._blknum; i++) - { - tmp->next = &(__other._lg->data[i]); - tmp = tmp->next; - } - large_type *lg = (large_type*)&_lg; - while(lg->next) - lg = lg->next; - lg->next = __other._lg; - } - tmp->next = __other._freelst; - __other._lg = 0; - __other._blknum = 0; - __other._freelst = 0; - } - - int create() { - _lg = 0; - _freelst = 0; - _blknum = 0; - _alloc.create(); - //_pool.create(); - return 0; - } - - int destroy() { - large_type *ptr = _lg; - while (_lg) { - _lg = _lg->next; - free (ptr); - ptr = _lg; - } - _alloc.destroy(); - //_pool.destroy(); - return 0; - } - - value_type * getp(pointer __p) const { return __p; } -}; - -template -inline bool operator == (const bsl_sample_alloc < _Alloc, _Items > &, - const bsl_sample_alloc < _Alloc, _Items > &) { - return false; -} -template -inline bool operator == (const bsl_sample_alloc <_Alloc, _Items> &, const _Alloc2 &) { - return false; -} - -template < typename _Alloc, size_t _Items > -inline bool operator != (const bsl_sample_alloc < _Alloc, _Items > &, - const bsl_sample_alloc < _Alloc, _Items > &) { - return true; -} - -template -inline bool operator != (const bsl_sample_alloc <_Alloc, _Items> &, const _Alloc2 &) { - return true; -} - -template -const bool bsl_sample_alloc<_Alloc, _Items>::recycle_space = true; -template -const bool bsl_sample_alloc<_Alloc, _Items>::thread_safe = false; - -} - -#endif //__BSL_SAMPLE_ALLOC_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/archive/BCLOUD b/bsl/archive/BCLOUD deleted file mode 100644 index b1edae7c020c17660796624ae0d5441a178f5271..0000000000000000000000000000000000000000 --- a/bsl/archive/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -#CPPFLAGS(r'-D_GNU_SOURCE -D__STDC_LIMIT_MACROS') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -fsigned-char -Wall -W -pipe -Wno-unused-parameter -g -fPIC') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libutils.a') -#LIBS('$OUT/so/libutils.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl/archive') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('utils', Sources(user_sources)) - -#UT -#UTApplication('utils', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_archive', Sources(user_sources)) -#StaticLibrary('utils', PreBuilt(True)) - -#.so -#SharedLibrary('utils', Sources(user_sources)) -#SharedLibrary('utils', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/archive/CMakeLists.txt b/bsl/archive/CMakeLists.txt deleted file mode 100644 index 5b95ed9a30869bc1dc1479794929e6363e19244c..0000000000000000000000000000000000000000 --- a/bsl/archive/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -FILE(GLOB archive_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(archive ${archive_srcs}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/archive/Makefile b/bsl/archive/Makefile deleted file mode 100644 index 813443b1734b56b505cf98715e338256a710447a..0000000000000000000000000000000000000000 --- a/bsl/archive/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -CC=/usr/bin/g++ - -ifeq ($(MAC),64) - LIBPATH=$(WORKROOT)lib2-64 -else - LIBPATH=$(WORKROOT)lib2 -endif - -BSL=../ -OUTINC=$(BSL)/output/include/bsl/archive -OUTLIB=$(BSL)/output/lib - - - -INCLUDES=-I$(BSL)/../ -CFLAGS = -fsigned-char -Wall -W -pipe -Wno-unused-parameter -g -fPIC -LDFLAGS= -lpthread -lm -OBJS=bsl_filestream.o -TARGET= -LIB=libbsl_archive.a -all : $(TARGET) $(LIB) output - -%.o : %.cpp - $(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES) - -$(LIB) : $(OBJS) - rm -f $@ - ar cr $@ $(OBJS) - -output : $(LIB) - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - mkdir -p $(OUTLIB) - cp *.h $(OUTINC) - cp $(LIB) $(OUTLIB) - - -tags : - ctags -R * - -clean: - rm -f $(OBJS) $(TARGET) $(LIB) test.o - rm -f -r $(OUTINC); - rm -f $(OUTLIB)/$(LIB) - - diff --git a/bsl/archive/bsl_binarchive.h b/bsl/archive/bsl_binarchive.h deleted file mode 100644 index e4ef44dc7892ae6ae00cab1c43b7bb4ef1149b83..0000000000000000000000000000000000000000 --- a/bsl/archive/bsl_binarchive.h +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_binarchive.h,v 1.5 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_binarchive.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/25 17:00:04 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - -#ifndef __BSL_BINARCHIVE_H_ -#define __BSL_BINARCHIVE_H_ - -#include -#include -#include -#include - -namespace bsl -{ -class binarchive -{ -protected: - bsl::stream &_fd; -public: - binarchive(bsl::stream & fd) : _fd(fd) {} - ~binarchive() {} - - /** - * @brief 从bsl stream 流中读取一个实体数据 - * - * @param [out] tp : _Tp* 非NULL指针 - * @return int 成功返回0,其他失败 - * @retval tp传NULL 会core - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:17:39 - **/ - template - int read(_Tp *tp) { - _fd.start_trans(); - int ret = bsl::deserialization(*this, *tp); - if (ret == 0) { - _fd.comit_trans(); - } else { - _fd.drop_trans(false); - } - return ret; - } - - /** - * @brief 往stream里面塞数据 - * - * @param [in] tp : const _Tp& 需要写入的实体数据 - * @return int 成功返回0,其他失败 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:19:50 - **/ - template - int write(const _Tp & tp) { - _fd.start_trans(); - int ret = bsl::serialization(*this, tp); - if (ret == 0) { - ret = _fd.comit_trans(); - if (ret != 0) { - _fd.drop_trans(true); - } - } else { - _fd.drop_trans(true); - } - return ret; - } - -public: - /** - * @brief 往stream里面写入size大的数据 - * - * @param [in/out] dat : const void* - * @param [in/out] size : size_t - * @return 0 表示成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:21:07 - **/ - int push(const void *dat, size_t size) { - //参数检查让底层去做 - return _fd.write(dat, size); - } - - /** - * @brief 往stream里面读数据 - * - * @param [in/out] dat : void* - * @param [in/out] size : size_t - * @return int 0表示成功,其他失败 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:23:02 - **/ - int pop(void *dat, size_t size) { - return _fd.read(dat, size); - } -}; - -} -#endif //__BSL_BINARCHIVE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/archive/bsl_filestream.cpp b/bsl/archive/bsl_filestream.cpp deleted file mode 100644 index b5eb49ac54c9d997dbc5ac2d3a81e6fcf7018626..0000000000000000000000000000000000000000 --- a/bsl/archive/bsl_filestream.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_filestream.cpp,v 1.5 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_filestream.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/07/25 17:17:56 - * @version $Revision: 1.5 $ - * @brief - * - **/ - -#include -#include -#include - -#include - -namespace bsl -{ -filestream::filestream() : _fp(NULL), _trans(0) -{ - _wbuffersize = 0; - _wbuffer = 0; - _rbuffer = 0; - _rbuffersize = 0; -} -filestream::~filestream() -{ - close(); -} -int filestream::open(const char *fname, const char *mode) -{ - if (fname == NULL || mode == NULL) { - __BSL_ERROR("invalid parama\n"); - return -1; - } - //参数检查 - _trans = 0; - _fp = ::fopen(fname, mode); - if (_fp == NULL) { - __BSL_ERROR("open %s file fail err[%m]", fname); - return -1; - } - _trans = ::fseek(_fp, 0, SEEK_CUR); - return 0; -} - -int filestream::close() -{ - if (_fp != NULL) { - ::fclose(_fp); - } - _fp = NULL; - if (_rbuffer) { - free (_rbuffer); - } - if (_wbuffer) { - free (_wbuffer); - } - _rbuffer = _wbuffer = 0; - _rbuffersize = _wbuffersize = 0; - return 0; -} - -int filestream::setwbuffer(size_t size) -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - if (_wbuffer) { - free (_wbuffer); - } - _wbuffersize = 0; - _wbuffer = 0; - if (size == 0) { - setvbuf(_fp, NULL, _IONBF, BUFSIZ); - return 0; - } - - _wbuffer = (char *)malloc(size); - if (_wbuffer) { - _wbuffersize = size; - setbuffer(_fp, _wbuffer, size); - return 0; - } - return -1; -} - -int filestream::setrbuffer(size_t size) -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - if (_rbuffer) { - free (_rbuffer); - } - _rbuffer = 0; - _rbuffersize = 0; - if (size == 0) return 0; - - _rbuffer = (char *)malloc(size); - if (_rbuffer) { - _rbuffersize = size; - return 0; - } - return -1; -} -int filestream::write(const void *dat, size_t size) -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - if (size == 0) { - return 0; - } - if (dat == NULL) { - __BSL_ERROR("input NULL pointer"); - return -1; - } - size_t ret = ::fwrite(dat, 1, size, _fp); - if (ret == (size_t)size) { - _trans_off += size; - return 0; - } - __BSL_ERROR("write data to filesystem wan[%ld] rel[%ld] error[%m]", (long)size, (long)ret); - if (ret > 0) { - ::fseek(_fp, -(long)ret, SEEK_CUR); - return -1; - } - return -1; -} - -int filestream::read(void *dat, size_t size) -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - if (size == 0) { - return 0; - } - if (dat == NULL) { - __BSL_ERROR("read %zu data to NULL pointer", size); - return -1; - } - size_t ret = ::fread(dat, 1, size, _fp); - if (ret == (size_t)size) { - _trans_off += size; - return 0; - } - __BSL_ERROR("read data from filesystem wan[%ld] rel[%ld] error[%m]", (long)size, (long)ret); - if (ret > 0) { - ::fseek(_fp, -(long)ret, SEEK_CUR); - return -1; - } - return -1; -} -int filestream::start_trans() -{ - _trans_off = 0; - //_trans = ::fseek(_fp, 0, SEEK_CUR); - return 0; -} -int filestream::comit_trans() -{ - _trans += _trans_off; - //_trans = ::fseek(_fp, 0, SEEK_CUR); - return 0; -} - -int filestream::drop_trans(bool trunc) -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - int ret = ::fseek(_fp, _trans, SEEK_SET); - if (ret == int(-1)) return -1; - if (trunc && ::ftruncate(::fileno(_fp), _trans) != 0) { - return -1; - } - return 0; -} - -int filestream::flush() -{ - if (_fp == NULL) { - __BSL_ERROR("invalid file pointer"); - return -1; - } - return ::fflush(_fp); -} - -}; - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/archive/bsl_filestream.h b/bsl/archive/bsl_filestream.h deleted file mode 100644 index 3dda13df6dfd0e2823856a583dde6afcc03803ff..0000000000000000000000000000000000000000 --- a/bsl/archive/bsl_filestream.h +++ /dev/null @@ -1,176 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_filestream.h,v 1.4 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_filestream.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/25 17:05:19 - * @version $Revision: 1.4 $ - * @brief - * - **/ - - -#ifndef __BSL_FILESTREAM_H_ -#define __BSL_FILESTREAM_H_ - -#include -#include -#include -#include -#include -#include - -namespace bsl -{ -class filestream : public stream -{ - FILE *_fp; - int _trans; - int _trans_off; - char *_wbuffer; - size_t _wbuffersize; - char *_rbuffer; - size_t _rbuffersize; -public: - filestream(); - ~filestream(); - /** - * @brief 文件打开模式 - * - * @param [in/out] fname : const char* 文件名 - * @param [in/out] mode : const char* 文件打开模式, - * "w" 写打开 - * "r" 读打开 - * 不要尝试读写打开,参数跟FILE一样 - * @return int 0表示成功,其他失败 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:24:02 - **/ - int open(const char *fname, const char *mode); - /** - * @brief 关闭文件 - * - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:26:05 - **/ - int close(); - /** - * @brief 往文件里面写数据,如果写入失败,什么都不发生 - * 要吗写入,要吗回滚到上一个状态 - * - * @param [in/out] dat : const void* 要写的数据指针 - * @param [in/out] size : size_t 写的数据长度 - * @return int 0 表示成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:26:17 - **/ - int write(const void *dat, size_t size); - /** - * @brief 往文件里面读数据,如果读入失败,什么都不发生 - * 要吗读入,要吗回滚到上一个状态 - * - * @param [in/out] dat : void* - * @param [in/out] size : size_t - * @return int 0表示成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:28:41 - **/ - int read(void *dat, size_t size); - /** - * @brief 开启一个事务 - * - * @return int 0 开启成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:29:49 - **/ - int start_trans(); - /** - * @brief 结束一个事务 - * - * @return int 0表示成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:30:08 - **/ - int comit_trans(); - /** - * @brief 放弃一个事务 - * - * @param [in] trunc : bool - * false : 不将该事务对磁盘的操作丢弃 - * true : 将该事务对磁盘的操作丢弃 - * @return int 0表示成功 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:30:31 - **/ - int drop_trans(bool trunc); - /** - * @brief 设置写缓冲区 - * - * @param [in/out] size : size_t 缓冲区大小为byte - * @return int 成功返回0 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:32:12 - **/ - int setwbuffer(size_t size); - /** - * @brief 设置读缓冲区 - * - * @param [in/out] size : size_t 缓冲区大小位byte - * @return int 成功返回0 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:33:01 - **/ - int setrbuffer(size_t size); - /** - * @brief 强制将数据刷到硬盘 - * - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/11/04 10:34:30 - **/ - int flush(); -}; -}; - - -#endif //__BSL_FILESTREAM_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/archive/bsl_serialization.h b/bsl/archive/bsl_serialization.h deleted file mode 100644 index e0bc7294342b3682492f8abd8621348b6f1e1b7d..0000000000000000000000000000000000000000 --- a/bsl/archive/bsl_serialization.h +++ /dev/null @@ -1,156 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_serialization.h,v 1.2 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_serialization.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/22 22:55:24 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_SERIALIZATION_H_ -#define __BSL_SERIALIZATION_H_ - -#include -#include -#include -#include - -namespace bsl -{ - -template -int serialization(_Archive & ar, const _Tp & tp) -{ - return ((_Tp &)tp).serialization(ar); -} - -template -int deserialization(_Archive & ar, _Tp &tp) -{ - return tp.deserialization(ar); -} - -#define __BSL_SERIAL_DEF(type) \ -template \ -int serialization(_Archive & ar, type &tp) \ -{ \ - return ar.push(&tp, sizeof(tp)); \ -} \ - -#define __BSL_DESERIAL_DEF(type) \ -template \ -int deserialization(_Archive &ar, type &tp) \ -{ \ - return ar.pop(&tp, sizeof(tp)); \ -} - -__BSL_SERIAL_DEF(char); -__BSL_SERIAL_DEF(const char); -__BSL_SERIAL_DEF(unsigned char); -__BSL_SERIAL_DEF(const unsigned char); -__BSL_SERIAL_DEF(short); -__BSL_SERIAL_DEF(const short); -__BSL_SERIAL_DEF(unsigned short); -__BSL_SERIAL_DEF(const unsigned short); -__BSL_SERIAL_DEF(int); -__BSL_SERIAL_DEF(const int); -__BSL_SERIAL_DEF(unsigned int); -__BSL_SERIAL_DEF(const unsigned int); -__BSL_SERIAL_DEF(long); -__BSL_SERIAL_DEF(const long); -__BSL_SERIAL_DEF(unsigned long); -__BSL_SERIAL_DEF(const unsigned long); -__BSL_SERIAL_DEF(float); -__BSL_SERIAL_DEF(const float); -__BSL_SERIAL_DEF(double); -__BSL_SERIAL_DEF(const double); -__BSL_SERIAL_DEF(long long); -__BSL_SERIAL_DEF(const long long); -__BSL_SERIAL_DEF(unsigned long long); -__BSL_SERIAL_DEF(const unsigned long long); - -__BSL_DESERIAL_DEF(char); -__BSL_DESERIAL_DEF(unsigned char); -__BSL_DESERIAL_DEF(short); -__BSL_DESERIAL_DEF(unsigned short); -__BSL_DESERIAL_DEF(int); -__BSL_DESERIAL_DEF(unsigned int); -__BSL_DESERIAL_DEF(long); -__BSL_DESERIAL_DEF(unsigned long); -__BSL_DESERIAL_DEF(float); -__BSL_DESERIAL_DEF(double); -__BSL_DESERIAL_DEF(long long); -__BSL_DESERIAL_DEF(unsigned long long); - -//增加std:string的序列化函数 -template -int serialization(_Archive &ar, const std::string & str) -{ - size_t siz = str.size(); - if (ar.push(&siz, sizeof(siz)) != 0) { - __BSL_ERROR("push siz[%ld] err", (long)siz); - return -1; - } - //__BSL_DEBUG("push siz=%ld", (long)siz); - if (ar.push(str.c_str(), str.size()) != 0) { - __BSL_ERROR("push str[%s] err", str.c_str()); - return -1; - } - return 0; -} - -template -int deserialization(_Archive &ar, std::string & str) -{ - size_t siz = 0; - if (ar.pop(&siz, sizeof(siz)) != 0) { - __BSL_ERROR("pop siz err"); - return -1; - } - //__BSL_DEBUG("pop siz=%ld", (long)siz); - char *ptr = (char *)malloc(siz); - if (ptr == NULL) { - return -1; - } - if (ar.pop(ptr, siz) != 0) { - __BSL_ERROR("pop str err"); - free (ptr); - return -1; - } - //__BSL_DEBUG("pop str=%s", ptr); - str.assign(ptr, siz); - free (ptr); - return 0; -} - -template -int serialization(_Archive &ar, const std::pair<_T1, _T2> &__p) -{ - if (bsl::serialization(ar, __p.first) != 0) return -1; - if (bsl::serialization(ar, __p.second) != 0) return -1; - return 0; -} - -template -int deserialization(_Archive &ar, std::pair<_T1, _T2> &__p) -{ - if (bsl::deserialization(ar, __p.first) != 0) return -1; - if (bsl::deserialization(ar, __p.second) != 0) return -1; - return 0; -} - -}; - -#endif //__BSL_SERIALIZATION_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/archive/bsl_stream.h b/bsl/archive/bsl_stream.h deleted file mode 100644 index 8b373b538f1f7aae2e6c1e57a15bb68ca9b3db1e..0000000000000000000000000000000000000000 --- a/bsl/archive/bsl_stream.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_stream.h,v 1.2 2008/09/25 08:06:51 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_stream.h - * @author xiaowei(com@baidu.com) - * @date 2008/09/01 14:25:20 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_STREAM_H_ -#define __BSL_STREAM_H_ - - -namespace bsl -{ -class stream -{ -public: - virtual ~stream() {}; - virtual int close() = 0; - virtual int write(const void *dat, size_t size) = 0; - virtual int read(void *dat, size_t size) = 0; - virtual int start_trans() = 0; - virtual int comit_trans() = 0; - virtual int drop_trans(bool) = 0; - virtual int flush() = 0; -}; -}; - - - - - - - - - - - - - - - -#endif //__BSL_STREAM_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/btree.h b/bsl/btree.h deleted file mode 100644 index ba214b2ae5394a496a98a62fe82e095e50059fd4..0000000000000000000000000000000000000000 --- a/bsl/btree.h +++ /dev/null @@ -1,9 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ - -#ifndef _BSL_BTREE_H_ -#define _BSL_BTREE_H_ - -#include "containers/btree/bsl_kv_btree.h" - -#endif diff --git a/bsl/buffer/AutoBuffer.cpp b/bsl/buffer/AutoBuffer.cpp deleted file mode 100644 index 58cbdf3419c79f23a4492713a5ba7e545ba1824f..0000000000000000000000000000000000000000 --- a/bsl/buffer/AutoBuffer.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_auto_buffer.cpp,v 1.6 2009/06/15 06:29:04 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_auto_buffer.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/12/12 15:31:45 - * @version $Revision: 1.6 $ - * @brief - * - **/ -#include "bsl/utils/bsl_memcpy.h" -#include "AutoBuffer.h" - -namespace bsl{ - const char * const AutoBuffer::TRUE_LITERAL = "true"; - const char * const AutoBuffer::FALSE_LITERAL= "false"; - const size_t AutoBuffer::TRUE_LITERAL_LEN = strlen(AutoBuffer::TRUE_LITERAL); - const size_t AutoBuffer::FALSE_LITERAL_LEN= strlen(AutoBuffer::FALSE_LITERAL); - - AutoBuffer& AutoBuffer::push(const char* cstr, size_t sub_str_len ){ - if ( cstr != NULL && sub_str_len != 0 ){ - if ( _str && (_size + sub_str_len <= _capacity) ){ - xmemcpy( _str + _size, cstr, sub_str_len ); - _size += sub_str_len; - _str[_size] = 0; - _truncated = false; - - }else{ //not enough space; - if ( reserve( _size + sub_str_len) ){ - //reserve succeed, copy succeed - xmemcpy( _str + _size, cstr, sub_str_len ); - _size += sub_str_len; - _str[_size] = 0; - _truncated = false; - - }else if ( _size < _capacity ){ - //reserve failed - //still has memory - //content is truncated - xmemcpy( _str + _size, cstr, _capacity - _size ); - _size = _capacity; - _str[_size] = 0; - _truncated = true; - }else{ - //is full or _str == NULL - _truncated = true; - } - } - } - return *this; - } - - AutoBuffer& AutoBuffer::vpushf( const char *format, va_list ap ){ - va_list aq; - int len = 0; - if ( !format ){ - return *this; - } - if ( _str ){ - va_copy( aq, ap ); - len = vsnprintf( _str + _size, _capacity - _size + 1, format, aq ); - va_end( aq ); - if ( len >= 0 && _size + len <= _capacity ){ - _size += len; - _truncated = false; - return *this; - } - }else{ - va_copy( aq, ap ); - len = vsnprintf( NULL, 0, format, aq ); - va_end( aq ); - } - - if ( len > 0 ){ - if ( reserve( _size + len) ){ - //reserve succeed, vsnprintf succeed - va_copy( aq, ap ); - vsnprintf( _str + _size, _capacity - _size + 1, format, aq ); - va_end( aq ); - - _size += len; - _truncated = false; - - }else{ - //reserve failed - //content is truncated - _size = _capacity; - _truncated = true; - } - - } - return *this; - } - - //write this way because of a bug of g++ 2.96 - //varargs function cannot be inline - AutoBuffer& AutoBuffer::pushf( const char *format, ... ){ - va_list ap; - va_start( ap, format ); - vpushf( format, ap ); - va_end( ap ); - return *this; - } -} //namespace bsl -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/buffer/AutoBuffer.h b/bsl/buffer/AutoBuffer.h deleted file mode 100644 index b208eb343b7f3ae92bde3fe5153fd381b614a1cf..0000000000000000000000000000000000000000 --- a/bsl/buffer/AutoBuffer.h +++ /dev/null @@ -1,1050 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_auto_buffer.h,v 1.9 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file AutoBuffer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/02 12:15:49 - * @version $Revision: 1.9 $ - * @brief - * - **/ -#ifndef __BSL_AUTO_BUFFER_H_ -#define __BSL_AUTO_BUFFER_H_ -#include -#include -#include -#include -#include -#include "bsl/utils/bsl_memcpy.h" -#include "bsl/pool/bsl_pool.h" - - -namespace bsl{ - /** - * @brief 类似于auto_ptr但更加安全的字符串缓冲区类 - * - * 该类的一大特点是不会抛出异常。在内存不足的时候,该类会截断字符串并置"被截断位"。 - * AutoBuffer对象自行管理一片用于表示字符串的缓冲区,并提供方法追加各种类型对象。 - * 若内存不足时,内存容量将番倍,若申请新内存失败,将填满旧内存,而且使truncated()方法返回true。 - */ - class AutoBuffer{ - public: - /** - * @brief 构造函数 - * - * 可传入__capacity参数指定预分配的内存空间。如__capacity==0没有动态内存分配。 - * 初始化内存池,默认不使用内存池,即直接malloc和free - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] __capacity : size_t - * @see - * @author chenxm - * @date 2009/02/04 17:39:57 - **/ - explicit AutoBuffer( size_t __capacity = DEFAULT_CAPACITY ) - :_size(0), _capacity(__capacity), _truncated(false), _str(NULL), - _mempool(NULL) { - if ( __capacity != 0 ){ - _str = static_cast(_mempool == NULL ? - malloc(_capacity + 1) : _mempool->malloc(_capacity + 1)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - } - - /** - * @brief 使用allocator的构造函数 - * - * 可传入__capacity参数指定预分配的内存空间。如__capacity==0没有动态内存分配。 - * 可传入pool参数指定使用的内存池 - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] pool : mempool& - * @param [in] __capacity : size_t - * @see - * @author liaoshangbin - * @date 2010/7/29 12:06:16 - **/ - explicit AutoBuffer( mempool& pool, size_t __capacity = DEFAULT_CAPACITY ) - :_size(0), _capacity(__capacity), _truncated(false), _str(NULL), _mempool(&pool) { - if ( __capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity + 1) : _mempool->malloc(_capacity + 1)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - } - - /** - * @brief 把另一AutoBuffer的内存转移到本AutoBuffer(另一AutoBuffer会被清空),O(1)复杂度 - * 因为不同AutoBuffer使用的内存池会有不同 - * 先释放自身_str的内存,然后_str指向other._str浅复制字符串, - * 自身的_mempool指向other._mempool,这样_mempool还是处理_str这块内存 - * 后清空other._str,other成为空的AutoBuffer还可以继续使用 - * - * @param [in] other : AutoBuffer& - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 17:45:30 - **/ - AutoBuffer& transfer_from ( AutoBuffer& other ){ - if ( &other != this ){ - if ( _str ){ - _mempool == NULL ? free( _str) : _mempool->free( _str, _capacity+1 ); - } - _size = other._size; - _capacity = other._capacity; - _truncated = other._truncated; - _str = other._str; - _mempool = other._mempool; - other._size = 0; - other._capacity = 0; - other._truncated= false; - other._str = NULL; - } - return *this; - } - - /** - * @brief 交换两AutoBuffer内容,O(1)复杂度 - * - * @param [in] other : AutoBuffer& - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:15 - **/ - void swap( AutoBuffer& other ){ - std::swap( _str, other._str ); - std::swap( _size, other._size ); - std::swap( _capacity, other._capacity ); - std::swap( _truncated, other._truncated ); - std::swap( _mempool, other._mempool ); - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 18:14:47 - **/ - ~AutoBuffer( ){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity + 1 ); - } - } - - /** - * @brief AutoBuffer长度。不包括最后的'\0' - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:56 - **/ - size_t size() const{ - return _size; - } - - /** - * @brief AutoBuffer当前容量。保证容量>=长度。当容量不足时,容量会自动增长。 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:15:23 - **/ - size_t capacity() const { - return _capacity; - } - - /** - * @brief 返回AutoBuffer是否为空 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:26 - **/ - bool empty() const { - return _size == 0; - } - - /** - * @brief 返回AutoBuffer是否为满 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:39 - **/ - bool full() const { - return _size == _capacity; - } - - /** - * @brief 返回AutoBuffer是否发生了截断 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:58 - **/ - bool truncated() const { - return _truncated; - } - - /** - * @brief 返回AutoBuffer内容的C风格字符串表示。O(1)复杂度 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:17:26 - **/ - const char * c_str() const { - if ( _str ){ - return _str; - }else{ - return ""; - } - } - - /** - * @brief 清空内容 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:12 - **/ - void clear() { - if ( _str && _capacity ){ - _str[0] = '\0'; - } - _size = 0; - } - - /** - * @brief 手动扩大内存容量 - * - * @param [in] __capacity : size_t - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:34 - **/ - bool reserve( size_t __capacity ) { - if ( __capacity > _capacity ){ - if ( __capacity < _capacity * 2 ){ - __capacity = _capacity * 2; - } - - char * _new = static_cast(_mempool == NULL ? - malloc(__capacity + 1) : _mempool->malloc(__capacity + 1)); - if ( !_new ){ - return false; - } - - if ( _str ){ - xmemcpy( _new, _str, _size + 1 ); - _mempool == NULL ? free( _str) : _mempool->free( _str, _capacity + 1); - } - - _str = _new; - _capacity = __capacity; - } - return true; - } - - /** - * @brief 追加另一个AutoBuffer - * - * @param [in] other : const AutoBuffer& - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:49:30 - **/ - AutoBuffer& operator << (const AutoBuffer& other){ - return push( other._str, other._size ); - } - - /** - * @brief 追加一个std::string,不包含c_str()中结尾的'\0' - * - * @param [in] str : const std::string & - * @return AutoBuffer& operator - * @retval - * @see - * @author chenyanling - * @date 2011/09/20 13:18:30 - **/ - AutoBuffer& operator << (const std::string& str){ - return push( str.c_str(),str.length() ); - } - - - /** - * @brief 追加布尔值 - * - * @param [in] b : bool - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:27:49 - **/ - AutoBuffer& operator << (bool b){ - if ( b ){ - return push( TRUE_LITERAL, TRUE_LITERAL_LEN ); - }else{ - return push( FALSE_LITERAL, FALSE_LITERAL_LEN ); - } - } - - /** - * @brief 追加字符,忽略'\0' - * - * @param [in] c : char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:03 - **/ - AutoBuffer& operator << (char c){ - if ( c == '\0' ){ - return *this; - } - if ( _size == _capacity ){ //full - reserve( _size + 1 ); //may fail, make best effort. - } - if ( _size < _capacity ){ - _str[_size] = c; - _str[++_size] = '\0'; - _truncated = false; - }else{ - _truncated = true; - } - return *this; - } - - /** - * @brief 追加有符号8位整数 - * - * @param [in] uc : signed char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:47:27 - **/ - AutoBuffer& operator << (signed char sc){ - return pushf( "%hhd", sc ); - } - - /** - * @brief 追加无符号8位整数 - * - * @param [in] uc : unsigned char - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:22 - **/ - AutoBuffer& operator << (unsigned char uc){ - return pushf( "%hhu", uc ); - } - - /** - * @brief 追加宽字符 - * - * @param [in] wc : wchar_t - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:38 - **/ - AutoBuffer& operator << (wchar_t wc){ - if ( wc == 0 ){ - return *this; - } -#if __GNUC__ <= 2 - wchar_t ws[] = { wc, 0 }; - return pushf( "%ls", ws ); -#else - return pushf( "%lc", wc ); -#endif - } - - /** - * @brief 追加宽字符串 - * - * @param [in] ws : const wchar_t* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:28:56 - **/ - AutoBuffer& operator << (const wchar_t *ws){ - if ( ws != NULL ){ - pushf( "%ls", ws ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加short型整数 - * - * @param [in] i : short - * @return AutoBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:35:32 - **/ - AutoBuffer& operator << (short i) { - return pushf( "%hd", i ); - } - - /** - * @brief 追加unsigned short型整数 - * - * @param [in] i : unsigned short - * @return AutoBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:42:27 - **/ - AutoBuffer& operator << (unsigned short i) { - return pushf( "%hu", i ); - } - - /** - * @brief 追加int型整数 - * - * @param [in] i : int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:10 - **/ - AutoBuffer& operator << (int i){ - return pushf( "%d", i ); - } - - /** - * @brief 追加unsigned int型整数 - * - * @param [in] i : unsigned int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:24 - **/ - AutoBuffer& operator << (unsigned int i){ - return pushf( "%u", i ); - } - - /** - * @brief 追加long int型整数 - * - * @param [in] i : long int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:44 - **/ - AutoBuffer& operator << (long int i){ - return pushf( "%ld", i ); - } - - /** - * @brief 追加unsigned long int型整数 - * - * @param [in] i : unsigned long int - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:29:58 - **/ - AutoBuffer& operator << (unsigned long int i){ - return pushf( "%lu", i ); - } - - /** - * @brief 追加字符串 - * - * @param [in] cstr : const char* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:26 - **/ - AutoBuffer& operator << (const char* cstr ){ - if ( cstr != NULL ){ - push( cstr, strlen(cstr) ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加long long型整数 - * - * @param [in] ll : long long - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:34 - **/ - AutoBuffer& operator << (long long ll){ - return pushf( "%lld", ll ); - } - - /** - * @brief 追加unsigned long long型整数 - * - * @param [in] ll : unsigned long long - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:44 - **/ - AutoBuffer& operator << (unsigned long long ll){ - return pushf( "%llu", ll ); - } - - /** - * @brief 追加double型浮点数 - * - * @param [in] n : double - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:30:59 - **/ - AutoBuffer& operator << (double n){ - return pushf( "%lg", n ); - } - - /** - * @brief 追加long double型浮点数 - * - * @param [in] n : long double - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:19 - **/ - AutoBuffer& operator << (long double n){ - return pushf( "%Lg", n ); - } - - /** - * @brief 追加指针字面值 - * - * @param [in] p : void* - * @return AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:53:41 - **/ - AutoBuffer& operator << (void *p){ - return pushf( "%p", p ); - } - - /** - * @brief 追加另一个AutoBuffer - * - * @param [in] other : const AutoBuffer& - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:54:00 - **/ - AutoBuffer& push(const AutoBuffer& other){ - return push( other._str, other._size ); - } - - /** - * @brief 追加布尔值 - * - * @param [in] b : bool - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:46 - **/ - AutoBuffer& push(bool b){ - if ( b ){ - return push( TRUE_LITERAL, TRUE_LITERAL_LEN ); - }else{ - return push( FALSE_LITERAL, FALSE_LITERAL_LEN ); - } - } - - /** - * @brief 追加字符,忽略'\0' - * - * @param [in] c : char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:31:58 - **/ - AutoBuffer& push(char c){ - if ( c == '\0' ){ - return *this; - } - if ( _size == _capacity ){ //full - reserve( _size + 1 ); //may fail - } - if ( _size < _capacity ){ - _str[_size] = c; - _str[++_size] = '\0'; - _truncated = false; - }else{ - _truncated = true; - } - return *this; - } - - /** - * @brief 追加有符号8位整数 - * - * @param [in] uc : signed char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:52:42 - **/ - AutoBuffer& push(signed char sc){ - return pushf("%hhd", sc); - } - - /** - * @brief 追加无符号8位整数 - * - * @param [in] uc : unsigned char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:39:33 - **/ - AutoBuffer& push(unsigned char uc){ - return pushf("%hhu", uc); - } - - /** - * @brief 追加多个字符,忽略'\0' - * - * @param [in] count : int - * @param [in] c : char - * @return AutoBuffer& - * @retval - * @see - * @author chenxm / zhujianwei - * @date 2009/02/04 18:40:04 / mod. by zhjw at 2010/09/21 - **/ - AutoBuffer& push(size_t count, char c){ - if ( c != '\0' ){ - if ( count > _capacity - _size ){ //full - count = (count <= size_t(-1) - _size) ? count : (size_t(-1) - _size); //limit the size - if( !reserve( _size + count ) ){ - //reserve fail - count = _capacity - _size; - _truncated = true; - }else{ - _truncated = false; - } - } - if ( count ){ - //str != NULL - memset( _str + _size, c, count ); - _str[ _size+=count ] = '\0'; - } - } - return *this; - } - - /** - * @brief 追加宽字符,忽略'\0' - * - * @param [in] wc : wchar_t - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:40:37 - **/ - AutoBuffer& push(wchar_t wc){ - if ( wc == 0 ){ - return *this; - } -#if __GNUC__ <= 2 - wchar_t ws[] = { wc, 0 }; - return pushf( "%ls", ws ); -#else - return pushf( "%lc", wc ); -#endif - } - - /** - * @brief 追加宽字符串,忽略'\0' - * - * @param [in] ws : const wchar_t* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:40:58 - **/ - AutoBuffer& push(const wchar_t * ws){ - if ( ws != NULL ){ - pushf( "%ls", ws ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加short型整数 - * - * @param [in] i : short - * @return AutoBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:43:58 - **/ - AutoBuffer& push(short i) { - return pushf( "%hd", i ); - } - - /** - * @brief 追加unsigned short型整数 - * - * @param [in] i : unsigned short - * @return AutoBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/17 18:44:41 - **/ - AutoBuffer& push(unsigned short i) { - return pushf( "%hu", i ); - } - - /** - * @brief 追加int型整数 - * - * @param [in] i : int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:22 - **/ - AutoBuffer& push(int i){ - return pushf( "%d", i ); - } - - /** - * @brief 追加unsigned int型整数 - * - * @param [in] i : unsigned int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:36 - **/ - AutoBuffer& push(unsigned int i){ - return pushf( "%u", i ); - } - - /** - * @brief 追加long int型整数 - * - * @param [in] i : long int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:41:50 - **/ - AutoBuffer& push(long int i){ - return pushf( "%ld", i ); - } - - /** - * @brief 追加unsigned long int型整数 - * - * @param [in] i : unsigned long int - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:00 - **/ - AutoBuffer& push(unsigned long int i){ - return pushf( "%lu", i ); - } - - /** - * @brief 追加字符串 - * - * @param [in] cstr : const char* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:15 - **/ - AutoBuffer& push(const char* cstr ){ - if ( cstr != NULL ){ - push( cstr, strlen(cstr) ); - }else{ - _truncated = false; - } - return *this; - } - - /** - * @brief 追加字符串子串 - * - * 调用者必须保证strlen(cstr) >= sub_str_len,否则行为未定义 - * - * @param [in] cstr : const char* - * @param [in] sub_str_len : size_t - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:28 - **/ - AutoBuffer& push(const char* cstr, size_t sub_str_len ); - - /** - * @brief 追加long long型整数 - * - * @param [in] ll : long long - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:47 - **/ - AutoBuffer& push(long long ll ){ - return pushf( "%lld", ll ); - } - - /** - * @brief 追加unsigned long long型整数 - * - * @param [in] ll : unsigned long long - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:23 - **/ - AutoBuffer& push(unsigned long long ll ){ - return pushf( "%llu", ll ); - } - - /** - * @brief 追加double型浮点数 - * - * @param [in] n : double - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:39 - **/ - AutoBuffer& push( double n ){ - return pushf( "%lg", n ); - } - - /** - * @brief 追加long double型浮点数 - * - * @param [in] n : long double - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:43:52 - **/ - AutoBuffer& push( long double n ){ - return pushf( "%Lg", n ); - } - - /** - * @brief 追加void *字符串 - * - * @param [in] p : void* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/04/12 01:33:41 - **/ - AutoBuffer& push( void *p ){ - return pushf( "%p", p ); - } - - //attrbute can only be put at function declarations until g++ 3 - /** - * @brief 以类似printf()语法追加字符串 - * - * @param [in] format : const char* - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:44:19 - **/ - AutoBuffer& pushf( const char *format, ... ) __attribute__ ((format (printf, 2, 3) )); - - /** - * @brief 以类似vprintf()语法追加字符串 - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return AutoBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:44:53 - **/ - AutoBuffer& vpushf( const char *format, va_list ap ); - - - public: - /** - * @brief 默认AutoBuffer的字符串容量 - * - **/ - static const int DEFAULT_CAPACITY = 64; - /** - * @brief 布尔型true的字面值 - * - **/ - static const char * const TRUE_LITERAL; - /** - * @brief 布尔型false的字面值 - * - **/ - static const char * const FALSE_LITERAL; - - private: - /** - * @brief 复制构造函数 - * - **/ - AutoBuffer( const AutoBuffer& other ); - /** - * @brief 复制赋值运算符 - * - **/ - AutoBuffer& operator = ( const AutoBuffer& ); - /** - * @brief AutoBuffer的长度 - * - **/ - size_t _size; - /** - * @brief AutoBuffer的容量 - * - **/ - size_t _capacity; - /** - * @brief 最近一次操作是否发生截断 - * - **/ - bool _truncated; - /** - * @brief AutoBuffer的内部字符串缓冲区 - * - **/ - char * _str; - /** - * @brief 布尔型true的字面值长度 - * - **/ - static const size_t TRUE_LITERAL_LEN; - /** - * @brief 布尔型false的字面值长度 - * - **/ - static const size_t FALSE_LITERAL_LEN; - - /** - * @brief 当前使用的内存池的指针 - * - **/ - mempool* _mempool; - - }; - -} //namespace bsl; - - -#endif //__BSL_AUTO_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/buffer/BCLOUD b/bsl/buffer/BCLOUD deleted file mode 100644 index 05daf6ce451de935f681565e4f020427b96c3aab..0000000000000000000000000000000000000000 --- a/bsl/buffer/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DBSL_DEBUG_FLAG -DBSL_VERSION=\"bsl1.0.2.0\" -DBSL_CVSTAG=\"bsl_1-0-2-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libbuffer.a') -#LIBS('$OUT/so/libbuffer.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("AutoBuffer.cpp BinBuffer.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('buffer', Sources(user_sources)) - -#UT -#UTApplication('buffer', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_buffer', Sources(user_sources)) -#StaticLibrary('buffer', PreBuilt(True)) - -#.so -#SharedLibrary('buffer', Sources(user_sources)) -#SharedLibrary('buffer', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/buffer/BinBuffer.cpp b/bsl/buffer/BinBuffer.cpp deleted file mode 100644 index 6aa9786505ef850b62be091701c192ad0221688e..0000000000000000000000000000000000000000 --- a/bsl/buffer/BinBuffer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_bin_buffer.cpp,v 1.0 2010/07/31 13:29:04 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_bin_buffer.cpp - * @author liaosb(liaoshangbin@baidu.com) - * @date 2010/07/31 13:47:35 - * @version $Revision: 1.0 $ - * @brief - * - **/ -#include "bsl/utils/bsl_memcpy.h" -#include "BinBuffer.h" - -namespace bsl{ - - BinBuffer& BinBuffer::push(const void* data_, size_t len ){ - if ( data_ != NULL && len != 0 ){ - if ( _str && (_size + len <= _capacity) ){ - xmemcpy( _str + _size, data_, len ); - _size += len; - _truncated = false; - }else{ //not enough space; - if ( reserve( _size + len) ){ - //reserve succeed, copy succeed - xmemcpy( _str + _size, data_, len ); - _size += len; - _truncated = false; - }else if ( _size < _capacity ){ - //reserve failed - //still has memory - //content is truncated - xmemcpy( _str + _size, data_, _capacity - _size ); - _size = _capacity; - _truncated = true; - _ever_truncated = true; - }else{ - //is full or _str == NULL - _truncated = true; - _ever_truncated = true; - _size = _capacity; - } - } - } - return *this; - } - -} //namespace bsl -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/buffer/BinBuffer.h b/bsl/buffer/BinBuffer.h deleted file mode 100644 index 867ae70d2e5fe98485b972222dd3a6edab76d13b..0000000000000000000000000000000000000000 --- a/bsl/buffer/BinBuffer.h +++ /dev/null @@ -1,573 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_bin_buffer.h,v 1.0 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - /** - * @file bsl_bin_buffer.h - * @author liaoshangbin(liaoshangbin@baidu.com) - * @date 2010/07/31 13:46:02 / 2010/10/15 modified by zhujianwei - * @version $Revision: 1.0 $ - * @brief - * - **/ - -#ifndef __BSL_BIN_BUFFER_H_ -#define __BSL_BIN_BUFFER_H_ -#include -#include -#include -#include -#include -#include "bsl/utils/bsl_memcpy.h" -#include "bsl/pool/bsl_pool.h" - - - -namespace bsl{ - /** - * @brief 读入数据,并按二进制进行存储 - * - * 该类的一大特点是不会抛出异常。在内存不足的时候,该类会截断字符串并置"被截断位"。 - * BinBuffer对象通过字节对齐方式自行管理一片用于表示字符串的缓冲区,并提供方法追加各种类型对象。 - * 若内存不足时,内存容量将翻倍,若申请新内存失败,将填满旧内存, - * 而且使truncated()方法返回true,ever_truncated()返回true。 - */ - class BinBuffer{ - public: - /** - * @brief 构造函数 - * - * 可传入capacity参数指定预分配的内存空间。如capacity==0没有动态内存分配。 - * 可传入pack参数指定默认字节对齐值,pack要求为2的整数幂并且<=MAX_PACK - * 否则_pack=DEFAULT_PACK - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] capacity : size_t - * @param [in] pack : size_t - * @see - * @author liaoshangbin - * @date 2010/7/29 12:05:10 - **/ - explicit BinBuffer( size_t cap = DEFAULT_CAPACITY, size_t pack = DEFAULT_PACK) - :_size(0), _capacity(cap), _pack(pack), - _truncated(false), _ever_truncated(false), _str(NULL), _mempool(NULL) { - if ( _capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity) : _mempool->malloc(_capacity)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - if(!(pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two(pack))){ - _pack = DEFAULT_PACK; - } - } - - /** - * @brief 使用allocator的构造函数 - * - * 可传入capacity参数指定预分配的内存空间。如capacity==0没有动态内存分配。 - * 可传入pool参数指定使用的内存池 - * 可传入pack参数指定默认字节对齐值,pack要求为2的整数幂并且<=MAX_PACK - * 否则_pack=DEFAULT_PACK - * - * 注:如内存分配失败不会抛出异常。其结果相当于以0为参数构造。 - * - * @param [in] pool : mempool& - * @param [in] capacity : size_t - * @param [in] pack : size_t - * @see - * @author - * @date 2010/7/29 12:06:16 - **/ - explicit BinBuffer( - mempool& pool, - size_t cap = DEFAULT_CAPACITY, - size_t pack = DEFAULT_PACK - ) - :_size(0), _capacity(cap), _pack(pack), - _truncated(false), _ever_truncated(false), _str(NULL), _mempool(&pool) { - if ( _capacity != 0 ) { - _str = static_cast(_mempool == NULL ? - malloc(_capacity) : _mempool->malloc(_capacity)); - if ( _str ){ - _str[0] = '\0'; - }else{ - _capacity = 0; - } - } - if(!(pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two(pack))) { - _pack = DEFAULT_PACK; - } - } - - /** - * @brief 把另一BinBuffer的内存转移到本BinBuffer(另一BinBuffer会被清空),O(1)复杂度 - * 因为不同BinBuffer使用的内存池会有不同 - * 先释放自身_str的内存,然后_str指向other._str浅复制字符串, - * 自身的_mempool指向other._mempool,这样_mempool还是处理_str这块内存 - * 最后清空other._str,other成为空的BinBuffer还可以继续使用 - * - * @param [in] other : BinBuffer& - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 17:45:30 - **/ - BinBuffer& transfer_from ( BinBuffer& other ){ - if ( &other != this ){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - _size = other._size; - _capacity = other._capacity; - _pack = other._pack; - _truncated = other._truncated; - _ever_truncated = other._ever_truncated; - _str = other._str; - _mempool = other._mempool; - other._size = 0; - other._capacity = 0; - other._pack = DEFAULT_PACK; - other._truncated= false; - other._ever_truncated = false; - other._str = NULL; - } - return *this; - } - - /** - * @brief 交换两BinBuffer内容,O(1)复杂度 - * - * @param [in] other : BinBuffer& - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:15 - **/ - void swap( BinBuffer& other ){ - std::swap( _str, other._str ); - std::swap( _size, other._size ); - std::swap( _capacity, other._capacity ); - std::swap( _pack, other._pack ); - std::swap( _truncated, other._truncated ); - std::swap( _ever_truncated, other._ever_truncated ); - std::swap( _mempool, other._mempool ); - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 18:14:47 - **/ - ~BinBuffer(){ - if ( _str ){ - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - } - - /** - * @brief BinBuffer长度 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:14:56 - **/ - size_t size() const{ - return _size; - } - - /** - * @brief BinBuffer当前容量。保证容量>=长度。当容量不足时,容量会自动增长。 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:15:23 - **/ - size_t capacity() const { - return _capacity; - } - - /** - * @brief 返回BinBuffer是否为空 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:26 - **/ - bool empty() const { - return _size == 0; - } - - /** - * @brief 返回BinBuffer是否为满 - * - * @return bool - * @retval - * @see - * @author - * @date - **/ - bool full() const { - return _size == _capacity; - } - - /** - * @brief 返回BinBuffer最近一次操作是否发生了截断 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:16:58 - **/ - bool truncated() const { - return _truncated; - } - - /** - * @brief 返回BinBuffer到目前为止是否发生了截断 - * - * @return bool - * @retval - * @see - * @author liaoshangbin - * @date 2010/07/31 14:49:24 - **/ - bool ever_truncated() const { - return _ever_truncated; - } - - /** - * @brief 返回BinBuffer内容的C风格字符串表示。O(1)复杂度 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:17:26 - **/ - const char * data() const { - if ( _str ){ - return _str; - }else{ - return ""; - } - } - - /** - * @brief 清空内容 - * - * @return void - * @retval - * @see - * @author liaoshangbin - * @date - **/ - void clear() { - if ( _size ){ - _str[0] = '\0'; - } - _size = 0; - } - - /** - * @brief 手动扩大内存容量 - * - * @param [in] __capacity : size_t - * @return bool - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:18:34 - **/ - bool reserve( size_t cap ) { - if ( cap > _capacity ){ - if ( cap < _capacity * 2 ){ - cap = _capacity * 2; - } - - char * _new = static_cast(_mempool == NULL ? - malloc(cap) :_mempool->malloc(cap)); - if ( !_new ){ - return false; - } - - if ( _str ){ - xmemcpy( _new, _str, _size ); - _mempool == NULL ? free( _str ) : _mempool->free( _str, _capacity); - } - - _str = _new; - _capacity = cap; - } - - return true; - } - - /** - * @brief 追加另一个BinBuffer,other按照min(other.get_pack(), this->_pack)字节对齐 - * - * @param [in] other : const BinBuffer& - * @return BinBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:49:30 - **/ - BinBuffer& operator << (const BinBuffer& other){ - size_t pack = other.get_pack(); - pack = pack < _pack ? pack : _pack; - _size = (_size + pack - 1) & (~(pack-1)); - return push( other.data(), other.size() ); - } - - /** - * @brief 处理数值类型 - * bool,signed char,unsigned char,short,unsigned short,int - * unsigned int,long int,unsigned long int,long long - * unsigned long lont,double,long double - * - * wchar_t:可输入任意的宽字符,包括'\0' - * char:可输入任意的字符,包括'\0' - * - * @param [in] value : _Tp - * @return BinBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/20 12:23:07 - **/ - template - BinBuffer& operator << ( _Tp value ) { - return push_bin_data( &value, sizeof(value) ); - } - - /** - * @brief 追加另一个BinBuffer,新的BinBuffer按照min(other.get_pack(), this->_pack)字节对齐 - * - * @param [in] other : const BinBuffer& - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:54:00 - **/ - BinBuffer& push(const BinBuffer& other){ - size_t pack = other.get_pack(); - pack = pack > _pack ? pack : _pack; - _size = (_size + pack - 1) & (~(pack-1)); - return push( other.data(), other._size ); - } - - /** - * @brief 处理数值类型 - * bool,signed char,unsigned char,short,unsigned short,int - * unsigned int,long int,unsigned long int,long long - * unsigned long lont,double,long double - * - * wchar_t:可输入任意的宽字符,包括'\0' - * char:可输入任意的字符,包括'\0' - * - * @param [in] value : _Tp - * @return BinBuffer& operator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/20 12:23:07 - **/ - template - BinBuffer& push( _Tp value ) { - return push_bin_data( &value, sizeof(value) ); - } - - /** - * @brief 追加多个任意字符 - * - * @param [in] count : int - * @param [in] c : char - * @return BinBuffer& - * @retval - * @see - * @author chenxm / zhujianwei - * @date 2009/02/04 18:40:04 / mod. by zhjw at 2010/09/21 - **/ - BinBuffer& push( size_t count, char c){ - if ( count > _capacity - _size ){ //full - count = (count <= size_t(-1) - _size) ? count : (size_t(-1) - _size); //limit the size - if( !reserve( _size + count ) ){ - //reserve fail - count = _capacity - _size; - _truncated = true; - _ever_truncated = true; - }else{ - _truncated = false; - } - } - if ( count ){ - //str != NULL - memset( _str + _size, c, count ); - _size += count; - } - return *this; - } - - /** - * @brief 追加len长度的数据 - * - * 调用者必须保证data指向的数据长度不大于len,否则行为未定义 - * - * @param [in] data_ : const void* - * @param [in] len : size_t - * @return BinBuffer& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:42:28 - **/ - BinBuffer& push(const void* data_, size_t len ); - - /** - * @brief 自定义字节对齐值 - * 返回值为true表示设置成功,false表示设置失败 - * - * @param [in] pack : size_t - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 17:46:41 - **/ - bool set_pack( size_t pack ) { - if ( pack > 0 && pack <= DEFAULT_MAX_PACK && is_power_two( pack ) ) { - _pack = pack; - return true; - } - return false; - } - - /** - * @brief 返回自定义字节对齐值 - * - * @param - * @return size_t - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/03 10:48:18 - **/ - size_t get_pack() const { - return _pack; - } - - public: - /** - * @brief 默认容量大小 - */ - static const size_t DEFAULT_CAPACITY = 64; - /** - * @brief 默认字节对齐值 - */ - static const size_t DEFAULT_PACK = 4; - /** - * @brief 默认最大字节对齐值 - */ - static const size_t DEFAULT_MAX_PACK = 64; - - private: - /** - * @brief 复制构造函数 - */ - BinBuffer( const BinBuffer& other ); - /** - * @brief 复制赋值运算符 - */ - BinBuffer& operator = ( const BinBuffer& ); - /** - * @brief 判断一个整数是否为2的整数幂 - * - * @param [in] n : int - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 15:55:57 - **/ - inline bool is_power_two(size_t n) { - return (((n)&(n-1))==0); - } - /** - * @brief 数值型数据通过此函数插入到buffer中 - * - * @param [in] data : const void* - * @param [in] len : size_t - * @return BinBuffer& - * @retval - * @see - * @author liaoshangbin - * @data 2010/07/31 17:50:09 - **/ - BinBuffer& push_bin_data( const void* data_, size_t len ) { - // 根据_pack计算_size的起始位置 - size_t len_ = (len < _pack) ? len : _pack; - _size = (_size + len_ - 1) & (~(len_ - 1)); - // push函数注意如果内存无法分配时调整_size大小 - return push( data_, len ); - } - - /** - * @brief BinBuffer的长度 - */ - size_t _size; - /** - * @brief BinBuffer的容量 - */ - size_t _capacity; - /** - * @brief 自定义字节对齐值 - */ - size_t _pack; - /** - * @brief 最近一次操作是否发生截断 - */ - bool _truncated; - /** - * @brief 到目前为止是否发现截断 - */ - bool _ever_truncated; - /** - * @brief BinBuffer的内部字符串缓冲区 - */ - char * _str; - - /** - * @brief 当前使用的内存池的指针 - * - **/ - mempool* _mempool; - - }; - -} //namespace bsl; - - -#endif //__BSL_AUTO_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/buffer/CMakeLists.txt b/bsl/buffer/CMakeLists.txt deleted file mode 100644 index 1eac01dd44c9cc71caf61e175cca83f3630d5a1d..0000000000000000000000000000000000000000 --- a/bsl/buffer/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -FILE(GLOB buffer_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(buffer ${CMAKE_CURRENT_LIST_DIR}/AutoBuffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/BinBuffer.cpp) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/buffer/Makefile b/bsl/buffer/Makefile deleted file mode 100644 index 65017bc623aed8a6d74003df0c916d8a97572b96..0000000000000000000000000000000000000000 --- a/bsl/buffer/Makefile +++ /dev/null @@ -1,109 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: 2008年 08月 18日 星期一 14:49:27 CST # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -TARGET = bsl_buffer -BSL_ROOT = .. -include Makefile.env - -CC = g++ -OUTPUT_HEAD_PATH= $(BSL_ROOT)/output/include/bsl -OUTPUT_LIB_PATH = $(BSL_ROOT)/output/lib - -##### build & test configuration ##### - -LOCAL_HEADS = $(wildcard *.h) $(wildcard *.hpp) - -HEADS = $(LOCAL_HEADS) - -OBJECTS = AutoBuffer.o BinBuffer.o - -INCLUDES = -LIBS = -L../output/lib/ -lbsl - -##### other ##### - -TAG_ROOT = $(BSL_ROOT) - -####################################### RULES ####################################### - -#comment the following line for debugging -.SILENT: all test output clean tag doc debug depend - -.PHONY: all test output clean tag doc debug depend - -#comment the following line to use default known suffixes (DANGEROUS!!!) -.SUFFIXES: - -all: output clean - cp *.h ../ - -%: %.o $(OBJECTS) - @echo "[make] building $@ ..." - $(CC) -o $@ $^ $(BSL_LDFLAGS) $(LIBS) - -%.o: %.cpp $(HEADS) - @echo "[make] building $@ ..." - $(CC) -g -o $@ -c $< $(DEBUG) $(BSL_CXXFLAGS) $(INCLUDES) - -depend: - @for DEPENDENCY in $(DEPENDENCYS); do echo "[make] making lib $$DEPENDENCY ..."; make -C $$DEPENDENCY; done - -test: $(TEST_TARGETS) - @echo "[make] testing ..." - @for TEST_TARGET in $(TEST_TARGETS); do echo "[make] testing $$TEST_TARGET ..."; ./$$TEST_TARGET; done - -test_$(TARGET): test_$(TARGET).o $(OBJECTS) - @echo "[make] building $@ ..." - $(CC) -o $@ $^ $(BSL_LDFLAGS) $(LIBS) - -output: lib$(TARGET).a $(LOCAL_HEADS) - @echo "[make] copying $< to $(OUTPUT_LIB_PATH) ..." - mkdir -p $(OUTPUT_LIB_PATH) - cp $< $(OUTPUT_LIB_PATH) - @echo "[make] copying $(LOCAL_HEADS) to $(OUTPUT_HEAD_PATH) ..." - mkdir -p $(OUTPUT_HEAD_PATH) - cp $(LOCAL_HEADS) $(OUTPUT_HEAD_PATH) - -lib$(TARGET).a: $(OBJECTS) - @echo "[make] building $@ ..." - ar cr $@ $^ - -clean: - @echo "[make] cleaning ..." - rm *.o *.a $(TEST_TARGETS) -f - -doc: - @echo "[make] generating documents ..." - doxygen - -tag: - @echo "[make] generating tags ..." - ctags --c++-kinds=+p --fields=+iaS --extra=+q -R $(TAG_ROOT); - -debug: - @echo "[make] printing variables ..." - @echo 'basic configuration' - @echo '$$(TARGET) = $(TARGET)' - @echo '' - @echo 'path configuration' - @echo '$$(WORK_ROOT) = $(WORK_ROOT)' - @echo '$$(LIB2_PATH) = $(LIB2_PATH)' - @echo '$$(BSL_ROOT) = $(BSL_ROOT)' - @echo '$$(OUTPUT_HEAD_PATH) = $(OUTPUT_HEAD_PATH)' - @echo '$$(OUTPUT_LIB_PATH) = $(OUTPUT_LIB_PATH)' - @echo '' - @echo 'build & test configuration' - @echo '$$(INCLUDES) = $(INCLUDES)' - @echo '$$(LOCAL_HEADS) = $(LOCAL_HEADS)' - @echo '$$(OBJECTS) = $(OBJECTS)' - @echo '$$(LIBS) = $(LIBS)' - @echo '$$(TEST_TARGETS) = $(TEST_TARGETS)' - @echo '' - @echo 'other' - @echo '$$(TAG_ROOT) = $(TAG_ROOT)' diff --git a/bsl/buffer/Makefile.env b/bsl/buffer/Makefile.env deleted file mode 100644 index 22a1ad910872b78a944b252ffae44c2bf8263150..0000000000000000000000000000000000000000 --- a/bsl/buffer/Makefile.env +++ /dev/null @@ -1,41 +0,0 @@ -# Public Makefile settings for BSL -# It requires BSL_ROOT to be set before include this file - -# About the project ######################### -BSL_PROJECT_NAME= bsl -BSL_VERSION = "$(BSL_PROJECT_NAME) 1.0.2.0" -BSL_CVSTAG = "$(BSL_PROJECT_NAME)_1-0-2-0_PD_BL" - -# Paths ##################################### -WORK_ROOT = $(BSL_ROOT)/../../ -BSL_OUTPUT_PATH = $(BSL_ROOT)/output/ - - -# Machine ################################### -ifeq ($(MAC),64) -ARCH = 64 -else -ARCH = 32 -endif - - -# Compile Tools ############################# -CXX = g++ -CC = g++ -SHELL = /bin/sh - -# Public flags -DEBUG_FLAG = -DBSL_DEBUG_FLAG -PROJECT_FLAGS = \ - -DBSL_VERSION="\$(BSL_VERSION)\" \ - -DBSL_CVSTAG="\$(BSL_CVSTAG)\" \ - -DBSL_PROJECT_NAME="\"$(BSL_PROJECT_NAME)\"" - -BSL_CXXFLAGS = \ - -g -rdynamic -pipe -fPIC -finline-functions \ - -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \ - -Wconversion -Winline -Woverloaded-virtual -Wsign-promo \ - $(DEBUG_FLAG) $(PROJECT_FLAGS) -I../output/include - -BSL_LDFLAGS = -rdynamic - diff --git a/bsl/buffer/bsl_shared_buffer.cpp b/bsl/buffer/bsl_shared_buffer.cpp deleted file mode 100644 index b3bc55ffe2a545c5de2953123f6b6548eb8f3b39..0000000000000000000000000000000000000000 --- a/bsl/buffer/bsl_shared_buffer.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_shared_buffer.cpp,v 1.4 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_shared_buffer.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/12/08 20:04:17 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "bsl_shared_buffer.h" -#include "bsl_exception.h" - -namespace bsl{ - const char * const SharedBuffer::TRUE_LITERAL = "true"; - const char * const SharedBuffer::FALSE_LITERAL= "false"; - - SharedBuffer::SharedBuffer( const SharedBuffer& other ) - : _pbuf( other._pbuf ) { - _pbuf->_ref_count += 1; - if ( _pbuf->_ref_count < 0 ){ - //reference count overflow - _pbuf->_ref_count -= 1; - throw OverflowException()<_ref_count -=1; - - if ( !_pbuf->_ref_count ){ - free( _pbuf ); - } - - _pbuf = other._pbuf; - _pbuf->_ref_count += 1; - - if ( _pbuf->_ref_count < 0 ){ - throw OverflowException()<_size + len) <= _pbuf->_capacity ){ - memcpy( _pbuf->_begin, cstr, len ); - _pbuf->_size += len; - _pbuf->_begin[ _pbuf->_size ] = 0; - _pbuf->_truncated = false; - - }else{ //not enough space; - if ( reserve( _pbuf->_size + len) ){ - //reserve succeed, copy succeed - memcpy( _pbuf->_begin, cstr, len ); - _pbuf->_size += len; - _pbuf->_begin[ _pbuf->_size ] = 0; - _pbuf->_truncated = false; - - }else{ - //reserve failed - //content is truncated - memcpy( _pbuf->_begin, cstr, _pbuf->_capacity - _pbuf->_size ); - _pbuf->_size = _pbuf->_capacity; - _pbuf->_begin[ _pbuf->_size ] = 0; - _pbuf->_truncated = true; - } - - } - } - return *this; - } - - SharedBuffer& SharedBuffer::vpushf( const char *format, va_list ap ){ - va_list aq; - va_copy( aq, ap ); - int len = vsnprintf( _pbuf->_begin + _pbuf->_size, _pbuf->_capacity - _pbuf->_size + 1, format, aq ); - va_end( aq ); - if ( len >= 0 ){ - - if ( _pbuf->_size + len <= _pbuf->_capacity ){ - _pbuf->_size += len; - _pbuf->_truncated = false; - - }else{ //truncated - if ( reserve( _pbuf->_size + len) ){ - //reserve succeed, vsnprintf succeed - va_copy( aq, ap ); - vsnprintf( _pbuf->_begin + _pbuf->_size, _pbuf->_capacity - _pbuf->_size + 1, format, aq ); - va_end( aq ); - - _pbuf->_size += len; - _pbuf->_truncated = false; - - }else{ - //reserve failed - //content is truncated - _pbuf->_size = _pbuf->_capacity; - _pbuf->_truncated = true; - } - - } - } - return *this; - } - - void SharedBuffer::_init( int __capacity ){ - if ( __capacity < 0 ){ - throw BadArgumentException()<(malloc(sizeof(_buffer_t))); - if ( !_pbuf ){ - throw BadAllocException()<_begin = static_cast(malloc(__capacity + 1)); - if ( !_pbuf->_begin ){ - free(_pbuf); - throw BadAllocException()<_size = 0; - _pbuf->_capacity = __capacity; - _pbuf->_ref_count = 1; - _pbuf->_truncated = false; - } -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/buffer/bsl_shared_buffer.h_ b/bsl/buffer/bsl_shared_buffer.h_ deleted file mode 100644 index 344d9fd4a4230dce5d9a6eda92f24158122cd0c9..0000000000000000000000000000000000000000 --- a/bsl/buffer/bsl_shared_buffer.h_ +++ /dev/null @@ -1,296 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_shared_buffer.h_,v 1.4 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file SharedBuffer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/02 12:15:49 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_SHARED_BUFFER_H_ -#define __BSL_SHARED_BUFFER_H_ -#include -#include -#include -#include - -namespace bsl{ - /** - * @brief 共享缓冲区类 - * - * 除构造失败、unshare()失败外,一切其它操作都不抛出异常。 - * 不使用copy-on-write,一切改操作对所有共享的实例都可见。若不希望修改对其它共享实例可见可调用unshare() - * 缓冲区满时,会尝试申请新的内存,若失败,不会抛出异常,写入的内容会被截断,truncated() 返回true - */ - class SharedBuffer{ - public: - SharedBuffer( int __capacity = DEFAULT_CAPACITY ){ - _init( __capacity ); - } - - SharedBuffer( const SharedBuffer& other ); - - SharedBuffer& operator = ( const SharedBuffer& other ); - - ~SharedBuffer( ){ - _pbuf->_ref_count -= 1; - - if ( !_pbuf->_ref_count ){ - free( _pbuf ); - } - } - - size_t size() const { - return _pbuf->_size; - } - - size_t capacity() const { - return _pbuf->_capacity; - } - - bool empty() const { - return _pbuf->_size == 0; - } - - bool full() const { - return _pbuf->_size == _pbuf->_capacity; - } - - bool truncated() const { - return _pbuf->_truncated; - } - - const char * c_str() const { - return _pbuf->_begin; - } - - void clear() { - _pbuf->_size = 0; - } - - bool reserve( int __capacity ) { - if ( __capacity > _pbuf->_capacity ){ - if ( __capacity < _pbuf->_capacity * 2 ){ - __capacity = _pbuf->_capacity * 2; - } - - char * _begin = static_cast(malloc(__capacity + 1)); - if ( !_begin ){ - return false; - } - - memcpy( _begin, _pbuf->_begin, _pbuf->_size + 1 ); - free( _pbuf->_begin ); - _pbuf->_begin = _begin; - _pbuf->_capacity = __capacity; - - } - - return true; - } - - void unshare(){ - if ( _pbuf->_ref_count > 1 ){ - _buffer_t *old_pbuf = _pbuf; - - try{ - _init( old_pbuf->_capacity ); //throw - - memcpy( _pbuf->_begin, old_pbuf->_begin, old_pbuf->_size + 1); - _pbuf->_size = old_pbuf->_size; - _pbuf->_truncated = old_pbuf->_truncated; - _pbuf->_ref_count = 1; - -- old_pbuf->_ref_count; - - }catch(...){ - _pbuf = old_pbuf; - throw; - } - } - } - - SharedBuffer& operator << (bool b){ - _push( b ? TRUE_LITERAL : FALSE_LITERAL, "%s" ); - return *this; - } - - SharedBuffer& operator << (char c){ - if ( c == '\0' ){ - return *this; - } - if ( _pbuf->_size == _pbuf->_capacity ){ //full - reserve( _pbuf->_size + 1 ); //may fail - } - if ( _pbuf->_size < _pbuf->_capacity ){ - _pbuf->_begin[_pbuf->_size] = c; - _pbuf->_begin[++_pbuf->_size] = '\0'; - _pbuf->_truncated = false; - }else{ - _pbuf->_truncated = true; - } - return *this; - } - - SharedBuffer& operator << (int i){ - _push( i, "%d" ); - return *this; - } - - SharedBuffer& operator << (const char* cstr ){ - if ( cstr != NULL ){ - _push( cstr, "%s" ); - }else{ - _pbuf->_truncated = false; - } - return *this; - } - - SharedBuffer& operator << (long long ll){ - _push( ll, "%lld" ); - return *this; - } - - SharedBuffer& operator << (double lf){ - _push( lf, "%lg" ); - return *this; - } - - SharedBuffer& push(bool b){ - _push( b ? TRUE_LITERAL : FALSE_LITERAL, "%s" ); - return *this; - } - - SharedBuffer& push(char c){ - if ( c == '\0' ){ - return *this; - } - if ( _pbuf->_size == _pbuf->_capacity ){ //full - reserve( _pbuf->_size + 1 ); //may fail - } - if ( _pbuf->_size < _pbuf->_capacity ){ - _pbuf->_begin[_pbuf->_size] = c; - _pbuf->_begin[++_pbuf->_size] = '\0'; - _pbuf->_truncated = false; - }else{ - _pbuf->_truncated = true; - } - return *this; - } - - SharedBuffer& push(int count, char c){ - if ( count > 0 && c != '\0' ){ - - if ( _pbuf->_size + count > _pbuf->_capacity ){ //full - if( !reserve( _pbuf->_size + count ) ){ - //reserve fail - count = _pbuf->_capacity - _pbuf->_size; - _pbuf->_truncated = true; - }else{ - _pbuf->_truncated = false; - } - } - memset( _pbuf->_begin + _pbuf->_size, c, count ); - _pbuf->_begin[ _pbuf->_size+=count ] = '\0'; - } - return *this; - } - - - SharedBuffer& push(int i){ - _push( i, "%d" ); - return *this; - } - - - SharedBuffer& push(const char* cstr ){ - if ( cstr != NULL ){ - _push( cstr, "%s" ); - }else{ - _pbuf->_truncated = false; - } - return *this; - } - - SharedBuffer& push(const char* cstr, size_t sub_str_len ); - - - SharedBuffer& push(long long ll ){ - _push( ll, "%lld" ); - return *this; - } - - - SharedBuffer& push( double n ){ - _push( n, "%lg" ); - return *this; - } - - SharedBuffer& pushf( const char *format, ... ){ - va_list ap; - va_start( ap, format ); - vpushf( format, ap ); - va_end( ap ); - return *this; - } - - SharedBuffer& vpushf( const char *format, va_list ap ); - - public: - - static const int DEFAULT_CAPACITY = 64; - static const char * const TRUE_LITERAL; - static const char * const FALSE_LITERAL; - - - private: - - void _init( int __capacity ); - - template - void _push(T value, const char * format ){ - int len = snprintf( _pbuf->_begin + _pbuf->_size, _pbuf->_capacity + 1 - _pbuf->_size, format, value ); - if ( _pbuf->_size + len <= _pbuf->_capacity ){ - _pbuf->_size += len; - _pbuf->_truncated = false; - - }else{ //truncated - if ( reserve( _pbuf->_size + len) ){ - //reserve succeed, snprintf succeed - snprintf( _pbuf->_begin + _pbuf->_size, _pbuf->_capacity + 1 - _pbuf->_size, format, value ); - _pbuf->_size += len; - _pbuf->_truncated = false; - - }else{ - //reserve failed - //content is truncated - _pbuf->_size = _pbuf->_capacity; - _pbuf->_truncated = true; - } - - } - } - - struct _buffer_t{ - char * _begin; - int _size; - int _capacity; - int _ref_count; - bool _truncated; - } *_pbuf; - - }; -} //namespace bsl; - - - -#endif //__BSL_SHARED_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/check_cast/BCLOUD b/bsl/check_cast/BCLOUD deleted file mode 100644 index 93beb86cfa4666ca6f57adc99546720796f6c0dc..0000000000000000000000000000000000000000 --- a/bsl/check_cast/BCLOUD +++ /dev/null @@ -1,70 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DVAR_DEBUG_FLAG -DBSL_VERSION=\"bsl1.1.0.0\" -DBSL_CVSTAG=\"bsl_1-1-0-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') - -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libexception.a') -#LIBS('$OUT/so/libexception.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl/check_cast') -HEADERS('*.h', '$INC/bsl/') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('exception', Sources(user_sources)) - -#UT -#UTApplication('exception', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_check_cast', Sources(user_sources)) -#StaticLibrary('exception', PreBuilt(True)) - -#.so -#SharedLibrary('exception', Sources(user_sources)) -#SharedLibrary('exception', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/check_cast/CMakeLists.txt b/bsl/check_cast/CMakeLists.txt deleted file mode 100644 index 3a8f94f8564fc3714f1a2a2dcd702444e276f28e..0000000000000000000000000000000000000000 --- a/bsl/check_cast/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -FILE(GLOB check_cast_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(check_cast ${check_cast_srcs}) -add_dependencies(check_cast copy_bsl_headers) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/check_cast/Makefile b/bsl/check_cast/Makefile deleted file mode 100644 index 8d23a2c5739b8ea326c2bf21a0a41908ad669bce..0000000000000000000000000000000000000000 --- a/bsl/check_cast/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = ../var -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_ENTRANCES= check_cast.h - -PROVIDE_HEADS = $(filter-out check_cast_generated.h, $(wildcard *.h) ) check_cast_generated.h - -PROVIDE_OBJECTS = check_cast_cstring.o - -PROVIDE_LIB = bsl_check_cast - -DEPEND_HEADS = $(PROVIDE_HEADS) - -DEPEND_OBJECTS = - -DEPEND_LIBS = - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -##### OVERWRITE ##### - -OUTPUT_HEAD_PATH= $(BSL_ROOT)/output/include/bsl/check_cast - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### -check_cast_generated.h: check_cast.py - ./$^ > $@ - - diff --git a/bsl/check_cast/check_cast.h b/bsl/check_cast/check_cast.h deleted file mode 100644 index 5203c6c69540a252b3d2d4d2cdbc048448896a4a..0000000000000000000000000000000000000000 --- a/bsl/check_cast/check_cast.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: check_cast.h,v 1.3 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file check_cast.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/11/11 13:39:24 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __CHECK_CAST_H_ -#define __CHECK_CAST_H_ - -#include "bsl/exception/bsl_exception.h" - -namespace bsl{ - /** - * @brief check_cast<>模板函数 - * - * 提供对C/C++各原生类型提供带上下溢出检查功能模板函数。使用方式与static_cast<>完全相同。 - * - * 目前支持所有有符号数值类型、无符号数值类型、浮点数类型中任意两类型的双向转换以及C风格字符串(const char *)到以上各类型的单向转换。不考虑浮点数转换成浮点数类型的数值溢出问题。 - * - * @param [in] value : SrcType - * @return DestType - * @retval - * @see - * @author chenxm - * @date 2009/02/03 11:36:45 - **/ - template - DestType check_cast( SrcType value ); - - - /** - * @brief check_cast<>模板函数在DestType == SrcType时的偏特化版本 - * - * @param [in] value : DestType - * @return DestType - * @retval - * @see - * @author chenxm - * @date 2009/02/03 11:40:03 - **/ -#if __GNUC__ < 4 - template - inline DestType check_cast( DestType value ){ - return value; - } -#endif - -} -#include "bsl/check_cast/check_cast_generated.h" //generated code -#include "bsl/check_cast/check_cast_cstring.h" -#include "bsl/check_cast/check_cast_bsl_string.h" - -#endif //__CHECK_CAST_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/check_cast/check_cast.py b/bsl/check_cast/check_cast.py deleted file mode 100755 index 92eaad8eb770718a8c84fd747dbd8d824115cbca..0000000000000000000000000000000000000000 --- a/bsl/check_cast/check_cast.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python -INF = float('inf') - -SUFFIX = { - 'long': 'L', - 'long long': 'LL', - 'unsigned int': 'U', - 'unsigned long': 'UL', - 'unsigned long long': 'ULL', - 'float': '.0', - 'double': '.0', - 'long double': '.0L' -} - -MIN_32 = { - 'char': -2**7, 'signed char': -2**7, 'short': -2**15, 'int': -2**31, 'long': -2**31, 'long long': -2**63, - 'unsigned char': 0, 'unsigned short': 0, 'unsigned int': 0, 'unsigned long': 0, 'unsigned long long': 0, - 'float': -INF, 'double': -INF, 'long double': -INF, -} - -MAX_32 = { - 'char': 2**7-1, 'signed char': 2**7-1, 'short': 2**15-1, 'int': 2**31-1, 'long': 2**31-1, 'long long': 2**63-1, - 'unsigned char': 2**8-1, 'unsigned short': 2**16-1, 'unsigned int': 2**32-1, 'unsigned long': 2**32-1, 'unsigned long long': 2**64-1, - 'float': INF, 'double': INF, 'long double': INF, -} - -MIN_64 = dict(MIN_32) -MIN_64['long'] = MIN_64['long long'] - -MAX_64 = dict(MAX_32) -MAX_64['long'] = MAX_64['long long'] -MAX_64['unsigned long'] = MAX_64['unsigned long long'] - -TYPES = MIN_32.keys() - -FILE_HEADER = """ -#ifndef __CHECK_CAST_GENERATED_H_ -#define __CHECK_CAST_GENERATED_H_ - -/* CAUTION: this file is generated by check_cast.py automatically, don't modify it */ -//internal use -#ifndef __CHECK_CAST_H_ -#error "this file cannot be included directly, please include \"check_cast.h\" instead" -#endif - -#include -namespace bsl{ -""" - -FILE_FOOTER = """ -} // namespace bsl -#endif //__CHECK_CAST_GENERATED_H_ -""" - -FUNCTION_TEMPLATE = """ - template<> - inline %(dest_type)s check_cast<%(dest_type)s, %(src_type)s>( %(src_type)s value ){ - %(min_check_code)s - %(max_check_code)s - return static_cast<%(dest_type)s>(value); - } -""" - - -def gen_function( src_type, dest_type, MIN, MAX ): - - - if MIN[src_type] < MIN[dest_type]: - min_check_code = """ - if ( value < %(bound)s ){ - throw bsl::UnderflowException()< MAX[dest_type]: - max_check_code = """ - if ( value > %(bound)s ){ - throw bsl::OverflowException()< - inline bsl::string check_cast(char value) { - return bsl::string().appendf("%c", value); - } - - /** - * @brief 将8位整数(int8_t)转换成bsl::string,使用十进制 - * - * @param [in/out] value : unsigned char - * @return bsl::string - * @retval - * @see - * @note - * @author chenxm - * @date 2009/08/11 17:16:20 - **/ - template<> - inline bsl::string check_cast(signed char value) - { - return bsl::string().appendf("%hhd", value); - } - - /** - * @brief 将8位整数(uint8_t)转换成bsl::string,使用十进制 - * - * @param [in/out] value : unsigned char - * @return bsl::string - * @retval - * @see - * @note - * @author chenxm - * @date 2009/08/11 17:16:20 - **/ - template<> - inline bsl::string check_cast(unsigned char value) - { - return bsl::string().appendf("%hhu", value); - } - - template<> - inline bsl::string check_cast(short value) - { - return bsl::string().appendf("%hd", value); - } - - template<> - inline bsl::string check_cast(unsigned short value) - { - return bsl::string().appendf("%hu", value); - } - - template<> - inline bsl::string check_cast(int value) - { - return bsl::string().appendf("%d", value); - } - - template<> - inline bsl::string check_cast(unsigned int value) - { - return bsl::string().appendf("%u", value); - } - - template<> - inline bsl::string check_cast(long value) - { - return bsl::string().appendf("%ld", value); - } - - template<> - inline bsl::string check_cast(unsigned long value) - { - return bsl::string().appendf("%lu", value); - } - - template<> - inline bsl::string check_cast(long long value) - { - return bsl::string().appendf("%lld", value); - } - - template<> - inline bsl::string check_cast(unsigned long long value) - { - return bsl::string().appendf("%llu", value); - } - - template<> - inline bsl::string check_cast(float value) - { - return bsl::string().appendf("%g", value); - } - - template<> - inline bsl::string check_cast(double value) - { - return bsl::string().appendf("%lg", value); - } - - template<> - inline bsl::string check_cast(long double value) - { - return bsl::string().appendf("%Lg", value); - } - - template<> - inline bsl::string check_cast(char * value) - { - return value; - } - - template<> - inline bsl::string check_cast(const char * value) - { - return value; - } - - //from bsl::string - /* 可能会有效率问题 - template<> - inline char check_cast( bsl::string s ){ - return s[0]; - } - - template<> - inline long check_cast ( bsl::string s ){ - return check_cast(s.c_str()); - } - - //signed char is used as int8 - template<> - inline signed char check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - //unsigned char is used as uint8 - template<> - inline unsigned char check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline short check_cast ( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline int check_cast ( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline long long check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - - template<> - inline unsigned long check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline unsigned short check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline unsigned int check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline unsigned long long check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline float check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline double check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline long double check_cast( bsl::string s ){ - return check_cast( s.c_str() ); - } - - template<> - inline const char * check_cast( bsl::string s ){ - return s.c_str(); - } - */ -} - - -#endif //__CHECK_CAST_BSL_STRING_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/check_cast/check_cast_cstring.cpp b/bsl/check_cast/check_cast_cstring.cpp deleted file mode 100644 index 30c9d55b1ca7dc8c0fa1638d5a16dc215798ab25..0000000000000000000000000000000000000000 --- a/bsl/check_cast/check_cast_cstring.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: check_cast_cstring.cpp,v 1.3 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file check_cast_cstring.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/11/12 20:44:10 - * @version $Revision: 1.3 $ - * @brief - * - **/ - -#include -#include "bsl/check_cast.h" - -namespace bsl{ - template<> - long check_cast ( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - long long check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - unsigned long check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - unsigned long long check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - float check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - double check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - long double check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - inline char check_cast( const char * s ){ - if ( !s ){ - throw bsl::NullPointerException()< - long check_cast ( const char * s ); - - //signed char is used as int8 - template<> - inline signed char check_cast( const char * s ){ - return check_cast( check_cast( s ) ); - } - - //unsigned char is used as uint8 - template<> - inline unsigned char check_cast( const char * s ){ - return check_cast( check_cast( s ) ); - } - - template<> - inline short check_cast ( const char * s ){ - return check_cast( check_cast( s ) ); - } - - template<> - inline int check_cast ( const char * s ){ - return check_cast( check_cast( s ) ); - } - - - template<> - long long check_cast( const char * s ); - - template<> - unsigned long check_cast( const char * s ); - - template<> - inline unsigned short check_cast( const char * s ){ - return check_cast( check_cast( s ) ); - } - - template<> - inline unsigned int check_cast( const char * s ){ - return check_cast( check_cast( s ) ); - } - - - template<> - unsigned long long check_cast( const char * s ); - - template<> - float check_cast( const char * s ); - - template<> - double check_cast( const char * s ); - - - template<> - long double check_cast( const char * s ); - - - template<> - inline char check_cast( char *s ){ - if ( !s ){ - throw bsl::NullPointerException()< - inline long check_cast ( char * s ){ - return check_cast(s); - } - - template<> - inline short check_cast ( char * s ){ - return check_cast( check_cast( s ) ); - } - - //signed char is used as int8 - template<> - inline signed char check_cast( char * s ){ - return check_cast( check_cast( s ) ); - } - - //unsigned char is used as uint8 - template<> - inline unsigned char check_cast( char * s ){ - return check_cast( check_cast( s ) ); - } - - template<> - inline int check_cast ( char * s ){ - return check_cast( check_cast( s ) ); - } - - - template<> - inline long long check_cast( char *s ){ - return check_cast(s); - } - - template<> - inline unsigned long check_cast( char *s ){ - return check_cast(s); - } - - template<> - inline unsigned short check_cast( char *s ){ - return check_cast( check_cast( s ) ); - } - - template<> - inline unsigned int check_cast( char *s ){ - return check_cast( check_cast( s ) ); - } - - - template<> - inline unsigned long long check_cast( char *s ){ - return check_cast(s); - } - - template<> - inline float check_cast( char *s ){ - return check_cast(s); - } - - template<> - inline double check_cast( char *s ){ - return check_cast(s); - } - - template<> - inline long double check_cast( char *s ){ - return check_cast(s); - } - -} - -#endif //__CHECK_CAST_CSTRING_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/check_cast/check_cast_generated.h b/bsl/check_cast/check_cast_generated.h deleted file mode 100644 index 15f7e509b3af6c88822dec287d39de7d3113abd7..0000000000000000000000000000000000000000 --- a/bsl/check_cast/check_cast_generated.h +++ /dev/null @@ -1,4683 +0,0 @@ - -#ifndef __CHECK_CAST_GENERATED_H_ -#define __CHECK_CAST_GENERATED_H_ - -/* CAUTION: this file is generated by check_cast.py automatically, don't modify it */ -//internal use -#ifndef __CHECK_CAST_H_ -#error "this file cannot be included directly, please include " check_cast.h " instead" -#endif - -#include -#include -namespace bsl{ - -#if __WORDSIZE == 32 - - template<> - inline short check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( short value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( short value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( long double value ){ - - if ( value < -32768.0L ){ - throw bsl::UnderflowException()< 32767.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long double value ){ - - if ( value < -2147483648.0L ){ - throw bsl::UnderflowException()< 2147483647.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 255.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 18446744073709551615.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( long double value ){ - - if ( value < -2147483648.0L ){ - throw bsl::UnderflowException()< 2147483647.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( long double value ){ - - if ( value < -128.0L ){ - throw bsl::UnderflowException()< 127.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 65535.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 4294967295.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( long double value ){ - - if ( value < -9223372036854775808.0L ){ - throw bsl::UnderflowException()< 9223372036854775807.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( long double value ){ - - if ( value < -128.0L ){ - throw bsl::UnderflowException()< 127.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 4294967295.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( int value ){ - - if ( value < -32768 ){ - throw bsl::UnderflowException()< 32767 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( int value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 65535 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( int value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( double value ){ - - if ( value < -32768.0 ){ - throw bsl::UnderflowException()< 32767.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( double value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( double value ){ - #ifdef __arm__ - volatile uint64_t tmp = *(volatile uint64_t *)&value; - return *(double *)(&tmp); - #else - return static_cast(value); - #endif - } - - - template<> - inline unsigned char check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 255.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( double value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( double value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 65535.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( double value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( double value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( unsigned char value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline float check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned char value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( unsigned long long value ){ - - - if ( value > 32767ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned long long value ){ - - - if ( value > 2147483647ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned long long value ){ - - - if ( value > 255ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned long long value ){ - - - if ( value > 2147483647ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( unsigned long long value ){ - - - if ( value > 127ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned long long value ){ - - - if ( value > 65535ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned long long value ){ - - - if ( value > 4294967295ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( unsigned long long value ){ - - - if ( value > 9223372036854775807ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( unsigned long long value ){ - - - if ( value > 127ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned long long value ){ - - - if ( value > 4294967295ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( long value ){ - - if ( value < -32768L ){ - throw bsl::UnderflowException()< 32767L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()< 255L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( long value ){ - - if ( value < -128L ){ - throw bsl::UnderflowException()< 127L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()< 65535L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( long value ){ - - if ( value < -128L ){ - throw bsl::UnderflowException()< 127L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned short check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned int check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( unsigned short value ){ - - - if ( value > 32767 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned short value ){ - - - if ( value > 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( unsigned short value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline float check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned short value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( float value ){ - - if ( value < -32768.0 ){ - throw bsl::UnderflowException()< 32767.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( float value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 255.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( float value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( float value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 65535.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( float value ){ - #ifdef __arm__ - volatile uint32_t tmp = *(volatile uint32_t *)&value; - return *(float *)&tmp; - #else - return static_cast(value); - #endif - } - - - template<> - inline unsigned long check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( float value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( float value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( unsigned long value ){ - - - if ( value > 32767UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned long value ){ - - - if ( value > 2147483647UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned long value ){ - - - if ( value > 255UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned long value ){ - - - if ( value > 2147483647UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( unsigned long value ){ - - - if ( value > 127UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned long value ){ - - - if ( value > 65535UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned long value ){ - - - if ( value > 127UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( long long value ){ - - if ( value < -32768LL ){ - throw bsl::UnderflowException()< 32767LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long long value ){ - - if ( value < -2147483648LL ){ - throw bsl::UnderflowException()< 2147483647LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 255LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( long long value ){ - - if ( value < -2147483648LL ){ - throw bsl::UnderflowException()< 2147483647LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( long long value ){ - - if ( value < -128LL ){ - throw bsl::UnderflowException()< 127LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 65535LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 4294967295LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( long long value ){ - - if ( value < -128LL ){ - throw bsl::UnderflowException()< 127LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 4294967295LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned short check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned int check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( unsigned int value ){ - - - if ( value > 32767U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned int value ){ - - - if ( value > 2147483647U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned int value ){ - - - if ( value > 255U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned int value ){ - - - if ( value > 2147483647U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( unsigned int value ){ - - - if ( value > 127U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned int value ){ - - - if ( value > 65535U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned int value ){ - - - if ( value > 127U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned int value ){ - - - return static_cast(value); - } - -#else - - template<> - inline short check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( short value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( short value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( short value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( long double value ){ - - if ( value < -32768.0L ){ - throw bsl::UnderflowException()< 32767.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long double value ){ - - if ( value < -2147483648.0L ){ - throw bsl::UnderflowException()< 2147483647.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 255.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 18446744073709551615.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( long double value ){ - - if ( value < -9223372036854775808.0L ){ - throw bsl::UnderflowException()< 9223372036854775807.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( long double value ){ - - if ( value < -128.0L ){ - throw bsl::UnderflowException()< 127.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 65535.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 18446744073709551615.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( long double value ){ - - if ( value < -9223372036854775808.0L ){ - throw bsl::UnderflowException()< 9223372036854775807.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( long double value ){ - - if ( value < -128.0L ){ - throw bsl::UnderflowException()< 127.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long double value ){ - - if ( value < 0.0L ){ - throw bsl::UnderflowException()< 4294967295.0L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( int value ){ - - if ( value < -32768 ){ - throw bsl::UnderflowException()< 32767 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( int value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()< 65535 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( int value ){ - - if ( value < -128 ){ - throw bsl::UnderflowException()< 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( int value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( double value ){ - - if ( value < -32768.0 ){ - throw bsl::UnderflowException()< 32767.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( double value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 255.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( double value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( double value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 65535.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( double value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( double value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( double value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( unsigned char value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline float check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned char value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( unsigned long long value ){ - - - if ( value > 32767ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned long long value ){ - - - if ( value > 2147483647ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned long long value ){ - - - if ( value > 255ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned long long value ){ - - - if ( value > 9223372036854775807ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( unsigned long long value ){ - - - if ( value > 127ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned long long value ){ - - - if ( value > 65535ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned long long value ){ - - - if ( value > 9223372036854775807ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( unsigned long long value ){ - - - if ( value > 127ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned long long value ){ - - - if ( value > 4294967295ULL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( long value ){ - - if ( value < -32768L ){ - throw bsl::UnderflowException()< 32767L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long value ){ - - if ( value < -2147483648L ){ - throw bsl::UnderflowException()< 2147483647L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()< 255L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( long value ){ - - if ( value < -128L ){ - throw bsl::UnderflowException()< 127L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()< 65535L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( long value ){ - - if ( value < -128L ){ - throw bsl::UnderflowException()< 127L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long value ){ - - if ( value < 0L ){ - throw bsl::UnderflowException()< 4294967295L ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned short check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned int check_cast( char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( unsigned short value ){ - - - if ( value > 32767 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned short value ){ - - - if ( value > 255 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( unsigned short value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline float check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned short value ){ - - - if ( value > 127 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( float value ){ - - if ( value < -32768.0 ){ - throw bsl::UnderflowException()< 32767.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( float value ){ - - if ( value < -2147483648.0 ){ - throw bsl::UnderflowException()< 2147483647.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 255.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long check_cast( float value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( float value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 65535.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 18446744073709551615.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long long check_cast( float value ){ - - if ( value < -9223372036854775808.0 ){ - throw bsl::UnderflowException()< 9223372036854775807.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( float value ){ - - if ( value < -128.0 ){ - throw bsl::UnderflowException()< 127.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( float value ){ - - if ( value < 0.0 ){ - throw bsl::UnderflowException()< 4294967295.0 ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( unsigned long value ){ - - - if ( value > 32767UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned long value ){ - - - if ( value > 2147483647UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned long value ){ - - - if ( value > 255UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned long value ){ - - - if ( value > 9223372036854775807UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline char check_cast( unsigned long value ){ - - - if ( value > 127UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned long value ){ - - - if ( value > 65535UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned long value ){ - - - if ( value > 9223372036854775807UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline signed char check_cast( unsigned long value ){ - - - if ( value > 127UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned long value ){ - - - if ( value > 4294967295UL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( long long value ){ - - if ( value < -32768LL ){ - throw bsl::UnderflowException()< 32767LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( long long value ){ - - if ( value < -2147483648LL ){ - throw bsl::UnderflowException()< 2147483647LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 255LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( long long value ){ - - if ( value < -128LL ){ - throw bsl::UnderflowException()< 127LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 65535LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( long long value ){ - - if ( value < -128LL ){ - throw bsl::UnderflowException()< 127LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( long long value ){ - - if ( value < 0LL ){ - throw bsl::UnderflowException()< 4294967295LL ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline short check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned short check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline float check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline long long check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned int check_cast( signed char value ){ - - if ( value < 0 ){ - throw bsl::UnderflowException()<(value); - } - - - template<> - inline short check_cast( unsigned int value ){ - - - if ( value > 32767U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline long double check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( unsigned int value ){ - - - if ( value > 2147483647U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline double check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( unsigned int value ){ - - - if ( value > 255U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned long long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( unsigned int value ){ - - - if ( value > 127U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned short check_cast( unsigned int value ){ - - - if ( value > 65535U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline float check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( unsigned int value ){ - - - if ( value > 127U ){ - throw bsl::OverflowException()<(value); - } - - - template<> - inline unsigned int check_cast( unsigned int value ){ - - - return static_cast(value); - } - -#endif - - template<> - inline bool check_cast( short value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( long double value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( int value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( double value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( unsigned char value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( unsigned long long value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( long value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( char value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( unsigned short value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( float value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( unsigned long value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( long long value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( signed char value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( unsigned int value ){ - - - return static_cast(value); - } - - - template<> - inline short check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline long double check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline int check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline double check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned char check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long long check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline long check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline char check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned short check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline float check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned long check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline long long check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline signed char check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline unsigned int check_cast( bool value ){ - - - return static_cast(value); - } - - - template<> - inline bool check_cast( bool value ){ - - - return static_cast(value); - } - - -} // namespace bsl -#endif //__CHECK_CAST_GENERATED_H_ - diff --git a/bsl/containers/BCLOUD b/bsl/containers/BCLOUD deleted file mode 100644 index 73ef0961c912f098359fc7f6d9b44694bcbc3567..0000000000000000000000000000000000000000 --- a/bsl/containers/BCLOUD +++ /dev/null @@ -1,75 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -#CXXFLAGS(' -fsigned-char -Wall -W -g -O2 -pipe -fPIC -finline-functions') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -#INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libcontainers.a') -#LIBS('$OUT/so/libcontainers.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -#user_sources=GLOB("*.c *.cpp *.cc *.idl") - -#release headers -HEADERS('string/*.h', '$INC/bsl/containers/string') -HEADERS('slist/*.h', '$INC/bsl/containers/slist') -HEADERS('list/*.h', '$INC/bsl/containers/list') -HEADERS('hash/*.h', '$INC/bsl/containers/hash') -HEADERS('deque/*.h', '$INC/bsl/containers/deque') -HEADERS('btree/*.h', '$INC/bsl/containers/btree') -HEADERS('btree/asm-i386', '$INC/bsl/containers/btree') -HEADERS('btree/asm-x86_64', '$INC/bsl/containers/btree') -HEADERS('btree/gen_xmemcpy_h.py', '$INC/bsl/containers/btree') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('containers', Sources(user_sources)) - -#UT -#UTApplication('containers', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -#StaticLibrary('containers', Sources(user_sources)) -#StaticLibrary('containers', PreBuilt(True)) - -#.so -#SharedLibrary('containers', Sources(user_sources)) -#SharedLibrary('containers', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/containers/CMakeLists.txt b/bsl/containers/CMakeLists.txt deleted file mode 100644 index 0e77b65c3f0a57e1184a3e0b624b607712bd30b6..0000000000000000000000000000000000000000 --- a/bsl/containers/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_subdirectory(btree) -add_subdirectory(deque) -add_subdirectory(hash) -add_subdirectory(list) -add_subdirectory(slist) -add_subdirectory(string) -add_custom_target(containers) diff --git a/bsl/containers/Makefile b/bsl/containers/Makefile deleted file mode 100644 index b73c2c4c7b0ea980ccf4cf2ae87d95917f560ac3..0000000000000000000000000000000000000000 --- a/bsl/containers/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -########################################################################### -# Automatically generated by comake (1.0.0a) 2008-12-08 14:07 # -########################################################################### -all : - make -C ./deque - make -C ./hash - make -C ./list - make -C ./slist - make -C ./string - make -C ./btree -clean : - make clean -C ./deque - make clean -C ./hash - make clean -C ./list - make clean -C ./slist - make clean -C ./string - make clean -C ./btree diff --git a/bsl/containers/btree/CMakeLists.txt b/bsl/containers/btree/CMakeLists.txt deleted file mode 100644 index 220e10e28adc152fa9dbb37298cf2684aae71d92..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/asm-i386) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/asm-x86_64) diff --git a/bsl/containers/btree/Makefile b/bsl/containers/btree/Makefile deleted file mode 100644 index be443f3746e856b95e357c6b7e313c552af617f2..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -VERSION_ID=bsl_btree[by YangZhenKun][JustForX8664] -CXX=g++ - -INCPATH=-I. -I../../../ #-I$(HOME)/utils/valgrind-3.5.0/memcheck -I$(HOME)/utils/valgrind-3.5.0/include -LDPATH=-L. -LDFLAGS=-lpthread -CXXFLAGS =-fsigned-char -Wall -W -g -O2 -pipe -fPIC -finline-functions \ - -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -D_XOPEN_SOURE=500 \ - -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D__VERSION_ID__="\"$(VERSION_ID)\"" - -all:output -%.o:%.cpp - $(CXX) -o $@ -c $^ $(CXXFLAGS) $(INCPATH) -TARGETS=test_bsl_kv_btree test_bsl_kv_btree_string test_mt_bsl_kv_btree test_xmemcpy_correctness -app:$(TARGETS) -%:%.cpp - $(CXX) -o $@ $^ $(CXXFLAGS) $(INCPATH) $(LDPATH) $(LDFLAGS) -BSL=../../ -OUTINC=$(BSL)/output/include/bsl/containers/btree -output:$(LIBNAME) - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp -r asm-i386 $(OUTINC) - cp -r asm-x86_64 $(OUTINC) - cp *h $(OUTINC) - cp gen_xmemcpy_h.py $(OUTINC) -CLEANFILES=$(OBJS) $(TARGETS) -.PHONY: clean -clean: - rm -rf $(CLEANFILES) $(APPTARGETS) *~ -dist:clean - cd ../;tar czvf btree.tar.gz btree;cd btree diff --git a/bsl/containers/btree/README b/bsl/containers/btree/README deleted file mode 100644 index a7fb5893ff0ea70bd29dcd4b3542f5414625129c..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/README +++ /dev/null @@ -1,40 +0,0 @@ -这里需要说明一下.这个库仅仅封装了df_xz_btree,所以以前很多dpf-btree里面 -的文件都没有保留. -1.bsl_kv_btree_adapter是对xz_btree的封装.我想统一一下最底层的btree调用 -接口. - -2.bsl_kv_btree_archive_traits是对xz_btree的K,V的序列化封装.因为btree仅 -仅有一个序列化到内存的接口,很难和bsl融合. - -3.bsl_kv_btree_data_unit是xz_btree的K,V封装.因为btree内部需要K,V之间能 -够相互比较,这就决定了V必须包含K - -4.bsl_kv_btree_iterator是xz_btree的iterator结构.里面有 -build_iterator_base和search_iterator_base表示对于build/search btree来 -说,iterator希望看到的接口.. - -5.bsl_kv_btree就是应该最终使用的文件..:). - -其他以df开头的都是原来dpf-btree里面的内容,这里简要说说 -1.df_2d_ary.h是btree底层的内存分配形式,使用二维数组来存储 -2.df_atomic.h/df_bitops.h是原子操作的包装,可以查看asm-x86/asm-i386都有 -对应的df_bitops.h实现 -3.df_btree.h是btree的底层实现,包装各种引用计数操作和BTREE的增删查改 -4.df_def.h是各种类型的定义 -5.df_log.h是打印日志.因为btree内部使用了很多内部日志,而且使用了ullog. -为了能够不依赖ullib,所以这里全部替换为哑宏 -6.df_misc.h这里面最主要的部分是锁的存在. -7.df_xz_btree.h是btree的xz版.:).. - -然后有两个测试用例分别表示KV为uint64和std::string这种流式类型.事实证明 -btree对于这种类型都可以操作和存储.:).[当然还支持bsl::string,现在的 -bsl::string是完全采用copy的方式来完成的,所以没有任何问题]. - -NOTE -1.这个更新似乎有点快,设计文档没有及时更新上.TODO -2.BTREE的性能似乎可以再上一个台阶..TODO. -a.memset -> bzero 约快3% -b.memcpy -> bsl_kv_btree_xmemcpy 没有用xiaowei的xmemcpy的原因是需要链 -接一个库.[没必要,而且放在头文件实现高效很多]越快1倍左右. -c.热点部分的inline.[使用oprofile annotate找到]. -d.减小BT_FANOUT是否有效....???;[20100806到此为止吧]. diff --git a/bsl/containers/btree/asm-i386/df_bitops.h b/bsl/containers/btree/asm-i386/df_bitops.h deleted file mode 100644 index 870e8a9085880e7eec67359222ce011a168fdb88..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/asm-i386/df_bitops.h +++ /dev/null @@ -1,326 +0,0 @@ -#ifndef _I386_BITOPS_H -#define _I386_BITOPS_H - -/* - * Copyright 1992, Linus Torvalds. - */ - -/* - * These have to be done with inline assembly: that way the bit-setting - * is guaranteed to be atomic. All bit operations return 0 if the bit - * was cleared before the operation and != 0 if it was not. - * - * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). - */ - -#define ADDR (*(volatile long *) addr) - -/** - * set_bit - Atomically set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * This function is atomic and may not be reordered. See __set_bit() - * if you do not require the atomic guarantees. - * Note that @nr may be almost arbitrarily large; this function is not - * restricted to acting on a single-word quantity. - */ -static __inline__ void set_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btsl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * __set_bit - Set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * Unlike set_bit(), this function is non-atomic and may be reordered. - * If it's called on the same region of memory simultaneously, the effect - * may be that only one operation succeeds. - */ -static __inline__ void __set_bit(int nr, volatile void * addr) -{ - __asm__( - "btsl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * clear_bit - Clears a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * clear_bit() is atomic and may not be reordered. However, it does - * not contain a memory barrier, so if it is used for locking purposes, - * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() - * in order to ensure changes are visible on other processors. - */ -static __inline__ void clear_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btrl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} -#define smp_mb__before_clear_bit() barrier() -#define smp_mb__after_clear_bit() barrier() - -/** - * __change_bit - Toggle a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * Unlike change_bit(), this function is non-atomic and may be reordered. - * If it's called on the same region of memory simultaneously, the effect - * may be that only one operation succeeds. - */ -static __inline__ void __change_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btcl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * change_bit - Toggle a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * change_bit() is atomic and may not be reordered. - * Note that @nr may be almost arbitrarily large; this function is not - * restricted to acting on a single-word quantity. - */ -static __inline__ void change_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btcl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * test_and_set_bit - Set a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_set_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btsl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr) : "memory"); - return oldbit; -} - -/** - * __test_and_set_bit - Set a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is non-atomic and can be reordered. - * If two examples of this operation race, one can appear to succeed - * but actually fail. You must protect multiple accesses with a lock. - */ -static __inline__ int __test_and_set_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__( - "btsl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr)); - return oldbit; -} - -/** - * test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr) : "memory"); - return oldbit; -} - -/** - * __test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is non-atomic and can be reordered. - * If two examples of this operation race, one can appear to succeed - * but actually fail. You must protect multiple accesses with a lock. - */ -static __inline__ int __test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__( - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr)); - return oldbit; -} - -/* WARNING: non atomic and it can be reordered! */ -static __inline__ int __test_and_change_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btcl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr) : "memory"); - return oldbit; -} - -/** - * test_and_change_bit - Change a bit and return its new value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_change_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btcl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr) : "memory"); - return oldbit; -} - -#if 0 /* Fool kernel-doc since it doesn't do macros yet */ -/** - * test_bit - Determine whether a bit is set - * @nr: bit number to test - * @addr: Address to start counting from - */ -static int test_bit(int nr, const volatile void * addr); -#endif - -static __inline__ int constant_test_bit(int nr, const volatile void * addr) -{ - return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0; -} - -static __inline__ int variable_test_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit) - :"m" (ADDR),"Ir" (nr)); - return oldbit; -} - -#define test_bit(nr,addr) \ -(__builtin_constant_p(nr) ? \ - constant_test_bit((nr),(addr)) : \ - variable_test_bit((nr),(addr))) - -/** - * find_first_zero_bit - find the first zero bit in a memory region - * @addr: The address to start the search at - * @size: The maximum size to search - * - * Returns the bit-number of the first zero bit, not the number of the byte - * containing a bit. - */ -static __inline__ int find_first_zero_bit(void * addr, unsigned size) -{ - int d0, d1, d2; - int res; - - if (!size) - return 0; - /* This looks at memory. Mark it volatile to tell gcc not to move it around */ - __asm__ __volatile__( - "movl $-1,%%eax\n\t" - "xorl %%edx,%%edx\n\t" - "repe; scasl\n\t" - "je 1f\n\t" - "xorl -4(%%edi),%%eax\n\t" - "subl $4,%%edi\n\t" - "bsfl %%eax,%%edx\n" - "1:\tsubl %%ebx,%%edi\n\t" - "shll $3,%%edi\n\t" - "addl %%edi,%%edx" - :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2) - :"1" ((size + 31) >> 5), "2" (addr), "b" (addr)); - return res; -} - -/** - * find_next_zero_bit - find the first zero bit in a memory region - * @addr: The address to base the search on - * @offset: The bitnumber to start searching at - * @size: The maximum size to search - */ -static __inline__ int find_next_zero_bit (void * addr, int size, int offset) -{ - unsigned long * p = ((unsigned long *) addr) + (offset >> 5); - int set = 0, bit = offset & 31, res; - - if (bit) { - /* - * Look for zero in first byte - */ - __asm__("bsfl %1,%0\n\t" - "jne 1f\n\t" - "movl $32, %0\n" - "1:" - : "=r" (set) - : "r" (~(*p >> bit))); - if (set < (32 - bit)) - return set + offset; - set = 32 - bit; - p++; - } - /* - * No zero yet, search remaining full bytes for a zero - */ - res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr)); - return (offset + set + res); -} - -/** - * ffz - find first zero in word. - * @word: The word to search - * - * Undefined if no zero exists, so code should check against ~0UL first. - */ -static __inline__ unsigned long ffz(unsigned long word) -{ - __asm__("bsfl %1,%0" - :"=r" (word) - :"r" (~word)); - return word; -} - -#endif /* _I386_BITOPS_H */ - diff --git a/bsl/containers/btree/asm-x86_64/df_bitops.h b/bsl/containers/btree/asm-x86_64/df_bitops.h deleted file mode 100644 index 0bb991ce393d598fc2274c594191f1ef037a9cf6..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/asm-x86_64/df_bitops.h +++ /dev/null @@ -1,415 +0,0 @@ -#ifndef _X86_64_BITOPS_H -#define _X86_64_BITOPS_H - -/* - * Copyright 1992, Linus Torvalds. - */ - -/* - * These have to be done with inline assembly: that way the bit-setting - * is guaranteed to be atomic. All bit operations return 0 if the bit - * was cleared before the operation and != 0 if it was not. - * - * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). - */ - -#ifdef CONFIG_SMP -#define LOCK_PREFIX "lock ; " -#else -#define LOCK_PREFIX "" -#endif - -#define ADDR (*(volatile long *) addr) - -/** - * set_bit - Atomically set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * This function is atomic and may not be reordered. See __set_bit() - * if you do not require the atomic guarantees. - */ -static __inline__ void set_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( LOCK_PREFIX - "btsl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -/** - * __set_bit - Set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * Unlike set_bit(), this function is non-atomic and may be reordered. - * If it's called on the same region of memory simultaneously, the effect - * may be that only one operation succeeds. - */ -static __inline__ void __set_bit(int nr, volatile void * addr) -{ - __asm__( - "btsl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -/** - * clear_bit - Clears a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * clear_bit() is atomic and may not be reordered. However, it does - * not contain a memory barrier, so if it is used for locking purposes, - * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() - * in order to ensure changes are visible on other processors. - */ -static __inline__ void clear_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( LOCK_PREFIX - "btrl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -static __inline__ void __clear_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btrl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} -#define smp_mb__before_clear_bit() barrier() -#define smp_mb__after_clear_bit() barrier() - -/** - * __change_bit - Toggle a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * Unlike change_bit(), this function is non-atomic and may be reordered. - * If it's called on the same region of memory simultaneously, the effect - * may be that only one operation succeeds. - */ -static __inline__ void __change_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( - "btcl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -/** - * change_bit - Toggle a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * change_bit() is atomic and may not be reordered. - * Note that @nr may be almost arbitrarily large; this function is not - * restricted to acting on a single-word quantity. - */ -static __inline__ void change_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( LOCK_PREFIX - "btcl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -/** - * test_and_set_bit - Set a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_set_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( LOCK_PREFIX - "btsl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr) : "memory"); - return oldbit; -} - -/** - * __test_and_set_bit - Set a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is non-atomic and can be reordered. - * If two examples of this operation race, one can appear to succeed - * but actually fail. You must protect multiple accesses with a lock. - */ -static __inline__ int __test_and_set_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__( - "btsl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr)); - return oldbit; -} - -/** - * test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( LOCK_PREFIX - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr) : "memory"); - return oldbit; -} - -/** - * __test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is non-atomic and can be reordered. - * If two examples of this operation race, one can appear to succeed - * but actually fail. You must protect multiple accesses with a lock. - */ -static __inline__ int __test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__( - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr)); - return oldbit; -} - -/* WARNING: non atomic and it can be reordered! */ -static __inline__ int __test_and_change_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btcl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr) : "memory"); - return oldbit; -} - -/** - * test_and_change_bit - Change a bit and return its new value - * @nr: Bit to set - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_change_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( LOCK_PREFIX - "btcl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr) : "memory"); - return oldbit; -} - -#if 0 /* Fool kernel-doc since it doesn't do macros yet */ -/** - * test_bit - Determine whether a bit is set - * @nr: bit number to test - * @addr: Address to start counting from - */ -static int test_bit(int nr, const volatile void * addr); -#endif - -static __inline__ int constant_test_bit(int nr, const volatile void * addr) -{ - return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0; -} - -static __inline__ int variable_test_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit) - :"m" (ADDR),"dIr" (nr)); - return oldbit; -} - -#define test_bit(nr,addr) \ -(__builtin_constant_p(nr) ? \ - constant_test_bit((nr),(addr)) : \ - variable_test_bit((nr),(addr))) - -/** - * find_first_zero_bit - find the first zero bit in a memory region - * @addr: The address to start the search at - * @size: The maximum size to search - * - * Returns the bit-number of the first zero bit, not the number of the byte - * containing a bit. - */ -static __inline__ int find_first_zero_bit(void * addr, unsigned size) -{ - int d0, d1, d2; - int res; - - if (!size) - return 0; - __asm__ __volatile__( - "movl $-1,%%eax\n\t" - "xorq %%rdx,%%rdx\n\t" - "repe; scasl\n\t" - "je 1f\n\t" - "xorl -4(%%rdi),%%eax\n\t" - "subq $4,%%rdi\n\t" - "bsfl %%eax,%%edx\n" - "1:\tsubq %%rbx,%%rdi\n\t" - "shlq $3,%%rdi\n\t" - "addq %%rdi,%%rdx" - :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2) - :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory"); - return res; -} - -/** - * find_first_bit - find the first set bit in a memory region - * @addr: The address to start the search at - * @size: The maximum size to search - * - * Returns the bit-number of the first set bit, not the number of the byte - * containing a bit. - */ -static __inline__ int find_first_bit(void * addr, unsigned size) -{ - int d0, d1; - int res; - - /* This looks at memory. Mark it volatile to tell gcc not to move it around */ - /* Work in 32bit for now */ - __asm__ __volatile__( - "xorl %%eax,%%eax\n\t" - "repe; scasl\n\t" - "jz 1f\n\t" - "leaq -4(%%rdi),%%rdi\n\t" - "bsfl (%%rdi),%%eax\n" - "1:\tsubq %%rbx,%%rdi\n\t" - "shlq $3,%%rdi\n\t" - "addq %%rdi,%%rax" - :"=a" (res), "=&c" (d0), "=&D" (d1) - :"1" ((size + 31) >> 5), "2" (addr), "b" (addr)); - return res; -} - -/** - * find_next_zero_bit - find the first zero bit in a memory region - * @addr: The address to base the search on - * @offset: The bitnumber to start searching at - * @size: The maximum size to search - */ -static __inline__ int find_next_zero_bit (void * addr, int size, int offset) -{ - unsigned int * p = ((unsigned int *) addr) + (offset >> 5); - int set = 0, bit = offset & 31, res; - - if (bit) { - /* - * Look for zero in the first 32 bits. - */ - __asm__("bsfl %1,%0\n\t" - "jne 1f\n\t" - "movl $32, %0\n" - "1:" - : "=r" (set) - : "r" (~(*p >> bit))); - if (set < (32 - bit)) - return set + offset; - set = 32 - bit; - p++; - } - /* - * No zero yet, search remaining full bytes for a zero - */ - res = find_first_zero_bit (p, size - 32 * (p - (unsigned int *) addr)); - return (offset + set + res); -} - -/** - * find_next_bit - find the first set bit in a memory region - * @addr: The address to base the search on - * @offset: The bitnumber to start searching at - * @size: The maximum size to search - */ -static __inline__ int find_next_bit (void * addr, int size, int offset) -{ - unsigned long * p = ((unsigned long *) addr) + (offset >> 5); - unsigned long set = 0, bit = offset & 63, res; - - if (bit) { - /* - * Look for nonzero in the first 64 bits: - */ - __asm__("bsfq %1,%0\n\t" - "jne 1f\n\t" - "movq $64, %0\n" - "1:" - : "=r" (set) - : "r" (*p >> bit)); - if (set < (64 - bit)) - return set + offset; - set = 64 - bit; - p++; - } - /* - * No set bit yet, search remaining full words for a bit - */ - res = find_first_bit (p, size - 64 * (p - (unsigned long *) addr)); - return (offset + set + res); -} - -/** - * ffz - find first zero in word. - * @word: The word to search - * - * Undefined if no zero exists, so code should check against ~0UL first. - */ -static __inline__ unsigned long ffz(unsigned long word) -{ - __asm__("bsfq %1,%0" - :"=r" (word) - :"r" (~word)); - return word; -} - -/** - * __ffs - find first bit in word. - * @word: The word to search - * - * Undefined if no bit exists, so code should check against 0 first. - */ -static __inline__ unsigned long __ffs(unsigned long word) -{ - __asm__("bsfq %1,%0" - :"=r" (word) - :"rm" (word)); - return word; -} - -#undef LOCK_PREFIX - -#endif /* _X86_64_BITOPS_H */ - diff --git a/bsl/containers/btree/bsl_kv_btree.h b/bsl/containers/btree/bsl_kv_btree.h deleted file mode 100644 index d00c07de2708bb066bf9cf3b6979418e6e0a9b63..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree.h +++ /dev/null @@ -1,488 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ -#ifndef _BSL_KV_BTREE_H_ -#define _BSL_KV_BTREE_H_ - -#if defined __x86_64 - -#define BSL_BTREE_WORKS -//只有在64位下面才能够运行... - -#include -#include "bsl/utils/bsl_construct.h" -//为bsl::string定制了特定的archive特化版本. -#include "bsl/string.h" -#include "df_xz_btree.h" -#include - -namespace bsl { -//BTREE错误返回值 -enum { - BTREE_UNKNOWN_ERROR=-1, - BTREE_OK=0, - //这个地方设置成为这样的原因 - //是为了和bsl::hashmap的值相同. - BTREE_EXIST=0xffff, - BTREE_NOEXIST, - BTREE_OVERWRITE, - BTREE_INSERT_SUC, -}; - -//forward declaration. -template -class _bsl_kv_btree_build; - -template -class _bsl_kv_btree_search; - -//archive traits for bsl kv btree. -//序列化的接口..如何进行类型的序列化和反序列化.. -#include "bsl_kv_btree_archive_traits.h" - -//kv btree data unit. -//数据单元 -#include "bsl_kv_btree_data_unit.h" - -//kv btree adapter -//现在仅仅提供了xz adapter -#include "bsl_kv_btree_adapter.h" - -//kv btree iterator -#include "bsl_kv_btree_iterator.h" - -template -class _bsl_kv_btree_build:public _bsl_kv_btree_build_iterator_base { -public: - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef _bsl_kv_btree_build_iterator iterator; - typedef _bsl_kv_btree_build_iterator const_iterator; - typedef _bsl_kv_btree_build_reverse_iterator reverse_iterator; - typedef _bsl_kv_btree_build_reverse_iterator const_reverse_iterator; - typedef BTreeAdapter btree_type; - typedef _bsl_kv_btree_search kv_btree_search_type; - -private: - //持有的数据对象 - btree_type _btree; - //end of iterator... - iterator _end_iter; - const_iterator _cst_end_iter; - reverse_iterator _rend_iter; - const_reverse_iterator _cst_rend_iter; - -public: - _bsl_kv_btree_build() { - _end_iter._end=true; - _cst_end_iter._end=true; - _rend_iter._end=true; - _cst_rend_iter._end=true; - } - bool get_smallest(DU &du)const { - return _btree.unify_get_smallest(du); - } - bool get_largest(DU &du)const { - return _btree.unify_get_largest(du); - } - bool get_smaller(const DU &pdu,DU &du)const { - return _btree.unify_get_smaller(pdu,du); - } - bool get_larger(const DU &pdu,DU &du)const { - return _btree.unify_get_larger(pdu,du); - } - //insert (key,value) into btree - //flag==0 如果值存在的话直接返回,否则就直接插入 - //flag!=0 如果值存在的话那么就会进行替换,否则就直接插入 - //返回值 - //-1表示内部错误.... - //BTREE_OVERWRITE 表示覆盖旧节点成功[flag!=0] - //BTREE_INSERT_SUC 表示插入新节点成功 - //BTREE_EXIST 表示节点存在[flag=0] - int set(const key_type &k,const value_type &v,int flag=0) { - DU du(k,v); - if(flag==0) { - int ret=_btree.unify_insert(k,du); - if(ret==0) { - return BTREE_EXIST; - } else if(ret==1) { - return BTREE_INSERT_SUC; - } - return BTREE_UNKNOWN_ERROR; - } - int ret=_btree.unify_insert_update(k,du); - if(ret==0) { - return BTREE_OVERWRITE; - } else if(ret==1) { - return BTREE_INSERT_SUC; - } - return BTREE_UNKNOWN_ERROR; - } - //BTREE_EXIST 项存在 - //BTREE_NOEXIST 项不存在.. - int get(const key_type &k,value_type *val=0) { - if(_btree.unify_get_batch_mutate_mode()) { - return BTREE_UNKNOWN_ERROR; - } - DU du; - bool ok=_btree.unify_search(k,&du); - if(ok) { - if(val) { - //做一个copy.. - bsl_construct(val,du._value); - } - return BTREE_EXIST; - } - return BTREE_NOEXIST; - } - int get(const key_type &k,value_type *val=0)const { - if(_btree.unify_get_batch_mutate_mode()) { - return BTREE_UNKNOWN_ERROR; - } - DU du; - bool ok=_btree.unify_search(k,&du); - if(ok) { - if(val) { - //做一个copy... - bsl_construct(val,du._value); - } - return BTREE_EXIST; - } - return BTREE_NOEXIST; - } - //支持从某个KV开始构建iterator. - //带有参数的begin就是从某个点开始进行构建iterator的方法. - iterator begin() { - DU du; - bool ok=get_smallest(du); - return iterator(this,du,!ok); - } - iterator begin(const key_type &k,const value_type &v) { - DU du(k,v); - return iterator(this,du,false); - } - const_iterator begin()const { - DU du; - bool ok=get_smallest(du); - return const_iterator(this,du,!ok); - } - const_iterator begin(const key_type &k,const value_type &v) const { - DU du(k,v); - return const_iterator(this,du,false); - } - reverse_iterator rbegin() { - DU du; - bool ok=get_largest(du); - return reverse_iterator(this,du,!ok); - } - reverse_iterator rbegin(const key_type &k,const value_type &v) { - DU du(k,v); - return reverse_iterator(this,du,false); - } - const_reverse_iterator rbegin()const { - DU du; - bool ok=get_largest(du); - return const_reverse_iterator(this,du,!ok); - } - const_reverse_iterator rbegin(const key_type &k,const value_type &v)const { - DU du(k,v); - return const_reverse_iterator(this,du,false); - } - const iterator &end() { - return _end_iter; - } - const const_iterator &end()const { - return _cst_end_iter; - } - const reverse_iterator &rend() { - return _rend_iter; - } - const const_reverse_iterator &rend()const { - return _cst_rend_iter; - } - //返回有多少个key. - size_t size() const { - uint64_t key=0,leaf=0,mid=0; - _btree.unify_get_total_num(key,leaf,mid); - return key; - } - //删除某个元素... - //BTREE_EXIST 如果key存在 - //BTREE_NOEXIST 如果key不存在. - int erase(const key_type &k) { - bool ok=_btree.unify_del(k); - if(ok) { - return BTREE_EXIST; - } - return BTREE_NOEXIST; - } - //清除,始终返回0. - int clear() { - int ret=_btree.unify_clear(); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - //创建checkpoint - //其实没有太多用途,因为你已经有了snapshot. - //0成功,-1失败... - int make_checkpoint() { - int ret=_btree.unify_set_checkpoint_state(false); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int end_checkpoint() { - int ret=_btree.unify_set_checkpoint_state(true); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int snapshot(kv_btree_search_type & search) { - int ret=_btree.unify_snapshot(search._rc_indexer); - search._btree=&_btree; - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int store(int fd,long long offset) { - dfs_file_rw_info_t info; - info.fd=fd; - info.orig_offset=offset; - info.reserved=0;//nothing. - int ret=_btree.unify_store_checkpoint(dfs_write_proc,&info); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int load(int fd,long long offset) { - dfs_file_rw_info_t info; - info.fd=fd; - info.orig_offset=offset; - int ret=_btree.unify_load_checkpoint(dfs_read_proc,&info); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int make_batch_mutate() { - int ret=_btree.unify_set_batch_mutate_mode(true); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - int end_batch_mutate() { - int ret=_btree.unify_set_batch_mutate_mode(false); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } - //添加下面这两个接口仅仅是为了bsl使用习惯配合. - //创建肯定成功. - int create() { - return 0; - } - //销毁的话只是清空.不做任何处理. - int destroy() { - int ret=_btree.unify_clear(); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } -}; - -template -class _bsl_kv_btree_search:public _bsl_kv_btree_search_iterator_base { -public: - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef _bsl_kv_btree_search_iterator iterator; - typedef _bsl_kv_btree_search_iterator const_iterator; - typedef _bsl_kv_btree_search_reverse_iterator reverse_iterator; - typedef _bsl_kv_btree_search_reverse_iterator const_reverse_iterator; - typedef _bsl_kv_btree_build kv_btree_build_type; - typedef BTreeAdapter btree_type; - -private: - friend class _bsl_kv_btree_build; - //持有的数据对象... - btree_type *_btree; - //rc indexer. - dfs_rc_indexer_t _rc_indexer; - //end iterator.. - iterator _end_iter; - const_iterator _cst_end_iter; - reverse_iterator _rend_iter; - const_reverse_iterator _cst_rend_iter; - -public: - _bsl_kv_btree_search() { - _end_iter._end=true; - _cst_end_iter._end=true; - _rend_iter._end=true; - _cst_rend_iter._end=true; - } - bool get_smallest(DU **du)const { - return _btree->unify_get_smallest(du,&_rc_indexer); - } - bool get_largest(DU **du)const { - return _btree->unify_get_largest(du,&_rc_indexer); - } - bool get_smaller(const DU &pdu,DU **du,dfs_btree_drill_t *pdrill_info)const { - return _btree->unify_get_smaller(pdu,du,pdrill_info,&_rc_indexer); - } - bool get_larger(const DU &pdu,DU **du,dfs_btree_drill_t *pdrill_info)const { - return _btree->unify_get_larger(pdu,du,pdrill_info,&_rc_indexer); - } - void let_it_go() { - //释放回收节点.. - _rc_indexer.init(); - } - ~_bsl_kv_btree_search() { - let_it_go(); - } - //BTREE_EXIST 项存在 - //BTREE_NOEXIST 项不存在.. - int get(const key_type &k,value_type *val=0) { - DU du; - bool ok=_btree->unify_search(k,&du,&_rc_indexer); - if(ok) { - if(val) { - bsl_construct(val,du._value); - } - return BTREE_EXIST; - } - return BTREE_NOEXIST; - } - int get(const key_type &k,value_type *val=0)const { - DU du; - bool ok=_btree->unify_search(k,&du,&_rc_indexer); - if(ok) { - if(val) { - bsl_construct(val,du._value); - } - return BTREE_EXIST; - } - return BTREE_NOEXIST; - } - iterator begin() { - DU *du; - bool ok=get_smallest(&du); - return iterator(this,du,!ok); - } - const_iterator begin()const { - DU *du; - bool ok=get_smallest(&du); - return const_iterator(this,du,!ok); - } - reverse_iterator rbegin() { - DU *du; - bool ok=get_largest(&du); - return reverse_iterator(this,du,!ok); - } - const_reverse_iterator rbegin()const { - DU *du; - bool ok=get_largest(&du); - return const_reverse_iterator(this,du,!ok); - } - const iterator &end() { - return _end_iter; - } - const const_iterator &end()const { - return _cst_end_iter; - } - const reverse_iterator &rend() { - return _rend_iter; - } - const const_reverse_iterator &rend()const { - return _cst_rend_iter; - } - //返回有多少个key. - size_t size() const { - uint64_t key=0,leaf=0,mid=0; - _btree->unify_get_total_num(key,leaf,mid,&_rc_indexer); - return key; - } - int store(int fd,unsigned long long offset) { - dfs_file_rw_info_t info; - info.fd=fd; - info.orig_offset=offset; - int ret=_btree->unify_store_checkpoint(dfs_write_proc,&info,&_rc_indexer); - if(ret==0) { - return BTREE_OK; - } - return BTREE_UNKNOWN_ERROR; - } -}; - -template, - typename VARCHIVE=_btree_archive_traits, - typename LT=std::less, - typename EQ=std::equal_to > -class bsl_kv_btree_search: - public _bsl_kv_btree_search< //data unit.. - _bsl_kv_btree_du, - ROW_SIZE, - //adapter... - _bsl_kv_btree_xz_adapter <_bsl_kv_btree_du,ROW_SIZE > > { -}; -template, - typename VARCHIVE=_btree_archive_traits, - typename LT=std::less, - typename EQ=std::equal_to > -class bsl_kv_btree_build: - public _bsl_kv_btree_build, - ROW_SIZE , - //adapter.. - _bsl_kv_btree_xz_adapter <_bsl_kv_btree_du,ROW_SIZE > > { -}; -} -#else -#undef BSL_BTREE_WORKS -#endif - -#endif diff --git a/bsl/containers/btree/bsl_kv_btree_adapter.h b/bsl/containers/btree/bsl_kv_btree_adapter.h deleted file mode 100644 index 8581bb05699bc6f668e9b1edf1e4e011e3a5c804..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree_adapter.h +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ -#ifndef _BSL_KV_BTREE_ADAPTER_H_ -#define _BSL_KV_BTREE_ADAPTER_H_ - -//如果需要依赖头文件,那么在bsl_kv_btree.h里面添加.. -//xz_btree_adapter.. -//内部的操作都叫做unify_xxxx.. -template -class _bsl_kv_btree_xz_adapter { -public: - typedef typename DU::key_type K; - -private: - //这个真正持有一个对象... - dfs_xz_btree_t_btree; - -public: - //这个遍历接口是为了build btree准备的.. - bool unify_get_smallest(DU &du, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - return _btree.get_smallest(du,prc_indexer); - } - bool unify_get_largest(DU &du, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - return _btree.get_largest(du,prc_indexer); - } - bool unify_get_smaller(const DU &pdu,DU &du, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - //使用key而不用data unit来查询. - return _btree.get_smaller(pdu,du,NULL,prc_indexer); - } - bool unify_get_larger(const DU &pdu,DU &du, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - //使用key而不用data unit来查询. - return _btree.get_larger(pdu,du,NULL,prc_indexer); - } - - //这个是为了search btree设计的.. - //search btree可以只掌握指针.. - //而build btree却需要掌握值. - bool unify_get_smallest(DU **du, - const dfs_rc_indexer_t *prc_indexer)const { - return _btree.zy_get_smallest_p(du,prc_indexer); - } - bool unify_get_largest(DU **du, - const dfs_rc_indexer_t *prc_indexer)const { - return _btree.zy_get_largest_p(du,prc_indexer); - } - //可以使用桶保存信息来加快查询... - bool unify_get_smaller(const DU &p,DU **du, - dfs_btree_drill_t *pdrill_info, - const dfs_rc_indexer_t *prc_indexer)const { - //使用data unit来进行查询.. - return _btree.zy_get_smaller_p(p,du,pdrill_info,prc_indexer); - } - bool unify_get_larger(const DU &p,DU **du, - dfs_btree_drill_t *pdrill_info, - const dfs_rc_indexer_t *prc_indexer)const { - //使用data unit来进行查询.. - return _btree.zy_get_larger_p(p,du,pdrill_info,prc_indexer); - } - - //其他接口... - int unify_insert(const K &/*k*/, - const DU &du) { - return _btree.zy_insert(du); - } - int unify_insert_update(const K &/*k*/, - const DU &du) { - return _btree.zy_insert_update(du); - } - bool unify_search(const K &k,DU *du, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - return _btree.zy_search(k,*du,prc_indexer); - } - int unify_get_total_num(uint64_t &key,uint64_t &leaf,uint64_t &mid, - const dfs_rc_indexer_t *prc_indexer=NULL)const { - //这里需要走两套逻辑,但是前端接口都是一样的... - if(prc_indexer==NULL) { - return _btree.get_total_num(key,leaf,mid); - } else { - return _btree.zy_get_total_num(prc_indexer,key,leaf,mid); - } - } - bool unify_del(const K &k) { - return _btree.del(k,NULL); - } - int unify_set_checkpoint_state(bool is_cancel) { - return _btree.set_checkpoint_state(is_cancel,0); - } - int unify_snapshot(dfs_rc_indexer_t &rc_indexer) { - return _btree.snapshot(rc_indexer); - } - int unify_store_checkpoint(const dfs_write_proc_t write_proc, - void * file_info, - const dfs_rc_indexer_t *prc_indexer=NULL) { - return _btree.store_checkpointing(write_proc,file_info,NULL,prc_indexer); - } - int unify_load_checkpoint(const dfs_read_proc_t read_proc, - void * file_info) { - return _btree.load_checkpointing(read_proc,file_info,NULL); - } - int unify_clear() { - return _btree.clear(); - } - int unify_set_batch_mutate_mode(bool batch_mode) { - return _btree.set_batch_mutate_mode(batch_mode); - } - bool unify_get_batch_mutate_mode()const { - return _btree.get_batch_mutate_mode(); - } -}; - -#endif diff --git a/bsl/containers/btree/bsl_kv_btree_archive_traits.h b/bsl/containers/btree/bsl_kv_btree_archive_traits.h deleted file mode 100644 index 5a811765c55b8aaa91418598e60eea8ab0157c65..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree_archive_traits.h +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ -#ifndef _BSL_KV_BTREE_ARCHIVE_TRAITS_H_ -#define _BSL_KV_BTREE_ARCHIVE_TRAITS_H_ - -//如果依赖头文件,那么直接在bsl_kv_btree.h里面填写. -//btree的archive接口...汗... -template -class _btree_archive_traits { - T *_ptr; - -public: - _btree_archive_traits(T *ptr):_ptr(ptr) { - } - _btree_archive_traits():_ptr(NULL) { - } - uint64_t size()const { - return (uint64_t)sizeof(T); - } - int serialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos)const { - int err=BTREE_OK; - if(_ptr && buf_size>data_pos && - (buf_size-data_pos)>=(uint64_t)size()) { - T *tmp=(T*)(buf+data_pos); - *tmp=*_ptr; - data_pos+=(uint64_t)size(); - } else { - err=BTREE_UNKNOWN_ERROR; - } - return err; - } - int deserialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos) { - int err=BTREE_OK; - if(_ptr && buf_size > data_pos && - (buf_size - data_pos)>=(uint64_t)size()) { - T *tmp=(T*)(buf+data_pos); - *_ptr=*tmp; - data_pos+=(uint64_t)size(); - } else { - err=BTREE_UNKNOWN_ERROR; - } - return err; - } -}; - -//为std::string定制的特化版本.. -template<> -class _btree_archive_traits { - std::string *_ptr; - -public: - _btree_archive_traits(std::string *ptr):_ptr(ptr) { - } - _btree_archive_traits():_ptr(NULL) { - } - uint64_t size()const { - if(!_ptr) { - return UNDEF_ID; - } - size_t siz=_ptr->size(); - return (uint64_t)sizeof(siz)+ - (uint64_t)siz; - } - int serialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos)const { - if(!_ptr) { - return BTREE_UNKNOWN_ERROR; - } - size_t siz=_ptr->size(); - //首先序列化长度部分.. - if(buf_size>data_pos && - (buf_size-data_pos)>=(uint64_t)sizeof(siz)) { - size_t *tmp=(size_t*)(buf+data_pos); - *tmp=siz; - data_pos+=(uint64_t)sizeof(siz); - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后序列化字符串部分.. - if(buf_size>data_pos && - (buf_size-data_pos)>=(uint64_t)siz) { - memcpy(buf+data_pos,_ptr->c_str(),siz); - data_pos+=siz; - } else { - return BTREE_UNKNOWN_ERROR; - } - return BTREE_OK; - } - int deserialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos) { - if(!_ptr) { - return BTREE_UNKNOWN_ERROR; - } - //首先读入size部分. - size_t siz; - if(buf_size > data_pos && - (buf_size - data_pos)>=(uint64_t)sizeof(siz)) { - size_t *tmp=(size_t*)(buf+data_pos); - siz=*tmp; - data_pos+=(uint64_t)sizeof(siz); - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后读入字符串部分 - const char *str; - if(buf_size > data_pos && - (buf_size - data_pos)>=(uint64_t)siz) { - str=(const char*)(buf+data_pos); - data_pos += (uint64_t)siz; - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后进行初始化. - //bsl construct没有使用两个参数初始化的... - //所以是用原始的.. - ::new(static_cast(_ptr))std::string(str,siz); - return BTREE_OK; - } -}; - -//bsl::string和std::string应该是走同样的逻辑的.. -template<> -class _btree_archive_traits { - bsl::string *_ptr; - -public: - _btree_archive_traits(bsl::string *ptr):_ptr(ptr) { - } - _btree_archive_traits():_ptr(NULL) { - } - uint64_t size()const { - if(!_ptr) { - return UNDEF_ID; - } - size_t siz=_ptr->size(); - return (uint64_t)sizeof(siz)+ - (uint64_t)siz; - } - int serialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos)const { - if(!_ptr) { - return BTREE_UNKNOWN_ERROR; - } - size_t siz=_ptr->size(); - //首先序列化长度部分.. - if(buf_size>data_pos && - (buf_size-data_pos)>=(uint64_t)sizeof(siz)) { - size_t *tmp=(size_t*)(buf+data_pos); - *tmp=siz; - data_pos+=(uint64_t)sizeof(siz); - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后序列化字符串部分.. - if(buf_size>data_pos && - (buf_size-data_pos)>=(uint64_t)siz) { - memcpy(buf+data_pos,_ptr->c_str(),siz); - data_pos+=siz; - } else { - return BTREE_UNKNOWN_ERROR; - } - return BTREE_OK; - } - int deserialize(char *buf,const uint64_t buf_size, - uint64_t &data_pos) { - if(!_ptr) { - return BTREE_UNKNOWN_ERROR; - } - //首先读入size部分. - size_t siz; - if(buf_size > data_pos && - (buf_size - data_pos)>=(uint64_t)sizeof(siz)) { - size_t *tmp=(size_t*)(buf+data_pos); - siz=*tmp; - data_pos+=(uint64_t)sizeof(siz); - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后读入字符串部分 - const char *str; - if(buf_size > data_pos && - (buf_size - data_pos)>=(uint64_t)siz) { - str=(const char*)(buf+data_pos); - data_pos += (uint64_t)siz; - } else { - return BTREE_UNKNOWN_ERROR; - } - //然后进行初始化. - //bsl construct没有使用两个参数初始化的... - //所以是用原始的.. - ::new(static_cast(_ptr))bsl::string(str,siz); - return BTREE_OK; - } -}; - -#endif diff --git a/bsl/containers/btree/bsl_kv_btree_data_unit.h b/bsl/containers/btree/bsl_kv_btree_data_unit.h deleted file mode 100644 index 2f8c54e2ca5b3555b8eac134f83b9ff14b05e199..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree_data_unit.h +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ -#ifndef _BSL_KV_BTREE_DATA_UNIT_H_ -#define _BSL_KV_BTREE_DATA_UNIT_H_ - -//如何依赖头文件,那么直接在bsl_kv_btree.h里面填写. -template, - typename VARCHIVE=_btree_archive_traits, - typename LT=std::less, - typename EQ=std::equal_to > -//这里很难使用Archive这个类 -//因为BSL里面的Archive根本就没有序列化到内存的接口.. -//所以自己写Archive类.._btree_archive_traits. -//kv btree内部应该包含的内容... -//应该包含V的所有接口.. -class _bsl_kv_btree_du { -public: - typedef _bsl_kv_btree_du Self; - //这样就能够得到最终的数据内容了... - typedef K key_type; - typedef V value_type; - -public: - //同时持有k,v. - K _key; - V _value; - uint64_t _id; - LT _lt; - EQ _eq; - _btree_archive_traits _idarchive; - KARCHIVE _karchive; - VARCHIVE _varchive; - -public: - //有默认的初始化构造函数和copy构造函数... - //并且用来初始化archive结构... - _bsl_kv_btree_du(): - _key(),_value(), - _idarchive(&_id),_karchive(&_key), - _varchive(&_value) { - init(); - } - _bsl_kv_btree_du(const K&k,const V&v): - _key(k),_value(v), - _idarchive(&_id),_karchive(&_key), - _varchive(&_value) { - init(); - } - _bsl_kv_btree_du(const _bsl_kv_btree_du &du): - _key(du._key),_value(du._value), - _idarchive(&_id),_karchive(&_key), - _varchive(&_value) { - init(); - } - const Self & operator = (const Self & v) { - //重复使用的话,那么释放之前的内存..... - //其实这样是可以使用变长内存的... - if(this!=&v) { - bsl_destruct(this); - bsl_construct(this,v); - } - return *this; - } - void init() { - _id=UNDEF_ID; - } - //下面这些方法仅仅对于定长有效,但是对于变长的话, -// //是需要重新实现的.. -// //这个可以固定住.. -// uint64_t get_store_size()const{ -// return (uint64_t)sizeof(Self); -// } -// //必须使用archive实现... -// //但是archive没有实现copy到内存的接口...:(.. -// int store(char *buf,const uint64_t buf_size, -// uint64_t &data_pos)const { -// int err=BTREE_OK; -// if(buf_size > data_pos && -// (buf_size - data_pos)>= (uint64_t)sizeof(V)) { -// //V *tmp=(V*)(buf+data_pos); -// //*tmp=_value; -// //data_pos+=(uint64_t)sizeof(V); -// Self *tmp=(Self*)(buf+data_pos); -// *tmp=*this; -// data_pos+=(uint64_t)sizeof(Self); -// } else { -// err=BTREE_UNKNOWN_ERROR; -// } -// return err; -// } -// int load(char *buf,const uint64_t buf_size, -// uint64_t &data_pos) { -// int err=BTREE_OK; -// if(buf_size > data_pos && -// (buf_size - data_pos)>= (uint64_t)sizeof(V)) { -// //V *tmp=(V*)(buf+data_pos); -// //_value=*tmp; -// //data_pos+=(uint64_t)sizeof(V); -// Self *tmp=(Self*)(buf+data_pos); -// *this=*tmp; -// data_pos+=(uint64_t)sizeof(Self); -// } else { -// err=BTREE_UNKNOWN_ERROR; -// } -// return err; -// } - //关于变长内存的话,那么store/load接口就需要花一些心思.. - uint64_t get_store_size()const { - return (uint64_t)_idarchive.size()+ - (uint64_t)_karchive.size()+ - (uint64_t)_varchive.size(); - } - int store(char *buf,const uint64_t buf_size, - uint64_t &data_pos)const { - int err=BTREE_OK; - err=_karchive.serialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - err=_varchive.serialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - err=_idarchive.serialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - return err; - } - int load(char *buf,const uint64_t buf_size, - uint64_t &data_pos) { - int err=BTREE_OK; - err=_karchive.deserialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - err=_varchive.deserialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - err=_idarchive.deserialize(buf,buf_size,data_pos); - if(err!=BTREE_OK) { - return err; - } - return err; - } - void set_id(uint64_t id) { - _id=id; - } - uint64_t get_id()const { - return _id; - } - //使用Compare对象实现比较接口.. - bool operator==(const K &k)const { - return _eq(_key,k); - } - bool operator==(const Self &self)const { - return _eq(_key,self._key); - } - - bool operator<(const K&k)const { - return _lt(_key,k); - } - bool operator<(const Self &self)const { - return _lt(_key,self._key); - } -}; - -#endif diff --git a/bsl/containers/btree/bsl_kv_btree_iterator.h b/bsl/containers/btree/bsl_kv_btree_iterator.h deleted file mode 100644 index bd42220f013b696047cbec0c4d76f93d2757d776..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree_iterator.h +++ /dev/null @@ -1,532 +0,0 @@ -/* -*- c++ -*- - copy[write] by dirlt(dirtysalt1987@gmail.com) */ -#ifndef _BSL_KV_BTREE_ITERATOR_H_ -#define _BSL_KV_BTREE_ITERATOR_H_ - -//如果需要添加头文件 -//统一在bsl_kv_btree.h里面 - -//============================================================ -//============================================================ -//============================================================ -//这个是一个基类.. -//提供遍历接口,这样iterator就只需要写一次了..:). -//纯粹就是一个接口... -//但是build btree和search btree所需要的接口是不同的. -template -class _bsl_kv_btree_build_iterator_base { -public: - virtual bool get_smallest(DU &du)const=0; - virtual bool get_largest(DU &du)const=0; - virtual bool get_smaller(const DU &pdu,DU &du)const=0; - virtual bool get_larger(const DU &pdu,DU &du)const=0; - virtual ~_bsl_kv_btree_build_iterator_base() { - } -}; - -//看了baonh的deque代码之后,发现这个地方实际上只需要定义一次 -//iterator就ok了...如果需要reverse_iterator的话,直接使用std::reverse_iterator包装 -//但是这里我不确定使用std::reverse_iterator自己的类里面需要包含哪些类.. -//所以还是自己写了一个reverse_iterator. -template -class _bsl_kv_btree_build_iterator { -public: - //相关的迭代器.. - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef key_type * kpointer; - typedef key_type & kreference; - typedef value_type * pointer; - typedef value_type & reference; - typedef const key_type * ckpointer; - typedef const key_type & ckreference; - typedef const value_type * cpointer; - typedef const value_type & creference; - typedef _bsl_kv_btree_build_iterator iterator; - typedef _bsl_kv_btree_build_iterator const_iterator; - //自己是self_type.. - typedef _bsl_kv_btree_build_iterator self_type; - //操纵的btree. - typedef _bsl_kv_btree_build_iterator_base kv_btree_type; - -private: - friend class _bsl_kv_btree_build; - const kv_btree_type *_btree; - //data. - DU _du; - //做一个_end的标记位... - bool _end; - -public: - _bsl_kv_btree_build_iterator() - :_btree(NULL),_du(),_end(true) { - //nothing. - } - _bsl_kv_btree_build_iterator(const kv_btree_type *btree, - const DU &du, - bool end=false):_btree(btree),_du(du),_end(end) { - } - _bsl_kv_btree_build_iterator(const iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - } - _bsl_kv_btree_build_iterator(const const_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - } - //如果用户在这里已修改iterator的话 - //是一个安全的操作,不会反映到btree - //但是却影响后面的查询. - VRef operator *() { - return _du._value; - } - VPtr operator->() { - return &(_du._value); - } - //相对于其他容器的iterator有这么一个接口就是能够获得key. - KPtr ptr_key() { - return &(_du._key); - } - KRef ref_key() { - return (_du._key); - } - bool operator == (const self_type & iter) const { - //如果都true的话,那么== - if(_end && iter._end) { - return true; - } else if(_end || iter._end) { - return false; - } - //必须是指向同一个btree并且du内容相同.. - return (_btree == iter._btree) && - (_du == iter._du); - } - bool operator != (const self_type & iter)const { - return !(*this == iter); - } - self_type & operator++() { - DU _tmp; - bool next=_btree->get_larger(_du,_tmp); - if(!next) { - //设置true.. - //不修改任何内容... - _end=true; - } else { - _du=_tmp; - } - return *this; - } - self_type operator++(int) { - self_type iter=*this; - ++*this; - return iter; - } - self_type & operator--() { - DU _tmp; - bool prev=_btree->get_smaller(_du,_tmp); - if(prev) { - _du=_tmp; - } - return *this; - } - self_type operator--(int) { - self_type iter=*this; - --*this; - return iter; - } -}; - -template -class _bsl_kv_btree_build_reverse_iterator { -public: - //相关的迭代器.. - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef key_type * kpointer; - typedef key_type & kreference; - typedef value_type * pointer; - typedef value_type & reference; - typedef const key_type * ckpointer; - typedef const key_type & ckreference; - typedef const value_type * cpointer; - typedef const value_type & creference; - typedef _bsl_kv_btree_build_reverse_iterator reverse_iterator; - typedef _bsl_kv_btree_build_reverse_iterator const_reverse_iterator; - //自己是self_type - typedef _bsl_kv_btree_build_reverse_iterator self_type; - //自己操纵的btree - typedef _bsl_kv_btree_build_iterator_base kv_btree_type; - -private: - friend class _bsl_kv_btree_build; - const kv_btree_type *_btree; - //data. - DU _du; - //做一个_end的标记位... - bool _end; - -public: - _bsl_kv_btree_build_reverse_iterator() - :_btree(NULL),_du(),_end(true) { - //nothing. - } - _bsl_kv_btree_build_reverse_iterator(const kv_btree_type *btree, - const DU &du, - bool end=false): - _btree(btree),_du(du),_end(end) { - } - _bsl_kv_btree_build_reverse_iterator(const reverse_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - } - _bsl_kv_btree_build_reverse_iterator(const const_reverse_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - } - //如果用户在这里已修改iterator的话 - //是一个安全的操作,不会反映到btree - //但是却影响后面的查询 - VRef operator *() { - return _du._value; - } - VPtr operator->() { - return &(_du._value); - } - //相对于其他容器的iterator有这么一个接口就是能够获得key. - KPtr ptr_key() { - return &(_du._key); - } - KRef ref_key() { - return (_du._key); - } - bool operator == (const self_type & iter) const { - //如果都true的话,那么== - if(_end && iter._end) { - return true; - } else if(_end || iter._end) { - return false; - } - //必须是指向同一个btree并且du内容相同.. - return (_btree == iter._btree) && - (_du == iter._du); - } - bool operator != (const self_type & iter)const { - return !(*this == iter); - } - self_type & operator++() { - DU _tmp; - bool next=_btree->get_smaller(_du,_tmp); - if(!next) { - //设置true.. - //不修改任何内容... - _end=true; - } else { - _du=_tmp; - } - return *this; - } - self_type operator++(int) { - self_type iter=*this; - ++*this; - return iter; - } - self_type & operator--() { - DU _tmp; - bool prev=_btree->get_larger(_du,_tmp); - if(prev) { - _du=_tmp; - } - return *this; - } - self_type operator--(int) { - self_type iter=*this; - --*this; - return iter; - } -}; - -//下面这个部分开始就是search btree的iterator.. -//============================================================ -//============================================================ -//============================================================ -template -class _bsl_kv_btree_search_iterator_base { -public: - virtual bool get_smallest(DU **du)const=0; - virtual bool get_largest(DU **du)const=0; - virtual bool get_smaller(const DU &pdu,DU **du, - dfs_btree_drill_t *pdrill_info)const=0; - virtual bool get_larger(const DU &pdu,DU **du, - dfs_btree_drill_t *pdrill_info)const=0; - virtual ~_bsl_kv_btree_search_iterator_base() { - } -}; -template -class _bsl_kv_btree_search_iterator { -public: - //相关的迭代器.. - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef key_type * kpointer; - typedef key_type & kreference; - typedef value_type * pointer; - typedef value_type & reference; - typedef const key_type * ckpointer; - typedef const key_type & ckreference; - typedef const value_type * cpointer; - typedef const value_type & creference; - typedef _bsl_kv_btree_search_iterator - iterator; - typedef _bsl_kv_btree_search_iterator - const_iterator; - //自己是self_type - typedef _bsl_kv_btree_search_iterator self_type; - //操纵的btree. - typedef _bsl_kv_btree_search_iterator_base kv_btree_type; - -private: - friend class _bsl_kv_btree_search; - const kv_btree_type *_btree; - //data. - //虽然这里du可以是const*的,但是我们为了提供 - //iterator和const iterator的话,那么只好在这里只使用非const * - //但是用户必须牢记不要修改du引出的值. - DU *_du; - //drill info - dfs_btree_drill_t _drill; - //做一个_end的标记位... - bool _end; -public: - _bsl_kv_btree_search_iterator() - :_btree(NULL),_du(NULL),_drill(),_end(true) { - //nothing. - } - _bsl_kv_btree_search_iterator(const kv_btree_type *btree, - DU *du, - bool end=false) - :_btree(btree),_du(du),_drill(),_end(end) { - } - _bsl_kv_btree_search_iterator(const iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - _drill=iter._drill; - } - _bsl_kv_btree_search_iterator(const const_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - _drill=iter._drill; - } - //用户不能够修改这个值..否则会影响到btree内容...:(.. - reference operator *() { - return _du->_value; - } - pointer operator->() { - return &(_du->_value); - } - //相对于其他容器的iterator有这么一个接口就是能够获得key. - KPtr ptr_key() { - return &(_du->_key); - } - KRef ref_key() { - return _du->_key; - } - bool operator == (const self_type & iter) const { - //如果都true的话,那么== - if(_end && iter._end) { - return true; - } else if(_end || iter._end) { - return false; - } - //必须du相同并且指向同一个btree. - return (_btree == iter._btree) && - (*_du == *iter._du); - } - bool operator != (const self_type & iter)const { - return !(*this == iter); - } - self_type & operator++() { - DU *_tmp; - bool next=_btree->get_larger(*_du,&_tmp,&_drill); - if(!next) { - //设置true.. - //不修改任何内容... - _end=true; - } else { - _du=_tmp; - } - return *this; - } - self_type operator++(int) { - self_type iter=*this; - ++*this; - return iter; - } - self_type & operator--() { - DU *_tmp; - bool prev=_btree->get_smaller(*_du,&_tmp,&_drill); - if(prev) { - _du=_tmp; - } - return *this; - } - self_type operator--(int) { - self_type iter=*this; - --*this; - return iter; - } -}; - -template -class _bsl_kv_btree_search_reverse_iterator { -public: - //相关的迭代器.. - typedef typename DU::key_type key_type; - typedef typename DU::value_type value_type; - typedef key_type * kpointer; - typedef key_type & kreference; - typedef value_type * pointer; - typedef value_type & reference; - typedef const key_type * ckpointer; - typedef const key_type & ckreference; - typedef const value_type * cpointer; - typedef const value_type & creference; - typedef _bsl_kv_btree_search_reverse_iterator - reverse_iterator; - typedef _bsl_kv_btree_search_reverse_iterator - const_reverse_iterator; - //自己是self_type - typedef _bsl_kv_btree_search_reverse_iterator self_type; - //操纵的btree. - typedef _bsl_kv_btree_search_iterator_base kv_btree_type; - -private: - friend class _bsl_kv_btree_search; - const kv_btree_type *_btree; - //data. - DU *_du; - //drill info - dfs_btree_drill_t _drill; - //做一个_end的标记位... - bool _end; - -public: - _bsl_kv_btree_search_reverse_iterator() - :_btree(NULL),_du(NULL),_drill(),_end(true) { - //nothing. - } - _bsl_kv_btree_search_reverse_iterator(const kv_btree_type *btree, - DU *du, - bool end=false): - _btree(btree),_du(du),_drill(),_end(end) { - } - _bsl_kv_btree_search_reverse_iterator(const reverse_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - _drill=iter._drill; - } - _bsl_kv_btree_search_reverse_iterator(const const_reverse_iterator & iter): - _btree(iter._btree),_du(iter._du),_end(iter._end) { - _drill=iter._drill; - } - //用户不允许修改这个值,不然会影响到btree的内容... - reference operator *() { - return _du->_value; - } - pointer operator->() { - return &(_du->_value); - } - //相对于其他容器的iterator有这么一个接口就是能够获得key. - KPtr ptr_key() { - return &(_du->_key); - } - KRef ref_key() { - return _du->_key; - } - bool operator == (const self_type & iter) const { - //如果都true的话,那么== - if(_end && iter._end) { - return true; - } else if(_end || iter._end) { - return false; - } - //必须du相同并且指向同一个btree. - return (_btree == iter._btree) && - (*_du == *iter._du); - } - bool operator != (const self_type & iter)const { - return !(*this == iter); - } - self_type & operator++() { - DU *_tmp; - bool next=_btree->get_smaller(*_du,&_tmp,&_drill); - if(!next) { - //设置true.. - //不修改任何内容... - _end=true; - } else { - _du=_tmp; - } - return *this; - } - self_type operator++(int) { - self_type iter=*this; - ++*this; - return iter; - } - self_type & operator--() { - DU *_tmp; - bool prev=_btree->get_larger(*_du,&_tmp,_drill); - if(prev) { - _du=_tmp; - } - return *this; - } - self_type operator--(int) { - self_type iter=*this; - --*this; - return iter; - } -}; - -#endif diff --git a/bsl/containers/btree/bsl_kv_btree_xmemcpy.h b/bsl/containers/btree/bsl_kv_btree_xmemcpy.h deleted file mode 100644 index d4c6780f9e5db0da4657997d54c664960764c50b..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/bsl_kv_btree_xmemcpy.h +++ /dev/null @@ -1,3633 +0,0 @@ -/* -*- c++ -*- */ -#ifndef __BSL_KV_BTREE_XMEMCPY_H__ -#define __BSL_KV_BTREE_XMEMCPY_H__ -//不要编辑这个文件..zhangyan04@baidu.com -//借鉴xiaowei的xmemcpy.但是这个东西让我非常不爽的一点就是 -//它有一个.cpp,你需要链接一个库.. -#include -#include -#include -#ifdef __SSE2__ -#include -#endif -//实现放在名字空间下面.. -namespace ZY{ -#ifdef __SSE2__ -typedef __m128i _memcpy_unit_128_t; -#endif -typedef unsigned long long _memcpy_unit_64_t; -typedef int _memcpy_unit_32_t; -//这个部分为_memcpy的实现. - //必须使用结构体,数组不允许copy. - template struct _memcpy_block__memcpy_unit_32_t_t{ - _memcpy_unit_32_t _data[size]; - }; - static void * _memcpy_0(void *dst,const void */*src*/){ - return dst; - } - static void * _memcpy_1(void *dst,const void *src){ - ((char *)dst)[0] = ((char *)src)[0]; - return dst; - } - static void * _memcpy_2(void *dst,const void *src){ - ((char *)dst)[1] = ((char *)src)[1];((char *)dst)[0] = ((char *)src)[0]; - return dst; - } - static void * _memcpy_3(void *dst,const void *src){ - ((char *)dst)[2] = ((char *)src)[2];((char *)dst)[1] = ((char *)src)[1];((char *)dst)[0] = ((char *)src)[0]; - return dst; - } - static void * _memcpy_4(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<1> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_5(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<1> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[4] = ((char *)src)[4]; - return dst; - } - static void * _memcpy_6(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<1> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[5] = ((char *)src)[5];((char *)dst)[4] = ((char *)src)[4]; - return dst; - } - static void * _memcpy_7(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<1> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[6] = ((char *)src)[6];((char *)dst)[5] = ((char *)src)[5];((char *)dst)[4] = ((char *)src)[4]; - return dst; - } - static void * _memcpy_8(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<2> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_9(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<2> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[8] = ((char *)src)[8]; - return dst; - } - static void * _memcpy_10(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<2> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[9] = ((char *)src)[9];((char *)dst)[8] = ((char *)src)[8]; - return dst; - } - static void * _memcpy_11(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<2> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[10] = ((char *)src)[10];((char *)dst)[9] = ((char *)src)[9];((char *)dst)[8] = ((char *)src)[8]; - return dst; - } - static void * _memcpy_12(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<3> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_13(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<3> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[12] = ((char *)src)[12]; - return dst; - } - static void * _memcpy_14(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<3> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[13] = ((char *)src)[13];((char *)dst)[12] = ((char *)src)[12]; - return dst; - } - static void * _memcpy_15(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<3> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[14] = ((char *)src)[14];((char *)dst)[13] = ((char *)src)[13];((char *)dst)[12] = ((char *)src)[12]; - return dst; - } - static void * _memcpy_16(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<4> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_17(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<4> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[16] = ((char *)src)[16]; - return dst; - } - static void * _memcpy_18(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<4> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[17] = ((char *)src)[17];((char *)dst)[16] = ((char *)src)[16]; - return dst; - } - static void * _memcpy_19(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<4> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[18] = ((char *)src)[18];((char *)dst)[17] = ((char *)src)[17];((char *)dst)[16] = ((char *)src)[16]; - return dst; - } - static void * _memcpy_20(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<5> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_21(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<5> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[20] = ((char *)src)[20]; - return dst; - } - static void * _memcpy_22(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<5> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[21] = ((char *)src)[21];((char *)dst)[20] = ((char *)src)[20]; - return dst; - } - static void * _memcpy_23(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<5> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[22] = ((char *)src)[22];((char *)dst)[21] = ((char *)src)[21];((char *)dst)[20] = ((char *)src)[20]; - return dst; - } - static void * _memcpy_24(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<6> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_25(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<6> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[24] = ((char *)src)[24]; - return dst; - } - static void * _memcpy_26(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<6> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[25] = ((char *)src)[25];((char *)dst)[24] = ((char *)src)[24]; - return dst; - } - static void * _memcpy_27(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<6> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[26] = ((char *)src)[26];((char *)dst)[25] = ((char *)src)[25];((char *)dst)[24] = ((char *)src)[24]; - return dst; - } - static void * _memcpy_28(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<7> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_29(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<7> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[28] = ((char *)src)[28]; - return dst; - } - static void * _memcpy_30(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<7> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[29] = ((char *)src)[29];((char *)dst)[28] = ((char *)src)[28]; - return dst; - } - static void * _memcpy_31(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<7> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[30] = ((char *)src)[30];((char *)dst)[29] = ((char *)src)[29];((char *)dst)[28] = ((char *)src)[28]; - return dst; - } - static void * _memcpy_32(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_33(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[32] = ((char *)src)[32]; - return dst; - } - static void * _memcpy_34(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[33] = ((char *)src)[33];((char *)dst)[32] = ((char *)src)[32]; - return dst; - } - static void * _memcpy_35(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[34] = ((char *)src)[34];((char *)dst)[33] = ((char *)src)[33];((char *)dst)[32] = ((char *)src)[32]; - return dst; - } - static void * _memcpy_36(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_37(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[36] = ((char *)src)[36]; - return dst; - } - static void * _memcpy_38(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[37] = ((char *)src)[37];((char *)dst)[36] = ((char *)src)[36]; - return dst; - } - static void * _memcpy_39(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[38] = ((char *)src)[38];((char *)dst)[37] = ((char *)src)[37];((char *)dst)[36] = ((char *)src)[36]; - return dst; - } - static void * _memcpy_40(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_41(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[40] = ((char *)src)[40]; - return dst; - } - static void * _memcpy_42(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[41] = ((char *)src)[41];((char *)dst)[40] = ((char *)src)[40]; - return dst; - } - static void * _memcpy_43(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[42] = ((char *)src)[42];((char *)dst)[41] = ((char *)src)[41];((char *)dst)[40] = ((char *)src)[40]; - return dst; - } - static void * _memcpy_44(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_45(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[44] = ((char *)src)[44]; - return dst; - } - static void * _memcpy_46(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[45] = ((char *)src)[45];((char *)dst)[44] = ((char *)src)[44]; - return dst; - } - static void * _memcpy_47(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[46] = ((char *)src)[46];((char *)dst)[45] = ((char *)src)[45];((char *)dst)[44] = ((char *)src)[44]; - return dst; - } - static void * _memcpy_48(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_49(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[48] = ((char *)src)[48]; - return dst; - } - static void * _memcpy_50(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[49] = ((char *)src)[49];((char *)dst)[48] = ((char *)src)[48]; - return dst; - } - static void * _memcpy_51(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[50] = ((char *)src)[50];((char *)dst)[49] = ((char *)src)[49];((char *)dst)[48] = ((char *)src)[48]; - return dst; - } - static void * _memcpy_52(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_53(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[52] = ((char *)src)[52]; - return dst; - } - static void * _memcpy_54(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[53] = ((char *)src)[53];((char *)dst)[52] = ((char *)src)[52]; - return dst; - } - static void * _memcpy_55(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[54] = ((char *)src)[54];((char *)dst)[53] = ((char *)src)[53];((char *)dst)[52] = ((char *)src)[52]; - return dst; - } - static void * _memcpy_56(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_57(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[56] = ((char *)src)[56]; - return dst; - } - static void * _memcpy_58(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[57] = ((char *)src)[57];((char *)dst)[56] = ((char *)src)[56]; - return dst; - } - static void * _memcpy_59(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[58] = ((char *)src)[58];((char *)dst)[57] = ((char *)src)[57];((char *)dst)[56] = ((char *)src)[56]; - return dst; - } - static void * _memcpy_60(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_61(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[60] = ((char *)src)[60]; - return dst; - } - static void * _memcpy_62(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[61] = ((char *)src)[61];((char *)dst)[60] = ((char *)src)[60]; - return dst; - } - static void * _memcpy_63(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[62] = ((char *)src)[62];((char *)dst)[61] = ((char *)src)[61];((char *)dst)[60] = ((char *)src)[60]; - return dst; - } - static void * _memcpy_64(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_65(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[64] = ((char *)src)[64]; - return dst; - } - static void * _memcpy_66(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[65] = ((char *)src)[65];((char *)dst)[64] = ((char *)src)[64]; - return dst; - } - static void * _memcpy_67(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[66] = ((char *)src)[66];((char *)dst)[65] = ((char *)src)[65];((char *)dst)[64] = ((char *)src)[64]; - return dst; - } - static void * _memcpy_68(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_69(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[68] = ((char *)src)[68]; - return dst; - } - static void * _memcpy_70(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[69] = ((char *)src)[69];((char *)dst)[68] = ((char *)src)[68]; - return dst; - } - static void * _memcpy_71(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[70] = ((char *)src)[70];((char *)dst)[69] = ((char *)src)[69];((char *)dst)[68] = ((char *)src)[68]; - return dst; - } - static void * _memcpy_72(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_73(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[72] = ((char *)src)[72]; - return dst; - } - static void * _memcpy_74(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[73] = ((char *)src)[73];((char *)dst)[72] = ((char *)src)[72]; - return dst; - } - static void * _memcpy_75(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[74] = ((char *)src)[74];((char *)dst)[73] = ((char *)src)[73];((char *)dst)[72] = ((char *)src)[72]; - return dst; - } - static void * _memcpy_76(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_77(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[76] = ((char *)src)[76]; - return dst; - } - static void * _memcpy_78(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[77] = ((char *)src)[77];((char *)dst)[76] = ((char *)src)[76]; - return dst; - } - static void * _memcpy_79(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[78] = ((char *)src)[78];((char *)dst)[77] = ((char *)src)[77];((char *)dst)[76] = ((char *)src)[76]; - return dst; - } - static void * _memcpy_80(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_81(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[80] = ((char *)src)[80]; - return dst; - } - static void * _memcpy_82(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[81] = ((char *)src)[81];((char *)dst)[80] = ((char *)src)[80]; - return dst; - } - static void * _memcpy_83(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[82] = ((char *)src)[82];((char *)dst)[81] = ((char *)src)[81];((char *)dst)[80] = ((char *)src)[80]; - return dst; - } - static void * _memcpy_84(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_85(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[84] = ((char *)src)[84]; - return dst; - } - static void * _memcpy_86(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[85] = ((char *)src)[85];((char *)dst)[84] = ((char *)src)[84]; - return dst; - } - static void * _memcpy_87(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[86] = ((char *)src)[86];((char *)dst)[85] = ((char *)src)[85];((char *)dst)[84] = ((char *)src)[84]; - return dst; - } - static void * _memcpy_88(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_89(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[88] = ((char *)src)[88]; - return dst; - } - static void * _memcpy_90(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[89] = ((char *)src)[89];((char *)dst)[88] = ((char *)src)[88]; - return dst; - } - static void * _memcpy_91(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[90] = ((char *)src)[90];((char *)dst)[89] = ((char *)src)[89];((char *)dst)[88] = ((char *)src)[88]; - return dst; - } - static void * _memcpy_92(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_93(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[92] = ((char *)src)[92]; - return dst; - } - static void * _memcpy_94(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[93] = ((char *)src)[93];((char *)dst)[92] = ((char *)src)[92]; - return dst; - } - static void * _memcpy_95(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[94] = ((char *)src)[94];((char *)dst)[93] = ((char *)src)[93];((char *)dst)[92] = ((char *)src)[92]; - return dst; - } - static void * _memcpy_96(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_97(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[96] = ((char *)src)[96]; - return dst; - } - static void * _memcpy_98(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[97] = ((char *)src)[97];((char *)dst)[96] = ((char *)src)[96]; - return dst; - } - static void * _memcpy_99(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[98] = ((char *)src)[98];((char *)dst)[97] = ((char *)src)[97];((char *)dst)[96] = ((char *)src)[96]; - return dst; - } - static void * _memcpy_100(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_101(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[100] = ((char *)src)[100]; - return dst; - } - static void * _memcpy_102(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[101] = ((char *)src)[101];((char *)dst)[100] = ((char *)src)[100]; - return dst; - } - static void * _memcpy_103(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[102] = ((char *)src)[102];((char *)dst)[101] = ((char *)src)[101];((char *)dst)[100] = ((char *)src)[100]; - return dst; - } - static void * _memcpy_104(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_105(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[104] = ((char *)src)[104]; - return dst; - } - static void * _memcpy_106(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[105] = ((char *)src)[105];((char *)dst)[104] = ((char *)src)[104]; - return dst; - } - static void * _memcpy_107(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[106] = ((char *)src)[106];((char *)dst)[105] = ((char *)src)[105];((char *)dst)[104] = ((char *)src)[104]; - return dst; - } - static void * _memcpy_108(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_109(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[108] = ((char *)src)[108]; - return dst; - } - static void * _memcpy_110(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[109] = ((char *)src)[109];((char *)dst)[108] = ((char *)src)[108]; - return dst; - } - static void * _memcpy_111(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[110] = ((char *)src)[110];((char *)dst)[109] = ((char *)src)[109];((char *)dst)[108] = ((char *)src)[108]; - return dst; - } - static void * _memcpy_112(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_113(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[112] = ((char *)src)[112]; - return dst; - } - static void * _memcpy_114(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[113] = ((char *)src)[113];((char *)dst)[112] = ((char *)src)[112]; - return dst; - } - static void * _memcpy_115(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[114] = ((char *)src)[114];((char *)dst)[113] = ((char *)src)[113];((char *)dst)[112] = ((char *)src)[112]; - return dst; - } - static void * _memcpy_116(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_117(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[116] = ((char *)src)[116]; - return dst; - } - static void * _memcpy_118(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[117] = ((char *)src)[117];((char *)dst)[116] = ((char *)src)[116]; - return dst; - } - static void * _memcpy_119(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[118] = ((char *)src)[118];((char *)dst)[117] = ((char *)src)[117];((char *)dst)[116] = ((char *)src)[116]; - return dst; - } - static void * _memcpy_120(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_121(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[120] = ((char *)src)[120]; - return dst; - } - static void * _memcpy_122(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[121] = ((char *)src)[121];((char *)dst)[120] = ((char *)src)[120]; - return dst; - } - static void * _memcpy_123(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[122] = ((char *)src)[122];((char *)dst)[121] = ((char *)src)[121];((char *)dst)[120] = ((char *)src)[120]; - return dst; - } - static void * _memcpy_124(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_125(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[124] = ((char *)src)[124]; - return dst; - } - static void * _memcpy_126(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[125] = ((char *)src)[125];((char *)dst)[124] = ((char *)src)[124]; - return dst; - } - static void * _memcpy_127(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[126] = ((char *)src)[126];((char *)dst)[125] = ((char *)src)[125];((char *)dst)[124] = ((char *)src)[124]; - return dst; - } - static void * _memcpy_128(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_32_t_t<32> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - //必须使用结构体,数组不允许copy. - template struct _memcpy_block__memcpy_unit_128_t_t{ - _memcpy_unit_128_t _data[size]; - }; - static void * _memcpy_129(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_130(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_131(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_132(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_133(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_134(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_135(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_136(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_137(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_138(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_139(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[138] = ((char *)src)[138];((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_140(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[139] = ((char *)src)[139];((char *)dst)[138] = ((char *)src)[138];((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_141(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[140] = ((char *)src)[140];((char *)dst)[139] = ((char *)src)[139];((char *)dst)[138] = ((char *)src)[138];((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_142(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[141] = ((char *)src)[141];((char *)dst)[140] = ((char *)src)[140];((char *)dst)[139] = ((char *)src)[139];((char *)dst)[138] = ((char *)src)[138];((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_143(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<8> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[142] = ((char *)src)[142];((char *)dst)[141] = ((char *)src)[141];((char *)dst)[140] = ((char *)src)[140];((char *)dst)[139] = ((char *)src)[139];((char *)dst)[138] = ((char *)src)[138];((char *)dst)[137] = ((char *)src)[137];((char *)dst)[136] = ((char *)src)[136];((char *)dst)[135] = ((char *)src)[135];((char *)dst)[134] = ((char *)src)[134];((char *)dst)[133] = ((char *)src)[133];((char *)dst)[132] = ((char *)src)[132];((char *)dst)[131] = ((char *)src)[131];((char *)dst)[130] = ((char *)src)[130];((char *)dst)[129] = ((char *)src)[129];((char *)dst)[128] = ((char *)src)[128]; - return dst; - } - static void * _memcpy_144(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_145(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_146(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_147(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_148(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_149(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_150(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_151(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_152(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_153(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_154(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_155(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[154] = ((char *)src)[154];((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_156(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[155] = ((char *)src)[155];((char *)dst)[154] = ((char *)src)[154];((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_157(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[156] = ((char *)src)[156];((char *)dst)[155] = ((char *)src)[155];((char *)dst)[154] = ((char *)src)[154];((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_158(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[157] = ((char *)src)[157];((char *)dst)[156] = ((char *)src)[156];((char *)dst)[155] = ((char *)src)[155];((char *)dst)[154] = ((char *)src)[154];((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_159(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<9> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[158] = ((char *)src)[158];((char *)dst)[157] = ((char *)src)[157];((char *)dst)[156] = ((char *)src)[156];((char *)dst)[155] = ((char *)src)[155];((char *)dst)[154] = ((char *)src)[154];((char *)dst)[153] = ((char *)src)[153];((char *)dst)[152] = ((char *)src)[152];((char *)dst)[151] = ((char *)src)[151];((char *)dst)[150] = ((char *)src)[150];((char *)dst)[149] = ((char *)src)[149];((char *)dst)[148] = ((char *)src)[148];((char *)dst)[147] = ((char *)src)[147];((char *)dst)[146] = ((char *)src)[146];((char *)dst)[145] = ((char *)src)[145];((char *)dst)[144] = ((char *)src)[144]; - return dst; - } - static void * _memcpy_160(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_161(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_162(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_163(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_164(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_165(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_166(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_167(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_168(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_169(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_170(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_171(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[170] = ((char *)src)[170];((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_172(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[171] = ((char *)src)[171];((char *)dst)[170] = ((char *)src)[170];((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_173(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[172] = ((char *)src)[172];((char *)dst)[171] = ((char *)src)[171];((char *)dst)[170] = ((char *)src)[170];((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_174(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[173] = ((char *)src)[173];((char *)dst)[172] = ((char *)src)[172];((char *)dst)[171] = ((char *)src)[171];((char *)dst)[170] = ((char *)src)[170];((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_175(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<10> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[174] = ((char *)src)[174];((char *)dst)[173] = ((char *)src)[173];((char *)dst)[172] = ((char *)src)[172];((char *)dst)[171] = ((char *)src)[171];((char *)dst)[170] = ((char *)src)[170];((char *)dst)[169] = ((char *)src)[169];((char *)dst)[168] = ((char *)src)[168];((char *)dst)[167] = ((char *)src)[167];((char *)dst)[166] = ((char *)src)[166];((char *)dst)[165] = ((char *)src)[165];((char *)dst)[164] = ((char *)src)[164];((char *)dst)[163] = ((char *)src)[163];((char *)dst)[162] = ((char *)src)[162];((char *)dst)[161] = ((char *)src)[161];((char *)dst)[160] = ((char *)src)[160]; - return dst; - } - static void * _memcpy_176(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_177(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_178(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_179(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_180(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_181(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_182(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_183(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_184(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_185(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_186(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_187(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[186] = ((char *)src)[186];((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_188(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[187] = ((char *)src)[187];((char *)dst)[186] = ((char *)src)[186];((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_189(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[188] = ((char *)src)[188];((char *)dst)[187] = ((char *)src)[187];((char *)dst)[186] = ((char *)src)[186];((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_190(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[189] = ((char *)src)[189];((char *)dst)[188] = ((char *)src)[188];((char *)dst)[187] = ((char *)src)[187];((char *)dst)[186] = ((char *)src)[186];((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_191(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<11> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[190] = ((char *)src)[190];((char *)dst)[189] = ((char *)src)[189];((char *)dst)[188] = ((char *)src)[188];((char *)dst)[187] = ((char *)src)[187];((char *)dst)[186] = ((char *)src)[186];((char *)dst)[185] = ((char *)src)[185];((char *)dst)[184] = ((char *)src)[184];((char *)dst)[183] = ((char *)src)[183];((char *)dst)[182] = ((char *)src)[182];((char *)dst)[181] = ((char *)src)[181];((char *)dst)[180] = ((char *)src)[180];((char *)dst)[179] = ((char *)src)[179];((char *)dst)[178] = ((char *)src)[178];((char *)dst)[177] = ((char *)src)[177];((char *)dst)[176] = ((char *)src)[176]; - return dst; - } - static void * _memcpy_192(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_193(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_194(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_195(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_196(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_197(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_198(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_199(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_200(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_201(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_202(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_203(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[202] = ((char *)src)[202];((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_204(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[203] = ((char *)src)[203];((char *)dst)[202] = ((char *)src)[202];((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_205(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[204] = ((char *)src)[204];((char *)dst)[203] = ((char *)src)[203];((char *)dst)[202] = ((char *)src)[202];((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_206(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[205] = ((char *)src)[205];((char *)dst)[204] = ((char *)src)[204];((char *)dst)[203] = ((char *)src)[203];((char *)dst)[202] = ((char *)src)[202];((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_207(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<12> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[206] = ((char *)src)[206];((char *)dst)[205] = ((char *)src)[205];((char *)dst)[204] = ((char *)src)[204];((char *)dst)[203] = ((char *)src)[203];((char *)dst)[202] = ((char *)src)[202];((char *)dst)[201] = ((char *)src)[201];((char *)dst)[200] = ((char *)src)[200];((char *)dst)[199] = ((char *)src)[199];((char *)dst)[198] = ((char *)src)[198];((char *)dst)[197] = ((char *)src)[197];((char *)dst)[196] = ((char *)src)[196];((char *)dst)[195] = ((char *)src)[195];((char *)dst)[194] = ((char *)src)[194];((char *)dst)[193] = ((char *)src)[193];((char *)dst)[192] = ((char *)src)[192]; - return dst; - } - static void * _memcpy_208(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_209(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_210(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_211(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_212(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_213(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_214(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_215(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_216(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_217(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_218(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_219(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[218] = ((char *)src)[218];((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_220(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[219] = ((char *)src)[219];((char *)dst)[218] = ((char *)src)[218];((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_221(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[220] = ((char *)src)[220];((char *)dst)[219] = ((char *)src)[219];((char *)dst)[218] = ((char *)src)[218];((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_222(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[221] = ((char *)src)[221];((char *)dst)[220] = ((char *)src)[220];((char *)dst)[219] = ((char *)src)[219];((char *)dst)[218] = ((char *)src)[218];((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_223(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<13> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[222] = ((char *)src)[222];((char *)dst)[221] = ((char *)src)[221];((char *)dst)[220] = ((char *)src)[220];((char *)dst)[219] = ((char *)src)[219];((char *)dst)[218] = ((char *)src)[218];((char *)dst)[217] = ((char *)src)[217];((char *)dst)[216] = ((char *)src)[216];((char *)dst)[215] = ((char *)src)[215];((char *)dst)[214] = ((char *)src)[214];((char *)dst)[213] = ((char *)src)[213];((char *)dst)[212] = ((char *)src)[212];((char *)dst)[211] = ((char *)src)[211];((char *)dst)[210] = ((char *)src)[210];((char *)dst)[209] = ((char *)src)[209];((char *)dst)[208] = ((char *)src)[208]; - return dst; - } - static void * _memcpy_224(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_225(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_226(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_227(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_228(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_229(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_230(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_231(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_232(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_233(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_234(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_235(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[234] = ((char *)src)[234];((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_236(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[235] = ((char *)src)[235];((char *)dst)[234] = ((char *)src)[234];((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_237(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[236] = ((char *)src)[236];((char *)dst)[235] = ((char *)src)[235];((char *)dst)[234] = ((char *)src)[234];((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_238(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[237] = ((char *)src)[237];((char *)dst)[236] = ((char *)src)[236];((char *)dst)[235] = ((char *)src)[235];((char *)dst)[234] = ((char *)src)[234];((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_239(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<14> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[238] = ((char *)src)[238];((char *)dst)[237] = ((char *)src)[237];((char *)dst)[236] = ((char *)src)[236];((char *)dst)[235] = ((char *)src)[235];((char *)dst)[234] = ((char *)src)[234];((char *)dst)[233] = ((char *)src)[233];((char *)dst)[232] = ((char *)src)[232];((char *)dst)[231] = ((char *)src)[231];((char *)dst)[230] = ((char *)src)[230];((char *)dst)[229] = ((char *)src)[229];((char *)dst)[228] = ((char *)src)[228];((char *)dst)[227] = ((char *)src)[227];((char *)dst)[226] = ((char *)src)[226];((char *)dst)[225] = ((char *)src)[225];((char *)dst)[224] = ((char *)src)[224]; - return dst; - } - static void * _memcpy_240(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_241(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_242(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_243(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_244(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_245(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_246(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_247(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_248(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_249(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_250(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_251(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[250] = ((char *)src)[250];((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_252(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[251] = ((char *)src)[251];((char *)dst)[250] = ((char *)src)[250];((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_253(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[252] = ((char *)src)[252];((char *)dst)[251] = ((char *)src)[251];((char *)dst)[250] = ((char *)src)[250];((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_254(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[253] = ((char *)src)[253];((char *)dst)[252] = ((char *)src)[252];((char *)dst)[251] = ((char *)src)[251];((char *)dst)[250] = ((char *)src)[250];((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_255(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<15> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[254] = ((char *)src)[254];((char *)dst)[253] = ((char *)src)[253];((char *)dst)[252] = ((char *)src)[252];((char *)dst)[251] = ((char *)src)[251];((char *)dst)[250] = ((char *)src)[250];((char *)dst)[249] = ((char *)src)[249];((char *)dst)[248] = ((char *)src)[248];((char *)dst)[247] = ((char *)src)[247];((char *)dst)[246] = ((char *)src)[246];((char *)dst)[245] = ((char *)src)[245];((char *)dst)[244] = ((char *)src)[244];((char *)dst)[243] = ((char *)src)[243];((char *)dst)[242] = ((char *)src)[242];((char *)dst)[241] = ((char *)src)[241];((char *)dst)[240] = ((char *)src)[240]; - return dst; - } - static void * _memcpy_256(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_257(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_258(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_259(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_260(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_261(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_262(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_263(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_264(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_265(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_266(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_267(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[266] = ((char *)src)[266];((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_268(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[267] = ((char *)src)[267];((char *)dst)[266] = ((char *)src)[266];((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_269(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[268] = ((char *)src)[268];((char *)dst)[267] = ((char *)src)[267];((char *)dst)[266] = ((char *)src)[266];((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_270(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[269] = ((char *)src)[269];((char *)dst)[268] = ((char *)src)[268];((char *)dst)[267] = ((char *)src)[267];((char *)dst)[266] = ((char *)src)[266];((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_271(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<16> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[270] = ((char *)src)[270];((char *)dst)[269] = ((char *)src)[269];((char *)dst)[268] = ((char *)src)[268];((char *)dst)[267] = ((char *)src)[267];((char *)dst)[266] = ((char *)src)[266];((char *)dst)[265] = ((char *)src)[265];((char *)dst)[264] = ((char *)src)[264];((char *)dst)[263] = ((char *)src)[263];((char *)dst)[262] = ((char *)src)[262];((char *)dst)[261] = ((char *)src)[261];((char *)dst)[260] = ((char *)src)[260];((char *)dst)[259] = ((char *)src)[259];((char *)dst)[258] = ((char *)src)[258];((char *)dst)[257] = ((char *)src)[257];((char *)dst)[256] = ((char *)src)[256]; - return dst; - } - static void * _memcpy_272(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_273(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_274(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_275(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_276(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_277(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_278(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_279(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_280(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_281(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_282(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_283(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[282] = ((char *)src)[282];((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_284(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[283] = ((char *)src)[283];((char *)dst)[282] = ((char *)src)[282];((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_285(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[284] = ((char *)src)[284];((char *)dst)[283] = ((char *)src)[283];((char *)dst)[282] = ((char *)src)[282];((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_286(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[285] = ((char *)src)[285];((char *)dst)[284] = ((char *)src)[284];((char *)dst)[283] = ((char *)src)[283];((char *)dst)[282] = ((char *)src)[282];((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_287(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<17> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[286] = ((char *)src)[286];((char *)dst)[285] = ((char *)src)[285];((char *)dst)[284] = ((char *)src)[284];((char *)dst)[283] = ((char *)src)[283];((char *)dst)[282] = ((char *)src)[282];((char *)dst)[281] = ((char *)src)[281];((char *)dst)[280] = ((char *)src)[280];((char *)dst)[279] = ((char *)src)[279];((char *)dst)[278] = ((char *)src)[278];((char *)dst)[277] = ((char *)src)[277];((char *)dst)[276] = ((char *)src)[276];((char *)dst)[275] = ((char *)src)[275];((char *)dst)[274] = ((char *)src)[274];((char *)dst)[273] = ((char *)src)[273];((char *)dst)[272] = ((char *)src)[272]; - return dst; - } - static void * _memcpy_288(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_289(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_290(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_291(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_292(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_293(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_294(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_295(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_296(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_297(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_298(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_299(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[298] = ((char *)src)[298];((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_300(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[299] = ((char *)src)[299];((char *)dst)[298] = ((char *)src)[298];((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_301(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[300] = ((char *)src)[300];((char *)dst)[299] = ((char *)src)[299];((char *)dst)[298] = ((char *)src)[298];((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_302(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[301] = ((char *)src)[301];((char *)dst)[300] = ((char *)src)[300];((char *)dst)[299] = ((char *)src)[299];((char *)dst)[298] = ((char *)src)[298];((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_303(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<18> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[302] = ((char *)src)[302];((char *)dst)[301] = ((char *)src)[301];((char *)dst)[300] = ((char *)src)[300];((char *)dst)[299] = ((char *)src)[299];((char *)dst)[298] = ((char *)src)[298];((char *)dst)[297] = ((char *)src)[297];((char *)dst)[296] = ((char *)src)[296];((char *)dst)[295] = ((char *)src)[295];((char *)dst)[294] = ((char *)src)[294];((char *)dst)[293] = ((char *)src)[293];((char *)dst)[292] = ((char *)src)[292];((char *)dst)[291] = ((char *)src)[291];((char *)dst)[290] = ((char *)src)[290];((char *)dst)[289] = ((char *)src)[289];((char *)dst)[288] = ((char *)src)[288]; - return dst; - } - static void * _memcpy_304(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_305(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_306(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_307(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_308(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_309(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_310(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_311(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_312(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_313(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_314(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_315(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[314] = ((char *)src)[314];((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_316(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[315] = ((char *)src)[315];((char *)dst)[314] = ((char *)src)[314];((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_317(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[316] = ((char *)src)[316];((char *)dst)[315] = ((char *)src)[315];((char *)dst)[314] = ((char *)src)[314];((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_318(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[317] = ((char *)src)[317];((char *)dst)[316] = ((char *)src)[316];((char *)dst)[315] = ((char *)src)[315];((char *)dst)[314] = ((char *)src)[314];((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_319(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<19> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[318] = ((char *)src)[318];((char *)dst)[317] = ((char *)src)[317];((char *)dst)[316] = ((char *)src)[316];((char *)dst)[315] = ((char *)src)[315];((char *)dst)[314] = ((char *)src)[314];((char *)dst)[313] = ((char *)src)[313];((char *)dst)[312] = ((char *)src)[312];((char *)dst)[311] = ((char *)src)[311];((char *)dst)[310] = ((char *)src)[310];((char *)dst)[309] = ((char *)src)[309];((char *)dst)[308] = ((char *)src)[308];((char *)dst)[307] = ((char *)src)[307];((char *)dst)[306] = ((char *)src)[306];((char *)dst)[305] = ((char *)src)[305];((char *)dst)[304] = ((char *)src)[304]; - return dst; - } - static void * _memcpy_320(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_321(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_322(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_323(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_324(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_325(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_326(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_327(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_328(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_329(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_330(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_331(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[330] = ((char *)src)[330];((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_332(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[331] = ((char *)src)[331];((char *)dst)[330] = ((char *)src)[330];((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_333(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[332] = ((char *)src)[332];((char *)dst)[331] = ((char *)src)[331];((char *)dst)[330] = ((char *)src)[330];((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_334(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[333] = ((char *)src)[333];((char *)dst)[332] = ((char *)src)[332];((char *)dst)[331] = ((char *)src)[331];((char *)dst)[330] = ((char *)src)[330];((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_335(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<20> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[334] = ((char *)src)[334];((char *)dst)[333] = ((char *)src)[333];((char *)dst)[332] = ((char *)src)[332];((char *)dst)[331] = ((char *)src)[331];((char *)dst)[330] = ((char *)src)[330];((char *)dst)[329] = ((char *)src)[329];((char *)dst)[328] = ((char *)src)[328];((char *)dst)[327] = ((char *)src)[327];((char *)dst)[326] = ((char *)src)[326];((char *)dst)[325] = ((char *)src)[325];((char *)dst)[324] = ((char *)src)[324];((char *)dst)[323] = ((char *)src)[323];((char *)dst)[322] = ((char *)src)[322];((char *)dst)[321] = ((char *)src)[321];((char *)dst)[320] = ((char *)src)[320]; - return dst; - } - static void * _memcpy_336(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_337(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_338(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_339(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_340(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_341(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_342(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_343(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_344(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_345(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_346(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_347(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[346] = ((char *)src)[346];((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_348(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[347] = ((char *)src)[347];((char *)dst)[346] = ((char *)src)[346];((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_349(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[348] = ((char *)src)[348];((char *)dst)[347] = ((char *)src)[347];((char *)dst)[346] = ((char *)src)[346];((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_350(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[349] = ((char *)src)[349];((char *)dst)[348] = ((char *)src)[348];((char *)dst)[347] = ((char *)src)[347];((char *)dst)[346] = ((char *)src)[346];((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_351(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<21> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[350] = ((char *)src)[350];((char *)dst)[349] = ((char *)src)[349];((char *)dst)[348] = ((char *)src)[348];((char *)dst)[347] = ((char *)src)[347];((char *)dst)[346] = ((char *)src)[346];((char *)dst)[345] = ((char *)src)[345];((char *)dst)[344] = ((char *)src)[344];((char *)dst)[343] = ((char *)src)[343];((char *)dst)[342] = ((char *)src)[342];((char *)dst)[341] = ((char *)src)[341];((char *)dst)[340] = ((char *)src)[340];((char *)dst)[339] = ((char *)src)[339];((char *)dst)[338] = ((char *)src)[338];((char *)dst)[337] = ((char *)src)[337];((char *)dst)[336] = ((char *)src)[336]; - return dst; - } - static void * _memcpy_352(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_353(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_354(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_355(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_356(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_357(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_358(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_359(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_360(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_361(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_362(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_363(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[362] = ((char *)src)[362];((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_364(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[363] = ((char *)src)[363];((char *)dst)[362] = ((char *)src)[362];((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_365(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[364] = ((char *)src)[364];((char *)dst)[363] = ((char *)src)[363];((char *)dst)[362] = ((char *)src)[362];((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_366(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[365] = ((char *)src)[365];((char *)dst)[364] = ((char *)src)[364];((char *)dst)[363] = ((char *)src)[363];((char *)dst)[362] = ((char *)src)[362];((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_367(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<22> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[366] = ((char *)src)[366];((char *)dst)[365] = ((char *)src)[365];((char *)dst)[364] = ((char *)src)[364];((char *)dst)[363] = ((char *)src)[363];((char *)dst)[362] = ((char *)src)[362];((char *)dst)[361] = ((char *)src)[361];((char *)dst)[360] = ((char *)src)[360];((char *)dst)[359] = ((char *)src)[359];((char *)dst)[358] = ((char *)src)[358];((char *)dst)[357] = ((char *)src)[357];((char *)dst)[356] = ((char *)src)[356];((char *)dst)[355] = ((char *)src)[355];((char *)dst)[354] = ((char *)src)[354];((char *)dst)[353] = ((char *)src)[353];((char *)dst)[352] = ((char *)src)[352]; - return dst; - } - static void * _memcpy_368(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_369(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_370(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_371(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_372(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_373(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_374(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_375(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_376(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_377(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_378(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_379(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[378] = ((char *)src)[378];((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_380(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[379] = ((char *)src)[379];((char *)dst)[378] = ((char *)src)[378];((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_381(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[380] = ((char *)src)[380];((char *)dst)[379] = ((char *)src)[379];((char *)dst)[378] = ((char *)src)[378];((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_382(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[381] = ((char *)src)[381];((char *)dst)[380] = ((char *)src)[380];((char *)dst)[379] = ((char *)src)[379];((char *)dst)[378] = ((char *)src)[378];((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_383(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<23> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[382] = ((char *)src)[382];((char *)dst)[381] = ((char *)src)[381];((char *)dst)[380] = ((char *)src)[380];((char *)dst)[379] = ((char *)src)[379];((char *)dst)[378] = ((char *)src)[378];((char *)dst)[377] = ((char *)src)[377];((char *)dst)[376] = ((char *)src)[376];((char *)dst)[375] = ((char *)src)[375];((char *)dst)[374] = ((char *)src)[374];((char *)dst)[373] = ((char *)src)[373];((char *)dst)[372] = ((char *)src)[372];((char *)dst)[371] = ((char *)src)[371];((char *)dst)[370] = ((char *)src)[370];((char *)dst)[369] = ((char *)src)[369];((char *)dst)[368] = ((char *)src)[368]; - return dst; - } - static void * _memcpy_384(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_385(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_386(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_387(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_388(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_389(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_390(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_391(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_392(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_393(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_394(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_395(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[394] = ((char *)src)[394];((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_396(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[395] = ((char *)src)[395];((char *)dst)[394] = ((char *)src)[394];((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_397(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[396] = ((char *)src)[396];((char *)dst)[395] = ((char *)src)[395];((char *)dst)[394] = ((char *)src)[394];((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_398(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[397] = ((char *)src)[397];((char *)dst)[396] = ((char *)src)[396];((char *)dst)[395] = ((char *)src)[395];((char *)dst)[394] = ((char *)src)[394];((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_399(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<24> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[398] = ((char *)src)[398];((char *)dst)[397] = ((char *)src)[397];((char *)dst)[396] = ((char *)src)[396];((char *)dst)[395] = ((char *)src)[395];((char *)dst)[394] = ((char *)src)[394];((char *)dst)[393] = ((char *)src)[393];((char *)dst)[392] = ((char *)src)[392];((char *)dst)[391] = ((char *)src)[391];((char *)dst)[390] = ((char *)src)[390];((char *)dst)[389] = ((char *)src)[389];((char *)dst)[388] = ((char *)src)[388];((char *)dst)[387] = ((char *)src)[387];((char *)dst)[386] = ((char *)src)[386];((char *)dst)[385] = ((char *)src)[385];((char *)dst)[384] = ((char *)src)[384]; - return dst; - } - static void * _memcpy_400(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_401(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_402(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_403(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_404(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_405(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_406(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_407(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_408(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_409(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_410(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_411(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[410] = ((char *)src)[410];((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_412(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[411] = ((char *)src)[411];((char *)dst)[410] = ((char *)src)[410];((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_413(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[412] = ((char *)src)[412];((char *)dst)[411] = ((char *)src)[411];((char *)dst)[410] = ((char *)src)[410];((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_414(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[413] = ((char *)src)[413];((char *)dst)[412] = ((char *)src)[412];((char *)dst)[411] = ((char *)src)[411];((char *)dst)[410] = ((char *)src)[410];((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_415(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<25> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[414] = ((char *)src)[414];((char *)dst)[413] = ((char *)src)[413];((char *)dst)[412] = ((char *)src)[412];((char *)dst)[411] = ((char *)src)[411];((char *)dst)[410] = ((char *)src)[410];((char *)dst)[409] = ((char *)src)[409];((char *)dst)[408] = ((char *)src)[408];((char *)dst)[407] = ((char *)src)[407];((char *)dst)[406] = ((char *)src)[406];((char *)dst)[405] = ((char *)src)[405];((char *)dst)[404] = ((char *)src)[404];((char *)dst)[403] = ((char *)src)[403];((char *)dst)[402] = ((char *)src)[402];((char *)dst)[401] = ((char *)src)[401];((char *)dst)[400] = ((char *)src)[400]; - return dst; - } - static void * _memcpy_416(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_417(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_418(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_419(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_420(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_421(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_422(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_423(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_424(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_425(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_426(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_427(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[426] = ((char *)src)[426];((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_428(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[427] = ((char *)src)[427];((char *)dst)[426] = ((char *)src)[426];((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_429(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[428] = ((char *)src)[428];((char *)dst)[427] = ((char *)src)[427];((char *)dst)[426] = ((char *)src)[426];((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_430(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[429] = ((char *)src)[429];((char *)dst)[428] = ((char *)src)[428];((char *)dst)[427] = ((char *)src)[427];((char *)dst)[426] = ((char *)src)[426];((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_431(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<26> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[430] = ((char *)src)[430];((char *)dst)[429] = ((char *)src)[429];((char *)dst)[428] = ((char *)src)[428];((char *)dst)[427] = ((char *)src)[427];((char *)dst)[426] = ((char *)src)[426];((char *)dst)[425] = ((char *)src)[425];((char *)dst)[424] = ((char *)src)[424];((char *)dst)[423] = ((char *)src)[423];((char *)dst)[422] = ((char *)src)[422];((char *)dst)[421] = ((char *)src)[421];((char *)dst)[420] = ((char *)src)[420];((char *)dst)[419] = ((char *)src)[419];((char *)dst)[418] = ((char *)src)[418];((char *)dst)[417] = ((char *)src)[417];((char *)dst)[416] = ((char *)src)[416]; - return dst; - } - static void * _memcpy_432(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_433(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_434(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_435(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_436(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_437(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_438(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_439(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_440(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_441(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_442(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_443(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[442] = ((char *)src)[442];((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_444(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[443] = ((char *)src)[443];((char *)dst)[442] = ((char *)src)[442];((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_445(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[444] = ((char *)src)[444];((char *)dst)[443] = ((char *)src)[443];((char *)dst)[442] = ((char *)src)[442];((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_446(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[445] = ((char *)src)[445];((char *)dst)[444] = ((char *)src)[444];((char *)dst)[443] = ((char *)src)[443];((char *)dst)[442] = ((char *)src)[442];((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_447(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<27> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[446] = ((char *)src)[446];((char *)dst)[445] = ((char *)src)[445];((char *)dst)[444] = ((char *)src)[444];((char *)dst)[443] = ((char *)src)[443];((char *)dst)[442] = ((char *)src)[442];((char *)dst)[441] = ((char *)src)[441];((char *)dst)[440] = ((char *)src)[440];((char *)dst)[439] = ((char *)src)[439];((char *)dst)[438] = ((char *)src)[438];((char *)dst)[437] = ((char *)src)[437];((char *)dst)[436] = ((char *)src)[436];((char *)dst)[435] = ((char *)src)[435];((char *)dst)[434] = ((char *)src)[434];((char *)dst)[433] = ((char *)src)[433];((char *)dst)[432] = ((char *)src)[432]; - return dst; - } - static void * _memcpy_448(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_449(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_450(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_451(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_452(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_453(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_454(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_455(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_456(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_457(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_458(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_459(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[458] = ((char *)src)[458];((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_460(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[459] = ((char *)src)[459];((char *)dst)[458] = ((char *)src)[458];((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_461(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[460] = ((char *)src)[460];((char *)dst)[459] = ((char *)src)[459];((char *)dst)[458] = ((char *)src)[458];((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_462(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[461] = ((char *)src)[461];((char *)dst)[460] = ((char *)src)[460];((char *)dst)[459] = ((char *)src)[459];((char *)dst)[458] = ((char *)src)[458];((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_463(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<28> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[462] = ((char *)src)[462];((char *)dst)[461] = ((char *)src)[461];((char *)dst)[460] = ((char *)src)[460];((char *)dst)[459] = ((char *)src)[459];((char *)dst)[458] = ((char *)src)[458];((char *)dst)[457] = ((char *)src)[457];((char *)dst)[456] = ((char *)src)[456];((char *)dst)[455] = ((char *)src)[455];((char *)dst)[454] = ((char *)src)[454];((char *)dst)[453] = ((char *)src)[453];((char *)dst)[452] = ((char *)src)[452];((char *)dst)[451] = ((char *)src)[451];((char *)dst)[450] = ((char *)src)[450];((char *)dst)[449] = ((char *)src)[449];((char *)dst)[448] = ((char *)src)[448]; - return dst; - } - static void * _memcpy_464(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_465(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_466(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_467(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_468(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_469(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_470(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_471(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_472(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_473(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_474(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_475(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[474] = ((char *)src)[474];((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_476(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[475] = ((char *)src)[475];((char *)dst)[474] = ((char *)src)[474];((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_477(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[476] = ((char *)src)[476];((char *)dst)[475] = ((char *)src)[475];((char *)dst)[474] = ((char *)src)[474];((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_478(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[477] = ((char *)src)[477];((char *)dst)[476] = ((char *)src)[476];((char *)dst)[475] = ((char *)src)[475];((char *)dst)[474] = ((char *)src)[474];((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_479(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<29> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[478] = ((char *)src)[478];((char *)dst)[477] = ((char *)src)[477];((char *)dst)[476] = ((char *)src)[476];((char *)dst)[475] = ((char *)src)[475];((char *)dst)[474] = ((char *)src)[474];((char *)dst)[473] = ((char *)src)[473];((char *)dst)[472] = ((char *)src)[472];((char *)dst)[471] = ((char *)src)[471];((char *)dst)[470] = ((char *)src)[470];((char *)dst)[469] = ((char *)src)[469];((char *)dst)[468] = ((char *)src)[468];((char *)dst)[467] = ((char *)src)[467];((char *)dst)[466] = ((char *)src)[466];((char *)dst)[465] = ((char *)src)[465];((char *)dst)[464] = ((char *)src)[464]; - return dst; - } - static void * _memcpy_480(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_481(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_482(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_483(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_484(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_485(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_486(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_487(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_488(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_489(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_490(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_491(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[490] = ((char *)src)[490];((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_492(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[491] = ((char *)src)[491];((char *)dst)[490] = ((char *)src)[490];((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_493(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[492] = ((char *)src)[492];((char *)dst)[491] = ((char *)src)[491];((char *)dst)[490] = ((char *)src)[490];((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_494(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[493] = ((char *)src)[493];((char *)dst)[492] = ((char *)src)[492];((char *)dst)[491] = ((char *)src)[491];((char *)dst)[490] = ((char *)src)[490];((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_495(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<30> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[494] = ((char *)src)[494];((char *)dst)[493] = ((char *)src)[493];((char *)dst)[492] = ((char *)src)[492];((char *)dst)[491] = ((char *)src)[491];((char *)dst)[490] = ((char *)src)[490];((char *)dst)[489] = ((char *)src)[489];((char *)dst)[488] = ((char *)src)[488];((char *)dst)[487] = ((char *)src)[487];((char *)dst)[486] = ((char *)src)[486];((char *)dst)[485] = ((char *)src)[485];((char *)dst)[484] = ((char *)src)[484];((char *)dst)[483] = ((char *)src)[483];((char *)dst)[482] = ((char *)src)[482];((char *)dst)[481] = ((char *)src)[481];((char *)dst)[480] = ((char *)src)[480]; - return dst; - } - static void * _memcpy_496(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - static void * _memcpy_497(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_498(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_499(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_500(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_501(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_502(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_503(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_504(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_505(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_506(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_507(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[506] = ((char *)src)[506];((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_508(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[507] = ((char *)src)[507];((char *)dst)[506] = ((char *)src)[506];((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_509(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[508] = ((char *)src)[508];((char *)dst)[507] = ((char *)src)[507];((char *)dst)[506] = ((char *)src)[506];((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_510(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[509] = ((char *)src)[509];((char *)dst)[508] = ((char *)src)[508];((char *)dst)[507] = ((char *)src)[507];((char *)dst)[506] = ((char *)src)[506];((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_511(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<31> type_t; - *(type_t*)dst=*(type_t*)src; - ((char *)dst)[510] = ((char *)src)[510];((char *)dst)[509] = ((char *)src)[509];((char *)dst)[508] = ((char *)src)[508];((char *)dst)[507] = ((char *)src)[507];((char *)dst)[506] = ((char *)src)[506];((char *)dst)[505] = ((char *)src)[505];((char *)dst)[504] = ((char *)src)[504];((char *)dst)[503] = ((char *)src)[503];((char *)dst)[502] = ((char *)src)[502];((char *)dst)[501] = ((char *)src)[501];((char *)dst)[500] = ((char *)src)[500];((char *)dst)[499] = ((char *)src)[499];((char *)dst)[498] = ((char *)src)[498];((char *)dst)[497] = ((char *)src)[497];((char *)dst)[496] = ((char *)src)[496]; - return dst; - } - static void * _memcpy_512(void *dst,const void *src){ - typedef _memcpy_block__memcpy_unit_128_t_t<32> type_t; - *(type_t*)dst=*(type_t*)src; - - return dst; - } - - //这个部分为跳转表 - typedef void* (*_memcpy_func_t)(void *dst,const void *src); - static const _memcpy_func_t got[]={ - _memcpy_0, -_memcpy_1, -_memcpy_2, -_memcpy_3, -_memcpy_4, -_memcpy_5, -_memcpy_6, -_memcpy_7, -_memcpy_8, -_memcpy_9, -_memcpy_10, -_memcpy_11, -_memcpy_12, -_memcpy_13, -_memcpy_14, -_memcpy_15, -_memcpy_16, -_memcpy_17, -_memcpy_18, -_memcpy_19, -_memcpy_20, -_memcpy_21, -_memcpy_22, -_memcpy_23, -_memcpy_24, -_memcpy_25, -_memcpy_26, -_memcpy_27, -_memcpy_28, -_memcpy_29, -_memcpy_30, -_memcpy_31, -_memcpy_32, -_memcpy_33, -_memcpy_34, -_memcpy_35, -_memcpy_36, -_memcpy_37, -_memcpy_38, -_memcpy_39, -_memcpy_40, -_memcpy_41, -_memcpy_42, -_memcpy_43, -_memcpy_44, -_memcpy_45, -_memcpy_46, -_memcpy_47, -_memcpy_48, -_memcpy_49, -_memcpy_50, -_memcpy_51, -_memcpy_52, -_memcpy_53, -_memcpy_54, -_memcpy_55, -_memcpy_56, -_memcpy_57, -_memcpy_58, -_memcpy_59, -_memcpy_60, -_memcpy_61, -_memcpy_62, -_memcpy_63, -_memcpy_64, -_memcpy_65, -_memcpy_66, -_memcpy_67, -_memcpy_68, -_memcpy_69, -_memcpy_70, -_memcpy_71, -_memcpy_72, -_memcpy_73, -_memcpy_74, -_memcpy_75, -_memcpy_76, -_memcpy_77, -_memcpy_78, -_memcpy_79, -_memcpy_80, -_memcpy_81, -_memcpy_82, -_memcpy_83, -_memcpy_84, -_memcpy_85, -_memcpy_86, -_memcpy_87, -_memcpy_88, -_memcpy_89, -_memcpy_90, -_memcpy_91, -_memcpy_92, -_memcpy_93, -_memcpy_94, -_memcpy_95, -_memcpy_96, -_memcpy_97, -_memcpy_98, -_memcpy_99, -_memcpy_100, -_memcpy_101, -_memcpy_102, -_memcpy_103, -_memcpy_104, -_memcpy_105, -_memcpy_106, -_memcpy_107, -_memcpy_108, -_memcpy_109, -_memcpy_110, -_memcpy_111, -_memcpy_112, -_memcpy_113, -_memcpy_114, -_memcpy_115, -_memcpy_116, -_memcpy_117, -_memcpy_118, -_memcpy_119, -_memcpy_120, -_memcpy_121, -_memcpy_122, -_memcpy_123, -_memcpy_124, -_memcpy_125, -_memcpy_126, -_memcpy_127, -_memcpy_128, -_memcpy_129, -_memcpy_130, -_memcpy_131, -_memcpy_132, -_memcpy_133, -_memcpy_134, -_memcpy_135, -_memcpy_136, -_memcpy_137, -_memcpy_138, -_memcpy_139, -_memcpy_140, -_memcpy_141, -_memcpy_142, -_memcpy_143, -_memcpy_144, -_memcpy_145, -_memcpy_146, -_memcpy_147, -_memcpy_148, -_memcpy_149, -_memcpy_150, -_memcpy_151, -_memcpy_152, -_memcpy_153, -_memcpy_154, -_memcpy_155, -_memcpy_156, -_memcpy_157, -_memcpy_158, -_memcpy_159, -_memcpy_160, -_memcpy_161, -_memcpy_162, -_memcpy_163, -_memcpy_164, -_memcpy_165, -_memcpy_166, -_memcpy_167, -_memcpy_168, -_memcpy_169, -_memcpy_170, -_memcpy_171, -_memcpy_172, -_memcpy_173, -_memcpy_174, -_memcpy_175, -_memcpy_176, -_memcpy_177, -_memcpy_178, -_memcpy_179, -_memcpy_180, -_memcpy_181, -_memcpy_182, -_memcpy_183, -_memcpy_184, -_memcpy_185, -_memcpy_186, -_memcpy_187, -_memcpy_188, -_memcpy_189, -_memcpy_190, -_memcpy_191, -_memcpy_192, -_memcpy_193, -_memcpy_194, -_memcpy_195, -_memcpy_196, -_memcpy_197, -_memcpy_198, -_memcpy_199, -_memcpy_200, -_memcpy_201, -_memcpy_202, -_memcpy_203, -_memcpy_204, -_memcpy_205, -_memcpy_206, -_memcpy_207, -_memcpy_208, -_memcpy_209, -_memcpy_210, -_memcpy_211, -_memcpy_212, -_memcpy_213, -_memcpy_214, -_memcpy_215, -_memcpy_216, -_memcpy_217, -_memcpy_218, -_memcpy_219, -_memcpy_220, -_memcpy_221, -_memcpy_222, -_memcpy_223, -_memcpy_224, -_memcpy_225, -_memcpy_226, -_memcpy_227, -_memcpy_228, -_memcpy_229, -_memcpy_230, -_memcpy_231, -_memcpy_232, -_memcpy_233, -_memcpy_234, -_memcpy_235, -_memcpy_236, -_memcpy_237, -_memcpy_238, -_memcpy_239, -_memcpy_240, -_memcpy_241, -_memcpy_242, -_memcpy_243, -_memcpy_244, -_memcpy_245, -_memcpy_246, -_memcpy_247, -_memcpy_248, -_memcpy_249, -_memcpy_250, -_memcpy_251, -_memcpy_252, -_memcpy_253, -_memcpy_254, -_memcpy_255, -_memcpy_256, -_memcpy_257, -_memcpy_258, -_memcpy_259, -_memcpy_260, -_memcpy_261, -_memcpy_262, -_memcpy_263, -_memcpy_264, -_memcpy_265, -_memcpy_266, -_memcpy_267, -_memcpy_268, -_memcpy_269, -_memcpy_270, -_memcpy_271, -_memcpy_272, -_memcpy_273, -_memcpy_274, -_memcpy_275, -_memcpy_276, -_memcpy_277, -_memcpy_278, -_memcpy_279, -_memcpy_280, -_memcpy_281, -_memcpy_282, -_memcpy_283, -_memcpy_284, -_memcpy_285, -_memcpy_286, -_memcpy_287, -_memcpy_288, -_memcpy_289, -_memcpy_290, -_memcpy_291, -_memcpy_292, -_memcpy_293, -_memcpy_294, -_memcpy_295, -_memcpy_296, -_memcpy_297, -_memcpy_298, -_memcpy_299, -_memcpy_300, -_memcpy_301, -_memcpy_302, -_memcpy_303, -_memcpy_304, -_memcpy_305, -_memcpy_306, -_memcpy_307, -_memcpy_308, -_memcpy_309, -_memcpy_310, -_memcpy_311, -_memcpy_312, -_memcpy_313, -_memcpy_314, -_memcpy_315, -_memcpy_316, -_memcpy_317, -_memcpy_318, -_memcpy_319, -_memcpy_320, -_memcpy_321, -_memcpy_322, -_memcpy_323, -_memcpy_324, -_memcpy_325, -_memcpy_326, -_memcpy_327, -_memcpy_328, -_memcpy_329, -_memcpy_330, -_memcpy_331, -_memcpy_332, -_memcpy_333, -_memcpy_334, -_memcpy_335, -_memcpy_336, -_memcpy_337, -_memcpy_338, -_memcpy_339, -_memcpy_340, -_memcpy_341, -_memcpy_342, -_memcpy_343, -_memcpy_344, -_memcpy_345, -_memcpy_346, -_memcpy_347, -_memcpy_348, -_memcpy_349, -_memcpy_350, -_memcpy_351, -_memcpy_352, -_memcpy_353, -_memcpy_354, -_memcpy_355, -_memcpy_356, -_memcpy_357, -_memcpy_358, -_memcpy_359, -_memcpy_360, -_memcpy_361, -_memcpy_362, -_memcpy_363, -_memcpy_364, -_memcpy_365, -_memcpy_366, -_memcpy_367, -_memcpy_368, -_memcpy_369, -_memcpy_370, -_memcpy_371, -_memcpy_372, -_memcpy_373, -_memcpy_374, -_memcpy_375, -_memcpy_376, -_memcpy_377, -_memcpy_378, -_memcpy_379, -_memcpy_380, -_memcpy_381, -_memcpy_382, -_memcpy_383, -_memcpy_384, -_memcpy_385, -_memcpy_386, -_memcpy_387, -_memcpy_388, -_memcpy_389, -_memcpy_390, -_memcpy_391, -_memcpy_392, -_memcpy_393, -_memcpy_394, -_memcpy_395, -_memcpy_396, -_memcpy_397, -_memcpy_398, -_memcpy_399, -_memcpy_400, -_memcpy_401, -_memcpy_402, -_memcpy_403, -_memcpy_404, -_memcpy_405, -_memcpy_406, -_memcpy_407, -_memcpy_408, -_memcpy_409, -_memcpy_410, -_memcpy_411, -_memcpy_412, -_memcpy_413, -_memcpy_414, -_memcpy_415, -_memcpy_416, -_memcpy_417, -_memcpy_418, -_memcpy_419, -_memcpy_420, -_memcpy_421, -_memcpy_422, -_memcpy_423, -_memcpy_424, -_memcpy_425, -_memcpy_426, -_memcpy_427, -_memcpy_428, -_memcpy_429, -_memcpy_430, -_memcpy_431, -_memcpy_432, -_memcpy_433, -_memcpy_434, -_memcpy_435, -_memcpy_436, -_memcpy_437, -_memcpy_438, -_memcpy_439, -_memcpy_440, -_memcpy_441, -_memcpy_442, -_memcpy_443, -_memcpy_444, -_memcpy_445, -_memcpy_446, -_memcpy_447, -_memcpy_448, -_memcpy_449, -_memcpy_450, -_memcpy_451, -_memcpy_452, -_memcpy_453, -_memcpy_454, -_memcpy_455, -_memcpy_456, -_memcpy_457, -_memcpy_458, -_memcpy_459, -_memcpy_460, -_memcpy_461, -_memcpy_462, -_memcpy_463, -_memcpy_464, -_memcpy_465, -_memcpy_466, -_memcpy_467, -_memcpy_468, -_memcpy_469, -_memcpy_470, -_memcpy_471, -_memcpy_472, -_memcpy_473, -_memcpy_474, -_memcpy_475, -_memcpy_476, -_memcpy_477, -_memcpy_478, -_memcpy_479, -_memcpy_480, -_memcpy_481, -_memcpy_482, -_memcpy_483, -_memcpy_484, -_memcpy_485, -_memcpy_486, -_memcpy_487, -_memcpy_488, -_memcpy_489, -_memcpy_490, -_memcpy_491, -_memcpy_492, -_memcpy_493, -_memcpy_494, -_memcpy_495, -_memcpy_496, -_memcpy_497, -_memcpy_498, -_memcpy_499, -_memcpy_500, -_memcpy_501, -_memcpy_502, -_memcpy_503, -_memcpy_504, -_memcpy_505, -_memcpy_506, -_memcpy_507, -_memcpy_508, -_memcpy_509, -_memcpy_510, -_memcpy_511, -_memcpy_512, - - }; - -//入口放在class作为静态方法.. -//class xmemcpy{ -//public: -static void *xmemcpy(void *dst,const void *src,size_t len){ -//这里使用long是合理的. -long _offset=(long)dst-(long)src; -//位置重叠或者是len过长.. -if(len>512 || (_offset<(long)len && _offset>(0-(long)len))){ -return ::memcpy(dst,src,len); -}else{ -return ZY::got[len](dst,src); -} -} -//}; -} -#endif diff --git a/bsl/containers/btree/df_2d_ary.h b/bsl/containers/btree/df_2d_ary.h deleted file mode 100644 index 40516c8dafed894b6cd9fe6aa53667a22089297d..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_2d_ary.h +++ /dev/null @@ -1,3418 +0,0 @@ -////==================================================================== -// -// df_2d_ary.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-01-05 by YANG Zhenkun (yangzhenkun@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration and implementation of dfs_bt2d_ary_t (2-dimension array) template -// -// ------------------------------------------------------------------- -// -// Change Log -// -// updated on 2008-07-28 by YANG Zhenkun (yangzhenkun@baidu.com) -// -////==================================================================== - -#ifndef __DF_2D_ARY_INCLUDE_H_ -#define __DF_2D_ARY_INCLUDE_H_ - -//调试信息打印输出开关 -//#ifndef DF_BT_PRINT_DEBUG_INFO -//#define DF_BT_PRINT_DEBUG_INFO -//#endif - -# if defined __x86_64__ -# else -# error "MUST COMPILED ON x86_64" -# endif - -#include -#include -#include -#include - -/* #include "ul_def.h" */ -/* #include "ul_log.h" */ -//#include "df_common.h" -#include "df_log.h" -#include "df_misc.h" - -//#ifndef DF_BT_PRINT_DEBUG_INFO -//#define DF_BT_PRINT_DEBUG_INFO -//#endif - - -static const uint64_t UNDEF_INDEX = MAX_U_INT64; -static const uint64_t NULL_INDEX = ((uint64_t)0ULL); -static const uint64_t UNDEF_ID = UNDEF_INDEX; -static const uint64_t NULL_ID = NULL_INDEX; - - - -//pvoid: pointer to void -#ifndef _pvoid_defined -typedef void *pvoid; -#define _pvoid_defined -#endif - -//pchar: pointer to char -#ifndef _pchar_defined -typedef char *pchar; -#define _pchar_defined -#endif - -//pcchar: pointer to const char -#ifndef _pcchar_defined -typedef const char *pcchar; -#define _pcchar_defined -#endif - - - -/* //功能:记录一个内部错误代码。 */ -/* //返回:前次的错误代码。 */ -/* int dfs_bt_set_internal_err( */ -/* const int err, */ -/* const int lineno = -1, */ -/* const char * funcname = NULL, */ -/* const char * filename = NULL); */ -/* //功能:记录一个普通错误代码。 */ -/* //返回:前次的错误代码。 */ -/* int dfs_bt_set_normal_err( */ -/* const int err, */ -/* const int lineno = -1, */ -/* const char * funcname = NULL, */ -/* const char * filename = NULL); */ -/* ////返回:最后的错误代码。 */ -/* //int dfs_bt_get_last_error(void); */ - - -/* #define DF_BT_SET_INTERNAL_ERR(err) dfs_bt_set_internal_err(err, __LINE__, __FUNCTION__, __FILE__) */ -/* #define DF_BT_SET_NORMAL_ERR(err) dfs_bt_set_normal_err(err, __LINE__, __FUNCTION__, __FILE__) */ -#define DF_BT_SET_INTERNAL_ERR(err) 0 -#define DF_BT_SET_NORMAL_ERR(err) 0 - -/* #ifdef DF_TEST_BTREE */ -/* extern volatile uint64_t s_dfs_bt_debug_trap_counter; */ -/* uint64_t dfs_bt_debug_trap(void); */ -/* #define DFS_BT_DEBUG_TRAP dfs_bt_debug_trap() */ -/* #else */ -/* #define DFS_BT_DEBUG_TRAP */ -/* #endif */ -#define DFS_BT_DEBUG_TRAP - - -#define ERRINFO_BT_NUM_ENCODE_BUF "error encode buf/data" -#define ERRINFO_BT_NUM_DECODE_BUF "error decode buf/data" -#define ERRINFO_BT_STORE_POS "error store pos" -#define ERRINFO_BT_STORE_BUF "error store buf" -#define ERRINFO_BT_STORE_TYPE "error store type" -#define ERRINFO_BT_LOAD_POS "error load pos" -#define ERRINFO_BT_LOAD_BUF "error load buf" -#define ERRINFO_BT_LOAD_MAJOR_TAG "error load major tag" -#define ERRINFO_BT_LOAD_MINOR_TAG "error load minor tag" -#define ERRINFO_BT_LOAD_HEAD_VER "error load head version" -#define ERRINFO_BT_LOAD_HEAD_SIZE "error load head size" -#define ERRINFO_BT_LOAD_KEY_NODE_NUM "error load key/node num" -#define ERRINFO_BT_LOAD_MAX_ID "get_next_allocate_id() > 1 && pcdu->get_id() >= get_next_allocate_id()" -#define ERRINFO_BT_NOMEM "%s == NULL" -#define ERRINFO_BT_DEL "" -#define ERRINFO_BT_NULL_BUF_POINTER "" -#define ERRINFO_BT_OBJ_NULL_POINTER "" -#define ERRINFO_BT_NOT_NULL_BUF_POINTER "" -#define ERRINFO_BT_NOT_OBJ_NULL_POINTER "" -#define ERRINFO_BT_2D_BASE_FREE "" -#define ERRINFO_BT_2D_BASE_IN_USE "" -#define ERRINFO_BT_BUF_SIZE "insuffient buffer size or null buffer" -#define ERRINFO_BT_BUF_POS "" -#define ERRINFO_BT_DIFF_POINTER "" -#define ERRINFO_BT_DIFF_INDEX "" -#define ERRINFO_BT_DIFF_ID "" -#define ERRINFO_BT_INVALID_ID "" -#define ERRINFO_BT_INVALID_INDEX "" -#define ERRINFO_BT_REF_COUNTER "" -#define ERRINFO_BT_DIFF_NUM_IN_BT_2D_ARY "" -#define ERRINFO_BT_OBJ_ACQUIRE "" -#define ERRINFO_BT_KEY_SIZE "" -#define ERRINFO_BT_KEY_MARK "" -#define ERRINFO_BT_KEY_POS "" -#define ERRINFO_BT_KEY_NOT_EXIST "error not existed key" -#define ERRINFO_BT_KEY_INVALID "error invalid key" -#define ERRINFO_BT_NODE_INDEX "" -#define ERRINFO_BT_ROOT_NODE_INDEX "" -#define ERRINFO_BT_MID_NODE_INDEX "" -#define ERRINFO_BT_LEAF_NODE_INDEX "" -#define ERRINFO_BT_MID_NODE_ACQUIRE "" -#define ERRINFO_BT_LEAF_NODE_ACQUIRE "" -#define ERRINFO_BT_NODE_NULL_POINTER "" -#define ERRINFO_BT_MID_NODE_NULL_POINTER "" -#define ERRINFO_BT_LEAF_NODE_NULL_POINTER "" -#define ERRINFO_BT_RESERVED_MID_NODE "" -#define ERRINFO_BT_RESERVED_LEAF_NODE "" -#define ERRINFO_BT_HETEROGENEOUS_MID_NODE "" -#define ERRINFO_BT_NODE_POS "" -#define ERRINFO_BT_NODE_NUM "" -#define ERRINFO_BT_NODE_NOTFULL_SPLIT "" -#define ERRINFO_BT_KEY_INDEX "" -#define ERRINFO_BT_KEY_ACQUIRE "" -#define ERRINFO_BT_KEY_NULL_POINTER "" -#define ERRINFO_BT_SUBKEY_POS "" -#define ERRINFO_BT_SUBKEY_NUM "" -#define ERRINFO_BT_SUBKEY_ORDER "" -#define ERRINFO_BT_SUBKEY_OVERFLOW "" -#define ERRINFO_BT_SUBKEY_UNDERFLOW "" -#define ERRINFO_BT_SUBKEY_INDEX "" -#define ERRINFO_BT_SUBNODE_INDEX "" -#define ERRINFO_BT_CKP_STATE "error ckp state" -#define ERRINFO_BT_CKP_ROOT "UNDEF_INDEX != ckp_root_index|| ckp_mutation_counter > 0" -#define ERRINFO_BT_CKP_SERIAL_READ_WRITE "checkpoint is not allowed during serial_read_write" -#define ERRINFO_BT_CKP_CANCELLED "" -#define ERRINFO_BT_CKP_FAIL "" -#define ERRINFO_BT_DRILL_OVERFLOW "" -#define ERRINFO_BT_DRILL_UNDERFLOW "" -#define ERRINFO_BT_DRILL_POS "" -#define ERRINFO_BT_DRILL_INS_POS "" -#define ERRINFO_BT_DRILL_NODE_INDEX "" -#define ERRINFO_BT_DRILL_KEY_INDEX "" -#define ERRINFO_BT_DRILL_NODE_NULL_POINTER "" -#define ERRINFO_BT_DRILL_KEY_NULL_POINTER "" -#define ERRINFO_BT_DRILL_DEL_NODE_POS "" -#define ERRINFO_BT_DRILL_DEL_NODE_INDEX "" -#define ERRINFO_BT_MUTATE_TYPE "" -#define ERRINFO_BT_NULL_ID "" -#define ERRINFO_BT_NOTNULL_ID "" -#define ERRINFO_BT_UNDEF_NAME_ID "" -#define ERRINFO_BT_NULL_PREFIX_ID "" -#define ERRINFO_BT_NOTNULL_PREFIX_ID "" -#define ERRINFO_BT_UNDEF_PREFIX_ID "" -#define ERRINFO_BT_UNDEF_SUFFIX_ID "" -#define ERRINFO_BT_UNDEF_NAME_INDEX "" -#define ERRINFO_BT_NONE_EMPTY_PREFIX_BTREE "" -#define ERRINFO_BT_NONE_EMPTY_SUFFIX_BTREE "" -#define ERRINFO_BT_NONE_EMPTY_BTREE "" -#define ERRINFO_BT_NONE_EMPTY_BUF "" -#define ERRINFO_BT_T_LEAK "" -#define ERRINFO_BT_DIFF_FP_ID_BTREE "" -#define ERRINFO_BT_WRITE_FILE "" -#define ERRINFO_BT_READ_FILE "" -#define ERRINFO_BT_FILE_POS "" -#define ERRINFO_BT_TIMEOUT "" -#define ERRINFO_BT_MUTATION_COUNTER "" -#define ERRINFO_BT_OFFSET "" -#define ERRINFO_BT_SET_GC_INFO "" -#define ERRINFO_BT_OBJ_FREE_IN_USE_STATE "" -#define ERRINFO_BT_COW_ONCOW_RETRY "" -#define ERRINFO_BT_COW_NUM "" -#define ERRINFO_BT_COW_MUTATION_COUNTER "" -#define ERRINFO_BT_LOCK_RE_RELEASE "error re-released btree mutate lock" -#define ERRINFO_BT_LOCK_HOLD_VERIFY "error btree mutate locke verify failed" -#define ERRINFO_BT_WRITE_ONLY "error btree is write only" - - - -#define BT_DF_WRITE_LOG_BYTES(log_level, info, buf, data_len) \ -{ \ - int64_t _j = 0; \ - const int64_t _n = (int64_t)data_len; \ - if (NULL != (info)) \ - { \ - DF_WRITE_LOG_US(log_level, "%s,len=%ld", info, _n); \ - } \ - if (NULL != (buf) && _n > 0) \ - { \ - while (_j < _n) \ - { \ - DF_WRITE_LOG_US(log_level, \ - "%.2x%.2x%.2x%.2x %.2x%.2x%.2x%.2x", \ - (buf)[_j], (buf)[_j+1], \ - (buf)[_j+2], (buf)[_j+3], \ - (buf)[_j+4], (buf)[_j+5], \ - (buf)[_j+6], (buf)[_j+7]); \ - _j += 8; \ - } \ - } \ -} \ - -#define BT_DF_WRITE_LOG_INT32S(log_level, info, buf, data_len) \ -{ \ - int64_t _j = 0; \ - const int64_t _n = (int64_t)data_len; \ - if (NULL != (info)) \ - { \ - DF_WRITE_LOG_US(log_level, "%s,len=%ld", info, _n); \ - } \ - if (NULL != (buf) && _n > 0) \ - { \ - while (_j < _n) \ - { \ - DF_WRITE_LOG_US(log_level, \ - "0x%.4x 0x%.4x 0x%.4x 0x%.4x", \ - (buf)[_j], (buf)[_j+1], \ - (buf)[_j+2], (buf)[_j+3]); \ - j += 4; \ - } \ - } \ -} \ - -#define BT_DF_WRITE_LOG_INT64S(log_level, info, buf, data_len) \ -{ \ - int64_t _j = 0; \ - const int64_t _n = (int64_t)data_len; \ - if (NULL != (info)) \ - { \ - DF_WRITE_LOG_US(log_level, "%s,len=%ld", info, _n); \ - } \ - if (NULL != (buf) && _n > 0) \ - { \ - while (_j < _n) \ - { \ - DF_WRITE_LOG_US(log_level, \ - "0x%lx 0x%lx", \ - (buf)[_j], (buf)[_j+1]); \ - _j += 2; \ - } \ - } \ -} \ - -//internal errno -class dfs_bt_const_t { -public: - enum DFS_BT_ERRNO_MASK { - ERRNO_BT_INTERNAL_ERR_FLAG = 0x40000000, - ERRNO_BT_ERR_NO_MASK = 0x0000ffff, - }; - enum DFS_BT_ERR_SYS { - ERRNO_BT_BASE_SYS = 0, //(ERRNO_BT_ERR_NO_MASK+1)*2 , - }; - enum DFS_BT_ERR_NO { - ERRNO_BT_TEST_ERR = 0x1111 , - ERRNO_BT_BUILD_IN_MIN_NO = 0x2000 , - ERRNO_BT_NUM_ENCODE_BUF = ERRNO_BT_BUILD_IN_MIN_NO, - ERRNO_BT_NUM_DECODE_BUF , - ERRNO_BT_STORE_POS , - ERRNO_BT_STORE_BUF , - ERRNO_BT_STORE_TYPE , - ERRNO_BT_LOAD_POS , - ERRNO_BT_LOAD_BUF , - ERRNO_BT_LOAD_MAJOR_TAG , - ERRNO_BT_LOAD_MINOR_TAG , - ERRNO_BT_LOAD_HEAD_VER , - ERRNO_BT_LOAD_HEAD_SIZE , - ERRNO_BT_LOAD_KEY_NODE_NUM , - ERRNO_BT_LOAD_MAX_ID , - ERRNO_BT_NOMEM , - ERRNO_BT_DEL , - ERRNO_BT_NULL_BUF_POINTER , - ERRNO_BT_OBJ_NULL_POINTER , - ERRNO_BT_NOT_NULL_BUF_POINTER , - ERRNO_BT_NOT_OBJ_NULL_POINTER , - ERRNO_BT_2D_BASE_FREE , - ERRNO_BT_2D_BASE_IN_USE , - ERRNO_BT_BUF_SIZE , - ERRNO_BT_BUF_POS , - ERRNO_BT_DIFF_POINTER , - ERRNO_BT_DIFF_INDEX , - ERRNO_BT_DIFF_ID , - ERRNO_BT_INVALID_ID , - ERRNO_BT_INVALID_INDEX , - ERRNO_BT_REF_COUNTER , - ERRNO_BT_DIFF_NUM_IN_BT_2D_ARY , //diff nums in btree and 2d_ary - ERRNO_BT_OBJ_ACQUIRE , - ERRNO_BT_KEY_SIZE , - ERRNO_BT_KEY_MARK , - ERRNO_BT_KEY_POS , - ERRNO_BT_KEY_NOT_EXIST , - ERRNO_BT_KEY_INVALID , - ERRNO_BT_NODE_INDEX , - ERRNO_BT_ROOT_NODE_INDEX , - ERRNO_BT_MID_NODE_INDEX , - ERRNO_BT_LEAF_NODE_INDEX , - ERRNO_BT_MID_NODE_ACQUIRE , - ERRNO_BT_LEAF_NODE_ACQUIRE , - ERRNO_BT_NODE_NULL_POINTER , - ERRNO_BT_MID_NODE_NULL_POINTER , - ERRNO_BT_LEAF_NODE_NULL_POINTER , - ERRNO_BT_RESERVED_MID_NODE , - ERRNO_BT_RESERVED_LEAF_NODE , - ERRNO_BT_HETEROGENEOUS_MID_NODE , - ERRNO_BT_NODE_POS , - ERRNO_BT_NODE_NUM , - ERRNO_BT_NODE_NOTFULL_SPLIT , - ERRNO_BT_KEY_INDEX , - ERRNO_BT_KEY_ACQUIRE , - ERRNO_BT_KEY_NULL_POINTER , - ERRNO_BT_SUBKEY_POS , - ERRNO_BT_SUBKEY_NUM , - ERRNO_BT_SUBKEY_ORDER , - ERRNO_BT_SUBKEY_OVERFLOW , - ERRNO_BT_SUBKEY_UNDERFLOW , - ERRNO_BT_SUBKEY_INDEX , - ERRNO_BT_SUBNODE_INDEX , - ERRNO_BT_CKP_STATE , - ERRNO_BT_CKP_ROOT , //_ckp_root_info内容异常 - ERRNO_BT_CKP_SERIAL_READ_WRITE , //串行读写时候禁止设置checkpoint - ERRNO_BT_CKP_CANCELLED , - ERRNO_BT_CKP_FAIL , - ERRNO_BT_DRILL_OVERFLOW , - ERRNO_BT_DRILL_UNDERFLOW , - ERRNO_BT_DRILL_POS , - ERRNO_BT_DRILL_INS_POS , - ERRNO_BT_DRILL_NODE_INDEX , - ERRNO_BT_DRILL_KEY_INDEX , - ERRNO_BT_DRILL_NODE_NULL_POINTER , - ERRNO_BT_DRILL_KEY_NULL_POINTER , - ERRNO_BT_DRILL_DEL_NODE_POS , - ERRNO_BT_DRILL_DEL_NODE_INDEX , - ERRNO_BT_MUTATE_TYPE , - ERRNO_BT_NULL_ID , - ERRNO_BT_NOTNULL_ID , - ERRNO_BT_UNDEF_NAME_ID , - ERRNO_BT_NULL_PREFIX_ID , - ERRNO_BT_NOTNULL_PREFIX_ID , - ERRNO_BT_UNDEF_PREFIX_ID , - ERRNO_BT_UNDEF_SUFFIX_ID , - ERRNO_BT_UNDEF_NAME_INDEX , - ERRNO_BT_NONE_EMPTY_PREFIX_BTREE , - ERRNO_BT_NONE_EMPTY_SUFFIX_BTREE , - ERRNO_BT_NONE_EMPTY_BTREE , - ERRNO_BT_NONE_EMPTY_BUF , - ERRNO_BT_T_LEAK , - ERRNO_BT_DIFF_SF_ID_BTREE , - ERRNO_BT_WRITE_FILE , - ERRNO_BT_READ_FILE , - ERRNO_BT_FILE_POS , - ERRNO_BT_TIMEOUT , - ERRNO_BT_MUTATION_COUNTER , - ERRNO_BT_OFFSET , - ERRNO_BT_SET_GC_INFO , - ERRNO_BT_OBJ_FREE_IN_USE_STATE , - ERRNO_BT_COW_ONCOW_RETRY , - ERRNO_BT_COW_NUM , - ERRNO_BT_COW_MUTATION_COUNTER , - ERRNO_BT_LOCK_RE_RELEASE , - ERRNO_BT_LOCK_HOLD_VERIFY , - ERRNO_BT_WRITE_ONLY , //B树为只写模式 - ERRNO_BT_BUILD_IN_MAX_NO , //must be the last one - }; - enum DFS_BT_CONST { - DEF_ROW_SIZE = 8192 , //二维数组行 - DEF_ROW_ARY_SIZE = 256 , //二维数组列 - DEF_KEY_BUF_SIZE = 0x20000 , //128KB char - MAX_BT_DEPTH = 64 , - UNDEF_POS = MAX_U_INT32 , - DEF_FANOUT = 17 , //B树的扇出: dfs_bt_obj_t(2*8-byte), dfs_btree_node_base_t((2+(DEF_FANOUT-1))*8-byte) - MIN_FANOUT = 5 , - MAX_FANOUT = 4090 , - MICROSECONDS_PER_SLEEP = 20 , - MAX_2D_ARY_HOLD_REALLOC_NUM = 16 , //暂存的重新申请的二维数组的索引个数(每次扩大一倍) - MAX_T_STORE_SIZE = 0x80000 , //512KB,单个对象T的存储尺寸上限 - MAX_BT_ROOT_ONCOW_RETRY_NUM = 16384*1024 , //锁定树根节点重试次数(microseconds), about 256s - MAX_BT_RC_ROOT_NUM = 1024 , //一个B树同一时间被读写的总个数 - MAX_BT_INSTANCE_NUM = 4 , //基本btree树在实例中的个数,一般为1,fp_btree中为4, ns_btree为2 - DEF_BT_INSTANCE_POS = 0 , //基本btree树在一系列实例中的序号,一般为0,fp_btree中为0~3 - - BT_FANOUT = DEF_FANOUT , - BT_LEAF_ROW_SIZE = DEF_ROW_SIZE/16 , - BT_MID_ROW_SIZE = DEF_ROW_SIZE/64 , - }; - static bool is_internal_err(const int err) { - return ((err & ERRNO_BT_INTERNAL_ERR_FLAG) != 0); - }; - static const uint64_t UNDEF_OFFSET = MAX_U_INT64; - static const uint64_t UNDEF_REF_COUNTER = MAX_U_INT64; - static const uint64_t MAX_ARY_INDEX = (1ULL<<(64-16-1))-3; //at most 2**47 = 128T indexes. -public: - //uint64_t: encode & decode - static const uint64_t ENCODE_1B_MAX = 128UL-1; - static const uint8_t ENCODE_1B_BASE = 0; - static const uint64_t ENCODE_2B_MAX = 128UL*128UL-1; - static const uint8_t ENCODE_2B_BASE = 0x80; - static const uint64_t ENCODE_3B_MAX = 128UL*128UL*128UL-1; - static const uint8_t ENCODE_3B_BASE = 0x80+0x40; - static const uint64_t ENCODE_4B_MAX = 128UL*128UL*128UL*128UL-1; - static const uint8_t ENCODE_4B_BASE = 0x80+0x40+0x20; - static const uint64_t ENCODE_5B_MAX = 128UL*128UL*128UL*128UL*128UL-1; - static const uint8_t ENCODE_5B_BASE = 0x80+0x40+0x20+0x10; - static const uint64_t ENCODE_6B_MAX = 128UL*128UL*128UL*128UL*128UL*128UL-1; - static const uint8_t ENCODE_6B_BASE = 0x80+0x40+0x20+0x10+0x08; - static const uint64_t ENCODE_7B_MAX = 128UL*128UL*128UL*128UL*128UL*128UL*128UL-1; - static const uint8_t ENCODE_7B_BASE = 0x80+0x40+0x20+0x10+0x08+0x04; - static const uint8_t ENCODE_8B_BASE = 0x80+0x40+0x20+0x10+0x08+0x04+0x02; - //at least 9 bytes space - static int encode_num( - const uint64_t data, - char * buf, - const uint64_t buf_size, - uint64_t & data_pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - int j = 0; - unsigned char base = 0; - - if (NULL == buf || (data_pos+9) > buf_size) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NUM_ENCODE_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NUM_ENCODE_BUF); - } else { - if (data <= ENCODE_1B_MAX) { - j = (1-1)*8; - base = ENCODE_1B_BASE; - } else if (data <= ENCODE_2B_MAX) { - j = (2-1)*8; - base = ENCODE_2B_BASE; - } else if (data <= ENCODE_3B_MAX) { - j = (3-1)*8; - base = ENCODE_3B_BASE; - } else if (data <= ENCODE_4B_MAX) { - j = (4-1)*8; - base = ENCODE_4B_BASE; - } else if (data <= ENCODE_5B_MAX) { - j = (5-1)*8; - base = ENCODE_5B_BASE; - } else if (data <= ENCODE_6B_MAX) { - j = (6-1)*8; - base = ENCODE_6B_BASE; - } else if (data <= ENCODE_7B_MAX) { - j = (7-1)*8; - base = ENCODE_7B_BASE; - } else { - buf[data_pos++] = (unsigned char)ENCODE_8B_BASE; - j = (8-1)*8; - base = 0; - } - buf[data_pos++] = (unsigned char)base|(unsigned char)(data>>j); - while(j > 0) { - j -= 8; - buf[data_pos++] = (unsigned char)(data>>j); - } - } - return err; - }; - //at least 9 bytes data - static int decode_num( - uint64_t & data, - const char * buf, - const uint64_t data_len, - uint64_t & data_pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - int j = 0; - unsigned char base = 0; - - if (NULL == buf || (data_pos+9) > data_len) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NUM_DECODE_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NUM_DECODE_BUF); - } else { - data = 0; - base = buf[data_pos++]; - if (base < ENCODE_2B_BASE) { - j = (1-1); - data = base - ENCODE_1B_BASE; - } else if (base < ENCODE_3B_BASE) { - j = (2-1); - data = base - ENCODE_2B_BASE; - } else if (base < ENCODE_4B_BASE) { - j = (3-1); - data = base - ENCODE_3B_BASE; - } else if (base < ENCODE_5B_BASE) { - j = (4-1); - data = base - ENCODE_4B_BASE; - } else if (base < ENCODE_6B_BASE) { - j = (5-1); - data = base - ENCODE_5B_BASE; - } else if (base < ENCODE_7B_BASE) { - j = (6-1); - data = base - ENCODE_6B_BASE; - } else if (base < ENCODE_8B_BASE) { - j = (7-1); - data = base - ENCODE_7B_BASE; - } else { - j = (8-1); - data = buf[data_pos++]; - } - while(j > 0) { - --j; - data = (data<<8)|((unsigned char)buf[data_pos++]); - } - } - return err; - }; - -}; - -template -class dfs_gc_du_t : public T { -private: - typedef T *PT; - typedef const T *PCT; -public: - dfs_gc_du_t() : T() { - }; - const dfs_gc_du_t & operator=(const dfs_gc_du_t & src) { - if (&src != this) { - *((T *)this) = (const T &)src; - } - return *this; - }; - const dfs_gc_du_t & operator=(const T & tobj) { - if (&tobj != this) { - *((T *)this) = tobj; - } - return *this; - }; - dfs_gc_du_t(const dfs_gc_du_t & src) : T((const T &)src) { - //*this = src; - }; - dfs_gc_du_t(const T & tobj) { - if ((T *)this != &tobj) { - *((T *)this) = tobj; - } - }; - ~dfs_gc_du_t() { - }; - void init(void) { //初始化对象 - T::init(); - }; -public: - //增加时所做的操作 - inline int action_while_added(void * /*pgc_info*/, - const uint64_t /*t_index*/) { - return 0; - }; - //删除前所做的操作 - inline int action_before_gc(void * /*pgc_info*/, - const uint64_t /*t_index*/) { - return 0; - }; -}; - - - -//dfs_2d_base_t:记录一个对象是否使用,如果在使用中,则记录了其应用计数(最大2**60-3), -// 如果是自由对象,则记录其指向下一个自由对象的index(最大2**60-3) -// 引用计数与下一个对象的index不能同时表示 -// 在单申请多释放模式下,作为引用计数还是作为单向链表都是线程安全的(无锁多线程加减元素) -//该类可作为二维数组dfs_bt2d_ary_t的数据类型的基类,也可用作其他可回收对象的基类 -class dfs_2d_base_t : public dfs_bt_const_t { -private: - //highest bit: 1 for free, 0 for in_use - //lowest 60 bits: for ref_counter or ~next_index - volatile uint64_t _ref_counter_next_index; -private: - enum cconst_private { - FREE_FLAG_BIT = 63, //this unit is in use - PAY_LOAD_BITS = 60, - }; - //有效载荷... - const static uint64_t PAY_LOAD_MASK = ((((uint64_t)0x1)<= MAX_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ref_counter >= MAX_REF_COUNTER"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - ref_counter = UNDEF_REF_COUNTER; - } - - return err; - }; - //if (ref_counter != 0)则+1,否则什么也不做 - //Return: 0 for success, other values for error - int inc_ref_counter_if_not_zero(uint64_t & ref_counter) { - uint64_t pre_v = _ref_counter_next_index; //保存v的原始值到cv - uint64_t org_v = pre_v; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = 0; - // 如果原始值ref_counter为0,或者对象是free的,则返回 - while (org_v != 0 && (org_v & FREE_FLAG) == 0) { - pre_v = df_atomic_compare_exchange(&_ref_counter_next_index, org_v+1, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - ++org_v; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - if ((org_v & FREE_FLAG) == 0) { - if ((ref_counter = org_v) >= MAX_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter >= MAX_REF_COUNTER"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - ref_counter = 0; - } - } - - return err; - }; - //Return: 0 for success, other values for error - int dec_ref_counter(uint64_t & ref_counter) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((ref_counter = df_atomic_dec(&_ref_counter_next_index)) >= MAX_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ref_counter >= MAX_REF_COUNTER"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - ref_counter = UNDEF_REF_COUNTER; - } - - return err; - }; - uint64_t get_ref_counter(void) const { - uint64_t ref_counter = _ref_counter_next_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (ref_counter >= MAX_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ref_counter >= MAX_REF_COUNTER"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - ref_counter = UNDEF_REF_COUNTER; - } - - return ref_counter; - }; -}; - -//二维数组dfs_bt2d_ary_t的数据类型的基类 -template -class dfs_2d_du_t : public dfs_2d_base_t, public T { -private: - typedef T *PT; - typedef const T *PCT; -public: - dfs_2d_du_t() : dfs_2d_base_t(), T() { - }; - const dfs_2d_du_t & operator=(const dfs_2d_du_t & src) { - if (&src != this) { - *((dfs_2d_base_t *)this) = (const dfs_2d_base_t &)src; - *((T *)this) = (const T &)src; - } - return *this; - }; - dfs_2d_du_t(const dfs_2d_du_t & src) : dfs_2d_base_t((const dfs_2d_base_t &)src), T((const T &)src) { - //*this = src; - }; - dfs_2d_du_t(const T & tobj) { - if ((T *)this != &tobj) { - init(); - *((T *)this) = tobj; - } - }; - ~dfs_2d_du_t() { - }; - void init(void) { //初始化对象 - dfs_2d_base_t::init(); - T::init(); - }; -}; - - - -class dfs_u_int64_t : public dfs_bt_const_t { -private: - uint64_t _data; -public: - dfs_u_int64_t(const uint64_t data = 0) { - _data = data; - }; - dfs_u_int64_t(const dfs_u_int64_t & src) { - *this = src; - }; - ~dfs_u_int64_t() { - }; - const dfs_u_int64_t & operator=(const dfs_u_int64_t & src) { - if (&src != this) { - _data = src._data; - } - return *this; - }; - void init(const uint64_t data = 0) { //初始化对象 - _data = data; - }; -public: - void set_data(const uint64_t data) { - _data = data; - }; - uint64_t get_data(void) const { - return _data; - }; - void set_index(const uint64_t index) { - _data = index; - }; - uint64_t get_index(void) const { - return _data; - }; -public: - bool operator==(const dfs_u_int64_t & src) const { - return (_data == src._data); - }; - bool operator!=(const dfs_u_int64_t & src) const { - return (_data != src._data); - }; - bool operator>=(const dfs_u_int64_t & src) const { - return (_data >= src._data); - }; - bool operator<=(const dfs_u_int64_t & src) const { - return (_data <= src._data); - }; - bool operator>(const dfs_u_int64_t & src) const { - return (_data > src._data); - }; - bool operator<(const dfs_u_int64_t & src) const { - return (_data < src._data); - }; -public: - //用户数据类型T需要支持以下接口: - // 功能:获得该实例store的数据长度(字节),该值不能超过MAX_T_STORE_SIZE - static uint64_t get_store_size(void) { - return sizeof(uint64_t); - }; - // - // 功能:存储该实例到buf - // 输入:data_pos为存储数据的起始位置 - // 输出:data_pos为存储T后新的起始位置 - // 返回:for success, other values for error (例如缓冲区剩余空间不足) - int store(char * buf, const uint64_t buf_size, uint64_t & data_pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((buf_size-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_BUF); - } else { - *((uint64_t *)(buf+data_pos)) = get_data(); - data_pos += sizeof(uint64_t); - } - - return err; - }; - // - // 功能:从buf中装载到该实例 - // 输入:data_pos为装载T前缓冲区的数据位置 - // 输出:data_pos为装载T后缓冲区的数据位置 - // 返回:for success, other values for error(例如缓冲区内数据不足) - int load(const char * buf, const uint64_t data_len, uint64_t & data_pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((data_len-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_BUF); - } else { - set_data(*((uint64_t *)(buf+data_pos))); - data_pos += sizeof(uint64_t); - } - - return err; - }; -}; - - -class dfs_id_t : public dfs_bt_const_t { -private: - uint64_t _id; -public: - dfs_id_t() { - _id = UNDEF_ID; - }; - dfs_id_t(const uint64_t id) { - _id = id; - }; - dfs_id_t(const dfs_id_t & src) { - *this = src; - }; - ~dfs_id_t() { - }; - const dfs_id_t & operator=(const dfs_id_t & src) { - if (&src != this) { - _id = src._id; - } - return *this; - }; - void init(const uint64_t id = UNDEF_ID) { //初始化对象 - _id = id; - }; -public: - void set_id(const uint64_t id) { - _id = id; - }; - uint64_t get_id(void) const { - return _id; - }; -public: - bool operator==(const dfs_id_t & src) const { - return (_id == src._id); - }; - bool operator!=(const dfs_id_t & src) const { - return (_id != src._id); - }; - bool operator>=(const dfs_id_t & src) const { - return (_id >= src._id); - }; - bool operator<=(const dfs_id_t & src) const { - return (_id <= src._id); - }; - bool operator>(const dfs_id_t & src) const { - return (_id > src._id); - }; - bool operator<(const dfs_id_t & src) const { - return (_id < src._id); - }; -public: - bool operator==(const uint64_t & id) const { - return (_id == id); - }; - bool operator!=(const uint64_t & id) const { - return (_id != id); - }; - bool operator>=(const uint64_t & id) const { - return (_id >= id); - }; - bool operator<=(const uint64_t & id) const { - return (_id <= id); - }; - bool operator>(const uint64_t & id) const { - return (_id > id); - }; - bool operator<(const uint64_t & id) const { - return (_id < id); - }; -public: - //用户数据类型T需要支持以下接口: - // 功能:获得该实例store的数据长度(字节),该值不能超过MAX_T_STORE_SIZE - static uint64_t get_store_size(void) { - return sizeof(uint64_t); - }; - // - // 功能:存储该实例到buf - // 输入:data_pos为存储数据的起始位置 - // 输出:data_pos为存储T后新的起始位置 - // 返回:for success, other values for error (例如缓冲区剩余空间不足) - int store(char * buf, const uint64_t buf_size, uint64_t & data_pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((buf_size-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_BUF); - } else { - *((uint64_t *)(buf+data_pos)) = get_id(); - data_pos += sizeof(uint64_t); - } - - return err; - }; - // - // 功能:从buf中装载到该实例 - // 输入:data_pos为装载T前缓冲区的数据位置 - // 输出:data_pos为装载T后缓冲区的数据位置 - // 返回:for success, other values for error(例如缓冲区内数据不足) - int load(const char * buf, const uint64_t data_len, uint64_t & data_pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((data_len-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_BUF); - } else { - set_id(*((uint64_t *)(buf+data_pos))); - data_pos += sizeof(uint64_t); - } - - return err; - }; -}; - - -class dfs_id_data_t : public dfs_id_t { -private: - uint64_t _data; -public: - dfs_id_data_t() : dfs_id_t() { - _data = MAX_U_INT64; - }; - dfs_id_data_t(const dfs_id_data_t & src) : dfs_id_t((const dfs_id_t &)src), _data(src._data) { - ; - }; - ~dfs_id_data_t() { - }; - const dfs_id_data_t & operator=(const dfs_id_data_t & src) { - if (&src != this) { - *((dfs_id_t *)this) = (const dfs_id_t &)src; - _data = src._data; - } - return *this; - }; - void init() { //初始化对象 - dfs_id_t::init(); - _data = MAX_U_INT64; - }; -public: - void set_data(const uint64_t data) { - _data = data; - }; - uint64_t get_data(void) const { - return _data; - }; -public: - //用户数据类型T需要支持以下接口: - // 功能:获得该实例store的数据长度(字节),该值不能超过MAX_T_STORE_SIZE - static uint64_t get_store_size(void) { - return (dfs_id_t::get_store_size()+sizeof(uint64_t)); - }; - // - // 功能:存储该实例到buf - // 输入:data_pos为存储数据的起始位置 - // 输出:data_pos为存储T后新的起始位置 - // 返回:for success, other values for error (例如缓冲区剩余空间不足) - int store(char * buf, const uint64_t buf_size, uint64_t & data_pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = dfs_id_t::store(buf, buf_size, data_pos)) == 0) { - if ((buf_size-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_STORE_BUF); - } else { - *((uint64_t *)(buf+data_pos)) = get_data(); - data_pos += sizeof(uint64_t); - } - } - - return err; - }; - // - // 功能:从buf中装载到该实例 - // 输入:data_pos为装载T前缓冲区的数据位置 - // 输出:data_pos为装载T后缓冲区的数据位置 - // 返回:for success, other values for error(例如缓冲区内数据不足) - int load(const char * buf, const uint64_t data_len, uint64_t & data_pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = dfs_id_t::load(buf, data_len, data_pos)) == 0) { - if ((data_len-data_pos) < sizeof(uint64_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_POS); - } else if (NULL == buf) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_BUF); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_BUF); - } else { - set_data(*((uint64_t *)(buf+data_pos))); - data_pos += sizeof(uint64_t); - } - } - - return err; - }; -}; - - - -// 功能:象普通数组一样提供对象按下标的随机访问,可以自动扩展数组大小。 -// 不支持多线程SingleWriteMultipleRead访问。 -// T: 对象类,需要实现以下成员函数: -// const T & operator=(const T & src); -// const T & operator==(const T & src); -template //建议常数ROW_SIZE是2的方幂 -class dfs_s_ary_t : virtual public dfs_bt_const_t { -private: - typedef T *PT; - typedef const T *PCT; -private: - enum cconst { - MIN_ROW_ARY_SIZE = DEF_ROW_ARY_SIZE , - //MIN_ROW_SIZE = 256 , - }; -private: - dfs_init_t _init_state; - T ** _t_row_ary; - uint64_t _t_row_ary_size; - uint64_t _t_index_for_next_row; - uint64_t _max_kept_key_index; - uint64_t _kept_key_num; - const T _init_t_value; -public: - dfs_s_ary_t(const T & init_t_value) : _init_t_value(init_t_value) { - _t_row_ary = NULL; - - init(); - }; - - virtual ~dfs_s_ary_t() { - if (NULL != _t_row_ary) { - for (uint64_t j = 0; j < _t_row_ary_size; ++j) { - if (NULL != _t_row_ary[j]) { - delete[] _t_row_ary[j]; - _t_row_ary[j] = NULL; - } - } - delete[] _t_row_ary; - _t_row_ary = NULL; - } - }; - bool is_valid_t_index(const uint64_t t_index) const { - return (t_index < _t_index_for_next_row); - }; - int init(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - _t_row_ary_size = MIN_ROW_ARY_SIZE; - _t_index_for_next_row = 0; - _max_kept_key_index = 0; - _kept_key_num = 0; - - if (NULL != _t_row_ary) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NOT_NULL_BUF_POINTER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL != _t_row_ary"); - } else if ((_t_row_ary = new(std::nothrow) T*[_t_row_ary_size]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "_t_row_ary"); - } else { - for (uint64_t j = 0; j < _t_row_ary_size; ++j) { - _t_row_ary[j] = NULL; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_t_row_ary=0x%p, _t_row_ary_size=%ld", - _t_row_ary, _t_row_ary_size); - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; -private: - //扩大row_ary - //return: 0 for success, other values for error - int _enlarge_row_ary(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((_t_index_for_next_row/ROW_SIZE) >= _t_row_ary_size) { - //当前_t_row_ary数组已满 - //typedef T *PT; - uint64_t j = 0; - uint64_t new_t_row_ary_size = _t_row_ary_size * 2; - uint64_t old_t_row_ary_size = 0; - T ** new_t_row_ary = new(std::nothrow) T*[new_t_row_ary_size]; - T ** old_t_row_ary = NULL; - - if (NULL == new_t_row_ary) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "new_t_row_ary"); - } else { - j = 0; - for (; j < _t_row_ary_size; ++j) { - //df_atomic_exchange_pointer((volatile pvoid *)&(new_t_row_ary[j]), (pvoid)_t_row_ary[j]); - new_t_row_ary[j] = _t_row_ary[j]; - } - for (; j < new_t_row_ary_size; ++j) { - new_t_row_ary[j] = NULL; - } - old_t_row_ary = (T **)df_atomic_exchange_pointer( - (volatile pvoid *)&(_t_row_ary), - (pvoid)new_t_row_ary); - old_t_row_ary_size = df_atomic_exchange( - (volatile uint64_t *)&_t_row_ary_size, - new_t_row_ary_size); - delete [] old_t_row_ary; - old_t_row_ary = NULL; - } - } - - return err; - }; - //申请一个新列 - //return: 0 for success, other values for error - int _alloc_new_row(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((_t_index_for_next_row/ROW_SIZE) >= _t_row_ary_size) { - //当前_t_row_ary数组已满 - err = _enlarge_row_ary(); - } - - if (0 == err) { - if ((_t_index_for_next_row/ROW_SIZE) < _t_row_ary_size) { - if (NULL == _t_row_ary[_t_index_for_next_row/ROW_SIZE]) { - if ((_t_row_ary[_t_index_for_next_row/ROW_SIZE] = - new(std::nothrow) T[ROW_SIZE]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - ERRINFO_BT_NOMEM, - "_t_row_ary[_t_index_for_next_row/ROW_SIZE]"); - } - } - if (NULL != _t_row_ary[_t_index_for_next_row/ROW_SIZE]) { - T * head_t = NULL; - uint64_t j = 0; - - head_t = _t_row_ary[_t_index_for_next_row/ROW_SIZE]; - for (j = 0; j < ROW_SIZE; ++j) { - *head_t = _init_t_value; - ++head_t; - } - _t_index_for_next_row += ROW_SIZE; - } - } else { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_SIZE); - } - } - - return err; - }; -private: - //return: 0 for success, other values for error - int _get_t(const uint64_t t_index, PT & pt) const { - int err = 0; - - pt = NULL; - if (is_valid_t_index(t_index)) { - pt = &(((_t_row_ary[t_index/ROW_SIZE])[t_index%ROW_SIZE])); - } else { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - pt = NULL; - } - - return err; - }; -public: - //return: 0 for success, other values for error - int get_t(const uint64_t orig_t_index, T & tobj) const { - const uint64_t true_t_index = orig_t_index; - T * pt = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tobj = _init_t_value; - if (UNDEF_INDEX == orig_t_index || true_t_index > _max_kept_key_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == orig_t_index || true_t_index > _max_kept_key_index"); - DF_WRITE_LOG_US(log_level, - "orig_t_index=0x%lx, true_t_index=0x%lx, _max_kept_key_index=0x%lx", - orig_t_index, true_t_index, _max_kept_key_index); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - //err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_t(true_t_index, pt)) == 0) { - tobj = *pt; - } - - return err; - }; - int put_t(const uint64_t orig_t_index, const T & tobj) { - const uint64_t true_t_index = orig_t_index; - T * pt = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX == orig_t_index || true_t_index > MAX_ARY_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == orig_t_index || true_t_index > MAX_ARY_INDEX"); - DF_WRITE_LOG_US(log_level, - "orig_t_index=0x%lx, true_t_index=0x%lx", - orig_t_index, true_t_index); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - while (true_t_index >= _t_index_for_next_row) { - if ((err = _alloc_new_row()) != 0) { - break; - } - } - if (0 == err) { - if ((err = _get_t(true_t_index, pt)) != 0) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (_init_t_value != *pt) { - //项必须为初始值 - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - *pt = tobj; - } - } - - if (true_t_index > _max_kept_key_index) { - _max_kept_key_index = true_t_index; - } - ++_kept_key_num; - } - - return err; - }; -public: - //clear all data and set to tobj - int clear(void) { - T * head_t = NULL; - uint64_t j = 0; - uint32_t k = 0; - int err = 0; - - for (j = 0; j < _t_row_ary_size; ++j) { - if ((head_t = _t_row_ary[j]) != NULL) { - for (k = 0; k < ROW_SIZE; ++k) { - *head_t = _init_t_value; - ++head_t; - } - } - } - - _t_index_for_next_row = 0; - _max_kept_key_index = 0; - _kept_key_num = 0; - - return err; - }; - uint64_t get_max_kept_key_index(void) const { - return _max_kept_key_index; - }; - uint64_t get_kept_key_num(void) const { - return _kept_key_num; - }; - uint64_t get_mem_size(void) const { - return (_t_row_ary_size*sizeof(T *)+_t_index_for_next_row*sizeof(T)); - }; -}; - -class dfs_rc_set_base_t; -class dfs_rc_indexer_t; -//reference counter setter.. -class dfs_rc_set_base_t : virtual public dfs_bt_const_t { - friend class dfs_rc_indexer_t; -public: - dfs_rc_set_base_t() { - ; - }; - virtual ~dfs_rc_set_base_t() { - ; - }; -protected: - //Return:0 for success, other values for error - virtual int _vir_inc_t_ref_counter(const uint64_t index, uint64_t & ref_counter) const = 0; - virtual int _vir_dec_t_ref_counter(const uint64_t index, uint64_t & ref_counter) const = 0; -}; - -//reference count indexer.. -class dfs_rc_indexer_t : public dfs_bt_const_t { - friend class dfs_rc_indexer_ext_t; -protected: - dfs_rc_set_base_t * _prc_set; - uint64_t _index; - uint64_t _user_def; //用户定义,例如序号 -public: - dfs_rc_indexer_t() : - _prc_set(NULL), _index(UNDEF_INDEX), _user_def(0) { - }; - ~dfs_rc_indexer_t() { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _clear_indexer()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_clear_indexer() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "_index=%ld", _index); - } - _prc_set = NULL; - _index = UNDEF_INDEX; - }; - //复制对象且增加引用计数 - const dfs_rc_indexer_t & operator=(const dfs_rc_indexer_t & src) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (&src != this) { - //占有这么一份index.. - if ((err = this->_set_indexer(&src)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_set_indexer() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "_index=%ld, src._index=%ld", _index, src._index); - } - this->_user_def = src._user_def; - } - - return *this; - }; - //构造对象且增加相应的引用计数 - dfs_rc_indexer_t(const dfs_rc_indexer_t & src) : - _prc_set(NULL), _index(UNDEF_INDEX), _user_def(0) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (&src != this) { - _user_def = src._user_def; - if ((err = this->_set_indexer(&src)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_set_indexer() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "_index=%ld, src._index=%ld", _index, src._index); - } - } - - return; - }; - int init(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - //如果是UNDEF INDEX的话. - if ((err = _clear_indexer()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_clear_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "_index=%ld", _index); - } - //_prc_set = NULL; - _index = UNDEF_INDEX; - - return err; - }; -public: - bool is_valid(void) const { - return (UNDEF_INDEX != _index); - }; - void set_user_def(const uint64_t user_def) { - _user_def = user_def; - }; - uint64_t get_user_def(void) const { - return _user_def; - }; -private: - int _set_indexer(const dfs_rc_indexer_t * psrc) { - uint64_t ref_counter = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //相当于控制转移... - //增加psrc的index的索引,然后释放本身的index索引... - if (NULL != psrc && UNDEF_INDEX != psrc->_index) { - if ((err = psrc->_prc_set->_vir_inc_t_ref_counter(psrc->_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_vir_inc_t_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 1"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - } - - if (UNDEF_INDEX != this->_index) { - if ((err = this->_prc_set->_vir_dec_t_ref_counter(this->_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_vir_dec_t_ref_counter() returns 0x%x", err); - } - } - - if (NULL != psrc) { - this->_prc_set = psrc->_prc_set; - this->_index = psrc->_index; - this->_user_def = psrc->_user_def; - } else { - this->_index = UNDEF_INDEX; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "_index=%ld, psrc->_index=%ld, ref_counter=%ld", - _index, - (NULL != psrc && UNDEF_INDEX != psrc->_index) ? psrc->_index : UNDEF_INDEX, - ref_counter); - } - - return err; - }; - int _clear_indexer(void) { - uint64_t ref_counter = 0; - //const uint64_t old_index = this->_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX != this->_index) { - if ((err = this->_prc_set->_vir_dec_t_ref_counter(this->_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_vir_dec_t_ref_counter() returns 0x%x", err); - } - } - - this->_index = UNDEF_INDEX; - - if (DF_UL_LOG_NONE != log_level) { - //DF_WRITE_LOG_US(log_level, "old_index=%ld, ref_counter=%ld", - //old_index, ref_counter); - DF_WRITE_LOG_US(log_level, "old_index=%ld, ref_counter=%ld", - this->_index, ref_counter); - } - - return err; - }; -}; - -class dfs_rc_indexer_ext_t : public dfs_rc_indexer_t { -public: - dfs_rc_indexer_ext_t(const dfs_rc_indexer_t & rc_indexer) { - _prc_set = rc_indexer._prc_set; - _index = rc_indexer._index; - _user_def = rc_indexer._user_def; - }; - dfs_rc_indexer_ext_t(dfs_rc_set_base_t * prc_set, const uint64_t index) { - _prc_set = prc_set; - _index = index; - _user_def = 0; - }; - ~dfs_rc_indexer_ext_t() { - set_indexer(NULL, UNDEF_INDEX); - _user_def = 0; - }; - void init(void) { - set_indexer(NULL, UNDEF_INDEX); - _user_def = 0; - }; - void set_indexer(dfs_rc_set_base_t * prc_set, const uint64_t index) { - _prc_set = prc_set; - _index = index; - }; - void set_indexer(const uint64_t index) { - _index = index; - }; - dfs_rc_set_base_t * get_rc_set(void) const { - return _prc_set; - }; - uint64_t get_index(void) const { - return _index; - }; -}; - - -//recycle set:其中元素循环使用: -//直接进行freee_head的管理... -template -class dfs_rc_set_t : public dfs_rc_set_base_t { -private: - typedef T *PT; - typedef const T *PCT; - typedef dfs_2d_du_t DU; - typedef dfs_2d_du_t *PDU; - typedef const dfs_2d_du_t *PCDU; -private: - dfs_init_t _init_state; - dfs_2d_base_t _free_head; - volatile uint64_t _free_counter; - volatile uint64_t _cur_index; //当前项 - void * _pgc_info; //for garbage collect purpose - DU * _rc_ary; -#ifdef DF_BT_STATISTIC_INFO - //statistic information purpose - volatile uint64_t _obj_del_counter; - volatile uint64_t _obj_add_counter; - volatile uint64_t _obj_ref_inc_counter; - volatile uint64_t _obj_ref_dec_counter; -#endif -public: - dfs_rc_set_t() { - _free_head.init(); - _free_head.set_free(); - _free_counter = 0; - _cur_index = UNDEF_INDEX; - _pgc_info = NULL; - _rc_ary = NULL; - -#ifdef DF_BT_STATISTIC_INFO - _obj_del_counter = 0; - _obj_add_counter = 0; - _obj_ref_inc_counter = 0; - _obj_ref_dec_counter = 0; -#endif - - //init(); - return; - }; - virtual ~dfs_rc_set_t() { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint64_t ref_counter = UNDEF_REF_COUNTER; - - if (UNDEF_INDEX != _cur_index) { - //#ifdef DF_BT_PRINT_DEBUG_INFO - //printf("~dfs_rc_set_t: line: <%d>, func: <%s>, file: <%s>\n", - // __LINE__, __FUNCTION__, __FILE__); - //#endif - - if ((err = _dec_t_ref_counter(_cur_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_t_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "_cur_index=%ld", _cur_index); - } - _cur_index = UNDEF_INDEX; - - //add by zhangyan04@baidu.com - //fixed it to avoid the valgrind warning.. - delete [] _rc_ary; - - //#ifdef DF_BT_PRINT_DEBUG_INFO - //printf("~dfs_rc_set_t: line: <%d>, func: <%s>, file: <%s>\n", - // __LINE__, __FUNCTION__, __FILE__); - //#endif - } - }; - int init(void * pgc_info); -private: - const dfs_rc_set_t & operator=(const dfs_rc_set_t & src); - dfs_rc_set_t(const dfs_rc_set_t & src); -public: - pvoid get_gc_info(void) const { - return _pgc_info; - }; - //int set_gc_info(void * pgc_info) - //{ - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // if (NULL != _pgc_info) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "NULL != _pgc_info"); - // err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SET_GC_INFO); - // } - // else - // { - // _pgc_info = pgc_info; - // } - // - // return err; - //}; -private: -#ifdef DF_BT_STATISTIC_INFO - //statistic information purpose - //called whenever an obj is deleted - uint64_t _inc_obj_del_counter(void) { - return df_atomic_inc(&_obj_del_counter); - }; - // - //called whenever a new obj is added - uint64_t _inc_obj_add_counter(void) { - return df_atomic_inc(&_obj_add_counter); - }; - // - //called whenever an obj's ref_counter is incremented - uint64_t _inc_obj_ref_inc_counter(void) { - return df_atomic_inc(&_obj_ref_inc_counter); - }; - // - //called whenever an obj's ref_counter is decremented - uint64_t _inc_obj_ref_dec_counter(void) { - return df_atomic_inc(&_obj_ref_dec_counter); - }; -#endif -private: - //读写线程都可能调用 - int _push_free(const uint64_t freed_index) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_exist_du(freed_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - //这是为free.. - pdu->dfs_2d_base_t::set_free(); - if ((err = _free_head.add_to_list(freed_index, *((dfs_2d_base_t *)pdu))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_free_head.add_to_list(%ld) returns 0x%x", - freed_index, err); - } else { - df_atomic_inc(&_free_counter); - } - } - - return err; - }; - //只有写线程调用,因此只有一个实例 - int _pop_free(uint64_t & ret_index) { - PDU pdu = NULL; - uint64_t raw_data = 0; - bool is_removed = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - raw_data = _free_head.get_raw_data(); - ret_index = dfs_2d_base_t::extract_next_index(raw_data); - while (UNDEF_INDEX != ret_index) { - is_removed = false; - if ((err = _get_exist_du(ret_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - ret_index = UNDEF_INDEX; - break; - } - //获得raw_data以及获得pdu以及pdu->get_next_index()不是一个原子操作, - //如果有多个_pop_free线程,则在获得raw_data后pdu->get_next_index()可能 - //发生变化(即使raw_data与ret_index没有变化),因此该算法对多个_pop_free()线程并不安全。 - else if ((err = _free_head.remove_from_list( - raw_data, - pdu->dfs_2d_base_t::get_next_index(), - is_removed)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_free_head.remove_from_list() returns 0x%x", err); - ret_index = UNDEF_INDEX; - break; - } else if (is_removed) { - pdu->set_in_use(); - df_atomic_dec(&_free_counter); - break; - } - raw_data = _free_head.dfs_2d_base_t::get_raw_data(); - ret_index = dfs_2d_base_t::extract_next_index(raw_data); - } - - return err; - }; - -private: - //Return: 0 for success, other values for error - int _release_t(const uint64_t t_index) { - PDU pdu = NULL; - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_del_counter(); -#endif - - if (!_is_valid_t_index(t_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "!is_valid_t_index(t_index)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((ref_counter = pdu->dfs_2d_base_t::get_ref_counter()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter != 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = pdu->action_before_gc(get_gc_info(), t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->action_before_gc(get_gc_info()...) returns 0x%x", err); - } else { - //Added by yangzhenkun per DTS in order to release the resource pointed by T on 20090717 - pdu->T::init(); - - // - if ((err = _push_free(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_push_free() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, ref_counter=%ld, pdu=0x%p", - t_index, ref_counter, pdu); - } - - return err; - }; -private: - inline BAIDU_INLINE int _get_exist_du(const uint64_t t_index, PDU & pdu) const { - const uint64_t true_t_index = t_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pdu = NULL; - if (true_t_index < SET_SIZE) { - pdu = _rc_ary + true_t_index; - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "true_t_index=%ld > SET_SIZE=%d", - true_t_index, SET_SIZE); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, true_t_index=0x%lx", - t_index, true_t_index); - } - - return err; - }; - //int _get_may_not_exist_du(const uint64_t t_index, PDU & pdu) const - //{ - // const uint64_t true_t_index = t_index; - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // pdu = NULL; - // if (_is_valid_t_index(t_index)) - // { - // pdu = _rc_ary + true_t_index; - // } - // else - // { - // //err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - // pdu = NULL; - // } - // - // if (DF_UL_LOG_NONE != log_level) - // { - // DF_WRITE_LOG_US(log_level, - // "t_index=0x%lx, true_t_index=0x%lx, pdu=0x%p", - // t_index, true_t_index, pdu); - // } - // - // return err; - //}; -public: - ////Return: 0 for success, other values for error - //int get_exist_t_unit(const uint64_t t_index, PT & pt) const - //{ - // PDU pdu = NULL; - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // pt = NULL; - // if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - // DF_WRITE_LOG_US(log_level, - // "t_index=0x%lx, pt=0x%p, pdu=0x%p", - // t_index, pt, pdu); - // err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - // } - // else - // { - // pt = ((T *)pdu); - // } - // - // return err; - //}; - //int get_may_not_exist_t_unit(const uint64_t t_index, PT & pt) const - //{ - // PDU pdu = NULL; - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // pt = NULL; - // if ((err = _get_may_not_exist_du(t_index, pdu)) != 0) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_get_may_not_exist_du() returns 0x%x", err); - // DF_WRITE_LOG_US(log_level, - // "t_index=0x%lx, pt=0x%p, pdu=0x%p", - // t_index, pt, pdu); - // } - // else if (NULL != pdu) - // { - // pt = ((T *)pdu); - // } - // - // return err; - //}; - -public: - //输入:tobj:新对象的值 - //输出:新对象的indexer - int acquire_t(const T & tobj, dfs_rc_indexer_t & rc_indexer) { - uint64_t ref_counter = 0; - uint64_t t_index = UNDEF_INDEX; - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - t_index = UNDEF_INDEX; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_add_counter(); -#endif - - if ((err = _pop_free(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_pop_free() returns 0x%x", err); - } else if (UNDEF_INDEX == t_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "fail to acquire t_obj"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_ACQUIRE); - t_index = UNDEF_INDEX; - } else { - if ((err = _get_exist_du(t_index, pdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - t_index = UNDEF_INDEX; - } else if (NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pdu"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - t_index = UNDEF_INDEX; - } else { - pdu->init(); - *((T *)pdu) = tobj; - if ((err = pdu->action_while_added(get_gc_info(), t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->action_while_added() returns 0x%x", err); - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->dfs_2d_base_t::inc_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } else { - ((dfs_rc_indexer_ext_t *)&rc_indexer)->set_indexer( - (dfs_rc_set_base_t *)this, - t_index); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "t_index=0x%lx", t_index); - } - - return err; - }; - -protected: - //Return:0 for success, other values for error - int _inc_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_ref_inc_counter(); -#endif - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->dfs_2d_base_t::inc_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } - - return err; - }; - //if (ref_counter != 0)则+1,否则什么也不做 - //Return: 0 for success, other values for error - int _inc_t_ref_counter_if_not_zero(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = 0; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero() returns 0x%x", - err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } -#ifdef DF_BT_STATISTIC_INFO - else if (0 != ref_counter && UNDEF_REF_COUNTER != ref_counter) { - _inc_obj_ref_inc_counter(); - } -#endif - - return err; - }; - //Return:0 for success, other values for error - int _dec_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_ref_dec_counter(); -#endif - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::dec_ref_counter(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->dfs_2d_base_t::dec_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } else if (0 == ref_counter && (err = _release_t(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_release_t() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } - - return err; - }; - //return: 0 for success, other values for error - int _get_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((ref_counter = pdu->dfs_2d_base_t::get_ref_counter()) == UNDEF_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter == UNDEF_REF_COUNTER"); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - - return err; - }; -public: - //要保证:如果new_index不是UNDEF_INDEX,那么其引用计数必须大于0。 - int update_cur_index(const dfs_rc_indexer_t & new_rc_indexer, dfs_rc_indexer_t & old_rc_indexer) { - //const dfs_rc_indexer_ext_t * pnew_rc_indexer_ext = (const dfs_rc_indexer_ext_t *)&new_rc_indexer; - //uint64_t ref_counter = 0; - uint64_t new_cur_index = ((const dfs_rc_indexer_ext_t *)&new_rc_indexer)->get_index(); - uint64_t old_cur_index = UNDEF_INDEX; - //PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - old_rc_indexer = new_rc_indexer; - if (!_is_valid_t_index(new_cur_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "new_cur_index=%ld", new_cur_index); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } else if (((const dfs_rc_indexer_ext_t *)&new_rc_indexer)->get_rc_set() - != (dfs_rc_set_base_t *)this) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "new_rc_indexer.get_rc_set() != this"); - DF_WRITE_LOG_US(log_level, - "new_cur_index=%ld", - new_cur_index); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DIFF_POINTER); - } - //else if ((err = _inc_t_ref_counter(new_cur_index, ref_counter)) != 0) - //{ - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_inc_ref_counter() returns 0x%x", err); - // DF_WRITE_LOG_US(log_level, - // "new_cur_index=%ld", - // new_cur_index); - //} - else { - old_cur_index = df_atomic_exchange(&_cur_index, new_cur_index); - //此处不需要额外进行引用计数的加减:前面的old_rc_indexer = new_rc_indexer - //导致new_cur_index的引用计数+1,以下的set_index(old_cur_index) - //将最终导致old_cur_index的引用计数-1 - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->set_indexer(old_cur_index); - //if ((err = _dec_t_ref_counter(old_cur_index, ref_counter)) != 0) - //{ - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_dec_ref_counter() returns 0x%x", err); - // DF_WRITE_LOG_US(log_level, "old_cur_index=%ld", old_cur_index); - //} - } - - return err; - }; - //说明:需要保证获得的项没有被回收 - inline BAIDU_INLINE int retrieve_cur_index(dfs_rc_indexer_t & rc_indexer) const { - //dfs_rc_indexer_ext_t * pnew_rc_index_ext = (dfs_rc_indexer_ext_t *)&rc_indexer; - PDU pdu = NULL; - uint64_t ref_counter = 0; - uint64_t t_index = _cur_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - rc_indexer.init(); - while (UNDEF_INDEX != t_index) { - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - break; - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero() returns 0x%x", - err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - break; - } else if (0 != ref_counter) { -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_ref_inc_counter(); -#endif - - //前面调用_inc_t_ref_counter_if_not_zero()时已经增加了引用计数 - ((dfs_rc_indexer_ext_t *)&rc_indexer)->set_indexer( - (dfs_rc_set_base_t *)this, - t_index); - - break; - } - //获得_cur_index的当前值以便重试 - t_index = _cur_index; - } - - return err; - }; -protected: - bool _is_valid_t_index(const uint64_t t_index) const { - return (t_index < SET_SIZE); - }; - //int valid_t_index_verify(const uint64_t t_index) const - //{ - // uint64_t true_t_index = t_index; - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // if (true_t_index >= SET_SIZE) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "true_t_index >= SET_SIZE"); - // DF_WRITE_LOG_US(log_level, - // "t_index=0x%lx, true_t_index=0x%lx, SET_SIZE=%d", - // t_index, true_t_index, _t_index_for_next_row); - // err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - // } - // - // return err; - //}; - - //return: 0 for success, other values for error - int _get_t_unit(const uint64_t t_index, PCT & pct) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pct = NULL; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pct = ((T *)pdu); - } - - return err; - }; - int _get_t_unit(const dfs_rc_indexer_t & rc_indexer, PCT & pct) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pct = NULL; - if ((err = _get_exist_du( - ((const dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(), - pdu)) != 0 - || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", - ((const dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(), - pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pct = ((T *)pdu); - } - - return err; - }; -public: - int get_t_unit(const dfs_rc_indexer_t & rc_indexer, PCT & pct) const { - return _get_t_unit(rc_indexer, pct); - }; - uint64_t get_in_use_num(void) const { - return (SET_SIZE-_free_counter); - }; - uint64_t get_free_counter(void) const { - return _free_counter; - }; - //bool is_valid_indexer(const uint64_t t_index) const - //{ - // return (t_index < SET_SIZE); - //}; - bool is_valid_in_use_indexer(const dfs_rc_indexer_t & rc_indexer) const { - PDU pdu = NULL; - const dfs_rc_set_base_t * prc_set = - ((const dfs_rc_indexer_ext_t *)&rc_indexer)->get_rc_set(); - const uint64_t t_index = ((const dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(); - int log_level = DF_UL_LOG_NONE; - int err = 0; - bool bret = false; - - if(NULL == prc_set || UNDEF_INDEX == t_index) { - bret = false; - } else if((dfs_rc_set_base_t *)this != prc_set) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "rc_indexer._prc_set != (dfs_rc_set_base_t *)this"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (t_index >= SET_SIZE) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "t_index=%ld > SET_SIZE=%d", t_index, SET_SIZE); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - if ((err = _get_exist_du(t_index,pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p",t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - bret = pdu->dfs_2d_base_t::is_in_use(); - } - } - - return bret; - }; -protected: - //Return:0 for success, other values for error - virtual int _vir_inc_t_ref_counter(const uint64_t index, uint64_t & ref_counter) const { - return ((dfs_rc_set_t *)this)->_inc_t_ref_counter(index, ref_counter); - }; - virtual int _vir_dec_t_ref_counter(const uint64_t index, uint64_t & ref_counter) const { - return ((dfs_rc_set_t *)this)->_dec_t_ref_counter(index, ref_counter); - }; -}; - - -template -int dfs_rc_set_t::init(void * pgc_info) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - uint64_t ref_counter = 0; - uint64_t t_index = UNDEF_INDEX; - int64_t j = 0; - int64_t n = (int64_t)SET_SIZE; - DU * pdu = NULL; - - - _pgc_info = pgc_info; - - if ((_rc_ary = new(std::nothrow) DU[SET_SIZE]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "_prc_root_set"); - } else { - for (j = 0; j < n; ++j) { - if ((err = _get_exist_du(j, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - pdu->init(); - pdu->set_free(); - - if ((err = _push_free(j)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_push_free() returns 0x%x", err); - break; - } - } - } - } - - if (0 == err) { - if ((err = _pop_free(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_pop_free() returns 0x%x", err); - } else if ((err = _inc_t_ref_counter(t_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=%ld", t_index); - } else if (1 != ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "1 != ref_counter(=%ld)", ref_counter); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - _cur_index = t_index; - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; -}; - - - -//数组模板类,外部看是一维数组,以uint64_t作为下标访问,数组元素类型是T。 -//dfs_bt2d_ary_t -// 模板参数:T,用户的数据单元类型 -// ROW_SIZE:常数,数组行尺寸,建议为2的方幂 -//特别说明:需要使用外部的锁机制来保证对数组的修改是单一的(即同一时间只能有一个线程修改数组)! -// 规则:public接口仅提供“只读”操作,protected接口提供修改操作。 -// -//内部是二维数组,每行ROW_SIZE个元素。 -//输入参数: -// T: 对象类(用户数据单元),需要提供以下接口: -// T(); -// T(const T & src); -// const T & operator=(const T & src); -// -// // 功能:对T进行初始化 -// void init(void); -// -//外部接口(public): -// 规则:public接口仅提供“只读”操作,protected接口提供修改操作 -// 构造函数:缺省构造函数; -// int acquire_t(const T * ptobjv, uint64_t & t_index, T ** pptobj); -// 功能:申请一个新的对象。成功时用pt所指对象初始化(pt非空时)或调用init()进行初始化(pt为空)。 -// 成功时,对象的状态总是为in_use,引用计数为0。 -// 输入:ptobjv:其指向的值用来初始化新对象,可以为NULL -// 输出:新对象的index以及指向新对象的指针,UNDEF_INDEX表示没有自由对象且无法申请新对象 -// int get_t_unit(const uint64_t t_index, const T * pct) const -// 功能:获得一个对象的指针,如果输入index非法或者对象不在使用中,则返回NULL -// 输入:对象的INDEX -// 返回:对象的指针,如果输入index非法或者对象不在使用中则返回NULL -// bool is_valid_t_index(const uint64_t t_index) const -// 功能:判断一个INDEX是否合法(使用中或自由的INDEX都是合法的) -// 输入:对象的INDEX -// 返回:true表示合法INDEX,false表示非法的INDEX -// 说明:新对象是成批申请的 -// uint64_t get_size(void) -// 功能:当前数组的大小(单元个数) -// 返回:返回0表示尚未有任何对象 -//外部接口(protected): -// int inc_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) -// 功能:对象的引用计数加1 -// 输入:对象的INDEX -// 返回:0 for success, other values for error -// int dec_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) -// 功能:对象的引用计数减1 -// 输入:对象的INDEX -// 返回:0 for success, other values for error -// int get_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) const; -// 功能:获得对象的引用计数 -// 输入:对象的INDEX -// 输出:对象的引用计数,UNDEF_REF_COUNTER表示非法的INDEX或者对象的引用计数异常 -// 返回:0 for success, other values for error -// int get_exist_t_unit(const uint64_t t_index, PT & pt) -// int get_may_not_exist_t_unit(const uint64_t t_index, PT & pt) -// 功能:获得一个对象的指针,如果输入index非法则返回NULL,否则返回该对象指针 -// 输入:对象的INDEX -// 返回:0 for success, other values for error -//private: -// int _release_t(const uint64_t t_index) -// 功能:释放一个对象 -// 输入:要释放对象的INDEX -// 返回:0 for success, other values for error - -//总是保留第一个元素 -template //, //建议常数ROW_SIZE是2的方幂 -class dfs_bt2d_ary_t : virtual public dfs_bt_const_t { -private: - typedef T *PT; - typedef const T *PCT; - typedef dfs_2d_du_t DU; - typedef dfs_2d_du_t *PDU; - typedef const dfs_2d_du_t *PCDU; -private: - enum cconst { - MIN_ROW_ARY_SIZE = 256, - MIN_ROW_SIZE = 256 , - }; -private: - dfs_init_t _init_state; - PDU * _t_row_ary; - uint64_t _t_row_ary_size; - uint64_t _t_index_for_next_alloc; //新申请ROW的分配位置 - uint64_t _t_index_for_next_row; - PDU * _realloc_t_row_ary[MAX_2D_ARY_HOLD_REALLOC_NUM]; - uint64_t _realloc_counter; - dfs_2d_base_t _free_head; - volatile uint64_t _free_counter; - pvoid _pgc_info; //for garbage collect purpose -#ifdef DF_BT_STATISTIC_INFO - //statistic information purpose - volatile uint64_t _obj_del_counter; - volatile uint64_t _obj_add_counter; - volatile uint64_t _obj_ref_inc_counter; - volatile uint64_t _obj_ref_dec_counter; -#endif -public: - dfs_bt2d_ary_t() { - _t_row_ary_size = MIN_ROW_ARY_SIZE; - _t_row_ary = NULL; - _t_index_for_next_alloc = 0; - _t_index_for_next_row = 0; - - _free_head.set_free(); - _free_counter = 0; - - for (uint32_t j = 0; j < df_len_of_ary(_realloc_t_row_ary); ++j) { - _realloc_t_row_ary[j] = NULL; - } - _realloc_counter = 0; - _pgc_info = NULL; - -#ifdef DF_BT_STATISTIC_INFO - _obj_del_counter = 0; - _obj_add_counter = 0; - _obj_ref_inc_counter = 0; - _obj_ref_dec_counter = 0; -#endif - - init(); - }; - virtual ~ dfs_bt2d_ary_t() { - if (NULL != _t_row_ary) { - for (uint64_t j = 0; j < _t_row_ary_size; ++j) { - if (NULL != _t_row_ary[j]) { - delete[] _t_row_ary[j]; - _t_row_ary[j] = NULL; - } - } - delete[] _t_row_ary; - _t_row_ary = NULL; - } - - for (uint32_t j = 0; j < df_len_of_ary(_realloc_t_row_ary); ++j) { - delete [] _realloc_t_row_ary[j]; - } - - _init_state.set_destructed(); - - return; - }; - int init(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - if (NULL != _t_row_ary) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NOT_NULL_BUF_POINTER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL != _t_row_ary"); - } else if ((_t_row_ary = new(std::nothrow) PDU[_t_row_ary_size]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "_t_row_ary"); - } else { - for (uint64_t j = 0; j < _t_row_ary_size; ++j) { - _t_row_ary[j] = NULL; - } - if ((err = _alloc_new_row()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_alloc_new_row() returns 0x%x", err); - } else { - //总是保留第一个元素 - ++_t_index_for_next_alloc; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_t_row_ary=0x%p, _t_row_ary_size=%ld", - _t_row_ary, _t_row_ary_size); - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; -public: - pvoid get_gc_info(void) const { - return _pgc_info; - }; - int set_gc_info(void * pgc_info) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL != _pgc_info) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL != _pgc_info"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SET_GC_INFO); - } else { - _pgc_info = pgc_info; - } - - return err; - }; -private: -#ifdef DF_BT_STATISTIC_INFO - //statistic information purpose - //called whenever an obj is deleted - uint64_t _inc_obj_del_counter(void) { - return df_atomic_inc(&_obj_del_counter); - }; - // - //called whenever a new obj is added - uint64_t _inc_obj_add_counter(void) { - return df_atomic_inc(&_obj_add_counter); - }; - // - //called whenever an obj's ref_counter is incremented - uint64_t _inc_obj_ref_inc_counter(void) { - return df_atomic_inc(&_obj_ref_inc_counter); - }; - // - //called whenever an obj's ref_counter is decremented - uint64_t _inc_obj_ref_dec_counter(void) { - return df_atomic_inc(&_obj_ref_dec_counter); - }; -#endif -public: - void clear_statistic_info(void) { -#ifdef DF_BT_STATISTIC_INFO - df_atomic_exchange(&_obj_del_counter, 0); - df_atomic_exchange(&_obj_add_counter, 0); - df_atomic_exchange(&_obj_ref_inc_counter, 0); - df_atomic_exchange(&_obj_ref_dec_counter, 0); -#endif - return; - }; - void log_statistic_info( - const int log_level, - const char * filename, - const int lineno, - const char * funcname, - const char * btreename, - const char * bt2dname) const { - DF_WRITE_LOG_US(log_level, "%s,%d,%s", filename, lineno, funcname); - DF_WRITE_LOG_US(log_level, "%s, %s", btreename, bt2dname); -#ifdef DF_BT_STATISTIC_INFO - DF_WRITE_LOG_US(log_level, "_obj_del_counter=%ld", _obj_del_counter); - DF_WRITE_LOG_US(log_level, "_obj_add_counter=%ld", _obj_add_counter); - DF_WRITE_LOG_US(log_level, "_obj_ref_inc_counter=%ld", _obj_ref_inc_counter); - DF_WRITE_LOG_US(log_level, "_obj_ref_dec_counter=%ld", _obj_ref_dec_counter); -#endif - return; - }; - void log_debug_info( - const int log_level, - const char * filename, - const int lineno, - const char * funcname, - const char * btreename, - const char * bt2dname) const { - DF_WRITE_LOG_US(log_level, "%s,%d,%s", filename, lineno, funcname); - DF_WRITE_LOG_US(log_level, "%s, %s", btreename, bt2dname); - DF_WRITE_LOG_US(log_level, "_t_row_ary_size=%ld", _t_row_ary_size); - DF_WRITE_LOG_US(log_level, "_t_index_for_next_alloc=%ld", _t_index_for_next_alloc); - DF_WRITE_LOG_US(log_level, "_t_index_for_next_row=%ld", _t_index_for_next_row); - DF_WRITE_LOG_US(log_level, "_realloc_counter=%ld", _realloc_counter); - DF_WRITE_LOG_US(log_level, "_free_head.get_next_index()=%ld", _free_head.get_next_index()); - DF_WRITE_LOG_US(log_level, "_free_counter=%ld", _free_counter); - }; - -private: - //扩大row_ary - //return: 0 for success, other values for error - int _enlarge_row_ary(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((_t_index_for_next_row/ROW_SIZE) >= _t_row_ary_size) { - //当前_t_row_ary数组已满 - //typedef T *PT; - uint64_t j = 0; - uint64_t new_t_row_ary_size = _t_row_ary_size * 2; - uint64_t old_t_row_ary_size = 0; - PDU * new_t_row_ary = new(std::nothrow) PDU[new_t_row_ary_size]; - PDU * old_t_row_ary = NULL; - - if (NULL == new_t_row_ary) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "new_t_row_ary"); - } else { - j = 0; - for (; j < _t_row_ary_size; ++j) { - new_t_row_ary[j] = _t_row_ary[j]; - } - for (; j < new_t_row_ary_size; ++j) { - new_t_row_ary[j] = NULL; - } - old_t_row_ary = (dfs_2d_du_t **)df_atomic_exchange_pointer( - (volatile pvoid *)&(_t_row_ary), - (pvoid)new_t_row_ary); - old_t_row_ary_size = df_atomic_exchange( - (volatile uint64_t *)&_t_row_ary_size, - new_t_row_ary_size); - //把旧数组加入到缓冲区链,暂时不释放,因为其他读线程可能正在访问。 - delete [] _realloc_t_row_ary[_realloc_counter]; - _realloc_t_row_ary[_realloc_counter] = old_t_row_ary; - _realloc_counter = (_realloc_counter+1)%df_len_of_ary(_realloc_t_row_ary); - } - } - - return err; - }; - //申请一个新列 - //return: 0 for success, other values for error - int _alloc_new_row(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((_t_index_for_next_row/ROW_SIZE) >= _t_row_ary_size) { - //当前_t_row_ary数组已满 - err = _enlarge_row_ary(); - } - - if (0 == err) { - if ((_t_index_for_next_row/ROW_SIZE) < _t_row_ary_size) { - if (NULL == _t_row_ary[_t_index_for_next_row/ROW_SIZE]) { - if ((_t_row_ary[_t_index_for_next_row/ROW_SIZE] = - new(std::nothrow) DU[ROW_SIZE]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - ERRINFO_BT_NOMEM, - "_t_row_ary[_t_index_for_next_row/ROW_SIZE]"); - } - } - if (NULL != _t_row_ary[_t_index_for_next_row/ROW_SIZE]) { - _t_index_for_next_alloc = _t_index_for_next_row; - _t_index_for_next_row += ROW_SIZE; - } - } else { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_SIZE); - } - } - - return err; - }; -private: - //读写线程都可能调用 - int _push_free(const uint64_t freed_index) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //if ((err = _t_free_locker.lock(0)) != 0) - //{ - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_t_free_locker.lock() returns 0x%x", err); - //} - //else - //{ - if ((err = _get_exist_du(freed_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - pdu->dfs_2d_base_t::set_free(); - if ((err = _free_head.add_to_list(freed_index, *((dfs_2d_base_t *)pdu))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_free_head.add_to_list() returns 0x%x", err); - } else { - df_atomic_inc(&_free_counter); - } - } - - // _t_free_locker.unlock(); - //} - - return err; - }; - //只有写线程调用,因此只有一个实例 - int _pop_free(uint64_t & ret_index) { - PDU pdu = NULL; - uint64_t raw_data = 0; - bool is_removed = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //if ((err = _t_free_locker.lock(0)) != 0) - //{ - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_t_free_locker.lock() returns 0x%x", err); - //} - //else - //{ - raw_data = _free_head.get_raw_data(); - ret_index = dfs_2d_base_t::extract_next_index(raw_data); - while (UNDEF_INDEX != ret_index) { - is_removed = false; - if ((err = _get_exist_du(ret_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - ret_index = UNDEF_INDEX; - break; - } - //获得raw_data以及获得pdu以及pdu->get_next_index()不是一个原子操作, - //如果有多个_pop_free线程,则在获得raw_data后pdu->get_next_index()可能 - //发生变化(即使raw_data与ret_index没有变化),因此该算法对多个_pop_free()线程并不安全。 - else if ((err = _free_head.remove_from_list( - raw_data, - pdu->dfs_2d_base_t::get_next_index(), - is_removed)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_free_head.remove_from_list() returns 0x%x", err); - ret_index = UNDEF_INDEX; - break; - } else if (is_removed) { - pdu->set_in_use(); - df_atomic_dec(&_free_counter); - break; - } - raw_data = _free_head.dfs_2d_base_t::get_raw_data(); - ret_index = dfs_2d_base_t::extract_next_index(raw_data); - } - - // _t_free_locker.unlock(); - //} - - return err; - }; - -private: - //Return: 0 for success, other values for error - int _release_t(const uint64_t t_index) { - PDU pdu = NULL; - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_del_counter(); -#endif - - if (!is_valid_t_index(t_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "!is_valid_t_index(t_index)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((ref_counter = pdu->dfs_2d_base_t::get_ref_counter()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter != 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = pdu->action_before_gc(get_gc_info(), t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->action_before_gc(get_gc_info()...) returns 0x%x", err); - } else { - //Added by yangzhenkun per DTS in order to release the resource pointed by T on 20090717 - pdu->T::init(); - if ((err = _push_free(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_push_free() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, ref_counter=%ld, pdu=0x%p", - t_index, ref_counter, pdu); - } - - return err; - }; -private: - //Return: 0 for success(even if t_index is invalid), other values for error - //Notice: may return 0 even if pdu is NULL - //int _get_du(const uint64_t t_index, PDU & pdu) const - //{ - // const uint64_t true_t_index = t_index; - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - - // pdu = NULL; - // if (is_valid_t_index(t_index)) - // { - // pdu = &(((_t_row_ary[true_t_index/ROW_SIZE])[true_t_index%ROW_SIZE])); - // } - // else - // { - // //err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - // pdu = NULL; - // } - - // return err; - //}; - inline BAIDU_INLINE int _get_exist_du(const uint64_t t_index, PDU & pdu) const { - const uint64_t true_t_index = t_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pdu = NULL; - if (is_valid_t_index(t_index)) { - pdu = &(((_t_row_ary[true_t_index/ROW_SIZE])[true_t_index%ROW_SIZE])); - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "!is_valid_t_index(t_index)"); - pdu = NULL; - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, true_t_index=0x%lx, pdu=0x%p", - t_index, true_t_index, pdu); - } - - return err; - }; - int _get_may_not_exist_du(const uint64_t t_index, PDU & pdu) const { - const uint64_t true_t_index = t_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pdu = NULL; - if (is_valid_t_index(t_index)) { - pdu = &(((_t_row_ary[true_t_index/ROW_SIZE])[true_t_index%ROW_SIZE])); - } else { - //err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - pdu = NULL; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, true_t_index=0x%lx, pdu=0x%p", - t_index, true_t_index, pdu); - } - - return err; - }; - ////Return: 0 for success(even if t_index is invalid), other values for error - ////Notice: may return 0 even if pdu is NULL - //int _get_du_ignore_recycle_counter(const uint64_t t_index, PDU & pdu) const - //{ - // const uint64_t true_t_index = t_index; - // //int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // pdu = NULL; - // if (is_valid_t_index(t_index)) - // { - // pdu = &(((_t_row_ary[true_t_index/ROW_SIZE])[true_t_index%ROW_SIZE])); - // } - // else - // { - // //err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - // pdu = NULL; - // } - // - // return err; - //}; -public: - //Return: 0 for success, other values for error - inline BAIDU_INLINE int get_exist_t_unit(const uint64_t t_index, PT & pt) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pt = NULL; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, pt=0x%p, pdu=0x%p", - t_index, pt, pdu); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pt = ((T *)pdu); - } - - return err; - }; - int get_may_not_exist_t_unit(const uint64_t t_index, PT & pt) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pt = NULL; - if ((err = _get_may_not_exist_du(t_index, pdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_may_not_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, pt=0x%p, pdu=0x%p", - t_index, pt, pdu); - } else if (NULL != pdu) { - pt = ((T *)pdu); - } - - return err; - }; - -public: - // 输入:ptobjv:其指向的值用来初始化新对象,可以为NULL - // 输出:新对象的index以及指向新对象的指针,UNDEF_INDEX表示没有自由对象且无法申请新对象 - int acquire_t(const T * pctobjv, uint64_t & t_index, T ** pptobj) { - dfs_u_int64_t idata; - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - t_index = UNDEF_INDEX; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_add_counter(); -#endif - - if ((err = _pop_free(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_pop_free() returns 0x%x", err); - } else { - if (UNDEF_INDEX == t_index) { - if (_t_index_for_next_alloc >= _t_index_for_next_row) { - if ((err = _alloc_new_row()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_alloc_new_row() returns 0x%x", err); - } - } - if (0 == err) { - //new obj - if (_t_index_for_next_alloc < _t_index_for_next_row) { - t_index = _t_index_for_next_alloc++; - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "fail to acquire t_obj"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_ACQUIRE); - t_index = UNDEF_INDEX; - } - } - } - - if (0 == err && UNDEF_INDEX != t_index) { - if ((err = _get_exist_du(t_index, pdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - t_index = UNDEF_INDEX; - } else if (NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pdu"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - t_index = UNDEF_INDEX; - } else { - pdu->init(); - } - } - } - - if (0 == err) { - if (NULL != pctobjv) { - *((T *)pdu) = *pctobjv; - } - if (NULL != pptobj) { - *pptobj = (T *)pdu; - } - if ((err = pdu->action_while_added(get_gc_info(), t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->action_while_added() returns 0x%x", err); - } - } else { - t_index = UNDEF_INDEX; - if (NULL != pptobj) { - *pptobj = NULL; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_t_index_for_next_alloc=0x%lx, _t_index_for_next_row=0x%lx", - _t_index_for_next_alloc, _t_index_for_next_row); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx", t_index); - } - - return err; - }; - uint64_t acquire_t(const T * pctobj) { - uint64_t t_index = UNDEF_INDEX; - int err = 0; - - if ((err = acquire_t(pctobj, t_index, NULL)) != 0) { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, "acquire_t() returns 0x%x, t_index=0x%lx", err, t_index); - t_index = UNDEF_INDEX; - } - - return t_index; - }; - -public: - //Return:0 for success, other values for error - int inc_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_ref_inc_counter(); -#endif - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->dfs_2d_base_t::inc_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } - - return err; - }; - //if (ref_counter != 0)则+1,否则什么也不做 - //Return: 0 for success, other values for error - int inc_t_ref_counter_if_not_zero(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = 0; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pdu->dfs_2d_base_t::inc_ref_counter_if_not_zero() returns 0x%x", - err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } -#ifdef DF_BT_STATISTIC_INFO - else if (0 != ref_counter && UNDEF_REF_COUNTER != ref_counter) { - _inc_obj_ref_inc_counter(); - } -#endif - - return err; - }; - //Return:0 for success, other values for error - int dec_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_BT_STATISTIC_INFO - _inc_obj_ref_dec_counter(); -#endif - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pdu->dfs_2d_base_t::dec_ref_counter(ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pdu->dfs_2d_base_t::dec_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } - //进行引用计数的内存释放.. - else if (0 == ref_counter && (err = _release_t(t_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_release_t() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - } - - return err; - }; - - - //return: 0 for success, other values for error - int get_t_ref_counter(const uint64_t t_index, uint64_t & ref_counter) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((ref_counter = pdu->dfs_2d_base_t::get_ref_counter()) == UNDEF_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter == UNDEF_REF_COUNTER"); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - - return err; - }; - - -public: - inline BAIDU_INLINE bool is_valid_t_index(const uint64_t t_index) const { - return (t_index < _t_index_for_next_row); - }; - int valid_t_index_verify(const uint64_t t_index) const { - uint64_t true_t_index = t_index; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (true_t_index >= _t_index_for_next_row) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "true_t_index >= _t_index_for_next_row"); - DF_WRITE_LOG_US(log_level, - "t_index=0x%lx, true_t_index=0x%lx, _t_index_for_next_row=0x%lx", - t_index, true_t_index, _t_index_for_next_row); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - return err; - }; - - //return: 0 for success, other values for error - int get_t_unit(const uint64_t t_index, PCT & pct) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pct = NULL; - if ((err = _get_exist_du(t_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_du() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "t_index=0x%lx, pdu=0x%p", t_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pct = ((T *)pdu); - } - - return err; - }; - -public: - //当前数组的大小(单元个数) - uint64_t get_size(void) const { - return _t_index_for_next_row; - }; - // return: 0 for success, other values for error - int get_in_use_num(uint64_t & in_use_num) const { - in_use_num = _t_index_for_next_alloc-_free_counter; - return 0; - }; - // - // return: 0 for success, other values for error - int get_total_ref_counter(uint64_t & total_ref_counter) const { - PDU pdu = NULL; - uint64_t ref_counter = 0; - uint64_t j = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - total_ref_counter = 0; - //excluding the first element as we keep it reserved. - for (j = 1; j < _t_index_for_next_alloc; ++j) { - if ((err = _get_may_not_exist_du(j, pdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_du_ignore_recycle_counter() returns 0x%x", err); - break; - } else if (NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pdu"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - break; - } else if (pdu->is_in_use()) { - if ((ref_counter = pdu->dfs_2d_base_t::get_ref_counter()) == UNDEF_REF_COUNTER) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pdu->dfs_2d_base_t::get_ref_counter() == UNDEF_REF_COUNTER"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - break; - } else { - total_ref_counter += ref_counter; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "j=0x%lx, _t_index_for_next_alloc=0x%lx", - j, _t_index_for_next_alloc); - } - - return err; - }; - uint64_t get_mem_size(void) const { - return (_t_row_ary_size*sizeof(PDU)+_t_index_for_next_row*sizeof(DU)); - }; -}; - - -// //用来以无锁方式对一个结构进行修改内容和复制内容 -// //修改内容时先_mutation_counter增1,修改完成后把_mutation_counter复制到_syn_mutation_counter -// //复制内容时先复制_syn_mutation_counter,复制完成后再复制_mutation_counter, -// //如果对象正在被修改,则_mutation_counter与_syn_mutation_counter不相等 -//class dfs_mutation_sycnizer_t -//{ -//private: -// //修改_mutation_counter增1,修改完成时设置_syn_mutation_counter为_mutation_counter -// //复制时按相反顺序:先复制_syn_mutation_counter,再_mutation_counter -// volatile uint64_t _mutation_counter; -// volatile uint64_t _syn_mutation_counter; -//public: -// dfs_mutation_sycnizer_t() -// { -// init(); -// }; -// ~dfs_mutation_sycnizer_t() -// { -// }; -//protected: -// //把赋值操作声明为protected是为了避免用它直接给btree的根节点_root_info赋值, -// //因为更新_root_info需要特别的步骤(start_mutating()=>更新root_node_index=>end_mutating()) -// inline const dfs_mutation_sycnizer_t & operator=(const dfs_mutation_sycnizer_t & src) -// { -// if (&src != this) -// { -// //修改顺序:先_mutation_counter,完成时设置_syn_mutation_counter为_mutation_counter -// //复制顺序:与修改顺序正好相反 -// _syn_mutation_counter = src._syn_mutation_counter ; -// _mutation_counter = src._mutation_counter ; -// } -// return *this; -// }; -//public: -// inline void set_value(const dfs_mutation_sycnizer_t & src) -// { -// *this = src; -// }; -//public: -// dfs_mutation_sycnizer_t(const dfs_mutation_sycnizer_t & src) : -// _mutation_counter(src._mutation_counter), -// _syn_mutation_counter(src._syn_mutation_counter) -// { -// }; -// void init(void) -// { -// _mutation_counter = 0; -// _syn_mutation_counter = 0; -// return; -// }; -//public: -// int set_mutation_counter(const uint64_t mutation_counter) -// { -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// -// if (mutation_counter < _mutation_counter) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "mutation_counter < _mutation_counter"); -// DF_WRITE_LOG_US(log_level, -// "mutation_counter=%lu, _mutation_counter=%lu", -// mutation_counter, _mutation_counter); -// err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_MUTATION_COUNTER); -// } -// else -// { -// df_atomic_exchange(&_mutation_counter, mutation_counter); -// } -// -// return err; -// }; -// void start_mutating(void) -// { -// df_atomic_inc(&_mutation_counter); -// return; -// }; -// void end_mutating(void) -// { -// df_atomic_exchange(&_syn_mutation_counter, _mutation_counter); -// return; -// }; -// void start_copying(const dfs_mutation_sycnizer_t & src) -// { -// df_atomic_exchange(&_syn_mutation_counter, src._syn_mutation_counter); -// return; -// }; -// void end_copying(const dfs_mutation_sycnizer_t & src) -// { -// df_atomic_exchange(&_mutation_counter, src._mutation_counter); -// return; -// }; -// //数据是否完整(vs.正在修改中) -// bool intergrity_check(void) const -// { -// return (_mutation_counter == _syn_mutation_counter); -// }; -// uint64_t get_mutation_counter(void) const -// { -// return _mutation_counter; -// }; -// uint64_t get_syn_mutation_counter(void) const -// { -// return _syn_mutation_counter; -// }; -//}; - - - - -#endif //__DF_2D_ARY_INCLUDE_H_ - diff --git a/bsl/containers/btree/df_atomic.h b/bsl/containers/btree/df_atomic.h deleted file mode 100644 index 4382439fc839fd7ca158d3ed7940246fc701b625..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_atomic.h +++ /dev/null @@ -1,309 +0,0 @@ -////==================================================================== -// -// df_atomic.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-02-02 by Li Wen (liwen@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration of atomic operation -// macro __x84_64__ should be defined for 64-bit platform -// -// ------------------------------------------------------------------- -// -// Change Log -// -////==================================================================== - -#ifndef __DF_DF_ATOMIC_INCLUDE__ -#define __DF_DF_ATOMIC_INCLUDE__ - -// Proclaim we are using SMP -#ifndef CONFIG_SMP -# define CONFIG_SMP -#endif - -#include "df_def.h" - -#if defined(__i386__) || defined(__x86_64__) - -// Atomic operations that C can't guarantee us. Useful for -// resource counting etc.. -// SMP lock prefix -#ifdef CONFIG_SMP -#define LOCK_PREFIX "lock ; " -#else -#define LOCK_PREFIX "" -#endif - -//return: the incremented value; -/// 原子地做 8位,16位,32位,64位的++i的操作 -/// 该操作虽然参数和返回值都是无符号型整数,但是一样可以 -/// 对有符号型整数做操作,只需要做适当的参数转换即可 -/// @param pv 指向操作数的指针 -/// @return 操作数加1以后的数值 -#ifdef __x86_64__ -static __inline__ uint64_t df_atomic_inc(volatile uint64_t * pv) { - register unsigned long __res; - __asm__ __volatile__ ( - "movq $1,%0;" - LOCK_PREFIX "xaddq %0,(%1);" - "incq %0" - :"=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} -#endif - -static __inline__ uint32_t df_atomic_inc(volatile uint32_t * pv) { - register unsigned int __res; - __asm__ __volatile__ ( - "movl $1,%0;" - LOCK_PREFIX "xaddl %0,(%1);" - "incl %0" - :"=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} - -static __inline__ uint16_t df_atomic_inc(volatile uint16_t * pv) { - register unsigned short __res; - __asm__ __volatile__ ( - "movw $1,%0;" - LOCK_PREFIX "xaddw %0,(%1);" - "incw %0" - :"=a" (__res), "=q" (pv): "1" (pv)); - return __res; - -} - -static __inline__ uint8_t df_atomic_inc(volatile uint8_t * pv) { - register unsigned char __res; - __asm__ __volatile__ ( - "movb $1,%0;" - LOCK_PREFIX "xaddb %0,(%1);" - "incb %0" - :"=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} - -//return: the decremented value; -/// 原子地做 8位,16位,32位,64位的--i的操作 -/// 该操作虽然参数和返回值都是无符号型整数,但是一样可以 -/// 对有符号型整数做操作,只需要做适当的参数转换即可 -/// @param pv 指向操作数的指针 -/// @return 操作数减1后的数值 -#ifdef __x86_64__ -static __inline__ uint64_t df_atomic_dec(volatile uint64_t * pv) { - register unsigned long __res; - __asm__ __volatile__ ( - "movq $0xffffffffffffffff,%0;" - LOCK_PREFIX "xaddq %0,(%1);" - "decq %0" - : "=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} -#endif -static __inline__ uint32_t df_atomic_dec(volatile uint32_t * pv) { - register unsigned int __res; - __asm__ __volatile__ ( - "movl $0xffffffff,%0;" - LOCK_PREFIX "xaddl %0,(%1);" - "decl %0" - : "=a" (__res), "=q" (pv): "1" (pv)); - return __res; - -} -static __inline__ uint16_t df_atomic_dec(volatile uint16_t * pv) { - register unsigned short __res; - __asm__ __volatile__ ( - "movw $0xffff,%0;" - LOCK_PREFIX "xaddw %0,(%1);" - "decw %0" - : "=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} - -static __inline__ uint8_t df_atomic_dec(volatile uint8_t * pv) { - register unsigned char __res; - __asm__ __volatile__ ( - "movb $0xff,%0;" - LOCK_PREFIX "xaddb %0,(%1);" - "decb %0" - : "=a" (__res), "=q" (pv): "1" (pv)); - return __res; -} - -//return: the initial value of *pv -/// 原子地做 8位,16位,32位,64位的加法的操作 -/// 该操作虽然参数和返回值都是无符号型整数,但是一样可以 -/// 对有符号型整数做操作,只需要做适当的参数转换即可 -/// @param pv 指向操作数的指针 -/// @return 操作数加法之前的数值 -#ifdef __x86_64__ -static __inline__ uint64_t df_atomic_add(volatile uint64_t * pv, const uint64_t av) { - //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv)); - register unsigned long __res; - __asm__ __volatile__ ( - "movq %2,%0;" - LOCK_PREFIX "xaddq %0,(%1);" - :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv)); - return __res; -} -#endif -static __inline__ uint32_t df_atomic_add(volatile uint32_t * pv, const uint32_t av) { - //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv)); - register unsigned int __res; - __asm__ __volatile__ ( - "movl %2,%0;" - LOCK_PREFIX "xaddl %0,(%1);" - :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv)); - return __res; -} - -static __inline__ uint16_t df_atomic_add(volatile uint16_t * pv, const uint16_t av) { - //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv)); - register unsigned short __res; - __asm__ __volatile__ ( - "movw %2,%0;" - LOCK_PREFIX "xaddw %0,(%1);" - :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv)); - return __res; -} - -static __inline__ uint8_t df_atomic_add(volatile uint8_t * pv, const uint8_t av) { - //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv)); - register unsigned char __res; - __asm__ __volatile__ ( - "movb %2,%0;" - LOCK_PREFIX "xaddb %0,(%1);" - :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv)); - return __res; -} - -//function: set *pv to nv -//return: the initial value of *pv -/// 原子地把nv赋值给pv指向的整数,支持8位,16位,32位,84位操作 -/// @param pv 待赋值的整数(目的操作数) -/// @param nv 向pv赋的整数 -/// @return pv指向的赋值前的数值 -#ifdef __x86_64__ -static __inline__ uint64_t df_atomic_exchange(volatile uint64_t * pv, const uint64_t nv) { - register unsigned long __res; - __asm__ __volatile__ ( - "1:" - LOCK_PREFIX "cmpxchgq %3,(%1);" \ - "jne 1b": - "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); - return __res; -} -#endif -static __inline__ uint32_t df_atomic_exchange(volatile uint32_t * pv, const uint32_t nv) { - register unsigned int __res; - __asm__ __volatile__ ( - "1:" - LOCK_PREFIX "cmpxchgl %3,(%1);" \ - "jne 1b": - "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); - return __res; -} - -static __inline__ uint16_t df_atomic_exchange(volatile uint16_t * pv, const uint16_t nv) { - register unsigned short __res; - __asm__ __volatile__ ( - "1:" - LOCK_PREFIX "cmpxchgw %3,(%1);" \ - "jne 1b": - "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); - return __res; -} - -static __inline__ uint8_t df_atomic_exchange(volatile uint8_t * pv, const uint8_t nv) { - register unsigned char __res; - __asm__ __volatile__ ( - "1:" - LOCK_PREFIX "cmpxchgb %3,(%1);" \ - "jne 1b": - "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); - return __res; -} - -//function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing. -//return: the initial value of *pv -/// 比较pv和cv,如果两者相等,则返回pv原有数值并且把nv赋值给pv -/// 否则什么也不作,返回pv原有数值 -/// @param pv 待赋值的整数(目的操作数) -/// @param nv 向pv赋的整数 -/// @param cv 和pv比较的整数 -/// @return pv指向的操作前的数值 -#ifdef __x86_64__ -static __inline__ uint64_t df_atomic_compare_exchange(volatile uint64_t * pv, - const uint64_t nv, const uint64_t cv) { - register unsigned long __res; - __asm__ __volatile__ ( - LOCK_PREFIX "cmpxchgq %3,(%1)" - : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv)); - return __res; -} -#endif -static __inline__ uint32_t df_atomic_compare_exchange(volatile uint32_t * pv, - const uint32_t nv, const uint32_t cv) { - register unsigned int __res; - __asm__ __volatile__ ( - LOCK_PREFIX "cmpxchgl %3,(%1)" - : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv)); - return __res; -} -static __inline__ uint16_t df_atomic_compare_exchange(volatile uint16_t * pv, - const uint16_t nv, const uint16_t cv) { - register unsigned short __res; - __asm__ __volatile__ ( - LOCK_PREFIX "cmpxchgw %3,(%1)" - : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv)); - return __res; -} -static __inline__ uint8_t df_atomic_compare_exchange(volatile uint8_t * pv, - const uint8_t nv, const uint8_t cv) { - register unsigned char __res; - __asm__ __volatile__ ( - LOCK_PREFIX "cmpxchgb %3,(%1)" - : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv)); - return __res; -} - -typedef void * pvoid; - -//function: set *pv to nv -//return: the initial value of *pv -/// 把nv原子地赋值给*pv -static __inline__ pvoid df_atomic_exchange_pointer(volatile pvoid * pv, const pvoid nv) { -#ifdef __x86_64__ - return (pvoid) df_atomic_exchange((uint64_t *) pv, (uint64_t) nv); -#else - return (pvoid) df_atomic_exchange((uint32_t *) pv, (uint32_t) nv); -#endif -} -//function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing. -//return: the initial value of *pv -/// 比较cv和*pv,如果两者相等则把nv赋值给*pv,并且返回*pv原有数值 -/// 否则返回*pv原有数值,不做赋值操作 -static __inline__ pvoid df_atomic_compare_exchange_pointer(volatile pvoid * pv, - const pvoid nv, const pvoid cv) { -#ifdef __x86_64__ - return (pvoid) df_atomic_compare_exchange((uint64_t *) pv, (uint64_t) nv, (uint64_t)cv); -#else - return (pvoid) df_atomic_compare_exchange((uint32_t *) pv, (uint32_t) nv, (uint32_t)cv); -#endif -} - -#undef LOCK_PREFIX - -#else // #if defined(__i386__) || defined(__x86_64__) - -#error "must compiled on i386 or x86_64" - -#endif // - -#endif //__DF_DF_ATOMIC_INCLUDE__ diff --git a/bsl/containers/btree/df_bitops.h b/bsl/containers/btree/df_bitops.h deleted file mode 100644 index 482b5b79e399dea0aff0ad2fc8cb8549ce919a77..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_bitops.h +++ /dev/null @@ -1,34 +0,0 @@ -////==================================================================== -// -// df_bitops.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-01-14 by Ye Ling (yeling@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration of bit operation -// macro __x84_64__ should be defined for 64-bit platform -// -// ------------------------------------------------------------------- -// -// Change Log -// -////==================================================================== - -#ifndef __DF_BITOPS_H__ -# define __DF_BITOPS_H__ -# if defined __x86_64__ -# include "asm-x86_64/df_bitops.h" -# else -# if defined __i386__ -# include "asm-i386/df_bitops.h" -# else -# error "MUST COMPILED ON i386 or x86_64" -# endif -# endif -#endif - diff --git a/bsl/containers/btree/df_btree.h b/bsl/containers/btree/df_btree.h deleted file mode 100644 index acaff393e491a8df420d614b9dd0f2c4a23ed1ba..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_btree.h +++ /dev/null @@ -1,10750 +0,0 @@ -////=================================================================== -// -// df_btree.h Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-01-05 by YANG Zhenkun (yangzhenkun@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration and implementation of dfs_btree_t (btree) template -// -// ------------------------------------------------------------------- -// -// Change Log -// -// updated on 2008-07-28 by YANG Zhenkun (yangzhenkun@baidu.com) -// -////==================================================================== - - -#ifndef __DFS_BTREE_INCLUDE_H_ -#define __DFS_BTREE_INCLUDE_H_ - -//调试信息打印输出开关 -//#ifndef DF_BT_PRINT_DEBUG_INFO -//#define DF_BT_PRINT_DEBUG_INFO -//#endif - -# if defined __x86_64__ -# else -# error "MUST COMPILED ON x86_64" -# endif - -#include - -//#include "ul_def.h" -//#include "df_common.h" -#include "df_misc.h" -#include "df_2d_ary.h" -//zhangyan04@baidu.com -#include "bsl_kv_btree_xmemcpy.h" - -//By yangzhenkun@baidu.com at 20090218 -//先前:如果“get_mutation_counter() > _bt_get_max_cow_mutation_counter()”(可能还有其他条件) -//则直接修改B树节点可能“使得一个正在读的节点被回收”。现在改为所有的修改都一直波及到根节点。 -//#ifndef BT_ALLOW_SERIAL_READ_WRITE -//#define BT_ALLOW_SERIAL_READ_WRITE -//#endif -//该宏可以减少B树结点一个uint64_t(用于记录mutation_cnt),但同时也降低了robust, -//反复考虑后暂不启用 yangzhenkun@baidu.com 2009/03/12 -//#ifndef BT_NO_BT_NODE_BASE_MUTATION_COUNTER -//#define BT_NO_BT_NODE_BASE_MUTATION_COUNTER -//#endif - -// 功能:从文件位置filepos读或写data_len字节数据,然后把文件当前位置移动到读或写后的位置 -// 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 -// filepos:文件读出或写入数据的起始位置(相对值),该位置以store或load调用时为基准。 -// data_len:数据长度,缓冲区的长度>=data_len -// 返回:0 for success, other values for error (如果读写错或者没有读写到指定大小的数据) -typedef int (*dfs_write_proc_t)( - void * file_info, - const int64_t filepos, - const void * buf, - const uint64_t data_len); -typedef int (*dfs_read_proc_t)( - void * file_info, - const int64_t filepos, - void * buf, - const uint64_t data_len); - -//用户数据类型T需要支持以下接口: -// 功能:获得该实例store的数据长度(字节),该值不能超过MAX_T_STORE_SIZE -// uint64_t get_store_size(void) const; -// -// 功能:存储该实例到buf -// 输入:data_pos为存储数据的起始位置 -// 输出:data_pos为存储T后新的起始位置 -// 返回:0 for success, other values for error -// int store(char * buf, const uint32_t buf_size, uint32_t & data_pos) const; -// -// 功能:获得该实例store的数据长度(字节),该值不能超过MAX_T_STORE_SIZE -// 输入:data_pos为存储数据的起始位置 -// 输出:data_pos为存储T后新的起始位置 -// 返回:0 for success, other values for error -// int load(char * buf, const uint32_t buf_size, uint32_t & data_pos); -// - - -class dfs_file_rw_info_t { -public: - int fd; - int reserved; - int64_t orig_offset; //typically zero -}; - - -//int dfs_write_proc(void * file_info, const int64_t filepos, const void * buf, const uint64_t data_len); -//int dfs_read_proc(void * file_info, const int64_t filepos, void * buf, uint64_t & data_len); - -inline int dfs_write_proc(void * file_info, const int64_t filepos, const void * buf, const uint64_t data_len) { - int err = 0; - - if (NULL == file_info) { - err = -1; - } else { - dfs_file_rw_info_t & rw_info = *((dfs_file_rw_info_t *)file_info); - int64_t written_len = pwrite(rw_info.fd, buf, data_len, rw_info.orig_offset+filepos); - - err = (data_len == (uint64_t)written_len) ? 0 : -1; - } - - return err; -}; - -inline int dfs_read_proc(void * file_info, const int64_t filepos, void * buf, const uint64_t data_len) { - int err = 0; - - if (NULL == file_info) { - err = -1; - } else { - dfs_file_rw_info_t & rw_info = *((dfs_file_rw_info_t *)file_info); - int64_t read_len = pread(rw_info.fd, buf, data_len, rw_info.orig_offset+filepos); - - err = (data_len == (uint64_t)read_len) ? 0 : -1; - } - - return err; -}; - - - -template class dfs_btree_node_base_t; -template class dfs_btree_leaf_node_t; -template class dfs_btree_mid_node_t; - -template -class dfs_btree_node_base_t : public dfs_bt_const_t { - friend class dfs_btree_leaf_node_t; - friend class dfs_btree_mid_node_t; -protected: - enum cconst_protected { - BT_HALF_FANOUT = FANOUT/2, - //leaf or mid - ATTR_MIDNODE_FLAG = 1, //this is a middle node instead of leaf node - MAX_KEY_NUM = FANOUT-1 , - }; -private: - uint16_t _attr; - uint16_t _subkey_num; - uint32_t _reserved; //保留 - uint64_t _mutation_counter; //mutation counter,在申请时获得,以后都不修改 -protected: - uint64_t _subkey_index_ary[MAX_KEY_NUM]; //the first unit also servers as the next index when this unit is free -private: - //此类不单独使用,因此其构造及析构函数为private - dfs_btree_node_base_t() { - init(); - }; - ~dfs_btree_node_base_t() { - }; - dfs_btree_node_base_t(const dfs_btree_node_base_t & src) : dfs_btree_node_base_t() { - *this = src; - }; - dfs_btree_node_base_t & operator=(const dfs_btree_node_base_t & src) { - if (&src != this) { - //zhangyan04 - //memcpy(this, &src, sizeof(*this)); - ZY::xmemcpy(this, &src, sizeof(*this)); - } - return *this; - }; -protected: - void init(void) { - int64_t j = 0; - - _attr = 0; - _subkey_num = 0; - _reserved = 0; - _mutation_counter = 0; - for (j = 0; j < (int64_t)df_len_of_ary(_subkey_index_ary); ++j) { - _subkey_index_ary[j] = UNDEF_INDEX; - } - return; - }; -public: - const uint64_t * get_subkey_ary(void) const { - return _subkey_index_ary; - }; - uint32_t get_subkey_num(void) const { - return _subkey_num; - }; - //return: 0 for success, other value for error - int set_subkey_num(const uint32_t subkey_num) { - int err = 0; - - if (subkey_num <= MAX_KEY_NUM) { - _subkey_num = subkey_num; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_SUBKEY_NUM); - } - - return err; - }; - void set_mutation_counter(const uint64_t mutation_counter) { - _mutation_counter = mutation_counter; - }; - uint64_t get_mutation_counter(void) const { - return _mutation_counter; - }; - bool is_leaf_node(void) const { - return ((_attr & ATTR_MIDNODE_FLAG) == 0); - }; - bool is_mid_node(void) const { - return ((_attr & ATTR_MIDNODE_FLAG) != 0); - }; -public: - //insert an item into scr_buff but save result to tag_buff - //There should be no overlap between tag_buff and src_buff. - //return: 0 for success, other value for error - static int insert( - uint64_t * tag_buff, - const uint32_t tag_buff_len, - const uint64_t * src_buff, - const uint32_t src_data_len, - const uint32_t ins_pos, - const uint64_t ins_data) { - int err = 0; - - if (src_data_len < tag_buff_len && ins_pos <= src_data_len) { - //zhangyan04 - //memcpy(tag_buff, src_buff, ins_pos*sizeof(tag_buff[0])); - ZY::xmemcpy(tag_buff, src_buff, ins_pos*sizeof(tag_buff[0])); - tag_buff[ins_pos] = ins_data; - //zhangyan04 - //memcpy(tag_buff+ins_pos+1, src_buff+ins_pos, (src_data_len-ins_pos)*sizeof(tag_buff[0])); - ZY::xmemcpy(tag_buff+ins_pos+1, src_buff+ins_pos, (src_data_len-ins_pos)*sizeof(tag_buff[0])); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_NODE_POS); - } - - return err; - }; - //delete an item from scr_buff but save result to tag_buff - //There should be no overlap between tag_buff and src_buff. - //return: 0 for success, other value for error - static int del( - uint64_t * tag_buff, - const uint32_t tag_buff_len, - const uint64_t * src_buff, - const uint32_t src_data_len, - const uint32_t del_pos) { - int err = 0; - - if (del_pos < src_data_len && (src_data_len-1) <= tag_buff_len) { - //zhangyan04 - //memcpy(tag_buff, src_buff, del_pos*sizeof(tag_buff[0])); - ZY::xmemcpy(tag_buff, src_buff, del_pos*sizeof(tag_buff[0])); - //memcpy(tag_buff+del_pos,src_buff+(del_pos+1),(src_data_len-(del_pos+1))*sizeof(tag_buff[0])); - ZY::xmemcpy(tag_buff+del_pos,src_buff+(del_pos+1),(src_data_len-(del_pos+1))*sizeof(tag_buff[0])); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_NODE_POS); - } - - return err; - }; -public: - bool is_full(void) const { - return (this->get_subkey_num() >= df_len_of_ary(this->_subkey_index_ary)); - }; - //return: key_index, UNDEF_INDEX for invalid pos - uint64_t get_subkey_index(const uint32_t pos) const { - uint64_t key_index = UNDEF_INDEX; - int err = 0; - - if (pos < this->get_subkey_num()) { - key_index = this->_subkey_index_ary[pos]; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - key_index = UNDEF_INDEX; - } - - return key_index; - }; - int get_subkeys( - uint64_t * buff, - const uint32_t buff_len) const { - int err = 0; - - if (this->get_subkey_num() < buff_len) { - //zhangyan04 - //memcpy(buff, this->_subkey_index_ary, this->get_subkey_num()*sizeof(buff[0])); - ZY::xmemcpy(buff, this->_subkey_index_ary, this->get_subkey_num()*sizeof(buff[0])); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_BUF_SIZE); - } - - return err; - }; - //insert a key into this obj, but save the result to a buff - //return: 0 for success, other value for error - int insert_subkey( - uint64_t * tag_buff, - const uint32_t buff_len, - const uint32_t ins_pos, - const uint64_t ins_key_index) const { - return insert( - tag_buff, - buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - ins_pos, - ins_key_index); - }; - //delete a key from this obj, but save the result to a buff - //return: 0 for success, other value for error - int del_subkey( - uint64_t * tag_buff, - const uint32_t buff_len, - const uint32_t del_pos) const { - return del( - tag_buff, - buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - }; -}; - - -template -class dfs_btree_leaf_node_t : public dfs_btree_node_base_t { -protected: - enum cconst_protected { - //FANOUT = dfs_btree_node_base_t::FANOUT, - }; -public: - friend class dfs_btree_leaf_node_t; - dfs_btree_leaf_node_t() { - init(); - }; - dfs_btree_leaf_node_t(const dfs_btree_leaf_node_t & src) { - *this = src; - }; - dfs_btree_leaf_node_t & operator=(const dfs_btree_leaf_node_t & src) { - if (&src != this) { - //zhangyan04 - //memcpy(this, &src, sizeof(*this)); - ZY::xmemcpy(this, &src, sizeof(*this)); - } - return *this; - }; - ~dfs_btree_leaf_node_t() { - }; - void init(void) { - dfs_btree_node_base_t::init(); - this->_attr &= ~(this->ATTR_MIDNODE_FLAG); - }; -public: - //insert a key into this obj, but save the result to a buff - //return: 0 for success, other value for error - int insert_subkey( - uint64_t * tag_buff, - const uint32_t buff_len, - const uint32_t ins_pos, - const uint64_t ins_key_index) const { - return insert( - tag_buff, - buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - ins_pos, - ins_key_index); - }; - //insert a key into this obj, but save the result to tag_node - //return: 0 for success, other value for error - int insert_subkey( - dfs_btree_leaf_node_t & tag_node, - const uint32_t ins_pos, - const uint64_t ins_key_index) const { - int err = 0; - - err = insert( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - ins_pos, - ins_key_index); - - if (0 == err) { - err = tag_node.set_subkey_num(this->get_subkey_num()+1); - } - - return err; - }; - //insert a key into this obj, but save the result to tag_node - //return: 0 for success, other value for error - int insert_subkey( - dfs_btree_leaf_node_t & tag_node, - const uint32_t ins_pos, - const uint64_t ins_key_index) const { - int err = 0; - - err = insert( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - ins_pos, - ins_key_index); - - if (0 == err) { - err = tag_node.set_subkey_num(this->get_subkey_num()+1); - } - - return err; - }; - //delete a key from this obj, but save the result to a buff - //return: 0 for success, other value for error - int del_subkey( - uint64_t * tag_buff, - const uint32_t buff_len, - const uint32_t del_pos) const { - return del( - tag_buff, buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - }; - //delete a key from this obj, but save the result to tag_node - //return: 0 for success, other value for error - int del_subkey( - dfs_btree_leaf_node_t & tag_node, - const uint32_t del_pos) const { - int err = del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - - if (0 == err) { - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } - - return err; - }; - //delete a key from this obj, but save the result to tag_node - //return: 0 for success, other value for error - int del_subkey( - dfs_btree_leaf_node_t & tag_node, - const uint32_t del_pos) const { - int err = del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - - if (0 == err) { - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } - - return err; - }; - //update a key of this obj - //return: 0 for success, other value for error - int update_subkey( - const uint32_t update_key_pos, - const uint64_t new_key_index, - uint64_t & old_key_index) { - int err = 0; - - if (update_key_pos < this->get_subkey_num()) { - old_key_index = df_atomic_exchange(this->_subkey_index_ary+update_key_pos, new_key_index); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a key of this obj, but save the result to the tag obj - //return: 0 for success, other value for error - int update_subkey( - dfs_btree_leaf_node_t & tag_node, - const uint32_t update_key_pos, - const uint64_t new_key_index) const { - int err = 0; - - if (update_key_pos < this->get_subkey_num()) { - tag_node = *this; - tag_node._subkey_index_ary[update_key_pos] = new_key_index; - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //return: 0 for success, other value for error - int put_subkeys( - const uint64_t * buff, - const uint32_t subkey_num) { - int err = 0; - - if (subkey_num <= df_len_of_ary(this->_subkey_index_ary)) { - //zhangyan04 - //memcpy(this->_subkey_index_ary, buff, subkey_num*sizeof(this->_subkey_index_ary[0])); - ZY::xmemcpy(this->_subkey_index_ary, buff, subkey_num*sizeof(this->_subkey_index_ary[0])); - err = this->set_subkey_num(subkey_num); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; -public: - //增加时所做的操作 - //如果copy叶子节点的话,,那么可以不进行任何操作... - inline int action_while_added(void * /*pgc_info*/, - const uint64_t /*node_index*/) { - return 0; - }; - //删除前所做的操作 - inline int action_before_gc(void * /*pgc_info*/, - const uint64_t /*node_index*/); -}; - - -template -class dfs_btree_mid_node_t : public dfs_btree_node_base_t { -protected: - enum cconst_protected { - //FANOUT = dfs_btree_node_base_t::FANOUT, - }; -public: - friend class dfs_btree_mid_node_t; - dfs_btree_mid_node_t() { - init(); - }; - dfs_btree_mid_node_t(const dfs_btree_mid_node_t & src) : dfs_btree_node_base_t() { - *this = src; - }; - dfs_btree_mid_node_t & operator=(const dfs_btree_mid_node_t & src) { - if (&src != this) { - //zhangyan04 - //memcpy(this, &src, sizeof(*this)); - ZY::xmemcpy(this, &src, sizeof(*this)); - } - return *this; - }; - ~dfs_btree_mid_node_t() { - }; - void init(void) { - int64_t j = 0; - - dfs_btree_node_base_t::init(); - this->_attr |= this->ATTR_MIDNODE_FLAG; - for (j = 0; j < (int64_t)df_len_of_ary(_subnode_index_ary); ++j) { - _subnode_index_ary[j] = UNDEF_INDEX; - } - return; - }; -protected: - uint64_t _subnode_index_ary[FANOUT]; -public: - //return: key_index, UNDEF_INDEX for invalid pos - uint64_t get_subnode_index(const uint32_t pos) const { - uint64_t node_index = UNDEF_INDEX; - int err = 0; - - if (pos <= this->get_subkey_num()) { - node_index = this->_subnode_index_ary[pos]; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - node_index = UNDEF_INDEX; - } - - return node_index; - }; -public: - //说明:update_node_index更新update_pos处,然后在update_pos左边插入(left_key_index,left_son_node_index)对, - // 结果保存在tag_node。 - //return: 0 for success, other value for error - int update_then_ins_to_left( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t left_key_index, - const uint64_t left_node_index, - const uint64_t update_node_index) const { - int err = 0; - - if (this->get_subkey_num() < df_len_of_ary(this->_subkey_index_ary) - && update_pos <= this->get_subkey_num()) { - if ((err = insert( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos, - left_key_index)) == 0 - && (err = insert( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos, - left_node_index)) == 0) { - tag_node._subnode_index_ary[update_pos+1] = update_node_index; - err = tag_node.set_subkey_num(this->get_subkey_num()+1); - } - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //说明:update_node_index更新update_pos处,然后在update_pos左边插入(left_key_index,left_son_node_index)对, - // 结果保存在tag_node。 - //return: 0 for success, other value for error - int update_then_ins_to_left( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t left_key_index, - const uint64_t left_node_index, - const uint64_t update_node_index) const { - int err = 0; - - if (update_pos <= this->get_subkey_num()) { - if ((err = insert - (tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos, - left_key_index)) == 0 - && (err = insert( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos, - left_node_index)) == 0) { - tag_node._subnode_index_ary[update_pos+1] = update_node_index; - err = tag_node.set_subkey_num(this->get_subkey_num()+1); - } - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //说明:update_node_index更新update_pos处,然后在update_pos左边插入(left_key_index,left_son_node_index)对, - // 结果保存在tag_key_buff和tag_node_buff。 - //return: 0 for success, other value for error - int update_then_ins_to_left( - uint64_t * tag_key_buff, - uint64_t * tag_node_buff, - const uint32_t key_buff_len, //(node_buff_len >= key_buff_len+1) - const uint32_t update_pos, - const uint64_t left_key_index, - const uint64_t left_node_index, - const uint64_t update_node_index) const { - int err = 0; - - if (this->get_subkey_num() < key_buff_len && update_pos <= this->get_subkey_num()) { - if ((err = insert( - tag_key_buff, - key_buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos, - left_key_index)) == 0 - && (err = insert( - tag_node_buff, - key_buff_len+1, - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos, - left_node_index)) == 0) { - tag_node_buff[update_pos+1] = update_node_index; - err = 0; - } - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //return: 0 for success, other value for error - int put_pairs( - const uint64_t * key_buff, - const uint64_t * node_buff, - const uint32_t subkey_num) { - int err = 0; - - if (subkey_num <= df_len_of_ary(this->_subkey_index_ary)) { - //zhangyan04 - //memcpy(this->_subkey_index_ary,key_buff,subkey_num*sizeof(this->_subkey_index_ary[0])); - ZY::xmemcpy(this->_subkey_index_ary,key_buff,subkey_num*sizeof(this->_subkey_index_ary[0])); - //memcpy(this->_subnode_index_ary,node_buff,(subkey_num+1)*sizeof(this->_subnode_index_ary[0])); - ZY::xmemcpy(this->_subnode_index_ary,node_buff,(subkey_num+1)*sizeof(this->_subnode_index_ary[0])); - err = this->set_subkey_num(subkey_num); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_BUF_SIZE); - } - - return err; - }; - //export nodes to a buff - //return: 0 for success, other value for error - int export_subnode_index( - uint64_t * tag_node_buff, - const uint32_t node_buff_len) const { - int err = 0; - - if ((this->get_subkey_num()+1) <= node_buff_len) { - //zhangyan04 - //memcpy(tag_node_buff,this->_subnode_index_ary,(this->get_subkey_num()+1)*sizeof(tag_node_buff[0])); - ZY::xmemcpy(tag_node_buff,this->_subnode_index_ary,(this->get_subkey_num()+1)*sizeof(tag_node_buff[0])); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_BUF_SIZE); - } - - return err; - }; - //insert a key into this obj, but save the result to a buff - //return: 0 for success, other value for error - int insert_subkey( - uint64_t * tag_buff, - const uint32_t buff_len, - const uint32_t ins_pos, - const uint64_t ins_key_index) const { - - return insert( - tag_buff, - buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - ins_pos, - ins_key_index); - }; - //update a key of this obj - //return: 0 for success, other value for error - int update_subkey( - const uint32_t update_key_pos, - const uint64_t new_key_index, - uint64_t & old_key_index) { - int err = 0; - - if (update_key_pos < this->get_subkey_num()) { - old_key_index = df_atomic_exchange(this->_subkey_index_ary+update_key_pos, new_key_index); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a subnode of this obj - //return: 0 for success, other value for failure - int update_subnode( - const uint32_t update_subnode_pos, - const uint64_t new_subnode_index, - uint64_t & old_subnode_index) { - int err = 0; - - if (update_subnode_pos <= this->get_subkey_num()) { - old_subnode_index = df_atomic_exchange(this->_subnode_index_ary+update_subnode_pos, - new_subnode_index); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a key of this obj, but save the result to the tag obj - //return: 0 for success, other value for error - int update_subkey( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_key_pos, - const uint64_t new_key_index) const { - int err = 0; - - if (update_key_pos < this->get_subkey_num()) { - tag_node = *this; - tag_node._subkey_index_ary[update_key_pos] = new_key_index; - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a subnode of this obj, but save the result to the tag obj - //return: 0 for success, other value for failure - int update_subnode( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_subnode_index) const { - int err = 0; - - if (update_pos <= this->get_subkey_num()) { - tag_node = *this; - tag_node._subnode_index_ary[update_pos] = new_subnode_index; - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a (key,node) pair as well as a followed node of this obj, but save the result to the tag obj - //return: 0 for success, other value for error - int update_brothers( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_key_index, - const uint64_t new_node_index, - const uint64_t new_right_node_index) const { - int err = 0; - - if (update_pos < this->get_subkey_num()) { - tag_node = *this; - tag_node._subkey_index_ary[update_pos] = new_key_index; - tag_node._subnode_index_ary[update_pos] = new_node_index; - tag_node._subnode_index_ary[update_pos+1] = new_right_node_index; - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a (key,node) pair as well as a followed node of this obj, but save the result to the tag buff - //return: 0 for success, other value for error - int update_brothers( - uint64_t * tag_key_buff, - uint64_t * tag_node_buff, - const uint32_t key_buff_len, //(node_buff_len >= key_buff_len+1) - const uint32_t update_pos, - const uint64_t new_key_index, - const uint64_t new_node_index, - const uint64_t new_right_node_index) const { - int err = 0; - - if (update_pos < this->get_subkey_num() && key_buff_len >= this->get_subkey_num()) { - //zhangyan04 - //memcpy(tag_key_buff,this->_subkey_index_ary,this->get_subkey_num()*sizeof(tag_key_buff[0])); - ZY::xmemcpy(tag_key_buff,this->_subkey_index_ary,this->get_subkey_num()*sizeof(tag_key_buff[0])); - //memcpy(tag_node_buff,this->_subnode_index_ary,(this->get_subkey_num()+1)*sizeof(tag_node_buff[0])); - ZY::xmemcpy(tag_node_buff,this->_subnode_index_ary,(this->get_subkey_num()+1)*sizeof(tag_node_buff[0])); - tag_key_buff[update_pos] = new_key_index; - tag_node_buff[update_pos] = new_node_index; - tag_node_buff[update_pos+1] = new_right_node_index; - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - ////update a (key,node) pair, but save the result to the tag obj - ////return: 0 for success, other value for error - //int update_pair( - // dfs_btree_mid_node_t & tag_node, - // const uint32_t update_pos, - // const uint64_t new_key_index, - // const uint64_t new_node_index) const - //{ - // int err = 0; - - // if (update_pos < this->get_subkey_num()) - // { - // tag_node = *this; - // tag_node._subkey_index_ary[update_pos] = new_key_index; - // tag_node._subnode_index_ary[update_pos] = new_node_index; - // err = 0; - // } - // else - // { - // err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - // } - - // return err; - //}; - //delete a pair from this obj, but save the result to a buff - //return: 0 for success, other value for error - int del_pair( - uint64_t * tag_key_buff, - uint64_t * tag_node_buff, - const uint32_t key_buff_len, //(node_buff_len >= key_buff_len+1) - const uint32_t del_pos) const { - int err = 0; - - if (del_pos < this->get_subkey_num() && (key_buff_len+1) >= this->get_subkey_num()) { - del( - tag_key_buff, key_buff_len, - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - del( - tag_node_buff, key_buff_len+1, - this->_subnode_index_ary, - this->get_subkey_num()+1, - del_pos); - err = 0; - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //delete a pair from this obj, but save the result to a tag obj - //return: 0 for success, other value for error - int del_pair( - dfs_btree_mid_node_t & tag_node, - const uint32_t del_pos) const { - int err = 0; - - if (del_pos < this->get_subkey_num()) { - del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - del_pos); - del( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - del_pos); - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - - //update a subnode pointed by update_pos and delete its left pair, but save the result to a tag obj - int update_then_del_left( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_node_index) const { - int err = 0; - - if (0 < update_pos && update_pos <= this->get_subkey_num()) { - del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos-1); - del( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos-1); - tag_node._subnode_index_ary[update_pos-1] = new_node_index; - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update a subnode pointed by update_pos and delete its left pair, but save the result to a tag obj - int update_then_del_left( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_node_index) const { - int err = 0; - - if (0 < update_pos && update_pos <= this->get_subkey_num()) { - del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos-1); - del( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos-1); - tag_node._subnode_index_ary[update_pos-1] = new_node_index; - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - - //update the left pair and the right subnode and delete myself pair, but save the result to a tag obj - int update_both_sides_then_del_mid( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_left_key_index, - const uint64_t new_left_subnode_index, - const uint64_t new_right_subnode_index) const { - int err = 0; - - if (0 < update_pos && (update_pos+1) <= this->get_subkey_num()) { - del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos); - del( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos); - tag_node._subkey_index_ary[update_pos-1] = new_left_key_index; - tag_node._subnode_index_ary[update_pos-1] = new_left_subnode_index; - tag_node._subnode_index_ary[update_pos] = new_right_subnode_index; - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; - //update the left pair and the right subnode and delete myself pair, but save the result to a tag obj - int update_both_sides_then_del_mid( - dfs_btree_mid_node_t & tag_node, - const uint32_t update_pos, - const uint64_t new_left_key_index, - const uint64_t new_left_subnode_index, - const uint64_t new_right_subnode_index) const { - int err = 0; - - if (0 < update_pos && (update_pos+1) <= this->get_subkey_num()) { - del( - tag_node._subkey_index_ary, - df_len_of_ary(tag_node._subkey_index_ary), - this->_subkey_index_ary, - this->get_subkey_num(), - update_pos); - del( - tag_node._subnode_index_ary, - df_len_of_ary(tag_node._subnode_index_ary), - this->_subnode_index_ary, - this->get_subkey_num()+1, - update_pos); - tag_node._subkey_index_ary[update_pos-1] = new_left_key_index; - tag_node._subnode_index_ary[update_pos-1] = new_left_subnode_index; - tag_node._subnode_index_ary[update_pos] = new_right_subnode_index; - err = tag_node.set_subkey_num(this->get_subkey_num()-1); - } else { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NODE_POS); - } - - return err; - }; -public: - //增加时所做的操作 - inline int action_while_added(void * /*pgc_info*/, - const uint64_t /*node_index*/) { - return 0; - }; - //删除前所做的操作 - inline int action_before_gc(void * /*pgc_info*/, - const uint64_t /*node_index*/); -}; - - -//单一B树的根节点 -class dfs_sbt_root_t { //single btree root -private: - uint64_t _root_node_index; - uint64_t _next_allocate_id; - uint64_t _mutation_counter; -public: - dfs_sbt_root_t() { - init(); - }; - ~dfs_sbt_root_t() { - }; -public: - inline const dfs_sbt_root_t & operator=(const dfs_sbt_root_t & src) { - if (&src != this) { - _root_node_index = src._root_node_index ; - _next_allocate_id = src._next_allocate_id ; - _mutation_counter = src._mutation_counter ; - } - return *this; - }; -public: - inline void set_value(const dfs_sbt_root_t & src) { - *this = src; - }; -public: - dfs_sbt_root_t(const dfs_sbt_root_t & src) : - _root_node_index(src._root_node_index), - _next_allocate_id(src._next_allocate_id), - _mutation_counter(src._mutation_counter) { - }; - void init(void) { - _root_node_index = UNDEF_INDEX; - //从编号1开始进行分配... - _next_allocate_id = 1; //skip NULL_ID - _mutation_counter = 0; - return; - }; -public: - //输入:new_root_index - //return: 0 for success, other values for error - int set_root_node_index(uint64_t & old_root_index, const uint64_t new_root_index) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX == new_root_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_root_index"); - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_INVALID_INDEX); - } else { - old_root_index = df_atomic_exchange(&_root_node_index, new_root_index); - } - - return 0; - }; - uint64_t get_root_node_index(void) const { - return _root_node_index; - }; -public: - bool is_invalid_id(const uint64_t id) const { - return (NULL_ID == id || UNDEF_ID == id - || ((_next_allocate_id > 1) && (id >= _next_allocate_id))); - }; - uint64_t alloc_id(void) { - return df_atomic_inc(&_next_allocate_id)-1; - }; - void set_next_allocate_id(const uint64_t next_allocate_id) { - df_atomic_exchange(&_next_allocate_id, next_allocate_id); - return; - }; - uint64_t get_next_allocate_id(void) const { - return _next_allocate_id; - }; - uint64_t get_mutation_counter(void) const { - return _mutation_counter; - }; - void set_mutation_counter(const uint64_t mutation_counter) { - _mutation_counter = mutation_counter; - return ; - }; - //uint64_t inc_mutation_counter(void) - //{ - // return ++_mutation_counter; - //}; -}; - -class dfs_btree_t; - -// -//根节点信息 -class dfs_bt_root_t : public dfs_bt_const_t { -private: - //dfs_btree_t * _pbtree; - //这个多个单根实例...:). - //fp最高可能到4. - dfs_sbt_root_t _sbt_root_ary[MAX_BT_INSTANCE_NUM]; -public: - dfs_bt_root_t() { // : _pbtree(NULL) - //init(); - }; - ~dfs_bt_root_t() { - }; - const dfs_bt_root_t & operator=(const dfs_bt_root_t & src) { - if (&src != this) { - //memcpy(this, &src, sizeof(*this)); - for (int64_t j = 0; j < (int64_t)df_len_of_ary(_sbt_root_ary); ++j) { - _sbt_root_ary[j] = src._sbt_root_ary[j]; - } - } - return *this; - }; - dfs_bt_root_t(const dfs_bt_root_t & src) { - //memcpy(this, &src, sizeof(*this)); - for (int64_t j = 0; j < (int64_t)df_len_of_ary(_sbt_root_ary); ++j) { - _sbt_root_ary[j] = src._sbt_root_ary[j]; - } - }; - void init(void) { - for (int64_t j = 0; j < (int64_t)df_len_of_ary(_sbt_root_ary); ++j) { - _sbt_root_ary[j].init(); - } - return; - }; -public: - //void set_btree(dfs_btree_t * pbtree) - //{ - // _pbtree = pbtree; - //}; - //输入:new_root_node_index(might be UNDEF_INDEX) - //return: 0 for success, other values for error - int set_root(const dfs_sbt_root_t & sbt_root, const uint32_t pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - DF_WRITE_LOG_US(log_level, "pos=%d", pos); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } - _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)].set_value(sbt_root); - - return err; - }; - const dfs_sbt_root_t & get_root(const uint32_t pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - DF_WRITE_LOG_US(log_level, "pos=%d", pos); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } - - return _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)]; - }; -public: - //输入:new_root_index - //return: 0 for success, other values for error - int set_root_node_index(uint64_t & old_root_index, const uint64_t new_root_index, const uint32_t pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - DF_WRITE_LOG_US(log_level, - "new_root_index=0x%lx, pos=%u", - new_root_index, pos); - } else if (UNDEF_INDEX == new_root_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_root_index"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - DF_WRITE_LOG_US(log_level, - "new_root_index=0x%lx, pos=%u", - new_root_index, pos); - } else if ((err = _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)].set_root_node_index( - old_root_index, - new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_sbt_root_ary[].set_root_node_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "new_root_index=0x%lx, pos=%u", - new_root_index, pos); - } - - return err; - }; - uint64_t get_root_node_index(const uint32_t pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - DF_WRITE_LOG_US(log_level, "pos=%d", pos); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } - - return _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)].get_root_node_index(); - }; - //int set_mutation_counter(const uint64_t mutation_counter, const uint32_t pos) - //{ - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // if (pos >= df_len_of_ary(_root_info_ary)) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_root_info_ary)"); - // DF_WRITE_LOG_US(log_level, "pos=%d", pos); - // err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - // } - // - // return _root_info_ary[pos%df_len_of_ary(_root_info_ary)].set_mutation_counter(mutation_counter); - //}; - //uint64_t get_mutation_counter(const uint32_t pos) const - //{ - // int log_level = DF_UL_LOG_NONE; - // int err = 0; - // - // if (pos >= df_len_of_ary(_root_info_ary)) - // { - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_root_info_ary)"); - // DF_WRITE_LOG_US(log_level, "pos=%d", pos); - // err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - // } - // - // return _root_info_ary[pos%df_len_of_ary(_root_info_ary)].get_mutation_counter(); - //}; - bool is_invalid_id(const uint64_t id, const uint32_t pos) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - DF_WRITE_LOG_US(log_level, "pos=%d", pos); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } - - return _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)].is_invalid_id(id); - }; - uint64_t alloc_id(const uint32_t pos) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (pos >= df_len_of_ary(_sbt_root_ary)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= df_len_of_ary(_sbt_root_ary)"); - DF_WRITE_LOG_US(log_level, "pos=%d", pos); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } - - return _sbt_root_ary[pos%df_len_of_ary(_sbt_root_ary)].alloc_id(); - }; -public: - //增加/减少根节点引用计数 - //????. - //????. - inline int action_while_added(void * pgc_info, const uint64_t node_index); - inline int action_before_gc(void * pgc_info, const uint64_t node_index); -}; - - - -//当删除操作发生在中间节点时,dfs_btree_drill_t中对应的node_index被替换成一个新的, -//对应位置的key_index被替换成其子树的最大的key_index -class dfs_btree_drill_t : public dfs_bt_const_t { -protected: - int _drill_ptr; - int _del_mid_drill_ptr; //删除所在中间节点 - uint64_t _del_mid_old_node_index; //删除所在中间节点原来的node_index - uint64_t _btree_mutation_counter; //inc whenever there is an update,修改的计数范围... - uint64_t _subnode_index_ary[MAX_BT_DEPTH]; //the node history for drilling down...node to drill down.. - uint32_t _ins_pos_ary[MAX_BT_DEPTH]; //insert pos in the node (_subnode_index_ary[]) of btree -public: - dfs_btree_drill_t() { - init(); - }; - ~dfs_btree_drill_t() { - }; - dfs_btree_drill_t & operator=(const dfs_btree_drill_t & src) { - if (&src != this) { - //zhangyan04 - //memcpy(this, &src, sizeof(*this)); - ZY::xmemcpy(this, &src, sizeof(*this)); - } - return *this; - }; - bool operator==(const dfs_btree_drill_t & src) const { - return (_drill_ptr == src._drill_ptr && - memcmp( - _subnode_index_ary, - src._subnode_index_ary, - (_drill_ptr+1)*sizeof(_subnode_index_ary[0])) == 0 - && memcmp( - _ins_pos_ary, - src._ins_pos_ary, - (_drill_ptr+1)*sizeof(_ins_pos_ary[0])) == 0); - }; - bool operator!=(const dfs_btree_drill_t & src) const { - return !(operator==(src)); - }; - void init(void) { - int64_t j = 0; - - _drill_ptr = -1; - _del_mid_drill_ptr = MAX_BT_DEPTH; //????. - _del_mid_old_node_index = UNDEF_INDEX; - _btree_mutation_counter = 0; - - for (j = 0; j < (int64_t)df_len_of_ary(_subnode_index_ary); ++j) { - _subnode_index_ary[j] = UNDEF_INDEX; - } - for (j = 0; j < (int64_t)df_len_of_ary(_ins_pos_ary); ++j) { - _ins_pos_ary[j] = 0; - } - - return; - }; -public: - //return: 0 for success, other value for error - int push(const uint32_t ins_pos, const uint64_t node_index) { - int err = 0; - - if (_drill_ptr < ((int)df_len_of_ary(_subnode_index_ary)-1)) { - ++_drill_ptr; - _subnode_index_ary[_drill_ptr] = node_index; - _ins_pos_ary[_drill_ptr] = ins_pos; - err = 0; - } else { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, "error: push drill overflow _drill_ptr=%d", _drill_ptr); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_OVERFLOW); - } - - return err; - }; - //return: 0 for success, other value for error - int pop(void) { - int err = 0; - - if (_drill_ptr >= 0) { - _subnode_index_ary[_drill_ptr] = UNDEF_INDEX; - --_drill_ptr; - err = 0; - } else { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, "error: pop drill underflow _drill_ptr=%d", _drill_ptr); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_UNDERFLOW); - } - - return err; - }; -public: - int get_drill_ptr(void) const { - return _drill_ptr; - }; - //return: node_index,UNDEF_INDEX for invalid drill_pos - uint64_t get_node_index(const int drill_pos) const { - uint64_t node_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (drill_pos >= 0 && drill_pos <= _drill_ptr) { - if ((node_index = _subnode_index_ary[drill_pos]) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_NODE_INDEX); - } - } else { - log_level = DF_UL_LOG_TRACE; - DF_WRITE_LOG_US(log_level, "drill_pos < 0 || drill_pos > _drill_ptr"); - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_DRILL_POS); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_pos=%d, _drill_ptr=%d, node_index=0x%lx", - drill_pos, _drill_ptr, node_index) - } - - return node_index; - }; - //return: node_index,UNDEF_INDEX for invalid drill_pos - uint64_t get_last_node_index(void) const { - uint64_t node_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_drill_ptr >= 0 && _drill_ptr < (int)df_len_of_ary(_subnode_index_ary)) { - if ((node_index = _subnode_index_ary[_drill_ptr]) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_NODE_INDEX); - } - } else { - log_level = DF_UL_LOG_TRACE; - DF_WRITE_LOG_US(log_level, "_drill_ptr < 0 || _drill_ptr >= df_len_of_ary(_subnode_index_ary)"); - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_DRILL_POS); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_drill_ptr=%d, node_index=0x%lx", - _drill_ptr, node_index) - } - - return node_index; - } - //return: ins_pos, UNDEF_POS for invalid drill_pos - uint32_t get_ins_pos(const int drill_pos) const { - uint32_t ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (drill_pos >= 0 && drill_pos <= _drill_ptr) { - if ((ins_pos = _ins_pos_ary[drill_pos]) >= BT_FANOUT) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ins_pos >= BT_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_INS_POS); - } - } else { - log_level = DF_UL_LOG_TRACE; - DF_WRITE_LOG_US(log_level, "drill_pos < 0 || drill_pos > _drill_ptr"); - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_DRILL_POS); - ins_pos = UNDEF_POS; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_pos=%d, _drill_ptr=%d, ins_pos=%d", - drill_pos, _drill_ptr, ins_pos) - } - - return ins_pos; - }; - //return: ins_pos, UNDEF_POS for invalid drill_pos - uint32_t get_last_ins_pos(void) const { - uint32_t ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_drill_ptr >= 0 && _drill_ptr < (int)df_len_of_ary(_ins_pos_ary)) { - if ((ins_pos = _ins_pos_ary[_drill_ptr]) >= BT_FANOUT) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ins_pos >= BT_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_INS_POS); - } - } else { - log_level = DF_UL_LOG_TRACE; - DF_WRITE_LOG_US(log_level, "_drill_ptr < 0 || _drill_ptr >= df_len_of_ary(_ins_pos_ary)"); - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_DRILL_POS); - ins_pos = UNDEF_POS; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_drill_ptr=%d, ins_pos=%d", - _drill_ptr, ins_pos) - } - - return ins_pos; - }; - //return: 0 for success, otherwise error - int inc_last_ins_pos(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_drill_ptr >= 0 && _drill_ptr < (int)df_len_of_ary(_ins_pos_ary)) { - ++_ins_pos_ary[_drill_ptr]; - if (_ins_pos_ary[_drill_ptr] >= BT_FANOUT) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ins_pos_ary[_drill_ptr] >= BT_FANOUT"); - DF_WRITE_LOG_US(log_level, "_ins_pos_ary[_drill_ptr]=%d", _ins_pos_ary[_drill_ptr]); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_INS_POS); - } - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_drill_ptr < 0 || _drill_ptr >= df_len_of_ary(_ins_pos_ary)"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_POS); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_drill_ptr=%d", - _drill_ptr); - } - - return err; - } - //return: 0 for success, otherwise error - int dec_last_ins_pos(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_drill_ptr >= 0 && _drill_ptr < (int)df_len_of_ary(_ins_pos_ary)) { - if (_ins_pos_ary[_drill_ptr] <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ins_pos_ary[_drill_ptr] <= 0"); - DF_WRITE_LOG_US(log_level, "_ins_pos_ary[_drill_ptr]=%d", _ins_pos_ary[_drill_ptr]); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_INS_POS); - } else { - --_ins_pos_ary[_drill_ptr]; - } - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_drill_ptr < 0 || _drill_ptr >= df_len_of_ary(_ins_pos_ary)"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_POS); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_drill_ptr=%d", - _drill_ptr); - } - - return err; - }; - //void empty(void) - //{ - // init(); - //}; - //bool is_empty(void) const - //{ - // return (_drill_ptr < 0); - //}; - //bool is_only_one_step(void) const - //{ - // return (0 == _drill_ptr); - //}; -public: - void set_btree_mutation_counter(const uint64_t btree_mutation_counter) { - _btree_mutation_counter = btree_mutation_counter; - }; - uint64_t get_btree_mutation_counter(void) const { - return _btree_mutation_counter; - }; -public: - //要删除的key所在的B树节点在drill_info中的位置 - //被删除点位于中间节点时,原来的node_index - int set_del_mid_drill_info(const int del_mid_drill_ptr, const uint64_t del_mid_new_node_index) { - int err = 0; - - if ((_del_mid_drill_ptr = del_mid_drill_ptr) >= 0 && _del_mid_drill_ptr < _drill_ptr) { - _del_mid_old_node_index = _subnode_index_ary[_del_mid_drill_ptr]; - _subnode_index_ary[_del_mid_drill_ptr] = del_mid_new_node_index; - } else { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, "error del_mid_drill_ptr=%d, _drill_ptr=%d", del_mid_drill_ptr, _drill_ptr); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_DRILL_DEL_NODE_POS); - } - - return err; - }; - //要删除的key所在的B树节点在drill_info中的位置 - int get_del_mid_drill_ptr(void) const { - return _del_mid_drill_ptr; - }; - //被删除点位于中间节点时,原来的node_index - uint64_t get_del_mid_old_node_index(void) const { - return _del_mid_old_node_index; - }; -public: - //bool is_match_tree(const uint64_t root_index, const uint64_t mutation_counter) const - //{ - // return (get_drill_ptr() >= 0 - // && get_btree_mutation_counter() == mutation_counter - // && get_node_index(0) == root_index); - //}; - //???what doest it mean??. - bool not_match_tree(const dfs_sbt_root_t & sbt_root) const { - return (get_drill_ptr() < 0 - || get_btree_mutation_counter() != sbt_root.get_mutation_counter() - || get_node_index(0) != sbt_root.get_root_node_index()); - }; -}; - - -//对节点更新(插入/删除)后的结果 -class dfs_btree_node_mutate_t : public dfs_bt_const_t { -public: - enum cconst_public { - //节点操作类型 - MUTATE_NOTHING = 0 , //没有更新操作 - UPDATE_NODE , //插入或删除而导致产生了新节点 - SPLIT_NODE , //节点分裂了(产生了两个新节点) - REBALANCE_LEFT , //与左兄弟进行了平衡(产生了新的左节点和新的本节点) - REBALANCE_RIGHT , //与右兄弟进行了平衡(产生了新的本节点和新的右节点) - MERGE_LEFT , //因为删除而与左兄弟进行合并(左兄弟被删除) - MERGE_RIGHT , //因为删除而与右兄弟进行了合并(本节点被删除) - MERGE_BOTH , //因为删除而同时与左右兄弟进行了合并(本节点被删除) - }; -protected: - int _mutate_type; - int _unused; - uint64_t _new_key_index ; - uint64_t _new_1st_node_index ; - uint64_t _new_2nd_node_index ; -public: - dfs_btree_node_mutate_t() { - _mutate_type = 0; - _unused = 0; - _new_key_index = UNDEF_INDEX; - _new_1st_node_index = UNDEF_INDEX; - _new_2nd_node_index = UNDEF_INDEX; - }; - ~dfs_btree_node_mutate_t() { - }; - dfs_btree_node_mutate_t(const dfs_btree_node_mutate_t & src) { - *this = src; - }; - dfs_btree_node_mutate_t & operator=(const dfs_btree_node_mutate_t & src) { - if (&src != this) { - //zhangyan04 - //memcpy(this, &src, sizeof(*this)); - ZY::xmemcpy(this, &src, sizeof(*this)); - } - return *this; - }; -public: - int get_update_type(void) const { - return _mutate_type; - }; - void set_mutate_nothing(void) { - _mutate_type = MUTATE_NOTHING; - _new_key_index = UNDEF_INDEX; - _new_1st_node_index = UNDEF_INDEX; - _new_2nd_node_index = UNDEF_INDEX; - }; - void set_update_node_info(const uint64_t new_node_index) { - _mutate_type = UPDATE_NODE; - _new_key_index = UNDEF_INDEX; - _new_1st_node_index = new_node_index; - _new_2nd_node_index = UNDEF_INDEX; - }; - int get_update_node_info(uint64_t & node_index) const { - int err = 0; - - if (get_update_type() != UPDATE_NODE) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - node_index = UNDEF_INDEX; - } else { - node_index = _new_1st_node_index; - err = 0; - } - - return err; - }; - void set_split_node_info( - const uint64_t new_left_key_index, - const uint64_t new_left_node_index, - const uint64_t new_right_node_index) { - _mutate_type = SPLIT_NODE; - _new_key_index = new_left_key_index; - _new_1st_node_index = new_left_node_index; - _new_2nd_node_index = new_right_node_index; - }; - int get_split_node_info( - uint64_t & new_left_key_index, - uint64_t & new_left_node_index, - uint64_t & new_right_node_index) const { - int err = 0; - - if (get_update_type() != SPLIT_NODE) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_left_key_index = UNDEF_INDEX; - new_left_node_index = UNDEF_INDEX; - new_right_node_index = UNDEF_INDEX; - } else { - new_left_key_index = _new_key_index; - new_left_node_index = _new_1st_node_index; - new_right_node_index = _new_2nd_node_index; - err = 0; - } - return err; - }; - - void set_rebalance_left_info( - const uint64_t new_left_key_index, - const uint64_t new_left_node_index, - const uint64_t new_myself_node_index) { - _mutate_type = REBALANCE_LEFT; - _new_key_index = new_left_key_index; - _new_1st_node_index = new_left_node_index; - _new_2nd_node_index = new_myself_node_index; - }; - int get_rebalance_left_info( - uint64_t & new_left_key_index, - uint64_t & new_left_node_index, - uint64_t & new_myself_node_index) const { - int err = 0; - - if (get_update_type() != REBALANCE_LEFT) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_left_key_index = UNDEF_INDEX; - new_left_node_index = UNDEF_INDEX; - new_myself_node_index = UNDEF_INDEX; - } else { - new_left_key_index = _new_key_index; - new_left_node_index = _new_1st_node_index; - new_myself_node_index = _new_2nd_node_index; - err = 0; - } - - return err; - }; - void set_rebalance_right_info( - const uint64_t new_myself_key_index, - const uint64_t new_myself_node_index, - const uint64_t new_right_node_index) { - _mutate_type = REBALANCE_RIGHT; - _new_key_index = new_myself_key_index; - _new_1st_node_index = new_myself_node_index; - _new_2nd_node_index = new_right_node_index; - }; - int get_rebalance_right_info( - uint64_t & new_myself_key_index, - uint64_t & new_myself_node_index, - uint64_t & new_right_node_index) const { - int err = 0; - - if (get_update_type() != REBALANCE_RIGHT) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_myself_key_index = UNDEF_INDEX; - new_myself_node_index = UNDEF_INDEX; - new_right_node_index = UNDEF_INDEX; - } else { - new_myself_key_index = _new_key_index; - new_myself_node_index = _new_1st_node_index; - new_right_node_index = _new_2nd_node_index; - err = 0; - } - - return err; - }; - void set_merge_left_info(const uint64_t new_myself_node_index) { - _mutate_type = MERGE_LEFT; - _new_key_index = UNDEF_INDEX; - _new_1st_node_index = new_myself_node_index; - _new_2nd_node_index = UNDEF_INDEX; - }; - int get_merge_left_info(uint64_t & new_myself_node_index) const { - int err = 0; - - if (get_update_type() != MERGE_LEFT) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_myself_node_index = UNDEF_INDEX; - } else { - new_myself_node_index = _new_1st_node_index; - err = 0; - } - - return err; - }; - void set_merge_right_info(const uint64_t new_right_node_index) { - _mutate_type = MERGE_RIGHT; - _new_key_index = UNDEF_INDEX; - _new_1st_node_index = new_right_node_index; - _new_2nd_node_index = UNDEF_INDEX; - }; - int get_merge_right_info(uint64_t & new_right_node_index) const { - int err = 0; - - if (get_update_type() != MERGE_RIGHT) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_right_node_index = UNDEF_INDEX; - } else { - new_right_node_index = _new_1st_node_index; - err = 0; - } - - return err; - }; - void set_merge_both_info( - const uint64_t new_left_key_index, - const uint64_t new_left_node_index, - const uint64_t new_right_node_index) { - _mutate_type = MERGE_BOTH; - _new_key_index = new_left_key_index; - _new_1st_node_index = new_left_node_index ; - _new_2nd_node_index = new_right_node_index; - }; - int get_merge_both_info( - uint64_t & new_left_key_index, - uint64_t & new_left_node_index, - uint64_t & new_right_node_index) const { - int err = 0; - - if (get_update_type() != MERGE_BOTH) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_MUTATE_TYPE); - new_left_key_index = UNDEF_INDEX; - new_left_node_index = UNDEF_INDEX; - new_right_node_index = UNDEF_INDEX; - } else { - new_left_key_index = _new_key_index; - new_left_node_index = _new_1st_node_index ; - new_right_node_index = _new_2nd_node_index ; - err = 0; - } - - return err; - }; -}; - -class dfs_btree_fhead_base_t { -public: - uint32_t size; //sizeof of the head (not only the base part) - uint32_t ver; - int64_t total_data_len; //including the head - uint32_t major_tag; //“大树”的类型,如'fpbt', 'idbt' - uint32_t minor_tag; //“小树”的类型,如'fpbt'下有'fpbt'和'idbt' - uint64_t reserve10; -}; - -//btree自己保存的头信息,各种不同btree(ID,FP,NS,XZ)还会保存自己的头信息 -class dfs_btree_fhead_ext_t { -public: - uint64_t total_leaf_node_num; - uint64_t total_mid_node_num; - uint64_t total_key_num; - int32_t store_t_type; //STORE_T_INDEX, STORE_T_VALUE or STORE_T_VALUE_KEEP_T_INDEX - uint32_t reserve20; - uint64_t reserve21[24]; -}; - -//btree自己保存的头信息,各种不同btree(ID,FP,NS,XZ)还会保存自己的头信息 -class dfs_btree_fhead_t : public dfs_btree_fhead_base_t, public dfs_btree_fhead_ext_t { -public: - enum cconst_public { - STORE_T_INDEX = 0 , - STORE_T_VALUE , - STORE_T_VALUE_KEEP_T_INDEX , //STORE_T_AND_KEEP_T_INDEX shoud > STORE_T_ONLY - - CORE_BT_VER = 0x00000002, //Hihg-16-bit: main ver; - CORE_BT_TAG = (((int)'b')<<24) | (((int)'t')<<16) | (((int)'r')<<8) | (((int)'e')), //"btree" - ATTR_MIDNODE_FLAG = 1, //this is a middle node instead of leaf node - }; -}; - - - - -class dfs_btree_store_info_t : - virtual public dfs_bt_const_t, - public dfs_s_ary_t { -public: - enum cconst_public { - STORE_T_INDEX = dfs_btree_fhead_t::STORE_T_INDEX , - STORE_T_VALUE = dfs_btree_fhead_t::STORE_T_VALUE , - STORE_T_VALUE_KEEP_T_INDEX = dfs_btree_fhead_t::STORE_T_VALUE_KEEP_T_INDEX , - }; -private: - dfs_init_t _init_state; - const dfs_write_proc_t _write_proc; - const pvoid _file_info; - int64_t _file_offset; - char * _buf; - const uint64_t _buf_size; - uint64_t _data_pos; - uint64_t _total_leaf_node_num; - uint64_t _total_mid_node_num; - uint64_t _total_key_num; - uint32_t _major_tag; - int32_t _store_t_type; //STORE_T_INDEX, STORE_T_VALUE or STORE_T_VALUE_KEEP_T_INDEX - uint64_t _kept_key_num; - //uint64_t _max_kept_key_index; -public: - dfs_btree_store_info_t( - const dfs_write_proc_t write_proc, - const pvoid file_info, - const uint64_t buf_size) : - dfs_s_ary_t(UNDEF_INDEX), - _write_proc(write_proc), - _file_info(file_info), - _buf_size(buf_size) - - { - _buf = NULL; - init(); - }; - ~dfs_btree_store_info_t() { - flush_data(); - if (NULL != _buf) { - delete [] _buf; - _buf = NULL; - } - }; - int init(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - _file_offset = 0; - _data_pos = 0; - _total_leaf_node_num = 0; - _total_mid_node_num = 0; - _total_key_num = 0; - _store_t_type = STORE_T_VALUE; - _kept_key_num = 0; - //_max_kept_key_index = 0; - - if ((err = dfs_s_ary_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_s_ary_t::init() returns 0x%x", err); - } else if (NULL != _buf) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NOT_NULL_BUF_POINTER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL != _buf"); - } else if ((_buf = new char[_buf_size]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "_buf"); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_buf=0x%p, _buf_size=%ld", - _buf, _buf_size); - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; - void init_counters(void) { - _total_leaf_node_num = 0; - _total_mid_node_num = 0; - _total_key_num = 0; - }; -public: - void set_major_tag(const uint32_t major_tag) { - _major_tag = major_tag; - }; - uint32_t get_major_tag(void) const { - return _major_tag; - }; - //uint64_t get_mutation_counter(void) const - //{ - // return _mutation_counter; - //}; - //void set_mutation_counter(const uint64_t mutation_counter) - //{ - // _mutation_counter = mutation_counter; - //}; - uint64_t get_total_leaf_node_num(void) const { - return _total_leaf_node_num; - }; - uint64_t get_total_mid_node_num(void) const { - return _total_mid_node_num; - }; - uint64_t get_total_key_num(void) const { - return _total_key_num; - }; -public: - uint64_t inc_total_leaf_node_num(void) { - return ++_total_leaf_node_num; - }; - uint64_t inc_total_mid_node_num(void) { - return ++_total_mid_node_num; - }; - uint64_t add_total_key_num(const uint32_t key_num) { - _total_key_num += key_num; - return _total_key_num; - }; -public: - //void set_file_offset(const int64_t file_offset) - //{ - // _file_offset = file_offset; - //}; - int64_t get_cur_file_offset(void) const { - return (_file_offset+(int64_t)_data_pos); - }; - int32_t get_store_t_type(void) const { - return _store_t_type; - }; - void set_store_t_index(void) { - _store_t_type = STORE_T_INDEX; - }; - void set_store_t_value(void) { - _store_t_type = STORE_T_VALUE; - }; - void set_store_t_value_keep_t_index(void) { - _store_t_type = STORE_T_VALUE_KEEP_T_INDEX; - }; -public: - int flush_data(void) { - int err = 0; - - if (_data_pos > 0) { - if ((err = _write_proc(_file_info, _file_offset, _buf, _data_pos)) != 0) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_WRITE_FILE); - } - _file_offset += _data_pos; - _data_pos = 0; - } - - return err; - }; - int padding(void) { - //to purpose for padding: 1. makes decode_num() always has at least 9 bytes; 2. alignment - uint64_t padding_num = 0x20 -(get_cur_file_offset() & 0xf); - int err = require_space(padding_num); - - if (0 == err) { - memset(_buf+_data_pos, 0, padding_num); - _data_pos += padding_num; - //err = flush_data(); - } - - return err; - }; - int rewrite_data(const void * buf, const uint64_t data_len, const int64_t file_offset) { - //refill the head - int err = flush_data(); - - if (0 == err) { - if ((err = _write_proc(_file_info, file_offset, buf, data_len)) != 0) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_WRITE_FILE); - } - } - - return err; - }; - uint64_t get_avail_space(void) const { - return (_buf_size-_data_pos); - }; - int require_space(const uint64_t space_len) { - int err = 0; - if (get_avail_space() <= space_len) { - if ((err = flush_data()) == 0 && get_avail_space() <= space_len) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_BUF_POS); - } - } - return err; - }; - int encode_num(const uint64_t num) { - int err = require_space(9); - - if (0 == err) { - err = dfs_bt_const_t::encode_num(num,_buf,_buf_size,_data_pos); - } - - return err; - }; - //encode the length of data and also guarantee there enough buf space for the data - int encode_data_len(const uint64_t data_len) { - int err = require_space(9+data_len); - - if (0 == err) { - err = dfs_bt_const_t::encode_num(data_len,_buf,_buf_size,_data_pos); - } - - return err; - }; - int store_data(const uint64_t data) { - int err = require_space(sizeof(data)); - - if (0 == err) { - *((uint64_t *)(_buf+_data_pos)) = data; - _data_pos += sizeof(data); - } - - return err; - }; - int store_data(const uint32_t data) { - int err = require_space(sizeof(data)); - - if (0 == err) { - *((uint32_t *)(_buf+_data_pos)) = data; - _data_pos += sizeof(data); - } - - return err; - }; - int store_buf(const void * buf, const uint32_t data_len) { - int err = require_space(data_len); - - if (0 == err) { - //zhangyan04 - //memcpy(_buf+_data_pos, buf, data_len); - ZY::xmemcpy(_buf+_data_pos, buf, data_len); - _data_pos += data_len; - } - - return err; - }; -public: - char * get_buf(void) const { - return _buf; - }; - uint64_t get_buf_size(void) const { - return _buf_size; - }; - uint64_t & get_data_pos(void) { - return _data_pos; - }; -public: - int keep_obj_index(const uint64_t key_index) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX == key_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == key_index"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } else if ((err = dfs_s_ary_t::put_t(key_index, _kept_key_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_s_ary_t::put_t() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "key_index=0x%lx, _kept_key_num=%ld", - key_index, _kept_key_num); - } else { - ++_kept_key_num; - } - - return err; - }; - int get_kept_obj_seq(const uint64_t key_index, uint64_t & key_seq) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - key_seq = UNDEF_INDEX; - if (UNDEF_INDEX == key_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == key_index"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } else if ((err = dfs_s_ary_t::get_t(key_index, key_seq)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_s_ary_t::get_t() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "key_index=0x%lx, _kept_key_num=%ld, key_seq=%ld", - key_index, _kept_key_num, key_seq); - } - - return err; - } - //int clear_kept_key_index(void) - //{ - // return dfs_s_ary_t::clear(); - //}; - int clear_session_nums(void) { - _total_leaf_node_num = 0; - _total_mid_node_num = 0; - _total_key_num = 0; - _kept_key_num = 0; - //_max_kept_key_index = 0; - - return dfs_s_ary_t::clear(); - }; -}; - - - -class dfs_btree_load_info_t : - virtual public dfs_bt_const_t, - public dfs_s_ary_t { -public: - enum cconst_public { - STORE_T_INDEX = dfs_btree_fhead_t::STORE_T_INDEX , - STORE_T_VALUE = dfs_btree_fhead_t::STORE_T_VALUE , - STORE_T_VALUE_KEEP_T_INDEX = dfs_btree_fhead_t::STORE_T_VALUE_KEEP_T_INDEX , - }; -private: - dfs_init_t _init_state; - const dfs_read_proc_t _read_proc; - const pvoid _file_info; - int64_t _file_offset; - int64_t _max_file_offset; //根据total_data_len计算出来的最终数据位置 - char * _buf; - const uint64_t _buf_size; - uint64_t _data_len; - uint64_t _data_pos; - uint64_t _total_leaf_node_num; - uint64_t _total_mid_node_num; - uint64_t _total_key_num; - uint32_t _major_tag; - int _store_t_type; //STORE_T_INDEX, STORE_T_VALUE or STORE_T_VALUE_KEEP_T_INDEX - uint64_t _kept_key_num; - //uint64_t _max_kept_key_index; -public: - dfs_btree_load_info_t( - const dfs_read_proc_t read_proc, - const pvoid file_info, - const uint64_t buf_size) : - dfs_s_ary_t(UNDEF_INDEX), - _read_proc(read_proc), - _file_info(file_info), - _buf_size(buf_size) { - _buf = NULL; - init(); - }; - ~dfs_btree_load_info_t() { - if (NULL != _buf) { - delete [] _buf; - _buf = NULL; - } - }; - int init(void) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - _file_offset = 0; - _max_file_offset = 0; - _data_len = 0; - _data_pos = 0; - _total_leaf_node_num = 0; - _total_mid_node_num = 0; - _total_key_num = 0; - _store_t_type = STORE_T_VALUE; - _kept_key_num = 0; - //_max_kept_key_index = 0; - - if ((err = dfs_s_ary_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_s_ary_t::init() returns 0x%x", err); - } else if (NULL != _buf) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_NOT_NULL_BUF_POINTER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL != _buf"); - } else if ((_buf = new char[_buf_size]) == NULL) { - err = DF_BT_SET_NORMAL_ERR(this->ERRNO_BT_NOMEM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_NOMEM, "_buf"); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "_buf=0x%p, _buf_size=%ld", - _buf, _buf_size); - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; -public: - void set_major_tag(const uint32_t major_tag) { - _major_tag = major_tag; - }; - uint32_t get_major_tag(void) const { - return _major_tag; - }; - //uint64_t get_mutation_counter(void) const - //{ - // return _mutation_counter; - //}; - //void set_mutation_counter(const uint64_t mutation_counter) - //{ - // _mutation_counter = mutation_counter; - //}; - uint64_t get_total_leaf_node_num(void) const { - return _total_leaf_node_num; - }; - uint64_t get_total_mid_node_num(void) const { - return _total_mid_node_num; - }; - uint64_t get_total_key_num(void) const { - return _total_key_num; - }; -public: - uint64_t dec_total_leaf_node_num(void) { - return --_total_leaf_node_num; - }; - uint64_t dec_total_mid_node_num(void) { - return --_total_mid_node_num; - }; - uint64_t sub_total_key_num(const uint32_t key_num) { - _total_key_num -= key_num; - return _total_key_num; - }; -public: - void set_total_nums( - const uint64_t total_leaf_node_num, - const uint64_t total_mid_node_num, - const uint64_t total_key_num) { - _total_leaf_node_num = total_leaf_node_num ; - _total_mid_node_num = total_mid_node_num ; - _total_key_num = total_key_num ; - }; -public: - //void set_file_offset(const int64_t file_offset) - //{ - // _file_offset = file_offset; - //}; - void set_max_file_offset(const int64_t max_file_offset) { - _max_file_offset = max_file_offset; - }; - int64_t get_cur_file_offset(void) const { - return (_file_offset-(int64_t)get_avail_data_len()); - }; - int64_t get_max_file_offset(void) const { - return _max_file_offset; - }; - int file_seek(const int64_t file_offset) { - int err = 0; - - if (file_offset == _file_offset) { - _data_pos = 0; - _data_len = 0; - } else if (file_offset != get_cur_file_offset()) { - if (file_offset <= 0) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_FILE_POS); - } else { - _file_offset = file_offset; - if ((err = _read_proc(_file_info, _file_offset-1, _buf, 1)) != 0) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_READ_FILE); - } - _data_pos = 0; - _data_len = 0; - } - } - - return err; - }; - int32_t get_store_t_type(void) const { - return _store_t_type; - }; - void set_store_t_type(const int store_t_type) { - _store_t_type = store_t_type; - }; -public: - int read_data(void) { - uint64_t read_len = 0; - int err = 0; - - if (_file_offset < _max_file_offset) { - if (_data_pos > 0) { - memmove(_buf, _buf+_data_pos, (_data_len-_data_pos)); - _data_len -= _data_pos; - _data_pos = 0; - } - read_len = MIN((int64_t)(_buf_size-_data_len),(_max_file_offset-_file_offset)); - if ((err = _read_proc(_file_info, _file_offset, _buf+_data_len, read_len)) != 0) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_READ_FILE); - } - _file_offset += read_len; - _data_len += read_len; - } - - return err; - }; - uint64_t get_avail_data_len(void) const { - return (_data_len-_data_pos); - }; - int require_data_len(const uint64_t data_len) { - int err = 0; - if (get_avail_data_len() < data_len) { - if ((err = read_data()) == 0 && get_avail_data_len() < data_len) { - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_FILE_POS); - } - } - return err; - }; - int decode_num(uint64_t & num) { - int err = require_data_len(9); - - if (0 == err) { - err = dfs_bt_const_t::decode_num(num,_buf,_data_len,_data_pos); - } - - return err; - }; - - //decode the length of data and also guarantee the data in the buf - int decode_data_len(uint64_t & data_len) { - int err = require_data_len(9); - - if (0 == err) { - err = dfs_bt_const_t::decode_num(data_len,_buf,_data_len,_data_pos); - if (0 == err) { - err = require_data_len(data_len); - } - } - - return err; - }; - int load_data(uint64_t & data) { - int err = require_data_len(sizeof(data)); - - if (0 == err) { - data = *((uint64_t *)(_buf+_data_pos)); - _data_pos += sizeof(data); - } - - return err; - }; - int load_data(uint32_t & data) { - int err = require_data_len(sizeof(data)); - - if (0 == err) { - data = *((uint32_t *)(_buf+_data_pos)); - _data_pos += sizeof(data); - } - - return err; - }; - int load_buf(void * buf, const uint32_t data_len) { - int err = 0; - - if ((err = require_data_len(data_len)) == 0) { - //zhangyan04 - //memcpy(buf, _buf+_data_pos, data_len); - ZY::xmemcpy(buf, _buf+_data_pos, data_len); - _data_pos += data_len; - } - - return err; - }; - int load_data_len(uint32_t & data_len) { - int err = load_data(data_len); - - if (0 == err) { - err = require_data_len(data_len); - } - - return err; - }; - int skip_data_len(const uint32_t data_len) { - int err = require_data_len(data_len); - - if (0 == err) { - _data_pos += data_len; - } - - return err; - } -public: - char * get_buf(void) const { - return _buf; - }; - uint64_t get_data_len(void) const { - return _data_len; - }; - uint64_t & get_data_pos(void) { - return _data_pos; - }; -public: - int keep_obj_index(const uint64_t key_index) { - int err = dfs_s_ary_t::put_t(_kept_key_num, key_index); - //if (key_index > _max_kept_key_index) - //{ - // _max_kept_key_index = key_index; - //} - ++_kept_key_num; - return err; - }; - int get_kept_key_index(const uint64_t key_seq, uint64_t & key_index) { - int err = 0; - - key_index = UNDEF_INDEX; - //if (key_seq >= _kept_key_num) - //{ - // err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_SUBKEY_NUM); - //} - //else - //{ - err = dfs_s_ary_t::get_t(key_seq, key_index); - //} - - return err; - } - //int clear_kept_key_index(void) - //{ - // return dfs_s_ary_t::clear(); - //}; - int clear_session_nums(void) { - _total_leaf_node_num = 0; - _total_mid_node_num = 0; - _total_key_num = 0; - _kept_key_num = 0; - //_max_kept_key_index = 0; - - return dfs_s_ary_t::clear(); - }; -}; - -//enum bt_ckp_state_t -//{ -// BT_CKP_STATE_OFF = 0 , -// BT_CKP_STATE_ON = 1 , -// BT_CKP_STATE_STORING = 2 , -// BT_CKP_STATE_LOADING = 3 , -//}; - - -// -//dfs_btree_t是B树的基本部分,完成B树元素的插入和删除以及由此导致的树的平衡操作。 -class dfs_btree_t : - virtual public dfs_bt_const_t, -public dfs_bt2d_ary_t< - dfs_btree_leaf_node_t, - dfs_bt_const_t::BT_LEAF_ROW_SIZE>, -public dfs_bt2d_ary_t< - dfs_btree_mid_node_t, - dfs_bt_const_t::BT_MID_ROW_SIZE> { - friend class dfs_bt_root_t; -private: - enum cconst_private { - STATE_INIT_FAIL = -2 , - STATE_INIT_NOT_YES = -1 , - STATE_INIT_SUCCEED = 0 , - - LEAF_NODE_FLAG_BIT = 63 , - //COW_NUM_BITS = 10 , //lowest bits - }; - static const uint32_t BT_FANOUT = dfs_bt_const_t::BT_FANOUT; - static const uint32_t BT_LEAF_ROW_SIZE = dfs_bt_const_t::BT_LEAF_ROW_SIZE; - static const uint32_t BT_MID_ROW_SIZE = dfs_bt_const_t::BT_MID_ROW_SIZE; - static const uint32_t BT_HALF_FANOUT = (BT_FANOUT-1)/2; - static const uint64_t MAX_MID_INDEX = MAX_U_INT64/4-2; - static const uint64_t MAX_LEAF_INDEX = MAX_U_INT64/4-2; - static const uint64_t LEAF_NODE_FLAG = ((uint64_t)0x1)< node_base_t; - typedef dfs_btree_leaf_node_t leaf_node_t; - typedef dfs_btree_mid_node_t mid_node_t; - typedef dfs_bt2d_ary_t, BT_LEAF_ROW_SIZE> leaf_ary_t; - typedef dfs_bt2d_ary_t, BT_MID_ROW_SIZE> mid_ary_t; -protected: - typedef void * pvoid; -private: - static uint64_t _add_leaf_flag_bit(const uint64_t node_index) { - return (node_index|LEAF_NODE_FLAG); - }; - static uint64_t _add_mid_flag_bit(const uint64_t node_index) { - return node_index; - }; - static uint64_t _remove_node_flag_bit(const uint64_t node_index) { - return (node_index&~LEAF_NODE_FLAG); - }; -protected: - static bool _is_leaf_node(const uint64_t node_index) { - return ((node_index&LEAF_NODE_FLAG) != 0); - }; - static bool _is_mid_node(const uint64_t node_index) { - return ((node_index&LEAF_NODE_FLAG) == 0); - }; - -protected: - enum cconst_protected { - COW_LOG_LEVEL = DF_UL_LOG_NOTICE, - CKP_LOG_LEVEL = COW_LOG_LEVEL, - VERIFY_LOG_LEVEL = COW_LOG_LEVEL, - }; -private: - dfs_init_t _init_state; - //dfs_sbt_root_t _wr_sbt_root; //修改的root - volatile uint64_t _mutation_counter; - //需要copy-on-write的最大mutation_counter - volatile uint64_t _max_cow_mutation_counter; - volatile uint32_t _is_reserved_leaf_node_acquired; - volatile uint32_t _is_reserved_mid_node_acquired; - volatile uint32_t _is_cancel_checkpointing; //取消正在进行中的store/load checkpointing - //当前实例序号... - uint32_t _bt_instance_pos; //本树在一系列实例中的序号,一般为0,fp_btree中为0~3,ns_btree为0~1 -public: - dfs_btree_t() { - //_wr_sbt_root.init(); - _mutation_counter = 0; - //需要copy-on-write的最大mutation_counter??? - _max_cow_mutation_counter = 0; - _is_reserved_leaf_node_acquired = 0; - _is_reserved_mid_node_acquired = 0; - _is_cancel_checkpointing = 0; - _bt_instance_pos = UNDEF_POS; - - //init(); - }; - virtual ~dfs_btree_t() { - _init_state.set_destructed(); - }; - //输出:初始化根节点 - int init(const uint32_t bt_instance_pos, dfs_bt_root_t & new_wr_bt_root); -protected: - inline uint32_t _bt_get_instance_pos(void) const; - //int _bt_set_bt_instance_pos(const uint32_t bt_instance_pos); - inline const dfs_sbt_root_t & _bt_get_sbt_root(const dfs_bt_root_t & bt_root) const; - inline int _bt_set_sbt_root( - dfs_bt_root_t & bt_root, - const dfs_sbt_root_t & sbt_root) const; -private: - //Disable operator=() and copy constructor - const dfs_btree_t & operator=(const dfs_btree_t & src); - dfs_btree_t(const dfs_btree_t & src); - //const dfs_btree_t & operator=(const dfs_btree_t & src) - //{ - // return *this; - //}; - //dfs_btree_t(const dfs_btree_t & src) : - // leaf_ary_t(), mid_ary_t() - //{ - //}; -protected: - ////获得wr_root - //const dfs_sbt_root_t & _bt_get_wr_root(void); - ////回滚并加减对应根节点引用计数(用于load checkpoint等) - //int _bt_rollback_wr_root(const dfs_sbt_root_t & sbt_root); -protected: - //inline uint64_t _bt_alloc_id(void); - //inline bool _bt_is_invalid_id(const uint64_t id) const; -protected: - //inline uint64_t _bt_inc_mutation_counter(void); - inline uint64_t _bt_update_mutation_counter(const bool is_batch_mode); - inline uint64_t _bt_get_mutation_counter(void) const; - inline uint64_t _bt_get_max_cow_mutation_counter(void) const; - //把_max_cow_mutation_counter设置为当前的mutation_counter - inline void _bt_update_max_cow_mutation_counter(void) const; - inline bool _bt_is_cancel_checkpointing(void) const; - //return previous state - inline bool _bt_set_cancel_checkpointing(const bool is_cancel); - inline int _bt_inc_root_ref_counter(const dfs_bt_root_t & bt_root) const; - inline int _bt_dec_root_ref_counter(const dfs_bt_root_t & bt_root) const; -protected: - //store all contents of a tree to file - int _bt_store_tree( - const dfs_bt_root_t & bt_root, - dfs_btree_store_info_t & store_info, - dfs_btree_fhead_t & btree_fhead) const; - // - int _bt_load_tree( - dfs_bt_root_t & new_wr_bt_root, - dfs_btree_load_info_t & load_info, - dfs_btree_fhead_t & btree_fhead); - -private: - //store all contents of a subtree to file - int _store_subtree( - const uint64_t subtree_root, - dfs_btree_store_info_t & store_info) const; - int _store_subkeys( - const uint64_t node_index, - dfs_btree_store_info_t & store_info) const; - int _store_fhead( - dfs_btree_store_info_t & store_info, - int64_t & file_head_offset, - dfs_btree_fhead_t & btree_fhead) const; - int _update_stored_fhead( - dfs_btree_store_info_t & store_info, - const int64_t file_head_offset, - dfs_btree_fhead_t & btree_fhead) const; - int _load_fhead( - dfs_btree_load_info_t & load_info, - int64_t & file_head_offset, - dfs_btree_fhead_t & btree_fhead) const; - int _load_subtree( - uint64_t & subtree_root, - dfs_btree_load_info_t & load_info); - int _load_subkeys( - uint64_t * subkey_index_ary, - const uint32_t ary_len, - uint32_t & subkey_num, - bool & is_mid_node, - dfs_btree_load_info_t & load_info); -private: - //return: 0 for success(be a valid index), other value for error - inline int _get_leaf_node_for_mutate(const uint64_t final_node_index, leaf_node_t ** ppleaf) const; - //return: 0 for success(be a valid index), other value for error - inline int _get_mid_node_for_mutate(const uint64_t final_node_index, mid_node_t ** ppmid) const; - //return: 0 for success(be a valid index), other value for error - inline int _get_leaf_node(const uint64_t final_node_index, const leaf_node_t ** ppleaf) const; - //return: 0 for success(be a valid index), other value for error - inline int _get_mid_node(const uint64_t final_node_index, const mid_node_t ** ppmid) const; - //return: 0 for success(be a valid index), other value for error - inline int _get_node(const uint64_t final_node_index, const node_base_t ** ppbase) const; - //return: 0 for success(be a valid index), other value for error - inline int _valid_leaf_node_index_verify(const uint64_t final_node_index) const; - //return: 0 for success(be a valid index), other value for error - inline int _valid_mid_node_index_verify(const uint64_t final_node_index) const; - //功能:获得node(leaf or mid)在pos处的key_index - //Return: 0 for success, other value for error - inline int _get_key_of_node(const uint64_t node_index, const uint32_t pos, uint64_t & key_index) const; - //功能:获得mid node在pos处的subnode - //Return: 0 for success, other value for error - inline int _get_subnode_of_mid_node(const uint64_t node_index, const uint32_t pos, uint64_t & subnode_index) const; -private: - //relase node由dfs_2d_ary自动进行(根据ref_counter) - int _acquire_leaf_node(uint64_t & final_node_index, leaf_node_t ** ppleaf_node); - int _acquire_reserved_leaf_node(uint64_t & final_node_index, leaf_node_t ** ppleaf_node); - //return: 0 for success, other values for failure - int _release_reserved_leaf_node(const uint64_t final_node_index); - //relase node由dfs_2d_ary自动进行(根据ref_counter) - int _acquire_mid_node(uint64_t & final_node_index, mid_node_t ** ppmid_node); - int _acquire_reserved_mid_node(uint64_t & final_node_index, mid_node_t ** ppmid_node); - //return: 0 for success, other values for failure - int _release_reserved_mid_node(const uint64_t final_node_index); - int _get_leaf_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) const; - int _get_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) const; - int _get_node_ref_counter(const uint64_t node_index, uint64_t & ref_counter) const { - return ((_is_leaf_node(node_index)) ? - _get_leaf_node_ref_counter(node_index, ref_counter) : - _get_mid_node_ref_counter(node_index, ref_counter)); - }; - //return: 0 for success, other value for error - int _inc_leaf_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter); - int _inc_leaf_node_ref_counter_if_not_zero(const uint64_t final_node_index, uint64_t & ref_counter); - int _inc_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter); - int _inc_mid_node_ref_counter_if_not_zero(const uint64_t final_node_index, uint64_t & ref_counter); - int _inc_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - return ((_is_mid_node(final_node_index)) ? - _inc_mid_node_ref_counter(final_node_index, ref_counter) - : _inc_leaf_node_ref_counter(final_node_index, ref_counter)); - }; - int _inc_node_ref_counter_if_not_zero(const uint64_t final_node_index, uint64_t & ref_counter) { - return ((_is_mid_node(final_node_index)) ? - _inc_mid_node_ref_counter_if_not_zero(final_node_index, ref_counter) - : _inc_leaf_node_ref_counter_if_not_zero(final_node_index, ref_counter)); - }; - int _dec_leaf_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter); - int _dec_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter); - int _dec_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - return ((_is_mid_node(final_node_index)) ? - _dec_mid_node_ref_counter(final_node_index, ref_counter) : - _dec_leaf_node_ref_counter(final_node_index, ref_counter)); - }; - //功能:计算新增一个节点引起的(key_index和B树节点)引用计数 - //Return: 0 for success, other value for error - int _inc_pointed_ref_counter(const uint64_t final_node_index); - //功能:计算删除一个节点引起的(key_index和B树节点)引用计数 - //Return: 0 for success, other value for error - int _dec_pointed_ref_counter(const uint64_t final_node_index); -public: - int action_before_leaf_node_gc(const uint64_t internal_node_index); - int action_before_mid_node_gc(const uint64_t internal_node_index); -private: - ////功能:增加或删除一个值导致上溢或下溢时,确定是与左或右兄弟平衡,还是独自分裂成为两个节点 - //// left_brother_node_index不等于UNDEF_INDEX则与之平衡,right_brother_node_index不等于UNDEF_INDEX则与之平衡, - //// 否则独自分裂成两节点 - //int _choose_rebalance_brother(const uint32_t new_key_number, - // uint64_t & left_brother_node_index, uint64_t & right_brother_node_index, - // const dfs_btree_drill_t & drill_info, const int drill_ptr); - //功能:增加或删除一个值导致上溢或下溢时,确定是与左或右兄弟平衡,还是独自分裂成为两个节点 - // left_brother_key_num,right_brother_key_num:左右兄弟的key的个数,为0表示不存在 - //返回:0 for success, other values for failure - int _get_left_right_brothers_info( - uint32_t & left_brother_key_num, - uint32_t & right_brother_key_num, - const dfs_btree_drill_t & drill_info, - const int drill_ptr); -private: - //功能:根据mutate_result对B树操作且返回新的根节点,但不替换当前树的根节点 - //输入:mutate_result及root_info - //返回:0 for success, other value for failure - int _op_tree( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); -private: - //功能:当一个节点因插入或删除项后,与其左边兄弟节点平衡,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _leaf_rebalance_left( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因插入或删除项后,与其右边兄弟节点平衡,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _leaf_rebalance_right( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因插入项后,进行分裂,结果记录在mutate_result - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _leaf_split( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其左边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _leaf_merge_left( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其右边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _leaf_merge_right( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其左右边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _leaf_merge_both( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); -private: - //功能:因子节点插入或删除导致了新节点(没有分裂或左右平衡)而对本节点更新 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_update( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:子节点因插入或删除项而与左兄弟平衡后,更新本节点。 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_rebalance_left( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:子节点因插入或删除项而与右左兄弟平衡后,更新本节点。 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_rebalance_right( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:因子节点插入导致分裂而对本节点更新 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_split( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - - //功能:因子节点与左兄弟合并而对本节点更新 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_merge_left( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:因子节点与右兄弟合并而对本节点更新 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_merge_right( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:因子节点与左右兄弟合并而对本节点更新 - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _op_mid_node_of_sub_merge_both( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); -private: - //功能:更新一个叶节点的一个subkey,结果写入mutate_result - //返回:0 for success, other value for failure - int _update_leaf_node_subkey( - const uint64_t node_index, - const uint32_t ins_pos, - const uint64_t new_key_index, - dfs_btree_node_mutate_t & mutate_result); - //功能:更新一个中间节点的一个subkey,结果写入mutate_result - //返回:0 for success, other value for failure - int _update_mid_node_subkey( - const uint64_t node_index, - const uint32_t ins_pos, - const uint64_t new_key_index, - dfs_btree_node_mutate_t & mutate_result); -private: - //功能:本节点(因插入或删除子项后),与其左边兄弟节点平衡,结果记录在mutate_result - // updated_myself_node:插入或删除子项后的节点 - //返回:0 for success, other values for failure - int _mid_rebalance_left( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:本节点(因插入或删除子项后),与其右边兄弟节点平衡,结果记录在mutate_result - // updated_myself_node:插入或删除子项后的节点 - //返回:0 for success, other values for failure - int _mid_rebalance_right( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:本节点因插入子项后,进行分裂,结果记录在mutate_result - // updated_myself_node:插入或删除子项后的节点 - //返回:0 for success, other values for failure - int _mid_split( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其左边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _mid_merge_left( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其右边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //输入:updated_myself_node:插入或删除后的本节点 - //返回:0 for success, other values for failure - int _mid_merge_right( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); - //功能:当一个节点因删除项下溢后,与其左右边兄弟节点合并,结果记录在mutate_result - //输入输入:mutate_result - //返回:0 for success, other values for failure - int _mid_merge_both( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result); -private: - //功能:在B树叶节点中插入或删除一个项(仅操作叶节点),把需要对其父节点的操作记录在mutate_result - // ins_key_index为插入项的key_index或者UNDEF_INDEX(删除项时) - // 如果drill_info.del_drill_ptr不等于-1,则表明是删除操作,当del_drill_ptr < drill_ptr时, - // 表示删除发生在中间节点上,但需要把对应子树的最大key_index提升到中间节点的对应位置。 - //返回:0 for success, other value for failure - int _ins_del_leaf_node( - const uint64_t ins_key_index, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result); -protected: - //功能:在B树中插入一个项且返回新的根节点,但不替换当前树的根节点 - //输入:root_info - //返回:0 for success, other value for failure - int _insert_to_btree( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const uint64_t ins_obj_index, - const dfs_btree_drill_t & drill_info); - - //功能:在B树中更新一个项,drill_ptr >= 0并可能指向叶节点或中间节点。 - //输入:root_info - //说明:调用者需要保证更新前后的项有相同的key。 - //返回:0 for success, other value for failure - int _update_of_btree( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const uint64_t new_obj_index, - const dfs_btree_drill_t & drill_info); - //功能:在B树中删除一个项,drill_ptr >= 0并可能指向叶节点或中间节点。 - //输入:root_info - //返回:0 for success, other value for failure - int _del_from_btree( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const dfs_btree_drill_t & drill_info); - //功能:生成一个内容为空的根节点(以便用来通过_update_root()清空树) - // return: 0 for success, other values for error - int _acquire_empty_root( - dfs_bt_root_t & new_wr_bt_root); -protected: - // 功能:获得B树最小元素并填充drill_info - // 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使树空)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_smallest( - const dfs_bt_root_t & bt_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - // - // 功能:获得B树最大元素并填充drill_info - // 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使树空)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_largest( - const dfs_bt_root_t & bt_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const ; - // - // 功能:获得一棵子树的最小元素,并追加drill_info中(与search一样) - // 输出:若存在(子树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使子树空且为根节点)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_subtree_smallest( - const uint64_t subtree_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - // - // 功能:获得一棵子树的最大元素,并追加drill_info中(与search一样) - // 输出:若存在(子树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使子树空且为根节点)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_subtree_largest( - const uint64_t subtree_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - // - // 功能:根据drill_info获得比当前项小的项,并更新drill_info指向之 - // 若存在则pct指向之且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使没有更小元素)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_smaller(dfs_btree_drill_t & drill_info, uint64_t & obj_indext) const; - // - // 功能:根据drill_info获得比当前项大的项,并更新drill_info指向之 - // 若存在则pct指向之且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX - // 返回: 成功(即使没有更大元素)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) - int _get_larger(dfs_btree_drill_t & drill_info, uint64_t & obj_index) const; - // - // 功能:获得刚好比输入项srct小的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较小元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 - // 返回:0 for no error, other values for error - int _get_smaller_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _get_smaller_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - // 功能:获得刚好比输入的srct大的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较大元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 - // 返回:0 for no error, other values for error - int _get_larger_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _get_larger_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; -protected: - // 功能:搜索整个树,结果写入到drill_info中。drill_info中还包含当前的mutation信息 - // 若存在,则drill_info以及pct都指向它,key_index为其key_index, - // 否则drill_info指向它插入后的位置,key_index和pct分别为UNDEF_INDEX和NULL。 - // return: 0 for success, other values for error - // this object may or may not in the btree - int _search_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t i_obj_index, - dfs_btree_drill_t & drill_info, - uint64_t & o_obj_index) const; - int _search_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _search_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; -protected: - // 功能:搜索某个子树,结果追加到drill_info中 - // 如果该元素存在,则drill_info中信息指向它,否则指向它插入后的位置。 - // 返回:0 for success, other values for error - int _search_subtree_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const uint64_t src_index, //this object may or may not in the btree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _search_subtree_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _search_subtree_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - // 功能:搜索B树的一个节点,结果加入到drill_info中 - // 返回:0 for success, other values for error - int _search_node_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, - const uint64_t src_index, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _search_node_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, //this object may or may not in the btree - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; - int _search_node_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const; -protected: - //return: 0 for success, other values for error - int _get_drill_last_obj( - const dfs_btree_drill_t & drill_info, - uint64_t & last_obj_index) const; -protected: - //// Return: 0 for success, other values for error - //virtual int vir_get_total_obj_ref_counter_in_ary( - // const dfs_bt_root_t & bt_root, - // uint64_t & total_ref_counter) const = 0; - // return: 0 for success, other values for error - virtual int vir_get_total_in_use_obj_num_in_ary(uint64_t & total_in_use_obj_num) const = 0; - // Return: 0 for success, other values for error - virtual int vir_obj_store_size( - const uint64_t obj_index, - uint64_t & store_size, - dfs_btree_store_info_t & store_info) const = 0; - // return: 0 for success, other values for error - virtual int vir_store_obj( - const uint64_t obj_index, - dfs_btree_store_info_t & store_info) const = 0; - // return: 0 for success, other values for error - virtual int vir_load_obj( - uint64_t & obj_index, - dfs_btree_load_info_t & load_info) = 0; - // return: 0 for success, other values for error - //virtual int vir_get_obj_ref_counter(const uint64_t obj_index, uint64_t & ref_counter) const = 0; - virtual int vir_inc_obj_ref_counter(const uint64_t obj_index) = 0; - virtual int vir_dec_obj_ref_counter(const uint64_t obj_index) = 0; - virtual int vir_inc_obj_ary_ref_counter(const uint64_t * obj_index_ary, const int32_t obj_num) = 0; - virtual int vir_dec_obj_ary_ref_counter(const uint64_t * obj_index_ary, const int32_t obj_num) = 0; - // - // return: 0 for success, other values for error - // cmp: -1, 0, 1 for less than, equal, great than - //virtual int vir_compare_index_index( - // const dfs_bt_root_t & bt_root, - // const uint64_t obj1_index, - // const uint64_t obj2_index, - // int & cmp) const = 0; - virtual int vir_compare_index_obj( - const dfs_bt_root_t & bt_root, - const uint64_t obj1_index, - const void * pobj2, - int & cmp) const = 0; - virtual int vir_compare_index_key( - const dfs_bt_root_t & bt_root, - const uint64_t obj1_index, - const void * pkey2, - int & cmp) const = 0; - virtual int vir_search_ary_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const uint64_t obj2_index, - int & ins_pos, - uint64_t & obj_index) const = 0; - virtual int vir_search_ary_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pobj2, - int & ins_pos, - uint64_t & obj_index) const = 0; - virtual int vir_search_ary_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pkey2, - int & ins_pos, - uint64_t & obj_index) const = 0; - virtual int vir_verify_index_ary( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - bool & is_inc_order) const = 0; -protected: - //增加/减少根节点引用计数 - virtual int vir_inc_root_ref_counter(const dfs_bt_root_t & bt_root) const; - virtual int vir_dec_root_ref_counter(const dfs_bt_root_t & bt_root) const; -private: - //uint64_t _get_max_verified_mutaiont_counter(void) const; - //int _set_max_verified_mutaiont_counter(const uint64_t mutaiont_counter) const; - // 功能:验证某个子树的顺序和每个节点分支个数 - // 输入:subtree_root:子树根节点 - // left_brother_key_index:子树的左兄弟,如果不等于UNDEF_INDEX,则<=子树的所有项 - // right_brother_key_index:子树的右兄弟,如果不等于UNDEF_INDEX,则>=子树的所有项 - // 返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 - int _verify_subtree( - const dfs_bt_root_t & bt_root, - const uint64_t father_mutation_counter, - const uint64_t subtree_root, - const uint64_t left_brother_obj_index, - const uint64_t right_brother_obj_index) const; -public: - // 功能:验证整个树的顺序和每个节点分支个数 - // 返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 - int bt_verify_tree(const dfs_bt_root_t & bt_root) const; -private: - // return: 0 for success, other values for error - int _get_subtree_total_num( - const uint64_t subtree_root, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const; -public: - // return: 0 for success, other values for error - int bt_get_total_num( - const dfs_bt_root_t & bt_root, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const; - // return: 0 for success, other values for error - int bt_get_in_use_node_num_in_2d_ary( - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const; -protected: - // return: 0 for success, other values for error - // Should be called in locked state and without checkpointing or other COW(load or store) - int _bt_sanitary_check(const dfs_bt_root_t & bt_root) const; -protected: - void _bt_clear_statistic_info(void) { - leaf_ary_t::clear_statistic_info(); - mid_ary_t::clear_statistic_info(); - return; - }; - void _bt_log_statistic_info( - const int log_level, - const char * filename, - const int lineno, - const char * funcname, - const char * btreename) const { - leaf_ary_t::log_statistic_info(log_level, filename, lineno, funcname, btreename, "leaf"); - mid_ary_t::log_statistic_info(log_level, filename, lineno, funcname, btreename, "mid"); - return; - }; - void _bt_log_debug_info( - const int log_level, - const char * filename, - const int lineno, - const char * funcname, - const char * btreename) const { - DF_WRITE_LOG_US(log_level, "%s,%d,%s", filename, lineno, funcname); - DF_WRITE_LOG_US(log_level, "%s", btreename); - DF_WRITE_LOG_US(log_level, "mutation_counter=%ld", _bt_get_mutation_counter()); - DF_WRITE_LOG_US(log_level, "max_cow_mutaiont_counter=%ld", _bt_get_max_cow_mutation_counter()); - }; - uint64_t _bt_get_mem_size(void) const { - return (leaf_ary_t::get_mem_size()+mid_ary_t::get_mem_size()); - }; -}; - -inline uint32_t dfs_btree_t::_bt_get_instance_pos(void) const { - uint32_t bt_instance_pos = _bt_instance_pos; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (bt_instance_pos >= MAX_BT_INSTANCE_NUM) { - bt_instance_pos = DEF_BT_INSTANCE_POS; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_instance_pos >= MAX_BT_INSTANCE_NUM"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_POS); - } - - return bt_instance_pos; -}; - -//inline int dfs_btree_t::_bt_set_bt_instance_pos(const uint32_t bt_instance_pos) -//{ -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// -// if (UNDEF_POS != _bt_instance_pos) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "UNDEF_POS != _bt_instance_pos"); -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_POS); -// } -// else if (bt_instance_pos >= MAX_BT_INSTANCE_NUM) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "bt_instance_pos >= MAX_BT_INSTANCE_NUM"); -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_POS); -// } -// else -// { -// _bt_instance_pos = bt_instance_pos; -// } -// -// return err; -//}; - -inline const dfs_sbt_root_t & dfs_btree_t::_bt_get_sbt_root(const dfs_bt_root_t & bt_root) const { - return bt_root.get_root(_bt_get_instance_pos()); -}; - -inline int dfs_btree_t::_bt_set_sbt_root( - dfs_bt_root_t & bt_root, - const dfs_sbt_root_t & sbt_root) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = bt_root.set_root(sbt_root, _bt_get_instance_pos())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_root.set_root() returns 0x%x", err); - } - - return err; -}; - - - -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_get_leaf_node_for_mutate(const uint64_t final_node_index, leaf_node_t ** ppleaf) const { - leaf_node_t * pleaf = NULL; - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL != ppleaf) { - *ppleaf = NULL; - } - - if ((err = leaf_ary_t::get_exist_t_unit(inter_node_index, pleaf)) != 0 || NULL == pleaf) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::get_exist_t_unit() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "inter_node_index=0x%lx, final_node_index=0x%lx, pleaf=0x%p", - inter_node_index, final_node_index, pleaf); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - if (NULL != ppleaf) { - *ppleaf = pleaf; - } - } - - return err; -}; - -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_get_mid_node_for_mutate(const uint64_t final_node_index, mid_node_t ** ppmid) const { - mid_node_t * pmid = NULL; - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL != ppmid) { - *ppmid = NULL; - } - - if ((err = mid_ary_t::get_exist_t_unit(inter_node_index, pmid)) != 0 || NULL == pmid) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::get_exist_t_unit() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "inter_node_index=0x%lx, final_node_index=0x%lx, pmid=0x%p", - inter_node_index, final_node_index, pmid); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else { - if (NULL != ppmid) { - *ppmid = pmid; - } - } - - return err; -}; - - -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_get_leaf_node(const uint64_t final_node_index, const leaf_node_t ** ppleaf) const { - leaf_node_t * pleaf = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_leaf_node_for_mutate(final_node_index, &pleaf)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node_for_mutate() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "final_node_index=0x%lx", final_node_index); - if (NULL != ppleaf) { - *ppleaf = NULL; - } - } else { - if (NULL != ppleaf) { - *ppleaf = pleaf; - } - } - - return err; -}; -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_get_mid_node(const uint64_t final_node_index, const mid_node_t ** ppmid) const { - mid_node_t * pmid = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_mid_node_for_mutate(final_node_index, &pmid)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node_for_mutate() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "final_node_index=0x%lx", final_node_index); - if (NULL != ppmid) { - *ppmid = NULL; - } - } else { - if (NULL != ppmid) { - *ppmid = pmid; - } - } - - return err; -}; -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_get_node(const uint64_t final_node_index, const node_base_t ** ppbase) const { - const leaf_node_t * pleaf = NULL; - const mid_node_t * pmid = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL != ppbase) { - *ppbase = NULL; - } - - if (_is_mid_node(final_node_index)) { - if ((err = _get_mid_node(final_node_index, &pmid)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "final_node_index=0x%lx", final_node_index); - } else if (NULL != ppbase) { - *ppbase = (node_base_t *)pmid; - } - } else { - if ((err = _get_leaf_node(final_node_index, &pleaf)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "final_node_index=0x%lx", final_node_index); - } else if (NULL != ppbase) { - *ppbase = (node_base_t *)pleaf; - } - } - - return err; -}; - -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_valid_leaf_node_index_verify(const uint64_t final_node_index) const { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (!_is_leaf_node(final_node_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "Invalid leaf node index"); - } else if ((err = leaf_ary_t::valid_t_index_verify(inter_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::valid_t_index_verify() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx", - final_node_index, inter_node_index); - } - - return err; -}; -//return: 0 for success(be a valid index), other value for error -inline int dfs_btree_t::_valid_mid_node_index_verify(const uint64_t final_node_index) const { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (!_is_mid_node(final_node_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "Invalid leaf node index"); - } else if ((err = mid_ary_t::valid_t_index_verify(inter_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::valid_t_index_verify() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx", - final_node_index, inter_node_index); - } - - return err; -}; - -//功能:获得node(leaf or mid)在pos处的key_index -//Return: 0 for success, other value for error -inline int dfs_btree_t::_get_key_of_node(const uint64_t node_index, const uint32_t pos, uint64_t & key_index) const { - const node_base_t * pnode = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - key_index = UNDEF_INDEX; - if ((err = _get_node(node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (pos >= pnode->get_subkey_num()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos >= pnode->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } else { - key_index = pnode->get_subkey_index(pos); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, pos=%d", - node_index, pos); - } - - return err; -}; -//功能:获得mid node在pos处的subnode -//Return: 0 for success, other value for error -inline int dfs_btree_t::_get_subnode_of_mid_node(const uint64_t node_index, const uint32_t pos, uint64_t & subnode_index) const { - const mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - subnode_index = UNDEF_INDEX; - if ((err = _get_mid_node(node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if (pos > pmid_node->get_subkey_num()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pos > pmid_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_POS); - } else { - subnode_index = pmid_node->get_subnode_index(pos); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, pos=%d", - node_index, pos); - } - - return err; -}; - - - -//inline uint64_t dfs_btree_t::_bt_inc_mutation_counter(void) -//{ -// return df_atomic_inc(&_mutation_counter); -//}; - -inline uint64_t dfs_btree_t::_bt_update_mutation_counter(const bool is_batch_mode) { - df_atomic_inc(&_mutation_counter); - if (!is_batch_mode) { - //TODO..??? - df_atomic_exchange(&_max_cow_mutation_counter, _mutation_counter); - } - - return _mutation_counter; -} - -inline uint64_t dfs_btree_t::_bt_get_mutation_counter(void) const { - return _mutation_counter; -}; - -inline uint64_t dfs_btree_t::_bt_get_max_cow_mutation_counter(void) const { - return _max_cow_mutation_counter; -}; - -inline void dfs_btree_t::_bt_update_max_cow_mutation_counter(void) const { - df_atomic_exchange(&(((dfs_btree_t *)this)->_max_cow_mutation_counter), _mutation_counter); - return; -}; - -inline bool dfs_btree_t::_bt_is_cancel_checkpointing(void) const { - return (_is_cancel_checkpointing != 0); -}; - -//return previous state -inline bool dfs_btree_t::_bt_set_cancel_checkpointing(const bool is_cancel) { - uint32_t pre_state = df_atomic_exchange(&_is_cancel_checkpointing, (is_cancel) ? 1 : 0); - - return (pre_state != 0); -}; - - -//not necessary in locked state -//_root_node_index might be UNDEF_INDEX -inline int dfs_btree_t::_bt_inc_root_ref_counter(const dfs_bt_root_t & bt_root) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - const uint64_t root_index = sbt_root.get_root_node_index(); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX != root_index) { - if ((err = ((dfs_btree_t *)this)->_inc_node_ref_counter(root_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_node_ref_counter() returns 0x%x", err); - } - } - - return err; -}; -inline int dfs_btree_t::_bt_dec_root_ref_counter(const dfs_bt_root_t & bt_root) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - const uint64_t root_index = sbt_root.get_root_node_index(); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (UNDEF_INDEX != root_index) { - if ((err = ((dfs_btree_t *)this)->_dec_node_ref_counter(root_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_node_ref_counter() returns 0x%x", err); - } - } - - return err; -}; - - -////for mutation operation -//inline int dfs_btree_t::_bt_copy_root(dfs_cell_root_t & bt_root) const -//{ -// _bt_set_own_root_info(bt_root, _root_info); -// return 0; -//}; -//inline int dfs_btree_t::_bt_update_root( -// dfs_cell_root_t & cur_root_info_ary, -// const dfs_cell_root_t & new_root_info_ary) -//{ -// const dfs_root_info_t & new_root_info = _bt_get_own_root_info(new_root_info_ary); -// const uint64_t new_root_index = new_root_info.get_root_node_index(); -// uint64_t old_root_index = _root_info.get_root_node_index(); -// uint64_t tmp_root_index = UNDEF_INDEX; -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// -// if (UNDEF_INDEX == new_root_index) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_root_info.get_root_node_index()"); -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); -// } -// else -// { -// _root_info.set_next_allocate_id(new_root_info.get_next_allocate_id()); -// _root_info.set_root_node_index(old_root_index, new_root_index); -// } -// _bt_set_own_root_node_index(cur_root_info_ary, tmp_root_index, old_root_index); -// -// if (DF_UL_LOG_NONE != log_level) -// { -// DF_WRITE_LOG_US(log_level, -// "old_root_index=0x%lx, new_root_index=0x%lx", -// old_root_index, new_root_index); -// } -// -// return err; -//}; - - - -//回收之前的动作... -template -inline int dfs_btree_leaf_node_t::action_before_gc(void * pgc_info, const uint64_t node_index) { - dfs_btree_t * pbtree = (dfs_btree_t *)pgc_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == pbtree) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbtree"); - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_SET_GC_INFO); - } else if((err = pbtree->action_before_leaf_node_gc(node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pbtree->action_before_leaf_node_gc() returns 0x%x", err); - } - - return err; -}; - -template -inline int dfs_btree_mid_node_t::action_before_gc(void * pgc_info, const uint64_t node_index) { - dfs_btree_t * pbtree = (dfs_btree_t *)pgc_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == pbtree) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbtree"); - err = DF_BT_SET_INTERNAL_ERR(dfs_bt_const_t::ERRNO_BT_SET_GC_INFO); - } else if((err = pbtree->action_before_mid_node_gc(node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pbtree->action_before_mid_node_gc() returns 0x%x", err); - } - - return err; -}; - -//增加前所做的操作 -inline int dfs_bt_root_t::action_while_added(void * pgc_info, - const uint64_t /*node_index*/) { - dfs_btree_t * pbtree = (dfs_btree_t *)pgc_info; - //uint64_t ref_counter = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == pbtree) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbtree"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SET_GC_INFO); - //增加根的操作..... - } else if ((err = pbtree->vir_inc_root_ref_counter(*this)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pbtree->vir_inc_root_ref_counter() returns 0x%x", err); - } - - return err; -}; -//删除前所做的操作 -//根节点删除之前... -inline int dfs_bt_root_t::action_before_gc(void * pgc_info, - const uint64_t /*node_index*/) { - dfs_btree_t * pbtree = (dfs_btree_t *)pgc_info; - //uint64_t ref_counter = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == pbtree) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbtree"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SET_GC_INFO); - } else if ((err = pbtree->vir_dec_root_ref_counter(*this)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pbtree->vir_dec_root_ref_counter() returns 0x%x", err); - } - - return err; -}; - - - -class dfs_btree_lock_hold_t : public dfs_mutex_hold_t { -}; - -class dfs_btree_lock_t : public dfs_mutex_lock_t { -public: - int init(void) const { - return 0; - }; -//protected: -// inline int _acquire_mutate_lock( -// dfs_btree_lock_hold_t & lock_hold, -// const int64_t wait_microsecond = 0) const; -// inline int _release_mutate_lock(dfs_btree_lock_hold_t & lock_hold) const; -// inline int _verify_mutate_locker(const dfs_btree_lock_hold_t & lock_hold) const; -public: - inline int acquire_mutate_lock( - dfs_btree_lock_hold_t & lock_hold, - const int64_t wait_microsecond = 0) const { - return dfs_mutex_lock_t::_acquire_lock(lock_hold, wait_microsecond); - }; - inline int release_mutate_lock(dfs_btree_lock_hold_t & lock_hold) const { - return dfs_mutex_lock_t::_release_lock(lock_hold); - }; - inline bool verify_lock_hold(const dfs_btree_lock_hold_t & lock_hold) const { - //??? - return _verify_hold(lock_hold); - }; -////Begin: Obsolete interface: -//protected: -// dfs_btree_lock_hold_t _lock_hold; -// inline int _acquire_mutate_lock(const int64_t wait_microsecond = 0) const -// { -// return acquire_mutate_lock((dfs_btree_lock_hold_t &)_lock_hold, wait_microsecond); -// }; -// inline int _release_mutate_lock(void) const -// { -// return release_mutate_lock((dfs_btree_lock_hold_t &)_lock_hold); -// }; -////End: Obsolete interface: -}; - - -#define BT_MUTATE_LOCK_ACQUIRE(hold_ptr, hold_inst, max_time_in_us) \ - ((NULL == hold_ptr) ? this->acquire_mutate_lock(hold_inst, max_time_in_us) : \ - this->_acquire_hold(*hold_ptr)) - -#define BT_MUTATE_LOCK_RELEASE(hold_ptr, hold_inst) \ - ((NULL == hold_ptr) ? this->release_mutate_lock(hold_inst) : \ - this->_release_hold(*hold_ptr)) - -#define BT_MUTATE_LOCK_ACQUIRE_ERR_INFO "BT_MUTATE_LOCK_ACQUIRE() returns error" - -#define BT_MUTATE_LOCK_RELEASE_ERR_INFO "BT_MUTATE_LOCK_RELEASE() returns error" - -//======================================================================================================================== -//======================================================================================================================== -//======================================================================================================================== -//======================================================================================================================== -//原来做为df_btree.cpp单独存在,现在提出来... -//放在一个头文件进行管理. -//输出:初始化根节点 -int dfs_btree_t::init(const uint32_t bt_instance_pos, dfs_bt_root_t & new_wr_bt_root) { - dfs_sbt_root_t sbt_root; - uint64_t final_node_index = UNDEF_INDEX; - uint64_t old_node_index = UNDEF_INDEX; - //uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - //DFS_BT_DEBUG_TRAP; - if ((err = leaf_ary_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::init() returns 0x%x", err); - } - //gc对象就是this... - else if ((err = leaf_ary_t::set_gc_info(this)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::set_gc_info() returns 0x%x", err); - } else if ((err = mid_ary_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::init() returns 0x%x", err); - } else if ((err = mid_ary_t::set_gc_info(this)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::set_gc_info() returns 0x%x", err); - } - //leaf_node: 保留unit 0,目前暂时未使用 - //mid_niode: 保留unit 0,在删除中间节点时,用于临时保存更新的中间节点(但整棵树还未更新) - //root node - else if ((err = _acquire_leaf_node(final_node_index, NULL)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == final_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == final_node_index"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = sbt_root.set_root_node_index(old_node_index, final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.set_root_node_index() returns 0x%x", err); - } else if (UNDEF_POS != _bt_instance_pos) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_POS != _bt_instance_pos"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_POS); - } else if (bt_instance_pos >= MAX_BT_INSTANCE_NUM) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_instance_pos >= MAX_BT_INSTANCE_NUM"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_BUF_POS); - } else { - _bt_instance_pos = bt_instance_pos; - sbt_root.set_mutation_counter(_bt_get_mutation_counter()); - if ((err = _bt_set_sbt_root(new_wr_bt_root, sbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_set_sbt_root() returns 0x%x", err); - } - - } - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - if (DF_UL_LOG_NONE != log_level) { - //DF_WRITE_LOG_US(log_level, - //"final_node_index=0x%lx, old_node_index=0x%lx, ref_counter=%ld", - //final_node_index, old_node_index, ref_counter); - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, old_node_index=0x%lx, ref_counter=%ld", - final_node_index, old_node_index, UNDEF_REF_COUNTER); - - } - - return err; -}; - - -//增加/减少根节点引用计数 -int dfs_btree_t::vir_inc_root_ref_counter( - const dfs_bt_root_t & bt_root) const { - DFS_BT_DEBUG_TRAP; - return this->_bt_inc_root_ref_counter(bt_root); -}; -int dfs_btree_t::vir_dec_root_ref_counter( - const dfs_bt_root_t & bt_root) const { - DFS_BT_DEBUG_TRAP; - return this->_bt_dec_root_ref_counter(bt_root); -}; - - - -int dfs_btree_t::_get_leaf_node_ref_counter( - const uint64_t final_node_index, - uint64_t & ref_counter) const { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_leaf_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = leaf_ary_t::get_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::get_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; - - -int dfs_btree_t::_get_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) const { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_mid_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_mid_node_index_verify() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = mid_ary_t::get_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::get_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; - -//relase node由dfs_2d_ary自动进行(根据ref_counter) -int dfs_btree_t::_acquire_leaf_node(uint64_t & final_node_index, leaf_node_t ** ppleaf_node) { - uint64_t inter_node_index = UNDEF_INDEX; - leaf_node_t * pleaf_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = leaf_ary_t::acquire_t(NULL, inter_node_index, &pleaf_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::acquire_t() returns 0x%x", err); - } else if (UNDEF_INDEX == inter_node_index || NULL == pleaf_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == inter_node_index || NULL == pleaf_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else { - final_node_index = _add_leaf_flag_bit(inter_node_index); - pleaf_node->set_mutation_counter(_bt_get_mutation_counter()); - //_bt_get_mutation_counter()+1; yangzhenkun@baidu.com @ 20090830 - } - - if (0 == err) { - if (NULL != ppleaf_node) { - *ppleaf_node = pleaf_node; - } - } else { - final_node_index = UNDEF_INDEX; - if (NULL != ppleaf_node) { - *ppleaf_node = NULL; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "pleaf_node=0x%p, final_node_index=0x%lx, inter_node_index=0x%lx", - pleaf_node, final_node_index, inter_node_index); - } - - return err; -}; - - -//relase node由dfs_2d_ary自动进行(根据ref_counter) -int dfs_btree_t::_acquire_reserved_leaf_node(uint64_t & final_node_index, leaf_node_t ** ppleaf_node) { - leaf_node_t * pleaf_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - final_node_index = UNDEF_INDEX; - if (NULL != ppleaf_node) { - *ppleaf_node = NULL; - } - - if (df_atomic_compare_exchange(&_is_reserved_leaf_node_acquired, 1, 0) == 0) { - final_node_index = _add_leaf_flag_bit(NULL_INDEX); - if ((err = _get_leaf_node_for_mutate(final_node_index, &pleaf_node)) != 0 || NULL == pleaf_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == inter_node_index || NULL == pleaf_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else { - pleaf_node->set_mutation_counter(_bt_get_mutation_counter()); - } - if (0 == err) { - if (NULL != ppleaf_node) { - *ppleaf_node = pleaf_node; - } - } else { - final_node_index = UNDEF_INDEX; - } - } - - return final_node_index; -}; -//return: 0 for success, other values for failure -//????.. -int dfs_btree_t::_release_reserved_leaf_node(const uint64_t final_node_index) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL_INDEX != inter_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL_INDEX != inter_node_index"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_RESERVED_LEAF_NODE); - } else if (df_atomic_compare_exchange(&_is_reserved_leaf_node_acquired, 0, 1) != 1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "release not acquired reserved_leaf_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_RESERVED_LEAF_NODE); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx", - final_node_index, inter_node_index); - } - - return err; -}; -//relase node由dfs_2d_ary自动进行(根据ref_counter) -int dfs_btree_t::_acquire_mid_node(uint64_t & final_node_index, mid_node_t ** ppmid_node) { - uint64_t inter_node_index = UNDEF_INDEX; - mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - final_node_index = UNDEF_INDEX; - if ((err = mid_ary_t::acquire_t(NULL, inter_node_index, &pmid_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::acquire_t() returns 0x%x", err); - } else if (UNDEF_INDEX == inter_node_index || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == inter_node_index || NULL == pmid_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_ACQUIRE); - } else { - final_node_index = _add_mid_flag_bit(inter_node_index); - pmid_node->set_mutation_counter(_bt_get_mutation_counter()); - //_bt_get_mutation_counter()+1; yangzhenkun@baidu.com @ 20090830 - } - - if (0 == err) { - if (NULL != ppmid_node) { - *ppmid_node = pmid_node; - } - } else { - final_node_index = UNDEF_INDEX; - if (NULL != ppmid_node) { - *ppmid_node = NULL; - } - } - - return err; -}; - -int dfs_btree_t::_acquire_reserved_mid_node(uint64_t & final_node_index, mid_node_t ** ppmid_node) { - mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - final_node_index = UNDEF_INDEX; - if (NULL != ppmid_node) { - *ppmid_node = NULL; - } - - if (df_atomic_compare_exchange(&_is_reserved_mid_node_acquired, 1, 0) == 0) { - final_node_index = _add_mid_flag_bit(NULL_INDEX); - if ((err = _get_mid_node_for_mutate(final_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == inter_node_index || NULL == pmid_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else { - pmid_node->set_mutation_counter(_bt_get_mutation_counter()); - } - - if (0 == err) { - if (NULL != ppmid_node) { - *ppmid_node = pmid_node; - } - } else { - final_node_index = UNDEF_INDEX; - } - } - - return final_node_index; -}; - -//return: 0 for success, other values for failure -int dfs_btree_t::_release_reserved_mid_node(const uint64_t final_node_index) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL_INDEX != inter_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "reserved_mid_node is not NULL_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_RESERVED_MID_NODE); - } else if (df_atomic_compare_exchange(&_is_reserved_mid_node_acquired, 0, 1) != 1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "release not acquired reserved_mid_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_RESERVED_MID_NODE); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx", - final_node_index, inter_node_index); - } - - return err; -}; - -//return: 0 for success, other value for error -int dfs_btree_t::_inc_leaf_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_leaf_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = leaf_ary_t::inc_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::inc_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; -int dfs_btree_t::_inc_leaf_node_ref_counter_if_not_zero( - const uint64_t final_node_index, - uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = 0; - if ((err = _valid_leaf_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = leaf_ary_t::inc_t_ref_counter_if_not_zero(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::inc_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; -int dfs_btree_t::_inc_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_mid_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_mid_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_INDEX); - } else if ((err = mid_ary_t::inc_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::inc_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; -int dfs_btree_t::_inc_mid_node_ref_counter_if_not_zero( - const uint64_t final_node_index, - uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = 0; - if ((err = _valid_mid_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_mid_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_INDEX); - } else if ((err = mid_ary_t::inc_t_ref_counter_if_not_zero(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::inc_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; - -int dfs_btree_t::_dec_leaf_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_leaf_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = leaf_ary_t::dec_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::dec_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; -int dfs_btree_t::_dec_mid_node_ref_counter(const uint64_t final_node_index, uint64_t & ref_counter) { - const uint64_t inter_node_index = _remove_node_flag_bit(final_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ref_counter = UNDEF_REF_COUNTER; - if ((err = _valid_mid_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_mid_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_INDEX); - } else if ((err = mid_ary_t::dec_t_ref_counter(inter_node_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::dec_t_ref_counter() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "final_node_index=0x%lx, inter_node_index=0x%lx, ref_counter=%ld", - final_node_index, inter_node_index, ref_counter); - } - - return err; -}; - -//功能:计算新增一个节点引起的(key_index和B树节点)引用计数 -//Return: 0 for success, other value for error -//假设新增final node index所引起的引用计数增加. -int dfs_btree_t::_inc_pointed_ref_counter(const uint64_t final_node_index) { - const node_base_t * pnode = NULL; - uint64_t ref_counter = UNDEF_REF_COUNTER; - uint32_t subkey_num = 0; - uint32_t j = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - - if ((err = _get_node(final_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node(final_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = vir_inc_obj_ary_ref_counter( - pnode->get_subkey_ary(), - pnode->get_subkey_num())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_inc_obj_ary_ref_counter() returns 0x%x", err); - } else if (_is_mid_node(final_node_index)) { - const mid_node_t * pmid_node = NULL; - - if ((err = _get_mid_node(final_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(final_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else { - //增加每个节点的ref cnt.. - subkey_num = pmid_node->get_subkey_num(); - for (j = 0; j <= subkey_num; ++j) { - if ((err = _inc_node_ref_counter(pmid_node->get_subnode_index(j), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_node_ref_counter returns 0x%x,", err); - break; - } - } - } - } - - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, subkey_num=%d", - final_node_index, subkey_num); - } - - return err; -}; - -//功能:计算删除一个节点引起的(key_index和B树节点)引用计数 -//Return: 0 for success, other value for error -int dfs_btree_t::_dec_pointed_ref_counter(const uint64_t final_node_index) { - const node_base_t * pnode = NULL; - uint64_t ref_counter = UNDEF_REF_COUNTER; - uint32_t subkey_num = 0; - uint32_t j = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_node(final_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node(final_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = vir_dec_obj_ary_ref_counter( - pnode->get_subkey_ary(), - pnode->get_subkey_num())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_dec_obj_ary_ref_counter() returns 0x%x", err); - } else if (_is_mid_node(final_node_index)) { - const mid_node_t * pmid_node = NULL; - - if ((err = _get_mid_node(final_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(final_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else { - subkey_num = pmid_node->get_subkey_num(); - - for (j = 0; j <= subkey_num; ++j) { - if ((err = _dec_node_ref_counter(pmid_node->get_subnode_index(j), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_node_ref_counter returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "j=%d, pmid_node->get_subnode_index(j)=0x%lx", - j, pmid_node->get_subnode_index(j)); - break; - } - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, subkey_num=%d", - final_node_index, subkey_num); - } - - return err; -}; - - -int dfs_btree_t::action_before_leaf_node_gc(const uint64_t internal_node_index) { - const uint64_t final_node_index = _add_leaf_flag_bit(internal_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _valid_leaf_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } - //去减少这个节点下面的引用计数.... - else if ((err = _dec_pointed_ref_counter(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_pointed_ref_counter() returns 0x%x", err); - } - - return err; - -}; - -int dfs_btree_t::action_before_mid_node_gc(const uint64_t internal_node_index) { - const uint64_t final_node_index = _add_mid_flag_bit(internal_node_index); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _valid_mid_node_index_verify(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_valid_leaf_node_index_check() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_INDEX); - } else if ((err = _dec_pointed_ref_counter(final_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_pointed_ref_counter() returns 0x%x", err); - } - - return err; -}; - -//drill last object...,得到一个index.. -int dfs_btree_t::_get_drill_last_obj( - const dfs_btree_drill_t & drill_info, - uint64_t & last_obj_index) const { - const node_base_t * pnode = NULL; - const uint64_t last_node_index = drill_info.get_last_node_index(); - const uint32_t last_ins_pos = drill_info.get_last_ins_pos(); - uint32_t subkey_num = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - last_obj_index = UNDEF_INDEX; - if (UNDEF_INDEX == last_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if (UNDEF_POS == last_ins_pos) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_ins_pos() returns UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((err = _get_node(last_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (last_ins_pos >= (subkey_num = pnode->get_subkey_num())) { - last_obj_index = UNDEF_INDEX; - } else if ((last_obj_index = pnode->get_subkey_index(last_ins_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_KEY_INDEX); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, last_ins_pos=%d, subkey_num=%d, last_node_index=0x%lx", - drill_info.get_drill_ptr(), last_ins_pos, subkey_num, last_node_index); - } - - return err; -}; - -//健康检查... -//主要是检查节点是否一致... -// return: 0 for success, other values for error -// Should be called in locked state and without checkpointing or other COW(load or store) -int dfs_btree_t::_bt_sanitary_check(const dfs_bt_root_t & bt_root) const { - uint64_t obj_num_in_btree = 0; - uint64_t in_use_obj_num_in_2d_ary = 0; - uint64_t leaf_node_num_in_btree = 0; - uint64_t in_use_leaf_node_num_in_2d_ary = 0; - uint64_t mid_node_num_in_btree = 0; - uint64_t in_use_mid_node_num_in_2d_ary = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - //从btree结构中得到... - //obj num in btree==total key number... - if ((err = bt_get_total_num( - bt_root, - obj_num_in_btree, - leaf_node_num_in_btree, - mid_node_num_in_btree)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_total_num() returns: 0x%x", err); - } else if ((err = bt_get_in_use_node_num_in_2d_ary( - in_use_leaf_node_num_in_2d_ary, - in_use_mid_node_num_in_2d_ary)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_in_use_node_num_in_2d_ary() returns: 0x%x", err); - } else if ((err = vir_get_total_in_use_obj_num_in_ary(in_use_obj_num_in_2d_ary)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_get_total_in_use_obj_num_in_ary() returns: 0x%x", err); - } else if ((obj_num_in_btree+1) != in_use_obj_num_in_2d_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(obj_num_in_btree+1) != in_use_obj_num_in_2d_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_T_LEAK); - } else if ((leaf_node_num_in_btree+1) != in_use_leaf_node_num_in_2d_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(leaf_node_num_in_btree+1) != in_use_leaf_node_num_in_2d_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_T_LEAK); - } else if ((mid_node_num_in_btree+1) != in_use_mid_node_num_in_2d_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(mid_node_num_in_btree+1) != in_use_mid_node_num_in_2d_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_T_LEAK); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_num_in_btree=%ld, leaf_node_num_in_btree=%ld, mid_node_num_in_btree=%ld", - obj_num_in_btree, leaf_node_num_in_btree, mid_node_num_in_btree); - DF_WRITE_LOG_US(log_level, - "in_use_leaf_node_num_in_2d_ary=%ld,in_use_mid_node_num_in_2d_ary=%ld", - in_use_leaf_node_num_in_2d_ary, in_use_mid_node_num_in_2d_ary); - DF_WRITE_LOG_US(log_level, - "in_use_obj_num_in_2d_ary=%ld", - in_use_obj_num_in_2d_ary); - } - - return err; -}; - -//功能:生成一个内容为空的根节点(以便用来通过_update_root()清空树) -// return: 0 for success, other values for error -int dfs_btree_t::_acquire_empty_root( - dfs_bt_root_t & new_wr_bt_root) { - dfs_sbt_root_t sbt_root = _bt_get_sbt_root(new_wr_bt_root); - uint64_t new_root_index = UNDEF_INDEX; - uint64_t tmp_root_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //_bt_inc_mutation_counter(); - if ((err = _acquire_leaf_node(new_root_index, NULL)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns: 0x%x", err); - } else if (UNDEF_INDEX == new_root_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "new_root_index is UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } - //获得了叶子节点作为根节点后,那么需要修改root index.. - else if ((err = sbt_root.set_root_node_index(tmp_root_index, new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "sbt_root.set_root_node_index() returns 0x%x", - err); - } else { - sbt_root.set_mutation_counter(_bt_get_mutation_counter()); - if ((err = _bt_set_sbt_root(new_wr_bt_root, sbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_set_sbt_root() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_root_index=0x%lx, tmp_root_index=0x%lx", - new_root_index, tmp_root_index); - } - - return err; -}; - - - - -//功能:在B树中插入一个项且返回新的根节点,但不替换当前树的根节点 -//输入:bt_root -//返回:0 for success, other value for failure -//返回根节点,但是并不替换当前... -int dfs_btree_t::_insert_to_btree( - const dfs_bt_root_t & cur_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const uint64_t ins_obj_index, - const dfs_btree_drill_t & drill_info) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - dfs_btree_node_mutate_t mutate_result; - - //_bt_inc_mutation_counter(); - //使用drill info来插入一个叶子节点... - //并且更新mutate result.. - //需要来插入和删除叶子节点... - //在叶子上直接操作 - //然后 - if ((err = _ins_del_leaf_node(ins_obj_index, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ins_del_leaf_node() returns: 0x%x", err); - } else if ((err = _op_tree( - cur_wr_bt_root, - new_wr_bt_root, - drill_info, - drill_info.get_drill_ptr()-1, - mutate_result)) != 0) - //然后操作cur和new节点的树... - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_tree() returns: 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "ins_obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - ins_obj_index, drill_info.get_drill_ptr()); - DF_WRITE_LOG_US(log_level, - "get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -}; - -//功能:在B树中更新一个项,drill_ptr >= 0并可能指向叶节点或中间节点。 -//输入:bt_root -//说明:调用者需要保证更新前后的项有相同的key。 -//返回:0 for success, other value for failure -int dfs_btree_t::_update_of_btree( - const dfs_bt_root_t & cur_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const uint64_t new_obj_index, - const dfs_btree_drill_t & drill_info) { - dfs_btree_node_mutate_t mutate_result; - const uint64_t myself_node_index = drill_info.get_last_node_index(); - const uint32_t myself_ins_pos = drill_info.get_last_ins_pos(); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //_bt_inc_mutation_counter(); - if (UNDEF_POS == myself_ins_pos) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_POS == myself_ins_pos"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if (UNDEF_INDEX == myself_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == myself_node_index"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else { - if (_is_mid_node(myself_node_index)) { //中间节点 - if ((err = _update_mid_node_subkey( - myself_node_index, - myself_ins_pos, - new_obj_index, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_mid_node_subkey() returns: 0x%x", err); - } - } else { //叶节点 - if ((err = _update_leaf_node_subkey( - myself_node_index, - myself_ins_pos, - new_obj_index, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_leaf_node_subkey() returns: 0x%x", err); - } - } - if (0 == err) { - if ((err = _op_tree( - cur_wr_bt_root, - new_wr_bt_root, - drill_info, - drill_info.get_drill_ptr()-1, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_tree() returns: 0x%x", err); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - new_obj_index, drill_info.get_drill_ptr()); - DF_WRITE_LOG_US(log_level, - "get_update_type()=%d", - mutate_result.get_update_type()); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, myself_ins_pos=%d", - myself_node_index, myself_ins_pos); - } - - return err; -}; - - -//功能:在B树中删除一个项,drill_ptr >= 0并可能指向叶节点或中间节点。 -//输入:bt_root -//返回:0 for success, other value for failure -int dfs_btree_t::_del_from_btree( - const dfs_bt_root_t & cur_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const dfs_btree_drill_t & drill_info) { - uint64_t del_node_index = UNDEF_INDEX; - uint64_t new_mid_node_ref_counter = UNDEF_REF_COUNTER; - uint64_t ref_counter = UNDEF_REF_COUNTER; - dfs_btree_node_mutate_t mutate_result; - dfs_btree_drill_t ext_drill_info(drill_info); - uint64_t subtree_largest_obj_index = UNDEF_INDEX; - mid_node_t * pnew_mid_node = NULL; - uint64_t new_mid_node_index = UNDEF_INDEX; - const mid_node_t * pmid_node = NULL; - const uint64_t myself_node_index = drill_info.get_last_node_index(); - const uint32_t myself_ins_pos = drill_info.get_last_ins_pos(); - bool is_reserved_mid_node_acquired = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - //_bt_inc_mutation_counter(); - if (UNDEF_POS == myself_ins_pos) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_POS == myself_ins_pos"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if (UNDEF_INDEX == myself_node_index) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == myself_node_index"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else { - if (_is_mid_node(myself_node_index)) { //中间节点 - //用该子节点下挂的子树的最大obj来替换被删除的obj - //太牛了...直接替换.... - //然后规约到删除叶子节点...:) - if ((err = _get_mid_node(myself_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns: 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if ((del_node_index = pmid_node->get_subnode_index(myself_ins_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "del_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - } else if ((err = _get_subtree_largest( - del_node_index, - ext_drill_info, - subtree_largest_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns: 0x%x", err); - } - //Using a reserved node to temporarily keep this node - else if ((err = _acquire_reserved_mid_node(new_mid_node_index, &pnew_mid_node)) == 0) { - //Using a reserved node to temporarily keep this node - //????... - is_reserved_mid_node_acquired = true; - if ((err = pmid_node->update_subkey( - *pnew_mid_node, - myself_ins_pos, - subtree_largest_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->update_subkey() returns: 0x%x", err); - } - //重新设置删除的位置.... - else if ((err = ext_drill_info.set_del_mid_drill_info( - drill_info.get_drill_ptr(), - new_mid_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ext_drill_info.set_del_mid_drill_info() returns: 0x%x", err); - } - } - //???... - //貌似会把节点给冲吊.... - else if ((err = _acquire_mid_node(new_mid_node_index, &pnew_mid_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node() returns 0x%x", err); - } - //Using an acquired node to temporarily keep this node - else { - //Using an acquired node to temporarily keep this node - is_reserved_mid_node_acquired = false; - if ((err = pmid_node->update_subkey( - *pnew_mid_node, - myself_ins_pos, - subtree_largest_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->update_subkey() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_mid_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } else if ((err = _inc_mid_node_ref_counter(new_mid_node_index, new_mid_node_ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_mid_node_ref_counter() returns 0x%x", err); - } else if ((err = ext_drill_info.set_del_mid_drill_info( - drill_info.get_drill_ptr(), - new_mid_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ext_drill_info.set_del_mid_drill_info() returns 0x%x", err); - } - } - } - } - if (0 == err) { - if ((err = _ins_del_leaf_node(UNDEF_INDEX, ext_drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_ins_del_leaf_node() returns 0x%x", err); - } else if ((err = _op_tree( - cur_wr_bt_root, - new_wr_bt_root, - ext_drill_info, - ext_drill_info.get_drill_ptr()-1, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_tree() returns 0x%x", err); - } - } - - if (NULL != pnew_mid_node) { - if (is_reserved_mid_node_acquired) { - //释放...中间节点... - //reversed mid node... - if ((err1 = _release_reserved_mid_node(new_mid_node_index)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_release_reserved_mid_node() returns 0x%x", err); - } - } else { - //释放该节点 - if ((err1 = _dec_mid_node_ref_counter(new_mid_node_index, ref_counter)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_mid_node_ref_counter() returns 0x%x", err); - } else if (0 != ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "0 != ref_counter"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "is_reserved_mid_node_acquired=%d", - is_reserved_mid_node_acquired); - DF_WRITE_LOG_US(log_level, - "drill_info.get_drill_ptr()=%d, myself_ins_pos=%d, myself_node_index=0x%lx", - drill_info.get_drill_ptr(), myself_ins_pos, myself_node_index); - DF_WRITE_LOG_US(log_level, - "del_node_index=0x%lx, new_mid_node_ref_counter=%ld, ref_counter=%ld", - del_node_index, new_mid_node_ref_counter, ref_counter); - DF_WRITE_LOG_US(log_level, - "get_update_type()=%d", - mutate_result.get_update_type()); - DF_WRITE_LOG_US(log_level, - "new_mid_node_index=0x%lx, subtree_largest_obj_index=0x%lx", - new_mid_node_index, subtree_largest_obj_index); - } - - return err; -}; - - - -// 功能:获得B树最小元素并填充drill_info -// 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使树空)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_smallest( - const dfs_bt_root_t & bt_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - drill_info.init(); - - if (UNDEF_INDEX == sbt_root.get_root_node_index()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == sbt_root.get_root_node_index()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node_ref_counter(sbt_root.get_root_node_index(), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 0 || UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } - //得到子树的最小值... - else if ((err = _get_subtree_smallest( - sbt_root.get_root_node_index(), - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_smallest() returns 0x%x", err); - } else { - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - obj_index, drill_info.get_drill_ptr()); - } - - return err; -}; - -// -// 功能:获得B树最大元素并填充drill_info -// 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使树空)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_largest( - const dfs_bt_root_t & bt_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - drill_info.init(); - - if (UNDEF_INDEX == sbt_root.get_root_node_index()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == sbt_root.get_root_node_index()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node_ref_counter(sbt_root.get_root_node_index(), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 0 || UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = _get_subtree_largest( - sbt_root.get_root_node_index(), - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_largest() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - obj_index, drill_info.get_drill_ptr()); - } - - return err; -}; - - - -// 功能:获得一棵子树的最小元素,并追加drill_info中(与search一样) -// 输出:若存在(子树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使子树空且为根节点)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_subtree_smallest( - const uint64_t subtree_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - uint64_t cur_subtree_root = subtree_root; - uint64_t nex_subtree_root = subtree_root; - const node_base_t * pnode = NULL; - const mid_node_t * pmid_node = NULL; - uint32_t subkey_num = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - while (0 == err) { - if ((err = _get_node(cur_subtree_root, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } else if ((subkey_num = pnode->get_subkey_num()) <= 0) { - //节点没有元素(只有根节点是唯一叶节点时才有这种情况) - if (drill_info.get_drill_ptr() >= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "empty btree, but _drill_ptr >= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((err = drill_info.push(0, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - } - break; - } else if (pnode->is_mid_node()) { - if ((err = drill_info.push(0, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - } else if ((err = _get_mid_node(cur_subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - break; - } else if ((nex_subtree_root = pmid_node->get_subnode_index(0)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subnode_index(0) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - break; - } else { - cur_subtree_root = nex_subtree_root; - } - } - //leaf node, no further search needed - else { - if ((err = drill_info.push(0, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - } else if ((obj_index = pnode->get_subkey_index(0)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_index(0) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - } - break; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, cur_subtree_root=0x%lx, subkey_num=%d", - subtree_root, cur_subtree_root, subkey_num); - DF_WRITE_LOG_US(log_level, - "drill_info.get_drill_ptr()=0x%x", - drill_info.get_drill_ptr()); - } - - return err; -}; - - -// 功能:获得一棵子树的最大元素,并追加drill_info中(与search一样) -// 输出:若存在(子树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使子树空且为根节点)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_subtree_largest( - const uint64_t subtree_root, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - uint64_t cur_subtree_root = subtree_root; - uint64_t nex_subtree_root = subtree_root; - const node_base_t * pnode = NULL; - const mid_node_t * pmid_node = NULL; - uint32_t subkey_num = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - while (0 == err) { - if ((err = _get_node(cur_subtree_root, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } else if ((subkey_num = pnode->get_subkey_num()) <= 0) { - //节点没有元素(只有根节点是唯一叶节点时才有这种情况) - if (drill_info.get_drill_ptr() >= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "empty btree, but _drill_ptr >= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((err = drill_info.push(0, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - } - break; - } else if (pnode->is_mid_node()) { - if ((err = drill_info.push(subkey_num, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - break; - } else if ((err = _get_mid_node(cur_subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - break; - } else if ((nex_subtree_root = pmid_node->get_subnode_index(subkey_num)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subnode_index(subkey_num) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - break; - } else { - cur_subtree_root = nex_subtree_root; - } - } - //leaf node, no further search needed - else { - if ((err = drill_info.push(subkey_num-1, cur_subtree_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.push() returns 0x%x", err); - break; - } else if ((obj_index = pnode->get_subkey_index(subkey_num-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_index(subkey_num-1) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_KEY_INDEX); - } - break; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, cur_subtree_root=0x%lx, subkey_num=%d", - subtree_root, cur_subtree_root, subkey_num); - DF_WRITE_LOG_US(log_level, - "drill_info.get_drill_ptr()=0x%x", - drill_info.get_drill_ptr()); - } - - return err; -}; - - -// 功能:根据drill_info获得比当前项小的项,并更新drill_info指向之 -// 若存在则pct指向之且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使没有更小元素)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_smaller( - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const node_base_t * pnode = NULL; - const mid_node_t * pmid_node = NULL; - uint64_t last_node_index = UNDEF_INDEX; - uint64_t next_node_index = UNDEF_INDEX; - uint32_t subkey_num = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - if (drill_info.get_drill_ptr() >= 0) { - if ((last_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if (_is_leaf_node(last_node_index)) { - //叶节点 - if (drill_info.get_last_ins_pos() > 0) { - if ((err = drill_info.dec_last_ins_pos()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.dec_last_ins_pos() returns 0x%x", err); - } - } else { - while (0 == err) { - //到最左边则向根回退上一层 - if ((err = drill_info.pop()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.pop() returns 0x%x", err); - break; - } else if (drill_info.get_drill_ptr() < 0) { - break; - } else if (drill_info.get_last_ins_pos() > 0) { - if ((err = drill_info.dec_last_ins_pos()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.dec_last_ins_pos() returns 0x%x", err); - } - break; - } - } - } - if (drill_info.get_drill_ptr() >= 0) { - if ((next_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_node(next_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - subkey_num = pnode->get_subkey_num(); - if ((obj_index = pnode->get_subkey_index(drill_info.get_last_ins_pos())) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pnode->get_subkey_index(drill_info.get_last_ins_pos()) UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_KEY_INDEX); - } - } - } - } else { - //中间节点 - if ((err = _get_mid_node(last_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else { - subkey_num = pmid_node->get_subkey_num(); - if ((next_node_index = pmid_node->get_subnode_index(drill_info.get_last_ins_pos())) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pmid_node->get_subnode_index(drill_info.get_last_ins_pos()) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_subtree_largest( - next_node_index, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_largest() returns 0x%x", err); - } - } - } - } else { - //没有更小的项 - obj_index = UNDEF_INDEX; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_info.get_last_node_index()=0x%lx, drill_ptr=%d, last_ins_pos=%d", - drill_info.get_last_node_index(), - drill_info.get_drill_ptr(), - drill_info.get_last_ins_pos()); - DF_WRITE_LOG_US(log_level, - "last_node_index=0x%lx, next_node_index=0x%lx, subkey_num=%d", - last_node_index, next_node_index, subkey_num); - } - - return err; -}; - - -// 功能:根据drill_info获得比当前项大的项,并更新drill_info指向之 -// 若存在则pct指向之且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使没有更大元素)返回0, 其他值错误(ERRNO_BT_DRILL_OBSOLETE则树有新的修改) -int dfs_btree_t::_get_larger( - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const node_base_t * pnode = NULL; - const mid_node_t * pmid_node = NULL; - uint64_t last_node_index = UNDEF_INDEX; - uint64_t next_node_index = UNDEF_INDEX; - uint32_t subkey_num = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - if (drill_info.get_drill_ptr() >= 0) { - if ((last_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_node(last_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (_is_leaf_node(last_node_index)) { - //叶节点 - if ((drill_info.get_last_ins_pos()+1) < pnode->get_subkey_num()) { - if ((err = drill_info.inc_last_ins_pos()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.inc_last_ins_pos() returns 0x%x", err); - } - } else if ((err = drill_info.pop()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.pop() returns 0x%x", err); - } else { - while (0 == err) { - if (drill_info.get_drill_ptr() < 0) { - break; - } - if ((last_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - break; - } else if ((err = _get_node(last_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } else if (drill_info.get_last_ins_pos() < (subkey_num = pnode->get_subkey_num())) { - break; - } - //到最左边则向根回退上一层 - else if ((err = drill_info.pop()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.pop() returns 0x%x", err); - } - } - } - if (drill_info.get_drill_ptr() >= 0) { - if ((next_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "drill_info.get_last_node_index() returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_node(next_node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((obj_index = pnode->get_subkey_index(drill_info.get_last_ins_pos())) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pnode->get_subkey_index(drill_info.get_last_ins_pos()) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } - } - } else { - //中间节点 - if ((err = _get_mid_node(last_node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if (drill_info.get_last_ins_pos() >= pmid_node->get_subkey_num()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_last_ins_pos() >= pmid_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((err = drill_info.inc_last_ins_pos()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.inc_last_ins_pos() returns 0x%x", err); - } else if ((next_node_index = pmid_node->get_subnode_index(drill_info.get_last_ins_pos())) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "pmid_node->get_subnode_index(drill_info.get_last_ins_pos()) returns UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_subtree_smallest( - next_node_index, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_smallest() returns 0x%x",err); - } - } - } else { - //没有更大的项 - obj_index = UNDEF_INDEX; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_info.get_last_node_index()=0x%lx, drill_ptr=%d, last_ins_pos=%d", - drill_info.get_last_node_index(), - drill_info.get_drill_ptr(), - drill_info.get_last_ins_pos()); - DF_WRITE_LOG_US(log_level, - "last_node_index=0x%lx, next_node_index=0x%lx, subkey_num=%d", - last_node_index, next_node_index, subkey_num); - } - - return err; -}; - - - -// 功能:获得刚好比输入项srct小的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较小元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 -// 返回:0 for no error, other values for error -int dfs_btree_t::_get_smaller_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - bool is_search = false; - int cmp = -2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (drill_info.not_match_tree(sbt_root)) { - //需要重新搜索... - is_search = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } else if (UNDEF_INDEX == obj_index) { - is_search = true; - } else if ((err = vir_compare_index_key(bt_root, obj_index, pkey, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_compare_index_key() returns 0x%x", err); - } else if (0 != cmp) { - is_search = true; - } - - if (0 == err && is_search) { - //需要重新搜索 - drill_info.init(); - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - //首先搜索到,然后再取稍微小一点的值...:)..... - if ((err = _search_by_key(bt_root, pkey, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - } - if (0 == err && (err = _get_smaller(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_smaller() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "drill_info._drill_ptr=%d,obj_index=0x%lx", - drill_info.get_drill_ptr(), obj_index); - } - - return err; -}; -int dfs_btree_t::_get_smaller_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - bool is_search = false; - int cmp = -2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (drill_info.not_match_tree(sbt_root)) { - is_search = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } else if (UNDEF_INDEX == obj_index) { - is_search = true; - } else if ((err = vir_compare_index_obj(bt_root, obj_index, pobj, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_compare_index_key() returns 0x%x", err); - } else if (0 != cmp) { - is_search = true; - } - - if (0 == err && is_search) { - //需要重新搜索 - drill_info.init(); - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - if ((err = _search_by_obj(bt_root, pobj, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - } - if (0 == err && (err = _get_smaller(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_smaller() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "sbt_root:root_node_index/mutation_counter=0x%lx/%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "drill_info._drill_ptr=%d,obj_index=0x%lx", - drill_info.get_drill_ptr(), obj_index); - } - - return err; -}; - -// 功能:获得刚好比输入的srct大的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较大元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 -// 返回:0 for no error, other values for error -int dfs_btree_t::_get_larger_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - bool is_next = false; - bool is_search = false; - int cmp = -2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (drill_info.not_match_tree(sbt_root)) { - is_search = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } else if (UNDEF_INDEX == obj_index) { - is_search = true; - } else if ((err = vir_compare_index_key(bt_root, obj_index, pkey, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_compare_index_key() returns 0x%x", err); - } else if (0 != cmp) { - is_search = true; - } - - if (0 == err && is_search) { - //需要重新搜索 - drill_info.init(); - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - if ((err = _search_by_key(bt_root, pkey, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - } - - if (0 == err) { - //搜索到了,则下一项是较大项; - //没有搜索到,假如所指项不是node的最后一项(无key),则就是较大项,否则是下一项; - is_next = false; - //搜索到了,则下一项是较大项; - if (UNDEF_INDEX != obj_index) { - is_next = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } - //没有搜索到,但所指项无key(node的最后一项),也是下一项是较大项 - else if (UNDEF_INDEX == obj_index) { - is_next = true; - } - if (0 == err && is_next && (err = _get_larger(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_larger() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "sbt_root:root_node_index/mutation_counter=0x%lx/%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "drill_info._drill_ptr=%d, obj_index=0x%lx", - drill_info.get_drill_ptr(), obj_index); - } - - return err; -}; -int dfs_btree_t::_get_larger_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - bool is_next = false; - bool is_search = false; - int cmp = -2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if (drill_info.not_match_tree(sbt_root)) { - is_search = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } else if (UNDEF_INDEX == obj_index) { - is_search = true; - } - //vir=virtual... - else if ((err = vir_compare_index_obj(bt_root, obj_index, pobj, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_compare_index_key() returns 0x%x", err); - } else if (0 != cmp) { - is_search = true; - } - - if (0 == err && is_search) { - //需要重新搜索 - drill_info.init(); - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - if ((err = _search_by_obj(bt_root, pobj, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - } - - if (0 == err) { - //搜索到了,则下一项是较大项; - //没有搜索到,假如所指项不是node的最后一项(无key),则就是较大项,否则是下一项; - is_next = false; - //搜索到了,则下一项是较大项; - if (UNDEF_INDEX != obj_index) { - is_next = true; - } else if ((err = _get_drill_last_obj(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_drill_last_obj() returns 0x%x", err); - } - //没有搜索到,但所指项无key(node的最后一项),也是下一项是较大项 - else if (UNDEF_INDEX == obj_index) { - is_next = true; - } - if (0 == err && is_next && (err = _get_larger(drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_larger() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "sbt_root:root_node_index/mutation_counter=0x%lx/%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "drill_info._drill_ptr=%d, obj_index=0x%lx", - drill_info.get_drill_ptr(), obj_index); - } - - return err; -}; - -//功能:更新一个叶节点的一个subkey,结果写入mutate_result -//返回:0 for success, other value for failure -int dfs_btree_t::_update_leaf_node_subkey( - const uint64_t node_index, - const uint32_t ins_pos, - const uint64_t new_obj_index, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - leaf_node_t * pleaf_node = NULL; - - if ((err = _get_leaf_node_for_mutate(node_index, &pleaf_node)) != 0 || NULL == pleaf_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node_for_mutate() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if (pleaf_node->get_mutation_counter() > _bt_get_max_cow_mutation_counter()) { - //直接修改 - uint64_t old_obj_index = UNDEF_INDEX; - - if ((err = pleaf_node->update_subkey(ins_pos, new_obj_index, old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleaf_node->update_subkey() returns 0x%x", err); - } else if ((err = vir_inc_obj_ref_counter(new_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_inc_obj_ref_counter() returns 0x%x", err); - } else if ((err = vir_dec_obj_ref_counter(old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_dec_obj_ref_counter() returns 0x%x", err); - } - mutate_result.set_mutate_nothing(); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "old_obj_index=0x%lx", old_obj_index); - } - } else { - //copy-on-write - leaf_node_t * pnew_leaf_node = NULL; - uint64_t new_leaf_node_index = UNDEF_INDEX; - - if ((err = _acquire_leaf_node(new_leaf_node_index, &pnew_leaf_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_leaf_node_index || NULL == pnew_leaf_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_leaf_node_index || NULL == pnew_leaf_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pleaf_node->update_subkey( - *pnew_leaf_node, - ins_pos, - new_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleaf_node->update_subkey() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_leaf_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_leaf_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_leaf_node_index=0x%lx, pnew_leaf_node=0x%p", - new_leaf_node_index, pnew_leaf_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, ins_pos=%d, new_obj_index=0x%lx, pleaf_node=0x%p", - node_index, ins_pos, new_obj_index, pleaf_node); - } - - return err; -}; - - - -//功能:更新一个中间节点的一个subkey,结果写入mutate_result -//返回:0 for success, other value for failure -int dfs_btree_t::_update_mid_node_subkey( - const uint64_t node_index, - const uint32_t ins_pos, - const uint64_t new_obj_index, - dfs_btree_node_mutate_t & mutate_result) { - int err = 0; - int log_level = DF_UL_LOG_NONE; - mid_node_t * pmid_node = NULL; - - if ((err = _get_mid_node_for_mutate(node_index, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node_for_mutate() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if (pmid_node->get_mutation_counter() > _bt_get_max_cow_mutation_counter()) - - { - //直接修改 - uint64_t old_obj_index = UNDEF_INDEX; - - if ((err = pmid_node->update_subkey(ins_pos, new_obj_index, old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->update_subkey() returns 0x%x", err); - } else if ((err = vir_inc_obj_ref_counter(new_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_inc_obj_ref_counter() returns 0x%x", err); - } else if ((err = vir_dec_obj_ref_counter(old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_dec_obj_ref_counter() returns 0x%x", err); - } - mutate_result.set_mutate_nothing(); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "old_obj_index=0x%lx", old_obj_index); - } - } else { - //copy-on-write - mid_node_t * pnew_mid_node = NULL; - uint64_t new_mid_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_mid_node_index, &pnew_mid_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_mid_node_index || NULL == pnew_mid_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_mid_node_index || NULL == pnew_mid_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_ACQUIRE); - } else if ((err = pmid_node->update_subkey( - *pnew_mid_node, - ins_pos, - new_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->update_subkey() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_mid_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_mid_node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_mid_node_index=0x%lx, pnew_mid_node=0x%p", - new_mid_node_index, pnew_mid_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, ins_pos=%d, new_obj_index=0x%lx, pmid_node=0x%p", - node_index, ins_pos, new_obj_index, pmid_node); - } - - return err; -}; - - - -//功能:根据mutate_result对B树操作且返回新的根节点,但不替换当前树的根节点 -//输入:mutate_result及bt_root -//返回:0 for success, other value for failure -int dfs_btree_t::_op_tree( - const dfs_bt_root_t & /*old_wr_bt_root*/, - dfs_bt_root_t & new_wr_bt_root, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t tmp_root_index = UNDEF_INDEX; - mid_node_t * pnew_root_node = NULL; - //新增的节点.... - dfs_sbt_root_t sbt_root = _bt_get_sbt_root(new_wr_bt_root); - uint64_t new_root_index = sbt_root.get_root_node_index(); - int cur_drill_ptr = drill_ptr; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - while (0 == err - && cur_drill_ptr >= 0 - && mutate_result.get_update_type() != dfs_btree_node_mutate_t::MUTATE_NOTHING) - //如果为NOTHINg的话,那么就不进行任何的更新..... - { - switch(mutate_result.get_update_type()) { - //子节点插入或删除而导致产生了新节点 - case dfs_btree_node_mutate_t::UPDATE_NODE : - if ((err = _op_mid_node_of_sub_update( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_mid_node_of_sub_update() returns 0x%x", err); - } - break; - //子节点分裂了(产生了两个新节点) - case dfs_btree_node_mutate_t::SPLIT_NODE : - if ((err = _op_mid_node_of_sub_split( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_mid_node_of_sub_split() returns 0x%x", err); - } - break; - //子节点与左兄弟进行了平衡(产生了新的左节点和新的本节点) - case dfs_btree_node_mutate_t::REBALANCE_LEFT : - if ((err = _op_mid_node_of_sub_rebalance_left( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "_op_mid_node_of_sub_rebalance_left() returns 0x%x", - err); - } - break; - //子节点与右兄弟进行了平衡(产生了新的本节点和新的右节点) - case dfs_btree_node_mutate_t::REBALANCE_RIGHT: - if ((err = _op_mid_node_of_sub_rebalance_right( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "_op_mid_node_of_sub_rebalance_right() returns 0x%x", - err); - } - break; - //子节点与左兄弟进行了合并 - case dfs_btree_node_mutate_t::MERGE_LEFT : - if ((err = _op_mid_node_of_sub_merge_left( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_mid_node_of_sub_merge_left() returns 0x%x", err); - } - break; - //子节点与右兄弟进行了合并 - case dfs_btree_node_mutate_t::MERGE_RIGHT: - if ((err = _op_mid_node_of_sub_merge_right( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_mid_node_of_sub_merge_right() returns 0x%x", err); - } - break; - case dfs_btree_node_mutate_t::MERGE_BOTH: //子节点与左右兄弟进行了合并 - if ((err = _op_mid_node_of_sub_merge_both( - drill_info, - cur_drill_ptr, - mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_op_mid_node_of_sub_merge_both() returns 0x%x", err); - } - break; - default: - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "Unknow mutate_type=%d", - mutate_result.get_update_type()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MUTATE_TYPE); - break; - } - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "cur_drill_ptr=%d", cur_drill_ptr); - } - if (0 != err) { - break; - } - --cur_drill_ptr; - } - if (0 == err && -1 == cur_drill_ptr) { //波及到了根节点 - //根节点可能:1.变成一个新根节点;2.分裂,B树长高;3.合并,B树变矮;4.不变化 - switch(mutate_result.get_update_type()) { - case dfs_btree_node_mutate_t::MUTATE_NOTHING : - err = 0; - break; - //子节点插入或删除而导致产生了新节点 - case dfs_btree_node_mutate_t::UPDATE_NODE : - //最新的树节点.... - if ((err = mutate_result.get_update_node_info(new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_node_info() returns 0x%x", - err); - } - break; - //子节点分裂了(产生了两个新节点) - case dfs_btree_node_mutate_t::SPLIT_NODE : - if ((err = _acquire_mid_node(new_root_index, &pnew_root_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_root_index || NULL == pnew_root_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_root_index || NULL == pnew_root_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_ACQUIRE); - } else { - uint64_t new_obj_index = UNDEF_INDEX; - uint64_t node_ary[2]; - - if ((err = mutate_result.get_split_node_info( - new_obj_index, - node_ary[0], - node_ary[1])) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "mutate_result.get_split_node_info() returns 0x%x", - err); - } else if ((err = pnew_root_node->put_pairs(&new_obj_index, node_ary, 1)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_root_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_obj_index=0x%lx, node_ary[0]=0x%lx, node_ary[1]=0x%lx", - new_obj_index, node_ary[0], node_ary[1]); - } - } - break; - default: - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "Unknow mutate_type=%d", - mutate_result.get_update_type()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MUTATE_TYPE); - break; - } - } - - if (0 == err) { - if ((err = sbt_root.set_root_node_index(tmp_root_index, new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "sbt_root.set_root_node_index() returns 0x%x", - err); - } else { - sbt_root.set_mutation_counter(_bt_get_mutation_counter()); - if ((err = _bt_set_sbt_root(new_wr_bt_root, sbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_set_sbt_root() returns 0x%x", err); - } - } - } else { - //如果出错,则把new_wr_bt_root置为old_wr_bt_root - //里面还是...原来的树... - if ((err = _bt_set_sbt_root(new_wr_bt_root, sbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_set_sbt_root() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, cur_drill_ptr=%d", - drill_ptr, cur_drill_ptr); - } - - return err; -}; - - - - -//功能:在B树叶节点中插入或删除一个项(仅操作叶节点),把需要对其父节点的操作记录在mutate_result -// ins_key_index为插入项的key_index或者UNDEF_INDEX(删除项时) -//设置删除的drill ptr:).. -// 如果drill_info.del_drill_ptr不等于-1,则表明是删除操作,当del_drill_ptr < drill_ptr时, -// 表示删除发生在中间节点上,但需要把对应子树的最大key_index提升到中间节点的对应位置。 -//返回:0 for success, other value for failure -int dfs_btree_t::_ins_del_leaf_node( - //UNDEF.. - const uint64_t ins_obj_index, - //!=-1表明删除... - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_ins_pos = 0; - uint64_t myself_node_index = UNDEF_INDEX; - const leaf_node_t * pmyself_node = NULL; - //插入项不是原子操作,不能修改原来的节点 - //插入是写操作...:). - uint32_t left_brother_key_num = 0; - uint32_t right_brother_key_num = 0; - dfs_btree_leaf_node_t super_node; //临时变量... - - if (drill_info.get_drill_ptr() < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_drill_ptr() < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_last_ins_pos()) == UNDEF_POS) { //插入位置... - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_node_index = drill_info.get_last_node_index()) == UNDEF_INDEX) { //插入 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_leaf_node(myself_node_index, &pmyself_node)) != 0 || NULL == pmyself_node) { //得到最后的节点.. - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_NULL_POINTER); - } else if (UNDEF_INDEX != ins_obj_index) { //插入节点 - if (drill_info.get_del_mid_old_node_index() != UNDEF_INDEX) { //确实要删除... - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_del_mid_old_node_index() != UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_DEL_NODE_INDEX); - } else if (pmyself_node->is_full()) { //节点已满,不能插入项,需要与左右兄弟平衡或分裂 - //保存在super node这个临时节点上... - //插入ins pos 和ins obj index.. - if ((err = pmyself_node->insert_subkey(super_node, myself_ins_pos, ins_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->insert_subkey() returns 0x%x", err); - } - //得到左右节点信息... - else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_info.get_drill_ptr())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } - //尝试左右节点子树进行平衡.... - else if (left_brother_key_num > 0 && left_brother_key_num < (BT_FANOUT-1) && - (left_brother_key_num <= right_brother_key_num || 0 == right_brother_key_num)) { - if ((err = _leaf_rebalance_left(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > 0 && right_brother_key_num < (BT_FANOUT-1)) { - if ((err = _leaf_rebalance_right(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_rebalance_right() returns 0x%x", err); - } - } else { - if ((err = _leaf_split(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_split() returns 0x%x", err); - } - } - } else { //节点未满,直接插入 - leaf_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_leaf_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->insert_subkey( - *pnew_myself_node, - myself_ins_pos, - ins_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->insert_subkey() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } else { - //仅仅是更新,把这个节点更新...:).. - mutate_result.set_update_node_info(new_myself_node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - } else { //if (UNDEF_INDEX == ins_key_index) //删除节点 - if (pmyself_node->get_subkey_num() <= BT_HALF_FANOUT && drill_info.get_drill_ptr() > 0) { - //节点半满且非根节点,不能删除项,需与左右兄弟平衡或合并 - if ((err = pmyself_node->del_subkey(super_node, myself_ins_pos)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->del_subkey() returns 0x%x", err); - } else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_info.get_drill_ptr())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } else if (left_brother_key_num > BT_HALF_FANOUT && - left_brother_key_num >= right_brother_key_num) { - if ((err = _leaf_rebalance_left(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > BT_HALF_FANOUT) { - if ((err = _leaf_rebalance_right(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_rebalance_right() returns 0x%x", err); - } - } - //总是尝试首先合并两个... - else if (left_brother_key_num > 0 && right_brother_key_num > 0) { - if ((err = _leaf_merge_both(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_merge_both() returns 0x%x", err); - } - } - //如果right brother key num==0的话... - else if (left_brother_key_num > 0) { - if ((err = _leaf_merge_left(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_merge_left() returns 0x%x", err); - } - } - //相反...那么来进行右节点的合并.. - else if (right_brother_key_num > 0) { - if ((err = _leaf_merge_right(super_node, drill_info, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_leaf_merge_right() returns 0x%x", err); - } - } else { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "wrong condition"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } - } else { //节点超过半满或者是根节点,直接删除 - leaf_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - //还是需要重新分配一个节点... - if ((err = _acquire_leaf_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->del_subkey(*pnew_myself_node, myself_ins_pos)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->del_subkey() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter() returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "ins_obj_index=0x%lx, drill_info._drill_ptr=%d, mutate_result.get_update_type()=%d", - ins_obj_index, drill_info.get_drill_ptr(), mutate_result.get_update_type()); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, myself_ins_pos=%d", - myself_node_index, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "left_brother_key_num=%d, right_brother_key_num=%d", - left_brother_key_num, right_brother_key_num); - DF_WRITE_LOG_US(log_level, - "super_node.get_subkey_num()=0x%x", - super_node.get_subkey_num()); - } - - return err; -}; - - - - -//功能:增加或删除一个值导致上溢或下溢时,确定是与左或右兄弟平衡,还是独自分裂成为两个节点 -// left_brother_node_index不等于UNDEF_INDEX则与之平衡,right_brother_node_index不等于UNDEF_INDEX则与之平衡, -// 否则独自分裂成两节点 -int dfs_btree_t::_get_left_right_brothers_info( - uint32_t & left_brother_key_num, - uint32_t & right_brother_key_num, - const dfs_btree_drill_t & drill_info, - const int drill_ptr) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - uint64_t left_node_index = UNDEF_INDEX; - uint64_t right_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - const node_base_t * pleft_node = NULL; - const node_base_t * pright_node = NULL; - - left_brother_key_num = 0; //左边兄弟的项的个数 - right_brother_key_num = 0; //右边兄弟的项的个数 - - if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if (0 == drill_ptr) { - ; //没有父节点,则一定没有左右兄弟 - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else { - //存在左子树... - if (myself_in_father_pos > 0) { - //left brother: if there is a left brother - if ((left_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pfather_node->get_subnode_index(...-1) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - } else if ((err = _get_node(left_node_index, &pleft_node)) != 0 || NULL == pleft_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - //left brother key number... - left_brother_key_num = pleft_node->get_subkey_num(); - } - } - if ((myself_in_father_pos+1) <= pfather_node->get_subkey_num()) { - //right brother: if there is a right brother - if ((right_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pfather_node->get_subnode_index(...+1) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - } else if ((err = _get_node(right_node_index, &pright_node)) != 0 || NULL == pright_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - right_brother_key_num = pright_node->get_subkey_num(); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d", - drill_ptr, myself_in_father_pos); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_node_index=0x%lx, pleft_node=0x%p", - left_node_index, pleft_node); - DF_WRITE_LOG_US(log_level, - "right_node_index=0x%lx, pright_node=0x%p", - right_node_index, pright_node); - DF_WRITE_LOG_US(log_level, - "left_brother_key_num=%d, right_brother_key_num=%d", - left_brother_key_num, right_brother_key_num); - } - - return err; -}; - - -//功能:当一个节点因插入或删除项后,与其左边兄弟节点平衡,结果记录在mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_leaf_rebalance_left( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const leaf_node_t * pleft_brother_node = NULL; - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_NULL_POINTER); - } else if (myself_in_father_pos > pfather_node->get_subkey_num() || //插入位置不能超出父节点的subkey_num - myself_in_father_pos <= 0) { //there should be 1+ left brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos > pfather_node->get_subkey_num() || <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_leaf_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - //也是copy过去... - if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - //check point也必须使用原有节点而不是使用新节点... - //都是必须创建新的节点...... - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_left_node = NULL; - leaf_node_t * pnew_myself_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_myself_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_leaf_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_leaf_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_subkeys(key_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_subkeys() returns 0x%x", err); - } else if ((err = pnew_myself_node->put_subkeys(key_index_ary+ptr+1, subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_subkeys() returns 0x%x", err); - } - //从最上面加一次引用计数... - //写内容... - else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - //左转平衡... - mutate_result.set_rebalance_left_info( //key index... - key_index_ary[ptr], - new_left_node_index, - new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "left_brother_key_index=0x%lx", - left_brother_key_index); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -} - - - -//功能:本节点(因插入或删除子项后),与其左边兄弟节点平衡,结果记录在mutate_result -// updated_myself_node:插入或删除子项后的节点 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_rebalance_left( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t node_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const mid_node_t * pleft_brother_node = NULL; - uint32_t subkey_num = 0; - - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if (myself_in_father_pos > pfather_node->get_subkey_num() || //插入位置不能超出父节点的subkey_num - myself_in_father_pos <= 0) { //there should be 1+ left brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos > pfather_node->get_subkey_num() || <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_mid_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(left_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else if ((err = pleft_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - - if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_left_node = NULL; - mid_node_t * pnew_myself_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_myself_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - - if ((err = _acquire_mid_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_left_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_pairs(key_index_ary, node_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_pairs() returns 0x%x", err); - } else if ((err = pnew_myself_node->put_pairs(key_index_ary+ptr+1, - node_index_ary+ptr+1, - subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_rebalance_left_info( - key_index_ary[ptr], - new_left_node_index, - new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "left_brother_key_index=0x%lx", - left_brother_key_index); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "node_index_ary", node_index_ary, subkey_num+1); - } - - return err; -} - - - - -//功能:当一个节点因插入或删除项后,与其右边兄弟节点平衡,结果记录在mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_leaf_rebalance_right( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t right_brother_node_index = UNDEF_INDEX; - uint64_t myself_key_index = UNDEF_INDEX; - const leaf_node_t * pright_brother_node = NULL; - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_MID_NODE_NULL_POINTER); - } else if ((myself_in_father_pos+1) > pfather_node->get_subkey_num()) { //should be 1+ right brothe - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(myself_in_father_pos+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_leaf_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_myself_node = NULL; - leaf_node_t * pnew_right_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - uint64_t new_right_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_leaf_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_leaf_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_myself_node->put_subkeys(key_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_subkeys() returns 0x%x", err); - } else if ((err = pnew_right_node->put_subkeys( - key_index_ary+ptr+1, - subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - mutate_result.set_rebalance_right_info( - key_index_ary[ptr], - new_myself_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx", - myself_key_index); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -} - - -//功能:本节点(因插入或删除子项后),与其右边兄弟节点平衡,结果记录在mutate_result -// updated_myself_node:插入或删除子项后的节点 -//输入输入:mutate_result -//说明:若是因为删除导致,则此时myself的key_index可能需要替换 -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_rebalance_right( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t node_index_ary[(BT_FANOUT+1)*2]; - uint64_t myself_key_index = UNDEF_INDEX; - uint64_t right_brother_node_index = UNDEF_INDEX; - const mid_node_t * pright_brother_node = NULL; - uint32_t subkey_num = 0; - - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((myself_in_father_pos+1) > pfather_node->get_subkey_num()) { //should be 1+ right brothe - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(myself_in_father_pos+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } - - else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_mid_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(right_brother_node_index) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else if ((err = pright_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_right_node = NULL; - mid_node_t * pnew_myself_node = NULL; - uint64_t new_right_node_index = UNDEF_INDEX; - uint64_t new_myself_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_mid_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_myself_node->put_pairs(key_index_ary, node_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_pairs() returns 0x%x", err); - } else if ((err = pnew_right_node->put_pairs(key_index_ary+ptr+1, - node_index_ary+ptr+1, - subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_rebalance_right_info( - key_index_ary[ptr], - new_myself_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx", - myself_key_index); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "node_index_ary", node_index_ary, subkey_num+1); - } - - return err; -} - - -//功能:当一个节点因插入项后,进行分裂,结果记录在mutate_result -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_leaf_split( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint64_t key_index_ary[BT_FANOUT+2]; - - if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if (updated_myself_node.get_subkey_num() < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkey_num() < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - } - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_left_node = NULL; - leaf_node_t * pnew_right_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_right_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_leaf_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_left_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_leaf_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_subkeys(key_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_subkeys() returns 0x%x", err); - } else if ((err = pnew_right_node->put_subkeys(key_index_ary+ptr+1, subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { //???.. - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - //根据B树的顺序关系,当一个节点分裂成左右两个节点后,其新右节点代替原节点在父节点中位置, - //其新左节点将插入其在原父节点中位置的左侧。 - mutate_result.set_split_node_info( - key_index_ary[ptr], - new_left_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, subkey_num=%d", - drill_ptr, subkey_num); - DF_WRITE_LOG_US(log_level, - "updated_myself_node.get_subkey_num()=%d", - updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -} - - - - -//功能:本节点因插入子项后,进行分裂,结果记录在mutate_result -// updated_myself_node:插入子项后的节点 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_split( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & /*drill_info*/, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t subkey_num = 0; - uint64_t key_index_ary[BT_FANOUT+2]; - uint64_t node_index_ary[BT_FANOUT+2]; - - if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if (updated_myself_node.get_subkey_num() < (BT_HALF_FANOUT*2+1)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkey_num() < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - } - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_left_node = NULL; - mid_node_t * pnew_right_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_right_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_mid_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_left_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_mid_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_pairs(key_index_ary, node_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_pairs() returns 0x%x", err); - } else if ((err = pnew_right_node->put_pairs( - key_index_ary+ptr+1, - node_index_ary+ptr+1, - subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - //根据B树的顺序关系,当一个节点分裂成左右两个节点后,其新右节点代替原节点在父节点中位置, - //其新左节点将插入其在原父节点中位置的左侧。 - mutate_result.set_split_node_info( - key_index_ary[ptr], - new_left_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, subkey_num=%d", - drill_ptr, subkey_num); - DF_WRITE_LOG_US(log_level, - "updated_myself_node.get_subkey_num()=%d", - updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -} - - - -//功能:当一个节点因删除项下溢后,与其左边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//返回:0 for success, other values for failure -int dfs_btree_t::_leaf_merge_left( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const leaf_node_t * pleft_brother_node = NULL; - - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_in_father_pos > pfather_node->get_subkey_num() || //插入位置不能超出父节点的subkey_num - myself_in_father_pos <= 0) { //there should be 1+ left brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos > pfather_node->get_subkey_num() || <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_leaf_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - - if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - - if (subkey_num < BT_HALF_FANOUT) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < BT_HALF_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (BT_FANOUT-1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (BT_FANOUT-1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_leaf_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_myself_node->put_subkeys(key_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_merge_left_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "left_brother_key_index=0x%lx, updated_myself_node..get_subkey_num()=%d", - left_brother_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -}; - - - -//功能:当一个节点因删除项下溢后,与其左边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_merge_left( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t node_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const mid_node_t * pleft_brother_node = NULL; - uint32_t subkey_num = 0; - - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_in_father_pos > pfather_node->get_subkey_num() || //插入位置不能超出父节点的subkey_num - myself_in_father_pos <= 0) { //there should be 1+ left brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos > pfather_node->get_subkey_num() || <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_mid_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(left_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else if ((err = pleft_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - - if ((err = updated_myself_node.get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.get_subkeys() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num(); - - if (subkey_num < BT_HALF_FANOUT) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < BT_HALF_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (BT_FANOUT-1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (BT_FANOUT-1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node() returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_myself_node->put_pairs( - key_index_ary, - node_index_ary, - subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_myself_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_merge_left_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "left_brother_key_index=0x%lx, updated_myself_node..get_subkey_num()=%d", - left_brother_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "node_index_ary", node_index_ary, subkey_num+1); - } - - return err; -}; - - - -//功能:当一个节点因删除项下溢后,与其右边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//返回:0 for success, other values for failure -int dfs_btree_t::_leaf_merge_right( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t right_brother_node_index = UNDEF_INDEX; - uint64_t myself_key_index = UNDEF_INDEX; - const leaf_node_t * pright_brother_node = NULL; - - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((myself_in_father_pos+1) > pfather_node->get_subkey_num()) { //should be 1+ right brothe - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(myself_in_father_pos+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_leaf_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node(right_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < BT_HALF_FANOUT) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < BT_HALF_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (BT_FANOUT-1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (BT_FANOUT-1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_right_node = NULL; - uint64_t new_right_node_index = UNDEF_INDEX; - - if ((err = _acquire_leaf_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_right_node->put_subkeys(key_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - mutate_result.set_merge_right_info(new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx, updated_myself_node..get_subkey_num()=%d", - myself_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -}; - - - -//功能:当一个节点因删除项下溢后,与其右边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//输入:updated_myself_node:插入或删除后的本节点 -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_merge_right( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t node_index_ary[(BT_FANOUT+1)*2]; - uint64_t myself_key_index = UNDEF_INDEX; - uint64_t right_brother_node_index = UNDEF_INDEX; - const mid_node_t * pright_brother_node = NULL; - uint32_t subkey_num = 0; - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((myself_in_father_pos+1) > pfather_node->get_subkey_num()) { //should be 1+ right brothe - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(myself_in_father_pos+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_mid_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(right_brother_node_index...) returns 0x%x", err); - - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else if ((err = pright_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < BT_HALF_FANOUT) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < BT_HALF_FANOUT"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (BT_FANOUT-1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > (BT_FANOUT-1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_right_node = NULL; - uint64_t new_right_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_right_node->put_pairs( - key_index_ary, - node_index_ary, - subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - mutate_result.set_merge_right_info(new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx, updated_myself_node..get_subkey_num()=%d", - myself_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "node_index_ary", node_index_ary, subkey_num+1); - } - - return err; -}; - - - - -//功能:当一个节点因删除项下溢后,与其左右边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//返回:0 for success, other values for failure -//合并之后立刻分拆成为两个节点... -int dfs_btree_t::_leaf_merge_both( - const dfs_btree_leaf_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - const int drill_ptr = drill_info.get_drill_ptr(); - uint32_t subkey_num = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const leaf_node_t * pleft_brother_node = NULL; - uint64_t myself_key_index = UNDEF_INDEX; - uint64_t right_brother_node_index = UNDEF_INDEX; - const leaf_node_t * pright_brother_node = NULL; - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_in_father_pos <= 0 || (myself_in_father_pos+1) > pfather_node->get_subkey_num()) - //there should be 1+ left and 1+ right brother - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos <= 0 || (...+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_leaf_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node(left_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = _get_leaf_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node(right_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - - if ((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - leaf_node_t * pnew_left_node = NULL; - leaf_node_t * pnew_right_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_right_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_leaf_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_left_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_leaf_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_subkeys(key_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_subkeys() returns 0x%x", err); - } else if ((err = pnew_right_node->put_subkeys(key_index_ary+ptr+1, subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - mutate_result.set_merge_both_info( - key_index_ary[ptr], - new_left_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx, updated_myself_node.get_subkey_num()=%d", - myself_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - } - - return err; -}; - - - -//功能:当一个节点因删除项下溢后,与其左右边兄弟节点合并,结果记录在mutate_result -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_mid_merge_both( - const dfs_btree_mid_node_t & updated_myself_node, - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - uint32_t myself_in_father_pos = UNDEF_POS; - uint64_t father_node_index = UNDEF_INDEX; - const mid_node_t * pfather_node = NULL; - uint64_t key_index_ary[(BT_FANOUT+1)*2]; - uint64_t node_index_ary[(BT_FANOUT+1)*2]; - uint64_t left_brother_node_index = UNDEF_INDEX; - uint64_t left_brother_key_index = UNDEF_INDEX; - const mid_node_t * pleft_brother_node = NULL; - uint64_t myself_key_index = UNDEF_INDEX; - uint64_t right_brother_node_index = UNDEF_INDEX; - const mid_node_t * pright_brother_node = NULL; - uint32_t subkey_num = 0; - - if (drill_ptr <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_in_father_pos = drill_info.get_ins_pos(drill_ptr-1)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((father_node_index = drill_info.get_node_index(drill_ptr-1)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "father_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(father_node_index, &pfather_node)) != 0 || NULL == pfather_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(father_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_in_father_pos <= 0 || (myself_in_father_pos+1) > pfather_node->get_subkey_num()) - //there should be 1+ left and 1+ right brother - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_in_father_pos <= 0 || (...+1) > pfather_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((left_brother_key_index = pfather_node->get_subkey_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((left_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos-1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "left_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((myself_key_index = pfather_node->get_subkey_index(myself_in_father_pos)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_key_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_INDEX); - } else if ((right_brother_node_index = pfather_node->get_subnode_index(myself_in_father_pos+1)) - == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "right_brother_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - } else if ((err = _get_mid_node(left_brother_node_index, &pleft_brother_node)) != 0 - || NULL == pleft_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(left_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = _get_mid_node(right_brother_node_index, &pright_brother_node)) != 0 - || NULL == pright_brother_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(right_brother_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = pleft_brother_node->insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - pleft_brother_node->get_subkey_num(), - left_brother_key_index)) != 0) - //把left brother对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->insert_subkey() returns 0x%x", err); - } else if ((err = pleft_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleft_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pleft_brother_node->get_subkey_num() + 1; - - if ((err = updated_myself_node.insert_subkey( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num, - updated_myself_node.get_subkey_num(), - myself_key_index)) != 0) - //把myself对应的key_index插入到最后 - { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.insert_subkey() returns 0x%x", err); - } else if ((err = updated_myself_node.export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "updated_myself_node.export_subnode_index() returns 0x%x", err); - } else { - subkey_num += updated_myself_node.get_subkey_num() + 1; - - if ((err = pright_brother_node->get_subkeys( - key_index_ary+subkey_num, - df_len_of_ary(key_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->get_subkeys() returns 0x%x", err); - } else if ((err = pright_brother_node->export_subnode_index( - node_index_ary+subkey_num, - df_len_of_ary(node_index_ary)-subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pright_brother_node->export_subnode_index() returns 0x%x", err); - } else { - subkey_num += pright_brother_node->get_subkey_num(); - - if (subkey_num < (BT_HALF_FANOUT*2+1)) { - //下溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (BT_HALF_FANOUT*2+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else if (subkey_num > (2*(BT_FANOUT-1)+1)) { - //上溢 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num < (2*(BT_FANOUT-1)+1)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } - } - } - } - - if (0 == err) { //不论是否checkpointing都得使用新节点而不能直接修改原有节点 - mid_node_t * pnew_left_node = NULL; - mid_node_t * pnew_right_node = NULL; - uint64_t new_left_node_index = UNDEF_INDEX; - uint64_t new_right_node_index = UNDEF_INDEX; - uint32_t ptr = subkey_num/2; - - if ((err = _acquire_mid_node(new_left_node_index, &pnew_left_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_left_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_left_node_index || NULL == pnew_left_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = _acquire_mid_node(new_right_node_index, &pnew_right_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_right_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node) { - //leaf_node - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_right_node_index || NULL == pnew_right_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pnew_left_node->put_pairs(key_index_ary, node_index_ary, ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_left_node->put_pairs() returns 0x%x", err); - } else if ((err = pnew_right_node->put_pairs( - key_index_ary+ptr+1, - node_index_ary+ptr+1, - subkey_num-(ptr+1))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnew_right_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_left_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_left_node_index) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_right_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_right_node_index) returns 0x%x", err); - } else { - //根据B树的顺序关系,当一个节点分裂成左右两个节点后,其新右节点代替原节点在父节点中位置, - //其新左节点将插入其在原父节点中位置的左侧。 - mutate_result.set_merge_both_info( - key_index_ary[ptr], - new_left_node_index, - new_right_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_left_node_index=0x%lx, pnew_left_node=0x%p", - new_left_node_index, pnew_left_node); - DF_WRITE_LOG_US(log_level, - "new_right_node_index=0x%lx, pnew_right_node=0x%p", - new_right_node_index, pnew_right_node); - DF_WRITE_LOG_US(log_level, "ptr=%d", ptr); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_in_father_pos=%d, subkey_num=%d", - drill_ptr, myself_in_father_pos, subkey_num); - DF_WRITE_LOG_US(log_level, - "father_node_index=0x%lx, pfather_node=0x%p", - father_node_index, pfather_node); - DF_WRITE_LOG_US(log_level, - "left_brother_node_index=0x%lx, pleft_brother_node=0x%p", - left_brother_node_index, pleft_brother_node); - DF_WRITE_LOG_US(log_level, - "right_brother_node_index=0x%lx, pright_brother_node=0x%p", - right_brother_node_index, pright_brother_node); - DF_WRITE_LOG_US(log_level, - "myself_key_index=0x%lx, updated_myself_node.get_subkey_num()=%d", - myself_key_index, updated_myself_node.get_subkey_num()); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "node_index_ary", node_index_ary, subkey_num+1); - } - - return err; -}; - - - - -//功能:因子节点插入或删除导致了新节点(没有分裂或左右平衡)而对本节点更新 -//输入输入:mutate_result -//说明:若是因为删除导致,则此时myself的key_index可能需要替换 -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_update( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_subnode_index = UNDEF_INDEX; - uint64_t old_subnode_index = UNDEF_INDEX; - uint64_t new_subnode_ref_counter = UNDEF_REF_COUNTER; - uint64_t old_subnode_ref_counter = UNDEF_REF_COUNTER; - uint64_t myself_node_index = UNDEF_INDEX; - mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - - if ((err = mutate_result.get_update_node_info(new_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_update_node_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node_for_mutate(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node_for_mutate(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } - //如果修改的节点在要删除的节点之上,就可以直接修改 - //可以直接进行修改... - else if (pmyself_node->get_mutation_counter() > _bt_get_max_cow_mutation_counter() - && drill_ptr < drill_info.get_del_mid_drill_ptr()) { - //直接修改 - if ((err = pmyself_node->update_subnode( - myself_ins_pos, - new_subnode_index, - old_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_subnode() returns 0x%x", err); - } - //增加... - else if ((err = _inc_node_ref_counter(new_subnode_index, new_subnode_ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_node_ref_counter(new_subnode_index) returns 0x%x", err); - } else if ((err = _dec_node_ref_counter(old_subnode_index, old_subnode_ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_node_ref_counter(old_subnode_index) returns 0x%x", err); - } else { - //设置0... - mutate_result.set_mutate_nothing(); - err = 0; - } - } else { - //copy-on-write - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_subnode(*pnew_myself_node, - myself_ins_pos, - new_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_subnode() returns 0x%x", err); - } - //增加这个index...的引用计数... - else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_subnode_index=0x%lx, old_subnode_index=0x%lx", - new_subnode_index, old_subnode_index); - DF_WRITE_LOG_US(log_level, - "new_subnode_ref_counter=%ld, old_subnode_ref_counter=%ld", - new_subnode_ref_counter, old_subnode_ref_counter); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -} - - -//功能:子节点因插入或删除项而与左兄弟平衡后,更新本节点。 -//输入输入:mutate_result -//说明:若是因为删除导致,则此时myself的key_index可能需要替换 -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_rebalance_left( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_left_subkey_index = UNDEF_INDEX; - uint64_t new_left_subnode_index = UNDEF_INDEX; - uint64_t new_myself_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - - if ((err = mutate_result.get_rebalance_left_info( - new_left_subkey_index, - new_left_subnode_index, - new_myself_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_rebalance_left_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - //不能用原子操作一次更新,必须copy-on-write - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX;; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_brothers(*pnew_myself_node, - myself_ins_pos-1, - new_left_subkey_index, - new_left_subnode_index, - new_myself_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_brothers(...) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_left_subkey_index=0x%lx, new_left_subnode_index=0x%lx", - new_left_subkey_index, new_left_subnode_index); - DF_WRITE_LOG_US(log_level, - "new_myself_subnode_index=0x%lx", - new_myself_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -} - - - -//功能:子节点因插入或删除项而与右兄弟平衡后,更新本节点。 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_rebalance_right( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_myself_subkey_index = UNDEF_INDEX; - uint64_t new_myself_subnode_index = UNDEF_INDEX; - uint64_t new_right_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = mutate_result.get_rebalance_right_info( - new_myself_subkey_index, - new_myself_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_rebalance_right_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node_for_mutate(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - //不能用原子操作一次更新,必须copy-on-write - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_brothers( - *pnew_myself_node, - myself_ins_pos, - new_myself_subkey_index, - new_myself_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_brothers(...) returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_myself_subkey_index=0x%lx, new_myself_subnode_index=0x%lx", - new_myself_subkey_index, new_myself_subnode_index); - DF_WRITE_LOG_US(log_level, - "new_right_subnode_index=0x%lx", - new_right_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -} - - - -//功能:因子节点插入导致分裂而对本节点更新 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_split( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_left_subkey_index = UNDEF_INDEX; - uint64_t new_left_subnode_index = UNDEF_INDEX; - uint64_t new_right_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = mutate_result.get_split_node_info( - new_left_subkey_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_split_node_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - // 根据B树的顺序关系,当一个节点分裂成左右两个节点后,其新右节点代替原节点在父节点中位置, - // 其新左节点将插入其在原父节点中位置的左侧。 - if (pmyself_node->is_full()) { //节点满,需要与左兄弟或右兄弟平衡或分裂 - uint32_t left_brother_key_num = 0; - uint32_t right_brother_key_num = 0; - dfs_btree_mid_node_t super_node; - //类似于 - if ((err = pmyself_node->update_then_ins_to_left( - super_node, - myself_ins_pos, - new_left_subkey_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_ins_to_left() returns 0x%x", err); - } else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } else if (left_brother_key_num > 0 && left_brother_key_num < (BT_FANOUT-1) && - (left_brother_key_num <= right_brother_key_num || 0 == right_brother_key_num)) { - if ((err = _mid_rebalance_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > 0 && right_brother_key_num < (BT_FANOUT-1)) { - if ((err = _mid_rebalance_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_right() returns 0x%x", err); - } - } else { - if ((err = _mid_split(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_split() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "left_brother_key_num=%d, right_brother_key_num=%d", - left_brother_key_num, right_brother_key_num); - } - } else { //节点未满,直接插入 - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_then_ins_to_left( - *pnew_myself_node, - myself_ins_pos, - new_left_subkey_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_ins_to_left() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_left_subkey_index=0x%lx, new_left_subnode_index=0x%lx", - new_left_subkey_index, new_left_subnode_index); - DF_WRITE_LOG_US(log_level, - "new_right_subnode_index=0x%lx", - new_right_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -} - - - - -//功能:因子节点与左兄弟合并而对本节点更新 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_merge_left( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_myself_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = mutate_result.get_merge_left_info(new_myself_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_merge_left_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_ins_pos <= 0 || myself_ins_pos > pmyself_node->get_subkey_num()) { - //at least one left brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos <= 0 || ... > pmyself_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } - //不能用原子操作一次更新,必须copy-on-write - else if (pmyself_node->get_subkey_num() <= BT_HALF_FANOUT && drill_ptr > 0) { //节点下溢,需要与左兄弟或右兄弟平衡或合并 - uint32_t left_brother_key_num = 0; - uint32_t right_brother_key_num = 0; - dfs_btree_mid_node_t super_node; - - if ((err = pmyself_node->update_then_del_left( - super_node, - myself_ins_pos, - new_myself_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_del_left() returns 0x%x", err); - } else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } else if (left_brother_key_num > BT_HALF_FANOUT && - left_brother_key_num >= right_brother_key_num) { - if ((err = _mid_rebalance_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > BT_HALF_FANOUT) { - if ((err = _mid_rebalance_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_right() returns 0x%x", err); - } - } else if (left_brother_key_num > 0) { - if (right_brother_key_num > 0) { - if ((err = _mid_merge_both(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_both() returns 0x%x", err); - } - } else { - if ((err = _mid_merge_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_left() returns 0x%x", err); - } - } - } else if (right_brother_key_num > 0) { - if ((err = _mid_merge_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_right() returns 0x%x", err); - } - } else { - //both left_brother_key_num and right_brother_key_num <= 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "both left_brother_key_num and right_brother_key_num <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "left_brother_key_num=%d, right_brother_key_num=%d", - left_brother_key_num, right_brother_key_num); - } - } else if (pmyself_node->get_subkey_num() > 1) { //节点未下溢或者是根节点且subkey_num>1,直接删除 - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_then_del_left( - *pnew_myself_node, - myself_ins_pos, - new_myself_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_del_left() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index...) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } else { //根节点且subkey_num == 1 - mutate_result.set_update_node_info(new_myself_subnode_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_myself_subnode_index=0x%lx", - new_myself_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -}; - - - -//功能:因子节点与右兄弟合并而对本节点更新 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_merge_right( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_right_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = mutate_result.get_merge_right_info(new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_merge_right_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((myself_ins_pos+1) > pmyself_node->get_subkey_num()) { - //at least one right brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(myself_ins_pos+1) > pmyself_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } - //不能用原子操作一次更新,必须copy-on-write - else if (pmyself_node->get_subkey_num() <= BT_HALF_FANOUT && drill_ptr > 0) { //节点下溢,需要与左兄弟或右兄弟平衡或合并 - uint32_t left_brother_key_num = 0; - uint32_t right_brother_key_num = 0; - dfs_btree_mid_node_t super_node; - - if ((err = pmyself_node->update_then_del_left( - super_node, - myself_ins_pos+1, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_del_left() returns 0x%x", err); - } else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } else if (left_brother_key_num > BT_HALF_FANOUT && - left_brother_key_num >= right_brother_key_num) { - if ((err = _mid_rebalance_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > BT_HALF_FANOUT) { - if ((err = _mid_rebalance_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_right() returns 0x%x", err); - } - } else if (left_brother_key_num > 0) { - if (right_brother_key_num > 0) { - if ((err = _mid_merge_both(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_both() returns 0x%x", err); - } - } else { - if ((err = _mid_merge_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_left() returns 0x%x", err); - } - } - } else if (right_brother_key_num > 0) { - if ((err = _mid_merge_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_right() returns 0x%x", err); - } - } else { - //both left_brother_key_num and right_brother_key_num <= 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "both left_brother_key_num and right_brother_key_num <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } - } else if (pmyself_node->get_subkey_num() > 1) { //节点未下溢或者是根节点且subkey_num>1,直接删除 - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_then_del_left( - *pnew_myself_node, - myself_ins_pos+1, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_del_left() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index...) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } else { //根节点且subkey_num == 1 - mutate_result.set_update_node_info(new_right_subnode_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_right_subnode_index=0x%lx", - new_right_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -}; - - - -//功能:因子节点与左右兄弟合并而对本节点更新 -//输入输入:mutate_result -//返回:0 for success, other values for failure -int dfs_btree_t::_op_mid_node_of_sub_merge_both( - const dfs_btree_drill_t & drill_info, - const int drill_ptr, - dfs_btree_node_mutate_t & mutate_result) { - uint64_t new_left_key_index = UNDEF_INDEX; - uint64_t new_left_subnode_index = UNDEF_INDEX; - uint64_t new_right_subnode_index = UNDEF_INDEX; - uint64_t myself_node_index = UNDEF_INDEX; - const mid_node_t * pmyself_node = NULL; - uint32_t myself_ins_pos = UNDEF_POS; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = mutate_result.get_merge_both_info( - new_left_key_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mutate_result.get_merge_both_info() returns 0x%x", err); - } else if (drill_ptr < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_ptr < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else if ((myself_ins_pos = drill_info.get_ins_pos(drill_ptr)) == UNDEF_POS) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos == UNDEF_POS"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } else if ((myself_node_index = drill_info.get_node_index(drill_ptr)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_node_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_NODE_INDEX); - } else if ((err = _get_mid_node(myself_node_index, &pmyself_node)) != 0 - || NULL == pmyself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(myself_node_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (myself_ins_pos <= 0 || (myself_ins_pos+1) > pmyself_node->get_subkey_num()) { - //at least one left brother and one right brother - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "myself_ins_pos <= 0 || (...+1) > pmyself_node->get_subkey_num()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_INS_POS); - } - //不能用原子操作一次更新,必须copy-on-write - else if (pmyself_node->get_subkey_num() <= BT_HALF_FANOUT && drill_ptr > 0) { //节点下溢,需要与左兄弟或右兄弟平衡或合并 - uint32_t left_brother_key_num = 0; - uint32_t right_brother_key_num = 0; - dfs_btree_mid_node_t super_node; - - if ((err = pmyself_node->update_both_sides_then_del_mid( - super_node, - myself_ins_pos, - new_left_key_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_both_sides_then_del_mid() returns 0x%x", err); - } else if ((err = _get_left_right_brothers_info( - left_brother_key_num, - right_brother_key_num, - drill_info, - drill_ptr)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_left_right_brothers_info() returns 0x%x", err); - } else if (left_brother_key_num > BT_HALF_FANOUT && - left_brother_key_num >= right_brother_key_num) { - if ((err = _mid_rebalance_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_left() returns 0x%x", err); - } - } else if (right_brother_key_num > BT_HALF_FANOUT) { - if ((err = _mid_rebalance_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_rebalance_right() returns 0x%x", err); - } - } else if (left_brother_key_num > 0) { - if (right_brother_key_num > 0) { - if ((err = _mid_merge_both(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_both() returns 0x%x", err); - } - } else { - if ((err = _mid_merge_left(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_left() returns 0x%x", err); - } - } - } else if (right_brother_key_num > 0) { - if ((err = _mid_merge_right(super_node, drill_info, drill_ptr, mutate_result)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_mid_merge_right() returns 0x%x", err); - } - } else { - //both left_brother_key_num and right_brother_key_num <= 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "both left_brother_key_num and right_brother_key_num <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "left_brother_key_num=%d, right_brother_key_num=%d", - left_brother_key_num, right_brother_key_num); - } - } else { //节点未下溢,直接删除 - mid_node_t * pnew_myself_node = NULL; - uint64_t new_myself_node_index = UNDEF_INDEX; - - if ((err = _acquire_mid_node(new_myself_node_index, &pnew_myself_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(new_myself_node_index...) returns 0x%x", err); - } else if (UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == new_myself_node_index || NULL == pnew_myself_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmyself_node->update_both_sides_then_del_mid( - *pnew_myself_node, - myself_ins_pos, - new_left_key_index, - new_left_subnode_index, - new_right_subnode_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmyself_node->update_then_del_left() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(new_myself_node_index)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(new_myself_node_index) returns 0x%x", err); - } else { - mutate_result.set_update_node_info(new_myself_node_index); - err = 0; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_myself_node_index=0x%lx, pnew_myself_node=0x%p", - new_myself_node_index, pnew_myself_node); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "drill_ptr=%d, myself_ins_pos=%d", - drill_ptr, myself_ins_pos); - DF_WRITE_LOG_US(log_level, - "myself_node_index=0x%lx, pmyself_node=0x%p", - myself_node_index, pmyself_node); - DF_WRITE_LOG_US(log_level, - "new_left_key_index=0x%lx, new_left_subnode_index=0x%lx", - new_left_key_index, new_left_subnode_index); - DF_WRITE_LOG_US(log_level, - "new_right_subnode_index=0x%lx", - new_right_subnode_index); - DF_WRITE_LOG_US(log_level, - "mutate_result.get_update_type()=%d", - mutate_result.get_update_type()); - } - - return err; -}; - - -//按照index来检索... -int dfs_btree_t::_search_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t i_obj_index, - dfs_btree_drill_t & drill_info, - uint64_t & o_obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - uint64_t ref_counter = UNDEF_REF_COUNTER; - uint64_t tag_obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //此处不能初始化:为了避免src_index与obj_index其实是同一变量,搜索的目的是为了获得drill_info - //obj_index = UNDEF_INDEX; - drill_info.init(); - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node_ref_counter(sbt_root.get_root_node_index(), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 0 || UNDEF_REF_COUNTER == ref_counter) { //检查一下refer count... - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = _search_subtree_by_index( - bt_root, - sbt_root.get_root_node_index(), - i_obj_index, - drill_info, - tag_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_subtree() returns 0x%x", err); - } else if (drill_info.get_drill_ptr() < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_drill_ptr() < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } else { - //检索到的tag给o.. - o_obj_index = tag_obj_index; - } - //mutation_counter is used to check the validness of the drill_info, - //mutation counter来保证drill info和sbt_root一致... - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "i_obj_index=0x%lx, ref_counter=%ld, drill_ptr=%d", - i_obj_index, ref_counter, drill_info.get_drill_ptr()); - } - - return err; -}; -int dfs_btree_t::_search_by_obj( - const dfs_bt_root_t & bt_root, - const void * pobj, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - drill_info.init(); - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node_ref_counter(sbt_root.get_root_node_index(), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 0 || UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = _search_subtree_by_obj( - bt_root, - sbt_root.get_root_node_index(), - pobj, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_subtree() returns 0x%x", err); - } else if (drill_info.get_drill_ptr() < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_drill_ptr() < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } - //mutation_counter is used to check the validness of the drill_info, - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "pobj=0x%p, ref_counter=%ld, drill_ptr=%d", - pobj, ref_counter, drill_info.get_drill_ptr()); - } - - return err; -}; -int dfs_btree_t::_search_by_key( - const dfs_bt_root_t & bt_root, - const void * pkey, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - drill_info.init(); - - if (sbt_root.get_root_node_index() == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "sbt_root.get_root_node_index() == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node_ref_counter(sbt_root.get_root_node_index(), ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node_ref_counter() returns 0x%x", err); - } else if (ref_counter <= 0 || UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_REF_COUNTER); - } else if ((err = _search_subtree_by_key( - bt_root, - sbt_root.get_root_node_index(), - pkey, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_subtree() returns 0x%x", err); - } else if (drill_info.get_drill_ptr() < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "drill_info.get_drill_ptr() < 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DRILL_POS); - } - //mutation_counter is used to check the validness of the drill_info, - drill_info.set_btree_mutation_counter(sbt_root.get_mutation_counter()); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "pkey=0x%lx, ref_counter=%ld, drill_ptr=%d", - (uint64_t)pkey, ref_counter, drill_info.get_drill_ptr()); - } - - return err; -}; - - - -// 功能:搜索某个子树,结果追加到drill_info中 -// 如果该元素存在,则drill_info中信息指向它,否则指向它插入后的位置。 -// return: 0 for success, other values for error -int dfs_btree_t::_search_subtree_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const uint64_t src_index, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - uint64_t cur_subtree_root = subtree_root; - const mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - while (UNDEF_INDEX == obj_index) { - //搜索结构自动追加到drill_info - if ((err = _search_node_by_index( - bt_root, - cur_subtree_root, - src_index, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_node() returns 0x%x", err); - break; - } else if (UNDEF_INDEX == obj_index && _is_mid_node(cur_subtree_root)) { - //not found & is_mid_node - if ((err = _get_mid_node(cur_subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } - //需要在这个sub index下面继续find... - else if ((cur_subtree_root = - pmid_node->get_subnode_index(drill_info.get_last_ins_pos())) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subnode_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "last_ins_pos=%d; get_subkey_num()=%d", - drill_info.get_last_ins_pos(), pmid_node->get_subkey_num()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - break; - } - } else { //叶子节点或者是found... - //found or leaf node - break; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "src_index=0x%lx, subtree_root=0x%lx, drill_ptr=%d", - src_index, subtree_root, drill_info.get_drill_ptr()); - } - - return err; -}; -int dfs_btree_t::_search_subtree_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const void * pobj, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - uint64_t cur_subtree_root = subtree_root; - const mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - while (UNDEF_INDEX == obj_index) { - //搜索结构自动追加到drill_info - if ((err = _search_node_by_obj(bt_root, cur_subtree_root, pobj, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_node() returns 0x%x", err); - break; - } else if (UNDEF_INDEX == obj_index && _is_mid_node(cur_subtree_root)) { - //not found & is_mid_node - if ((err = _get_mid_node(cur_subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } else if ((cur_subtree_root = - pmid_node->get_subnode_index(drill_info.get_last_ins_pos())) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subnode_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "last_ins_pos=%d; get_subkey_num()=%d", - drill_info.get_last_ins_pos(), pmid_node->get_subkey_num()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - break; - } - } else { - //found or leaf node - break; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "pobj=0x%p, subtree_root=0x%lx", - pobj, subtree_root); - DF_WRITE_LOG_US(log_level, - "cur_subtree_root=0x%lx, drill_ptr=%d", - cur_subtree_root, drill_info.get_drill_ptr()); - } - - return err; -}; -int dfs_btree_t::_search_subtree_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t subtree_root, - const void * pkey, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - uint64_t cur_subtree_root = subtree_root; - const mid_node_t * pmid_node = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - while (UNDEF_INDEX == obj_index) { - //搜索结构自动追加到drill_info - if ((err = _search_node_by_key(bt_root, cur_subtree_root, pkey, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_node() returns 0x%x", err); - break; - } else if (UNDEF_INDEX == obj_index && _is_mid_node(cur_subtree_root)) { - //not found & is_mid_node - if ((err = _get_mid_node(cur_subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - break; - } else if ((cur_subtree_root = - pmid_node->get_subnode_index(drill_info.get_last_ins_pos())) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subnode_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, - "last_ins_pos=%d; get_subkey_num()=%d", - drill_info.get_last_ins_pos(), pmid_node->get_subkey_num()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_INDEX); - break; - } - } else { - //found or leaf node - break; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, pkey=0x%p", - subtree_root, pkey); - DF_WRITE_LOG_US(log_level, - "cur_subtree_root=0x%lx, drill_ptr=%d", - cur_subtree_root, drill_info.get_drill_ptr()); - } - - return err; -}; - - - -//搜索B树的一个节点,结果加入到drill_info中 -//return: 0 for success, other values for error -int dfs_btree_t::_search_node_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, - const uint64_t src_index, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const node_base_t * pnode = NULL; - int32_t ins_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - if ((err = _get_node(node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = vir_search_ary_by_index( - bt_root, - pnode->get_subkey_ary(), - pnode->get_subkey_num(), - src_index, - ins_pos, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_search_ary_by_index() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "subkey_num=%d", pnode->get_subkey_num()); - } else { - drill_info.push(ins_pos, node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, src_index=0x%lx", - node_index, src_index); - DF_WRITE_LOG_US(log_level, - "ins_pos=%d, pnode=0x%p", - ins_pos, pnode); - } - - return err; -}; -int dfs_btree_t::_search_node_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, - const void * pobj, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const node_base_t * pnode = NULL; - int32_t ins_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - if ((err = _get_node(node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = vir_search_ary_by_obj( - bt_root, - pnode->get_subkey_ary(), - pnode->get_subkey_num(), - pobj, - ins_pos, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_search_ary_by_key() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "subkey_num=%d", pnode->get_subkey_num()); - } else { - drill_info.push(ins_pos, node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, pobj=0x%p", - node_index, pobj); - DF_WRITE_LOG_US(log_level, - "ins_pos=%d, pnode=0x%p", - ins_pos, pnode); - } - - return err; -}; -int dfs_btree_t::_search_node_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t node_index, - const void * pkey, //may not in the tree - dfs_btree_drill_t & drill_info, - uint64_t & obj_index) const { - const node_base_t * pnode = NULL; - int32_t ins_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - if ((err = _get_node(node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if ((err = vir_search_ary_by_key( - bt_root, - pnode->get_subkey_ary(), - pnode->get_subkey_num(), - pkey, - ins_pos, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_search_ary_by_key() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "subkey_num=%d", pnode->get_subkey_num()); - } else { - drill_info.push(ins_pos, node_index); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, pkey=0x%p", - node_index, pkey); - DF_WRITE_LOG_US(log_level, - "ins_pos=%d, pnode=0x%p", - ins_pos, pnode); - } - - return err; -}; - - - -//功能:验证某个子树的顺序和每个节点分支个数 -//输入:subtree_root:子树根节点 -// left_brother_key_index:子树的左兄弟,如果不等于UNDEF_INDEX,则<=子树的所有项 -// right_brother_key_index:子树的右兄弟,如果不等于UNDEF_INDEX,则>=子树的所有项 -//返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 -int dfs_btree_t::_verify_subtree( - const dfs_bt_root_t & bt_root, - const uint64_t /*father_mutation_counter*/, - const uint64_t subtree_root, - const uint64_t left_brother_key_index, - const uint64_t right_brother_key_index) const { - uint64_t key_index_ary[BT_FANOUT+2]; - const node_base_t * pnode = NULL; - uint64_t mutation_counter = 0; - bool is_inc_order = false; - uint32_t j = 0; - uint32_t j1 = (UNDEF_INDEX != left_brother_key_index) ? 0 : 1; - uint32_t j2 = (UNDEF_INDEX != right_brother_key_index) ? 0 : 1; - uint32_t n = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_node(subtree_root, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (pnode->get_subkey_num() > (BT_FANOUT-1)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_num() > (BT_FANOUT-1)"); - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_num()=%d", pnode->get_subkey_num()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_OVERFLOW); - } else if (pnode->get_subkey_num() < (BT_FANOUT-1)/2 && - (UNDEF_INDEX != left_brother_key_index || UNDEF_INDEX != right_brother_key_index)) { - //none-root node should owns at least this number of keys. - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_num() < (BT_FANOUT-1)/2 && ..."); - DF_WRITE_LOG_US(log_level, "pnode->get_subkey_num()=%d", pnode->get_subkey_num()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_UNDERFLOW); - } else { - j = 0; - key_index_ary[j++] = left_brother_key_index; - if ((err = pnode->get_subkeys(key_index_ary+j, df_len_of_ary(key_index_ary)-j)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pnode->get_subkeys() returns 0x%x", err); - } else { - j += pnode->get_subkey_num(); - key_index_ary[j++] = right_brother_key_index; - j2 = j - j2; - } - mutation_counter = pnode->get_mutation_counter(); - if (0 == err) { - if ((err = vir_verify_index_ary( - bt_root, - key_index_ary+j1, - j2-j1, - is_inc_order)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_verify_index_ary() returns 0x%x", err); - } - //同时判断是否为升序... - else if (!is_inc_order) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "!is_from_s_to_l"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_ORDER); - } - } - if (0 == err && _is_mid_node(subtree_root)) { - const mid_node_t * pmid_node = NULL; - uint64_t subnode_index = UNDEF_INDEX; - - if ((err = _get_mid_node(subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(subtree_root...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - n = pnode->get_subkey_num()+1; - for (j = 0; j < n; ++j) { - if ((subnode_index = pmid_node->get_subnode_index(j)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subnode_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - break; - } else if (_is_leaf_node(pmid_node->get_subnode_index(0)) && - !_is_leaf_node(subnode_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_is_leaf_node(subnode_index[0]) && !_is_leaf_node(subnode_index)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_HETEROGENEOUS_MID_NODE); - break; - } else if (_is_mid_node(pmid_node->get_subnode_index(0)) && - !_is_mid_node(subnode_index)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_is_mid_node(subnode_index[0]) && !_is_mid_node(subnode_index)"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_HETEROGENEOUS_MID_NODE); - break; - } else if ((err = _verify_subtree( - bt_root, - mutation_counter, - subnode_index, - key_index_ary[j], - key_index_ary[j+1])) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_verify_subtree() returns 0x%x", err); - break; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subnode_index=0x%lx, pmid_node=0x%p", - subnode_index, pmid_node); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, left_brother_key_index=0x%lx, right_brother_key_index=0x%lx", - subtree_root, left_brother_key_index, right_brother_key_index); - DF_WRITE_LOG_US(log_level, - "pnode=0x%lx, father_mutation_counter=%lu, mutation_counter=%lu", - (uint64_t)pnode, father_mutation_counter, mutation_counter); - DF_WRITE_LOG_US(log_level, - "is_inc_order=%d, j=%d, j1=%d, j2=%d, n=%d", - is_inc_order, j, j1, j2, n); - BT_DF_WRITE_LOG_INT64S(log_level, "key_index_ary", key_index_ary, df_len_of_ary(key_index_ary)); - } - - return err; -}; - -// 功能:验证整个树的顺序和每个节点分支个数 -// 返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 -int dfs_btree_t::bt_verify_tree(const dfs_bt_root_t & bt_root) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _verify_subtree( - bt_root, - sbt_root.get_mutation_counter(), - sbt_root.get_root_node_index(), - UNDEF_INDEX, - UNDEF_INDEX)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_verify_subtree() returns 0x%x", err); - } - //else if ((err = _set_max_verified_mutaiont_counter(sbt_root.get_mutation_counter())) != 0) - //{ - // log_level = DF_UL_LOG_FATAL; - // DF_WRITE_LOG_US(log_level, "_set_max_verified_mutaiont_counter() returns 0x%x", err); - //} - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), - sbt_root.get_mutation_counter()); - } - - return err; -}; - -//Return: 0 for success, other values for error -int dfs_btree_t::_get_subtree_total_num( - const uint64_t subtree_root, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const { - const leaf_node_t * pleaf_node = NULL; - const mid_node_t * pmid_node = NULL; - uint64_t subnode_index = UNDEF_INDEX; - uint32_t n = 0; - uint32_t j = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_is_mid_node(subtree_root)) { - if ((err = _get_mid_node(subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node(subtree_root...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - total_key_num += pmid_node->get_subkey_num(); - n = pmid_node->get_subkey_num()+1; - for (j = 0; j < n; ++j) { - if ((subnode_index = pmid_node->get_subnode_index(j)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subnode_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - break; - } else if ((err = _get_subtree_total_num( - subnode_index, - total_key_num, - total_leaf_node_num, - total_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_total_num() returns 0x%x", err); - break; - } - } - } - ++total_mid_node_num; - } else { //leaf node - if ((err = _get_leaf_node(subtree_root, &pleaf_node)) != 0 || NULL == pleaf_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_leaf_node(subtree_root...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - total_key_num += pleaf_node->get_subkey_num(); - } - ++total_leaf_node_num; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, subnode_index=0x%lx", - subtree_root, subnode_index); - DF_WRITE_LOG_US(log_level, - "total_key_num=%ld, total_leaf_node_num=%ld, total_mid_node_num=%ld", - total_key_num, total_leaf_node_num, total_mid_node_num); - DF_WRITE_LOG_US(log_level, - "pleaf_node=0x%p, pleaf_node=0x%p", - pleaf_node, pleaf_node); - DF_WRITE_LOG_US(log_level, - "j=%d, n=%d", - j, n); - } - - return err; -}; - - -int dfs_btree_t::bt_get_total_num( - const dfs_bt_root_t & bt_root, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - total_key_num = 0; - total_leaf_node_num = 0; - total_mid_node_num = 0; - - if (UNDEF_INDEX == sbt_root.get_root_node_index()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == sbt_root.get_root_node_index()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_subtree_total_num( - sbt_root.get_root_node_index(), - total_key_num, - total_leaf_node_num, - total_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_subtree_total_num() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "total_key_num=%ld, total_leaf_node_num=%ld, total_mid_node_num=%ld", - total_key_num, total_leaf_node_num, total_mid_node_num); - } - - return err; -}; - -int dfs_btree_t::bt_get_in_use_node_num_in_2d_ary( - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err1 = leaf_ary_t::get_in_use_num(in_use_leaf_node_num)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "leaf_ary_t::get_in_use_num() returns 0x%x", err); - } - if ((err1 = mid_ary_t::get_in_use_num(in_use_mid_node_num)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "mid_ary_t::get_in_use_num() returns 0x%x", err); - } - - return err; -}; - -// //should be called in locked state -//int dfs_btree_t::_bt_set_ckp_state(const uint32_t ckp_state) -//{ -// uint64_t ckp_root_index = UNDEF_INDEX; -// uint64_t ckp_mutation_counter = 0; -// dfs_bt_root_t bt_root; -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// int err1 = 0; -// -// ckp_root_index = _ckp_sbt_root.get_root_node_index(); -// ckp_mutation_counter = _ckp_sbt_root.get_mutation_counter(); -// switch ((_ckp_state<<4) | (ckp_state & 0xf)) -// { -// case ((BT_CKP_STATE_OFF<<4)|BT_CKP_STATE_OFF ) : -// //do nothing -// break; -// case ((BT_CKP_STATE_OFF<<4)|BT_CKP_STATE_ON ) : -// //_inc_mutation_counter(); -// if (UNDEF_INDEX != ckp_root_index || ckp_mutation_counter > 0) -// { -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_CKP_ROOT); -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, ERRINFO_BT_CKP_ROOT); -// } -// //串行读写时候禁止设置checkpoint -// else if (_get_serial_read_write_state()) -// { -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_CKP_SERIAL_READ_WRITE); -// log_level = DF_UL_LOG_NOTICE; -// DF_WRITE_LOG_US(log_level, ERRINFO_BT_CKP_SERIAL_READ_WRITE); -// } -// //cow ==> copy-on-write -// else if ((err = _bt_set_ckp_root()) != 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_bt_set_ckp_root() returns 0x%x", err); -// } -// else -// { -// df_atomic_exchange(&_ckp_state, ckp_state); -// }; -// break; -// case ((BT_CKP_STATE_OFF<<4 )|BT_CKP_STATE_LOADING ) : -// //_inc_mutation_counter(); -// df_atomic_exchange(&_ckp_state, ckp_state); -// break; -// case ((BT_CKP_STATE_ON <<4)|BT_CKP_STATE_STORING ) : -// // ckp_set => storing -// //_inc_mutation_counter(); -// df_atomic_exchange(&_ckp_state, ckp_state); -// break; -// case ((BT_CKP_STATE_ON <<4)|BT_CKP_STATE_OFF ) : -// if (UNDEF_INDEX == ckp_root_index || ckp_mutation_counter <= 0) -// { -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_CKP_ROOT); -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, ERRINFO_BT_CKP_ROOT); -// } -// else if ((err = _bt_xchg_ckp_root(bt_root)) = 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_bt_xchg_ckp_root() returns 0x%x", err); -// } -// //cow ==> copy-on-write -// else if ((err = _bt_remove_cow(bt_root)) != 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_bt_remove_cow() returns 0x%x", err); -// } -// else -// { -// df_atomic_exchange(&_ckp_state, ckp_state); -// }; -// break; -// case ((BT_CKP_STATE_STORING<<4)|BT_CKP_STATE_OFF ) : -// df_atomic_exchange(&_ckp_state, ckp_state); -// break; -// case ((BT_CKP_STATE_LOADING <<4)|BT_CKP_STATE_OFF ) : -// //取消loading时设置_ckp_mutation_counter为0 -// df_atomic_exchange(&_ckp_state, ckp_state); -// break; -// case ((BT_CKP_STATE_ON <<4)|BT_CKP_STATE_ON ) : -// case ((BT_CKP_STATE_ON <<4)|BT_CKP_STATE_LOADING ) : -// case ((BT_CKP_STATE_STORING <<4)|BT_CKP_STATE_ON ) : -// case ((BT_CKP_STATE_LOADING <<4)|BT_CKP_STATE_ON ) : -// //先取消,再设置ckp -// if ((err1 = _bt_set_ckp_state(BT_CKP_STATE_OFF)) != 0) -// { -// err = err1; -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_bt_set_ckp_state(BT_CKP_STATE_OFF) returns 0x%x", err); -// } -// if ((err1 = _bt_set_ckp_state(ckp_state)) != 0) -// { -// err = err1; -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_bt_set_ckp_state(ckp_state) returns 0x%x", err); -// } -// break; -// case ((BT_CKP_STATE_STORING <<4)|BT_CKP_STATE_STORING ) : -// case ((BT_CKP_STATE_STORING <<4)|BT_CKP_STATE_LOADING ) : -// case ((BT_CKP_STATE_LOADING <<4)|BT_CKP_STATE_LOADING ) : -// case ((BT_CKP_STATE_LOADING <<4)|BT_CKP_STATE_STORING ) : -// case ((BT_CKP_STATE_OFF<<4)|BT_CKP_STATE_STORING ) : -// default: -// //error state -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_CKP_STATE); -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, ERRINFO_BT_CKP_STATE); -// break; -// } -// -// if (DF_UL_LOG_NONE != log_level) -// { -// DF_WRITE_LOG_US(log_level, -// "ckp_root_index/ckp_mutation_counter=0x%lx/%lu", -// ckp_root_index, ckp_mutation_counter); -// DF_WRITE_LOG_US(log_level, -// "_ckp_state=%d, ckp_state=%d", -// _ckp_state, ckp_state); -// } -// -// return err; -//}; - - - -//store all contents of a tree to file -int dfs_btree_t::_bt_store_tree( - const dfs_bt_root_t & bt_root, - dfs_btree_store_info_t & store_info, - dfs_btree_fhead_t & btree_fhead) const { - const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - const node_base_t * pnode = NULL; - int64_t file_head_offset = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - log_level = this->CKP_LOG_LEVEL; - memset(&btree_fhead, 0, sizeof(btree_fhead)); - store_info.init_counters(); - - if (UNDEF_INDEX == sbt_root.get_root_node_index()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == sbt_root.get_root_node_index()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_node(sbt_root.get_root_node_index(), &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } - //空的树也要保存文件后和节点信息 - else { //if (pnode->get_subkey_num() >= 0) - //首先写头... - //保存一下是在什么位置上面改写的:).. - if ((err = _store_fhead(store_info, file_head_offset, btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_store_fhead() returns 0x%x", err); - } else { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - //然后保存子树... - if ((err = _store_subtree(sbt_root.get_root_node_index(), store_info)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_store_subtree() returns 0x%x", err); - } - //然后往store_info里面进行padding. - else if ((err = store_info.padding()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.padding() returns 0x%x", err); - } - } - if (0 == err) { - //然后更新一下btree头把..:).. - if ((err = _update_stored_fhead(store_info, file_head_offset, btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_stored_fhead() returns 0x%x", err); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "root_index=0x%lx, mutation_counter=%lu", - sbt_root.get_root_node_index(), sbt_root.get_mutation_counter()); - DF_WRITE_LOG_US(log_level, - "file_head_offset=%ld", - file_head_offset); - if (NULL != pnode) { - DF_WRITE_LOG_US(log_level, - "pnode->get_subkey_num()=%d", - pnode->get_subkey_num()); - } - } - - return err; -}; - - -// -int dfs_btree_t::_bt_load_tree( - dfs_bt_root_t & new_wr_bt_root, - dfs_btree_load_info_t & load_info, - dfs_btree_fhead_t & btree_fhead) { - dfs_sbt_root_t sbt_root = _bt_get_sbt_root(new_wr_bt_root); - uint64_t tmp_root_index = UNDEF_INDEX; - uint64_t new_root_index = UNDEF_INDEX; - int64_t file_head_offset = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - log_level = this->CKP_LOG_LEVEL; - memset(&btree_fhead, 0, sizeof(btree_fhead)); - - if ((err = _load_fhead(load_info, file_head_offset, btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_load_fhead() returns 0x%x", err); - } - //会得到load info的index...:).. - else if ((err = _load_subtree(new_root_index, load_info)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_load_subtree() returns 0x%x", err); - } else if (0 != load_info.get_total_leaf_node_num() - || 0 != load_info.get_total_mid_node_num() - || 0 != load_info.get_total_key_num()) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_KEY_NODE_NUM); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_KEY_NODE_NUM); - } else if ((err = load_info.file_seek(file_head_offset+btree_fhead.total_data_len)) != 0) { - //move the file to the correct position - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.file_seek() returns 0x%x", err); - } - - if (0 == err) { - if ((err = sbt_root.set_root_node_index(tmp_root_index, new_root_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "sbt_root.set_root_node_index() returns 0x%x", - err); - } else { - sbt_root.set_mutation_counter(_bt_get_mutation_counter()); - if ((err = _bt_set_sbt_root(new_wr_bt_root, sbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_set_sbt_root() returns 0x%x", err); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "tmp_root_index=0x%lx, new_root_index=0x%lx, file_head_offset=0x%lx", - tmp_root_index, new_root_index, file_head_offset); - DF_WRITE_LOG_US(log_level, - "leaf_node_num=%ld, mid_node_num=%ld, key_num=%ld", - load_info.get_total_leaf_node_num(), - load_info.get_total_mid_node_num(), - load_info.get_total_key_num()); - } - - return err; -}; - - - -//store all contents of a subtree to file -int dfs_btree_t::_store_subtree( - const uint64_t subtree_root, - dfs_btree_store_info_t & store_info) const { - const mid_node_t * pmid_node = NULL; - uint64_t subnode_index = UNDEF_INDEX; - uint32_t subnode_num = 0; - uint32_t subnode_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //在checkpointing过程中,一旦检测到_ckp_state变化,则中止该checkpointing。 - if (_bt_is_cancel_checkpointing()) { - log_level = DF_UL_LOG_NOTICE; - DF_WRITE_LOG_US(log_level, "storing checkpointing cancelled"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_CKP_CANCELLED); - - } else if ((err = _store_subkeys(subtree_root, store_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_store_subkeys() returns 0x%x", err); - - } else if (_is_mid_node(subtree_root)) { - if ((err = _get_mid_node(subtree_root, &pmid_node)) != 0 || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_mid_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else if (pmid_node->get_subkey_num() <= 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->get_subkey_num() <= 0"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_NUM); - } else { - subnode_num = pmid_node->get_subkey_num()+1; - for (subnode_pos = 0; subnode_pos < subnode_num; ++subnode_pos) { - if ((subnode_index = pmid_node->get_subnode_index(subnode_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subnode_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBNODE_INDEX); - break; - } else if ((err = _store_subtree(subnode_index, store_info)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_store_subtree() returns 0x%x", err); - break; - } - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx, subnode_index=0x%lx", - subtree_root, subnode_index); - DF_WRITE_LOG_US(log_level, - "subnode_num=%d, subnode_pos=%d", - subnode_num, subnode_pos); - if (NULL != pmid_node) { - DF_WRITE_LOG_US(log_level, - "pmid_node->get_subkey_num()=%d", - pmid_node->get_subkey_num()); - } - } - - return err; -}; - -//load all contents of a subtree to file -int dfs_btree_t::_load_subtree( - uint64_t & subtree_root, - dfs_btree_load_info_t & load_info) { - uint64_t subkey_index_ary[BT_FANOUT-1]; - uint64_t subnode_index_ary[BT_FANOUT]; - uint64_t ref_counter = UNDEF_REF_COUNTER; - uint32_t subkey_num = 0; - uint32_t subnode_pos = 0; - uint32_t j = 0; - bool is_mid_node = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - subtree_root = UNDEF_INDEX; - - //在checkpointing过程中,一旦检测到_ckp_state变化,则中止该checkpointing。 - if (_bt_is_cancel_checkpointing()) { - log_level = DF_UL_LOG_NOTICE; - DF_WRITE_LOG_US(log_level, "loading checkpointing cancelled"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_CKP_CANCELLED); - } else if ((err = _load_subkeys( - subkey_index_ary, - df_len_of_ary(subkey_index_ary), - subkey_num, - is_mid_node, - load_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_load_subkeys() returns 0x%x", err); - } else if (is_mid_node) { - for (subnode_pos = 0; subnode_pos <= subkey_num; ++subnode_pos) { - if ((err = _load_subtree( - subnode_index_ary[subnode_pos], - load_info)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_load_subtree() returns 0x%x", err); - - //如果出现错误,则已经生成的obj对象需要回收 - //如果不保存INDEX的话,那么需要释放...:)..... - //???what does it means..??; - if (load_info.get_store_t_type() != dfs_btree_load_info_t::STORE_T_INDEX) { - //先+1引用计数,再-1引用计数,这导致对象回收 - if ((err1 = vir_inc_obj_ary_ref_counter(subkey_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_inc_obj_ary_ref_counter() returns 0x%x", err1); - } else if ((err1 = vir_dec_obj_ary_ref_counter(subkey_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_dec_obj_ary_ref_counter() returns 0x%x", err1); - } - } - //已经生成的子树也需要回收 - for (j = 0; j < subnode_pos; ++j) { - //先+1引用计数,再-1引用计数,这导致对象回收 - if ((err1 = _inc_node_ref_counter(subnode_index_ary[j], ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_node_ref_counter() returns 0x%x", err1); - } else if ((err1 = _dec_node_ref_counter(subnode_index_ary[j], ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_node_ref_counter() returns 0x%x", err1); - } - } - break; - } - } - if (0 == err) { - mid_node_t * pmid_node = NULL; - if ((err = _acquire_mid_node(subtree_root, &pmid_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_mid_node(subtree_root...) returns 0x%x", err); - } else if (UNDEF_INDEX == subtree_root || NULL == pmid_node) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == subtree_root || NULL == pmid_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pmid_node->put_pairs( - subkey_index_ary, - subnode_index_ary, - subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pmid_node->put_pairs() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(subtree_root)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(subtree_root) returns 0x%x", err); - } - } - load_info.dec_total_mid_node_num(); - } else { - //leaf node - leaf_node_t * pleaf_node = NULL; - - if ((err = _acquire_leaf_node(subtree_root, &pleaf_node)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_leaf_node(subtree_root...) returns 0x%x", err); - } else if (UNDEF_INDEX == subtree_root || NULL == pleaf_node) { - //leaf_node: 保留unit 0 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "UNDEF_INDEX == subtree_root || NULL == pleaf_node"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LEAF_NODE_ACQUIRE); - } else if ((err = pleaf_node->put_subkeys(subkey_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pleaf_node->put_subkeys() returns 0x%x", err); - } else if ((err = _inc_pointed_ref_counter(subtree_root)) != 0) { //由该新节点导致的引用计数增加 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_pointed_ref_counter(subtree_root) returns 0x%x", err); - } - load_info.dec_total_leaf_node_num(); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "subtree_root=0x%lx", - subtree_root); - DF_WRITE_LOG_US(log_level, - "subkey_num=%d, subnode_pos=%d, is_mid_node=%d", - subkey_num, subnode_pos, is_mid_node); - BT_DF_WRITE_LOG_INT64S(log_level, "subkey_index_ary", subkey_index_ary, subkey_num); - BT_DF_WRITE_LOG_INT64S(log_level, "subnode_index_ary", subnode_index_ary, subkey_num+1); - } - - return err; -}; - - -//store contents of all subkeys of a node to file -int dfs_btree_t::_store_subkeys( - const uint64_t node_index, - dfs_btree_store_info_t & store_info) const { - uint64_t num = 0; - uint64_t obj_index = UNDEF_INDEX; - uint64_t pre_data_pos = 0; - const node_base_t * pnode = NULL; - uint32_t subkey_num = 0; - uint32_t subkey_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _get_node(node_index, &pnode)) != 0 || NULL == pnode) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_node() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NODE_NULL_POINTER); - } else { - subkey_num = pnode->get_subkey_num(); - num = subkey_num<<1; - store_info.add_total_key_num(subkey_num); - if (pnode->is_mid_node()) { - num |= dfs_btree_fhead_t::ATTR_MIDNODE_FLAG; - store_info.inc_total_mid_node_num(); - } else { - store_info.inc_total_leaf_node_num(); - } - //num有什么用...... - if ((err = store_info.encode_num(num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.encode_num() returns 0x%x", err); - } else { - for (subkey_pos = 0; subkey_pos < subkey_num; ++subkey_pos) { - if ((obj_index = pnode->get_subkey_index(subkey_pos)) == UNDEF_INDEX) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "obj_index == UNDEF_INDEX"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_KEY_INDEX); - break; - } else if ((err = vir_obj_store_size(obj_index, num, store_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_obj_store_size() returns 0x%x", err); - break; - } else if ((err = store_info.encode_data_len(num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.encode_data_len() returns 0x%x", err); - break; - } else { - pre_data_pos = store_info.get_data_pos(); - if ((err = vir_store_obj(obj_index, store_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_store_obj() returns 0x%x", err); - break; - } else if ((pre_data_pos+num) != store_info.get_data_pos()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(pre_data_pos+num) != store_info.get_data_pos()"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_STORE_POS); - break; - } - } - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "node_index=0x%lx, obj_index=0x%lx", - node_index, obj_index); - DF_WRITE_LOG_US(log_level, - "pre_data_pos=%ld, store_info.get_data_pos()=%ld", - pre_data_pos, store_info.get_data_pos()); - DF_WRITE_LOG_US(log_level, - "subkey_num=%d, subkey_pos=%d, num=%ld", - subkey_num, subkey_pos, num); - } - - return err; -}; - -//store contents of all subkeys of a node to file -int dfs_btree_t::_load_subkeys( - uint64_t * subkey_index_ary, - const uint32_t ary_len, - uint32_t & subkey_num, - bool & is_mid_node, - dfs_btree_load_info_t & load_info) { - uint64_t num = 0; - uint64_t pre_data_pos = 0; - uint64_t obj_index = UNDEF_INDEX; - uint32_t subkey_pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - subkey_num = 0; - is_mid_node = false; - - //first the length - if ((err = load_info.decode_num(num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.decode_num() returns 0x%x", err); - } else { - is_mid_node = ((num & dfs_btree_fhead_t::ATTR_MIDNODE_FLAG) != 0); - //subkey_num是0是可能的:空的树 - if ((subkey_num = (uint32_t)(num>>1)) > ary_len) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "subkey_num > ary_len"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_SUBKEY_NUM); - } - load_info.sub_total_key_num(subkey_num); - } - - if (0 == err) { - for (subkey_pos = 0; subkey_pos < subkey_num; ++subkey_pos) { - obj_index = UNDEF_INDEX; - if ((err = load_info.decode_data_len(num)) != 0) { - //length of T - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.decode_data_len() returns 0x%x", err); - break; - } else { - pre_data_pos = load_info.get_data_pos(); - if ((err = vir_load_obj(obj_index, load_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_load_obj() returns 0x%x", err); - break; - } else if ((pre_data_pos+num) != load_info.get_data_pos()) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_POS); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_POS); - break; - } - } - if (load_info.get_store_t_type() == dfs_btree_load_info_t::STORE_T_INDEX) { - if ((err = load_info.get_kept_key_index(obj_index, subkey_index_ary[subkey_pos])) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.get_kept_key_index() returns 0x%x", err); - break; - } - } else { - subkey_index_ary[subkey_pos] = obj_index; - if (load_info.get_store_t_type() == - dfs_btree_load_info_t::STORE_T_VALUE_KEEP_T_INDEX) { - if ((err = load_info.keep_obj_index(subkey_index_ary[subkey_pos])) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.keep_obj_index() returns 0x%x", err); - break; - } - } - } - } - //如果出现错误,则已经生成的obj对象需要回收 - if (0 != err && load_info.get_store_t_type() != dfs_btree_load_info_t::STORE_T_INDEX) { - if (UNDEF_INDEX != obj_index) { - subkey_index_ary[subkey_pos++] = obj_index; - } - //先+1引用计数,再-1引用计数,这导致对象回收 - if ((err1 = vir_inc_obj_ary_ref_counter(subkey_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_inc_obj_ary_ref_counter() returns 0x%x", err1); - } else if ((err1 = vir_dec_obj_ary_ref_counter(subkey_index_ary, subkey_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "vir_dec_obj_ary_ref_counter() returns 0x%x", err1); - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx", - obj_index); - DF_WRITE_LOG_US(log_level, - "pre_data_pos=%ld, load_info.get_data_pos()=%ld, num=%ld", - pre_data_pos, load_info.get_data_pos(), num); - DF_WRITE_LOG_US(log_level, - "subkey_num=%d, subkey_pos=%d, ary_len=%d, is_mid_node=%d", - subkey_num, subkey_pos, ary_len, is_mid_node); - BT_DF_WRITE_LOG_INT64S(log_level, "subkey_index_ary", subkey_index_ary, subkey_num); - } - - return err; -}; - - - -//填写文件头.. -int dfs_btree_t::_store_fhead( - dfs_btree_store_info_t & store_info, - int64_t & file_head_offset, - dfs_btree_fhead_t & btree_fhead) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - file_head_offset = store_info.get_cur_file_offset(); - - memset(&btree_fhead, 0, sizeof(btree_fhead)); - //填写好btree fhead... - btree_fhead.size = sizeof(btree_fhead); - btree_fhead.ver = dfs_btree_fhead_t::CORE_BT_VER ; - btree_fhead.major_tag = store_info.get_major_tag(); - btree_fhead.minor_tag = dfs_btree_fhead_t::CORE_BT_TAG; - btree_fhead.store_t_type = store_info.get_store_t_type(); - - if ((err = store_info.store_buf(&btree_fhead, sizeof(btree_fhead))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.store_buf() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "file_head_offset=%ld", - file_head_offset); - } - - return err; -}; - - -int dfs_btree_t::_update_stored_fhead( - dfs_btree_store_info_t & store_info, - const int64_t file_head_offset, - dfs_btree_fhead_t & btree_fhead) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - btree_fhead.total_data_len = store_info.get_cur_file_offset() - file_head_offset; - btree_fhead.total_leaf_node_num = store_info.get_total_leaf_node_num() ; - btree_fhead.total_mid_node_num = store_info.get_total_mid_node_num() ; - btree_fhead.total_key_num = store_info.get_total_key_num() ; - - if ((err = store_info.rewrite_data(&btree_fhead, sizeof(btree_fhead), file_head_offset)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.rewrite_data() returns 0x%x", err); - } - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "file_head_offset=%ld", - file_head_offset); - } - - return err; -}; - - - -int dfs_btree_t::_load_fhead( - dfs_btree_load_info_t & load_info, - int64_t & file_head_offset, - dfs_btree_fhead_t & btree_fhead) const { - uint32_t unread_len = 0; - const uint32_t unread_head = sizeof(dfs_btree_fhead_t)-sizeof(dfs_btree_fhead_base_t); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - file_head_offset = load_info.get_cur_file_offset(); - memset(&btree_fhead, 0, sizeof(btree_fhead)); - - //此时最大长度不知道,暂时设置为基本头的长度 - load_info.set_max_file_offset(file_head_offset+sizeof(dfs_btree_fhead_base_t)); - //加载基本头信息 - if ((err = load_info.load_buf( - (void *)((dfs_btree_fhead_base_t *)&btree_fhead), - sizeof(dfs_btree_fhead_base_t))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.load_buf(dfs_btree_fhead_base_t) returns 0x%x", err); - } else if (load_info.get_major_tag() != btree_fhead.major_tag) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_MAJOR_TAG); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_MAJOR_TAG); - } else if (dfs_btree_fhead_t::CORE_BT_TAG != btree_fhead.minor_tag) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_MINOR_TAG); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_MINOR_TAG); - } else if (dfs_btree_fhead_t::CORE_BT_VER < btree_fhead.ver) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_HEAD_VER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_HEAD_VER); - } else if (btree_fhead.size < sizeof(dfs_btree_fhead_base_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_HEAD_SIZE); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_HEAD_SIZE); - } else { - unread_len = btree_fhead.size-sizeof(dfs_btree_fhead_base_t); - - //设置准确的最大长度 - load_info.set_max_file_offset(file_head_offset+btree_fhead.total_data_len); - - //加载扩展头信息:头信息尺寸可能不等于sizeof(btree_fhead) - if ((err = load_info.load_buf( - (void *)((dfs_btree_fhead_ext_t *)&btree_fhead), - MIN(unread_len, unread_head))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - "load_info.load_buf(dfs_btree_fhead_ext_t) returns 0x%x", - err); - } else if (unread_len > unread_head) { - if ((err = load_info.skip_data_len(unread_len-unread_head)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - "load_info.load_buf(unread_len-unread_head) returns 0x%x", - err); - } - } - } - - load_info.set_store_t_type(btree_fhead.store_t_type); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "file_head_offset=%ld", - file_head_offset); - DF_WRITE_LOG_US(log_level, - "load_info.get_major_tag()=0x%x, btree_fhead.major_tag=0x%x", - load_info.get_major_tag(), btree_fhead.major_tag); - DF_WRITE_LOG_US(log_level, - "dfs_btree_fhead_t::CORE_BT_TAG=0x%x, btree_fhead.minor_tag=0x%x", - dfs_btree_fhead_t::CORE_BT_TAG, btree_fhead.minor_tag); - DF_WRITE_LOG_US(log_level, - "dfs_btree_fhead_t::CORE_BT_VER=0x%x, btree_fhead.ver=0x%x", - dfs_btree_fhead_t::CORE_BT_VER, btree_fhead.ver); - DF_WRITE_LOG_US(log_level, - "unread_len=0x%x, unread_head=0x%x, btree_fhead.size=0x%x", - unread_len, unread_head, btree_fhead.size); - } - - return err; -}; - -#endif //__DFS_BTREE_INCLUDE_H_ diff --git a/bsl/containers/btree/df_def.h b/bsl/containers/btree/df_def.h deleted file mode 100644 index b648f2d65eb6da864eaf929b8c817d1d45e0f946..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_def.h +++ /dev/null @@ -1,57 +0,0 @@ -////==================================================================== -// -// df_def.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-04-22 by Ye Ling (yeling@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration of common types -// -// ------------------------------------------------------------------- -// -// Change Log -// -////==================================================================== - -#ifndef __DF_DEF_H__ -#define __DF_DEF_H__ - -// Enable macros definition in stdint.h -#ifndef __STDC_LIMIT_MACROS -# define __STDC_LIMIT_MACROS 1 -# undef _STDINT_H -#endif - -#include -//#include "ul_def.h" - -// Definition of common types -typedef signed char char8; -typedef unsigned char u_char8; - -const uint64_t MAX_U_INT64 = UINT64_MAX; -const int64_t MAX_INT64 = INT64_MAX; -const int64_t MIN_INT64 = INT64_MIN; -const uint32_t MAX_U_INT32 = UINT32_MAX; -const int32_t MAX_INT32 = INT32_MAX; -const int32_t MIN_INT32 = INT32_MIN; -const uint16_t MAX_U_INT16 = UINT16_MAX; -const int16_t MAX_INT16 = INT16_MAX; -const int16_t MIN_INT16 = INT16_MIN; -const uint8_t MAX_U_INT8 = UINT8_MAX; -const int8_t MAX_INT8 = INT8_MAX; -const int8_t MIN_INT8 = INT8_MIN; - -//zhangyan04@baidu.com -#define BAIDU_INLINE __attribute__((__always_inline__)) -#define BAIDU_UNLIKELY(exp) (exp) -#define BAIDU_LIKELY(exp) (exp) -//#define BAIDU_UNLIKELY(exp) __builtin_expect((exp),0) -//#define BAIDU_LIKELY(exp) __bultin_expect((exp),1) -#endif // #ifndef __DF_DEF_H__ - diff --git a/bsl/containers/btree/df_log.h b/bsl/containers/btree/df_log.h deleted file mode 100644 index 4b46ccced61abfa7c5f9a45df2838febd44eda13..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_log.h +++ /dev/null @@ -1,98 +0,0 @@ -///==================================================================== -// -// df_log.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2007-12-27 by Ye Ling (yeling@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration of common logging lib -// -// ------------------------------------------------------------------- -// -// Change Log -// -// updated on 2008-12-12 by Ye Ling -// -////==================================================================== - -#ifndef __DF_LOG_H__ -#define __DF_LOG_H__ - -///////////////////////////////////////////////////////////////////////// -//下面这些是不使用ul_log的代码..不会打印任何日志...:). -#include - -#define DF_LOG_NONE "DF_NONE" -#define DF_LOG_FATAL "DF_FATAL" -#define DF_LOG_WARNING "DF_WARNING" -#define DF_LOG_NOTICE "DF_NOTICE" -#define DF_LOG_TRACE "DF_TRACE" -#define DF_LOG_DEBUG "DF_DEBUG" -#define DF_LOG_ALL "DF_ALL" - -#define DF_UL_LOG_NONE 0 -#define DF_UL_LOG_FATAL 0x01 /**< fatal errors */ -#define DF_UL_LOG_WARNING 0x02 /**< exceptional events */ -#define DF_UL_LOG_NOTICE 0x04 /**< informational notices */ -#define DF_UL_LOG_TRACE 0x08 /**< program tracing */ -#define DF_UL_LOG_DEBUG 0x10 /**< full debugging */ -#define DF_UL_LOG_ALL 0xff /**< everything */ -#define DF_UL_LOG_LEVEL_COUNT 17 - -const char DF_LOG_LEVEL[DF_UL_LOG_LEVEL_COUNT][16] = { - DF_LOG_NONE, DF_LOG_FATAL, DF_LOG_WARNING, DF_LOG_NONE, DF_LOG_NOTICE, - DF_LOG_NONE, DF_LOG_NONE, DF_LOG_NONE, DF_LOG_TRACE, DF_LOG_NONE, - DF_LOG_NONE, DF_LOG_NONE, DF_LOG_NONE, DF_LOG_NONE, DF_LOG_NONE, - DF_LOG_NONE, DF_LOG_DEBUG -}; - -// DF_OPEN_LOG 用于打开日志,和ul_openlog一致,直接替换该函数调用即可 -// NOTE: 请保证使用该宏打开日志 -#define DF_OPEN_LOG(_logpath_, _logname_, _plogstat_, _log_size_) - -// 打开日志,将warning/fatal日志也输出到debug日志中,且使用异步方式写日志文件 -#define DF_OPEN_LOG_EX(_logpath_, _logname_, _plogstat_, _log_size_) - -#define DF_CLOSE_LOG() - -// DF_WRITE_LOG 用于系统日志的记录 -// NOTE:对于数据/展现日志请勿使用 -#define DF_WRITE_LOG(_loglevel_, _fmt_, args...) - -#define DF_WRITE_LOG_DEBUG(_fmt_, args...) - -#define DF_WRITE_LOG_EX(_loglevel_, _fmt_, args...) - -// DF_WRITE_LOG_NOTICE_US 用于系统日志的记录 -// 不打印文件名,函数,行号,增加微秒数 -#define DF_WRITE_LOG_NOTICE_US(_loglevel_, _fmt_, args...) - -// DF_WRITE_LOG_US 用于系统日志的记录,带微秒数 -// NOTE:对于数据/展现日志请勿使用 -#define DF_WRITE_LOG_US(_loglevel_, _fmt_, args...) - -// AP_WRITE_LOG 用于系统日志的记录 -// NOTE:对于数据/展现日志请勿使用 -#define AP_WRITE_LOG(_loglevel_, _fmt_, args...) - -// AP_WRITE_LOG_DEBUG用于系统调试日志的记录,正式发布会删除 -// NOTE: 对于数据/展现日志请勿使用 -#define AP_WRITE_LOG_DEBUG(_fmt_, args...) - -#define AP_WRITE_LOG_EX(_loglevel_, _fmt_, args...) - -// AP_WRITE_LOG_NOTICE_US 用于系统日志的记录 -// 不打印文件名,函数,行号,增加微秒数 -#define AP_WRITE_LOG_NOTICE_US(_loglevel_, _fmt_, args...) - -// AP_WRITE_LOG_US 用于系统日志的记录,带微秒数 -// NOTE:对于数据/展现日志请勿使用 -#define AP_WRITE_LOG_US(_loglevel_, _fmt_, args...) - -#endif // #ifndef __DF_LOG_H__ - diff --git a/bsl/containers/btree/df_misc.h b/bsl/containers/btree/df_misc.h deleted file mode 100644 index 87d178feab8a838719a1a7e2c9d61d6e34012be8..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_misc.h +++ /dev/null @@ -1,727 +0,0 @@ -////==================================================================== -// -// df_2d_ary.h - Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-02-01 by YANG Zhenkun (yangzhenkun@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration and implementation of some common functions and classes -// -// ------------------------------------------------------------------- -// -// Change Log -// -// updated on 2008-02-01 by YANG Zhenkun (yangzhenkun@baidu.com) -// -////==================================================================== - -#ifndef __DF_MISC_INCLUDE_H_ -#define __DF_MISC_INCLUDE_H_ - -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -//zhangyan04@baidu.com -#include "bsl_kv_btree_xmemcpy.h" - -#include "df_def.h" -#include "df_atomic.h" -//#include "ul_def.h" -//#include "df_log.h" -//#include -//#include "df_common.h" - -//using namespace std; - -//Linux kernel 2.6的一个bug使得调用pthread_mutex_timedlock()可能出core -//因此把互斥的mutex锁换成了读写锁 -//阳振坤(yangzhenkun@baidu.com) 20090311 -#ifndef DF_NOT_USE_MUTEX_TIMEDLOCK -#define DF_NOT_USE_MUTEX_TIMEDLOCK -#endif - -//Obtain the length of an array -//#define len_of_ary(ary) ((uint32_t)(sizeof(ary)/sizeof((ary)[0]))) -#define df_len_of_ary(ary) (sizeof(ary)/sizeof((ary)[0])) - - -inline timeval df_microseconds_to_tv(const int64_t microseconds) { - struct timeval tp; - - tp.tv_sec = microseconds / 1000000; - tp.tv_usec = microseconds % 1000000; - - return tp; -} - -inline timespec df_microseconds_to_ts(const int64_t microseconds) { - struct timespec ts; - - ts.tv_sec = microseconds / 1000000; - ts.tv_nsec = (microseconds % 1000000) * 1000; - - return ts; -} - -inline int64_t df_tv_to_microseconds(const timeval & tp) { - return (((int64_t) tp.tv_sec) * 1000000 + (int64_t) tp.tv_usec); -} - -inline int64_t df_ts_to_microseconds(const timespec & ts) { - return (((int64_t) ts.tv_sec) * 1000000 + (int64_t) ((ts.tv_nsec + 500) / 1000)); -} - -inline int64_t df_get_cur_microseconds_time(void) { - struct timeval tp; - - gettimeofday(&tp, NULL); - - return df_tv_to_microseconds(tp); -} - -inline void df_microseconds_sleep(const int64_t microseconds) { - struct timespec ts = df_microseconds_to_ts(microseconds); - - nanosleep(&ts, NULL); -} - -inline void df_make_timespec_with_interval(struct timespec& tsp, int64_t useconds) { - struct timeval now; - - gettimeofday(&now, NULL); - useconds += now.tv_usec; - tsp.tv_sec = now.tv_sec; - while (useconds >= 1000000) { - tsp.tv_sec++; - useconds -= 1000000; - } - tsp.tv_nsec = useconds * 1000; -} - -# if defined __x86_64__ - -class dfs_init_t { -protected: - enum cconst_private { - STATE_INIT_SUCCEED = 0 , - STATE_NOT_INIT_YET , - STATE_INIT_FAIL , - STATE_DESTRUCTED , - }; -public: - dfs_init_t() { - _err = 0; - set_not_init_yet(); - }; - ~dfs_init_t() { - set_destructed(); - }; -private: - int _state; - int _err; -public: - bool is_not_init_yet(void) const { - return (STATE_NOT_INIT_YET == _state); - }; - bool is_init_fail(void) const { - return (STATE_INIT_FAIL == _state); - }; - bool is_init_succeed(void) const { - return (STATE_INIT_SUCCEED == _state); - }; - void set_not_init_yet(void) const { - *((int *)&_state) = STATE_NOT_INIT_YET; - }; - void set_init_result(const int err) const { - if (is_not_init_yet()) { - *((int *)&_err) = err; - *((int *)&_state) = (0 == err) ? STATE_INIT_SUCCEED : STATE_INIT_FAIL; - } - }; - int get_init_result(void) const { - return _err; - }; - void set_destructed(void) const { - *((int *)&_state) = STATE_DESTRUCTED; - }; -}; - -// a lightweight lock -class dfs_spinlock_t { -public: - enum cconst_private { - MICROSECONDS_PER_SLEEP = 20 , - }; -private: - dfs_init_t _init_state; - pthread_spinlock_t _spinlock; -public: - inline dfs_spinlock_t() { - init(); - } - inline ~ dfs_spinlock_t() { - if (_init_state.is_init_succeed()) { - pthread_spin_destroy(&_spinlock); - _init_state.set_destructed(); - } - } -public: - int init(void) const { - int err = 0; - - if (_init_state.is_not_init_yet()) { - err = pthread_spin_init((pthread_spinlock_t *)&_spinlock, PTHREAD_PROCESS_PRIVATE); - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; -protected: - //return: 0 for success, other values for error - // possible errors: EBUSY, EINVAL, EAGAIN, ENOMEM, EDEADLK, EPERM - inline int _lock(const int64_t wait_microsecond = 0) const { - int64_t wait_us = (wait_microsecond <= 0) ? (MAX_INT64/2) : wait_microsecond; - int64_t time_us = 0; - int err = 0; - - while (wait_us > 0) { - time_us = df_get_cur_microseconds_time(); - if ((err = pthread_spin_trylock((pthread_spinlock_t *)&_spinlock)) == 0) { - break; - } else if (EBUSY == err) { - df_microseconds_sleep(MICROSECONDS_PER_SLEEP); - wait_us -= df_get_cur_microseconds_time() - time_us; - } else { - break; - } - } - - return err; - } - inline int _unlock(void) const { - int err = 0; - - err = pthread_spin_unlock((pthread_spinlock_t *) &_spinlock); - - return err; - } -public: - // 功能:尝试在max_try_time微秒内锁住整棵B树,如果不能,返回失败。 - // 一旦B树被锁住,在解锁前无法进行任何修改操作,也不能verify其正确性(读操作可正常进行)。 - // 今后视需要实现锁住后在max_hold_time后自动解锁 - // 返回:返回0表示成功,返回非0(错误代码)表示失败 - int lock(const int64_t max_try_time) const { - return _lock(max_try_time); - }; - // 功能:解锁 - // 返回:返回0表示成功,返回非0(错误代码)表示失败 - int unlock(void) const { - return _unlock(); - }; -}; - - -class dfs_wrlock_t { -private: - enum cconst_private { - MICROSECONDS_PER_R_SLEEP = 20 , - MICROSECONDS_PER_W_SLEEP = 20 , - }; - static const uint64_t W_FLAG = ((uint64_t)0x1)<<62; - static const uint64_t R_MASK = W_FLAG-1; -private: - dfs_init_t _init_state; - pthread_rwlock_t _rwlock; -public: - inline dfs_wrlock_t() { - init(); - } - inline ~ dfs_wrlock_t() { - if (_init_state.is_init_succeed()) { - pthread_rwlock_destroy(&_rwlock); - _init_state.set_destructed(); - } - } -public: - int init(void) const { - int err = 0; - - if (_init_state.is_not_init_yet()) { - err = pthread_rwlock_init((pthread_rwlock_t *)&_rwlock, NULL); - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; - }; -protected: - //return: 0 for success, other values for error - // possible errors: EBUSY, EINVAL, EAGAIN, ENOMEM, EDEADLK, EPERM - inline int _r_lock(const int64_t wait_microsecond = 0) const { - int64_t wait_us = (wait_microsecond <= 0) ? (MAX_INT64/2) : wait_microsecond; - struct timespec ts = df_microseconds_to_ts(wait_us); - int err = 0; - - err = pthread_rwlock_timedrdlock((pthread_rwlock_t *)&_rwlock, &ts); - - return err; - }; - //return: 0 for success, other values for error - // possible errors: EBUSY, EINVAL, EAGAIN, ENOMEM, EDEADLK, EPERM - inline int _w_lock(const int64_t wait_microsecond = 0) const { - int64_t wait_us = (wait_microsecond <= 0) ? (MAX_INT64/2) : wait_microsecond; - struct timespec ts = df_microseconds_to_ts(wait_us); - int err = 0; - - err = pthread_rwlock_timedwrlock((pthread_rwlock_t *)&_rwlock, &ts); - - return err; - }; - inline int _unlock(void) const { - int err = 0; - - err = pthread_rwlock_unlock((pthread_rwlock_t *)&_rwlock); - - return err; - }; -public: - // 功能:尝试在max_try_time微秒内锁住整棵B树,如果不能,返回失败。 - // 一旦B树被锁住,在解锁前无法进行任何修改操作,也不能verify其正确性(读操作可正常进行)。 - // 今后视需要实现锁住后在max_hold_time后自动解锁 - // 返回:返回0表示成功,返回非0(错误代码)表示失败 - int r_lock(const int64_t max_try_time) const { - return _r_lock(max_try_time); - }; - // 功能:解锁 - // 返回:返回0表示成功,返回非0(错误代码)表示失败 - int r_unlock(void) const { - return _unlock(); - }; - int w_lock(const int64_t max_try_time) const { - return _w_lock(max_try_time); - }; - // 功能:解锁 - // 返回:返回0表示成功,返回非0(错误代码)表示失败 - int w_unlock(void) const { - return _unlock(); - }; -}; - - -class dfs_mutex_lock_t; //锁本身 -class dfs_mutex_hold_t; //当前上锁后的锁标识 - - -class dfs_mutex_hold_t { - friend class dfs_mutex_lock_t; -public: - dfs_mutex_hold_t() { - _init(NULL); - }; - ~dfs_mutex_hold_t(); -private: - uint64_t _lock_uniq_cnt; - const dfs_mutex_lock_t * _plock; -private: - void _init(dfs_mutex_lock_t * plock) { - _set_lock_uniq_cnt(0); - _set_lock_ptr(plock); - }; - void _set_lock_uniq_cnt(const uint64_t lock_uniq_cnt) { - _lock_uniq_cnt = lock_uniq_cnt; - return; - }; - uint64_t _get_lock_uniq_cnt(void) const { - return _lock_uniq_cnt; - }; - void _set_lock_ptr(const dfs_mutex_lock_t * plock) { - _plock = plock; - }; - const dfs_mutex_lock_t * _get_lock_ptr(void) const { - return _plock; - }; -}; - - - -class dfs_mutex_lock_t { - friend class dfs_mutex_hold_t; -private: -protected: - enum cconst_private { - LOCK_UNIQ_CNT_ADD = 2 , //_lock_uniq_cnt每次增加的值 - ON_MUTATE_MARK = 1 , //当前正在修改的标记 - }; -private: - dfs_init_t _init_state; - uint64_t _lock_uniq_cnt; -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - pthread_rwlock_t _rwlock; -#else - pthread_mutex_t _lock; -#endif -public: - inline dfs_mutex_lock_t() { - //int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - if ((err = pthread_rwlock_init((pthread_rwlock_t *)&_rwlock, NULL)) != 0) -#else - if ((err = pthread_mutex_init(&_lock, NULL)) != 0) -#endif - { - //log_level = DF_UL_LOG_FATAL; - //DF_WRITE_LOG_US(log_level, "pthread_mutex_init(,NULL) returns 0x%x", err); - } - - _lock_uniq_cnt = LOCK_UNIQ_CNT_ADD; - - _init_state.set_init_result(err); - } - inline ~ dfs_mutex_lock_t() { -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - pthread_rwlock_destroy(&_rwlock); -#else - pthread_mutex_destroy(&_lock); -#endif - _init_state.set_destructed(); - } -public: - int init(void) const { - return 0; - }; -protected: - inline int _acquire_lock( - dfs_mutex_hold_t & lock_hold, - const int64_t wait_microsecond = 0) const; - inline int _release_lock(dfs_mutex_hold_t & lock_hold) const; - //验证是否是当前的hold - inline bool _verify_hold(const dfs_mutex_hold_t & lock_hold) const; - //验证是当前的hold通过且设置ON_MUTATE_MARK,否则返回错误 - inline int _acquire_hold(const dfs_mutex_hold_t & lock_hold) const; - //验证是当前的hold通过且清除ON_MUTATE_MARK,否则返回错误 - inline int _release_hold(const dfs_mutex_hold_t & lock_hold) const; -}; - - -inline dfs_mutex_hold_t::~dfs_mutex_hold_t() { - if (NULL != _plock) { - _plock->_release_lock(*this); - _plock = NULL; - } -}; - - -inline int dfs_mutex_lock_t::_acquire_lock( - dfs_mutex_hold_t & lock_hold, - const int64_t wait_microsecond) const { - //int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (wait_microsecond <= 0 || wait_microsecond >= MAX_INT64/4) { -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - if ((err = pthread_rwlock_wrlock((pthread_rwlock_t *)&_rwlock)) != 0) -#else - if ((err = pthread_mutex_lock((pthread_mutex_t *)&_lock)) != 0) -#endif - { - //log_level = DF_UL_LOG_FATAL; - //DF_WRITE_LOG_US(log_level, "pthread_mutex_lock() returns 0x%x", err); - } - //当前不应该正在修改中 - else if ((_lock_uniq_cnt & ON_MUTATE_MARK) != 0) { - err = EINTR; - } else { - lock_hold._set_lock_uniq_cnt(_lock_uniq_cnt); - lock_hold._set_lock_ptr(this); - } - } else { - const int64_t wait_us = wait_microsecond+df_get_cur_microseconds_time(); - struct timespec ts = df_microseconds_to_ts(wait_us); - -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - if ((err = pthread_rwlock_timedwrlock((pthread_rwlock_t *)&_rwlock, &ts)) != 0) -#else - if ((err = pthread_mutex_timedlock((pthread_mutex_t *)&_lock, &ts)) != 0) -#endif - { - //log_level = DF_UL_LOG_FATAL; - //DF_WRITE_LOG_US(log_level, "pthread_mutex_timedlock() returns 0x%x", err); - } - //当前不应该正在修改中 - else if ((_lock_uniq_cnt & ON_MUTATE_MARK) != 0) { - err = EINTR; - } else { - lock_hold._set_lock_uniq_cnt(_lock_uniq_cnt); - lock_hold._set_lock_ptr(this); - } - } - - return err; -}; - -inline int dfs_mutex_lock_t::_release_lock(dfs_mutex_hold_t & lock_hold) const { - //int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (df_atomic_compare_exchange( - (volatile uint64_t *)&_lock_uniq_cnt, - lock_hold._get_lock_uniq_cnt()+LOCK_UNIQ_CNT_ADD, - lock_hold._get_lock_uniq_cnt()) == lock_hold._get_lock_uniq_cnt()) { -#ifdef DF_NOT_USE_MUTEX_TIMEDLOCK - if ((err = pthread_rwlock_unlock((pthread_rwlock_t *)&_rwlock)) != 0) -#else - if ((err = pthread_mutex_unlock((pthread_mutex_t *)&_lock)) != 0) -#endif - { - //log_level = DF_UL_LOG_FATAL; - //DF_WRITE_LOG_US(log_level, "pthread_mutex_unlock() returns 0x%x", err); - } else { - lock_hold._set_lock_uniq_cnt(0); - lock_hold._set_lock_ptr(NULL); - } - } else { - err = EPERM; - //log_level = DF_UL_LOG_WARNING; - //DF_WRITE_LOG_US(log_level, "lock_hold unmatch"); - } - - return err; -}; - -//验证是否是当前的hold -inline bool dfs_mutex_lock_t::_verify_hold(const dfs_mutex_hold_t & lock_hold) const { - return (lock_hold._get_lock_uniq_cnt() == _lock_uniq_cnt); -}; - - -//验证是当前的hold通过且设置ON_MUTATE_MARK,否则返回错误 -inline int dfs_mutex_lock_t::_acquire_hold(const dfs_mutex_hold_t & lock_hold) const { - int err = 0; - //如果正在修改中... - if ((lock_hold._get_lock_uniq_cnt() & ON_MUTATE_MARK) != 0) { - err = EINVAL; - } - //原子修改 - //告诉已经mutate了..:).. - else if (df_atomic_compare_exchange( - (uint64_t *)&_lock_uniq_cnt, - _lock_uniq_cnt | ON_MUTATE_MARK, - lock_hold._get_lock_uniq_cnt()) - != lock_hold._get_lock_uniq_cnt()) { - err = EPERM; - } - - return err; -}; - -//验证是当前的hold通过且清除ON_MUTATE_MARK,否则返回错误 -inline int dfs_mutex_lock_t::_release_hold(const dfs_mutex_hold_t & lock_hold) const { - int err = 0; - - if ((lock_hold._get_lock_uniq_cnt() & ON_MUTATE_MARK) != 0) { - err = EINVAL; - } else if (df_atomic_compare_exchange( - (uint64_t *)&_lock_uniq_cnt, - _lock_uniq_cnt & ~((uint64_t)ON_MUTATE_MARK), - lock_hold._get_lock_uniq_cnt() | ON_MUTATE_MARK) - != (lock_hold._get_lock_uniq_cnt() | ON_MUTATE_MARK)) { - err = EPERM; - } - - return err; -}; - - -//Function: if *pv is NOT equal to cv, then inc; otherwise, do nothing. -//return: current value of *pv -inline uint64_t df_atomic_inc_if_not_equal(volatile uint64_t * pv, const uint64_t cv) { - uint64_t pre_v = *pv; //保存v的原始值到cv - uint64_t org_v = pre_v; - - while (cv != org_v) { // 如果原始值org_v为cv,什么都不做 - pre_v = df_atomic_compare_exchange(pv, org_v+1, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - ++org_v; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - return org_v; -}; -inline uint32_t df_atomic_inc_if_not_equal(volatile uint32_t * pv, const uint32_t cv) { - uint32_t pre_v = *pv; //保存v的原始值到cv - uint32_t org_v = pre_v; - - while (cv != org_v) { // 如果原始值org_v为cv,什么都不做 - pre_v = df_atomic_compare_exchange(pv, org_v+1, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - ++org_v; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - return org_v; -}; -inline uint16_t df_atomic_inc_if_not_equal(volatile uint16_t * pv, const uint16_t cv) { - uint16_t pre_v = *pv; //保存v的原始值到cv - uint16_t org_v = pre_v; - - while (cv != org_v) { // 如果原始值org_v为cv,什么都不做 - pre_v = df_atomic_compare_exchange(pv, org_v+1, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - ++org_v; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - return org_v; -}; -inline uint8_t df_atomic_inc_if_not_equal(volatile uint8_t * pv, const uint8_t cv) { - uint8_t pre_v = *pv; //保存v的原始值到cv - uint8_t org_v = pre_v; - - while (cv != org_v) { // 如果原始值org_v为cv,什么都不做 - pre_v = df_atomic_compare_exchange(pv, org_v+1, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - ++org_v; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - return org_v; -}; - - -//Function: if nv > *pv, then set *pv to nv atomically; otherwise, do nothing. -//return: current value of *pv -inline uint64_t df_atomic_exchange_to_larger(volatile uint64_t * pv, const uint64_t nv) { - uint64_t pre_v = *pv; //保存v的原始值到cv - uint64_t org_v = pre_v; - - while (nv > org_v) { // 如果原始值org_v >= nv,什么都不做 - pre_v = df_atomic_compare_exchange(pv, nv, org_v); - if (pre_v == org_v) { - //如果*pv原始值和*pv相等,则没有其他线程对*p进行操作,成功完成+1操作 - org_v = nv; - break; - } else { - //否则别的线程已经对*pv做了操作,把org_v更新为当前被别的线程修改后的值后重试 - org_v = pre_v; - } - } - - return org_v; -}; - - - - -//简单的缓冲区自动申请释放类 -class dfs_buf_t { -protected: - enum cconst { - MIN_BUF_SIZE = 1024, - }; -public: - dfs_buf_t(uint64_t buf_size = 0) { - _buf = NULL; - _buf_size = 0; - if (buf_size > 0) { - _buf_size = (buf_size + MIN_BUF_SIZE - 1) / MIN_BUF_SIZE * MIN_BUF_SIZE; - _buf = new(std::nothrow) char[_buf_size]; - } - } - - virtual ~ dfs_buf_t() { - if (NULL != _buf) { - delete[] _buf; - _buf = NULL; - } - _buf_size = 0; - } - - void * get_buf(void) const { - return (void *) _buf; - } - - uint64_t get_buf_size(void) const { - return _buf_size; - } - - //return: reallocated bufer.如果没有足够内存,则返回NULL,现有缓冲区不改变。 - void *realloc(const uint64_t new_buf_size) { - const uint64_t adjusted_new_buf_size = ((new_buf_size + MIN_BUF_SIZE - 1) / MIN_BUF_SIZE) - * MIN_BUF_SIZE; - char *ret_buf = NULL; - - if (adjusted_new_buf_size != _buf_size) { - if (adjusted_new_buf_size > 0) { - ret_buf = new(std::nothrow) char[adjusted_new_buf_size]; - - if (NULL != ret_buf) { - //memcpy(ret_buf, _buf, MIN(_buf_size, adjusted_new_buf_size)); - ZY::xmemcpy(ret_buf, _buf, MIN(_buf_size, adjusted_new_buf_size)); - delete[] _buf; - _buf = ret_buf; - _buf_size = adjusted_new_buf_size; - } - } else { - delete[] _buf; - _buf = NULL; - _buf_size = 0; - ret_buf = NULL; - } - } else { - ret_buf = _buf; - } - return (void *) ret_buf; - } - - void dealloc(void) { - delete[] _buf; - _buf = NULL; - _buf_size = 0; - } - -protected: - char *_buf; - uint64_t _buf_size; -}; - -#endif - -#endif //__DF_MISC_INCLUDE_H_ - diff --git a/bsl/containers/btree/df_xz_btree.h b/bsl/containers/btree/df_xz_btree.h deleted file mode 100644 index 1c1a3c7b95bb233a9064156ab75255ecb704ae5f..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/df_xz_btree.h +++ /dev/null @@ -1,4778 +0,0 @@ -////=================================================================== -// -// df_xz_btree.h Pyramid / DFS / df-lib -// -// Copyright (C) 2008 Baidu.com, Inc. -// -// Created on 2008-01-05 by YANG Zhenkun (yangzhenkun@baidu.com) -// -// ------------------------------------------------------------------- -// -// Description -// -// declaration and implementation of dfs_xz_btree_t (btree) template -// -// ------------------------------------------------------------------- -// -// Change Log -// -// updated on 2008-07-28 by YANG Zhenkun (yangzhenkun@baidu.com) -// -////==================================================================== - - -#ifndef __DFS_XZ_BTREE_INCLUDE_H_ -#define __DFS_XZ_BTREE_INCLUDE_H_ - -//调试信息打印输出开关 -//#ifndef DF_BT_PRINT_DEBUG_INFO -//#define DF_BT_PRINT_DEBUG_INFO -//#endif - -//#include "ul_def.h" -//#include "df_common.h" -#include "df_btree.h" - -//#define TEST_RWLOCK_TIME - -class dfs_xz_btree_fhead_ext_t { -public: - uint64_t total_leaf_node_num; - uint64_t total_mid_node_num; - uint64_t total_key_num; - uint64_t reserve31[25]; -}; - -class dfs_xz_btree_fhead_t : public dfs_btree_fhead_base_t, public dfs_xz_btree_fhead_ext_t { -}; - - - -// -//模板类:dfs_xz_btree_t -//dfs_xz_btree_t是一棵以K为key的B树 -//模板参数: -// T: 基本数据单元 -// K: 关键字类型 -// ROW_SIZE:基本数据单元二维数组的ROW_SIZE,最好是的方幂。 -// FANOUT:B树的扇出尺寸,每个节点最多(FANOUT-1)个key和FANOUT个子节点。 -// -// -// - - -template -class _dfs_xz_btree_t : - virtual public dfs_bt_const_t, - //virtual private dfs_bt2d_ary_t, - public dfs_btree_t { -protected: - enum cconst_protected { - XZ_BTREE_VER = 0x00000002, //Hihg-16-bit: main ver; - XZ_BTREE_TAG = (((int)'x')<<24) | (((int)'z')<<16) | (((int)'b')<<8) | (((int)'t')), //"xzbt" - }; -private: - //typedef T *PT; - typedef const T *PCT; - typedef T DU; - typedef DU *PDU; - typedef const DU *PCDU; - typedef K *PK; - typedef const K *PCK; -protected: - typedef dfs_bt2d_ary_t t_ary_t; - typedef void * pvoid; -private: - dfs_init_t _init_state; - t_ary_t & _t_2d_ary; -public: - _dfs_xz_btree_t(t_ary_t & t_2d_ary) : - dfs_btree_t(), - _t_2d_ary(t_2d_ary) { - //init(); - } - virtual ~_dfs_xz_btree_t() { - _init_state.set_destructed(); - } - int init(const uint32_t bt_instance_pos, dfs_bt_root_t & new_wr_bt_root); -private: - //Disable operator=() and copy constructor - const _dfs_xz_btree_t & operator=(const _dfs_xz_btree_t & src); - _dfs_xz_btree_t(const _dfs_xz_btree_t & src); - //const _dfs_xz_btree_t & operator=(const _dfs_xz_btree_t & src) - //{ - // return *this; - //}; - //_dfs_xz_btree_t(const _dfs_xz_btree_t & src) - //{ - //}; -private: - int _xz_store_fhead( - dfs_btree_store_info_t & store_info, - int64_t & file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead) const; - int _xz_update_stored_fhead( - dfs_btree_store_info_t & store_info, - const int64_t file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead) const; - int _xz_load_fhead( - dfs_btree_load_info_t & load_info, - int64_t & file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead); -protected: - inline int _xz_inc_root_ref_counter(const dfs_bt_root_t & bt_root) const { - return _bt_inc_root_ref_counter(bt_root); - }; - inline int _xz_dec_root_ref_counter(const dfs_bt_root_t & bt_root) const { - return _bt_dec_root_ref_counter(bt_root); - }; - void _xz_set_cancel_checkpointing(bool is_cancel) { - _bt_set_cancel_checkpointing(is_cancel); - return ; - }; - void _xz_update_mutation_counter(const bool is_batch_mode) { - _bt_update_mutation_counter(is_batch_mode); - return ; - }; - void _xz_update_max_cow_mutation_counter(void) const { - _bt_update_max_cow_mutation_counter(); - return ; - }; - // 功能:把已经设置的checkpoint存储到文件中 - // 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 - // 返回:0 for success, other values for error - int _xz_store_checkpointing( - const dfs_bt_root_t & bt_root, - dfs_btree_store_info_t & store_info) const; - // - // 功能:把先前存储在文件的checkpoint加载到内存中 - // 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 - // 返回:0 for success, other values for error - int _xz_load_checkpointing( - dfs_bt_root_t & new_bt_root, - dfs_btree_load_info_t & load_info); -protected: - // 功能:获得B树最小元素 - // 返回: 成功(即使树空)返回0, 其他值错误 - int _xz_get_smallest( - const dfs_bt_root_t & bt_root, - PCDU & pcdu) const; - // - // 功能:获得B树最大元素 - // 返回: 成功(即使树空)返回0, 其他值错误 - int _xz_get_largest( - const dfs_bt_root_t & bt_root, - PCDU & pcdu) const; - // - // 功能:获得刚好比输入项srct小的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较小元素存在,其值复制到tobj,drill_info指向搜索key的结果。 - // 返回:0 for no error, other values for error - int _xz_get_smaller( - const dfs_bt_root_t & bt_root, - const K & key, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const; - int _xz_get_smaller( - const dfs_bt_root_t & bt_root, - const DU & srcdu, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const; - // 功能:获得刚好比输入的srct大的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较大元素存在,其值复制到tobj,drill_info指向搜索srct的结果。 - // 返回:0 for no error, other values for error - int _xz_get_larger( - const dfs_bt_root_t & bt_root, - const K & key, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const; - int _xz_get_larger( - const dfs_bt_root_t & bt_root, - const DU & srcdu, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const; -protected: - // 功能:把项t插入或更新到B树中。 - // insert:tobj包含的关键字在B树中不存在,则加入B树并返回成功,否则返回失败。 - // update:tobj包含的关键字在B树存在就更新其值为tobj并返回成功,否则返回失败。 - // insert_update:先执行insert,如果该项存在就再执行update。 - // 输入:项tobj - // 输出:更新后的树的根节点 - // 如果原来项存在且old_pt非空,则其值复制到*old_pt。 - // return: 0 for success, other values for error - int _xz_insert( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist); - int _xz_update( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist); - int _xz_insert_update( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist); - // 功能:如果一个项存在,则删除;否则,不做任何事情。 - // 输出:更新后的树的根节点 - // 如果原来项存在,则pcdu为指向其的指针,否则是NULL。 - // return: 0 for success, other values for error - int _xz_del( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const K & key, - T * old_pt, - bool & is_old_exist); - int _xz_del( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist); -protected: - //return: 0 for success, other values for error - //May return 0 even if obj_index is invalid and *ppdu is set to NULL. - inline int _get_exist_obj_for_mutate(const uint64_t obj_index, PDU & pdu) const; - //return: 0 for success, other values for error - //Notice: the obj must exist. - inline BAIDU_INLINE int _get_exist_obj(const uint64_t obj_index, PCDU & pcdu) const ; - //return: 0 for success, other values for error - //May return 0 even if obj_index is invalid and *ppcdu is set to NULL. - inline int _get_may_not_exist_obj(const uint64_t obj_index, PCDU & pcdu) const; -protected: - //return: 0 for success, other values for error - //以tobj为基础生成一个新的T对象 - inline int _add_obj(const DU & duobj, uint64_t & obj_index); -//protected: -// //告诉obj做必要的工作,在fp_btree中,当对象删除时,用来减少字符串的引用计数。 -// inline int _del_obj(const uint64_t obj_index); -private: - //return: 0 for success, other values for error - //cmp: -1, 0, 1 for less than, equal, great than - inline BAIDU_INLINE int _compare_obj_obj(const DU & duobj1, const DU & duobj2, int & cmp) const; - inline BAIDU_INLINE int _compare_obj_key(const DU & duobj1, const K & key2, int & cmp) const; - inline BAIDU_INLINE int _inc_obj_ref_counter(const uint64_t obj_index, uint64_t & ref_counter); - inline BAIDU_INLINE int _dec_obj_ref_counter(const uint64_t obj_index, uint64_t & ref_counter); -protected: - //// return: 0 for success, other values for error - //virtual int vir_get_total_obj_ref_counter_in_ary(uint64_t & total_ref_counter) const; - // return: 0 for success, other values for error - virtual int vir_get_total_in_use_obj_num_in_ary(uint64_t & total_in_use_obj_num) const; - // Return: 0 for success, other values for error - virtual int vir_obj_store_size( - const uint64_t obj_index, - uint64_t & store_size, - dfs_btree_store_info_t & store_info) const; - // return: 0 for success, other values for error - virtual int vir_store_obj( - const uint64_t obj_index, - dfs_btree_store_info_t & store_info) const; - // return: 0 for success, other values for error - virtual int vir_load_obj( - uint64_t & obj_index, - dfs_btree_load_info_t & load_info); - //// return: 0 for success, other values for error - //virtual int vir_get_obj_ref_counter(const uint64_t obj_index, uint64_t & ref_counter) const; - virtual int vir_inc_obj_ref_counter(const uint64_t obj_index); - virtual int vir_dec_obj_ref_counter(const uint64_t obj_index); - virtual int vir_inc_obj_ary_ref_counter(const uint64_t * obj_index_ary, const int32_t obj_num); - virtual int vir_dec_obj_ary_ref_counter(const uint64_t * obj_index_ary, const int32_t obj_num); -protected: - // - // return: 0 for success, other values for error - // cmp: -1, 0, 1 for less than, equal, great than - //virtual int vir_compare_index_index(const uint64_t obj1_index, const uint64_t obj2_index, int & cmp) const; - virtual int vir_compare_index_obj( - const dfs_bt_root_t & bt_root, - const uint64_t obj1_index, - const void * pobj2, - int & cmp) const; - virtual int vir_compare_index_key( - const dfs_bt_root_t & bt_root, - const uint64_t obj1_index, - const void * pkey2, - int & cmp) const; - - virtual int vir_search_ary_by_index( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const uint64_t obj2_index, - int & ins_pos, - uint64_t & obj_index) const; - virtual int vir_search_ary_by_obj( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pobj2, - int & ins_pos, - uint64_t & obj_index) const; - virtual int vir_search_ary_by_key( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pkey2, - int & ins_pos, - uint64_t & obj_index) const; - virtual int vir_verify_index_ary( - const dfs_bt_root_t & bt_root, - const uint64_t * obj_index_ary, - const int32_t obj_num, - bool & is_inc_order) const; -public: - // return: 0 for success, other values for error - int xz_get_in_use_num_in_2d_ary( - uint64_t & in_use_obj_num, - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const; -protected: - void _xz_clear_statistic_info(void) { - _t_2d_ary.clear_statistic_info(); - this->_bt_clear_statistic_info(); - }; - void _xz_log_statistic_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname) const { - _t_2d_ary.log_statistic_info(org_log_level, filename, lineno, funcname, "xz", "t_2d_ary"); - this->_bt_log_statistic_info(org_log_level, filename, lineno, funcname, "xz"); - }; - void _xz_log_debug_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname) const { - _t_2d_ary.log_debug_info(org_log_level, filename, lineno, funcname, "xz", "t_2d_ary"); - this->_bt_log_debug_info(org_log_level, filename, lineno, funcname, "xz"); - }; - uint64_t _xz_get_mem_size(void) const { - return this->_bt_get_mem_size()+_get_bt2d_ary_mem_size(); - }; - uint64_t _get_bt2d_ary_mem_size() const { - return _t_2d_ary.get_mem_size(); - }; -}; - - -template -int _dfs_xz_btree_t::init( - const uint32_t bt_instance_pos, - dfs_bt_root_t & new_wr_bt_root) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - if ((err = dfs_btree_t::init(bt_instance_pos, new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_btree_t::init() returns 0x%x", err); - } - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; -}; - -//return: 0 for success, other values for error -//May return 0 even if obj_index is invalid and *ppdu is set to NULL. -template -inline int _dfs_xz_btree_t::_get_exist_obj_for_mutate( - const uint64_t obj_index, - PDU & pdu) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _t_2d_ary.get_exist_t_unit(obj_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.get_exist_t_unit() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index=0x%lx, pdu=0x%p", obj_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } - - return err; -}; -//return: 0 for success, other values for error -//Notice: the obj must exist. -template -inline BAIDU_INLINE int _dfs_xz_btree_t::_get_exist_obj( - const uint64_t obj_index, - PCDU & pcdu) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - if ((err = _t_2d_ary.get_exist_t_unit(obj_index, pdu)) != 0 || NULL == pdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.get_exist_t_unit() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index=0x%lx, pdu=0x%p", obj_index, pdu); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } else { - pcdu = pdu; - } - - return err; -}; -//return: 0 for success, other values for error -//May return 0 even if obj_index is invalid and *ppcdu is set to NULL. -template -inline int _dfs_xz_btree_t::_get_may_not_exist_obj( - const uint64_t obj_index, - PCDU & pcdu) const { - PDU pdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - if ((err = _t_2d_ary.get_may_not_exist_t_unit(obj_index, pdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.get_may_not_exist_t_unit() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index=0x%lx, pdu=0x%p", obj_index, pdu); - } else { - pcdu = pdu; - } - - return err; -}; - -//return: 0 for success, other values for error -//以tobj为基础生成一个新的T对象 -template -inline int _dfs_xz_btree_t::_add_obj( - const DU & duobj, - uint64_t & obj_index) { - PDU pdu = NULL; - int err = 0; - - if ((err = _t_2d_ary.acquire_t(&duobj, obj_index, &pdu)) != 0) { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, "_t_2d_ary.acquire_t() returns 0x%x", err); - } else if (UNDEF_INDEX == obj_index || NULL == pdu) { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, - "_t_2d_ary.acquire_t() succeeds, but obj_index=0x%lx, pt=NULL", - obj_index); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_ACQUIRE); - } else { - //if ((err = vir_add_index(key_index)) != 0) - //{ - // key_index = UNDEF_INDEX; - //} - } - - return err; -}; - -//template -//inline int _dfs_xz_btree_t::_del_obj(const uint64_t obj_index) -//{ -// PDU pdu = NULL; -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// -// if ((err = this->_get_exist_obj_for_mutate(obj_index, pdu)) != 0 || NULL == pdu) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_get_exist_obj_for_mutate() returns 0x%x", err); -// err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); -// } -// else if ((err = pdu->gc_obj(this->bt_get_extra_info())) != 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "pcdu->gc_obj(this->bt_get_extra_info()) returns 0x%x", err); -// } -// -// return err; -//}; - - -//return: 0 for success, other values for error -//cmp: -1, 0, 1 for less than, equal, great than -template -inline int _dfs_xz_btree_t::_compare_obj_obj( - const DU & duobj1, - const DU & duobj2, - int & cmp) const { - cmp = 1; - if (duobj1 == duobj2) { - cmp = 0; - } else if (duobj1 < duobj2) { - cmp = -1; - } else { - cmp = 1; - } - - return 0; -}; -//return: 0 for success, other values for error -//cmp: -1, 0, 1 for less than, equal, great than -template -inline BAIDU_INLINE int _dfs_xz_btree_t::_compare_obj_key( - const DU & duobj1, - const K & key2, - int & cmp) const { - if (duobj1 == key2) { - cmp = 0; - } else if (duobj1 < key2) { - cmp = -1; - } else { - cmp = 1; - } - - return 0; -}; - -template -inline int _dfs_xz_btree_t::_inc_obj_ref_counter( - const uint64_t obj_index, - uint64_t & ref_counter) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //_bt_inc_key_ref_inc_counter(); - ref_counter = UNDEF_REF_COUNTER; - if ((err = _t_2d_ary.inc_t_ref_counter(obj_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.inc_t_ref_counter() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } else if (0 == ref_counter || UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter=%ld", ref_counter); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, ref_counter=%ld", - obj_index, ref_counter); - } - - return err; -}; -template -int _dfs_xz_btree_t::_dec_obj_ref_counter( - const uint64_t obj_index, - uint64_t & ref_counter) { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //DFS_BT_DEBUG_TRAP; - //_bt_inc_key_ref_dec_counter(); - ref_counter = UNDEF_REF_COUNTER; - - if ((err = _t_2d_ary.dec_t_ref_counter(obj_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.dec_t_ref_counter() returns 0x%x", err); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } else if (UNDEF_REF_COUNTER == ref_counter) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "ref_counter=%ld", ref_counter); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, ref_counter=%ld", - obj_index, ref_counter); - } - - return err; -}; - -//// return: 0 for success, other values for error -//virtual int vir_get_total_obj_ref_counter_in_ary(uint64_t & total_ref_counter) const -//{ -// int err = 0; - -// if ((err = _t_2d_ary.get_total_ref_counter(total_ref_counter)) != 0) -// { -// DF_WRITE_LOG_US(DF_UL_LOG_FATAL, -// "_t_2d_ary.get_total_ref_counter() returns 0x%x, total_ref_counter=%ld", -// err, total_ref_counter); -// } -// else -// { -// --total_ref_counter; //deduct the ref_counter of [0] -// } - -// return err; -//}; -// return: 0 for success, other values for error -template -int _dfs_xz_btree_t::vir_get_total_in_use_obj_num_in_ary( - uint64_t & total_in_use_obj_num) const { - int err = 0; - - if ((err = _t_2d_ary.get_in_use_num(total_in_use_obj_num)) != 0) { - DF_WRITE_LOG_US(DF_UL_LOG_FATAL, - "_t_2d_ary.get_in_use_num() returns 0x%x, total_in_use_obj_num=%ld", - err, total_in_use_obj_num); - } - - return err; -}; -// Return: 0 for success, other values for error -template -int _dfs_xz_btree_t::vir_obj_store_size( - const uint64_t obj_index, - uint64_t & store_size, - dfs_btree_store_info_t & store_info) const { - PCDU pcdu = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - store_size = 0; - if(store_info.get_store_t_type() == dfs_btree_store_info_t::STORE_T_INDEX) { - store_size = sizeof(uint64_t); - } else if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); - } else { - store_size = pcdu->get_store_size(); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, store_size=%ld", - obj_index, store_size); - } - - return err; -}; -// return: 0 for success, other values for error -template -int _dfs_xz_btree_t::vir_store_obj( - const uint64_t obj_index, - dfs_btree_store_info_t & store_info) const { - PCDU pcdu = NULL; - uint64_t key_seq = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if(store_info.get_store_t_type() == dfs_btree_store_info_t::STORE_T_INDEX) { - if ((err = store_info.get_kept_obj_seq(obj_index, key_seq)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.get_kept_obj_seq() returns 0x%x", err); - } else if ((err = store_info.store_data(key_seq)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.store_data() returns 0x%x", err); - } - } else if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj() returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = pcdu->store( - store_info.get_buf(), - store_info.get_buf_size(), - store_info.get_data_pos())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pcdu->store() returns 0x%x", err); - } else if (store_info.get_store_t_type() == dfs_btree_store_info_t::STORE_T_VALUE_KEEP_T_INDEX) { - if ((err = store_info.keep_obj_index(obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.keep_obj_index() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "key_seq=%lu, obj_index=0x%lx", - key_seq, obj_index); - DF_WRITE_LOG_US(log_level, - "store_buf_size=%ld/data_pos=%ld", - store_info.get_buf_size(), store_info.get_data_pos()); - } - - return err; -}; -// return: 0 for success, other values for error -template -int _dfs_xz_btree_t::vir_load_obj( - uint64_t & obj_index, - dfs_btree_load_info_t & load_info) { - DU duobj; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - obj_index = UNDEF_INDEX; - duobj.init(); - if(load_info.get_store_t_type() == dfs_btree_load_info_t::STORE_T_INDEX) { - if ((err = load_info.load_data(obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.load_data() returns 0x%x", err); - } - } else if ((err = duobj.load( - load_info.get_buf(), - load_info.get_data_len(), - load_info.get_data_pos())) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "duobj.load() returns 0x%x", err); - } else if ((err = this->_add_obj(duobj, obj_index)) != 0) { //以tobj为基础生成一个新的T对象 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_add_obj() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, load_buf_data_len/data_pos=%ld/%ld", - obj_index, load_info.get_data_len(), load_info.get_data_pos()); - } - - return err; -}; -//// return: 0 for success, other values for error -//virtual int vir_get_obj_ref_counter(const uint64_t obj_index, uint64_t & ref_counter) const -//{ -// int log_level = DF_UL_LOG_NONE; -// int err = 0; -// -// ref_counter = UNDEF_REF_COUNTER; -// if ((err = _t_2d_ary.get_t_ref_counter(obj_index, ref_counter)) != 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_t_2d_ary.get_t_ref_counter() returns 0x%x", err); -// //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); -// } -// else if (UNDEF_REF_COUNTER == ref_counter) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "ref_counter=%ld", ref_counter); -// err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); -// } - -// if (DF_UL_LOG_NONE != log_level) -// { -// DF_WRITE_LOG_US(log_level, -// "obj_index=0x%lx, ref_counter=%ld", -// obj_index, ref_counter); -// } - -// return err; -//}; -template -int _dfs_xz_btree_t::vir_inc_obj_ref_counter( - const uint64_t obj_index) { - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _inc_obj_ref_counter(obj_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_obj_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index=0x%lx, ref_counter=%ld", obj_index, ref_counter); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } - - return err; -}; -template -int _dfs_xz_btree_t::vir_dec_obj_ref_counter( - const uint64_t obj_index) { - uint64_t ref_counter = UNDEF_REF_COUNTER; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //DFS_BT_DEBUG_TRAP; - if ((err = _dec_obj_ref_counter(obj_index, ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_obj_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index=0x%lx, ref_counter=%ld", obj_index, ref_counter); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - } - - return err; -}; - -template -int _dfs_xz_btree_t::vir_inc_obj_ary_ref_counter( - const uint64_t * obj_index_ary, - const int32_t obj_num) { - uint64_t ref_counter = UNDEF_REF_COUNTER; - int32_t pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "null obj_index_ary parameter"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - for (pos = 0; pos < obj_num; ++pos) { - ref_counter = UNDEF_REF_COUNTER; - if ((err = _inc_obj_ref_counter(obj_index_ary[pos], ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_inc_obj_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index_ary[pos]=0x%lx, ref_counter=%ld", - obj_index_ary[pos], ref_counter); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - break; - } - } - } - - //不能在此处报告obj_index_ary[pos](因为obj_index_ary可能为NULL) - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_num=%d, pos=%d", - obj_num, pos); - } - - return err; -}; -template -int _dfs_xz_btree_t::vir_dec_obj_ary_ref_counter( - const uint64_t * obj_index_ary, - const int32_t obj_num) { - uint64_t ref_counter = UNDEF_REF_COUNTER; - int32_t pos = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - DFS_BT_DEBUG_TRAP; - if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "null obj_index_ary parameter"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - for (pos = 0; pos < obj_num; ++pos) { - ref_counter = UNDEF_REF_COUNTER; - if ((err = _dec_obj_ref_counter(obj_index_ary[pos], ref_counter)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_dec_obj_ref_counter() returns 0x%x", err); - DF_WRITE_LOG_US(log_level, "obj_index_ary[pos]=0x%lx, ref_counter=%ld", - obj_index_ary[pos], ref_counter); - //err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_REF_COUNTER); - break; - } - } - } - - //不能在此处报告obj_index_ary[pos](因为obj_index_ary可能为NULL) - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_num=%d, pos=%d", - obj_num, pos); - } - - return err; -}; - -// -// return: 0 for success, other values for error -// cmp: -1, 0, 1 for less than, equal, great than -//virtual int vir_compare_index_index(const uint64_t obj1_index, const uint64_t obj2_index, int & cmp) const -//{ -// PCDU pcdu1 = NULL; -// PCDU pcdu2 = NULL; -// int log_level = DF_UL_LOG_NONE; -// int err = 0; - -// cmp = 1; -// if (obj1_index == obj2_index) -// { -// cmp = 0; -// } -// else if ((err = _get_exist_obj(obj1_index, pcdu1)) != 0 || NULL == pcdu1) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj1_index...) returns 0x%x", err); -// err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); -// } -// else if ((err = _get_exist_obj(obj2_index, pcdu2)) != 0 || NULL == pcdu2) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj2_index...) returns 0x%x", err); -// err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); -// } -// else if ((err = _compare_obj_obj(*pcdu1, *pcdu2, cmp)) != 0) -// { -// log_level = DF_UL_LOG_FATAL; -// DF_WRITE_LOG_US(log_level, "_compare_obj_obj() returns 0x%x", err); -// } - -// if (DF_UL_LOG_NONE != log_level) -// { -// DF_WRITE_LOG_US(log_level, -// "obj1_index=0x%lx, obj2_index=0x%lx, cmp=%d", -// obj1_index, obj2_index, cmp); -// } - -// return err; -//}; -template -int _dfs_xz_btree_t::vir_compare_index_obj( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t obj1_index, - const void * pobj2, - int & cmp) const { - PCDU pcdu1 = NULL; - PCDU pcdu2 = (PCDU)pobj2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - cmp = 1; - if ((err = _get_exist_obj(obj1_index, pcdu1)) != 0 || NULL == pcdu1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj1_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); - } else if (NULL == pcdu2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pcdu2"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _compare_obj_obj(*pcdu1, *pcdu2, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_obj() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj1_index=0x%lx, pobj2=0x%p, cmp=%d", - obj1_index, pobj2, cmp); - } - - return err; -}; -template -int _dfs_xz_btree_t::vir_compare_index_key( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t obj1_index, - const void * pkey2, - int & cmp) const { - PCDU pcdu1 = NULL; - PCK pckey2 = (const K *)pkey2; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - cmp = 1; - if ((err = _get_exist_obj(obj1_index, pcdu1)) != 0 || NULL == pcdu1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj1_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_OBJ_NULL_POINTER); - } else if (NULL == pckey2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pckey2"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_KEY_NULL_POINTER); - } else if ((err = _compare_obj_key(*pcdu1, *pckey2, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_key() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj1_index=0x%lx, pkey2=0x%p, cmp=%d", - obj1_index, pkey2, cmp); - } - - return err; -}; - - -template -int _dfs_xz_btree_t::vir_search_ary_by_index( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const uint64_t obj2_index, - int & ins_pos, - uint64_t & obj_index) const { - PCDU pcdu1 = NULL; - PCDU pcdu2 = NULL; - - int cmp = 1; - int32_t pos1 = 0; - int32_t pos2 = 0; - int32_t mid = 0; - - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ins_pos = 0; - obj_index = UNDEF_INDEX; - if ((err = _get_exist_obj(obj2_index, pcdu2)) != 0 || NULL == pcdu2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj2_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == obj_index_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pos1 = 0; - pos2 = obj_num-1; - while (pos1 <= pos2) { - mid = (pos1+pos2)/2; - if ((err = _get_exist_obj(obj_index_ary[mid], pcdu1)) != 0 || NULL == pcdu1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index_ary[mid]...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - break; - } else if ((err = _compare_obj_obj(*pcdu1, *pcdu2, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_obj() returns 0x%x", err); - break; - } else if (0 == cmp) { - //找到了 - pos1 = mid; - break; - } else if (cmp > 0) { - pos2 = mid-1; - } else { //if (cmp < 0) - pos1 = mid+1; - } - } - ins_pos = pos1; - if (0 == err && 0 == cmp) { - if (pos1 >= obj_num || pos1 < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "cmp == 0 && (pos1 >= obj_num || pos1 < 0)"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_SUBKEY_OVERFLOW); - } else { - obj_index = obj_index_ary[pos1]; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj2_index=0x%lx, ins_pos=%d, obj_index=0x%lx", - obj2_index, ins_pos, obj_index); - DF_WRITE_LOG_US(log_level, - "pos1=%d, pos2=%d, mid=%d", - pos1, pos2, mid); - if (NULL != obj_index_ary && obj_num > 0) { - BT_DF_WRITE_LOG_INT64S(log_level, "obj_index_ary", obj_index_ary, obj_num); - } - } - - return err; -}; -template -int _dfs_xz_btree_t::vir_search_ary_by_obj( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pobj2, - int & ins_pos, - uint64_t & obj_index) const { - PCDU pcdu1 = NULL; - PCDU pcdu2 = (PCDU)pobj2; - - int cmp = 1; - int32_t pos1 = 0; - int32_t pos2 = 0; - int32_t mid = 0; - - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ins_pos = 0; - obj_index = UNDEF_INDEX; - if (NULL == pcdu2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pcdu2"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == obj_index_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pos1 = 0; - pos2 = obj_num-1; - while (pos1 <= pos2) { - mid = (pos1+pos2)/2; - if ((err = _get_exist_obj(obj_index_ary[mid], pcdu1)) != 0 || NULL == pcdu1) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index_ary[mid]...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - break; - } else if ((err = _compare_obj_obj(*pcdu1, *pcdu2, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_obj() returns 0x%x", err); - break; - } else if (0 == cmp) { - //找到了 - pos1 = mid; - break; - } else if (cmp > 0) { - pos2 = mid-1; - } else { //if (cmp < 0) - pos1 = mid+1; - } - } - ins_pos = pos1; - if (0 == err && 0 == cmp) { - if (pos1 >= obj_num || pos1 < 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "cmp == 0 && (pos1 >= obj_num || pos1 < 0)"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_SUBKEY_OVERFLOW); - } else { - obj_index = obj_index_ary[pos1]; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "pobj2=0x%p, ins_pos=%d, obj_index=0x%lx", - pobj2, ins_pos, obj_index); - DF_WRITE_LOG_US(log_level, - "pos1=%d, pos2=%d, mid=%d", - pos1, pos2, mid); - if (NULL != obj_index_ary && obj_num > 0) { - BT_DF_WRITE_LOG_INT64S(log_level, "obj_index_ary", obj_index_ary, obj_num); - } - } - - return err; -}; -template -int _dfs_xz_btree_t::vir_search_ary_by_key( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t * obj_index_ary, - const int32_t obj_num, - const void * pkey2, - int & ins_pos, - uint64_t & obj_index) const { - PCDU pcdu1 = NULL; - PCK pckey2 = (const K *)pkey2; - - int cmp = 1; - int32_t pos1 = 0; - int32_t pos2 = 0; - int32_t mid = 0; - - int log_level = DF_UL_LOG_NONE; - int err = 0; - - ins_pos = 0; - obj_index = UNDEF_INDEX; - if (NULL == pckey2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pckey2"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_KEY_NULL_POINTER); - } else if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == obj_index_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - pos1 = 0; - pos2 = obj_num-1; - while (pos1 <= pos2) { - mid = (pos1+pos2)/2; - if (BAIDU_UNLIKELY((err = _get_exist_obj(obj_index_ary[mid], pcdu1)) != 0 || NULL == pcdu1)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index_ary[mid]...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - break; - } else if (BAIDU_UNLIKELY((err = _compare_obj_key(*pcdu1, *pckey2, cmp)) != 0)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_key() returns 0x%x", err); - break; - } else if (0 == cmp) { - //找到了 - pos1 = mid; - break; - } else if (cmp > 0) { - pos2 = mid-1; - } else { //if (cmp < 0) - pos1 = mid+1; - } - } - ins_pos = pos1; - if (0 == err && 0 == cmp) { - if (BAIDU_UNLIKELY(pos1 >= obj_num || pos1 < 0)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "cmp == 0 && (pos1 >= obj_num || pos1 < 0)"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_SUBKEY_OVERFLOW); - } else { - obj_index = obj_index_ary[pos1]; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "pkey2=0x%p, ins_pos=%d, obj_index=0x%lx", - pkey2, ins_pos, obj_index); - DF_WRITE_LOG_US(log_level, - "pos1=%d, pos2=%d, mid=%d", - pos1, pos2, mid); - if (NULL != obj_index_ary && obj_num > 0) { - BT_DF_WRITE_LOG_INT64S(log_level, "obj_index_ary", obj_index_ary, obj_num); - } - } - - return err; -}; - -template -int _dfs_xz_btree_t::vir_verify_index_ary( - const dfs_bt_root_t & /*bt_root*/, - const uint64_t * obj_index_ary, - const int32_t obj_num, - bool & is_inc_order) const { - PCDU pcdu1 = NULL; - PCDU pcdu2 = NULL; - int32_t j = 0; - int32_t cmp = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_inc_order = false; - - if (NULL == obj_index_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == obj_index_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if (obj_num <= 1) { - is_inc_order = true; - } else { - j = 0; - if ((err = _get_exist_obj(obj_index_ary[j], pcdu2)) != 0 || NULL == pcdu2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index_ary[j]...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - is_inc_order = true; - ++j; - while (j < obj_num) { - pcdu1 = pcdu2; - if ((err = _get_exist_obj(obj_index_ary[j], pcdu2)) != 0 || NULL == pcdu2) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index_ary[j]...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - is_inc_order = false; - break; - } else if ((err = _compare_obj_obj(*pcdu1, *pcdu2, cmp)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_compare_obj_obj() returns 0x%x", err); - is_inc_order = false; - break; - } else if (cmp >= 0) { - is_inc_order = false; - break; - } - ++j; - } - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "j=%d, cmp=%d, is_inc_order=%d", - j, cmp, is_inc_order); - if (NULL != obj_index_ary && obj_num > 0) { - BT_DF_WRITE_LOG_INT64S(log_level, "obj_index_ary", obj_index_ary, obj_num); - } - } - - return err; -}; - - -// return: 0 for success, other values for error -template -int _dfs_xz_btree_t::xz_get_in_use_num_in_2d_ary( - uint64_t & in_use_obj_num, - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - in_use_obj_num = 0; - in_use_leaf_node_num = 0; - in_use_mid_node_num = 0; - - if ((err = _t_2d_ary.get_in_use_num(in_use_obj_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_t_2d_ary.get_in_use_num() returns 0x%x", err); - } else if ((err = this->bt_get_in_use_node_num_in_2d_ary( - in_use_leaf_node_num, - in_use_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_in_use_node_num_in_2d_ary() returns 0x%x", err); - } - - return err; -}; - - -// 功能:获得B树最小元素并填充drill_info -// 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使树空)返回0, 其他值错误 -template -int _dfs_xz_btree_t::_xz_get_smallest( - const dfs_bt_root_t & bt_root, - PCDU & pcdu) const { - dfs_btree_drill_t drill_info; - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_smallest(bt_root, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_smallest() returns 0x%x", err); - } else if (UNDEF_INDEX != obj_index) { //smallest obj existed - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - obj_index, drill_info.get_drill_ptr()); - } - - return err; -}; - -// -// 功能:获得B树最大元素并填充drill_info -// 输出:若存在(B树非空),则pct指向它且key_index为其值,否则pct为NULL且key_index为UNDEF_INDEX -// 返回: 成功(即使树空)返回0, 其他值错误 -template -int _dfs_xz_btree_t::_xz_get_largest( - const dfs_bt_root_t & bt_root, - PCDU & pcdu) const { - dfs_btree_drill_t drill_info; - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_largest(bt_root, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_largest() returns 0x%x", err); - } else if (UNDEF_INDEX != obj_index) { //smallest obj existed - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, drill_info.get_drill_ptr()=%d", - obj_index, drill_info.get_drill_ptr()); - } - - return err; -}; - -// -// 功能:获得刚好比输入项srct小的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较小元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 -// 返回:0 for no error, other values for error -template -int _dfs_xz_btree_t::_xz_get_smaller( - const dfs_bt_root_t & bt_root, - const K & key, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const { - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_smaller_by_key(bt_root, (const void *)&key, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_smaller_by_key() returns 0x%x", err); - } - //smaller obj existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "&key=0x%p, obj_index=0x%lx", - &key, obj_index); - } - - return err; -}; -template -int _dfs_xz_btree_t::_xz_get_smaller( - const dfs_bt_root_t & bt_root, - const T & srct, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const { - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_smaller_by_obj(bt_root, (const void *)&srct, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_smaller_by_key() returns 0x%x", err); - } - //smaller obj existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "&srct=0x%p, obj_index=0x%lx", - &srct, obj_index); - } - - return err; -}; - -// 功能:获得刚好比输入的srct大的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较大元素存在,pct指向它,否则pct为NULL,drill_info指向搜索srct的结果。 -// 返回:0 for no error, other values for error -template -int _dfs_xz_btree_t::_xz_get_larger( - const dfs_bt_root_t & bt_root, - const K & key, - dfs_btree_drill_t & drill_info,PCDU & pcdu) const { - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_larger_by_key(bt_root, (const void *)&key, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_larger_by_key() returns 0x%x", err); - } - //larger obj existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "&key=0x%p, obj_index=0x%lx", - &key, obj_index); - } - - return err; -}; -template -int _dfs_xz_btree_t::_xz_get_larger( - const dfs_bt_root_t & bt_root, - const T & srct, - dfs_btree_drill_t & drill_info, - PCDU & pcdu) const { - uint64_t obj_index = UNDEF_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - pcdu = NULL; - - if ((err = this->_get_larger_by_obj(bt_root, (const void *)&srct, drill_info, obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_larger_by_key() returns 0x%x", err); - } - //larger obj existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "&srct=0x%p, obj_index=0x%lx", - &srct, obj_index); - } - - return err; -}; - - -// 功能:把项t插入或更新到B树中。 -// insert:如果T的id为UNDEF_ID则为其申请一个新ID。如果T的id在B树中不存在,则加入B树,否则不做操作并返回UNDEF_ID。 -// update:如果T的id在B树存在就更新其值为t,否则返回UNDEF_ID。 -// insert_update:先执行insert,如果该项存在就再执行update。 -// 输入:项t -// 输出:更新后的树的根节点 -// 如果原来项存在且old_pt非空,则其值复制到*old_pt。 -//return: 0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_insert( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist) { - DU new_duobj(tobj); - PCDU pcdu = NULL; - uint64_t old_obj_index = UNDEF_INDEX; - uint64_t new_obj_index = UNDEF_INDEX; - dfs_btree_drill_t drill_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_old_exist = false; - - if ((err = this->_search_by_obj( - old_wr_bt_root, - (const void *)&tobj, - drill_info, - old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_obj() returns 0x%x", err); - } - //存在 - else if (UNDEF_INDEX != old_obj_index) { - if ((err = _get_exist_obj(old_obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(old_obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //复制旧对象:一定要在更新B树之前,因为之后就对象可能被释放并调用了init() - if (NULL != old_pt) { - *old_pt = *((const T *)pcdu); - } - is_old_exist = true; - } - } - //不存在 - else { //if (UNDEF_INDEX == old_obj_index) - if ((err = this->_add_obj(new_duobj, new_obj_index)) != 0) { //以tobj为基础生成一个新的T对象 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_add_obj() returns 0x%x", err); - } else if ((err = this->_insert_to_btree( - old_wr_bt_root, - new_wr_bt_root, - new_obj_index, - drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_insert_to_btree() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_obj_index=0x%lx, old_obj_index=0x%lx", - new_obj_index, old_obj_index); - } - - return err; -}; - -// 功能:把项t插入或更新到B树中。 -// insert:如果T的id为UNDEF_ID则为其申请一个新ID。如果T的id在B树中不存在,则加入B树,否则不做操作并返回UNDEF_ID。 -// update:如果T的id在B树存在就更新其值为t,否则返回UNDEF_ID。 -// insert_update:先执行insert,如果该项存在就再执行update。 -// 输入:项t -// 输出:更新后的树的根节点 -// 如果原来项存在且old_pt非空,则其值复制到*old_pt。 -//return: 0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_update( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist) { - DU new_duobj(tobj); - PCDU pcdu = NULL; - uint64_t old_obj_index = UNDEF_INDEX; - uint64_t new_obj_index = UNDEF_INDEX; - dfs_btree_drill_t drill_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_old_exist = false; - - if ((err = this->_search_by_obj( - old_wr_bt_root, - (const void *)&tobj, - drill_info, - old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_obj() returns 0x%x", err); - } else if (UNDEF_INDEX != old_obj_index) { - //exist - if ((err = _get_exist_obj(old_obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(old_obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //复制旧对象:一定要在更新B树之前,因为之后就对象可能被释放并调用了init() - if (NULL != old_pt) { - *old_pt = *((const T *)pcdu); - } - is_old_exist = true; - - if ((err = this->_add_obj(new_duobj, new_obj_index)) != 0) { //以tobj为基础生成一个新的T对象 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_add_obj() returns 0x%x", err); - } else if ((err = this->_update_of_btree( - old_wr_bt_root, - new_wr_bt_root, - new_obj_index, - drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_of_btree() returns 0x%x", err); - } - } - } else { //not existed - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_obj_index=0x%lx, old_obj_index=0x%lx", - new_obj_index, old_obj_index); - } - - return err; -}; - -// 功能:把项t插入或更新到B树中。 -// insert:如果T的id为UNDEF_ID则为其申请一个新ID。如果T的id在B树中不存在, -// 则加入B树,否则不做操作并返回失败。 -// update:如果T的id在B树存在就更新其值为t,否则返回UNDEF_ID。 -// insert_update:先执行insert,如果该项存在就再执行update。 -// 输入:项t -// 输出:更新后的树的根节点 -// 如果原来项存在且old_pt非空,则其值复制到*old_pt。 -//return: 0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_insert_update( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist) { - DU new_duobj(tobj); - PCDU pcdu = NULL; - uint64_t old_obj_index = UNDEF_INDEX; - uint64_t new_obj_index = UNDEF_INDEX; - dfs_btree_drill_t drill_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_old_exist = false; - - if ((err = this->_search_by_obj( - old_wr_bt_root, - (const void *)&tobj, - drill_info, - old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_obj() returns 0x%x", err); - } else if ((err = this->_add_obj(new_duobj, new_obj_index)) != 0) { //以tobj为基础生成一个新的T对象 - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_add_obj() returns 0x%x", err); - } else if (UNDEF_INDEX != old_obj_index) { //existed - if ((err = _get_exist_obj(old_obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(old_obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //复制旧对象:一定要在更新B树之前,因为之后就对象可能被释放并调用了init() - if (NULL != old_pt) { - *old_pt = *((const T *)pcdu); - } - is_old_exist = true; - - if ((err = this->_update_of_btree( - old_wr_bt_root, - new_wr_bt_root, - new_obj_index, - drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_of_btree() returns 0x%x", err); - } - } - } else { //not exist - if ((err = this->_insert_to_btree( - old_wr_bt_root, - new_wr_bt_root, - new_obj_index, - drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_insert_to_btree() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "new_obj_index=0x%lx, old_obj_index=0x%lx", - new_obj_index, old_obj_index); - } - - return err; -}; - - -// 功能:如果一个项存在,则删除;否则,不做任何事情。 -// 输出:is_deleted: true如果项存在,false如果项不存在 -// 输出:更新后的树的根节点 -// 如果原来项存在,则pcdu为指向其的指针,否则是NULL。 -//return: 0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_del( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const K & key, - T * old_pt, - bool & is_old_exist) { - PCDU pcdu = NULL; - uint64_t old_obj_index = UNDEF_INDEX; - dfs_btree_drill_t drill_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_old_exist = false; - - if ((err = this->_search_by_key( - old_wr_bt_root, - (const void *)&key, - drill_info, - old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } else if (UNDEF_INDEX != old_obj_index) { - if ((err = _get_exist_obj(old_obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(old_obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //复制旧对象:一定要在更新B树之前,因为之后就对象可能被释放并调用了init() - if (NULL != old_pt) { - *old_pt = *((const T *)pcdu); - } - is_old_exist = true; - - if ((err = this->_del_from_btree(old_wr_bt_root, new_wr_bt_root, drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_del_from_btree() returns 0x%x", err); - } else { - } - } - } - - return err; -}; -template -int _dfs_xz_btree_t::_xz_del( - const dfs_bt_root_t & old_wr_bt_root, - dfs_bt_root_t & new_wr_bt_root, - const T & tobj, - T * old_pt, - bool & is_old_exist) { - PCDU pcdu = NULL; - uint64_t old_obj_index = UNDEF_INDEX; - dfs_btree_drill_t drill_info; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - is_old_exist = false; - - if ((err = this->_search_by_obj( - old_wr_bt_root, - (const void *)&tobj, - drill_info, - old_obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_obj() returns 0x%x", err); - } else if (UNDEF_INDEX != old_obj_index) { - if ((err = _get_exist_obj(old_obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(old_obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //复制旧对象:一定要在更新B树之前,因为之后就对象可能被释放并调用了init() - if (NULL != old_pt) { - *old_pt = *((const T *)pcdu); - } - is_old_exist = true; - - if ((err = this->_del_from_btree(old_wr_bt_root, new_wr_bt_root, drill_info)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_del_from_btree() returns 0x%x", err); - } else { - } - } - } - - return err; -}; - -// 功能:把已经设置的checkpoint存储到文件中 -// 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 -// 返回:0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_store_checkpointing( - const dfs_bt_root_t & bt_root, - dfs_btree_store_info_t & store_info) const { - //const dfs_sbt_root_t & sbt_root = _bt_get_sbt_root(bt_root); - dfs_xz_btree_fhead_t xz_btree_fhead; - dfs_btree_fhead_t btree_fhead; - int64_t file_head_offset = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - log_level = this->CKP_LOG_LEVEL; - - if ((err = _xz_store_fhead(store_info, file_head_offset, xz_btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_store_fhead() returns 0x%x", err); - } else if ((err = this->_bt_store_tree(bt_root, store_info, btree_fhead)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_store_tree() returns 0x%x", err); - } else if ((err = _xz_update_stored_fhead(store_info, file_head_offset, xz_btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_update_stored_fhead() returns 0x%x", err); - } else if ((err = store_info.flush_data()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.flush_data() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "xz_btree_fhead.total_data_len=%ld, file_head_offset=%ld", - xz_btree_fhead.total_data_len, file_head_offset); - } - - return err; -}; - -// 功能:把先前存储在文件的checkpoint加载到内存中 -// 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 -// 返回:0 for success, other values for error -template -int _dfs_xz_btree_t::_xz_load_checkpointing( - dfs_bt_root_t & new_bt_root, - dfs_btree_load_info_t & load_info) { - //dfs_sbt_root_t sbt_root; - dfs_xz_btree_fhead_t xz_btree_fhead; - dfs_btree_fhead_t btree_fhead; - int64_t file_head_offset = 0; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - log_level = this->CKP_LOG_LEVEL; - if ((err = _xz_load_fhead(load_info, file_head_offset, xz_btree_fhead)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_load_fhead() returns 0x%x", err); - } else if ((err = this->_bt_load_tree( - new_bt_root, - load_info, - btree_fhead)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_store_tree() returns 0x%x", err); - } - //move the file to the correct position - else if ((err = load_info.file_seek(file_head_offset+xz_btree_fhead.total_data_len)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.file_seek() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "xz_btree_fhead.total_data_len=%ld, file_head_offset=%ld", - xz_btree_fhead.total_data_len, file_head_offset); - } - - return err; -}; - - -template -int _dfs_xz_btree_t::_xz_store_fhead( - dfs_btree_store_info_t & store_info, - int64_t & file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead) const { - int err = 0; - - file_head_offset = store_info.get_cur_file_offset(); - //zhangyan04@baidu.com - //memset(&xz_btree_fhead, 0, sizeof(xz_btree_fhead)); - bzero(&xz_btree_fhead,sizeof(xz_btree_fhead)); - - xz_btree_fhead.size = sizeof(xz_btree_fhead); - xz_btree_fhead.ver = XZ_BTREE_VER; - xz_btree_fhead.major_tag = store_info.get_major_tag(); - xz_btree_fhead.minor_tag = XZ_BTREE_TAG; - - err = store_info.store_buf(&xz_btree_fhead, sizeof(xz_btree_fhead)); - - return err; -}; - -template -int _dfs_xz_btree_t::_xz_update_stored_fhead( - dfs_btree_store_info_t & store_info, - const int64_t file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead) const { - int err = 0; - - xz_btree_fhead.total_data_len = store_info.get_cur_file_offset() - file_head_offset; - xz_btree_fhead.total_leaf_node_num = store_info.get_total_leaf_node_num() ; - xz_btree_fhead.total_mid_node_num = store_info.get_total_mid_node_num() ; - xz_btree_fhead.total_key_num = store_info.get_total_key_num() ; - err = store_info.rewrite_data(&xz_btree_fhead, sizeof(xz_btree_fhead), file_head_offset); - - return err; -}; - -template -int _dfs_xz_btree_t::_xz_load_fhead( - dfs_btree_load_info_t & load_info, - int64_t & file_head_offset, - dfs_xz_btree_fhead_t & xz_btree_fhead) { - uint32_t unread_len = 0; - const uint32_t unread_head = sizeof(dfs_xz_btree_fhead_t)-sizeof(dfs_btree_fhead_base_t); - int log_level = DF_UL_LOG_NONE; - int err = 0; - - file_head_offset = load_info.get_cur_file_offset(); - //zhangyan04@baidu.com - //memset(&xz_btree_fhead, 0, sizeof(xz_btree_fhead)); - bzero(&xz_btree_fhead,sizeof(xz_btree_fhead)); - - //此时最大长度不知道,暂时设置为基本头的长度 - load_info.set_max_file_offset(file_head_offset+sizeof(dfs_btree_fhead_base_t)); - //加载基本头信息 - if ((err = load_info.load_buf( - (void *)((dfs_btree_fhead_base_t *)&xz_btree_fhead), - sizeof(dfs_btree_fhead_base_t))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.load_buf(dfs_btree_fhead_base_t) returns 0x%x", err); - } else if (load_info.get_major_tag() != xz_btree_fhead.major_tag) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_MAJOR_TAG); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_MAJOR_TAG); - } else if (XZ_BTREE_TAG != xz_btree_fhead.minor_tag) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_MINOR_TAG); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_MINOR_TAG); - } else if (XZ_BTREE_VER < xz_btree_fhead.ver) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_HEAD_VER); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_HEAD_VER); - } else if (xz_btree_fhead.size < sizeof(dfs_btree_fhead_base_t)) { - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_LOAD_HEAD_SIZE); - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, ERRINFO_BT_LOAD_HEAD_SIZE); - } else { - unread_len = xz_btree_fhead.size-sizeof(dfs_btree_fhead_base_t); - - //设置准确的最大长度 - load_info.set_max_file_offset(file_head_offset+xz_btree_fhead.total_data_len); - - //加载扩展头信息:头信息尺寸可能不等于sizeof(xz_btree_fhead) - if ((err = load_info.load_buf( - (void *)((dfs_xz_btree_fhead_ext_t *)&xz_btree_fhead), - MIN(unread_len, unread_head))) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - "load_info.load_buf(dfs_xz_btree_fhead_ext_t) returns 0x%x", - err); - } else if (unread_len > unread_head) { - if ((err = load_info.skip_data_len(unread_len-unread_head)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US( - log_level, - "load_info.skip_data_len(unread_len-unread_head) returns 0x%x", - err); - } - } - } - - load_info.set_total_nums( - xz_btree_fhead.total_leaf_node_num , - xz_btree_fhead.total_mid_node_num , - xz_btree_fhead.total_key_num); - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "xz_btree_fhead.total_data_len=%ld, file_head_offset=%ld", - xz_btree_fhead.total_data_len, file_head_offset); - DF_WRITE_LOG_US(log_level, - "load_info.get_major_tag()=0x%x, xz_btree_fhead.major_tag=0x%x", - load_info.get_major_tag(), xz_btree_fhead.major_tag); - DF_WRITE_LOG_US(log_level, - "XZ_BTREE_TAG=0x%x, xz_btree_fhead.minor_tag=0x%x", - XZ_BTREE_TAG, xz_btree_fhead.minor_tag); - DF_WRITE_LOG_US(log_level, - "XZ_BTREE_VER=0x%x, xz_btree_fhead.ver=0x%x", - XZ_BTREE_VER, xz_btree_fhead.ver); - DF_WRITE_LOG_US(log_level, - "unread_len=0x%x, unread_head=0x%x, xz_btree_fhead.size=0x%x", - unread_len, unread_head, xz_btree_fhead.size); - } - - return err; -}; - - -//xz_btree with public interfaces and lock mechanism -template -class dfs_xz_btree_t : - virtual public dfs_bt_const_t, -public dfs_btree_lock_t, -private dfs_bt2d_ary_t, ROW_SIZE>, - //private dfs_rc_set_t, - private _dfs_xz_btree_t, K, ROW_SIZE> { -private: - enum cconst_private { - DEF_BT_INSTANCE_POS = 0, - }; -private: - //typedef T *PT; - //typedef const T *PCT; - typedef dfs_gc_du_t DU; - typedef DU *PDU; - typedef const DU *PCDU; - typedef K *PK; - typedef const K *PCK; - typedef dfs_bt2d_ary_t t_ary_t; - typedef void * pvoid; - typedef dfs_rc_set_t rc_root_set_t; -private: - dfs_init_t _init_state; - rc_root_set_t _rc_root_set; - dfs_rc_indexer_t _ckp_root_indexer; //当前checkpoint根节点在rc_root_set_t中的位置 - volatile uint32_t _is_batch_mutate_mode; - uint32_t _reserved; - //for test only -#ifdef TEST_RWLOCK_TIME - pthread_rwlock_t _test_locker; -#endif //#ifdef TEST_RWLOCK_TIME -public: - dfs_xz_btree_t() : - _dfs_xz_btree_t(*((t_ary_t *)this)) { - init(); - }; - virtual ~dfs_xz_btree_t() { -#ifdef TEST_RWLOCK_TIME - //for test only - pthread_rwlock_destroy(&_test_locker); -#endif //#ifdef TEST_RWLOCK_TIME - }; - int init(void); -private: - //Disable operator=() and copy constructor - const dfs_xz_btree_t & operator=(const dfs_xz_btree_t & src); - dfs_xz_btree_t(const dfs_xz_btree_t & src); - //const dfs_xz_btree_t & operator=(const dfs_xz_btree_t & src) - //{ - // return *this; - //}; - //dfs_xz_btree_t(const dfs_xz_btree_t & src) : - // _dfs_xz_btree_t() - //{ - //}; -private: - //对当前的wr_root进行快照(需要更新_max_cow_mutation_counter) - inline int _snapshot_wr_root_indexer( - dfs_rc_indexer_t & rc_indexer) const; - //获得当前wr_root,但不进行快照(也不更新_max_cow_mutation_counter) - inline int _retrieve_wr_root_indexer( - dfs_rc_indexer_t & rc_indexer, - const dfs_bt_root_t *& pbt_root) const; - //进行修改(insert/update...)后更新当前wr_root - inline int _update_wr_root_indexer(const dfs_bt_root_t & bt_root); - inline int _get_root( - const dfs_rc_indexer_t & rc_indexer, - const dfs_bt_root_t *& pbt_root) const; -protected: - //增加/减少根节点引用计数 - virtual int vir_inc_root_ref_counter(const dfs_bt_root_t & bt_root) const; - virtual int vir_dec_root_ref_counter(const dfs_bt_root_t & bt_root) const; -public: - // 功能:搜索一个项,存在则返回true,否则返回false。对应项存在时其值被复制到tagt - // 如果prc_indexer非空则指向一个根节点,操作在该根节点进行,否则在当前根节点进行; - // 如果search()及其他读操作的dfs_rc_indexer_t非空,则修改操作适用batch mode - bool search(const K & key, T & tagt, const dfs_rc_indexer_t * prc_indexer = NULL) const; - bool search(const T & srct, T & tagt, const dfs_rc_indexer_t * prc_indexer = NULL) const; - - // 功能:is_batch_mutate_mode为true则允许batch mutation,seacrh等读操作时 - // 需要提供有效的dfs_rc_indexer_t;为false时禁止batch mutation, - // search等操作可以提供空的dfs_rc_indexer_t。 - // 说明:batch_mutate_mode为true时更新速度快,但search()等读操作的dfs_rc_indexer_t必须非空 - // 返回:0 for success, other values for error - int set_batch_mutate_mode( - const bool is_batch_mutate_mode, - const dfs_btree_lock_hold_t * plock_hold = NULL); - bool get_batch_mutate_mode(void) const; - // - // 功能:把项t插入或更新到B树中。 - // insert:如果K在B树中不存在,则加入B树并返回成功,否则不做操作并返回失败。 - // update:如果K在B树中存在,则更新之并返回成功,否则不做操作并返回失败。 - // insert_update:如果项不存在则执行insert,否则执行update。 - // 输入:项t - // 如果原来项存在且old_pt非空,则其值复制到*old_pt。 - // 返回:操作成功返回true,否则返回false - bool insert( - const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - bool update( - const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - bool insert_update( - const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - // - // 功能:如果一个项存在,则删除;否则,不做任何事情。 - // 如果原来项存在且old_pt非空,则其值复制到*old_pt。 - // 返回:true如果删除成功,false如果删除失败(例如项不存在) - bool del( - const K & key, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - bool del( - const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - // 功能:清空整个树。 - // 返回:0 for success, other values for error - int clear(const dfs_btree_lock_hold_t * plock_hold = NULL); - //功能:验证整个树的顺序和每个节点分支个数 - //返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 - int verify(const dfs_rc_indexer_t * prc_indexer = NULL) const; -public: //obsolete APIs - int set_serial_read_write_state( - const bool is_serial_read_write, - bool & is_success, - const dfs_btree_lock_hold_t * plock_hold = NULL) { - return 0; - }; - int get_serial_read_write_state( - bool & is_serial_read_write, - const dfs_btree_lock_hold_t * plock_hold = NULL) const { - return 0; - }; -public: - // return: 0 for success, other values for error - int get_total_num( - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const; - // return: 0 for success, other values for error - int get_in_use_num_in_2d_ary( - uint64_t & in_use_key_num, - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const; - // return: 0 for success, other values for error - int empty_btree_check( - const bool is_should_empty, - const dfs_btree_lock_hold_t * plock_hold = NULL) const; - // return: 0 for success, other values for error - // Should be called in locked state and without checkpointing or other COW(load or store) - int sanitary_check(const dfs_btree_lock_hold_t * plock_hold = NULL); - void clear_statistic_info(const dfs_btree_lock_hold_t * plock_hold = NULL); - void log_statistic_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname, - const dfs_btree_lock_hold_t * plock_hold = NULL) const; - void log_debug_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname, - const dfs_btree_lock_hold_t * plock_hold = NULL) const; - uint64_t get_mem_size(const dfs_btree_lock_hold_t * plock_hold = NULL) const; -public: - // - // 功能:获得B树最小元素 - // 输出:如果B树非空,则最小项的值被复制到tobj,否则tobj被初始化 - // 返回:最小元素存在则返回true,最小元素不存在(如B树为空)返回false。 - bool get_smallest(T & tobj, const dfs_rc_indexer_t * prc_indexer = NULL) const; - // 功能:获得B树最大元素 - // 输出:如果B树非空,则最大项的值被复制到tobj,否则tobj被初始化 - // 返回:最大元素存在则返回true,最大元素不存在(如B树为空)返回false。 - bool get_largest(T & tobj, const dfs_rc_indexer_t * prc_indexer = NULL) const; - // 功能:获得刚好比输入项srct小的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较小元素存在,则其值被复制到tagt,否则tagt被初始化 - // 返回:较小元素存在则返回true,较小元素不存在返回false。 - bool get_smaller( - const K & key, - T & tagt, - dfs_btree_drill_t * pdrill_info = NULL, - const dfs_rc_indexer_t * prc_indexer = NULL) const; - bool get_smaller( - const T & srct, - T & tagt, - dfs_btree_drill_t * pdrill_info = NULL, - const dfs_rc_indexer_t * prc_indexer = NULL) const; - // 功能:获得刚好比输入的srct大的元素 - // 输入:srct不需要在B树中存在 - // 输出:如果较大元素存在,则其值被复制到tagt,否则tagt被初始化 - // 返回:较大元素存在则返回true,较大元素不存在返回false。 - bool get_larger( - const K & key, - T & tagt, - dfs_btree_drill_t * pdrill_info = NULL, - const dfs_rc_indexer_t * prc_indexer = NULL) const; - bool get_larger( - const T & srct, - T & tagt, - dfs_btree_drill_t * pdrill_info = NULL, - const dfs_rc_indexer_t * prc_indexer = NULL) const; -public: - //功能:设置或取消checkpoint状态 - //输入:is_cancel:true取消checkpoint点及进行中的checkpoing操作,false设置一个新的checkpoint点 - // 参数max_wait_microseconds不再使用 - //建议:仅用此函数取消进行中的checkpoint,通过snapshot()获得一个checkpoint - //返回:0: 设置或取消成功,取消不存在的checkpoint状态也返回0 - int set_checkpoint_state( - const bool is_cancel, - const int64_t max_wait_microseconds, - const dfs_btree_lock_hold_t * plock_hold = NULL); - int get_checkpoint_state(void) const { - return this->_bt_is_cancel_checkpointing() ; - }; -public: - //获得当前B树的一个快照,不再使用后尽快调用rc_indexer.init()以释放快照占用的内存 - int snapshot( - dfs_rc_indexer_t & rc_indexer, - const dfs_btree_lock_hold_t * plock_hold = NULL); - // - // 功能:把已经设置的checkpoint存储到文件中 - // 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 - // 返回:0 for success, other values for error - int store_checkpointing( - const dfs_write_proc_t write_proc, - void * file_info, - const dfs_btree_lock_hold_t * plock_hold = NULL, - const dfs_rc_indexer_t * prc_indexer = NULL); - // - // 功能:把先前存储在文件的checkpoint加载到内存中 - // 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 - // 返回:0 for success, other values for error - int load_checkpointing( - const dfs_read_proc_t read_proc, - void * file_info, - const dfs_btree_lock_hold_t * plock_hold = NULL); - -//////////////////////////////////////////////////////////// -//zhangyan04@baidu.com -//新增接口.. -//内部接口,请勿使用... - bool zy_search(const K & key, - T & tagt, - const dfs_rc_indexer_t * prc_indexer) const; - int zy_insert(const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - int zy_insert_update(const T & tobj, - T * old_pt = NULL, - const dfs_btree_lock_hold_t * plock_hold = NULL); - bool zy_get_smallest_p(T ** tobj, - const dfs_rc_indexer_t * prc_indexer) const; - bool zy_get_largest_p(T ** tobj, - const dfs_rc_indexer_t * prc_indexer) const; - bool zy_get_smaller_p(const T & srct, - T ** tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const; - bool zy_get_larger_p(const T & srct, - T ** tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const; - int zy_get_total_num(const dfs_rc_indexer_t *prc_indexer, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mod_node_num) const; -//////////////////////////////////////////////////////////// -}; - - -template -int dfs_xz_btree_t::init(void) { - //const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - //dfs_rc_indexer_t old_rc_indexer; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (_init_state.is_not_init_yet()) { - _is_batch_mutate_mode = 0; - _reserved = 0; - - if ((err = dfs_btree_lock_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "dfs_btree_lock_t::init() returns 0x%x", err); - } else if ((err = t_ary_t::init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "t_ary_t::init() returns 0x%x", err); - } else if ((err = _rc_root_set.init((dfs_btree_t *)this)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set::init() returns 0x%x", err); - } else if ((err = _dfs_xz_btree_t::init( - DEF_BT_INSTANCE_POS, - new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "_dfs_xz_btree_t::init() returns 0x%x", - err); - } - //把rc_root_set_t的当前indexer设置为修改后的root - else if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } -#ifdef TEST_RWLOCK_TIME - //for test only - else if ((err = pthread_rwlock_init(&_test_locker, NULL)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rwlock_init(&_test_locker,NULL) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - _init_state.set_init_result(err); - } else { - err = _init_state.get_init_result(); - } - - return err; -}; - - -//对当前的wr_root进行快照(需要更新_max_cow_mutation_counter) -template -inline int dfs_xz_btree_t::_snapshot_wr_root_indexer( - dfs_rc_indexer_t & rc_indexer) const { - const dfs_bt_root_t * pbt_root = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //更新_max_cow_mutation_counter - this->_xz_update_max_cow_mutation_counter(); - - if ((err = _rc_root_set.retrieve_cur_index(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set.retrieve_cur_index() returns 0x%x", err); - } else if ((err = _get_root(rc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - ; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "rc_indexer._index=%lu, pbt_root=0x%p", - ((dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(), pbt_root); - } - - return err; -}; - -//获得当前wr_root,但不进行快照(也不更新_max_cow_mutation_counter) -template -inline int dfs_xz_btree_t::_retrieve_wr_root_indexer( - dfs_rc_indexer_t & rc_indexer, - const dfs_bt_root_t *& pbt_root) const - -{ - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _rc_root_set.retrieve_cur_index(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set.retrieve_cur_index() returns 0x%x", err); - } else if ((err = _get_root(rc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else { - ; - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "rc_indexer._index=%lu, pbt_root=0x%p", - ((dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(), pbt_root); - } - - return err; -}; - - -//进行修改(insert/update...)后更新当前wr_root -template -inline int dfs_xz_btree_t::_update_wr_root_indexer(const dfs_bt_root_t & bt_root) { - dfs_rc_indexer_t new_rc_indexer; - dfs_rc_indexer_t old_rc_indexer; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _rc_root_set.acquire_t(bt_root, new_rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set.update_cur_index() returns 0x%x", err); - } else if ((err = _rc_root_set.update_cur_index(new_rc_indexer, old_rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set.update_cur_index() returns 0x%x", err); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, "new_rc_indexer._index=%lu, old_rc_indexer._index=%lu", - ((const dfs_rc_indexer_ext_t *)&new_rc_indexer)->get_index(), - ((const dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - } - - return err; -}; - -//根据indexer获得dfs_bt_root -template -inline int dfs_xz_btree_t::_get_root( - const dfs_rc_indexer_t & rc_indexer, - const dfs_bt_root_t *& pbt_root) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (!rc_indexer.is_valid()) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "!rc_indexer.is_valid()"); - err = DF_BT_SET_INTERNAL_ERR(this->ERRNO_BT_INVALID_INDEX); - } else if ((err = _rc_root_set.get_t_unit(rc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_rc_root_set.get_t_unit() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "rc_indexer._index=%lu, pbt_root=0x%p", - ((dfs_rc_indexer_ext_t *)&rc_indexer)->get_index(), pbt_root); - } - - return err; -}; - -//增加/减少根节点引用计数 -template -int dfs_xz_btree_t::vir_inc_root_ref_counter( - const dfs_bt_root_t & bt_root) const { - return this->_bt_inc_root_ref_counter(bt_root); -}; -template -int dfs_xz_btree_t::vir_dec_root_ref_counter( - const dfs_bt_root_t & bt_root) const { - return this->_bt_dec_root_ref_counter(bt_root); -}; - - -// 功能:搜索一个项,存在则返回true,否则返回false。如果pt不为空,则存在时对应项的值被复制到*pt -// prc_indexer非空则指向一个根节点,操作在该根节点进行,否则在当前根节点进行; -// 如果search()及其他读操作的dfs_rc_indexer_t非空,则修改操作适用batch mode -template -bool dfs_xz_btree_t::search( - const K & key, - T & tagt, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t drill_info; - PCDU pcdu = NULL; - uint64_t obj_index = NULL_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_rdlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rdlock_wrlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - - tagt.init(); - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_unlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rwlock_unlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(BAIDU_UNLIKELY(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer))) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - if (BAIDU_UNLIKELY((err = this->_search_by_key(*pbt_root, - (const void *)&key, - drill_info, - obj_index)) != 0)) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - //object existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - tagt = *((T *)pcdu); - } - } - //object not existed - else { - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, &key=0x%p, drill_info.get_drill_ptr()=%d", - obj_index, &key, drill_info.get_drill_ptr()); - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - return (0 == err && UNDEF_INDEX != obj_index); -}; - -//这个纯粹是为了便于管理..:).和search是一样的.. -template -bool dfs_xz_btree_t::zy_search( - const K & key, - T & tagt, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t drill_info; - PCDU pcdu = NULL; - uint64_t obj_index = NULL_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_rdlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rdlock_wrlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - - tagt.init(); - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_unlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rwlock_unlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - if ((err = this->_search_by_key( - *pbt_root, - (const void *)&key, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_key() returns 0x%x", err); - } - //object existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - tagt = *((T *)pcdu); - } - } - //object not existed - else { - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, &key=0x%p, drill_info.get_drill_ptr()=%d", - obj_index, &key, drill_info.get_drill_ptr()); - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - return (0 == err && UNDEF_INDEX != obj_index); -}; - -template -bool dfs_xz_btree_t::search( - const T & srct, - T & tagt, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t drill_info; - PCDU pcdu = NULL; - DU duobj(srct); - uint64_t obj_index = NULL_INDEX; - int log_level = DF_UL_LOG_NONE; - int err = 0; - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_rdlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rdlock_wrlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - tagt.init(); - -#ifdef TEST_RWLOCK_TIME - //for test only - if ((err = pthread_rwlock_unlock((pthread_rwlock_t *)&_test_locker)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "pthread_rwlock_unlock(&_test_locker) returns 0x%x", err); - } -#endif //#ifdef TEST_RWLOCK_TIME - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - if ((err = this->_search_by_obj( - *pbt_root, - (const void *)&duobj, - drill_info, - obj_index)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_search_by_obj() returns 0x%x", err); - } - //object existed - else if (UNDEF_INDEX != obj_index) { - if ((err = _get_exist_obj(obj_index, pcdu)) != 0 || NULL == pcdu) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_exist_obj(obj_index...) returns 0x%x", err); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - tagt = *((T *)pcdu); - } - } - //object not existed - else { - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "obj_index=0x%lx, &srct=0x%p, drill_info.get_drill_ptr()=%d", - obj_index, &srct, drill_info.get_drill_ptr()); - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - return (0 == err && UNDEF_INDEX != obj_index); -}; - - -// 功能:is_batch_mutate_mode为true则允许batch mutation,seacrh等读操作时 -// 需要提供有效的dfs_rc_indexer_t;为false时禁止batch mutation, -// search等操作可以提供空的dfs_rc_indexer_t。 -// 返回:0 for success, other values for error -template -int dfs_xz_btree_t::set_batch_mutate_mode( - const bool is_batch_mutate_mode, - const dfs_btree_lock_hold_t * plock_hold) { - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果是非batch mutate mode,则max_cow_mutation_counter需要更新到 - //当前mutation_counter以免读对象被原子操作修改。 - if (!is_batch_mutate_mode) { - this->_xz_update_max_cow_mutation_counter(); - } - - df_atomic_exchange(&_is_batch_mutate_mode, (is_batch_mutate_mode) ? 1 : 0); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return err; -}; - -template -bool dfs_xz_btree_t::get_batch_mutate_mode(void) const { - return (0 != _is_batch_mutate_mode); -}; - - -// 功能:把项tobj插入或更新到B树中。 -// insert:如果T的id为UNDEF_ID则为其申请一个新ID。 -// 如果T的id在B树中不存在,则加入B树,否则不做操作并返回UNDEF_ID。 -// update:如果T的id在B树存在就更新其值为tobj,否则返回UNDEF_ID。 -// insert_update:先执行insert,如果该项存在就再执行update。 -// 如果项存在且pt非空,则其原值被复制到*pt中 -// 输入:项tobj -// 返回:项的id(操作成功)或UNDEF_ID -template -bool dfs_xz_btree_t::insert( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU new_duobj(tobj); - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_insert( - *pold_wr_bt_root, - new_wr_bt_root, - new_duobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_insert() returns 0x%x", err); - } - //原来项存在 - else if (is_old_exist) { - } - //原来项不存在 - else { - //把rc_root_set_t的当前indexer设置为修改后的root - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "batch_mutate_mode=%d", get_batch_mutate_mode()); - } - - - return (0 == err && !is_old_exist); -}; - -//修改原来的insert接口.. -//返回值使用int表示,bool已经不够了.. -//我们需要知道 -//1.内部错误,-1 -//2.原来的值存在,0 -//3.原来的值不存在,1 -template -int dfs_xz_btree_t::zy_insert( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU new_duobj(tobj); - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_insert( - *pold_wr_bt_root, - new_wr_bt_root, - new_duobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_insert() returns 0x%x", err); - } - //原来项存在 - else if (is_old_exist) { - } - //原来项不存在 - else { - //把rc_root_set_t的当前indexer设置为修改后的root - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "batch_mutate_mode=%d", get_batch_mutate_mode()); - } - - //如果存在错误.. - if(err!=0) { - return -1; - } - if(is_old_exist) { - return 0; - } else { - return 1; - } - //return (0 == err && !is_old_exist); -}; - -template -bool dfs_xz_btree_t::update( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU new_duobj(tobj); - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_update( - *pold_wr_bt_root, - new_wr_bt_root, - new_duobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update() returns 0x%x", err); - } - //原来项存在 - else if (is_old_exist) { - //把rc_root_set_t的当前indexer设置为修改后的root - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - //原来项不存在 - else { - ; - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode()=%d", get_batch_mutate_mode()); - } - - - return (0 == err && is_old_exist); -}; - -template -bool dfs_xz_btree_t::insert_update( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU new_duobj(tobj); - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_insert_update( - *pold_wr_bt_root, - new_wr_bt_root, - new_duobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update() returns 0x%x", err); - } else if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } else { - ; - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode()=%d", get_batch_mutate_mode()); - } - - - return (0 == err); -}; - -//内部错误-1 -//如果原来值存在,那么返回0 -//如果原来值不存在,那么返回1 -template -int dfs_xz_btree_t::zy_insert_update( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU new_duobj(tobj); - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_insert_update( - *pold_wr_bt_root, - new_wr_bt_root, - new_duobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update() returns 0x%x", err); - } else if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } else { - ; - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode()=%d", get_batch_mutate_mode()); - } - - if(err!=0) { - return -1; - } - if(is_old_exist) { - return 0; - } else { - return 1; - } - //return (0 == err); -}; - -// 功能:如果一个项存在,则删除;否则,不做任何事情。 -// 如果项存在且pt非空,则其原值被复制到*pt中 -// 返回:true如果删除成功,false如果删除失败(例如项不存在) -template -bool dfs_xz_btree_t::del( - const K & key, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if((err = this->_xz_del( - *pold_wr_bt_root, - new_wr_bt_root, - key, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update() returns 0x%x", err); - } - //原来项存在 - else if (is_old_exist) { - //把rc_root_set_t的当前indexer设置为修改后的root - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - //原来项不存在 - else { - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode()=%d", get_batch_mutate_mode()); - } - - - return (0 == err && is_old_exist); -}; -template -bool dfs_xz_btree_t::del( - const T & tobj, - T * old_pt, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - DU old_duobj; - bool is_old_exist = false; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - old_duobj.init(); - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(get_batch_mutate_mode()); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_xz_del( - *pold_wr_bt_root, - new_wr_bt_root, - tobj, - &old_duobj, - is_old_exist)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update() returns 0x%x", err); - } - //原来项存在 - else if (is_old_exist) { - //把rc_root_set_t的当前indexer设置为修改后的root - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - //原来项不存在 - else { - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (NULL != old_pt) { - *old_pt = *((T *)&old_duobj); - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode()=%d", get_batch_mutate_mode()); - } - - - return (0 == err && is_old_exist); -}; - -// 功能:清空整个树。 -// 返回:0 for success, other values for error -template -int dfs_xz_btree_t::clear( - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(false); //get_batch_mutate_mode() - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //先复制根节点以便获得mutation counter, next_allocate_id等信息 - new_wr_bt_root = *pold_wr_bt_root; - if ((err = this->_acquire_empty_root(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_acquire_empty_root() returns 0x%x", err); - } - //把rc_root_set_t的当前indexer设置为修改后的root - else if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - } - - - return err; -}; - - -//获得当前B树的一个快照 -template -int dfs_xz_btree_t::snapshot( - dfs_rc_indexer_t & rc_indexer, - const dfs_btree_lock_hold_t * plock_hold) { - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //把max_cow_mutation_counter更新到当前mutation_counter以免对象被原子操作修改。 - this->_xz_update_max_cow_mutation_counter(); - - if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&rc_indexer)->get_index()); - } - - - return err; -}; - - - -// return: 0 for success, other values for error -template -int dfs_xz_btree_t::get_total_num( - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - //dfs_bt_root_t * pnew_wr_bt_root = NULL; - dfs_rc_indexer_t old_rc_indexer; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - if ((err = this->bt_get_total_num( - *pold_wr_bt_root, - total_key_num, - total_leaf_node_num, - total_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_total_num() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "old_rc_indexer._index=%lu", - ((dfs_rc_indexer_ext_t *)&old_rc_indexer)->get_index()); - } - - - return err; -}; - -//zhangyan04@baidu.com -//原始的get_total_num之能够获得当前write的root的内容 -//但是有时候对于snapshot的btree也需要.. -template -int dfs_xz_btree_t::zy_get_total_num( - const dfs_rc_indexer_t * prc_indexer, - uint64_t & total_key_num, - uint64_t & total_leaf_node_num, - uint64_t & total_mid_node_num) const { - const dfs_bt_root_t * pbt_root = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - //根据snapshot的index获得root,然后去统计.. - if((err=_get_root(*prc_indexer,pbt_root))!=0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - if ((err = this->bt_get_total_num( - *pbt_root, - total_key_num, - total_leaf_node_num, - total_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_total_num() returns 0x%x", err); - } - } - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer->_index=%lu", - ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - return err; -}; - -// return: 0 for success, other values for error -template -int dfs_xz_btree_t::get_in_use_num_in_2d_ary( - uint64_t & in_use_key_num, - uint64_t & in_use_leaf_node_num, - uint64_t & in_use_mid_node_num) const { - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if ((err = this->xz_get_in_use_num_in_2d_ary( - in_use_key_num, - in_use_leaf_node_num, - in_use_mid_node_num)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "xz_get_in_use_num_in_2d_ary() returns 0x%x", err); - } - - return err; -} -// return: 0 for success, other values for error -template -int dfs_xz_btree_t::empty_btree_check( - const bool is_should_empty, - const dfs_btree_lock_hold_t * plock_hold) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - uint64_t key_num_in_btree = 0; - uint64_t key_num_in_2d_ary = 0; - uint64_t leaf_node_num_in_btree = 0; - uint64_t leaf_node_num_in_2d_ary = 0; - uint64_t mid_node_num_in_btree = 0; - uint64_t mid_node_num_in_2d_ary = 0; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else if ((err = _get_root(rc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = this->bt_get_total_num( - *pbt_root, - key_num_in_btree, - leaf_node_num_in_btree, - mid_node_num_in_btree)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "bt_get_total_num() returns 0x%x", err); - } else if ((err = this->xz_get_in_use_num_in_2d_ary( - key_num_in_2d_ary, - leaf_node_num_in_2d_ary, - mid_node_num_in_2d_ary)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "xz_get_in_use_num_in_2d_ary() returns 0x%x", err); - } else if (is_should_empty) { - if (_rc_root_set.get_in_use_num() != 1) { - DFS_BT_DEBUG_TRAP; - - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "_rc_root_set.get_in_use_num() (=%ld) != 1", - _rc_root_set.get_in_use_num()); - DF_WRITE_LOG_US(log_level, - "_ckp_root_indexer=%ld", - ((dfs_rc_indexer_ext_t *)&_ckp_root_indexer)->get_index()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_T_LEAK); - } else if (0 != key_num_in_btree) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "0 != key_num_in_btree"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_NONE_EMPTY_BTREE); - } else if ((key_num_in_btree+1) != key_num_in_2d_ary) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "(key_num_in_btree+1) == key_num_in_2d_ary"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_DIFF_NUM_IN_BT_2D_ARY); - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "is_should_empty=%d", - is_should_empty); - DF_WRITE_LOG_US(log_level, - "key_num_in_btree=%ld, key_num_in_2d_ary=%ld", - key_num_in_btree, key_num_in_2d_ary); - DF_WRITE_LOG_US(log_level, - "leaf_node_num_in_btree=%ld, leaf_node_num_in_2d_ary=%ld", - leaf_node_num_in_btree, leaf_node_num_in_2d_ary); - DF_WRITE_LOG_US(log_level, - "mid_node_num_in_btree=%ld, mid_node_num_in_2d_ary=%ld", - mid_node_num_in_btree, mid_node_num_in_2d_ary); - } - - return err; -}; -// return: 0 for success, other values for error -// Should be called in locked state and without checkpointing or other COW(load or store) -template -int dfs_xz_btree_t::sanitary_check(const dfs_btree_lock_hold_t * plock_hold) { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - if (_rc_root_set.get_in_use_num() != 1) { - DFS_BT_DEBUG_TRAP; - - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, - "_rc_root_set.get_in_use_num() (= %ld) != 1", - _rc_root_set.get_in_use_num()); - DF_WRITE_LOG_US(log_level, - "_ckp_root_indexer=%ld", - ((dfs_rc_indexer_ext_t *)&_ckp_root_indexer)->get_index()); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_T_LEAK); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else if ((err = _get_root(rc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = this->_bt_sanitary_check(*pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_bt_sanitary_check() returns 0x%x", err); - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return err; -}; -template -void dfs_xz_btree_t::clear_statistic_info(const dfs_btree_lock_hold_t * plock_hold) { - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - this->_xz_clear_statistic_info(); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return; -}; -template -void dfs_xz_btree_t::log_statistic_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname, - const dfs_btree_lock_hold_t * plock_hold) const { - uint64_t mem_size = 0; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - this->_xz_log_statistic_info(org_log_level, filename, lineno, funcname); - mem_size = this->_xz_get_mem_size(); - DF_WRITE_LOG_US(log_level,"xz_btree in-use memory=%luMB", mem_size/1024/1024); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return; -}; -template -void dfs_xz_btree_t::log_debug_info( - const int org_log_level, - const char * filename, - const int lineno, - const char * funcname, - const dfs_btree_lock_hold_t * plock_hold) const { - this->_xz_log_debug_info(org_log_level, filename, lineno, funcname); -}; - -template -uint64_t dfs_xz_btree_t::get_mem_size( - const dfs_btree_lock_hold_t * plock_hold) const { - uint64_t mem_size = 0; - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - mem_size = this->_xz_get_mem_size(); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return mem_size; -}; - - - -// -// 功能:获得B树最小元素 -// 输出:如果B树非空,则最小项的值被复制到tobj,否则tobj被初始化 -// 返回:最小元素存在则返回true,最小元素不存在(如B树为空)返回false。 -template -bool dfs_xz_btree_t::get_smallest( - T & tobj, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tobj.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_smallest(*pbt_root, pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_smallest() returns 0x%x", err); - } else if (NULL != pcdu) { - tobj = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -//返回T的指针..这个只是在snapshot的状态下面有效.. -template -bool dfs_xz_btree_t::zy_get_smallest_p( - T ** tobj, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //tobj.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_smallest(*pbt_root, pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_smallest() returns 0x%x", err); - } else if (NULL != pcdu) { - //tobj = *((const T *)pcdu); - *tobj=(T*)pcdu; - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -// 功能:获得B树最大元素 -// 输出:如果B树非空,则最大项的值被复制到tobj,否则tobj被初始化 -// 返回:最大元素存在则返回true,最大元素不存在(如B树为空)返回false。 -template -bool dfs_xz_btree_t::get_largest( - T & tobj, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tobj.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_largest(*pbt_root, pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_largest() returns 0x%x", err); - } else if (NULL != pcdu) { - tobj = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -//返回tobj的指针,必须保证在snapshot的状态.. -template -bool dfs_xz_btree_t::zy_get_largest_p( - T ** tobj, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //tobj.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_largest(*pbt_root, pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_largest() returns 0x%x", err); - } else if (NULL != pcdu) { - *tobj=(T*)pcdu; - //tobj = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -// 功能:获得刚好比输入项srct小的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较小元素存在,则其值被复制到tagt,否则tagt被初始化 -// 返回:较小元素存在则返回true,较小元素不存在返回false。 -template -bool dfs_xz_btree_t::get_smaller( - const K & key, - T & tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_smaller( - *pbt_root, - key, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_smaller() returns 0x%x", err); - } else if (NULL != pcdu) { - tagt = *((const T *)pcdu); - is_exist = true; - } - } - - return is_exist; -}; - -template -bool dfs_xz_btree_t::get_smaller( - const T & srct, - T & tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - DU duobj(srct); - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_smaller( - *pbt_root, - duobj, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_smaller() returns 0x%x", err); - } else if (NULL != pcdu) { - tagt = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -} - -//返回target的指针,必须保证在snapshot状态下面.. -template -bool dfs_xz_btree_t::zy_get_smaller_p( - const T & srct, - T ** tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - DU duobj(srct); - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_smaller( - *pbt_root, - duobj, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_smaller() returns 0x%x", err); - } else if (NULL != pcdu) { - //tagt = *((const T *)pcdu); - *tagt=(T*)pcdu; - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -} - - -// 功能:获得刚好比输入的srct大的元素 -// 输入:srct不需要在B树中存在 -// 输出:如果较大元素存在,则其值被复制到tagt,否则tagt被初始化 -// 返回:较大元素存在则返回true,较大元素不存在返回false。 -template -bool dfs_xz_btree_t::get_larger( - const K & key, - T & tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_larger( - *pbt_root, - key, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_larger() returns 0x%x", err); - } else if (NULL != pcdu) { - tagt = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -template -bool dfs_xz_btree_t::get_larger( - const T & srct, - T & tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - DU duobj(srct); - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_larger( - *pbt_root, - duobj, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_larger() returns 0x%x", err); - } else if (NULL != pcdu) { - tagt = *((const T *)pcdu); - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - -//获得target的指针,必须保证在snapshot状态下面... -template -bool dfs_xz_btree_t::zy_get_larger_p( - const T & srct, - T ** tagt, - dfs_btree_drill_t * pdrill_info, - const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_drill_t bck_drill_info; - dfs_btree_drill_t & drill_info = (NULL == pdrill_info) ? bck_drill_info : *pdrill_info; - PCDU pcdu = NULL; - DU duobj(srct); - bool is_exist = false; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - //tagt.init(); - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _xz_get_larger( - *pbt_root, - duobj, - drill_info, - pcdu)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_get_larger() returns 0x%x", err); - } else if (NULL != pcdu) { - //tagt = *((const T *)pcdu); - *tagt=(T*)pcdu; - is_exist = true; - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return is_exist; -}; - - - -//功能:验证整个树的顺序和每个节点分支个数 -//返回:返回0如果验证通过,返回非0(错误代码)如果验证失败 -template -int dfs_xz_btree_t::verify(const dfs_rc_indexer_t * prc_indexer) const { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - int log_level = DF_UL_LOG_NONE; - int err = 0; - - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - if (get_batch_mutate_mode()) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "get_batch_mutate_mode() is true but NULL == prc_indexer"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = _snapshot_wr_root_indexer(rc_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } else { - prc_indexer = &rc_indexer; - } - } else if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } - - if (0 == err) { - if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else if ((err = this->bt_verify_tree(*pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_verify() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return err; -}; - -//功能:设置或取消checkpoint状态 -//输入:is_cancel:true取消checkpoint点及进行中的checkpoing操作,false设置一个新的checkpoint点 -// 参数max_wait_microseconds不再使用 -//建议:仅用此函数取消进行中的checkpoint,通过snapshot()获得一个checkpoint -//返回:0: 设置或取消成功,取消不存在的checkpoint状态也返回0 -template -int dfs_xz_btree_t::set_checkpoint_state( - const bool is_cancel, - const int64_t /*max_wait_microseconds*/, - const dfs_btree_lock_hold_t * plock_hold) { - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - //为了避免此时写线程修改btree - //因此要锁住_mutate_locker()避免写线程工作。 - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - if (is_cancel) { - _ckp_root_indexer.init(); - } else { - if ((err = _snapshot_wr_root_indexer(_ckp_root_indexer)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_snapshot_wr_root_indexer() returns 0x%x", err); - } - } - //取消或设置checkpoint - this->_bt_set_cancel_checkpointing(is_cancel); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - return err; -}; - -// -// 功能:把已经设置的checkpoint存储到文件中 -// 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 -// 返回:0 for success, other values for error -template -int dfs_xz_btree_t::store_checkpointing( - const dfs_write_proc_t write_proc, - void * file_info, - const dfs_btree_lock_hold_t * plock_hold, - const dfs_rc_indexer_t * prc_indexer) { - dfs_rc_indexer_t rc_indexer; - const dfs_bt_root_t * pbt_root = NULL; - dfs_btree_store_info_t store_info(write_proc, file_info, MAX_T_STORE_SIZE*4); - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - log_level = this->CKP_LOG_LEVEL; - - //不论其他操作是否成功,_xz_ckp_store_begin和_xz_ckp_store_end都需要执行以清除ckp状态 - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //清除“取消store/load状态” - this->_xz_set_cancel_checkpointing(false); //is_cancel; - - if ((err = store_info.init()) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "store_info.init() returns 0x%x", err); - } else { - store_info.set_major_tag(this->XZ_BTREE_TAG); - store_info.set_store_t_value(); //store T's value - } - - if (0 == err) { - if (NULL == prc_indexer || !(prc_indexer->is_valid())) { - rc_indexer = _ckp_root_indexer; - prc_indexer = &rc_indexer; - } - - if(!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)) { - log_level = DF_UL_LOG_WARNING; - DF_WRITE_LOG_US(log_level, "!_rc_root_set.is_valid_in_use_indexer(*prc_indexer)"); - err = DF_BT_SET_NORMAL_ERR(ERRNO_BT_INVALID_INDEX); - } else if ((err = _get_root(*prc_indexer, pbt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_get_root() returns 0x%x", err); - } else if (NULL == pbt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pbt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } - } - - //只要能够得到锁,就清空_ckp_root_indexer - _ckp_root_indexer.init(); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - if (0 == err) { - if ((err = this->_xz_store_checkpointing(*pbt_root, store_info)) != 0) { - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_store_checkpointing() returns 0x%x", err); - } - } - - if (DF_UL_LOG_NONE != log_level) { - DF_WRITE_LOG_US(log_level, - "prc_indexer=%p, prc_indexer->_index=%lu", - prc_indexer, - (NULL == prc_indexer) ? - UNDEF_INDEX : ((dfs_rc_indexer_ext_t *)prc_indexer)->get_index()); - } - - - return err; -}; - -// -// 功能:把先前存储在文件的checkpoint加载到内存中 -// 参数:file_info:文件的控制信息,例如文件句柄,调用store或load时文件数据的位置等。 -// 返回:0 for success, other values for error -template -int dfs_xz_btree_t::load_checkpointing( - const dfs_read_proc_t read_proc, - void * file_info, - const dfs_btree_lock_hold_t * plock_hold) { - const dfs_bt_root_t * pold_wr_bt_root = NULL; - dfs_bt_root_t new_wr_bt_root; - dfs_rc_indexer_t old_rc_indexer; - dfs_btree_load_info_t load_info(read_proc, file_info, MAX_T_STORE_SIZE*4); - dfs_btree_lock_hold_t lock_hold; - int log_level = DF_UL_LOG_NONE; - int err = 0; - int err1 = 0; - - //Step 1. preparation - //Step 2. load the btree - //step 3. update the root - - log_level = this->CKP_LOG_LEVEL; - - //Step 1. preparation - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //清除“取消store/load状态” - this->_xz_set_cancel_checkpointing(false); //is_cancel; - - if ((err1 = load_info.init()) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "load_info.init() returns 0x%x", err); - } else { - load_info.set_major_tag(this->XZ_BTREE_TAG); - - if ((err = _retrieve_wr_root_indexer(old_rc_indexer, pold_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_retrieve_wr_root_indexer() returns 0x%x", err); - } else if (NULL == pold_wr_bt_root) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "NULL == pold_wr_bt_root"); - err = DF_BT_SET_INTERNAL_ERR(ERRNO_BT_OBJ_NULL_POINTER); - } else { - //先复制根节点以便获得mutation counter, next_allocate_id等信息 - new_wr_bt_root = *pold_wr_bt_root; - } - } - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - - //Step 2. load the btree - if (0 == err) { - if ((err1 = this->_xz_load_checkpointing(new_wr_bt_root, load_info)) != 0) { - err = err1; - log_level = (ERRNO_BT_CKP_CANCELLED == err) ? DF_UL_LOG_NOTICE : DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_load_checkpointing() returns 0x%x", err); - } - - if (0 != err) { - //发生错误后要删除已经生成的对象 - //先+1引用计数,再-1引用计数,这导致对象回收 - if ((err1 = this->_xz_inc_root_ref_counter(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_inc_root_ref_counter() returns 0x%x", err1); - } else if ((err1 = this->_xz_dec_root_ref_counter(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_xz_dec_root_ref_counter() returns 0x%x", err1); - } - } - } - - //step 3. update the root - if (0 == err) { - if ((err = BT_MUTATE_LOCK_ACQUIRE(plock_hold, lock_hold, 0)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_ACQUIRE_ERR_INFO); - } else { - //如果不是batch mode,则同时更新_max_cow_mutation_counter从而禁止修改时的指针原子替换 - this->_xz_update_mutation_counter(false); //get_batch_mutate_mode(); - - if((err = this->_update_wr_root_indexer(new_wr_bt_root)) != 0) { - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, "_update_wr_root_indexer() returns 0x%x", err); - } - - //只要能够得到锁,就清空_ckp_root_indexer - _ckp_root_indexer.init(); - - if ((err1 = BT_MUTATE_LOCK_RELEASE(plock_hold, lock_hold)) != 0) { - err = err1; - log_level = DF_UL_LOG_FATAL; - DF_WRITE_LOG_US(log_level, BT_MUTATE_LOCK_RELEASE_ERR_INFO); - } - } - } - - return err; -}; - - -#endif //__DFS_XZ_BTREE_INCLUDE_H_ - diff --git a/bsl/containers/btree/gen_xmemcpy_h.py b/bsl/containers/btree/gen_xmemcpy_h.py deleted file mode 100755 index 0bc3953d07d5386ed608e2522b24f13d50f24ced..0000000000000000000000000000000000000000 --- a/bsl/containers/btree/gen_xmemcpy_h.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -#coding:gbk -#copy[write] by dirlt(dirtysalt1987@gmail.com) - -import string -import re -import os -import sys - -#class declaration.[incluing the necessary namespace] -CLSDECL="""/* -*- c++ -*- */ -#ifndef __BSL_KV_BTREE_XMEMCPY_H__ -#define __BSL_KV_BTREE_XMEMCPY_H__ -//不要编辑这个文件..zhangyan04@baidu.com -//借鉴xiaowei的xmemcpy.但是这个东西让我非常不爽的一点就是 -//它有一个.cpp,你需要链接一个库.. -#include -#include -#include -#ifdef __SSE2__ -#include -#endif -//实现放在名字空间下面.. -namespace %(ns_name)s{ -#ifdef __SSE2__ -typedef __m128i _memcpy_unit_128_t; -#endif -typedef unsigned long long _memcpy_unit_64_t; -typedef int _memcpy_unit_32_t; -%(implement)s -//入口放在class作为静态方法.. -//class %(cls_name)s{ -//public: -static void *xmemcpy(void *dst,const void *src,size_t len){ -//这里使用long是合理的. -long _offset=(long)dst-(long)src; -//位置重叠或者是len过长.. -if(len>%(thres)d || (_offset<(long)len && _offset>(0-(long)len))){ -return ::memcpy(dst,src,len); -}else{ -return %(ns_name)s::got[len](dst,src); -} -} -//}; -} -#endif -""" - -def generator(ns_name,cls_name,SSE2): - #泛化.. - GENERAL_TEMPLATE="""//这个部分为_memcpy的实现. - %(_memcpy_implement)s - //这个部分为跳转表 - typedef void* (*_memcpy_func_t)(void *dst,const void *src); - static const _memcpy_func_t got[]={ - %(gototables)s - }; - """ - - #不同类型对应的block. - BLOCK_TYPE="""//必须使用结构体,数组不允许copy. - template struct _memcpy_block_%(aggtype)s_t{ - %(aggtype)s _data[size]; - }; - """ - - #实例化实现. - TEMPLATE="""static void * _memcpy_%(bsize)d(void *dst,const void *src){ - typedef _memcpy_block_%(aggtype)s_t<%(bsize_roundup)d> type_t; - *(type_t*)dst=*(type_t*)src; - %(extra)s - return dst; - } - """ - - #特殊的实例化实现.. - SPEC_TEMPLATE="""static void * _memcpy_%(bsize)d(void *dst,const void *src){ - %(extra)s - return dst; - } - """ - - SPEC_TEMPLATE_ZERO="""static void * _memcpy_0(void *dst,const void */*src*/){ - return dst; - } - """ - #在64位下面支持SSE2指令.. - if(SSE2): - #大于512字节的话,那么不进行优化.. - thres=512 - conf_list=[['_memcpy_unit_32_t',4,0,128], - ['_memcpy_unit_128_t',16,129,512]] - else: - thres=128 - #大于128字节的话,就不进行优化. - conf_list=[['_memcpy_unit_32_t',4,0,128]] - - #产生memcpy的实现. - _memcpy_implement="" - for conf in conf_list: - aggtype=conf[0] - sizeof_aggtype=conf[1] - #首先需要定义block type.. - block_type=BLOCK_TYPE%(locals()) - _memcpy_implement+=block_type - for i in range(conf[2],conf[3]+1): - bsize=i - bsize_roundup=i/sizeof_aggtype - extra="" - for j in range(1,sizeof_aggtype): - if((i%sizeof_aggtype)>=j): - extra+="""((char *)dst)[%d] = ((char *)src)[%d];"""%(i-j,i-j) - if(i==0): - template=SPEC_TEMPLATE_ZERO - elif(i -#include -#include -#include - -using namespace std; -//对于key需要指定各种compare的方法... -struct Key_t { - unsigned long long key; - Key_t():key(0) { - } - bool operator==(const Key_t &k)const { - return key==k.key; - } - bool operator!=(const Key_t &k)const { - return key!=k.key; - } - bool operator<(const Key_t &k)const { - return key(const Key_t &k)const { - return key>k.key; - } -}; - -struct Data_t { - unsigned long long data; - Data_t():data(0) { - } -}; - -typedef bsl::bsl_kv_btree_build kv_btree_build_t; -typedef bsl::bsl_kv_btree_search kv_btree_search_t; - -int test_insert(kv_btree_build_t &bt){ - for(int i=0; i<10; i++) { - Key_t k; - Data_t v; - k.key=i; - v.data=i; - //插入成功.. - assert(bt.set(k,v)==bsl::BTREE_INSERT_SUC); - } - for(int i=0; i<10; i++) { - Key_t k; - Data_t v; - k.key=i; - v.data=i; - //数据存在.. - assert(bt.set(k,v)==bsl::BTREE_EXIST); - } - for(int i=0; i<10; i++) { - Key_t k; - Data_t v; - k.key=i; - v.data=i; - //数据被覆盖.. - assert(bt.set(k,v,!0)==bsl::BTREE_OVERWRITE); - } - for(int i=10; i<20; i++) { - Key_t k; - Data_t v; - k.key=i; - v.data=i; - assert(bt.set(k,v,!0)==bsl::BTREE_INSERT_SUC); - } - return 0; -} - -int test_batch_mutate(kv_btree_build_t &bt){ - bt.make_batch_mutate(); - bt.end_batch_mutate(); - return 0; -} - -int test_get(kv_btree_build_t &bt){ - for(int i=0; i<20; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v.data==k.key); - } - for(int i=20; i<30; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_get_const(const kv_btree_build_t &bt){ - for(int i=0; i<20; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v.data==k.key); - } - for(int i=20; i<30; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_erase(kv_btree_build_t &bt){ - for(int i=10; i<20; i++) { - Key_t k; - k.key=i; - assert(bt.erase(k)==bsl::BTREE_EXIST); - } - for(int i=20; i<30; i++) { - Key_t k; - k.key=i; - assert(bt.erase(k)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_clear(kv_btree_build_t &bt){ - bt.clear(); - return 0; -} - -int test_store_checkpoint(kv_btree_build_t &bt){ - assert(bt.make_checkpoint()==bsl::BTREE_OK); - int fd=-1; - fd=open("bt.img",O_WRONLY | O_CREAT,0666); - assert(fd!=-1); - assert(bt.store(fd,0)==bsl::BTREE_OK); - assert(bt.end_checkpoint()==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_load_checkpoint(kv_btree_build_t &bt){ - int fd=-1; - fd=open("bt.img",O_RDONLY,0666); - assert(fd!=-1); - assert(bt.load(fd,0)==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_size(const kv_btree_build_t &bt,uint64_t v){ - assert(bt.size()==v); - return 0; -} - -int test_iterator(kv_btree_build_t &bt){ - unsigned long long v=0; - for(kv_btree_build_t::iterator it=bt.begin(); - it!=bt.end(); ++it) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v++; - } - v=0; - for(kv_btree_build_t::iterator it=bt.begin(); - it!=bt.end(); it++) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v++; - } - return 0; -} - -int test_const_iterator(const kv_btree_build_t &bt){ - unsigned long long v=0; - for(kv_btree_build_t::const_iterator it=bt.begin(); - it!=bt.end(); ++it) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v++; - } - v=0; - for(kv_btree_build_t::const_iterator it=bt.begin(); - it!=bt.end(); it++) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v++; - } - return 0; -} - -int test_reverse_iterator(kv_btree_build_t &bt){ - unsigned long long v=19; - for(kv_btree_build_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v--; - } - v=19; - for(kv_btree_build_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v--; - } - return 0; -} - -int test_const_reverse_iterator(const kv_btree_build_t &bt){ - unsigned long long v=19; - for(kv_btree_build_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v--; - } - v=19; - for(kv_btree_build_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v--; - } - return 0; -} -int test_snapshot(kv_btree_build_t &bt, - kv_btree_search_t &sbt){ - assert(bt.snapshot(sbt)==bsl::BTREE_OK); - return 0; -} - -int test_snapshot_get(kv_btree_search_t &bt){ - for(int i=0; i<20; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v.data==k.key); - } - for(int i=20; i<30; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_snapshot_get_const(const kv_btree_search_t &bt){ - for(int i=0; i<20; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v.data==k.key); - } - for(int i=20; i<30; i++) { - Key_t k; - Data_t v; - k.key=i; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} -int test_store_snapshot(kv_btree_search_t &sbt){ - int fd=-1; - fd=open("bt.img",O_WRONLY | O_CREAT,0666); - assert(fd!=-1); - assert(sbt.store(fd,0)==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_snapshot_iterator(kv_btree_search_t &bt){ - unsigned long long v=0; - for(kv_btree_search_t::iterator it=bt.begin(); - it!=bt.end(); ++it) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(key.key==v); - assert(pkey->key==v); - v++; - } - v=0; - for(kv_btree_search_t::iterator it=bt.begin(); - it!=bt.end(); it++) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v++; - } - return 0; -} - -int test_snapshot_const_iterator(const kv_btree_search_t &bt){ - unsigned long long v=0; - for(kv_btree_search_t::const_iterator it=bt.begin(); - it!=bt.end(); ++it) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v++; - } - v=0; - for(kv_btree_search_t::const_iterator it=bt.begin(); - it!=bt.end(); it++) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v++; - } - return 0; -} - -int test_snapshot_reverse_iterator(kv_btree_search_t &bt){ - unsigned long long v=19; - for(kv_btree_search_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v--; - } - v=19; - for(kv_btree_search_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - Key_t key; - key=it.ref_key(); - Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v--; - } - return 0; -} - -int test_snapshot_const_reverse_iterator(const kv_btree_search_t &bt){ - unsigned long long v=19; - for(kv_btree_search_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v--; - } - v=19; - for(kv_btree_search_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - Key_t key; - key=it.ref_key(); - const Key_t *pkey; - pkey=it.ptr_key(); - assert((*it).data==v); - assert(it->data==v); - assert(pkey->key==v); - v--; - } - return 0; -} - -int test_print_iterator(kv_btree_build_t &bt){ - for(kv_btree_build_t::iterator it=bt.begin(); it!=bt.end(); ++it) { - cout<data<data< -#include -#include -#include - -using namespace std; -//对于key需要指定各种compare的方法... -typedef string Key_t; -typedef string Data_t; -typedef bsl::bsl_kv_btree_build kv_btree_build_t; -typedef bsl::bsl_kv_btree_search kv_btree_search_t; -string strfy(unsigned int i){ - char buf[1024]; - snprintf(buf,sizeof(buf),"string.%04u",i); - return buf; -} - -int test_insert(kv_btree_build_t &bt){ - for(int i=0; i<10; i++) { - Key_t k=strfy(i); - Data_t v=strfy(i); - //插入成功.. - assert(bt.set(k,v)==bsl::BTREE_INSERT_SUC); - } - for(int i=0; i<10; i++) { - Key_t k=strfy(i); - Data_t v=strfy(i); - //数据存在.. - assert(bt.set(k,v)==bsl::BTREE_EXIST); - } - for(int i=0; i<10; i++) { - Key_t k=strfy(i); - Data_t v=strfy(i); - //数据被覆盖.. - assert(bt.set(k,v,!0)==bsl::BTREE_OVERWRITE); - } - for(int i=10; i<20; i++) { - Key_t k=strfy(i); - Data_t v=strfy(i); - assert(bt.set(k,v,!0)==bsl::BTREE_INSERT_SUC); - } - return 0; -} - -int test_batch_mutate(kv_btree_build_t &bt){ - bt.make_batch_mutate(); - bt.end_batch_mutate(); - return 0; -} - -int test_get(kv_btree_build_t &bt){ - for(int i=0; i<20; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v==k); - } - for(int i=20; i<30; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_get_const(const kv_btree_build_t &bt){ - for(int i=0; i<20; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v==k); - } - for(int i=20; i<30; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_erase(kv_btree_build_t &bt){ - for(int i=10; i<20; i++) { - Key_t k=strfy(i); - assert(bt.erase(k)==bsl::BTREE_EXIST); - } - for(int i=20; i<30; i++) { - Key_t k=strfy(i); - assert(bt.erase(k)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_clear(kv_btree_build_t &bt){ - bt.clear(); - return 0; -} - -int test_store_checkpoint(kv_btree_build_t &bt){ - assert(bt.make_checkpoint()==bsl::BTREE_OK); - int fd=-1; - fd=open("bt.img",O_WRONLY | O_CREAT,0666); - assert(fd!=-1); - assert(bt.store(fd,0)==bsl::BTREE_OK); - assert(bt.end_checkpoint()==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_load_checkpoint(kv_btree_build_t &bt){ - int fd=-1; - fd=open("bt.img",O_RDONLY,0666); - assert(fd!=-1); - assert(bt.load(fd,0)==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_size(const kv_btree_build_t &bt,uint64_t v){ - assert(bt.size()==v); - return 0; -} - -int test_iterator(kv_btree_build_t &bt){ - unsigned long long v=0; - for(kv_btree_build_t::iterator it=bt.begin(); - it!=bt.end(); ++it) { - assert((*it)==strfy(v)); - v++; - } - v=0; - for(kv_btree_build_t::iterator it=bt.begin(); - it!=bt.end(); it++) { - assert((*it)==strfy(v)); - v++; - } - return 0; -} - -int test_const_iterator(const kv_btree_build_t &bt){ - unsigned long long v=0; - for(kv_btree_build_t::const_iterator it=bt.begin(); - it!=bt.end(); ++it) { - assert((*it)==strfy(v)); - v++; - } - v=0; - for(kv_btree_build_t::const_iterator it=bt.begin(); - it!=bt.end(); it++) { - assert((*it)==strfy(v)); - v++; - } - return 0; -} - -int test_reverse_iterator(kv_btree_build_t &bt){ - unsigned long long v=19; - for(kv_btree_build_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - assert((*it)==strfy(v)); - v--; - } - v=19; - for(kv_btree_build_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - assert((*it)==strfy(v)); - v--; - } - return 0; -} - -int test_const_reverse_iterator(const kv_btree_build_t &bt){ - unsigned long long v=19; - for(kv_btree_build_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - assert((*it)==strfy(v)); - v--; - } - v=19; - for(kv_btree_build_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - assert((*it)==strfy(v)); - v--; - } - return 0; -} - -int test_snapshot(kv_btree_build_t &bt, - kv_btree_search_t &sbt){ - assert(bt.snapshot(sbt)==bsl::BTREE_OK); - return 0; -} - -int test_snapshot_get(kv_btree_search_t &bt){ - for(int i=0; i<20; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v==k); - } - for(int i=20; i<30; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_snapshot_get_const(const kv_btree_search_t &bt){ - for(int i=0; i<20; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_EXIST); - assert(bt.get(k)==bsl::BTREE_EXIST); - assert(v==k); - } - for(int i=20; i<30; i++) { - Key_t k=strfy(i); - Data_t v; - assert(bt.get(k,&v)==bsl::BTREE_NOEXIST); - } - return 0; -} - -int test_store_snapshot(kv_btree_search_t &sbt){ - int fd=-1; - fd=open("bt.img",O_WRONLY | O_CREAT,0666); - assert(fd!=-1); - assert(sbt.store(fd,0)==bsl::BTREE_OK); - close(fd); - return 0; -} - -int test_snapshot_iterator(kv_btree_search_t &bt){ - unsigned long long v=0; - for(kv_btree_search_t::iterator it=bt.begin(); - it!=bt.end(); ++it) { - assert((*it)==strfy(v)); - v++; - } - v=0; - for(kv_btree_search_t::iterator it=bt.begin(); - it!=bt.end(); it++) { - assert((*it)==strfy(v)); - v++; - } - return 0; -} - -int test_snapshot_const_iterator(const kv_btree_search_t &bt){ - unsigned long long v=0; - for(kv_btree_search_t::const_iterator it=bt.begin(); - it!=bt.end(); ++it) { - assert((*it)==strfy(v)); - v++; - } - v=0; - for(kv_btree_search_t::const_iterator it=bt.begin(); - it!=bt.end(); it++) { - assert((*it)==strfy(v)); - v++; - } - return 0; -} - -int test_snapshot_reverse_iterator(kv_btree_search_t &bt){ - unsigned long long v=19; - for(kv_btree_search_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - assert((*it)==strfy(v)); - v--; - } - v=19; - for(kv_btree_search_t::reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - assert((*it)==strfy(v)); - v--; - } - return 0; -} - -int test_snapshot_const_reverse_iterator(const kv_btree_search_t &bt){ - unsigned long long v=19; - for(kv_btree_search_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); ++it) { - assert((*it)==strfy(v)); - v--; - } - v=19; - for(kv_btree_search_t::const_reverse_iterator it=bt.rbegin(); - it!=bt.rend(); it++) { - assert((*it)==strfy(v)); - v--; - } - return 0; -} - -int test_print_iterator(kv_btree_build_t &bt){ - for(kv_btree_build_t::iterator it=bt.begin(); it!=bt.end(); ++it) { - cout<<*it< -#include -#include -#include - -using namespace std; -//对于key需要指定各种compare的方法... -struct Key_t { - unsigned long long key; - Key_t():key(0) { - } - bool operator==(const Key_t &k)const { - return key==k.key; - } - bool operator!=(const Key_t &k)const { - return key!=k.key; - } - bool operator<(const Key_t &k)const { - return key(const Key_t &k)const { - return key>k.key; - } -}; - -struct Data_t { - unsigned long long data; - Data_t():data(0) { - } -}; - -typedef bsl::bsl_kv_btree_build kv_btree_build_t; -typedef bsl::bsl_kv_btree_search kv_btree_search_t; - -//顺序插入这些数据.. -static const int DATA_NR=1000000; -void * thread_set(void *arg){ - kv_btree_build_t &bt=*(kv_btree_build_t*)arg; - for(int i=0;i -#include "bsl_kv_btree_xmemcpy.h" -int main(){ - const int SZ=4096; - unsigned char src[SZ]; - for(int i=0;i -#include -#include - -namespace bsl { - - /** - * @brief deque的迭代器 - * - */ - template - struct _deque_iterator { - typedef _deque_iterator<_Tp, _Tp&, _Tp*, _BuffSize> iterator; - typedef _deque_iterator<_Tp, const _Tp&, const _Tp*, _BuffSize> const_iterator; - - typedef std::random_access_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp** _map_pointer; - typedef _deque_iterator _self; - - value_type* _cur; - value_type* _first; - value_type* _last; - _map_pointer _node; - - static const size_type _BUFF_SIZE = sizeof(value_type)<_BuffSize? - size_type(_BuffSize/sizeof(value_type)):size_type(1); - - _deque_iterator(_Tp* __x, _map_pointer __y) - : _cur(__x), _first(NULL == __y ? NULL : *__y), - _last(NULL == __y ? NULL : *__y + _BUFF_SIZE), - _node(__y) {} - - /** - * @brief 生成空迭带器 - **/ - _deque_iterator() : _cur(NULL), _first(NULL), _last(NULL), _node(NULL) {} - - /** - * @brief 由另一迭带器复制 - * - * @param [in] __x : const iterator& - **/ - _deque_iterator(const iterator& __x) - : _cur(__x._cur), - _first(__x._first), - _last(__x._last), - _node(__x._node) {} - - reference operator*() const - { - if(NULL == _cur){ - throw bsl::NullPointerException()<() const - { - return _cur; - } - - _self& operator++() - { - ++_cur; - if (_cur == _last) { - ++_node; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _first; - } - return *this; - } - - _self operator++(int) - { - _self tmp = *this; - ++*this; - return tmp; - } - - _self operator--() - { - if (_cur == _first) { - --_node; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _last; - } - --_cur; - return *this; - } - - _self operator--(int) - { - _self tmp = *this; - --*this; - return tmp; - } - - _self& operator+=(difference_type __n) - { - const difference_type offset = __n + (_cur - _first); - if (offset >= 0 && offset < difference_type(_BUFF_SIZE)) { - _cur += __n; - } else { - const difference_type node_offset = - offset > 0 ? offset / difference_type(_BUFF_SIZE) - : -difference_type((-offset - 1) - / _BUFF_SIZE) - 1; - _node += node_offset; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _first + (offset - node_offset - * difference_type(_BUFF_SIZE)); - } - return *this; - } - - _self operator+(difference_type __n) const - { - _self tmp = *this; - return tmp += __n; - } - - _self& operator-=(difference_type __n) - { - return *this += -__n; - } - - _self operator-(difference_type __n) const - { - _self tmp = *this; - return tmp -= __n; - } - - reference operator[](difference_type __n) const - { - return *(*this + __n); - } - }; - - template - inline bool operator==(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return __x._cur == __y._cur; - } - - template - inline bool operator==(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return __x._cur == __y._cur; - } - - template - inline bool operator!=(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return !(__x == __y); - } - - template - inline bool operator!=(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return !(__x == __y); - } - - template - inline bool operator<(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return (__x._node == __y._node) ? (__x._cur < __y._cur) - : (__x._node < __y._node); - } - - template - inline bool operator<(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return (__x._node == __y._node) ? (__x._cur < __y._cur) - : (__x._node < __y._node); - } - - template - inline bool operator>(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return __y < __x; - } - - template - inline bool operator>(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return __y < __x; - } - - template - inline bool - operator<=(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return !(__y < __x); - } - - template - inline bool operator<=(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return !(__y < __x); - } - - template - inline bool operator>=(const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return !(__x < __y); - } - - template - inline bool operator>=(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return !(__x < __y); - - } - - template - inline typename _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::difference_type - operator-(const _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _deque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return typename _deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::difference_type - (_deque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::_BUFF_SIZE) - * (__x._node - __y._node - 1) + (__x._cur - __x._first) - + (__y._last - __y._cur); - } - - template - inline _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize> - operator+(ptrdiff_t __n, const _deque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x) - { - return __x + __n; - } - - - - /** - * @brief deque - * - * 双头队列, 通过一个索引表对数据块进行操作 - * 可以通过_BuffSize指定每个块的字节大小,每个块的元素大小通过 _BuffSize除元素的大小取整得到。 - * - */ - template > - class deque - { - public: - typedef typename _InnerAlloc::pool_type::template rebind<_Tp>::other _base; - - typedef typename _base::value_type value_type; - typedef typename _base::pointer pointer; - typedef typename _base::const_pointer const_pointer; - typedef typename _base::reference reference; - typedef typename _base::const_reference const_reference; - typedef typename _base::size_type size_type; - typedef typename _base::difference_type difference_type; - - typedef _deque_iterator iterator; - - typedef _deque_iterator const_iterator; - - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; - - private: - typedef typename _InnerAlloc::pool_type::template rebind::other - _base_pointer; - _base _node_alloc; /**< 内存块分配器 */ - _base_pointer _map_alloc; /**< 索引内存 分配器 */ - /**< 每个块的元素个数 */ - static const size_type _BUFF_SIZE = sizeof(_Tp) < _BuffSize? - size_type(_BuffSize / sizeof(_Tp)) : size_type(1); - /**< 索引表的大小初始为 _INITIAL_MAP_SIZE */ - enum { _INITIAL_MAP_SIZE = 8UL }; - /** - * @brief 指向头块和尾块的结构体 - * - */ - struct impl_t { - pointer cur; - pointer first; /**< 块头部 */ - pointer last; /**< 块尾部 */ - pointer* map; /**< 指向块的指针 */ - }; - - impl_t _start; /**< 块头 */ - impl_t _finish; /**< 块尾 */ - - pointer* _map_first; /**< 索引表头 */ - pointer* _map_last; /**< 索引表尾 */ - size_type _map_size; /**< 索引表大小 */ - - public: - - /* * - * @brief 默认构造函数 - * 无异常 - * 不需调create - * */ - deque(){ - _reset(); - } - - /** - * @brief 构造函数 - * @param [in] __size : size_type - * - * 失败抛异常 - * 不需调create - * - **/ - explicit deque(size_type __size) { - _reset(); - if (create(__size) != 0) { - throw BadAllocException()<= size2 - for (size_t i = size1; i > size2; -- i) { - if ( pop_back() != 0 ) { - throw BadAllocException()< - int assign(_InputIterator __first, _InputIterator __last) - { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - return _assign(__first, __last, _Integral()); - } - - template - int _assign(_Integer __n, _Integer __val, __true_type) - { - return assign(size_type(__n), value_type(__val)); - } - - template - int _assign(_InputIterator __first, _InputIterator __last, __false_type) - { - clear(); - for (_InputIterator iter = __first; iter != __last; ++iter) { - if (push_back(*iter) != 0) { - goto fail; - } - } - return 0; - fail: - clear(); - return -1; - } - - /** - * @brief 完全销毁deque, 需要再次create才能使用 - * - * @return 成功返回0 - **/ - int destroy() - { - //清空deque - clear(); - //销毁最后的内存块 - if (NULL != _start.map) { - _node_alloc.deallocate(_start.map[0], _BUFF_SIZE); - _start.map = NULL; - } - //销毁索引 - if (_map_first != NULL) { - _map_alloc.deallocate(_map_first, _map_size); - _map_first = NULL; - } - //数据重置 - _reset(); - //销毁内存池 - _node_alloc.destroy(); - _map_alloc.destroy(); - return 0; - } - - /** - * @brief 清空deque, 但不销毁内存,可以再次使用 - * - * @return 成功返回0 - **/ - int clear() - { - while (pop_back() == 0) { - } - return 0; - } - - iterator begin() - { - return iterator(_start.cur, _start.map); - } - - iterator end() - { - return iterator(_finish.cur, _finish.map); - } - - const_iterator begin() const - { - return const_iterator(_start.cur, _start.map); - } - - const_iterator end() const - { - return const_iterator(_finish.cur, _finish.map); - } - - reverse_iterator rbegin() - { - return reverse_iterator(end()); - } - - const_reverse_iterator rbegin() const - { - return const_reverse_iterator(end()); - } - - reverse_iterator rend() - { - return reverse_iterator(begin()); - } - - const_reverse_iterator rend() const - { - return const_reverse_iterator(begin()); - } - - size_type max_size() const - { - return size_type(-1); - } - - - /** - * @brief 从尾部插入元素 - * - * @param [in] __x : 插入的元素 - * @return 成功返回0,失败返回-1 - **/ - int push_back(const value_type& __x) - { - //如果未创建,则创建之 - if(0 == _map_size){ - if(create() != 0){ - return -1; - } - } - if (_finish.cur) { - pointer cur = _finish.cur++; - if (_finish.cur == _finish.last) { - if (_finish.map == _map_last) { - if (_new_map() != 0) { - //失败恢复现场 - _finish.cur = cur; - return -1; - } - } - //分配新的内存块 - pointer new_node = _node_alloc.allocate(_BUFF_SIZE); - if (NULL == new_node) { - //失败恢复现场 - _finish.cur = cur; - return -1; - } - (*(++_finish.map)) = new_node; - _finish.first = new_node; - _finish.last = new_node + _BUFF_SIZE; - _finish.cur = new_node; - } - bsl::bsl_construct(cur, __x); - return 0; - } - return -1; - } - - /** - * @brief 从头部插入元素 - * - * @param [in] __x : 插入的元素 - * @return 成功返回0,失败返回-1 - **/ - int push_front(const value_type& __x) - { - //如果未创建,则创建之 - if(0 == _map_size){ - if(create() != 0){ - return -1; - } - } - if (_start.cur) { - if (_start.cur != _start.first) { - --_start.cur; - bsl::bsl_construct(_start.cur, __x); - return 0; - } - if (_start.map == _map_first) { - if (_new_map() != 0) { - return -1; - } - } - pointer new_node = _node_alloc.allocate(_BUFF_SIZE); - if (NULL == new_node) { - return -1; - } - *(--_start.map) = new_node; - _start.first = new_node; - _start.last = new_node + _BUFF_SIZE; - _start.cur = _start.last - 1; - bsl::bsl_construct(_start.cur, __x); - return 0; - } - return -1; - } - - /** - * @brief 删除尾部元素 - * - * @return 成功返回0, 失败返回-1 - **/ - int pop_back() - { - if (_start.cur != _finish.cur) { - if (_finish.cur == _finish.first) { - _node_alloc.deallocate(_finish.first, _BUFF_SIZE); - _finish.first = *(--_finish.map); - _finish.last = _finish.first + _BUFF_SIZE; - _finish.cur = _finish.last; - } - --_finish.cur; - bsl::bsl_destruct(_finish.cur); - return 0; - } - return -1; - } - - /** - * @brief 删除头部元素 - * - * @return 成功返回0, 失败返回-1 - **/ - int pop_front() - { - if (_start.cur != _finish.cur) { - bsl::bsl_destruct(_start.cur); - ++_start.cur; - if (_start.cur == _start.last) { - _node_alloc.deallocate(_start.first, _BUFF_SIZE); - _start.first = *(++_start.map); - _start.last = _start.first + _BUFF_SIZE; - _start.cur = _start.first; - } - return 0; - } - return -1; - } - - /** - * @brief 取头部元素的引用 - * - * 如果为容器为空,则抛出异常。 - * @return 头部元素的引用 - **/ - reference front() - { - //检查是否为空 - if(_start.cur == _finish.cur){ - throw bsl::InvalidOperationException()<= size() || NULL == __val) { - return -1; - } - bsl::bsl_construct(__val, (*this)[__n]); - return 0; - } - - /** - * @brief 设置第n个元素的值为 __val - * - * @param [in] __n : 位置 - * @param [in] __val : 需要设置的值 - * @return 失败返回-1, 成功返回0 - **/ - int set(const size_type &__n, const value_type &__val) - { - if (__n >= size()) { - return -1; - } - bsl::bsl_construct(&((*this)[__n]), __val); - return 0; - } - - /** - * @brief deque的长度 - * - * @return deque的长度 - **/ - size_type size() const - { - if (_start.map == _finish.map) { - return _finish.cur - _start.cur; - } - return (_start.last - _start.cur) + - (_finish.cur - _finish.first) + - (_finish.map - _start.map - 1) * _BUFF_SIZE; - } - - /** - * @brief 重新分配空间大小,并初始化为__x - * - * @param [in] __new_size : 新的大小 - * @param [in] __x : 初始化的值 - * @return 0成功,-1失败 - **/ - int resize(size_type __new_size, const value_type& __x) - { - size_type len = size(); - if (__new_size < size()) { - for (size_type i = __new_size; i < len; ++i) { - if (pop_back() < 0) { - goto fail; - } - } - } else { - for (size_type i = len; i < __new_size; ++i) { - if (push_back(__x) < 0) { - goto fail; - } - } - } - return 0; - fail: - return -1; - - } - - /** - * @brief 重新分配空间大小 - * - * @param [in] __new_size : 新的大小 - * @return 0成功,-1失败 - **/ - int resize(size_type __new_size) - { - return resize(__new_size, value_type()); - } - - /** - * @brief 判断是否为空 - * - * @return true为空 - **/ - bool empty() const - { - return (_start.cur == _finish.cur); - } - - - /** - * @brief 与另一个deque进行交换 - * - * @param [in] __x : 进行交换的deque - **/ - void swap(deque& __x) - { - std::swap(this->_start, __x._start); - std::swap(this->_finish, __x._finish); - std::swap(this->_map_first, __x._map_first); - std::swap(this->_map_last, __x._map_last); - std::swap(this->_map_size, __x._map_size); - std::swap(this->_map_alloc, __x._map_alloc); - std::swap(this->_node_alloc, __x._node_alloc); - } - - - /** - * @brief 序列化接口 - * - * @param [in] ar : 序列化的结果 - * - * @return 成功返回0, 失败返回-1 - **/ - template - int serialization(_Archive &__ar) - { - if (bsl::serialization(__ar, size()) != 0) { - return -1; - } - for (iterator iter = begin(); iter != end(); ++iter) { - if (bsl::serialization(__ar, *iter) != 0) { - return -1; - } - } - return 0; - } - - /** - * @brief 反序列化接口 - * - * @param [in] ar : 需要反序列化的容器 - * - * @return 成功返回0, 失败返回-1, 失败的同时会清空deque - **/ - template - int deserialization(_Archive &ar) - { - size_type len = size(); - if (bsl::deserialization(ar, len) != 0) { - return -1; - } - clear(); - value_type tmp; - while (len--) { - if (bsl::deserialization(ar, tmp) != 0) { - goto fail; - } - if (push_back(tmp) != 0) { - goto fail; - } - } - - return 0; - fail: - clear(); - return -1; - } - - private: - /** - * @brief 重置deque - * - **/ - void _reset() - { - _map_first = NULL; - _map_last = NULL; - _start.cur = NULL; - _start.first = NULL; - _start.last = NULL; - _start.map = NULL; - _finish = _start; - _map_size = 0; - } - - /** - * @brief 初始化索引表 - * - * @param [in] __initialize_size : 初始化索引表的大小 - * @return 成功返回0, 失败返回-1 - **/ - int _initialize_map(size_type __initialize_size) - { - //分配内存给索引 - _map_first = _map_alloc.allocate(__initialize_size); - if (NULL == _map_first) { - goto fail; - } - _map_size = __initialize_size; - _map_last = _map_first + _map_size - 1; - _start.map = _map_first + (_map_size>>1); - //分配第一个内存块 - _start.first = _node_alloc.allocate(_BUFF_SIZE); - if (NULL == _start.first) { - goto fail; - } - //头尾内存块的初始化 - (*_start.map) = _start.first; - _start.last = _start.first + _BUFF_SIZE; - _start.cur = _start.first; - _finish = _start; - return 0; - fail: - if (_map_first != NULL) { - _map_alloc.deallocate(_map_first, __initialize_size); - _map_first = NULL; - } - _reset(); - return -1; - } - - /** - * @brief 索引表扩展 - * - * - * @return 成功返回0, 失败返回-1 - **/ - int _new_map() - { - //这里分两种情况,如果实际使用的空间没有占到一半,只进行移动 - //否则分配新的内存块。 - //这样处理可以节省一定的内存。 - const difference_type offset = _finish.map - _start.map + 1; - pointer* new_start = NULL; - if ((difference_type)_map_size > 2 * offset) { - new_start = _map_first + ((_map_size - offset) >> 1); - //判断是向前还是向后移 - //这里不用memmov的是因为我们测试的结果for循环的性能要跟好一些 - - if (new_start < _start.map) { - for (pointer* p = new_start; p < new_start + offset; ++p) { - *p = *_start.map; - ++_start.map; - } - } else { - for (pointer* p = new_start + offset - 1; p >= new_start; --p) { - *p = *_finish.map; - --_finish.map; - } - } - } else { - //分配新的内存快 - pointer* new_map = _map_alloc.allocate(_map_size << 1); - if (NULL == new_map) { - return -1; - } - //拷贝旧的索引 - new_start = new_map + (_map_size - (offset >> 1)); - memcpy(new_start, _start.map, offset * sizeof(pointer)); - _map_alloc.deallocate(_map_first, _map_size); - _map_size <<= 1; - //指针的切换 - _map_first = new_map; - _map_last = new_map + _map_size - 1; - } - _start.map = new_start; - _finish.map = new_start + offset - 1; - return 0; - } - - }; - - /** - * 交换两个相同类型的deque - * - * @param __x : 需要交换的deque - * @param __y : 需要交换的deque - **/ - template - inline void swap(deque<_Tp, _BuffSize, _InnerAlloc>& __x, - deque<_Tp, _BuffSize, _InnerAlloc>& __y) - { - __x.swap(__y); - } - - -} //namespace bsl - -#endif //__BSL_DEQUE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/containers/deque/bsl_rwseque.h b/bsl/containers/deque/bsl_rwseque.h deleted file mode 100644 index f48bbeffd049ddc49c38d25346d5bd891d4081c5..0000000000000000000000000000000000000000 --- a/bsl/containers/deque/bsl_rwseque.h +++ /dev/null @@ -1,960 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_rwseque.h,v 1.11 2009/04/07 06:35:53 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file rwseque.h - * @author baonh(baonenghui@baidu.com) - * @date 2008/07/27 14:22:17 - * @version $Revision: 1.11 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_RWSEQUE_H_ -#define __BSL_RWSEQUE_H_ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include - -#include -#include -#include - -namespace bsl { - /** - * @brief bsl_deque的迭代器 - * - * 使用迭带器有线呈安全问题,这里之所以保留迭带器主要是为了能够与stl的算法库一起连用 - */ - - template - struct _rwseque_iterator { - typedef _rwseque_iterator<_Tp, _Tp&, _Tp*, _BuffSize> iterator; - typedef _rwseque_iterator<_Tp, const _Tp&, const _Tp*, _BuffSize> const_iterator; - - typedef std::random_access_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp** _map_pointer; - typedef _rwseque_iterator _self; - - value_type* _cur; - value_type* _first; - value_type* _last; - _map_pointer _node; - - static const size_type _BUFF_SIZE = sizeof(value_type)<_BuffSize? - size_type(_BuffSize/sizeof(value_type)):size_type(1UL); - - - //当_map_pointer为空时,_first和_last置为空 - _rwseque_iterator(_Tp* __x, _map_pointer __y) - : _cur(__x), _first(NULL == __y ? NULL : *__y), - _last(NULL == __y ? NULL : *__y + _BUFF_SIZE), - _node(__y) {} - - /** - * @brief 生成空迭带器 - **/ - _rwseque_iterator() : _cur(NULL), _first(NULL), _last(NULL), _node(NULL) {} - - /** - * @brief 由另一迭带器复制 - * - * @param [in] __x : const iterator& - **/ - _rwseque_iterator(const iterator& __x) - : _cur(__x._cur), - _first(__x._first), - _last(__x._last), - _node(__x._node) {} - - reference operator*() const - { - if(NULL == _cur){ - throw bsl::NullPointerException()<() const - { - return _cur; - } - - _self& operator++() - { - ++_cur; - if (_cur == _last) { - ++_node; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _first; - } - return *this; - } - - _self operator++(int) - { - _self tmp = *this; - ++*this; - return tmp; - } - - _self operator--() - { - if (_cur == _first) { - --_node; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _last; - } - --_cur; - return *this; - } - - _self operator--(int) - { - _self tmp = *this; - --*this; - return tmp; - } - - _self& operator+=(difference_type __n) - { - const difference_type offset = __n + (_cur - _first); - if (offset >= 0 && offset < difference_type(_BUFF_SIZE)) { - _cur += __n; - } else { - const difference_type node_offset = - offset > 0 ? offset / difference_type(_BUFF_SIZE) - : -difference_type((-offset - 1) - / _BUFF_SIZE) - 1; - _node += node_offset; - _first = *_node; - _last = _first + difference_type(_BUFF_SIZE); - _cur = _first + (offset - node_offset - * difference_type(_BUFF_SIZE)); - } - return *this; - } - - _self operator+(difference_type __n) const - { - _self tmp = *this; - return tmp += __n; - } - - _self& operator-=(difference_type __n) - { - return *this += -__n; - } - - _self operator-(difference_type __n) const - { - _self tmp = *this; - return tmp -= __n; - } - - reference operator[](difference_type __n) const - { - return *(*this + __n); - } - }; - - template - inline bool operator==(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return __x._cur == __y._cur; - } - - template - inline bool operator==(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return __x._cur == __y._cur; - } - - template - inline bool operator!=(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return !(__x == __y); - } - - template - inline bool operator!=(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return !(__x == __y); - } - - template - inline bool operator<(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { - return (__x._node == __y._node) ? (__x._cur < __y._cur) - : (__x._node < __y._node); - } - - template - inline bool operator<(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return (__x._node == __y._node) ? (__x._cur < __y._cur) - : (__x._node < __y._node); - - } - - template - inline bool - operator>(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { return __y < __x; } - - template - inline bool - operator>(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { return __y < __x; } - - template - inline bool - operator<=(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { return !(__y < __x); } - - template - inline bool - operator<=(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { return !(__y < __x); } - - template - inline bool - operator>=(const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __y) - { return !(__x < __y); } - - template - inline bool - operator>=(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { return !(__x < __y); } - - template - inline typename _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::difference_type - operator-(const _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>& __x, - const _rwseque_iterator<_Tp, _RefR, _PtrR, _BuffSize>& __y) - { - return typename _rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::difference_type - (_rwseque_iterator<_Tp, _RefL, _PtrL, _BuffSize>::_BUFF_SIZE) - * (__x._node - __y._node - 1) + (__x._cur - __x._first) - + (__y._last - __y._cur); - } - - template - inline _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize> - operator+(ptrdiff_t __n, const _rwseque_iterator<_Tp, _Ref, _Ptr, _BuffSize>& __x) - { return __x + __n; } - - - template > - class rwseque - { - public: - - typedef typename _InnerAlloc::pool_type::template rebind<_Tp>::other _base; - - typedef typename _base::value_type value_type; - typedef typename _base::pointer pointer; - typedef typename _base::const_pointer const_pointer; - typedef typename _base::reference reference; - typedef typename _base::const_reference const_reference; - typedef typename _base::size_type size_type; - typedef typename _base::difference_type difference_type; - - - typedef _rwseque_iterator iterator; - - typedef _rwseque_iterator const_iterator; - - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; - - private: - - typedef typename _InnerAlloc::pool_type::template rebind::other - _base_pointer; - typedef typename _InnerAlloc::pool_type::template rebind::other - _base_lock; - typedef typename _InnerAlloc::pool_type::template rebind::other - _base_lock_list; - - _base _node_alloc; - _base_pointer _map_alloc; - _base_lock _locks_alloc; - _base_lock_list _locks_list_alloc; - - static const size_type _BUFF_SIZE = sizeof(_Tp) < _BuffSize? - size_type(_BuffSize / sizeof(_Tp)) : size_type(1); - - enum { _INITIAL_MAP_SIZE = 8 }; /**< 初始的map大小 */ - enum { _MAP_LIST_SIZE = 64 }; /**< map增加的等级,每级size翻倍 */ - enum { _LOCK_NUM = 8 }; /**< _LOCK_NUM 个连续的内存块使用一个读写锁 */ - - pointer _last; /**< 最后一个元素的指针位置 */ - size_type _finish; /**< 最后一个元素的实际偏移 */ - size_type _size; /**< 元素的长度 */ - size_type _lsize; - size_type _locks_map_size; /**< 锁的个数 */ - - pthread_rwlock_t** _locks; - pointer* _map; - size_type _map_size; /**< map的大小 */ - - pthread_rwlock_t** _locks_list[_MAP_LIST_SIZE]; - pointer* _map_list[_MAP_LIST_SIZE]; - size_type _cur_list; - - /** - * @brief 互斥锁 - */ - pthread_mutex_t _up_locks; - /** - * @brief 初始化更新互斥锁的标记,true表示更新成功 - */ - bool _lock_init; - - private: - - /** - * @brief 等号设为私有,不支持拷贝构造,需要的请使用assign - * @note 不支持= ,同时也不支持 std::swap - */ - rwseque& operator=(const rwseque&); - rwseque(const rwseque&); - - public: - - /* * - * @brief 默认构造函数 - * 无异常 - * 需要调create - * */ - rwseque(){ - _reset(); - _lock_init = false; - } - - /** - * @brief 构造函数 - * @param [in] __size : size_type rwseque大小 - * 如果构造失败,将抛异常 - * 不需调create - */ - explicit rwseque(size_type __size) - { - _reset(); - _lock_init = false; - if (create(__size) != 0) { - throw BadAllocException()< - int assign(_InputIterator __first, _InputIterator __last) - { - if (!_lock_init) { - return -1; - } - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - return _assign(__first, __last, _Integral()); - } - - template - int _assign(_Integer __n, _Integer __val, __true_type) - { - return assign(size_type(__n), value_type(__val)); - } - - template - int _assign(_InputIterator __first, _InputIterator __last, __false_type) - { - mutexlock_monitor up_lock(&_up_locks); - _clear(); - for (_InputIterator iter = __first; iter != __last; ++iter) { - if (_push_back(*iter) != 0) { - goto fail; - } - } - return 0; - fail: - _clear(); - return -1; - } - - - int destroy() - { - _clear(); - //销毁最后的内存块 - if (NULL != _map) { - if (NULL != _map[0]) { - _node_alloc.deallocate(_map[0], _BUFF_SIZE); - } - //销毁读写锁 - for (size_type i = 0; i < _locks_map_size; ++i) { - if (NULL != _locks[i]) { - pthread_rwlock_destroy(_locks[i]); - _locks_alloc.deallocate(_locks[i], 1); - } - } - } - //销毁map_list和_lock_list - for (size_type list_size = _map_size; - (list_size > 0) ; - (list_size >>= 1), (_locks_map_size >>= 1), --_cur_list) { - if (NULL != _map_list[_cur_list]) { - //销毁map_list - _map_alloc.deallocate(_map_list[_cur_list], list_size); - //销毁lock_list - _locks_list_alloc.deallocate(_locks_list[_cur_list], _locks_map_size); - - } - if (0 == _cur_list) { - break; - } - } - - _reset(); - //销毁内存池 - _node_alloc.destroy(); - _map_alloc.destroy(); - _locks_alloc.destroy(); - _locks_list_alloc.destroy(); - //销毁全局互斥锁 - if (_lock_init) { - pthread_mutex_destroy(&_up_locks); - _lock_init = false; - } - return 0; - } - - int clear() - { - if (!_lock_init) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - return _clear(); - } - - size_type max_size() const - { - return size_type(-1); - } - - iterator begin() - { - return iterator((NULL == _map ? NULL : _map[0]), _map); - } - - iterator end() - { - return iterator(_last, _map + _finish); - } - - const_iterator begin() const - { - return const_iterator((NULL == _map ? NULL : _map[0]), _map); - } - - const_iterator end() const - { - return const_iterator(_last, _map + _finish); - } - - reverse_iterator rbegin() - { - return reverse_iterator(end()); - } - - const_reverse_iterator rbegin() const - { - return const_reverse_iterator(end()); - } - - reverse_iterator rend() - { - return reverse_iterator(begin()); - } - - const_reverse_iterator rend() const - { - return const_reverse_iterator(begin()); - } - - int push_back(const value_type& __x) - { - if (!_lock_init) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - return _push_back(__x); - } - - int pop_back() - { - if (!_lock_init) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - return _pop_back(); - } - - int get(const size_type &__n, value_type *__val) - { - if (!_lock_init) { - return -1; - } - //这里要传值,传引用多线程__n的值会变化, volatile避免被优化掉 - volatile size_type n = __n; - if (n >= _size || NULL == __val) { - return -1; - } - pthread_rwlock_t &plock = *(_locks[n/_lsize]); - pthread_rwlock_rdlock(&plock); - int ret = 0; - if (n < _size) { - bsl::bsl_construct(__val, _map[n/_BUFF_SIZE][n%_BUFF_SIZE]); - } else { - ret = -1; - } - - pthread_rwlock_unlock(&plock); - return ret; - } - - int set(const size_type &__n, const value_type &__val) - { - if (!_lock_init) { - return -1; - } - //这里要传值,传引用多线程__n的值会变化, volatile避免被优化掉 - volatile size_type n = __n; - if (n >= _size) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - int ret = 0; - pthread_rwlock_t &plock = *(_locks[n/_lsize]); - pthread_rwlock_wrlock(&plock); - if (n < _size) { - bsl::bsl_construct(&(_map[n/_BUFF_SIZE][n%_BUFF_SIZE]), __val); - } else { - ret = -1; - } - pthread_rwlock_unlock(&plock); - return ret; - } - - size_type size() const - { - return _size; - } - - bool empty() const - { - return (0 == _size); - } - - template - int serialization(_Archive &__ar) - { - if (!_lock_init) { - return -1; - } - if (bsl::serialization(__ar, _size) < 0) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - for (const_iterator iter = begin(); iter != end(); ++iter) { - if (bsl::serialization(__ar, *iter) < 0) { - return -1; - } - } - return 0; - } - - template - int deserialization(_Archive &__ar) - { - if (!_lock_init) { - return -1; - } - mutexlock_monitor up_lock(&_up_locks); - size_type len = size(); - if (bsl::deserialization(__ar, len) < 0) { - return -1; - } - _clear(); - value_type tmp; - while (len--) { - if (bsl::deserialization(__ar, tmp) < 0) { - goto fail; - } - if (_push_back(tmp) < 0) { - goto fail; - } - } - return 0; - fail: - _clear(); - return -1; - } - - private: - - /** - * @brief 重置squeue的内部变量 - * - **/ - void _reset() - { - _finish = 0; - _last = NULL; - _map = NULL; - _locks = NULL; - _cur_list = 0; - _map_size = 0; - _size = 0; - _lsize = 0; - _locks_map_size = 0; - } - - /* * - * @brief 初始化索引表 - * @return 返回0表示成功,-1表示失败 - * */ - int _initialize_map(size_type __initialize_size, size_type __lock_num) - { - _map = _map_alloc.allocate(__initialize_size); - if (NULL == _map) { - goto fail; - } - - _map[0] = _node_alloc.allocate(_BUFF_SIZE); - if (NULL == _map[0]) { - goto fail; - } - - _locks_map_size = (__initialize_size-1)/__lock_num+1; - //初始化锁, 分配空间 - _locks = _locks_list_alloc.allocate(_locks_map_size); - if (NULL == _locks) { - goto fail; - } - - //锁的初始化 - if (_initialize_locks(_locks, _locks + _locks_map_size) != 0) { - goto fail; - } - - //初始化更新互斥锁 - if (!_lock_init) { - if (pthread_mutex_init(&_up_locks, NULL) < 0) { - goto fail; - } - _lock_init = true; - } - //位置标记初始化 - _last = _map[_finish]; - _finish = 0; - _size = 0; - _cur_list = 0; - _map_list[0] = _map; - _locks_list[0] = _locks; - _map_size = __initialize_size; - return 0; - fail: - if (NULL != _map) { - if (NULL != _map[0]) { - _node_alloc.deallocate(_map[0], _BUFF_SIZE); - } - _map_alloc.deallocate(_map, __initialize_size); - } - - if (NULL != _locks) { - _locks_list_alloc.deallocate(_locks, _locks_map_size); - } - _locks_map_size = 0; - _reset(); - - return -1; - } - - - /** - * @brief 初始化读写锁 - * - * @param [in] __locks_first : 锁列表的头部 - * @param [in] __locks_last : 锁列表的尾部 - * @return 成功返回0,失败返回-1 - **/ - int _initialize_locks(pthread_rwlock_t **__locks_first, - pthread_rwlock_t **__locks_last) - { - for (pthread_rwlock_t **plock = __locks_first; - plock != __locks_last; ++plock) { - *plock = _locks_alloc.allocate(1); - if (NULL == *plock || pthread_rwlock_init(*plock, NULL) < 0) { - for (pthread_rwlock_t **lock_destroy = __locks_first; - lock_destroy != plock; ++lock_destroy) { - if (NULL != *lock_destroy) { - pthread_rwlock_destroy(*lock_destroy); - _locks_alloc.deallocate(*lock_destroy, 1); - } - } - if (*plock != NULL) { - _locks_alloc.deallocate(*plock, 1); - } - return -1; - } - } - - return 0; - } - - /** - * @brief 索引表扩张 - * @return 成功返回0,失败返回-1 - * */ - int _new_map() - { - pthread_rwlock_t **new_locks = NULL; - //新的索引列表 - pointer* new_map = _map_alloc.allocate(_map_size<<1); - if (NULL == new_map) { - goto fail; - } - //新的锁列表 - new_locks = _locks_list_alloc.allocate(_locks_map_size<<1); - if (NULL == new_locks) { - goto fail; - } - //复制到新的位置 - memcpy(new_map, _map, _map_size * sizeof(new_map[0])); - memcpy(new_locks, _locks, _locks_map_size * sizeof(new_locks[0])); - //对锁进行初始化 - if (_initialize_locks(new_locks + _locks_map_size, - new_locks + (_locks_map_size<<1)) != 0) { - goto fail; - } - - //map_list增长 - ++_cur_list; - _map_list[_cur_list] = new_map; - _locks_list[_cur_list] = new_locks; - //替换旧的_map - _map = new_map; - _locks = new_locks; - _map_size <<= 1; - _locks_map_size <<=1; - return 0; - - fail: - //失败销毁内存 - if (NULL != new_map) { - _map_alloc.deallocate(new_map, _map_size<<1); - } - - if (NULL != new_locks) { - _locks_list_alloc.deallocate(new_locks, _locks_map_size<<1); - } - return -1; - } - - /** - * @brief 在尾部增加元素 - * @return 成功返回0,失败返回-1 - * */ - int _push_back(const value_type& __x) - { - if (NULL == _map) { - goto fail; - } - - if (_last != _map[_finish] + _BUFF_SIZE - 1) { - bsl::bsl_construct(_last, __x); - ++_last; - ++_size; - } else { - if (_finish + 1 == _map_size) { - if (_new_map() < 0) { - goto fail; - } - } - pointer new_node = _node_alloc.allocate(_BUFF_SIZE); - if (NULL == new_node) { - goto fail; - } - bsl::bsl_construct(_last, __x); - ++_finish; - _map[_finish] = new_node; - _last = new_node; - ++_size; - } - return 0; - fail: - return -1; - } - - /* * - * @brief 弹出尾部元素 - * @return 成功返回0,失败返回-1 - * 若容器为空,则返回失败 - * */ - int _pop_back() - { - if (0 == _size) { - return -1; - } - - pthread_rwlock_t &plock = *_locks[(_size - 1)/_lsize]; - pthread_rwlock_wrlock(&plock); - --_size; - pthread_rwlock_unlock(&plock); - if (_last == _map[_finish]) { - _node_alloc.deallocate(_map[_finish], _BUFF_SIZE); - --_finish; - _last = _map[_finish] + _BUFF_SIZE; - } - --_last; - bsl::bsl_destruct(_last); - return 0; - } - - int _assign(size_type __n, const value_type& __val) - { - _clear(); - for (size_type i = 0; i < __n; ++i) { - if (_push_back(__val) != 0) { - goto fail; - } - } - return 0; - fail: - _clear(); - return -1; - } - - /* * - * @brief 清除所有元素 - * @return 成功返回0,失败返回-1 - * */ - int _clear() - { - //这个小于0是已经为空了没有必要再pop了 - while (_pop_back() == 0) { - } - return 0; - } - }; - - -} //namespace bsl - - -#endif //__BSL_RWSEQUE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/containers/hash/CMakeLists.txt b/bsl/containers/hash/CMakeLists.txt deleted file mode 100644 index 3d0c2997243c7ff472ee9d6344f103b76098bf26..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/containers/hash/Makefile b/bsl/containers/hash/Makefile deleted file mode 100644 index 7eb3fc5b61614a7d8faa9bd49cd0bf0cc12f4a23..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -BSL=../../ -OUTINC=$(BSL)/output/include/bsl/containers/hash -all : - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp *.h $(OUTINC) - -clean : - rm -rf $(OUTINC) - diff --git a/bsl/containers/hash/bsl_hash_fun.h b/bsl/containers/hash/bsl_hash_fun.h deleted file mode 100644 index c1a376546a5e017efd72974256f984ca6cee7091..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hash_fun.h +++ /dev/null @@ -1,141 +0,0 @@ -// 'struct xhash' from SGI -*- C++ -*- - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, 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 General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/* - * Copyright (c) 1996-1998 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** @file ext/hash_fun.h - * This file is a GNU extension to the Standard C++ Library (possibly - * containing extensions from the HP/SGI STL subset). You should only - * include this header if you are using GCC 3 or later. - */ - -#ifndef _BSL_HASH_FUN_H -#define _BSL_HASH_FUN_H - -#include -#include - - -namespace bsl -{ - using std::size_t; - - template struct xhash { - size_t operator () (const _Key & _k) const { - return (size_t)_k; - } - }; - - inline size_t - __bsl_hash_string(const char* __s) - { - if (__s == 0) return 0; - unsigned long __h = 0; - for ( ; *__s; ++__s) - __h = 5*__h + *__s; - return size_t(__h); - } - - template <> struct xhash { - size_t operator () (const std::string & _k) const { - return __bsl_hash_string(_k.c_str()); - } - }; - - template <> struct xhash { - size_t operator () (const std::string & _k) const { - return __bsl_hash_string(_k.c_str()); - } - }; - - template<> struct xhash - { - size_t operator()(const char* __s) const - { return __bsl_hash_string(__s); } - }; - - template<> struct xhash - { - size_t operator()(const char* __s) const - { return __bsl_hash_string(__s); } - }; - - template<> struct xhash - { size_t operator()(char __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(unsigned char __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(unsigned char __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(short __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(unsigned short __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(int __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(unsigned int __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(long __x) const { return __x; } }; - - template<> struct xhash - { size_t operator()(unsigned long __x) const { return __x; } }; -} // namespace __gnu_cxx - -#endif diff --git a/bsl/containers/hash/bsl_hash_multimap.h b/bsl/containers/hash/bsl_hash_multimap.h deleted file mode 100644 index 54f54a99fed0f495ce5fe63c2de90e1f8374d66b..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hash_multimap.h +++ /dev/null @@ -1,409 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_hashmap.h,v 1.4 2009/08/24 06:24:49 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file hash_multimap.h - * @author luoweii(sat@baidu.com) - * @date 2012/09/04 14:45:23 - * @brief 实现管理key value对的hash表, - * 线程不安全 - * - **/ - - -#ifndef __BSL_HASH_MULTIMAP_H_ -#define __BSL_HASH_MULTIMAP_H_ - -#include - -namespace bsl -{ - -/** - * @brief hash_multimap - */ -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2) const ; - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class hash_multimap -{ -public: - /** - * @brief 键 - */ - typedef _Key key_type; - /** - * @brief 值 - */ - typedef _Value value_type; - //typedef bsl::pair<_Key, _Value> _Pair; //将key value打包,作为底层容器的存储value - /** - * @brief //将key value打包,作为底层容器的存储value - */ - typedef std::pair<_Key, _Value> _Pair; - /** - * @brief hashmap别名 - */ - typedef hash_multimap<_Key, _Value, _HashFun, _Equl, _InnerAlloc> _Self; - /** - * @brief hashtable别名 - */ - typedef bsl_hashtable<_Key, _Pair, _HashFun, _Equl, pair_first<_Pair>, _InnerAlloc> hash_type; - /** - * @brief 内部的hashtable - */ - hash_type _ht; //底层hash表 -public: - /** - * @brief 迭代器 - */ - typedef typename hash_type::iterator iterator; - /** - * @brief 只读迭代器 - */ - typedef typename hash_type::const_iterator const_iterator; - - /** - * @brief 迭代器pair - */ - typedef std::pair iterator_pair; - - /** - * @brief 只读迭代器pair - */ - typedef std::pair const_iterator_pair; - -public: - - /** - * @brief 默认构造函数 - * 不抛异常 - * 需调用create - **/ - hash_multimap(){} - - /** - * @brief 带桶大小的构造函数 - * 失败时会抛出异常 - * 不需调create - **/ - explicit hash_multimap(size_t bitems, const _HashFun& hf = _HashFun(), const _Equl& eq = _Equl()) - { - if (_ht.create(bitems,hf,eq) != 0) - { - _ht.destroy(); - throw BadAllocException()<的迭代器首尾pair - * - * @param [in/out] k : const key_type& - * @return _const_iterator_pair hash表空,返回 - * 不存在返回, - * 查找成功返回range的<头迭代器,尾迭代器的下一个迭代器 > - * @retval - * @see - * @note - * @author luowei - * @date 2012/8/22 14:21:43 - **/ - const_iterator_pair get (const key_type &k) const { - return _ht.find_multimap(_ht._hashfun(k), k); - } - - /** - * @brief 根据key查找元素,返回所有的key为k的的迭代器pair - */ - iterator_pair get (const key_type &k) { - return _ht.find_multimap(_ht._hashfun(k), k); - } - - /** - * @brief 将key 和 value 对 插入 hash表中 - * - * @param [in/out] k : const key_type& key值 - * @param [in/out] val : const value_type& value值 - * @param [in/out] flag : int - * flag ==0,如果值存在直接返回, - * 非0表示,如果值存在,替换旧值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面两个状态 - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author luowei - * @date 2012/09/04 21:20:49 - **/ - int set(const key_type &k, const value_type &val, int flag = 0) { - return _ht.set_multimap(_ht._hashfun(k), k, val, flag); - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 删除结点的个数 - * @retval - * @see - * @author luowei - * @date 2012/09/04 21:24:58 - **/ - int erase(const key_type &k) { - return _ht.erase_multimap(_ht._hashfun(k), k); - } - - /** - * @brief 根据指定的删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 删除结点的个数 - * @retval - * @see - * @author luowei - * @date 2012/9/04 21:24:58 - **/ - int erase_pair(const key_type &k, const value_type &val) { - return _ht.erase_pair(_ht._hashfun(k), k, val); - } - - /** - * @brief 将其他容器对hash表进行附值 - * - * @param [in/out] __begin : _Iterator 迭代器的起始地址 - * @param [in/out] __end : _Iterator 迭代器的结束地址 - * @return int 0 表示附值成功,其他表示失败 - * @retval - * @see - * @author luowei - * @date 2012/09/04 21:26:00 - **/ - template - int assign(_Iterator __begin, _Iterator __end, int flag = 0) { - return _ht.assign_multimap(__begin, __end, flag); - } - - /** - * @brief hash_multimap数据串行化 - */ - template - int serialization(_Archive &ar) { - return bsl::serialization(ar, _ht); - } - - /** - * @brief hash_multimap数据反串行化 - */ - template - int deserialization(_Archive &ar) { - return _ht.deserialization_multimap(ar); - } - /** - * @brief 清空hash_multsh_multimapimap - */ - int clear() { - return _ht.clear(); - } -}; - - -} -#endif //__HASH_MULTIMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ - diff --git a/bsl/containers/hash/bsl_hashmap.h b/bsl/containers/hash/bsl_hashmap.h deleted file mode 100644 index 165fae678ea4f7adfca8b84df485371fdccf63a7..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hashmap.h +++ /dev/null @@ -1,359 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_hashmap.h,v 1.4 2009/08/24 06:24:49 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file hashmap.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/13 18:45:23 - * @version $Revision: 1.4 $ 2010/10/15 modified by zhjw(zhujanwei@baidu.com) - * @brief 实现管理key value对的hash表, - * 线程不安全 - * - **/ - - -#ifndef __BSL_HASHMAP_H_ -#define __BSL_HASHMAP_H_ - -#include - -namespace bsl -{ - -/** - * @brief hashmap - */ -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2) const ; - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class hashmap -{ -public: - /** - * @brief 键 - */ - typedef _Key key_type; - /** - * @brief 值 - */ - typedef _Value value_type; - //typedef bsl::pair<_Key, _Value> _Pair; //将key value打包,作为底层容器的存储value - /** - * @brief //将key value打包,作为底层容器的存储value - */ - typedef std::pair<_Key, _Value> _Pair; - /** - * @brief hashmap别名 - */ - typedef hashmap<_Key, _Value, _HashFun, _Equl, _InnerAlloc> _Self; - /** - * @brief hashtable别名 - */ - typedef bsl_hashtable<_Key, _Pair, _HashFun, _Equl, pair_first<_Pair>, _InnerAlloc> hash_type; - /** - * @brief 内部的hashtable - */ - hash_type _ht; //底层hash表 -public: - /** - * @brief 迭代器 - */ - typedef typename hash_type::iterator iterator; - /** - * @brief 只读迭代器 - */ - typedef typename hash_type::const_iterator const_iterator; - -public: - - /** - * @brief 默认构造函数 - * 不抛异常 - * 需调用create - **/ - hashmap(){} - - /** - * @brief 带桶大小的构造函数 - * 失败时会抛出异常 - * 不需调create - **/ - explicit hashmap(size_t bitems, const _HashFun& hf = _HashFun(), const _Equl& eq = _Equl()) - : _ht(bitems, hf, eq){} - - /** - * @brief 拷贝构造函数 - * 失败时会抛出异常 - **/ - hashmap(const _Self& other): _ht(other._ht){} - - /** - * @brief 赋值运算符 - * 失败会抛出异常 - **/ - _Self& operator=(const _Self& other){ - _ht = other._ht; - return *this; - } - - /** - * @brief 返回迭代器的起始地址 - * - * @return iterator - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:13:26 - **/ - iterator begin() { - return _ht.begin(); - } - /** - * @brief 返回只读迭代器的起始地址 - */ - const_iterator begin() const { - return _ht.begin(); - } - - /** - * @brief 返回迭代器的结束地址 - * - * @return iterator - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:13:39 - **/ - iterator end() { - return _ht.end(); - } - /** - * @brief 返回只读迭代器的结束地址 - */ - const_iterator end() const { - return _ht.end(); - } - - /** - * @brief 返回hash表目前有多少个元素 - * - * @return size_t 当前的元素个数 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:14:05 - **/ - size_t size() const { - return _ht.size(); - } - - /** - * @brief 创建一张hashmap - * - * @param [in/out] bitems : int 设置hash桶的大小 - * @param [in/out] hf : const _HashFun& 设置hash函数 - * @param [in/out] eq : const _Equl& 设置相等比较函数 - * @return int 返回 0 表示创建成功 - * 返回 其他 表示创建失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:12:50 - **/ - int create(size_t bitems, const _HashFun &hf = _HashFun(), const _Equl & eq = _Equl()) { - return _ht.create(bitems, hf, eq); - } - - /* * - * @brief 判断hashmap是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return _ht.is_created(); - } - - /** - * @brief 销毁hash表 - * - * @return int 返回0表示删除成功,其他表示删除失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:16:39 - **/ - int destroy() { - return _ht.destroy(); - } - - /** - * @brief 根据指定key获取value值 - * - * @param [in/out] k : const key_type& 指定的查找key - * @param [in/out] val : value_type* 获取的value值的存储地址 - * 如果value不为空,将*val附值查找的值 - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k, value_type *val=0) const { - _Pair *ptr = _ht.find(_ht._hashfun(k), k); - if (ptr == NULL) { - return HASH_NOEXIST; - } - if (val) { - *val = ptr->second; - } - return HASH_EXIST; - } - /** - * @brief 根据指定key获取value值 - */ - int get(const key_type &k, value_type *val=0) { - _Pair *ptr = _ht.find(_ht._hashfun(k), k); - if (ptr == NULL) { - return HASH_NOEXIST; - } - if (val) { - *val = ptr->second; - } - return HASH_EXIST; - } - - /** - * @brief 根据指定的key获取value指针 - * - * @param [in/out] k : const key_type& - * @return _Pair* 不存在返回NULL - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/09/04 14:21:43 - **/ - _Pair * find (const key_type &k) const { - return _ht.find(_ht._hashfun(k), k); - } - - /** - * @brief 根据指定的key获取value指针 - */ - _Pair * find (const key_type &k) { - return _ht.find(_ht._hashfun(k), k); - } - - /** - * @brief 将key 和 value 对 插入 hash表中 - * - * @param [in/out] k : const key_type& key值 - * @param [in/out] val : const value_type& value值 - * @param [in/out] flag : int - * flag ==0,如果值存在直接返回, - * 非0表示,如果值存在,替换旧值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面三个状态 - * 返回 HASH_OVERWRITE 表示覆盖旧结点成功(在flag非0的时候返回) - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:20:49 - **/ - int set(const key_type &k, const value_type &val, int flag = 0) { - return _ht.set_map(_ht._hashfun(k), k, val, flag); - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - return _ht.erase(_ht._hashfun(k), k); - } - - /** - * @brief 将其他容器对hash表进行附值 - * - * @param [in/out] __begin : _Iterator 迭代器的起始地址 - * @param [in/out] __end : _Iterator 迭代器的结束地址 - * @return int 0 表示附值成功,其他表示失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:26:00 - **/ - template - int assign(_Iterator __begin, _Iterator __end) { - return _ht.assign(__begin, __end); - } - - /** - * @brief hashmap数据串行化 - */ - template - int serialization(_Archive &ar) { - return bsl::serialization(ar, _ht); - } - - /** - * @brief hashmap数据反串行化 - */ - template - int deserialization(_Archive &ar) { - return bsl::deserialization(ar, _ht); - } - /** - * @brief 清空hashmap - */ - int clear() { - return _ht.clear(); - } -}; - -}; - -#endif //__HASHMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_hashset.h b/bsl/containers/hash/bsl_hashset.h deleted file mode 100644 index 3b20872bcf3dd62c2e704e3a59405a9bc43ded65..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hashset.h +++ /dev/null @@ -1,315 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_hashset.h,v 1.2 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file hashset.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/13 21:30:57 - * @version $Revision: 1.2 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_HASHSET_H_ -#define __BSL_HASHSET_H_ - - -#include - -namespace bsl -{ - -/** - * @brief hashset - */ -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2); - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class hashset -{ - /** - * @brief 键 - */ - typedef _Key key_type; - /** - * @brief 值 - */ - typedef _Key value_type; - /** - * @brief hashset别名 - */ - typedef hashset<_Key, _HashFun, _Equl, _InnerAlloc> _Self; - /** - * @brief hashtable别名 - */ - typedef bsl_hashtable<_Key, _Key, _HashFun, _Equl, param_select<_Key>, _InnerAlloc> hash_type; - /** - * @brief 内部的hashtable - */ - hash_type _ht; -public: - /** - * @brief 迭代器 - */ - typedef typename hash_type::iterator iterator; - /** - * @brief 只读迭代器 - */ - typedef typename hash_type::const_iterator const_iterator; - -public: - /** - * @brief 默认构造函数 - * 无异常 - * 需调create - **/ - hashset() {} - - /** - * @brief 带桶大小的构造函数 - * 失败会抛出异常 - * 不需调create - **/ - hashset(size_t bitems, const _HashFun& hf = _HashFun(), const _Equl& eq = _Equl()) - :_ht(bitems, hf, eq){} - - /** - * @brief 拷贝构造函数 - * 失败会抛出异常 - */ - hashset(const _Self& other): _ht(other._ht){} - - /** - * @brief 赋值运算符 - * 失败抛出异常 - **/ - _Self& operator = (const _Self& other) { - _ht = other._ht; - return *this; - } - - /** - * @brief 返回迭代器的起始地址 - * - * @return iterator - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:13:26 - **/ - iterator begin() { - return _ht.begin(); - } - - /** - * @brief 返回只读迭代器的起始地址 - */ - const_iterator begin() const { - return _ht.begin(); - } - - /** - * @brief 返回迭代器的结束地址 - * - * @return iterator - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:13:39 - **/ - iterator end() { - return _ht.end(); - } - /** - * @brief 返回只读迭代器的结束地址 - */ - const_iterator end() const { - return _ht.end(); - } - - /** - * @brief 返回hash表目前有多少个元素 - * - * @return size_t 当前的元素个数 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:14:05 - **/ - size_t size() const { - return _ht.size(); - } - - /** - * @brief 创建hashset - * - * @param [in/out] bitems : int 设置hash桶的大小 - * @param [in/out] hf : const _HashFun& 设置hash函数 - * @param [in/out] eq : const _Equl& 设置相等比较函数 - * @return int 返回 0 表示创建成功 - * 返回 其他 表示创建失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:12:50 - **/ - int create(size_t bitems, const _HashFun &hf = _HashFun(), const _Equl & eq = _Equl()) { - return _ht.create(bitems, hf, eq); - } - - /* * - * @brief 判断hashset是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return _ht.is_created(); - } - - /** - * @brief 销毁hash表 - * - * @return int 返回0表示删除成功,其他表示删除失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:16:39 - **/ - int destroy() { - return _ht.destroy(); - } - - /** - * @brief 查询key_type是否存在 - * - * @param [in/out] k : const key_type& 指定的查找key - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k) const { - //返回的是指针 - if (_ht.find(_ht._hashfun(k), k) == NULL) { - return HASH_NOEXIST; - } - return HASH_EXIST; - } - - /** - * @brief 查询key_type是否存在 - */ - int get(const key_type &k) { - //返回的是指针 - if (_ht.find(_ht._hashfun(k), k) == NULL) { - return HASH_NOEXIST; - } - return HASH_EXIST; - } - - /** - * @brief 将key插入hash表 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 -1表示set调用出错 - * 返回 HASH_EXIST 表示hash结点存在 - * 返回 HASH_INSERT_SEC 表示插入成功 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:33:10 - **/ - int set(const key_type &k) { - return _ht.set(_ht._hashfun(k), k, k); - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - return _ht.erase(_ht._hashfun(k), k); - } - - /** - * @brief 将其他容器对hash表进行赋值 - * - * @param [in/out] __begin : _Iterator 迭代器的起始地址 - * @param [in/out] __end : _Iterator 迭代器的结束地址 - * @return int 0 表示附值成功,其他表示失败 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:26:00 - **/ - template - int assign(_Iterator __begin, _Iterator __end) { - return _ht.assign(__begin, __end); - } - - /** - * @brief hashset数据串行化 - */ - template - int serialization(_Archive &ar) { - return bsl::serialization(ar, _ht); - } - - /** - * @brief hashset数据反串行化 - */ - template - int deserialization(_Archive &ar) { - return bsl::deserialization(ar, _ht); - } - /** - * @brief 清空hashset - */ - int clear() { - return _ht.clear(); - } -}; -} -#endif //__HASHSET_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_hashtable.h b/bsl/containers/hash/bsl_hashtable.h deleted file mode 100644 index 5f51c38caaa90c5ad73d6a337040a4cc3cc3767e..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hashtable.h +++ /dev/null @@ -1,1285 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_hashtable.h,v 1.12 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_hashmap.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/12 21:04:29 - * @version $Revision: 1.12 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_HASHTABLE_H_ -#define __BSL_HASHTABLE_H_ - -#include -#include -#include -#include -#include -#include -#include - -namespace bsl -{ - -template -struct bsl_hashtable_node_t; - -template -struct bsl_hashtable_node_t -{ - _Tp val; - typedef typename _Alloc::template rebind::other::pointer pointer; - pointer next; -}; - -template -class bsl_hashtable; - -template -struct bsl_hashtable_iterator; - -template -struct bsl_hashtable_const_iterator; - -/** - * @brief hash表迭代器实现 - */ -template -struct bsl_hashtable_iterator -{ - typedef bsl_hashtable<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> hashtable; - typedef bsl_hashtable_iterator<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> iterator; - typedef bsl_hashtable_const_iterator<_Key, _Value, _HashFun, - _Equl, _GetKey, _InnerAlloc> const_iterator; - typedef bsl_hashtable_node_t<_Value, _InnerAlloc> node_t; - typedef typename hashtable::node_pointer node_pointer; - - typedef std::forward_iterator_tag iterator_category; - typedef _Value value_type; - typedef ptrdiff_t difference_type; - typedef value_type * pointer; - typedef value_type & reference; - - hashtable *_ht; - size_t _bucketpos; - node_pointer _node; - -public: - bsl_hashtable_iterator() { - _ht = 0; - _bucketpos = 0; - _node = 0; - } - bsl_hashtable_iterator(const iterator &iter) { - _ht = iter._ht; - _bucketpos = iter._bucketpos; - _node = iter._node; - } - /* - //TODO:这个构造函数语义有问题,而且暂时没有用户使用过(因为编译时会报错),以后考虑删掉 - bsl_hashtable_iterator (const const_iterator & iter) { - _ht = iter._ht; - _bucketpos = iter._bucketpos; - _node = iter._node; - } - */ - bsl_hashtable_iterator(hashtable *ht, size_t bp, node_pointer node) { - _ht = ht; - _bucketpos = bp; - _node = node; - if(_ht != 0){ - while (_node == 0 && _bucketpos < _ht->_bitems) { - _node = _ht->_bucket[_bucketpos]; - if (_node == 0) { - ++_bucketpos; - } - } - } - } - reference operator * () { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->val; - } - pointer operator -> () { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->val); - } - - //这里可以优化 - bool operator == (const iterator & iter) const { - return (_node == iter._node); - } - bool operator != (const iterator & iter) const { - return (_node != iter._node); - } - - iterator & operator ++ () { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->next; - if (_node) { - return *this; - } - } - for (size_t i = _bucketpos + 1; i < _ht->_bitems; ++i) { - _node = _ht->_bucket[i]; - if (_node) { - _bucketpos = i; - return *this; - } - } - _bucketpos = _ht->_bitems; - return *this; - } - iterator operator ++ (int) { - iterator iter = *this; - ++ *this; - return iter; - } -}; - -/** - * @brief hashtable的只读迭代器 - */ -template -struct bsl_hashtable_const_iterator -{ - typedef bsl_hashtable<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> hashtable; - typedef bsl_hashtable_iterator<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> iterator; - typedef bsl_hashtable_const_iterator<_Key, _Value, _HashFun, - _Equl, _GetKey, _InnerAlloc> const_iterator; - - typedef bsl_hashtable_node_t<_Value, _InnerAlloc> node_t; - typedef typename hashtable::node_pointer node_pointer; - typedef std::forward_iterator_tag iterator_category; - typedef _Value value_type; - typedef ptrdiff_t difference_type; - - typedef const value_type * pointer; - typedef const value_type & reference; - - const hashtable *_ht; - size_t _bucketpos; - node_pointer _node; - -public: - bsl_hashtable_const_iterator() { - _ht = 0; - _bucketpos = 0; - _node = 0; - } - bsl_hashtable_const_iterator(const const_iterator &iter) { - _ht = iter._ht; - _bucketpos = iter._bucketpos; - _node = iter._node; - } - bsl_hashtable_const_iterator(const iterator &iter) { - _ht = iter._ht; - _bucketpos = iter._bucketpos; - _node = iter._node; - } - bsl_hashtable_const_iterator(const hashtable *ht, size_t bp, node_pointer node) { - _ht = ht; - _bucketpos = bp; - _node = node; - if(_ht != 0){ - while (_node == 0 && _bucketpos < _ht->_bitems) { - _node = _ht->_bucket[_bucketpos]; - if (_node == 0) { - ++_bucketpos; - } - } - } - } - reference operator * () const { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->val; - } - pointer operator -> () const { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->val); - } - - //这里可以优化 - bool operator == (const const_iterator & iter) const { - return (_node == iter._node); - } - bool operator != (const const_iterator & iter) const { - return (_node != iter._node); - } - - const_iterator & operator ++ () { - if(0 == _ht){ - throw bsl::NullPointerException()<_sp_alloc.getp(_node)->next; - if (_node) { - return *this; - } - } - for (size_t i = _bucketpos + 1; i < _ht->_bitems; ++i) { - _node = _ht->_bucket[i]; - if (_node) { - _bucketpos = i; - return *this; - } - } - _bucketpos = _ht->_bitems; - return *this; - } - const_iterator operator ++ (int) { - const_iterator iter = *this; - ++ *this; - return iter; - } -}; - -//默认bitems大小 -//modified by chenyanling@baidu.com -const size_t HASHTABLE_BITEMS = 64; - -/** - * @brief 普通的hashtable - */ -template -class bsl_hashtable -{ -public: - typedef bsl_hashtable<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> _Self; - typedef _Value value_type; - typedef _Key key_type; - typedef value_type * pointer; - - typedef bsl_hashtable_node_t node_t; - typedef typename _InnerAlloc::pool_type pool_type; - - typedef typename _InnerAlloc::template rebind::other sample_alloc_type; - typedef typename sample_alloc_type::pointer node_pointer; - typedef typename pool_type::template rebind::other node_p_alloc_type; - - friend struct bsl_hashtable_iterator<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc>; - friend struct bsl_hashtable_const_iterator<_Key, _Value, _HashFun, - _Equl, _GetKey, _InnerAlloc>; - -public: - sample_alloc_type _sp_alloc; - node_p_alloc_type _np_alloc; - - node_pointer *_bucket; - size_t _bitems; - size_t _size; - - _HashFun _hashfun; - _Equl _equl; - _GetKey _getkey; - -public: - typedef bsl_hashtable_iterator<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> iterator; - typedef bsl_hashtable_const_iterator<_Key, _Value, _HashFun, - _Equl, _GetKey, _InnerAlloc> const_iterator; - - typedef std::pair const_iterator_pair; - typedef std::pair iterator_pair; - - iterator _end_iter; - -public: - /** - * @brief 构造函数 - * 无异常 - * 需调create - */ - bsl_hashtable() { - _reset(); - } - - /** - * @brief 带桶大小的构造函数,抛异常 - * 如果构造失败,将销毁对象 - * 不需调create - * - * @param [in] bitems : size_t hash桶的大小 - * @param [in] hf : const _HashFun& hash函数 - * @param [in] eq : const _Equl& hash结点的比较仿函数 - */ - bsl_hashtable(size_t bitems, const _HashFun& hf = _HashFun(), const _Equl& eq = _Equl()) { - _reset(); - if (create(bitems,hf,eq) != 0) { - destroy(); - throw BadAllocException()<= size_t(-1) / sizeof(void *)) { - __BSL_ERROR("too large bitems, overflower"); - return -1; - } - - if (bitems == 0) { - __BSL_ERROR("bitems == 0"); - return -1; - } - - if (destroy() != 0) { - __BSL_ERROR("destroy error when create hash bitems[%lu]", (unsigned long)bitems); - return -1; - } - if (recreate(bitems) != 0) { - __BSL_ERROR("recreate error when create hash bitems[%lu]", (unsigned long)bitems); - return -1; - } - _hashfun = hf; - _equl = eq; - return 0; - } - - /* * - * @brief 判断hashtable是否已初始化 - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return (_bucket != 0); - } - - //destroy分两部分,一个有构造函数,一个没有构造函数 - int destroy() { - //具体实现 - if (_bucket) { - if (sample_alloc_type::recycle_space) { - bsl::bsl_destruct(begin(), end()); - } else { - node_pointer nd = 0; - for (size_t i=0; i<_bitems; ++i) { - while (_bucket[i]) { - nd = _bucket[i]; - _bucket[i] = _sp_alloc.getp(_bucket[i])->next; - //nd->val.~value_type(); - bsl::bsl_destruct(&(_sp_alloc.getp(nd)->val)); - _sp_alloc.deallocate(nd, 1); - } - } - } - } - _sp_alloc.destroy(); - - if (_bucket) { - _np_alloc.deallocate(_bucket, _bitems); - } - _np_alloc.destroy(); - _bitems = 0; - _bucket = 0; - - _size = 0; - _end_iter._bucketpos = 0; - return 0; - } - - iterator begin() { - return iterator(this, 0, 0); - } - - const_iterator begin() const { - return const_iterator(this, 0, 0); - } - - iterator end() { - return _end_iter; - } - - const_iterator end() const { - return const_iterator(this, _bitems, 0); - } - - size_t size() const { - return _size; - } - - /** - * @brief hash表中键值等于key的个数 - * @param [in/out] hashval : const size_t hash值 - * @param [in/out] k : const key_type 键值 - * @param [in/out] flag : int 相同是否重复计数 - * flag == 0,重复计数 - * flag != 0,不重复计数(目前没有实现,只是留作接口) - * @return size_t 返回键值等于key的个数 - * @author luowei - * @date 2012/08/27 17:11:02 - **/ - size_t count(size_t hashval, const key_type &k, int flag = 0) - { - if(0 == _bitems || 0 == _bucket) - { - return 0; - } - size_t __result = 0; - node_pointer lst = _bucket[hashval % _bitems]; - while(lst && !_equl(_getkey(_sp_alloc.getp(lst)->val),k)) - { - lst = _sp_alloc.getp(lst)->next; - } - if(lst) - { - __result = 1; - lst = _sp_alloc.getp(lst)->next; - while(lst && _equl(_getkey(_sp_alloc.getp(lst)->val), k)) - { - ++__result; - lst = _sp_alloc.getp(lst)->next; - } - } - return __result; - } - -public: - /** - * @brief 用其他容器对hash表进行附值操作 - * - * @param [in/out] __begin : _Iterator 迭代器的起始地址 - * @param [in/out] __end : _Iterator 迭代器的结束地址 - * @return int 0 表示成功附值,其他失败 - * 如果返回出错,请调用destroy,销毁该对象 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 17:11:02 - **/ - template - int assign(_Iterator __begin, _Iterator __end) - { - size_t bkt = 0; - bkt = std::distance(__begin, __end) * 2; - if (bkt < _bitems) { - bkt = _bitems; - } - destroy(); - if (recreate(bkt) != 0) { - return -1; - } - for (_Iterator iter = __begin; iter != __end; ++iter) { - if (set(_hashfun(_getkey(*iter)), _getkey(*iter), *iter) == -1) { - return -1; - } - } - return 0; - } - - /** - * @brief 用其他的map容器对hash表进行附值,允许重复key - * @param [in/out] __begin : _Iterator 迭代器的起始地址 - * @param [in/out] __end : _Iterator 迭代器的结束地址 - * @param [in/out] flag : int 0表示不允许重复;非0表示允许.默认为0 - * @return int 返回0表示删除成功,其他表示失败 - * - * @author luowei - * @date 2012/08/28 19:40:02 - **/ - template - int assign_multimap(_Iterator __begin, _Iterator __end, int flag = 0) - { - size_t bkt = 0; - bkt = std::distance(__begin, __end) * 2; - if(bkt < _bitems) - { - bkt = _bitems; - } - destroy(); - if(recreate(bkt) != 0) - { - return -1; - } - for(_Iterator iter = __begin; iter != __end; ++iter) - { - if (set_multimap(_hashfun(_getkey(*iter)), _getkey(*iter), (*iter).second, flag) == -1) - { - return -1; - } - } - return 0; - } - - /** - * @brief 根据hash值,和key查找元素 - * - * @param [in/out] hashval : size_t - * @param [in/out] k : const key_type& - * @return value_type* 存在返回值指针,否这返回NULL - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/08/13 12:11:39 - **/ - value_type * find (size_t hashval, const key_type &k) const { - if(0 == _bitems || 0 == _bucket){ - return NULL; - } - node_pointer lst = _bucket[hashval % _bitems]; - while (lst) { - if (_equl(_getkey(_sp_alloc.getp(lst)->val), k)) { - return &(_sp_alloc.getp(lst)->val); - } - lst = _sp_alloc.getp(lst)->next; - } - return NULL; - } - value_type * find (size_t hashval, const key_type &k) { - if(0 == _bitems || 0 == _bucket){ - return NULL; - } - node_pointer lst = _bucket[hashval % _bitems]; - while (lst) { - if (_equl(_getkey(_sp_alloc.getp(lst)->val), k)) { - return &(_sp_alloc.getp(lst)->val); - } - lst = _sp_alloc.getp(lst)->next; - } - return NULL; - } - - /** - * @brief 根据hash值,和key/value查找元素 - * @param [in/out] hashval : size_t - * @param [in/out] k : value_type & val - * @return Hash表为空返回-1 - * 找到对 返回HASH_EXIST - * 否则 返回HASH_NOEXIST - * @author luowei - * @date 2012/08/28 19:11:39 - **/ - template - int find_pair(size_t hashval, const key_type &k, const pair_sec_type &val) - { - if(0 ==_bitems || 0 == _bucket) - { - return -1; - } - - //value值的比较函数 - std::equal_to _val_equl; - - node_pointer lst = _bucket[hashval % _bitems]; - - while(lst) - { - if(_equl(_sp_alloc.getp(lst)->val.first, k)) - { - while(lst && _equl(_sp_alloc.getp(lst)->val.first, k)) - { - if(_val_equl(_sp_alloc.getp(lst)->val.second, val)) - { - return HASH_EXIST; - } - lst = _sp_alloc.getp(lst)->next; - } - break; - } - lst = _sp_alloc.getp(lst)->next; - } - return HASH_NOEXIST; - } - - template - int find_pair(size_t hashval, const key_type &k, const pair_sec_type &val) const - { - if(0 ==_bitems || 0 == _bucket) - { - return -1; - } - - //value值的比较函数 - std::equal_to _val_equl; - - node_pointer lst = _bucket[hashval % _bitems]; - while(lst) - { - if(_equl(_sp_alloc.getp(lst)->val.first, k)) - { - while(lst && _equl(_sp_alloc.getp(lst)->val.first, k)) - { - if(_val_equl(_sp_alloc.getp(lst)->val.second, val)) - { - return HASH_EXIST; - } - lst = _sp_alloc.getp(lst)->next; - } - break; - } - lst = _sp_alloc.getp(lst)->next; - } - return HASH_NOEXIST; - } - - /** - * @brief 根据hashval和key在hash_multimap查找元素,返回所有的key为k的 - * - * @param [in/out] hashval : size_t - * @param [in/out] k : const key_type& - * @return _const_iterator_pair 返回key对应的range的首、尾迭代器的pair - * @retval - * @see - * @note - * @author luowei - * @date 2012/08/21 18:55:39 - **/ - const_iterator_pair find_multimap (size_t hashval, const key_type &k) const - { - if(0 == _bitems || 0 == _bucket) - { - return const_iterator_pair(end(), end()); - } - size_t key = hashval % _bitems; - node_pointer __first = _bucket[key];//记录找到的第一个迭代器位置 - node_pointer __cur = NULL; - for (;__first; __first= _sp_alloc.getp(__first)->next) - { - if (_equl(_sp_alloc.getp(__first)->val.first, k)) - { - for(__cur = _sp_alloc.getp(__first)->next; __cur; __cur= _sp_alloc.getp(__cur)->next) - { - if(!_equl(_sp_alloc.getp(__cur)->val.first, k)) - { - return const_iterator_pair(const_iterator(this, key, __first), - const_iterator(this, key, __cur)); - } - } - for(size_t __m = key + 1; __m < _bitems; ++__m) - { - if(_bucket[__m]) - { - return const_iterator_pair(const_iterator(this, key, __first), - const_iterator(this, __m, _bucket[__m])); - } - } - return const_iterator_pair(const_iterator(this, key, __first), end()); - } - } - return const_iterator_pair(end(), end()); - } - - iterator_pair find_multimap (size_t hashval, const key_type &k) - { - if(0 == _bitems || 0 == _bucket) - { - return iterator_pair(end(), end()); - } - size_t key = hashval % _bitems; - node_pointer __first = _bucket[key];//记录找到的第一个迭代器位置 - node_pointer __cur = NULL; - for (;__first; __first= _sp_alloc.getp(__first)->next) - { - if (_equl(_sp_alloc.getp(__first)->val.first, k)) - { - for(__cur = _sp_alloc.getp(__first)->next; __cur; __cur= _sp_alloc.getp(__cur)->next) - { - if(!_equl(_sp_alloc.getp(__cur)->val.first, k)) - { - return iterator_pair(iterator(this, key, __first), - iterator(this, key, __cur)); - } - } - for(size_t __m = key + 1; __m < _bitems; ++__m) - { - if(_bucket[__m]) - { - return iterator_pair(iterator(this, key, __first), - iterator(this, __m, _bucket[__m])); - } - } - return iterator_pair(iterator(this, key, __first), end()); - } - } - return iterator_pair(end(), end()); - } - - //根据行为产生一个copy on write的还有直接附值的hash表 - /** - * @brief 将val插入hash表中 - * - * @param [in/out] hashval : size_t hash key值 - * @param [in/out] k : const key_type& key 值 - * @param [in/out] val : const value_type& 数据值 - * @param [in/out] flag : int 0表示如果值存在,直接返回,非0表示替换旧值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面三个状态 - * 返回 HASH_OVERWRITE 表示覆盖旧结点成功(在flag非0的时候返回) - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 20:56:27 - **/ - int set (size_t hashval, const key_type &k, const value_type &val, int flag = 0) { - if(0 == _bitems || 0 == _bucket){ - return -1; - } - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - while (lst) { - if (_equl(_getkey(_sp_alloc.getp(lst)->val), k)) { - if (flag) { - _sp_alloc.getp(lst)->val = val; - return HASH_OVERWRITE; - } - return HASH_EXIST; - } - lst = _sp_alloc.getp(lst)->next; - } - node_pointer node = _sp_alloc.allocate(1); - if (0 == node) { - return -1; - } - bsl::bsl_construct(&(_sp_alloc.getp(node)->val), val); - //::new (&node->val) value_type(val); - _sp_alloc.getp(node)->next = _bucket[key]; - _bucket[key] = node; - ++ _size; - return HASH_INSERT_SEC; - } - - template - int set_map(size_t hashval, const key_type &k, const pair_sec_type &val, int flag = 0) { - if(0 == _bitems || 0 == _bucket){ - return -1; - } - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - while (lst) { - if (_equl(_sp_alloc.getp(lst)->val.first, k)) { - if (flag) { - _sp_alloc.getp(lst)->val.second = val; - return HASH_OVERWRITE; - } - return HASH_EXIST; - } - lst = _sp_alloc.getp(lst)->next; - } - node_pointer node = _sp_alloc.allocate(1); - if (node == 0) { - return -1; - } - ::new (&(_sp_alloc.getp(node)->val)) value_type(k, val); - _sp_alloc.getp(node)->next = _bucket[key]; - _bucket[key] = node; - ++ _size; - return HASH_INSERT_SEC; - } - - /** - * @brief 向hash_multimap中插入 - * @param [in] hashval: const hashval hash值 - * @param [in] k : const key_type key值 - * @param [in] val : const value_type& value值 - * @param [in] flag : int flag==0,不允许重复;flag!=0,允许重复.默认为不允许重复 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点,或者hash表未create) - * 其他均表示插入成功:插入成功分下面2个状态 - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @author luowei - * @date 2012/08/27 11:11:02 - * */ - template - int set_multimap(size_t hashval, const key_type &k, const pair_sec_type &val, int flag = 0) - { - if(0 == _bitems || 0 == _bucket) - { - return -1; - } - std::equal_to _val_equl; - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - node_pointer front = 0; - while(lst) - { - if(_equl(_sp_alloc.getp(lst)->val.first, k)) - { - if(0 == flag) - { - while(lst && _equl(_sp_alloc.getp(lst)->val.first, k)) - { - if(_val_equl(_sp_alloc.getp(lst)->val.second, val)) - { - return HASH_EXIST; - } - lst = _sp_alloc.getp(lst)->next; - } - } - break; - } - //遍历_bucket[key]链表里的元素,直到键值为k - front = lst; - lst = _sp_alloc.getp(lst)->next; - } - node_pointer node = _sp_alloc.allocate(1); - if(0 == node) - { - return -1; - } - ::new(&(_sp_alloc.getp(node)->val)) value_type(k,val); - - //在第一个键值为k的结点之前插入,若无hash值为key的结点,则直接在链表尾部插入 - if(0 == front) - { - _sp_alloc.getp(node)->next = _bucket[key]; - _bucket[key] = node; - } - else - { - _sp_alloc.getp(node)->next = _sp_alloc.getp(front)->next; - _sp_alloc.getp(front)->next = node; - } - ++_size; - return HASH_INSERT_SEC; - } -public: - - /** - * @brief 根据指定key删除结点 - * - * @param [in/out] hashval : size_t - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:00:58 - **/ - int erase (size_t hashval, const key_type &k) { - if(0 == _bitems || 0 == _bucket){ - return HASH_NOEXIST; - } - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - node_pointer front = 0; - while (lst != 0) { - if (_equl(_getkey(_sp_alloc.getp(lst)->val), k)) { - if (front == 0) { - _bucket[key] = _sp_alloc.getp(lst)->next; - } else { - _sp_alloc.getp(front)->next = _sp_alloc.getp(lst)->next; - } - bsl::bsl_destruct(&(_sp_alloc.getp(lst)->val)); - //lst->val.~value_type(); - _sp_alloc.deallocate(lst, 1 ); - -- _size; - return HASH_EXIST; - } - front = lst; - lst = _sp_alloc.getp(lst)->next; - } - return HASH_NOEXIST; - } - - /** - * @brief 根据指定key删除hash_multimap中的结点,并返回删除的结点个数 - * - * @param [in] hashval : size_t - * @param [in] k : const key_type& - * @return int : 删除的结点个数 - * @retval - * @see - * @author xiaowei - * @date 2012/08/30 21:00:58 - **/ - int erase_multimap(size_t hashval, const key_type &k) - { - if(0 == _bitems || 0 == _bucket) - { - return -1; - } - - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - node_pointer front = 0; - node_pointer first = 0; - node_pointer tmp = 0; - int __result = 0; - - while (lst != 0) - { - if (_equl(_sp_alloc.getp(lst)->val.first, k)) - { - first = lst; - while (lst != 0 && _equl(_sp_alloc.getp(lst)->val.first, k)) - { - lst = _sp_alloc.getp(lst)->next; - } - if (front == 0) - { - _bucket[key] = lst; - } - else - { - _sp_alloc.getp(front)->next = lst; - } - tmp = first->next; - while(first != lst) - { - bsl::bsl_destruct(&(_sp_alloc.getp(first)->val)); - _sp_alloc.deallocate(first, 1 ); - -- _size; - ++__result; - - if(!tmp) - { - break; - } - first = tmp; - tmp = _sp_alloc.getp(tmp)->next; - - } - return __result; - } - front = lst; - lst = _sp_alloc.getp(lst)->next; - } - return 0; - } - - /** - * @brief 根据指定key和指定value删除hash_multimap中的结点,并返回删除的结点个数 - * - * @param [in] hashval : size_t - * @param [in] k : const key_type& - * @param [in] val : const value_type& value值 - * @return int - * 返回 删除的结点个数 - * @retval - * @see - * @author luowei - * @date 2012/08/30 21:00:58 - **/ - template - int erase_pair (size_t hashval, const key_type &k, const pair_sec_type &val) - { - if(0 == _bitems || 0 == _bucket) - { - return -1; - } - std::equal_to _val_equl; - size_t key = hashval % _bitems; - node_pointer lst = _bucket[key]; - node_pointer front = 0; - int __result= 0; - - while (lst != 0) - { - if (_equl(_sp_alloc.getp(lst)->val.first, k)) - { - if (_val_equl(_sp_alloc.getp(lst)->val.second, val)) - { - if (0 == front) - { - _bucket[key] = _sp_alloc.getp(lst)->next; - } - else - { - _sp_alloc.getp(front)->next = _sp_alloc.getp(lst)->next; - } - bsl::bsl_destruct(&(_sp_alloc.getp(lst)->val)); - _sp_alloc.deallocate(lst, 1 ); - --_size; - - ++__result; - - if (0 == front) - { - lst = _bucket[key]; - } - else - { - lst = _sp_alloc.getp(front)->next; - } - continue; - } - } - front = lst; - lst = _sp_alloc.getp(lst)->next; - } - - return __result; - - } - - -public: - template - int serialization(_Archive & ar) { - if (bsl::serialization(ar, _bitems)) { - return -1; - } - __BSL_DEBUG("write _bitems=%ld", (long)_bitems); - if (bsl::serialization(ar, _size)) { - return -1; - } - __BSL_DEBUG("write _size=%ld", (long)_size); - if (_size > 0) { - for (iterator iter = begin(); iter != end(); ++iter) { - if (bsl::serialization(ar, *iter)) { - return -1; - } - } - } - return 0; - } - - template - int deserialization(_Archive & ar) { - size_t bitems = 0; - if (bsl::deserialization(ar, bitems)) { - __BSL_ERROR("deserialization bitems error"); - return -1; - } - __BSL_DEBUG("bitems = %ld", (long)bitems); - - //已经被初始化过 - if (_bucket) { - if (clear()) { - __BSL_ERROR("clear phashtable error"); - return -1; - } - } else { //没有初始化过 - if (create(bitems, _HashFun(), _Equl())) { - __BSL_ERROR("create hashtable error"); - return -1; - } - } - - size_t __size = 0; - if (bsl::deserialization(ar, __size)) { - __BSL_ERROR("deserialization size error"); - return -1; - } - value_type val; - for (size_t i=0; i<__size; ++i) { - if (bsl::deserialization(ar, val)) { - __BSL_ERROR("deserialization val at[%ld] error", (long)i); - return -1; - } - if (set(_hashfun(_getkey(val)), _getkey(val), val) == -1) { - __BSL_ERROR("deserialization set at[%ld] error", (long)i); - return -1; - } - } - - return 0; - } - - /** - * @brief 数据反串行化,允许有重复key - * - * @param [in/out] ar : _Archive & - * @return int 0:正确返回,-1:错误 - * @author luowei - * @date 2012/08/21 17:11:02 - **/ - template - int deserialization_multimap(_Archive & ar) - { - size_t bitems = 0; - if (bsl::deserialization(ar, bitems)) - { - __BSL_ERROR("deserialization bitems error"); - return -1; - } - __BSL_DEBUG("bitems = %ld", (long)bitems); - - if (_bucket) - { - clear(); - } - else - { - if (create(bitems, _HashFun(), _Equl())) - { - __BSL_ERROR("create hashtable error"); - return -1; - } - } - - size_t __size = 0; - if (bsl::deserialization(ar, __size)) - { - __BSL_ERROR("deserialization size error"); - return -1; - } - value_type val; - for (size_t i=0; i<__size; ++i) - { - if (bsl::deserialization(ar, val)) - { - __BSL_ERROR("deserialization val at[%ld] error", (long)i); - return -1; - } - if (set_multimap(_hashfun(_getkey(val)), val.first, val.second, 1) == -1) - { - printf("deserialization set at[%ld] error", (long)i); - return -1; - } - } - return 0; - } - - int clear() { - for (size_t i=0; i<_bitems; ++i) { - node_pointer nd = 0; - while (_bucket[i]) { - nd = _bucket[i]; - _bucket[i] = _sp_alloc.getp(_bucket[i])->next; - bsl::bsl_destruct(&_sp_alloc.getp(nd)->val); - _sp_alloc.deallocate(nd, 1); - } - } - _size = 0; - return 0; - } - -protected: - int recreate(size_t bitems) { - _bitems = bitems; - //默认_bitems大小 - //modified by chenyanling@baidu.com - //2011/11/15 - if(_bitems == 0) - { - _bitems = HASHTABLE_BITEMS; - } - - _sp_alloc.create(); - _np_alloc.create(); - _bucket = _np_alloc.allocate(_bitems); - if (_bucket == 0) { - goto err; - } - memset(_bucket, 0, sizeof(node_pointer ) * _bitems); - - //初始化end 迭代器 - _end_iter._ht = this; - _end_iter._bucketpos = _bitems; - _end_iter._node = 0; - - _size = 0; - return 0; - err: - _sp_alloc.destroy(); - _np_alloc.destroy(); - _bitems = 0; - _end_iter._bucketpos = 0; - return -1; - } -private: - void _reset(){ - _bitems = 0; - _bucket = 0; - _end_iter._ht = this; - _end_iter._bucketpos = 0; - _end_iter._node = 0; - _size = 0; - } -}; - -} - -#endif //__BSL_HASHTABLE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_hashutils.h b/bsl/containers/hash/bsl_hashutils.h deleted file mode 100644 index a874f1d3048e249722d17df5b3a95361b0256c90..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_hashutils.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_hashutils.h,v 1.3 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_hashutils.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/13 17:40:15 - * @version $Revision: 1.3 $ - * @brief - * - **/ - - -#ifndef __BSL_HASHUTILS_H_ -#define __BSL_HASHUTILS_H_ -#include - -#include "bsl_hash_fun.h" - -namespace bsl -{ - -enum { - HASH_EXIST = 0xffff, //hash值存在 - HASH_NOEXIST, //hash值不存在 - HASH_OVERWRITE, //覆盖原有的hash值 - HASH_INSERT_SEC, //插入成功 -}; - -#if 0 -template -struct xhash -{ - inline size_t operator () (const _Tp &_1) const { - return size_t(_1); - } -}; -#endif - -enum { __bsl_num_primes = 28 }; - -static const unsigned long __bsl_prime_list[__bsl_num_primes] = -{ - 53ul, 97ul, 193ul, 389ul, 769ul, - 1543ul, 3079ul, 6151ul, 12289ul, 24593ul, - 49157ul, 98317ul, 196613ul, 393241ul, 786433ul, - 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, - 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul, - 1610612741ul, 3221225473ul, 4294967291ul -}; - -inline unsigned long __bsl_next_prime(unsigned long __n) -{ - const unsigned long* __first = __bsl_prime_list; - const unsigned long* __last = __bsl_prime_list + (int)__bsl_num_primes; - const unsigned long* pos = std::lower_bound(__first, __last, __n); - return pos == __last ? *(__last - 1) : *pos; -} - -}; - - -#ifndef BSL_USER_LOCK -#define BSL_RWLOCK_T pthread_rwlock_t -#define BSL_RWLOCK_INIT(lock) pthread_rwlock_init(lock, NULL) -#define BSL_RWLOCK_DESTROY(lock) pthread_rwlock_destroy(lock) -#define BSL_RWLOCK_RDLOCK(lock) pthread_rwlock_rdlock(lock) -#define BSL_RWLOCK_WRLOCK(lock) pthread_rwlock_wrlock(lock) -#define BSL_RWLOCK_UNLOCK(lock) pthread_rwlock_unlock(lock) -#endif - - - - - - - - - - - -#endif //__BSL_HASHUTILS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_phashmap.h b/bsl/containers/hash/bsl_phashmap.h deleted file mode 100644 index 721589cc8ede940291d2a3c6c974f626eb6b8382..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_phashmap.h +++ /dev/null @@ -1,183 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_phashmap.h,v 1.2 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file phashmap.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/05 21:23:54 - * @version $Revision: 1.2 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_PHASHMAP_H_ -#define __BSL_PHASHMAP_H_ - -#include - -namespace bsl -{ - -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2); - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class phashmap : public bsl_phashtable<_Key, std::pair<_Key, _Value>, _HashFun, _Equl, - bsl::pair_first >, _InnerAlloc> -{ -public: - typedef std::pair<_Key, _Value> _Pair; - typedef phashmap<_Key, _Value, _HashFun, _Equl, _InnerAlloc> _Self; - typedef bsl_phashtable<_Key, _Pair, _HashFun, _Equl, bsl::pair_first<_Pair>, _InnerAlloc> _Base; - typedef typename _Base::iterator iterator; - typedef typename _Base::const_iterator const_iterator; - - typedef _Value value_type; - typedef _Key key_type; - -private: - /* * - * @beirf 拷贝构造函数 - **/ - phashmap(const _Self &); //禁用 - /* * - * @brief 赋值运算符 - * */ - _Self & operator = (const _Self &); //禁用 - -public: - - /** - * @brief 默认构造函数 - * 无异常 - * 需调用create才能用 - **/ - phashmap(){} - - /** - * @brief 带桶大小的构造函数 - * 如果失败抛异常 - * 不需调用create - * - * @param [in] bitems : size_t hash桶个数 - * @param [in] rwlsize : size_t 读写锁个数 - * @param [in] hf : const _HashFun& hash函数 - * @param [in] eq : const _Equl& 比较函数 - **/ - phashmap(size_t bitems, size_t rwlsize = 0, - const _HashFun &hf = _HashFun(), - const _Equl &eq = _Equl()): - _Base(bitems, rwlsize, hf, eq){ - } - - /** - * create方法参考phashtable的方法,直接继承 - * destroy方法也直接继承 - */ - - - /** - * @brief 根据指定key获取value值 - * - * @param [in/out] k : const key_type& 指定的查找key - * @param [in/out] val : value_type* 获取的value值的存储地址 - * 如果value不为空,将*val附值查找的值 - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k, value_type *val = 0) const { - return _Base::get_map(k, val); - } - int get(const key_type &k, value_type *val = 0) { - return _Base::get_map(k, val); - } - - /** - * @brief 根据指定key获取value,应用回调函数,返回原值 - * 若不需要原值,传入NULL指针 - * _ValOpFunc可以是函数指针,也可以是functor,参数类型为(_Second*, void*) - **/ - template - int get(const key_type &k, value_type *old_val, _ValOpFunc val_op_func, void *args = 0) { - return _Base::get_map(k, old_val, val_op_func, args); - } - - /** - * @brief 将key 和 value 对 插入 hash表中 - * - * @param [in/out] k : const key_type& key值 - * @param [in/out] val : const value_type& value值 - * @param [in/out] flag : int - * flag ==0,如果值存在直接返回, - * 非0表示,如果值存在,替换旧值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面三个状态 - * 返回 HASH_OVERWRITE 表示覆盖旧结点成功(在flag非0的时候返回) - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:20:49 - **/ - int set(const key_type &k, const value_type &val, int flag = 0) { - return _Base::set(k, _Pair(k, val), flag); - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - return _Base::erase(k); - } -}; - -}; - - -#endif //__PHASHMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_phashset.h b/bsl/containers/hash/bsl_phashset.h deleted file mode 100644 index f6f4a13f399160f2764db8778da4227efb04d46d..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_phashset.h +++ /dev/null @@ -1,174 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_phashset.h,v 1.2 2008/12/15 09:56:59 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file phashset.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/13 22:05:17 - * @version $Revision: 1.2 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_PHASHSET_H_ -#define __BSL_PHASHSET_H_ - -#include - -namespace bsl -{ - -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2); - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class phashset : public bsl_phashtable<_Key, _Key, _HashFun, _Equl, - bsl::param_select<_Key>, _InnerAlloc> -{ -public: - typedef phashset<_Key, _HashFun, _Equl, _InnerAlloc> _Self; - typedef bsl_phashtable<_Key, _Key, _HashFun, _Equl, bsl::param_select<_Key>, _InnerAlloc> _Base; - typedef typename _Base::iterator iterator; - typedef typename _Base::const_iterator const_iterator; - typedef _Key value_type; - typedef _Key key_type; -private: - /** - * @brief 拷贝构造函数 - * */ - phashset(const _Self&); //禁用 - /** - * @brief 赋值运算符 - * */ - _Self & operator = (const _Self &); //禁用 - -public: - - /** - * @brief 默认构造函数 - * 无异常 - * 需调create - **/ - phashset(){} - - /** - * @brief 带桶大小的构造函数 - * 抛异常 - * 不需调create - * @param [in] bitems : size_t hash桶个数 - * @param [in] rwlsize : size_t 读写锁个数 - * @param [in] hf : const _HashFun& hash函数 - * @param [in] eq : const _Equl& 比较函数 - **/ - phashset(size_t bitems, size_t rwlsize = 0, - const _HashFun &hf = _HashFun(), - const _Equl &eq = _Equl()) - :_Base(bitems, rwlsize, hf, eq){ - } - - /** - * create方法参考phashtable的方法,直接继承 - * destroy方法也直接继承 - */ - - /** - * @brief 查询key_type是否存在 - * - * @param [in/out] k : const key_type& 指定的查找key - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k) const { - return _Base::get(k); - } - int get(const key_type &k) { - return _Base::get(k); - } - - /** - * @brief 将key插入 hash表中 - * - * @param [in/out] k : const key_type& key值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面三个状态 - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:20:49 - **/ - int set(const key_type &k) { - return _Base::set(k, k); - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - return _Base::erase(k); - } - -}; - -}; - - - - - - - - - - - - - - - -#endif //__PHASHSET_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/containers/hash/bsl_phashtable.h b/bsl/containers/hash/bsl_phashtable.h deleted file mode 100644 index 03740ebbf102cb8d12933b437beedffea7bfacec..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_phashtable.h +++ /dev/null @@ -1,1261 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_phashtable.h,v 1.11 2010/02/24 09:19:45 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_phashtable.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/05 11:19:36 - * @version $Revision: 1.11 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_PHASHTABLE_H_ -#define __BSL_PHASHTABLE_H_ -#include -#include -#include -#include -#include -#include - -namespace bsl -{ - -enum { - PHASH_NORMAL = 0, //正常状态 - PHASH_START_CHECKPOINT, //开始CHECKPOINTER - PHASH_END_CHECKPOINT, //checkpoint 完之后内存整理 -}; - -/** - * @brief 线程安全的hashtable - */ -template -class bsl_phashtable -{ - - public: - /** - * @brief 自身的别名 - */ - typedef bsl_phashtable<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> _Self; - /** - * @brief 内部使用的hashtable - */ - typedef bsl_hashtable<_Key, _Value, _HashFun, _Equl, _GetKey, _InnerAlloc> _Base; - /** - * @brief 迭代器 - */ - typedef typename _Base::iterator iterator; - /** - * @brief 只读迭代器 - */ - typedef typename _Base::const_iterator const_iterator; - /** - * @brief 值 - */ - typedef _Value value_type; - /** - * @brief 键 - */ - typedef _Key key_type; - /** - * @brief 键值的指针类型 - */ - typedef value_type * pointer; - - typedef typename _Base::node_pointer node_pointer; - typedef typename _Base::node_t node_t; - typedef typename _InnerAlloc::pool_type pool_type; - - struct deleteNode { - node_pointer lst; - size_t key; - }; - typedef std::vector deleteVec; - - BSL_RWLOCK_T * _rwlocks; - size_t _rwlocksize; - size_t _tmpsize; //保存在dump的时候有多少个结点差 - node_pointer *_tmplist; //临时用来检索的拉链 - volatile int _flag; //标志当前状态 - typedef typename pool_type::template rebind::other lockalloc_type; - //typedef typename pool_type::template rebind::other nodealloc_type; - - /** - * @brief 内部的hashtable - * - */ - _Base _base; - lockalloc_type _lockalloc; - //nodealloc_type _nodealloc; - - bool _mlockcreat; - pthread_mutex_t _cplock; - pthread_mutex_t _uplock; - mutable pthread_mutex_t _hslock;//用来在_end_checkpoint和_get时锁住_hashset和_tmplist - typedef bsl_rwhashset, std::equal_to, _InnerAlloc> _Set; - typedef typename pool_type::template rebind<_Set>::other setalloc_type; - _Set *_hashset; - setalloc_type _setalloc; - protected: - /** - * @brief 申请读写锁 - */ - int alloc_rwlocks(size_t bitems, size_t lsize) { - if (lsize > bitems) { - _rwlocksize = bitems; - } else { - _rwlocksize = lsize; - } - if (_rwlocksize <= 0) { - _rwlocksize = (1 + (size_t)((float)(0.05)*(float)bitems)); - if (_rwlocksize > 100) { - _rwlocksize = 100; - } - } - _rwlocks = _lockalloc.allocate(_rwlocksize); - if (_rwlocks == 0) { - return -1; - } - //__BSL_DEBUG("allocate rwlocsk %d", (int)_rwlocksize); - - for (size_t i=0; i<_rwlocksize; ++i) { - BSL_RWLOCK_INIT(_rwlocks+i); - } - return 0; - } - /** - * @brief 重新创建phashtable - */ - int recreate(size_t bitems, size_t rwlsize) { - _tmpsize = 0; - _tmplist = NULL; - _flag = PHASH_NORMAL; - - _lockalloc.create(); - //_nodealloc.create(); - _setalloc.create(); - - if (alloc_rwlocks(bitems, rwlsize) != 0) { - goto err; - } - - return 0; - err: - if (_rwlocks) { - for (size_t i=0; i<_rwlocksize; ++i) { - BSL_RWLOCK_DESTROY(_rwlocks+i); - } - _lockalloc.deallocate(_rwlocks, _rwlocksize); - } - _rwlocks = NULL; - _rwlocksize = 0; - _lockalloc.destroy(); - //_nodealloc.destroy(); - _setalloc.destroy(); - return -1; - } - - void destruct_node(node_pointer node, size_t key) { - BSL_RWLOCK_T &__lock = _rwlocks[key % _rwlocksize]; - BSL_RWLOCK_WRLOCK(&__lock); - bsl::bsl_destruct(&(_base._sp_alloc.getp(node)->val)); - _base._sp_alloc.deallocate(node, 1); - BSL_RWLOCK_UNLOCK(&__lock); - } - private: - /** - * @brief 拷贝构造函数 - */ - bsl_phashtable(const _Self&); //禁用 - /** - * @brief 赋值运算符 - */ - _Self & operator = (const _Self &); //禁用 - - public: - /** - * @brief 构造函数 - * 无异常 - * 需调create - */ - bsl_phashtable() { - _reset(); - } - /** - * @brief 带桶大小的构造函数 - * 如果构造失败,将销毁对象 - * - * 抛异常 - * 不需调create - * - * @param [in] bitems : size_t hash桶个数 - * @param [in] rwlsize : size_t 读写锁个数 - * @param [in] hf : const _HashFun& hash函数 - * @param [in] eq : const _Equl& 比较函数 - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/30 13:42:53 - **/ - bsl_phashtable(size_t bitems, size_t rwlsize = 0, - const _HashFun &hf = _HashFun(), - const _Equl &eq = _Equl()) { - _reset(); - if (create(bitems,rwlsize,hf,eq) != 0) { - destroy(); - throw BadAllocException()<= size_t(-1) / sizeof(void *)) { - __BSL_ERROR("too large bitems, overflower"); - return -1; - } - - //判断hash桶数 - if(0 == bitems){ - __BSL_ERROR("bitems == 0"); - } - - if (destroy() != 0) { - __BSL_ERROR("destroy error when create hash bitems[%lu]", (unsigned long)bitems); - return -1; - } - if (recreate(bitems, rwlsize) != 0) { - __BSL_ERROR("recreate error when create hash bitems[%lu], rwlsize[%lu]", - (unsigned long)bitems, (unsigned long)rwlsize); - return -1; - } - - if (pthread_mutex_init(&_cplock, NULL) != 0) { - int ret = destroy(); - __BSL_ERROR("init cplock err, destroy data[%d]", ret); - return -1; - } - if (pthread_mutex_init(&_uplock, NULL) != 0) { - int ret = destroy(); - __BSL_ERROR("init uplock err, destroy data[%d]", ret); - pthread_mutex_destroy(&_cplock); - return -1; - } - - if (pthread_mutex_init(&_hslock, NULL) != 0) { - int ret = destroy(); - __BSL_ERROR("init uplock err, destroy data[%d]", ret); - pthread_mutex_destroy(&_cplock); - pthread_mutex_destroy(&_uplock); - return -1; - } - - _mlockcreat = true; - - _hashset = NULL; - return _base.create(bitems, hf, eq); - } - - /* * - * @brief 判断phashtable是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return _base.is_created(); - } - - /** - * @brief 销毁hash表 - * - * @return int 返回0表示删除成功,其他表示删除失败 - * 失败的情况是容器正在dump数据 - * @retval 线程不安全 - * @see - * @author xiaowei - * @date 2008/08/12 21:16:39 - **/ - int destroy() { - if (_flag != PHASH_NORMAL) { - return -1; - } - if (_rwlocks) { - for (size_t i=0; i<_rwlocksize; ++i) { - BSL_RWLOCK_DESTROY(_rwlocks + i); - } - //__BSL_DEBUG("release rwlocks[%ld]", _rwlocksize); - _lockalloc.deallocate(_rwlocks, _rwlocksize); - } - _rwlocks = NULL; - _rwlocksize = 0; - - if (_tmplist) { - //_nodealloc.deallocate(_tmplist, _base._bitems); - _base._np_alloc.deallocate(_tmplist, _base._bitems); - } - _tmplist = NULL; - - if (_hashset != NULL) { - _hashset->destroy(); - bsl::bsl_destruct(_hashset); - _setalloc.deallocate(_hashset, 1); - _hashset = NULL; - } - - _lockalloc.destroy(); - //_nodealloc.destroy(); - _setalloc.destroy(); - if (_mlockcreat) { - pthread_mutex_destroy(&_cplock); - pthread_mutex_destroy(&_uplock); - pthread_mutex_destroy(&_hslock); - _mlockcreat = false; - } - return _base.destroy(); - } - - - /** - * @brief 清空数据 - * - * @return int 0表示成功,其他表示失败 - * @retval 只有在非dump状态才能清空数据 - * 如果容器处于checkpoint状态,clear返回-1 - * @see - * @author xiaowei - * @date 2008/08/12 22:59:36 - **/ - int clear() { - if (!_mlockcreat) {//没有初始化锁 - return 0; - } - mutexlock_monitor q(&_uplock); - if (_flag != PHASH_NORMAL) { - return -1; - } - for (size_t i=0; i<_base._bitems; ++i) { - node_pointer nd = 0; - while (_base._bucket[i]) { - nd = _base._bucket[i]; - _base._bucket[i] = _base._sp_alloc.getp(_base._bucket[i])->next; - destruct_node(nd, i); - } - } - _base._size = 0; - _tmpsize = 0; - return 0; - } - - /** - * @brief 当前时刻创建内存dump - * - * @return int 0表示成功创建 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 23:00:17 - **/ - int make_checkpoint() { - //先锁cp 再锁up防止死锁 - //mutexlock_monitor l(&_cplock); - //mutexlock_monitor q(&_uplock); - if (pthread_mutex_trylock(&_cplock) != 0) { - return -1; - } - if (pthread_mutex_lock(&_uplock) != 0) { - pthread_mutex_unlock(&_cplock); - return -1; - } - int ret = _make_checkpoint(); - pthread_mutex_unlock(&_uplock); - pthread_mutex_unlock(&_cplock); - - return ret; - } - - /** - * @brief make_checkpoint掉完之后和end_checkpoint被调用之前 - * make_checkpoint调用瞬间的内存将被锁住,你可以对这个内存在另外的线程里面 - * 做遍历读操作. - * - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/08/18 17:37:46 - **/ - int end_checkpoint() { - mutexlock_monitor l(&_cplock); - return _end_checkpoint(); - } - - /** - * @brief 序列化方法,外面申明一个archive实体 ar - * 调用ar.write()进行序列化到指定位置 - * 这里实现的是如何将这个类打包成流 - * - * @param [in/out] ar : _Archive& 序列化句柄 - * @return int 成功返回0,失败返回 -1 - * @retval 注意!!!!想序列化一个线程安全的hash表 - * 必须调用make_checkpoint,这样他才知道序列化哪些内存 - * 因为多读多写下,hash表的状态是变化的,但是序列化内存是你调用 - * make_checkpoint瞬间的内存映射,在 serialization 函数返回之前, - * 所有的更新操作,都不会被序列化 - * - * 如果你没有调用checkpoint,那么 serialization 函数调用的时候,会 - * 显著帮你调用一个,dump当前内存 - * - * 线程安全 - * @see - * @note - * @author xiaowei - * @date 2008/08/13 14:21:21 - **/ - template - int serialization(_Archive & ar) { - mutexlock_monitor l(&_cplock); - int ret = -1; - __BSL_DEBUG("this = 0x%lx", (long)(this)); - //锁没被获取,这样需要调用make_checkpoint获取锁 - { - mutexlock_monitor q(&_uplock); - if (_flag == PHASH_NORMAL) { - ret = _make_checkpoint(); - if (ret != 0) { - return -1; - } - } - if (_flag != PHASH_START_CHECKPOINT) { - return -1; - } - } - { - if (_base.serialization(ar) != 0) { - _end_checkpoint(); - return -1; - } - } - - __BSL_DEBUG("_flag = %d", _flag); - //checkpoint完毕之后的收尾工作 - return _end_checkpoint(); - } - - /** - * @brief 从序列化流中,重建数据结构 - * - * @param [in/out] ar : _Archive& - * @return template int 成功返回0,失败返回-1 - * @retval 不可重入的算法 - * @see - * @note - * @author xiaowei - * @date 2008/08/13 14:24:50 - **/ - template - int deserialization(_Archive & ar) { - size_t bitems = 0; - if (bsl::deserialization(ar, bitems) != 0) { - __BSL_ERROR("deserialization bitems error"); - return -1; - } - __BSL_DEBUG("bitems = %ld", (long)bitems); - - //已经被初始化过 - if (_base._bucket) { - if (clear() != 0) { - __BSL_ERROR("clear phashtable error"); - return -1; - } - } else { //没有初始化过 - if (create(bitems) != 0) { - __BSL_ERROR("create hashtable error"); - return -1; - } - } - - size_t __size = 0; - if (bsl::deserialization(ar, __size) != 0) { - __BSL_ERROR("deserialization size error"); - return -1; - } - value_type val; - for (size_t i=0; i<__size; ++i) { - if (bsl::deserialization(ar, val) != 0) { - __BSL_ERROR("deserialization val at[%ld] error", (long)i); - return -1; - } - if (set(_base._getkey(val), val) == -1) { - __BSL_ERROR("deserialization set at[%ld] error", (long)i); - return -1; - } - } - - return 0; - } - - /** - * @brief 根据指定key获取value值 - * - * @param [in/out] k : const key_type& 指定的查找key - * @param [in/out] val : value_type* 获取的value值的存储地址 - * 如果value不为空,将*val赋值查找的值 - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k, value_type *val = 0) const { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[ key % _rwlocksize]; - BSL_RWLOCK_RDLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (val) { - *val = *ptr; - } - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 根据指定key获取value值 - */ - int get(const key_type &k, value_type *val = 0) { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[ key % _rwlocksize]; - BSL_RWLOCK_RDLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (val) { - *val = *ptr; - } - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 根据指定key获取value值,应用回调函数,返回原值 - * 若不需要原值,传入NULL指针 - * _ValOpFunc可以是函数或functor,参数为(value_type*, void*) - */ - template - int get(const key_type &k, value_type *old_val, _ValOpFunc val_op_func, void *args = 0){ - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[ key % _rwlocksize]; - BSL_RWLOCK_WRLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (old_val) { - *old_val = *ptr; - } - val_op_func(ptr, args); - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 根据指定key获取valua pair中的second值 - * - * @param [in/out] k : const key_type& 指定的查找key - * @param [in/out] val : _Second* 获取的second值的存储地址 - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - template - int get_map(const key_type &k, _Second *val = 0) const { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[key % _rwlocksize]; - BSL_RWLOCK_RDLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (val) { - *val = ptr->second; - } - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 根据指定key获取valua pair中的second值 - **/ - template - int get_map(const key_type &k, _Second *val = 0) { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[key % _rwlocksize]; - BSL_RWLOCK_RDLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (val) { - *val = ptr->second; - } - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 根据指定key获取value pair中的second值,应用回调函数,返回原值 - * 若不需要原值,传入NULL指针 - * _ValOpFunc可以是函数指针,也可以是functor,参数类型为(_Second*, void*) - **/ - template - int get_map(const key_type &k, _Second *old_val, _ValOpFunc val_op_func, void *args = 0) { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - BSL_RWLOCK_T &__lock = _rwlocks[key % _rwlocksize]; - BSL_RWLOCK_WRLOCK(&__lock); - value_type *ptr = _get(key, k); - int ret = HASH_NOEXIST; - if (ptr) { - ret = HASH_EXIST; - if (old_val) { - *old_val = ptr->second; - } - val_op_func(&(ptr->second), args); - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 将key 和 value 对 插入 hash表中 - * - * @param [in/out] k : const key_type& key值 - * @param [in/out] val : const value_type& value值 - * @param [in/out] flag : int - * flag ==0,如果值存在直接返回, - * 非0表示,如果值存在,替换旧值 - * @return int - * 返回 -1 表示set调用出错, (无法分配新结点) - * 其他均表示插入成功:插入成功分下面三个状态 - * 返回 HASH_OVERWRITE 表示覆盖旧结点成功(在flag非0的时候返回) - * 返回 HASH_INSERT_SEC 表示插入新结点成功 - * 返回 HASH_EXIST 表示hash表结点存在(在flag为0的时候返回) - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:20:49 - **/ - int set(const key_type &k, const value_type &val, int flag = 0) { - if(0 == _base._bitems){ - return -1; - } - size_t key = _base._hashfun(k) % _base._bitems; - mutexlock_monitor q(&_uplock); - int ret = _set(key, k, val, flag); - return ret; - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - if(0 == _base._bitems){ - return HASH_NOEXIST; - } - size_t key = _base._hashfun(k) % _base._bitems; - mutexlock_monitor q(&_uplock); - int ret = _erase(key, k); - return ret; - } - - /** - * @brief 附值是先清空数据,后附值,所以如果附值失败,会将数据清空 - * @附值过程中,原来的老数据已经被删除,可能检索不出来 - * - * @param [in/out] __begin : _Iterator - * @param [in/out] __end : _Iterator - * @return int - * 成功返回 0 - * 如果容器没有调用create,将返回-1失败 - * 如果容器clean失败,将返回-1 - * 如果容器处于checkpoint状态,将返回-1失败 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/08/13 22:03:43 - **/ - template - int assign(_Iterator __begin, _Iterator __end) { - if (clear() != 0) { - __BSL_ERROR("inside assign clear error"); - return -1; - } - if (_base._bitems <= 0) { - __BSL_ERROR("didn't create before assign"); - return -1; - } - //__BSL_DEBUG("start to phashtable assign"); - mutexlock_monitor q(&_uplock); - //__BSL_DEBUG("inside lock"); - if (_flag == PHASH_NORMAL) { - for (_Iterator iter = __begin; iter != __end; ++iter) { - if ( _base.set(_base._hashfun(_base._getkey(*iter)), - _base._getkey(*iter), *iter) == -1 ) { - __BSL_ERROR("set error in phashtable assign"); - return -1; - } - ++ _tmpsize; - } - return 0; - } - return -1; - } - - public: - value_type * _get(size_t key, const key_type &k) const { - //正常情况下 - if (_flag == PHASH_NORMAL) { - return _base.find(key, k); - } else { - if(_tmplist!=NULL){ - mutexlock_monitor __lock(&_hslock); - if(_tmplist!=NULL){ - //在新链上查是否有数据 - node_pointer lst = _tmplist[key]; - while (lst) { - if (_base._equl(_base._getkey(_base._sp_alloc.getp(lst)->val), k)) { - return & _base._sp_alloc.getp(lst)->val; - } - lst = _base._sp_alloc.getp(lst)->next; - } - } - } - //新链上没有查到数据 - //老链上查找数据 - value_type *val = _base.find(key, k); - if(_hashset!=NULL){ - mutexlock_monitor __lock(&_hslock); - //查看是否标志删除 - if (_hashset!=NULL && _hashset->get(val) == HASH_EXIST) { - return NULL; - } - } - return val; - } - } - - - value_type * _get(size_t key, const key_type &k) { - //正常情况下 - if (_flag == PHASH_NORMAL) { - return _base.find(key, k); - } else { - if(_tmplist!=NULL){ - mutexlock_monitor __lock(&_hslock); - if(_tmplist!=NULL){ - //在新链上查是否有数据 - node_pointer lst = _tmplist[key]; - while (lst) { - if (_base._equl(_base._getkey(_base._sp_alloc.getp(lst)->val), k)) { - return & _base._sp_alloc.getp(lst)->val; - } - lst = _base._sp_alloc.getp(lst)->next; - } - } - } - //新链上没有查到数据 - //老链上查找数据 - value_type *val = _base.find(key, k); - if(_hashset!=NULL){ - mutexlock_monitor __lock(&_hslock); - //查看是否标志删除 - if (_hashset!=NULL && _hashset->get(val) == HASH_EXIST) { - return NULL; - } - } - return val; - } - } - - int _set(size_t key, const key_type &k, const value_type &val, int flag) { - int ret = 0; - switch (_flag) { - case PHASH_START_CHECKPOINT: - ret = _start_cp_set(key, k, val, flag); - break; - case PHASH_END_CHECKPOINT: - ret = _end_cp_set(key, k, val, flag); - break; - default: - ret = _normal_set(key, k, val, flag, _base._bucket); - break; - } - if (ret == HASH_INSERT_SEC) { - ++ _tmpsize; - } - return ret; - } - - int _end_cp_set(size_t key, const key_type &k, const value_type &val, int flag) { -#if 0 - value_type *ptr = _base.find(key, k); - if (ptr) { //底层bucket中存在结点 - //查看结点是否被删除 - if (_hashset->get(ptr) != HASH_EXIST) { - //结点不存在 - return _normal_set(key, k, val, flag, _base._bucket); - } - } - return _normal_set(key, k, val, flag, _tmplist); -#endif - value_type *ptr = _base.find(key, k); - if (ptr) { //底层bucket中存在结点 - //查看结点是否被删除, 且队列也是空的 - if (_hashset->get(ptr) != HASH_EXIST) { - //结点没有被删除过 - if (_tmplist[key] == 0) { - return _normal_set(key, k, val, flag, _base._bucket); - } else { - if (flag == 0) { - return HASH_EXIST; - } else { - _normal_erase(key, k, _base._bucket); - _normal_set(key, k, val, flag, _tmplist); - return HASH_OVERWRITE; - } - } - } else { - return _normal_set(key, k, val, flag, _tmplist); - } - } else { - if (_tmplist[key] == 0) { - return _normal_set(key, k, val, flag, _base._bucket); - } else { - return _normal_set(key, k, val, flag, _tmplist); - } - } - return 0; - } - int _start_cp_set(size_t key, const key_type &k, const value_type &val, int flag) { - int tmp = 0; - value_type *ptr = _base.find(key, k); - if (ptr) { //覆盖 - if (flag) { - //标志删除 - if (_hashset->set(ptr) == HASH_INSERT_SEC) { - tmp = 1; //表示存在这个元素,且有效,现在标志删除 - } - } else { - //如果不需要替换,查看是否被标志删除过 - if (_hashset->get(ptr) != HASH_EXIST) { - //没有被标志删除过,直接返回 - return HASH_EXIST; - } - } - } - //需要在新链上修改数据 - int ret = _normal_set(key, k, val, flag, _tmplist); - if (ret != -1 && tmp == 1) { - return HASH_OVERWRITE; - } - return ret; - } - - int _normal_set(size_t key, const key_type &k, const value_type &val, - int flag, node_pointer * __bucket) { - node_pointer lst = __bucket[key]; - node_pointer front = 0; - int ret = -1; - while (lst) { - if (_base._equl(_base._getkey(_base._sp_alloc.getp(lst)->val), k)) { - if (flag) { - ret = HASH_OVERWRITE; - break; - } - return HASH_EXIST; - } - front = lst; - lst = _base._sp_alloc.getp(lst)->next; - } - node_pointer node = _base._sp_alloc.allocate(1); - if (0 == node) { - return -1; - } - - bsl::bsl_construct(&(_base._sp_alloc.getp(node)->val), val); - - //insertion bug fixed. - if (ret == HASH_OVERWRITE) { - _base._sp_alloc.getp(node)->next = _base._sp_alloc.getp(lst)->next; - if (front) { - _base._sp_alloc.getp(front)->next = node; - }else{ - __bucket[key] = node; - } - destruct_node(lst, key); - return ret; - } else { - _base._sp_alloc.getp(node)->next = __bucket[key]; - __bucket[key] = node; - } - - return HASH_INSERT_SEC; - } - - int _erase(size_t key, const key_type &k) { - int ret = 0; - switch (_flag) { - case PHASH_START_CHECKPOINT: - ret = _start_cp_erase(key, k); - break; - case PHASH_END_CHECKPOINT: - ret = _end_cp_erase(key, k); - break; - default: - ret = _normal_erase(key, k, _base._bucket); - break; - } - if (ret == HASH_EXIST) { - -- _tmpsize; - } - return ret; - } - - int _start_cp_erase(size_t key, const key_type &k) { - value_type *ptr = _base.find(key, k); - if (ptr != NULL) { - if (_hashset->set(ptr) == HASH_INSERT_SEC) { - //存在,标志删除 - return HASH_EXIST; - } - } - return _normal_erase(key, k, _tmplist); - } - - int _end_cp_erase(size_t key, const key_type &k) { - int ret = _normal_erase(key, k, _tmplist); - if (ret == HASH_NOEXIST) { - value_type *ptr = _base.find(key, k); - if (ptr == NULL || _hashset->get(ptr) == HASH_EXIST) { - return HASH_NOEXIST; - } - return _normal_erase(key, k, _base._bucket); - } - return ret; - } - - int _normal_erase(size_t key, - const key_type &k, - node_pointer *__bucket, - deleteVec *delvec = NULL - ) { - node_pointer lst = __bucket[key]; - node_pointer front = 0; - while (lst) { - if (_base._equl(_base._getkey(_base._sp_alloc.getp(lst)->val), k)) { - if (front == 0) { - __bucket[key] = _base._sp_alloc.getp(lst)->next; - } else { - _base._sp_alloc.getp(front)->next = _base._sp_alloc.getp(lst)->next; - } - if (delvec == NULL) { - destruct_node(lst, key); - } else { - deleteNode delnode; - delnode.lst = lst; - delnode.key = key; - try { - delvec->push_back(delnode); - } catch (...) { - destruct_node(lst, key); - } - } - return HASH_EXIST; - } - front = lst; - lst = _base._sp_alloc.getp(lst)->next; - } - return HASH_NOEXIST; - } - - private: - void _reset(){ - _rwlocks = NULL; - _rwlocksize = 0; - _tmpsize = 0; - _tmplist = NULL; - _flag = PHASH_NORMAL; - _hashset = NULL; - _mlockcreat = false; - } - - int _make_checkpoint() { - if (_flag != PHASH_NORMAL) { - return -1; - } - if (_tmplist == NULL) { - //_tmplist = _nodealloc.allocate(_base._bitems); - _tmplist = _base._np_alloc.allocate(_base._bitems); - if (_tmplist == NULL) { - return -1; - } - memset(_tmplist, 0, sizeof(node_pointer ) * _base._bitems); - } - if (_hashset == NULL) { - _hashset = _setalloc.allocate(1); - bsl::bsl_construct(_hashset); - if (_hashset == NULL) { - return -1; - } - if (_hashset->create(__bsl_next_prime(1<<15)) != 0) { - bsl::bsl_destruct(_hashset); - _setalloc.deallocate(_hashset, 1); - _hashset = NULL; - return -1; - } - } - _flag = PHASH_START_CHECKPOINT; - _base._size = _tmpsize; - __BSL_DEBUG("make checkpoint end %lu %lu", (long)_base._size, (long)_tmpsize); - return 0; - } - - int _end_checkpoint() { - //__BSL_DEBUG("start to end checkpoint"); - if (_flag != PHASH_START_CHECKPOINT) { - //__BSL_ERROR("dumpstatus error flag[%d]", _flag); - return -1; - } - - AUTO_TIMER("end checkpoint"); - { - mutexlock_monitor l(&_uplock); - _flag = PHASH_END_CHECKPOINT; - } - { - { - __BSL_DEBUG("lock _hashset->lock"); - mutexlock_monitor t(&_hashset->_lock); - __BSL_DEBUG("in lock _hashset->lock items %lu", (long)_hashset->_ht._bitems); - for (size_t i=0; i<_hashset->_ht._bitems; ++i) { - mutexlock_monitor l(&_uplock); - BSL_RWLOCK_T &__lock = _hashset->get_rwlock(i); - BSL_RWLOCK_WRLOCK(&__lock); - deleteVec delvec; - typename _Set::hash_type::node_pointer nd = 0; - while (_hashset->_ht._bucket[i]) { - nd = _hashset->_ht._bucket[i]; - { - const key_type & key = - _base._getkey(*(_hashset->_ht._sp_alloc.getp(nd)->val)); - _normal_erase(_base._hashfun(key) % _base._bitems, - key, - _base._bucket, - &delvec - ); - } - //考虑get的时候 检索可能出的问题 - _hashset->_ht._bucket[i] = - _hashset->_ht._sp_alloc.getp(_hashset->_ht._bucket[i])->next; - bsl::bsl_destruct(&(_hashset->_ht._sp_alloc.getp(nd)->val)); - _hashset->_ht._sp_alloc.deallocate(nd, 1); - } - BSL_RWLOCK_UNLOCK(&__lock); - for (typename deleteVec::iterator delIter = delvec.begin(); - delIter != delvec.end(); ++delIter) { - destruct_node(delIter->lst, delIter->key); - } - } - __BSL_DEBUG("walk _ht._bitems"); - } - __BSL_DEBUG("base bitems %lu", (long)_base._bitems); - for (size_t i=0; i<_base._bitems; ++i) { - //__BSL_DEBUG("start in uplock"); - mutexlock_monitor l(&_uplock); - //__BSL_DEBUG("inside uplock"); - if (0) { - node_pointer nd = _tmplist[i]; - while (nd) { - const key_type & key = _base._getkey(_base._sp_alloc.getp(nd)->val); - if (_normal_erase(i, key, _base._bucket) == HASH_EXIST) { - -- _tmpsize; - __BSL_DEBUG("has same id %d", (int)i); - } - nd = _base._sp_alloc.getp(nd)->next; - } - } - //__BSL_DEBUG("inside uplock"); - if (_tmplist[i] != 0) { - node_pointer lst = _base._bucket[i]; - node_pointer front = 0; - while (lst) { - front = lst; - lst = _base._sp_alloc.getp(lst)->next; - } - if (front) { - _base._sp_alloc.getp(front)->next = _tmplist[i]; - } else { - _base._bucket[i] = _tmplist[i]; - } - _tmplist[i] = 0; - - } - - } - __BSL_DEBUG("walk _tmplist"); - } - - { - _Set * __hashset = _hashset; - node_pointer *__tmplist = _tmplist; - mutexlock_monitor t(&_uplock); - //将_flag放在前面,可以使_get的时候少走一步 - _flag = PHASH_NORMAL; - { - mutexlock_monitor __lock(&_hslock); - _hashset = NULL; - _tmplist = NULL; - } - __hashset->destroy(); - bsl::bsl_destruct(__hashset); - _setalloc.deallocate(__hashset, 1); - //同理,不必判断_tmplist是否为NULL - _base._np_alloc.deallocate(__tmplist, _base._bitems); - } - - - return 0; - } -}; - -} -#endif //__BSL_PHASHTABLE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/hash/bsl_readmap.h b/bsl/containers/hash/bsl_readmap.h deleted file mode 100644 index 5c404d006f6f7d0e1be14fba4767f19c73f4b8fa..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_readmap.h +++ /dev/null @@ -1,531 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_readmap.h,v 1.10 2010/05/05 13:15:01 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_readmap.h - * @author yingxiang(yingxiang@baidu.com) - * @date 2008/07/31 13:39:16 - * @version $Revision: 1.10 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief A read-only hash table - * - **/ - - -#ifndef __BSL_READMAP_H_ -#define __BSL_READMAP_H_ - -#include "bsl/alloc/bsl_alloc.h" -#include "bsl/utils/bsl_utils.h" -#include "bsl/containers/hash/bsl_hashutils.h" -#include "bsl/archive/bsl_serialization.h" -#include "bsl/exception/bsl_exception.h" -#include -#include - -namespace bsl{ - -/** - * @brief 只读hash表 - */ -template , - class _EqualFunction = std::equal_to<_Key>, - class _Alloc = bsl_alloc<_Key> > -class readmap{ -private: - //data structure types - typedef _Key key_type; - typedef _Value value_type; - typedef typename std::pair<_Key, _Value> pair_type; - typedef size_t size_type; - typedef size_t sign_type;//Hash signature type, generated by HashFunction - typedef readmap<_Key, _Value, - _HashFunction, _EqualFunction, _Alloc > self_type; - - struct _node_type{ - size_type idx, pos, hash_value; - }; -public: - enum { DEFAULT_BUCKET_SIZE = 65535 }; - typedef pair_type* iterator; - typedef const pair_type* const_iterator; - typedef _node_type node_type; -private: - //Allocator types - typedef typename _Alloc::template rebind :: other itr_alloc_type; - typedef typename _Alloc::template rebind :: other pair_alloc_type; - typedef typename _Alloc::template rebind :: other node_alloc_type; -public: - //compare functions - static int _cmp_hash(node_type __a, node_type __b){ return __a.hash_value < __b.hash_value; } - static int _cmp_idx(node_type __a, node_type __b){ return __a.idx < __b.idx; } -private: - //data - iterator* _bucket; - iterator _storage; - size_type _hash_size; /**<哈希桶的大小 */ - size_type _size; /**<哈希中元素的个数 */ - size_type _mem_size; /**< 内存空间,=_hash_size+1 */ - //Object Function - _HashFunction _hashfun; - _EqualFunction _eqfun; - //Allocators - itr_alloc_type _itr_alloc; - pair_alloc_type _pair_alloc; - node_alloc_type _node_alloc; -public: - - /** - * @brief 构造函数 - * 无异常 - * 需调create - **/ - readmap(){ - _reset(); - } - - /** - * @brief 带桶大小的构造函数 - * 如果构造失败,将销毁对象 - * 抛异常 - * 不需调create - * @param [in] __bucket_size : const size_type - * @param [in] __hash_func : const _HashFunction& - * @param [in] __equal_func : const _EqualFunction& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/30 15:00:13 - **/ - readmap(const size_type __bucket_size, - const _HashFunction& __hash_func = _HashFunction(), - const _EqualFunction& __equal_func = _EqualFunction()) { - _reset(); - if (create(__bucket_size, __hash_func, __equal_func) != 0) { - destroy(); - throw BadAllocException()< -1:出错 - *
  • 0:成功 - * @retval - * @see - * @note 如果hash桶已经创建,第二次调用create时会先destroy之前的hash表 - * @author yingxiang - * @date 2008/08/14 11:24:28 - **/ - int create(const size_type __bucket_size = size_type(DEFAULT_BUCKET_SIZE), - const _HashFunction& __hash_func = _HashFunction(), - const _EqualFunction& __equal_func = _EqualFunction()){ - if(_hash_size){ - destroy();//防止重复create - } - - _itr_alloc.create(); - _pair_alloc.create(); - _node_alloc.create(); - - _hashfun = __hash_func; - _eqfun = __equal_func; - _hash_size = __bucket_size; - - if(_hash_size <= 0) return -1; - _mem_size = _hash_size + 1;//可以优化查询速度 - _bucket = _itr_alloc.allocate(_mem_size); - if(0 == _bucket) return -1; - if (0 < _mem_size) { - _bucket[0] = NULL; - } - return 0; - } - - /* * - * @brief 判断readmap是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return (_bucket != 0); - } - - template - /** - * @brief 向hash表中赋初始元素。将[start, finish)区间的元素插入hash表
    - * [start, finish)为左闭右开区间
    - * 如果assign之前未显式调用create,assign会自动调用create
    - * - * @param [in] __start : _PairIterator 起始位置 - * @param [in] __finish : _PairIterator 终止位置 - * @return int - *
  • 0 : 成功 - *
  • -1 : 其他错误 - * @retval - * @see - * @note 插入的key值不可以有相同 - * @author yingxiang - * @date 2008/08/14 11:32:20 - **/ - int assign(const _PairIterator __start, const _PairIterator __finish){ - if(_size){ - clear(); - } - _size = std::distance(__start, __finish); - - if (_size == 0) { - return 0; - } - //如果未显示调用create,则自动创建,桶大小为4倍 - if(0 == _hash_size) { - if(create(_size * 4)) return -1; - } - - iterator p = _pair_alloc.allocate(_size); - if(0 == p) { - _size = 0; - return -1; - } - _storage = p; - - node_type* temp = _node_alloc.allocate(_size); - if(0 == temp) { - _pair_alloc.deallocate(p, _size); - _size = 0; - return -1; - } - - _PairIterator itr = __start; - size_type i, j; - for(i = 0; itr != __finish; ++itr, ++i){ - temp[i].idx = i; - temp[i].hash_value = _hashfun(itr->first) % _hash_size; - } - - //为每个萝卜分配一个坑 - std::sort(temp, temp + _size, _cmp_hash); - for(i = 0; i < _size; ++i){ - temp[i].pos = i; - } - - //计算桶入口 - for(i = 0, j = 0; j < _mem_size; ++j){ - while(i < _size && temp[i].hash_value < j){ - ++i; - } - _bucket[j] = _storage + i; - } - - //拷贝内存到存储区 - std::sort(temp, temp + _size, _cmp_idx); - for(i = 0, itr = __start; i < _size; ++i, ++itr){ - bsl::bsl_construct(&_storage[temp[i].pos], *itr); - } - - _node_alloc.deallocate(temp, _size); - - return 0; - } - - /** - * @brief 根据Key值查询 - * - * @param [in] __key : const key_type& 要查询的Key值 - * @param [out] __value : value_type* 查询结果的Value值 - * @return int - *
  • HASH_EXIST : 存在 - *
  • HASH_NOEXIST : 不存在 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:50:34 - **/ - int get(const key_type& __key, value_type* __value=NULL) const { - if (NULL == _bucket || NULL == _bucket[0]) { - return HASH_NOEXIST; - } - sign_type hash_value = _hashfun(__key) % _hash_size; - for(iterator p = _bucket[hash_value]; p < _bucket[hash_value + 1]; ++p){ - if(_eqfun(__key, p->first)){ - if(__value)*__value = p->second; - return HASH_EXIST; - } - }; - return HASH_NOEXIST; - } - - /** - * @brief 返回hash表中的元素个数 - * - * @return size_type 元素个数 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:53:51 - **/ - size_type size() const { - return _size; - } - - /** - * @brief 返回hash表桶大小 - * - * @return size_type 桶大小 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:54:30 - **/ - size_type bucket_size() const { - return _hash_size; - } - - /** - * @brief 销毁hash表 - * - * @return void - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:54:52 - **/ - void destroy(){ - clear(); - if(_mem_size > 0 && NULL != _bucket){ - _itr_alloc.deallocate(_bucket, _mem_size); - _mem_size = _hash_size = 0; - _bucket = NULL; - } - _pair_alloc.destroy(); - _itr_alloc.destroy(); - _node_alloc.destroy(); - } - - /** - * @brief 清空hash表中的元素 - * - * @return void - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:55:07 - **/ - void clear(){ - if(_size > 0 && NULL != _storage){ - bsl::bsl_destruct(_storage, _storage + _size); - _pair_alloc.deallocate(_storage, _size); - _size = 0; - _storage = NULL; - } - } - - /** - * @brief 存储区的头指针。用于遍历hash表中的元素。
    - * 仅用于访问操作 - * - * @return iterator 头部指针 对于空容器返回NULL - * @retval - * @see - * @author yingxiang - * @date 2008/08/21 14:37:35 - **/ - iterator begin(){ - return _storage; - } - /** - * @brief 存储区的头指针 - */ - const_iterator begin() const { - return _storage; - } - - /** - * @brief 存储区的尾指针。 - * - * @return const_iterator 尾部指针(指向内存单元不可以被访问) - * 对于空容器返回为NULL - * @retval - * @see - * @author yingxiang - * @date 2008/08/21 14:38:45 - **/ - iterator end(){ - return _storage + size(); - } - /** - * @brief 存储区的尾指针 - */ - const_iterator end() const { - return _storage + size(); - } - - ~readmap(){ - destroy(); - } - - template - /** - * @brief 串行化。将hash表串行化到指定的流 - * - * @param [in/out] ar : _Archive& 串行化流 - * @return int - *
  • 0 : 成功 - *
  • -1 : 失败 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 16:08:11 - **/ - int serialization(_Archive & ar) { - if(bsl::serialization(ar, _hash_size)) goto _ERR_S; - if(bsl::serialization(ar, _size)) goto _ERR_S; - size_type i; - for(i = 0; i < _size; ++i){ - if(bsl::serialization(ar, _storage[i])){ - goto _ERR_S; - } - } - return 0; -_ERR_S: - return -1; - } - - template - /** - * @brief 反串行化。从串行化流中获取数据重建hash表 - * - * @param [in] ar : _Archive& 串行化流 - * @return int - *
  • 0 : 成功 - *
  • -1 : 失败 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 16:08:19 - **/ - int deserialization(_Archive & ar){ - size_type fsize, hashsize, i; - iterator tmp_storage = NULL; - - destroy(); - - if(bsl::deserialization(ar, hashsize) != 0) { - goto _ERR_DS; - } - if(bsl::deserialization(ar, fsize) != 0) { - goto _ERR_DS; - } - if(hashsize <= 0 || fsize <= 0){ - goto _ERR_DS; - } - - if(create(hashsize)){ - goto _ERR_DS; - } - - tmp_storage = _pair_alloc.allocate(fsize); - if(NULL == tmp_storage) { - goto _ERR_DS; - } - - for(i = 0; i < fsize; i++){ - bsl::bsl_construct(&tmp_storage[i]); - } - - for(i = 0; i < fsize; i++){ - if(bsl::deserialization(ar, tmp_storage[i]) != 0) { - goto _ERR_DS; - } - } - - if(assign(tmp_storage, tmp_storage + fsize) != 0) { - goto _ERR_DS; - } - - bsl::bsl_destruct(tmp_storage, tmp_storage + fsize); - _pair_alloc.deallocate(tmp_storage, fsize); - return 0; -_ERR_DS: - if(NULL != tmp_storage){ - bsl::bsl_destruct(tmp_storage, tmp_storage + fsize); - _pair_alloc.deallocate(tmp_storage, fsize); - } - destroy(); - return -1; - } -private: - void _reset(){ - _bucket = NULL; - _storage = NULL; - _hash_size = 0; - _mem_size = 0; - _size = 0; - } -};//class readmap - -}//namespace bsl - - - -#endif //__BSL_READMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/containers/hash/bsl_readset.h b/bsl/containers/hash/bsl_readset.h deleted file mode 100644 index 42bcc106a6db622b5d08a0eab53989d8c4bba784..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_readset.h +++ /dev/null @@ -1,540 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_readset.h,v 1.9 2009/04/07 06:35:53 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_readset.h - * @author yingxiang(yingxiang@baidu.com) - * @date 2008/08/14 13:39:16 - * @version $Revision: 1.9 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief A read-only hash table - * - **/ - - -#ifndef __BSL_READSET_H_ -#define __BSL_READSET_H_ - -#include "bsl/alloc/bsl_alloc.h" -#include "bsl/utils/bsl_utils.h" -#include "bsl/containers/hash/bsl_hashutils.h" -#include "bsl/archive/bsl_serialization.h" -#include "bsl/exception/bsl_exception.h" -#include -#include - -namespace bsl{ - -template , - class _EqualFunction = std::equal_to<_Key>, - class _Alloc = bsl_alloc<_Key> > -class readset{ -private: - //data structure types - typedef _Key key_type; - typedef size_t size_type; - typedef size_t sign_type;//Hash signature type, generated by HashFunction - typedef readset<_Key, _HashFunction, _EqualFunction, _Alloc> self_type; - - struct _node_type{ - size_type idx, pos, hash_value; - }; -public: - enum{ DEFAULT_BUCKET_SIZE = 65535 }; - typedef key_type* iterator; - typedef const key_type* const_iterator; - typedef _node_type node_type; -private: - //Allocator types - typedef typename _Alloc::template rebind :: other itr_alloc_type; - typedef typename _Alloc::template rebind :: other key_alloc_type; - typedef typename _Alloc::template rebind :: other node_alloc_type; -public: - //compare functions - static int _cmp_hash(node_type __a, node_type __b){ - return __a.hash_value < __b.hash_value; - } - static int _cmp_idx(node_type __a, node_type __b){ - return __a.idx < __b.idx; - } -private: - //data - iterator* _bucket; - iterator _storage; - size_type _hash_size; /**<哈希桶的大小 */ - size_type _size; /**<哈希中元素的个数 */ - size_type _mem_size; /**< 内存空间,=_hash_size+1 */ - //Object Function - _HashFunction _hashfun; - _EqualFunction _eqfun; - //Allocators - itr_alloc_type _itr_alloc; - key_alloc_type _key_alloc; - node_alloc_type _node_alloc; -public: - - /* * - * @brief 默认构造函数 - * 无异常 - * 需调create - * */ - readset(){ - _reset(); - } - - /** - * @brief 带桶大小的构造函数 - * 如果构造失败,将销毁对象 - * 抛异常 - * 不需调create - * @param [in] __bucket_size : const size_type - * @param [in] __hash_func : const _HashFunction& - * @param [in] __equal_func : const _EqualFunction& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/30 15:16:58 - **/ - readset(const size_type __bucket_size, - const _HashFunction& __hash_func = _HashFunction(), - const _EqualFunction& __equal_func = _EqualFunction()){ - _reset(); - if (create(__bucket_size,__hash_func,__equal_func) != 0) { - destroy(); - throw BadAllocException()< -1:出错 - *
  • 0:成功 - * @retval - * @see - * @note 如果hash桶已经创建,第二次调用create时会先destroy之前的hash表 - * @author yingxiang - * @date 2008/08/14 11:24:28 - **/ - int create(const size_type __bucket_size = size_type(DEFAULT_BUCKET_SIZE), - const _HashFunction& __hash_func = _HashFunction(), - const _EqualFunction& __equal_func = _EqualFunction()){ - if(_hash_size){ - destroy();//防止重复create - } - - _itr_alloc.create(); - _key_alloc.create(); - _node_alloc.create(); - - _hashfun = __hash_func; - _eqfun = __equal_func; - _hash_size = __bucket_size; - - if(_hash_size <= 0){ - return -1; - } - - _mem_size = _hash_size + 1;//可以优化查询速度 - _bucket = _itr_alloc.allocate(_mem_size); - if(0 == _bucket){ - return -1; - } - return 0; - } - - /* * - * @brief 判断readset是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return (_bucket != 0); - } - - /** - * @brief 向hash表中赋初始元素。将[start, finish)区间的元素插入hash表
    - * [start, finish)为左闭右开区间
    - * 如果assign之前未显式调用create,assign会自动调用create
    - * - * @param [in] __start : _Iterator 起始位置 - * @param [in] __finish : _Iterator 终止位置 - * @return int - *
  • 0 : 成功 - *
  • -1 : 其他错误 - * @retval - * @see - * @note 插入的key值不可以有相同 - * @author yingxiang - * @date 2008/08/14 11:32:20 - **/ - template - int assign(const _Iterator __start, const _Iterator __finish){ - if(_size) { - clear(); - } - - _size = std::distance(__start, __finish); - - if (_size == 0) { - return 0; - } - //如果未显示调用create,则自动创建,桶大小为4倍 - if(0 == _hash_size) { - if(create(_size * 4)){ - return -1; - } - } - - iterator p = _key_alloc.allocate(_size); - if(0 == p) { - _size = 0; - return -1; - } - _storage = p; - - node_type* temp = _node_alloc.allocate(_size); - if(0 == temp) { - _key_alloc.deallocate(p, _size); - _size = 0; - return -1; - } - - _Iterator itr = __start; - size_type i, j; - for(i = 0; itr != __finish; ++itr, ++i){ - temp[i].idx = i; - temp[i].hash_value = _hashfun(*itr) % _hash_size; - } - - //为每个萝卜分配一个坑 - std::sort(temp, temp + _size, _cmp_hash); - for(i = 0; i < _size; ++i){ - temp[i].pos = i; - } - - //计算桶入口 - for(i = 0, j = 0; j < _mem_size; ++j){ - while(i < _size && temp[i].hash_value < j){ - ++i; - } - _bucket[j] = _storage + i; - } - - //拷贝内存到存储区 - std::sort(temp, temp + _size, _cmp_idx); - for(i = 0, itr = __start; i < _size; ++i, ++itr){ - bsl::bsl_construct(&_storage[temp[i].pos], *itr); - } - - _node_alloc.deallocate(temp, _size); - - return 0; - } - - /** - * @brief 根据Key值查询 - * - * @param [in] __key : const key_type& 要查询的Key值 - * @return int - *
  • HASH_EXIST : 存在 - *
  • HASH_NOEXIST : 不存在 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:50:34 - **/ - int get(const key_type& __key) const{ - if(0 == _size){ - return HASH_NOEXIST; - } - sign_type hash_value = _hashfun(__key) % _hash_size; - for(iterator p = _bucket[hash_value]; p < _bucket[hash_value + 1]; ++p){ - if(_eqfun(__key, *p)){ - return HASH_EXIST; - } - } - return HASH_NOEXIST; - } - - /** - * @brief 返回hash表中的元素个数 - * - * @return size_type 元素个数 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:53:51 - **/ - size_type size() const { - return _size; - } - - /** - * @brief 返回hash表桶大小 - * - * @return size_type 桶大小 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:54:30 - **/ - size_type bucket_size() const { - return _hash_size; - } - - /** - * @brief 销毁hash表 - * - * @return void - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:54:52 - **/ - void destroy(){ - clear(); - if(_mem_size > 0 && NULL != _bucket){ - _itr_alloc.deallocate(_bucket, _mem_size); - _mem_size = _hash_size = 0; - _bucket = NULL; - } - _key_alloc.destroy(); - _itr_alloc.destroy(); - _node_alloc.destroy(); - } - - /** - * @brief 清空hash表中的元素 - * - * @return void - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 15:55:07 - **/ - void clear(){ - if(_size > 0 && NULL != _storage){ - bsl::bsl_destruct(_storage, _storage + _size); - _key_alloc.deallocate(_storage, _size); - _size = 0; - _storage = NULL; - } - } - - /** - * @brief 存储区的头部指针。用于遍历hash表中的元素。仅用于访问操作 - * - * @return const iterator 头部指针。空容器返回NULL - * @retval - * @see - * @author yingxiang - * @date 2008/08/21 15:01:53 - **/ - iterator begin(){ - return _storage; - } - - /** - * @brief 存储区的头部指针 - */ - const_iterator begin() const { - return _storage; - } - - /** - * @brief 存储区的尾部指针 - * - * @return const iterator 尾部指针(指向的内存单元不可以被访问 - * @retval - * @see - * @author yingxiang - * @date 2008/08/21 15:02:31 - **/ - iterator end(){ - return _storage + size(); - } - - /** - * @brief 存储区的尾部指针 - */ - const_iterator end() const { - return _storage + size(); - } - - ~readset(){ - destroy(); - } - - /** - * @brief 串行化。将hash表串行化到指定的流 - * - * @param [in/out] ar : _Archive& 串行化流 - * @return int - *
  • 0 : 成功 - *
  • -1 : 失败 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 16:08:11 - **/ - template - int serialization(_Archive & ar) { - if(bsl::serialization(ar, _hash_size) != 0){ - goto _ERR_S; - } - if(bsl::serialization(ar, _size) != 0) { - goto _ERR_S; - } - size_type i; - for(i = 0; i < _size; ++i){ - if(bsl::serialization(ar, _storage[i]) != 0){ - goto _ERR_S; - } - } - return 0; -_ERR_S: - return -1; - } - - /** - * @brief 反串行化。从串行化流中获取数据重建hash表 - * - * @param [in] ar : _Archive& 串行化流 - * @return int - *
  • 0 : 成功 - *
  • -1 : 失败 - * @retval - * @see - * @author yingxiang - * @date 2008/08/14 16:08:19 - **/ - template - int deserialization(_Archive & ar){ - size_type fsize, hashsize, i; - iterator tmp_storage = NULL; - - destroy(); - - if(bsl::deserialization(ar, hashsize) != 0){ - goto _ERR_DS; - } - if(bsl::deserialization(ar, fsize) != 0){ - goto _ERR_DS; - } - if(hashsize <= 0 || fsize <= 0) { - goto _ERR_DS; - } - - if(create(hashsize) != 0){ - goto _ERR_DS; - } - - tmp_storage = _key_alloc.allocate(fsize); - if(NULL == tmp_storage){ - goto _ERR_DS; - } - - for(i = 0; i < fsize; ++i){ - bsl::bsl_construct(&tmp_storage[i]); - } - - for(i = 0; i < fsize; ++i){ - if(bsl::deserialization(ar, tmp_storage[i]) != 0){ - goto _ERR_DS; - } - } - - if(assign(tmp_storage, tmp_storage + fsize) != 0){ - goto _ERR_DS; - } - - bsl::bsl_destruct(tmp_storage, tmp_storage + fsize); - _key_alloc.deallocate(tmp_storage, fsize); - return 0; -_ERR_DS: - if(NULL != tmp_storage){ - bsl::bsl_destruct(tmp_storage, tmp_storage + fsize); - _key_alloc.deallocate(tmp_storage, fsize); - } - destroy(); - return -1; - } -private: - void _reset(){ - _bucket = NULL; - _storage = NULL; - _hash_size = 0; - _mem_size = 0; - _size = 0; - } - -};//class readset - -}//namespace bsl - - - - - - -#endif //__BSL_READSET_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/containers/hash/bsl_rwhashset.h b/bsl/containers/hash/bsl_rwhashset.h deleted file mode 100644 index 53a7d17c05bef5c623084d6889db35fa22627166..0000000000000000000000000000000000000000 --- a/bsl/containers/hash/bsl_rwhashset.h +++ /dev/null @@ -1,323 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_rwhashset.h,v 1.11 2009/08/24 06:24:49 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_rwhashset.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/28 22:16:54 - * @version $Revision: 1.11 $ 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * @brief - * - **/ - - -#ifndef __BSL_RWHASHSET_H_ -#define __BSL_RWHASHSET_H_ - -#include -#include - -namespace bsl -{ - -template , - /** - * 判断两个key相等的仿函数 - * 比如 struct equal { - * inline bool operator () (const _Tp &_1, const _Tp &_2); - * }; - */ - class _Equl = std::equal_to<_Key>, - /** - * 空间分配器,默认的空间分配器能够高效率的管理小内存,防止内存碎片 - * 但是在容器生命骑内不会释放申请的内存 - * - * bsl_alloc<_Key>做内存分配器,可以在容器生命期内释放内存, - * 但是不能有效防止内存碎片 - */ - class _InnerAlloc = bsl_sample_alloc, 256> - > -class bsl_rwhashset -{ -public: - typedef _Key key_type; - - typedef bsl_rwhashset<_Key, _HashFun, _Equl, _InnerAlloc> _Self; - typedef bsl_hashtable<_Key, _Key, _HashFun, _Equl, param_select<_Key>, _InnerAlloc> hash_type; - typedef typename _InnerAlloc::pool_type::template rebind::other lockalloc_type; - typedef typename hash_type::node_pointer node_pointer; - - BSL_RWLOCK_T *_locks; - pthread_mutex_t _lock; - size_t _lsize; - lockalloc_type _alloc; - hash_type _ht; - -private: - /** 拷贝构造函数 */ - bsl_rwhashset (const _Self &); //禁用 - /** 赋值运算符 */ - _Self & operator = (const _Self &); //禁用 - -public: - - /* * - * @brief 默认构造函数 - * 无异常 - * 需调create - * */ - bsl_rwhashset() { - _locks = 0; - _lsize = 0; - } - - /** - * @brief 带桶大小的线程安全容器 - * 如果构造失败,将销毁对象 - *排滓斐 - * 不需调create - **/ - bsl_rwhashset(size_t bitems, size_t lsize = 0, - const _HashFun &hf = _HashFun(), - const _Equl &eq = _Equl()) { - _locks = 0; - _lsize = 0; - if (create(bitems,lsize,hf,eq) != 0) { - destroy(); - throw BadAllocException()<= size_t(-1) / sizeof(void *)) { - __BSL_ERROR("too large bitems, overflower"); - return -1; - } - destroy(); - - if (lsize > bitems) { - _lsize = bitems; - } else { - _lsize = lsize; - } - if (_lsize <= 0) { - _lsize = (1 + (size_t)((float)(0.05)*(float)bitems)); - if (_lsize > 100) { - _lsize = 100; - } - } - - _alloc.create(); - - _locks = _alloc.allocate(_lsize); - if (_locks == 0) return -1; - for(size_t i=0; i<_lsize; ++i) { - BSL_RWLOCK_INIT(_locks+i); - } - - pthread_mutex_init(&_lock, NULL); - return _ht.create(bitems, hf, eq); - } - - /* * - * @brief 判断rwhashset是否已create - * @author zhujianwei - * @date 2010/12/13 - * */ - bool is_created() const{ - return _ht.is_created(); - } - - /** - * @brief 销毁hash表 - * - * @return int 返回0表示删除成功,其他表示删除失败 - * @retval 线程不安全 - * @see - * @author xiaowei - * @date 2008/08/12 21:16:39 - **/ - int destroy() { - if (_locks) { - _alloc.deallocate(_locks, _lsize); - pthread_mutex_destroy(&_lock); - } - _alloc.destroy(); - _locks = NULL; - _lsize = 0; - return _ht.destroy(); - } - - /** - * @brief 查询key_type是否存在 - * - * @param [in/out] k : const key_type& 指定的查找key - * @return int - * 返回 HASH_EXIST 表示hash值存在 - * 返回 HASH_NOEXIST 表示hash值不存在 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:17:52 - **/ - int get(const key_type &k) const { - size_t key = _ht._hashfun(k); - BSL_RWLOCK_T &__lock = get_rwlock(key); - BSL_RWLOCK_RDLOCK(&__lock); - int ret = HASH_EXIST; - if (_ht.find(key, k) == NULL) { - ret = HASH_NOEXIST; - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - int get(const key_type &k) { - size_t key = _ht._hashfun(k); - BSL_RWLOCK_T &__lock = get_rwlock(key); - BSL_RWLOCK_RDLOCK(&__lock); - int ret = HASH_EXIST; - if (_ht.find(key, k) == NULL) { - ret = HASH_NOEXIST; - } - BSL_RWLOCK_UNLOCK(&__lock); - return ret; - } - - /** - * @brief 将key插入hash表 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 -1表示set调用出错 - * 返回 HASH_EXIST 表示hash结点存在 - * 返回 HASH_INSERT_SEC 表示插入成功 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:33:10 - **/ - int set(const key_type &k) { - size_t key = _ht._hashfun(k); - pthread_mutex_lock(&_lock); - - BSL_RWLOCK_T &__lock = get_rwlock(key); - BSL_RWLOCK_WRLOCK(&__lock); - int ret = _ht.set(key, k, k); - BSL_RWLOCK_UNLOCK(&__lock); - - pthread_mutex_unlock(&_lock); - return ret; - } - - /** - * @brief 根据指定的key删除结点 - * - * @param [in/out] k : const key_type& - * @return int - * 返回 HASH_EXIST表示结点存在并删除成功 - * 返回 HASH_NOEXIST表示结点不存在不用删除 - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 21:24:58 - **/ - int erase(const key_type &k) { - size_t key = _ht._hashfun(k); - pthread_mutex_lock(&_lock); - - BSL_RWLOCK_T &__lock = get_rwlock(key); - BSL_RWLOCK_WRLOCK(&__lock); - int ret = _ht.erase(key, k); - BSL_RWLOCK_UNLOCK(&__lock); - - pthread_mutex_unlock(&_lock); - return ret; - } - - - /** - * @brief 将数据清空,线程安全 - * - * @return int - * @retval - * @see - * @author xiaowei - * @date 2008/08/12 22:17:48 - **/ - int clear() { - //读写锁每被初始化,没有被create - if (_locks == NULL) { - return 0; - } - pthread_mutex_lock(&_lock); - for (size_t i=0; i<_ht._bitems; ++i) { - BSL_RWLOCK_T &__lock = get_rwlock(i); - BSL_RWLOCK_WRLOCK(&__lock); - //typename hash_type::node_t *nd = NULL; - node_pointer nd = 0; - while (_ht._bucket[i]) { - nd = _ht._bucket[i]; - _ht._bucket[i] = _ht._sp_alloc.getp(_ht._bucket[i])->next; - bsl::bsl_destruct(&_ht._sp_alloc.getp(nd)->val); - _ht._sp_alloc.deallocate(nd, 1); - } - BSL_RWLOCK_UNLOCK(&__lock); - } - _ht.clear();//什么都发生,只清空一下标志位 - pthread_mutex_unlock(&_lock); - return 0; - } - - size_t size() const { - return _ht.size(); - } - - template - int assign(_Iterator __begin, _Iterator __end) { - return _ht.assign(__begin, __end); - } - -}; - -}; - -#endif //__BSL_RWHASHSET_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/containers/list/CMakeLists.txt b/bsl/containers/list/CMakeLists.txt deleted file mode 100644 index 3d0c2997243c7ff472ee9d6344f103b76098bf26..0000000000000000000000000000000000000000 --- a/bsl/containers/list/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/containers/list/ChangeLog b/bsl/containers/list/ChangeLog deleted file mode 100644 index b9031921449535275f90fabb9a018cf5e6c5fa3f..0000000000000000000000000000000000000000 --- a/bsl/containers/list/ChangeLog +++ /dev/null @@ -1,2 +0,0 @@ -1.0.0.0 bsl_slist 2008.8.4 - Initial release diff --git a/bsl/containers/list/Makefile b/bsl/containers/list/Makefile deleted file mode 100644 index a558549306e41cd0cfe583b3fa58967e3a9ead04..0000000000000000000000000000000000000000 --- a/bsl/containers/list/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -BSL=../../ -OUTINC=$(BSL)/output/include/bsl/containers/list -all : - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp *.h $(OUTINC) - -clean : - rm -rf $(OUTINC) - diff --git a/bsl/containers/list/README b/bsl/containers/list/README deleted file mode 100644 index 35e4863095b335a736ae266256d85e184a4a7f89..0000000000000000000000000000000000000000 --- a/bsl/containers/list/README +++ /dev/null @@ -1,18 +0,0 @@ -bsl::dlist的说明 -~~~~~~~~~~~~~~~~ - bsl::dlist是bsl下的双向链表模板,那使用了bsl::alloc的高效内存管理,相比std::list有5倍的性能提升 - - -目录结构 -~~~~~~~~ - bsl_dlist.h 模板头文件 - perfbench dlist性能测试,基于yperfbench - unittest dlist的单元测试 - -使用方法 -~~~~~~~~ - 包含bls_dlist.h头文件,创建bsl::dlist的实例 - -反馈意见 -~~~~~~~~ - 联系yufan@baidu.com 或 com@baidu.com diff --git a/bsl/containers/list/bsl_list.h b/bsl/containers/list/bsl_list.h deleted file mode 100644 index 8eeb5aeb1927251eeb4c4052f585085ecd7d1ee4..0000000000000000000000000000000000000000 --- a/bsl/containers/list/bsl_list.h +++ /dev/null @@ -1,1800 +0,0 @@ -/* * - * @brief 双向链表 - * @author yufan - * @version 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * - * */ - -#ifndef _BSL_LIST_H__ -#define _BSL_LIST_H__ - -#include -#include -#include -#include -#include - -namespace bsl -{ - -template -struct list_node_t -{ - typedef _Tp value_type; - typedef list_node_t<_Tp, _Alloc> node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - node_pointer next; - node_pointer prev; - value_type val; -}; - -template class list; - -/** - * @brief list只读迭代器 - */ -template -class list_const_iterator -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef ptrdiff_t difference_type; -private: - typedef list_const_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef list<_Tp, _Alloc> list_t; - typedef typename list_t::iterator iterator; - typedef list_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - typedef typename node_alloc_t::const_pointer node_const_pointer; -public: - /** - * @brief - * 建立一个未初始化的迭代器 - * @see - * @author yufan - * @date 2008/08/07 11:22:25 - **/ - list_const_iterator() - { - _node = 0; - } - /** - * @brief - * 从另一个迭代器复制,指向统一份内容 - * @param [in] __x : const self& 要拷贝的迭代器 - * @see - * @author yufan - * @date 2008/08/07 11:22:36 - **/ - list_const_iterator(const self & __x) - { - _node = __x._node; - } - list_const_iterator(const iterator & __x) - { - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator ++ () - { - _node = _node->next; - return *this; - } - self operator ++ (int) - { - self iter = *this; - ++ *this; - return iter; - } - self & operator --() - { - _node = _node->prev; - return *this; - } - self operator --(int) - { - self iter = *this; - -- *this; - return iter; - } - /** - * @brief - * 从一个指向节点的内存指针建立迭代器,内部使用 - * @param [in] __x : node_pointer - * @see - * @author yufan - * @date - **/ - list_const_iterator(node_pointer __x) - { - _node = __x; - } - - list_const_iterator(node_const_pointer __x) - { - _node = const_cast(__x); - } -private: - node_pointer _node; -}; - -/** - * @brief list迭代器 - */ -template -class list_iterator -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef ptrdiff_t difference_type; - typedef const _Tp * const_pointer; //常空间地址指针 - typedef const _Tp & const_reference; //常空间地址指针 -private: - typedef list_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef list<_Tp, _Alloc> list_t; - typedef list_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - typedef typename node_alloc_t::const_pointer node_const_pointer; - friend class list<_Tp, _Alloc>; -public: - /** - * @brief - * 建立一个未初始化的迭代器 - * @see - * @author yufan - * @date 2008/08/07 11:22:25 - **/ - list_iterator() - { - _list = 0; - _node = 0; - } - /** - * @brief - * 从另一个迭代器复制,指向统一份内容 - * @param [in] __x : const self& 要拷贝的迭代器 - * @see - * @author yufan - * @date 2008/08/07 11:22:36 - **/ - list_iterator(const self & __x) - { - _list = __x._list; - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator ++ () - { - _node = _node->next; - return *this; - } - self operator ++ (int) - { - self iter = *this; - ++ *this; - return iter; - } - self & operator --() - { - _node = _node->prev; - return *this; - } - self operator --(int) - { - self iter = *this; - -- *this; - return iter; - } - /** - * @brief - * 从一个指向节点的内存指针建立迭代器,内部使用 - * @param [in] __x : node_pointer - * @see - * @author yufan - * @date - **/ - list_iterator(list_t* __l, node_pointer __x) - { - _list = __l; - _node = __x; - } - - list_iterator(list_t* __l, node_const_pointer __x) - { - _list = const_cast(__l); - _node = const_cast(__x); - } -public: - node_pointer _node; -private: - list_t* _list; -}; - -/** - * @brief list反向只读迭代器 - */ -template -class list_const_reverse_iterator -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef ptrdiff_t difference_type; -private: - typedef list_const_reverse_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef list<_Tp, _Alloc> list_t; - typedef typename list_t::reverse_iterator reverse_iterator; - typedef list_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - typedef typename node_alloc_t::const_pointer node_const_pointer; - friend class list<_Tp, _Alloc>; -public: - list_const_reverse_iterator() - { - _node = 0; - } - list_const_reverse_iterator(const reverse_iterator & __x) - { - _node = __x._node; - } - list_const_reverse_iterator(const self& __x) - { - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator -- () - { - _node = _node->next; - return *this; - } - self operator -- (int) - { - self iter = *this; - -- *this; - return iter; - } - self & operator ++() - { - _node = _node->prev; - return *this; - } - self operator ++(int) - { - self iter = *this; - ++ *this; - return iter; - } - /** - * @brief - * - * @param [in/out] __x : node_pointer - * @see - * @author yufan - * @date 2008/08/07 11:21:37 - **/ - list_const_reverse_iterator(node_pointer __x) - { - _node = __x; - } - list_const_reverse_iterator(node_const_pointer __x) - { - _node = const_cast(__x); - } -private: - node_pointer _node; -}; -/** - * @brief list反向迭代器 - */ -template -class list_reverse_iterator -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef ptrdiff_t difference_type; - typedef list_const_reverse_iterator<_Tp, const _Tp *, - const _Tp &, _Alloc> const_reverse_iterator; -private: - typedef list_reverse_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef list<_Tp, _Alloc> list_t; - typedef list_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - typedef typename node_alloc_t::const_pointer node_const_pointer; - friend class list<_Tp, _Alloc>; -public: - list_reverse_iterator() - { - _list = 0; - _node = 0; - } - list_reverse_iterator(const self& __x) - { - _list = __x._list; - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator -- () - { - _node = _node->next; - return *this; - } - self operator -- (int) - { - self iter = *this; - -- *this; - return iter; - } - self & operator ++() - { - _node = _node->prev; - return *this; - } - self operator ++(int) - { - self iter = *this; - ++ *this; - return iter; - } - /** - * @brief - * - * @param [in/out] __x : node_pointer - * @see - * @author yufan - * @date 2008/08/07 11:21:37 - **/ - list_reverse_iterator(list_t* __l, node_pointer __x) - { - _list = __l; - _node = __x; - } - list_reverse_iterator(list_t* __l, node_const_pointer __x) - { - _list = const_cast(__l); - _node = const_cast(__x); - } -public: - node_pointer _node; -private: - list_t* _list; -}; - -/** - * @brief list双向链表 - */ -template , 256> > -class list -{ -public: - typedef _Tp value_type; //数据类型定义 - typedef _Tp * pointer; //空间地址指针 - typedef const _Tp * const_pointer; //常空间地址指针 - typedef _Tp & reference; - typedef const _Tp & const_reference; - typedef size_t size_type; - typedef long difference_type; - typedef list_iterator iterator; - typedef list_const_iterator const_iterator; - typedef list_reverse_iterator reverse_iterator; - typedef list_const_reverse_iterator const_reverse_iterator; -protected: - typedef list_node_t<_Tp, _Alloc> node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - typedef typename node_alloc_t::const_pointer node_const_pointer; - //typedef typename node_alloc_t::reference node_reference; - //typedef typename node_alloc_t::const_reference node_const_reference; - //friend class list_iterator; - //friend class list_iterator; - //friend class list_reverse_iterator; - //friend class list_reverse_iterator; - -private: - struct list_node_place_holder_t - { - node_pointer next; - node_pointer prev; - //由于链表的根节点在程序中被多次调用, - //为了避免在程序中显式将node_holder_t*转换为node_t*, 定义以下的自动类型转换 - operator node_pointer () - { - return reinterpret_cast(this); - } - operator node_const_pointer () const - { - return reinterpret_cast(this); - } - }; - typedef list_node_place_holder_t node_holder_t; - typedef list<_Tp,_Alloc> self; - node_holder_t _root; - node_alloc_t _node_allocator; - size_type _size; - -public: - - /* * - * @brief list默认构造函数 - * 无异常 - * 不需调create - * */ - list(){ - _reset(); - create(); - } - - /** - * @brief - * 拷贝构造函数 - * 如果拷贝失败,抛出出异常,恢复成原来的空list - * - * @see - * @author yufan - * @date 2008/09/04 14:59:47 - **/ - list(const self& other) - { - _reset(); - create(); - if (assign(other.begin(),other.end()) != 0) { - throw BadAllocException()< size1) { // this中需要添加结点 - // other反向遍历,this从前插入结点 - const_reverse_iterator rfirst2 = other.rbegin(); - for (size_t i = size1; i < size2; i ++) { - if (push_front( *rfirst2 ) != 0) { - for (size_t j = size1; j < i; j ++) { - pop_front(); - } - throw BadAllocException()<next = _root.next; - _root.next->prev = _root.prev; - - _root.next = rfirst1._node->next; - _root.prev = rfirst1._node; - - rfirst1._node->next->prev = _root; - rfirst1._node->next = _root; - } - } else { // size1 >= size2 - // 从末尾删除结点 - for (size_t i = size1; i > size2; -- i) { - if ( pop_back() != 0 ) { - throw BadAllocException()<clear(); - _node_allocator.destroy(); - return 0; - - } - /** - * @brief - * 析构函数 - * @see - * @author yufan - * @date 2008/08/11 16:22:36 - **/ - ~list() - { - destroy(); - } - /** - * @brief - * 从__x中复制节点,如果__x是其本身,则跳过 - * @param [in] __x : self& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:22:47 - **/ - int assign (const self & __x) - { - if (this == &__x) - { - return 0; - } - else - { - return assign(__x.begin(), __x.end()); - } - } - - /** - * @brief - * 从迭代其中复制链表,迭代器可以是指向其自身的 - * @param [in] __begin : InputIterator 开始节点 - * @param [in] __end : InputIterator 指向结束节点(不包括该节点) - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:22:25 - **/ - template - int assign(InputIterator __begin, InputIterator __end) - { - node_holder_t tmp_root; - tmp_root.prev = tmp_root; - node_pointer cur = tmp_root; - InputIterator tp = __begin; - size_type n = 0; - while(tp != __end) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err1; - } - bsl::bsl_construct(&tmp->val, *tp); - tmp->prev = cur; - cur->next = tmp; - cur = tmp; - ++tp; - ++n; - } - cur->next = tmp_root; - tmp_root.prev = cur; - clear(); - _root.next = tmp_root.next; - tmp_root.next->prev = _root; - _root.prev = tmp_root.prev; - tmp_root.prev->next = _root; - _size = n; - return 0; - err1: - while(cur->prev != tmp_root) - { - node_pointer tmp = cur->prev; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - cur = tmp; - - } - return -1; - } - - /** - * @brief - * 清除全部节点 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:23:02 - **/ - int clear() - { - node_pointer cur = _root.next; - while(cur != _root) - { - node_pointer tmp = cur->next; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - cur = tmp; - --_size; - } - _root.next = _root.prev = _root; - _size = 0; - return 0; - } - - /** - * @brief - * 返回容器是否包含内容 - * @return bool - * @retval 容器为空返回true,否则返回false - * @see - * @author yufan - * @date 2008/08/11 16:22:55 - **/ - bool empty() const - { - return _root.prev == _root; - } - - /** - * @brief - * 从头部增加新节点 - * @param [in] __x : const value_type& 被加入的元素 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:23:14 - **/ - inline int push_front(const value_type &__x) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - tmp->next = _root.next; - tmp->prev = _root; - _root.next->prev = tmp; - _root.next = tmp; - ++_size; - return 0; - err: - return -1; - } - - /** - * @brief - * 删除头节点 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:22:14 - **/ - int pop_front() - { - return erase(begin()); - /* - if(_root.next == _root) - { - return -1; - } - else - { - node_pointer tmp = _root.next; - _root.next = tmp->next; - tmp->next->prev = _root; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - return 0; - }*/ - } - - /** - * @brief - * 从尾部增加节点 - * @param [in] __x : const value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:22:07 - **/ - int push_back(const value_type &__x) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - tmp->prev = _root.prev; - tmp->next = _root; - _root.prev->next = tmp; - _root.prev = tmp; - ++_size; - return 0; - err: - return -1; - } - - /** - * @brief - * 删除尾节点 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:57 - **/ - int pop_back() - { - if(_root.prev == _root) - { - return -1; - } - else - { - node_pointer tmp = _root.prev; - _root.prev = tmp->prev; - tmp->prev->next = _root; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - --_size; - return 0; - } - } - - /** - * @brief - * 在__i指向的元素前,增加由__s和__e指定的节点 - * @param [in] __i : iterator - * @param [in] __s : InputIterator - * @param [in] __e : InputIterator - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:22:03 - **/ - template - inline int insert( iterator __i, _InputIterator __s, _InputIterator __e) - { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - return(_aux_insert(__i, __s, __e, _Integral())); - } - template - inline int _aux_insert(iterator __i, InputIterator __s, InputIterator __e, - __true_type) - { - return _insert(__i, __s, __e); - } - template - int _aux_insert(iterator __i, InputIterator __s, InputIterator __e, - __false_type) - { - if ( __s == __e ) { - return 0; - } - - InputIterator tp = __s; - node_holder_t tmp_root; - tmp_root.prev = tmp_root; - node_pointer cur = tmp_root; - size_type n = 0; - while(tp!=__e) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, *tp); - tmp->prev = cur; - cur->next = tmp; - cur = tmp; - ++tp; - ++n; - } - __i._node->prev->next = tmp_root.next; - tmp_root.next->prev = __i._node->prev; - cur->next = __i._node; - __i._node->prev = cur; - __i._list->_size += n; - return 0; - err: - while(cur->prev != tmp_root) - { - node_pointer tmp = cur->prev; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - cur = tmp; - } - return -1; - } - /** - * @brief - * 在由__i指向的接点之前,增加__n个值为__x的元素 - * @param [in] __i : iterator 指向插入位置 - * @param [in] __n : size_type 插入元素的数量 - * @param [in] __x : const value_type& 待插入的元素 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:39 - **/ - - inline int insert( iterator __i, size_type __n, const value_type &__x) - { - return _insert(__i, __n, __x); - } - int _insert( iterator __i, size_type __n, const value_type &__x) - { - if ( __n == 0 ) { - return 0; - } - - node_holder_t tmp_root; - tmp_root.prev = tmp_root; - node_pointer cur = tmp_root; - size_type tcount = __n; - while(tcount) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - tmp->prev = cur; - cur->next = tmp; - cur = tmp; - tcount--; - } - __i._node->prev->next = tmp_root.next; - tmp_root.next->prev = __i._node->prev; - cur->next = __i._node; - __i._node->prev = cur; - __i._list->_size += __n; - return 0; - err: - while(cur->prev != tmp_root) - { - node_pointer tmp = cur->prev; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - cur = tmp; - - } - return -1; - } - - /** - * @brief - * 在节点__i之前,增加__x节点 - * @param [in] __i : iterator - * @param [in] __x : const value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:48 - **/ - int insert( iterator __i, const value_type &__x) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - tmp->next = __i._node; - tmp->prev = __i._node->prev; - __i._node->prev->next = tmp; - __i._node->prev = tmp; - __i._list->_size += 1; - return 0; - err: - return -1; - } - - /** - * @brief - * 和__x容器交换内容 - * @param [in/out] __x : self& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:42 - **/ - int swap( self & __x) - { - _node_allocator.swap(__x._node_allocator); - std::swap(_root, __x._root); - if(_root.next != __x._root) - { - _root.next->prev = _root; - _root.prev->next = _root; - } - else - { - _root.next = _root; - _root.prev = _root; - } - if ( __x._root.next != _root) - { - __x._root.next->prev = __x._root; - __x._root.prev->next = __x._root; - } - else - { - __x._root.next = __x._root; - __x._root.prev = __x._root; - } - std::swap(_size, __x._size); - //check(); - //__x.check(); - return 0; - } - - - /** - * @brief - * 删除__s和__e之间的节点 - * @param [in] __s : iterator - * @param [in] __e : iterator - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:35 - **/ - int erase ( iterator __s, iterator __e) - { - node_pointer prev = __s._node->prev; - node_pointer cur = __s._node; - node_pointer t_end = __e._node; - size_type n = 0; - while(cur != t_end) - { - node_pointer tmp = cur->next; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - cur = tmp; - ++n; - } - prev->next = t_end; - t_end->prev = prev; - __s._list->_size -= n; - return 0; - } - - /** - * @brief - * 删除 __x指向的节点 - * @param [in] __x : iterator - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 20:22:22 - **/ - int erase ( iterator __x) - { - if(_root.next == _root || __x._node == (node_pointer)&_root) { - return -1; - } - node_pointer cur = __x._node; - cur->next->prev = cur->prev; - cur->prev->next = cur->next; - bsl::bsl_destruct(&(cur->val)); - _node_allocator.deallocate(cur, 1); - __x._list->_size -= 1; - return 0; - } - - /** - * @brief - * 返回头的常引用 - * @return const_reference - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:21:04 - **/ - inline const_reference front() const - { - if(_root.next == _root) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回头元素的引用 - * @return reference - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:21:11 - **/ - inline reference front() - { - if(_root.next == _root) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回尾节点的常引用 - * @return const_reference - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:21:16 - **/ - inline const_reference back() const - { - if(_root.next == _root) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回尾节点的引用 - * @return reference - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:21:21 - **/ - inline reference back() - { - if(_root.next == _root) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回指向头节点的常迭代器 - * @return const_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:21:27 - **/ - inline const_iterator begin() const - { - return const_iterator(_root.next); - } - - /** - * @brief - * 返回指向头节点的迭代器 - * @return iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:55 - **/ - inline iterator begin() - { - return iterator(this, _root.next); - } - - /** - * @brief - * 返回指向尾节点的常迭代器 - * @return const_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:52 - **/ - inline const_iterator end() const - { - return const_iterator(_root); - } - - /** - * @brief - * 返回指向尾节点的迭代器 - * @return iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:50 - **/ - inline iterator end() - { - return iterator(this, _root); - } - - /** - * @brief - * 返回指向首部的反向常迭代器 - * @return const_reverse_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:47 - **/ - inline const_reverse_iterator rbegin() const - { - return const_reverse_iterator(_root.prev); - } - - /** - * @brief - * 返回指向首节点的反向常迭代器 - * @return reverse_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:40 - **/ - inline reverse_iterator rbegin() - { - return reverse_iterator(this, _root.prev); - } - - /** - * @brief - * 返回指向尾节点的反向常迭代器 - * @return const_reverse_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:38 - **/ - inline const_reverse_iterator rend() const - { - return const_reverse_iterator(_root); - } - /** - * @brief - * 返回指向尾节点的反向迭代器 - * @return reverse_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:33 - **/ - inline reverse_iterator rend() - { - return reverse_iterator(this, _root); - } - - /** - * @brief - * 返回容器包含的节点数量 - * @return size_type - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:30 - **/ - size_type size() const - { - return _size; - } - - /** - * @brief - * 返回容器所能容纳的最大节点数量 - * @return size_type - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:27 - **/ - inline size_type max_size() const - { - return (size_type)(-1); - } - - /* - * @brief - * 通过增加或删除尾部节点,使容器的节点数量等于__n - * @param [in] __n : size_type 所需要的容器大小 - * @param [in] __x : value_type 如果需要扩大容器,用于插入的元素 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:20:24 - **/ - int resize(size_type __n, value_type __x = value_type()) - { - size_type tp = size(); - if(tp > __n) - { - for(difference_type i = 0; i < (difference_type)( tp-__n); i++) - { - if(pop_back()) { - goto err; - } - } - } - else - { - for(difference_type i=0; i < (difference_type)( __n-tp); i++) - { - if(push_back(__x)) { - goto err; - } - } - } - return 0; - err: - return -1; - } - - /** - * @brief - * 将__l中的全部节点插入到__x指向的结点之前,并从__l中删除, - * __l必须是一个不同于__x所在的容器 - * @param [in/out] __x : iterator - * @param [in/out] __l : self& - * @return int - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:10 - **/ - int splice(iterator __x, self & __l) - { - if(__l._root.prev != __l._root.next) - { - size_type n = __l.size(); - _node_allocator.merge(__l._node_allocator); - node_pointer cur = __x._node; - cur->prev->next = __l._root.next; - __l._root.next->prev = cur->prev; - cur->prev = __l._root.prev; - __l._root.prev->next = cur; - __l._root.next = __l._root.prev = __l._root; - __x._list->_size += n; - __l._size = 0; - } - return 0; - } - -#if 0 - /** - * @brief - * 将__l中__p指向的节点删除,并插入到当前容器的__x指向的节点之间 - * @param [in/out] __x : iterator - * @param [in/out] __l : self& - * @param [in/out] __p : iterator - * @return int - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:14 - **/ - int splice(iterator __x, self & __l, iterator __p) - { - - if(__p != __l.end()) - { - node_pointer cur = __x._node; - node_pointer target = __p._node; - target->prev->next = target->next; - target->next->prev = target->prev; - cur->prev->next = target; - target->prev = cur->prev; - cur->prev = target; - target->next = cur; - } - return 0; - } - - /** - * @brief - * 将__l中[__p,__e)区间的节点从__l中删除,并插入到__x节点之前。 - * @param [in/out] __x : iterator - * @param [in/out] __l : self& - * @param [in/out] __p : iterator - * @param [in/out] __e : iteratot - * @return int - * @retval - * @see - * @author yufan - * @date 2008/08/15 11:54:23 - **/ - int splice(iterator __x, self & __l, iterator __p, iterator __e) - { - - if (__p != __e) - { - node_pointer cur = __x._node; - node_pointer end = __e._node->prev; - node_pointer target = __p._node; - - target->prev->next = __e._node; - __e._node->prev = target->prev; - - - cur->prev->next = target; - target->prev = cur->prev; - - cur->prev = end; - end->next = cur; - target->next->prev = target->prev; - } - return 0; - } -#endif - - /** - * @brief - * 从链表中删除与__x值相同的实例 - * @param [in] __x : const value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 15:54:50 - **/ - inline int remove(const value_type & __x) - { - return remove_if(std::bind2nd(std::equal_to<_Tp>(), __x)); - } - /** - * @brief - * 根据条件函数删除元素 - * @param [in] __p : Predicate - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 15:56:19 - **/ - template - int remove_if(Predicate __p) - { - node_pointer cur = _root.next; - while(cur != _root) - { - if(__p(cur->val)) - { - node_pointer tmp = cur; - cur = cur->next; - tmp->prev->next = tmp->next; - tmp->next->prev = tmp->prev; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - --_size; - } - else - { - cur = cur->next; - } - } - return 0; - } - - /** - * @brief - * 将链表反序排列 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:07:48 - **/ - int reverse() - { - node_pointer cur = _root.next; - _root.next = _root.prev; - _root.prev = cur; - while(cur != _root) - { - node_pointer tmp = cur->next; - cur->next = cur->prev; - cur->prev = tmp; - cur = tmp; - } - return 0; - } - - /** - * @brief - * 序列化 - * @param [in] ar : _Archive& - * @return template int 序列化方法提供类 - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:19:29 - **/ - template - int serialization(_Archive &ar) - { - size_t l = size(); - if(bsl::serialization(ar, l)) { - return -1; - } - for(iterator i=begin(); i!=end(); i++) - { - if(bsl::serialization(ar, *i)) { - return -1; - } - } - return 0; - } - - /** - * @brief - * 反序列化 - * @param [in] ar : _Archive& - * @return template int 反序列化方法提供类 - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:19:47 - **/ - template - int deserialization(_Archive &ar) - { - size_t l; - clear(); - if(bsl::deserialization(ar, l)) { - return -1; - } - iterator cur = begin(); - for(size_t i=0; i()); - } - - /** - * @brief - * 将两个已排序的链表合并,合并后,__other将为空 - * @param [in/out] __other : self& - * @param [in/out] __p : _Predicator - * @return template int - * @retval - * @see - * @author yufan - * @date 2008/08/19 20:56:06 - **/ - template - int merge(self & __other, _Predicator __p) - { - if(_root.next != _root && __other._root.next != __other._root) - { - size_type other_size = __other.size(); - _node_allocator.merge(__other._node_allocator); - _root.prev->next = 0; - __other._root.prev->next = 0; - _root.next = _merge( - (node_pointer)(_root.next), - (node_pointer)(__other._root.next), - __p - ); - __other._root.prev = __other._root.next = __other._root; - _relink(); - _size += other_size; - __other._size = 0; - return 0; - } - else if(__other._root.next != __other._root) - { - return swap(__other); - } - else - { - return 0; - } - } -#define __BSL_LIST_STACK_DEPTH 64 - /** - * @brief - * 按递增顺序排序 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:08:57 - **/ - int sort() - { - return sort(std::less<_Tp>()); - } - /** - * @brief - * 根据仿函数返回的结果对链表排序 - * @param [in/out] _p : Predicate& 仿函数 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/18 14:34:00 - **/ - template - int sort(Predicate _p = std::less<_Tp>()) - { - if( _root.next == _root) { - return 0; - } - node_pointer cur = _root.next; - node_pointer counter[__BSL_LIST_STACK_DEPTH ]; - for(int i=0; i < __BSL_LIST_STACK_DEPTH ; i++) - { - counter[i] = 0; - } - // int fill=0; - while( cur != _root) - { - node_pointer tmp = cur; - cur = cur->next; - tmp->next = 0; - int i = 0; - while(counter[i] != 0) - { - tmp = _merge(tmp,counter[i], _p); - counter[i]=0; - i++; - } - counter[i] = tmp; - // if(i > fill) - // fill = i; - } - for(int i = 1; i < __BSL_LIST_STACK_DEPTH ; i++) - { - counter[i] = _merge(counter[i-1], counter[i], _p); - } - _root.next = counter[__BSL_LIST_STACK_DEPTH - 1]; - _relink(); - return 0; - } -private: - - void _reset(){ - _root.next = _root.prev = _root; - _size = 0; - } - - void _relink() - { - node_pointer t_begin = _root; - do - { - t_begin->next->prev = t_begin; - t_begin = t_begin->next; - } - while(t_begin->next != 0); - t_begin->next = _root; - _root.prev = t_begin; - } - template - inline node_pointer _merge(node_pointer list1, node_pointer list2, const _Predicate &_p) - { - if(0 == list2) { - return list1; - } - if(0 == list1) { - return list2; - } - volatile node_holder_t tmp_root; - node_pointer tp = (node_pointer)&tmp_root; - node_pointer a = list1; - node_pointer b = list2; - while(true) - { - if(_p(a->val,b->val)) - { - tp->next = a; - if(a->next != 0) - { - tp = a; - a = a->next; - } - else - { - a->next = b; - return tmp_root.next; - } - - } - else - { - tp->next = b; - if(b->next != 0) - { - tp = b; - b = b->next; - } - else - { - b->next = a; - return tmp_root.next; - } - } - } - } - /** - * @brief - * 检查链表结构完整性,如前后指针是否一致,是否存在环, 用于DEBUG - * @return void - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:09:32 - **/ - void check() - { - if(_root.next == _root.prev) { - return; - } - node_pointer tmp = _root.next; - while(tmp != _root) - { - if(tmp->prev == 0) - { - *(int*)0=1; - } - if(tmp->next->prev != tmp) - { - *(int *)0=1; - } - tmp->prev = 0; - tmp = tmp->next; - } - tmp = _root.next; - tmp->prev = _root; - while(tmp != _root) - { - tmp->next->prev = tmp; - tmp = tmp->next; - } - } -}; - -} - - -#endif diff --git a/bsl/containers/slist/CMakeLists.txt b/bsl/containers/slist/CMakeLists.txt deleted file mode 100644 index 3d0c2997243c7ff472ee9d6344f103b76098bf26..0000000000000000000000000000000000000000 --- a/bsl/containers/slist/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/containers/slist/ChangeLog b/bsl/containers/slist/ChangeLog deleted file mode 100644 index b9031921449535275f90fabb9a018cf5e6c5fa3f..0000000000000000000000000000000000000000 --- a/bsl/containers/slist/ChangeLog +++ /dev/null @@ -1,2 +0,0 @@ -1.0.0.0 bsl_slist 2008.8.4 - Initial release diff --git a/bsl/containers/slist/Makefile b/bsl/containers/slist/Makefile deleted file mode 100644 index db42023a63d78aafccb669215e227187c3f0248d..0000000000000000000000000000000000000000 --- a/bsl/containers/slist/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -BSL=../../ -OUTINC=$(BSL)/output/include/bsl/containers/slist -all : - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp *.h $(OUTINC) - -clean : - rm -rf $(OUTINC) - diff --git a/bsl/containers/slist/README b/bsl/containers/slist/README deleted file mode 100644 index 571e1779659cf2465e342817254bd9d6e99cc742..0000000000000000000000000000000000000000 --- a/bsl/containers/slist/README +++ /dev/null @@ -1,18 +0,0 @@ -bsl::slist的说明 -~~~~~~~~~~~~~~~~ - bsl::slist是bsl下的单向链表模板,那使用了bsl::alloc的高效内存管理,相比std::list有5倍的性能提升 - - -目录结构 -~~~~~~~~ - bsl_slist.h 模板头文件 - perfbench slist性能测试,基于yperfbench - unittest slist的单元测试 - -使用方法 -~~~~~~~~ - 包含bls_slist.h头文件,创建bsl::slist的实例 - -反馈意见 -~~~~~~~~ - 联系yufan@baidu.com 或 com@baidu.com diff --git a/bsl/containers/slist/bsl_slist.h b/bsl/containers/slist/bsl_slist.h deleted file mode 100644 index 9a9cd2fc917055140940cb958c41bc5fb8e1691d..0000000000000000000000000000000000000000 --- a/bsl/containers/slist/bsl_slist.h +++ /dev/null @@ -1,1078 +0,0 @@ -/* * - * @brief: 单向链表 - * @author: yufan - * @version: 2010/10/15 modified by zhjw(zhujianwei@baidu.com) - * */ - -#ifndef _BSL_SLIST__ -#define _BSL_SLIST__ - -#include -#include -#include -#include - -#if 0 -template -class alloc -{ -public: - typedef _Tp* pointer; //空间地址指针 - typedef _Tp* const const_pointer; //常空间地址指针 - typedef _Tp& reference; //常空间地址指针 - _Tp * allocate(int n) - { - return new _Tp[n]; - } - void deallocate(_Tp * _x ) - { - delete [] _x; - } - -}; -#endif -namespace bsl -{ - -/** - * @brief slist的结点 - */ -template -struct slist_node_t -{ - typedef _Tp value_type; - typedef slist_node_t<_Tp, _Alloc> node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - node_pointer next; - value_type val; -}; - -template class slist; - -/** - * @brief slist只读迭代器 - */ -template -class slist_const_iterator -{ -private: - typedef slist<_Tp, _Alloc> slist_t; -public: - //typedef std::forward_iterator_tag iterator_category; - typedef typename slist_t::value_type value_type; - typedef typename slist_t::iterator iterator; - typedef _Ptr pointer; - typedef _Ref reference; -private: - typedef slist_const_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef slist_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - friend class slist; -public: - slist_const_iterator() - { - _node = 0; - } - slist_const_iterator(const self& __x) - { - _node = __x._node; - } - slist_const_iterator(const iterator & __x) - { - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator ++ () - { - _node = _node->next; - return *this; - } - self operator ++ (int) - { - self iter = *this; - ++ *this; - return iter; - } -private: - slist_const_iterator(node_pointer __x) - { - _node = __x; - } -public: - node_pointer _node; -}; - -/** - * @brief slist迭代器 - */ -template -class slist_iterator -{ -private: - typedef slist<_Tp, _Alloc> slist_t; -public: - //typedef std::forward_iterator_tag iterator_category; - typedef typename slist_t::value_type value_type; - typedef typename slist_t::iterator iterator; - typedef typename slist_t::const_iterator const_iterator; - typedef _Ptr pointer; - typedef _Ref reference; -private: - typedef slist_iterator<_Tp, _Ptr, _Ref, _Alloc> self; - typedef slist_node_t node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; - typedef typename node_alloc_t::pointer node_pointer; - friend class slist; -public: - slist_iterator() - { - _slist = 0; - _node = 0; - } - slist_iterator(const self& __x) - { - _slist = __x._slist; - _node = __x._node; - } - reference operator *() const - { - return _node->val; - } - bool operator == (const self & __iter) const - { - return (_node == __iter._node); - } - bool operator != (const self & __iter) const - { - return (_node != __iter._node); - } - pointer operator ->() const - { - return &_node->val; - } - self & operator ++ () - { - _node = _node->next; - return *this; - } - self operator ++ (int) - { - self iter = *this; - ++ *this; - return iter; - } -private: - slist_iterator(slist_t* __l, node_pointer __x) - { - _slist = __l; - _node = __x; - } -public: - node_pointer _node; -private: - slist_t *_slist; //归属的slist -}; - -/** - * @brief slist单向链表 - */ -template , 256> > -class slist -{ -private: - typedef slist<_Tp,_Alloc> self; - typedef slist_node_t<_Tp, _Alloc> node_t; - typedef typename _Alloc::template rebind::other node_alloc_t; -public: - typedef _Tp value_type; - typedef _Tp * pointer; - typedef const _Tp * const_pointer; - typedef _Tp & reference; - typedef const _Tp & const_reference; - typedef size_t size_type; - typedef long difference_type; - typedef slist_iterator iterator; - typedef slist_const_iterator const_iterator; -private: - typedef typename node_alloc_t::pointer node_pointer; - //typedef typename node_alloc_t::const_pointer node_const_pointer; - //typedef typename node_alloc_t::reference node_reference; - //typedef typename node_alloc_t::const_reference node_const_reference; - //friend class slist_iterator<_Tp, _Alloc>; - node_pointer _header; - node_alloc_t _node_allocator; - size_type _size; - -public: - /** - * @brief 构造函数 - * 无异常 - * 不需调create - **/ - slist() - { - _reset(); - create(); - } - - /** - * @brief - * 拷贝构造函数,抛异常 - * 如果拷贝失败,将恢复成原来的空slist - * 不需调create - **/ - slist( const self& other ) - { - _reset(); - create(); - if (assign(other.begin(),other.end()) != 0) { - throw BadAllocException()< size1) { - for ( size_t i = 1; i < size1; ++ i ) { - ++ first1; - ++ first2; - } - // this不为空,则first2为需要插入的第一个结点 - if (size1) { - ++ first2; - } - iterator tmp = first1; - while ( first2 != last2 ) { - if (insert_after( first1, *first2) != 0) { - erase_after( tmp, end() ); - throw BadAllocException()<= size2 - for ( size_t i = size1; i > size2; -- i ) { - if ( pop_front() != 0 ) { - throw BadAllocException()<clear(); - _node_allocator.destroy(); - return 0; - - } - /** - * @brief - * 析构函数 - * @see - * @author yufan - * @date 2008/08/15 12:33:56 - **/ - ~slist() - { - destroy(); - } - /** - * @brief - * 从另一个容器复制副本 - * @param [in/out] __x : slist_t& 要拷贝的实例 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:01 - **/ - int assign (const self & __x) - { - if (&__x != this) { - return assign(__x.begin(), __x.end()); - } else { - return 0; - } - } - - /** - * @brief - * 从迭代器复制副本 - * @param [in/out] __begin : __iterator - * @param [in/out] __end : __iterator - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:09 - **/ - template - int assign(__iterator __begin, __iterator __end) - { - node_pointer tmp_header; - node_pointer cur = reinterpret_cast(&tmp_header); - __iterator tp = __begin; - size_type n = 0; - while(tp != __end) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err1; - } - bsl::bsl_construct(&tmp->val, *tp); - cur->next = tmp; - cur = tmp; - ++tp; - ++n; - } - cur->next = 0; - clear(); - _header = tmp_header; - _size = n; - return 0; - err1: - if(0 == tmp_header->next) { - return -1; - } else { - tmp_header = tmp_header->next; - } - do { - node_pointer tmp = tmp_header->next; - bsl::bsl_destruct(&(tmp_header->val)); - _node_allocator.deallocate(tmp_header, 1); - tmp_header = tmp; - } while(cur != tmp_header); - return -1; - } - - /** - * @brief - * 清除所有元素 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:15 - **/ - int clear() - { - while(_header) - { - pop_front(); - } - _size = 0; - return 0; - } - - /** - * @brief - * 检查容器是否为空 - * @return bool - * @retval 空返回true,非空为false - * @see - * @author yufan - * @date 2008/08/15 12:34:18 - **/ - inline bool empty() const - { - return _header == 0; - } - - /** - * @brief - * 将新元素加入到链表头 - * @param [in/out] __x : value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:24 - **/ - int push_front(const value_type &__x) - { - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - tmp->next = _header; - _header = tmp; - ++_size; - return 0; - err: - return -1; - } - - /** - * @brief - * 删除链表的头元素 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:29 - **/ - int pop_front() - { - if ( 0 == _header) { - return -1; - } - - node_pointer tmp = _header->next; - bsl::bsl_destruct(&(_header->val)); - _node_allocator.deallocate(_header, 1); - _header = tmp; - --_size; - return 0; - } - - /** - * @brief - * 将元素插入到__i指向的位置之后,如果迭代器指向空节点,则插入到头节点。 - * @param [in/out] __i : iterator - * @param [in/out] __x : value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:36 - **/ - int insert_after( iterator __i, const value_type &__x) - { - if( 0 == __i._node && _header != 0) { - return -1; - } - - node_pointer tmp = _node_allocator.allocate(1); - if (!tmp) { - goto err; - } - bsl::bsl_construct(&tmp->val, __x); - if(__i._node) - { - tmp->next = __i._node->next; - __i._node->next = tmp; - } - else - { - tmp->next = _header; - _header = tmp; - } - __i._slist->_size += 1; - return 0; - err: - return -1; - } - /** - * @brief - * 删除__i指向的节点的下一个节点 - * @param [in/out] __i : iterator - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/19 16:48:28 - **/ - int erase_after ( iterator __i) - { - if( 0 == __i._node) { - return -1; - } - node_pointer tmp = __i._node->next; - __i._node->next = tmp->next; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - __i._slist->_size -= 1; - return 0; - } - /** - * @brief - * 删除__s和__e之间的节点,区间为(__s,__e) - * @param [in/out] __s : iterator - * @param [in/out] __e : iterator - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/19 16:48:33 - **/ - int erase_after ( iterator __s, iterator __e) - { - if(__s._node == 0) { - return -1; - } - node_pointer s = __s._node->next; - node_pointer e = __e._node; - size_t n = 0; - while(s != e) - { - node_pointer tmp = s; - s = s->next; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - ++n; - } - __s._node->next = __e._node; - __s._slist->_size -= n; - return 0; - } - /** - * @brief - * 返回头元素的常引用 - * @return const_reference - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:34:43 - **/ - inline const_reference front() const - { - if( 0 == _header ) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回头元素的引用 - * @return reference - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:34:47 - **/ - inline reference front() - { - if( 0 == _header ) { - throw bsl::InvalidOperationException()<val; - } - - /** - * @brief - * 返回指向头节点的常迭代器 - * @return const_iterator - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:34:52 - **/ - inline const_iterator begin() const - { - return const_iterator(_header); - } - - /** - * @brief - * 返回指向头节点的迭代器 - * @return iterator - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:34:55 - **/ - inline iterator begin() - { - return iterator(this, _header); - } - - /** - * @brief - * 返回指向尾节点的常迭代器 - * @return const_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:35:04 - **/ - inline const_iterator end() const - { - return const_iterator(0); - } - - /** - * @brief - * 返回指向尾节点的迭代器 - * @return iterator - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:35:07 - **/ - inline iterator end() - { - return iterator(this, 0); - } - /** - * @brief - * 将链表反序排列 - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:07:48 - **/ - int reverse() - { - node_pointer prev = 0; - node_pointer cur = _header; - while(cur != 0) - { - node_pointer tmp = cur->next; - cur->next = prev; - prev = cur; - cur = tmp; - } - _header = prev; - return 0; - } - - /** - * @brief - * 返回指向上一个节点的迭代器,复杂度O(n) - * @param [in/out] pos : iterator - * @return iterator - * @retval - * @see - * @author yufan - * @date 2008/08/19 19:19:08 - **/ - iterator previous(iterator pos) - { - if(0 == pos._node) { - return iterator(this, 0); - } - node_pointer tp = _header; - if(tp == pos._node) { - return iterator(this, 0); - } - while(tp != 0) - { - if(tp->next == pos._node) { - return iterator(this, tp); - } else { - tp = tp->next; - } - } - return iterator(this, 0); - } - - /** - * @brief - * 返回指向上一个节点的迭代器,复杂度O(n) - * @param [in/out] pos : const_iterator - * @return const_iterator - * @retval - * @see - * @author yufan - * @date 2008/08/19 19:19:47 - **/ - const_iterator previous(const_iterator pos) const - { - if(0 == pos._node) { - return const_iterator(0); - } - node_pointer tp = _header; - while(tp->next != pos._node) - { - tp = tp->next; - } - return const_iterator(tp); - } - /** - * @brief - * 返回容器的节点数量 - * @return int - * @retval - * @see - * @author yufan - * @date 2008/08/15 12:35:15 - **/ - size_type size() const - { - return _size; - } - /** - * @brief - * 返回容器所能容纳的最大节点数量 - * @return size_type - * @retval - * @see - * @author yufan - * @date 2008/08/11 16:20:27 - **/ - inline size_type max_size() const - { - return (size_type)(-1); - } - /** - * @brief - * 和__x容器交换内容 - * @param [in/out] __x : self& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 16:21:42 - **/ - int swap( self & __x) - { - //if(__x - _node_allocator.swap(__x._node_allocator); - std::swap(_header, __x._header); - std::swap(_size, __x._size); - //check(); - //__x.check(); - return 0; - } - /** - * @brief - * 序列化 - * @param [in/out] ar : _Archive& - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:35:21 - **/ - template - int serialization(_Archive &ar) - { - size_type l = size(); - if(bsl::serialization(ar, l)) { - goto err; - } - for(iterator i=begin(); i!=end(); i++) - { - if(bsl::serialization(ar, *i)) { - goto err; - } - } - return 0; - err: - return -1; - } - - /** - * @brief - * 反序列化 - * @param [in/out] ar : _Archive& - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/15 12:35:28 - **/ - template - int deserialization(_Archive &ar) - { - node_pointer cur; - size_type l; - clear(); - if(bsl::deserialization(ar, l)) { - goto err; - } - cur = reinterpret_cast(&_header); - for(size_type i=0; inext; - } - return 0; - err: - err2: - clear(); - return -1; - - } -#define __BSL_LIST_STACK_DEPTH 64 - /** - * @brief - * 按递增顺序排序 - * @return int - * @retval 成功返回0,其他返回-1 - tmp->val = __x; - * @see - * @author yufan - * @date 2008/08/11 16:08:57 - **/ - inline int sort() - { - return sort(std::less<_Tp>()); - } - /** - * @brief - * 按Predicate指定的顺序排序 - * @param [in/out] _p : Predicate - * @return template int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/19 10:44:33 - **/ - template - int sort(Predicate _p) - { - if( 0 == _header) { - return 0; - } - node_pointer cur = _header; - node_pointer counter[__BSL_LIST_STACK_DEPTH]; - for(int i=0; i<__BSL_LIST_STACK_DEPTH ; i++) - { - counter[i] = 0; - } - // int fill=0; - while( cur != 0) - { - node_pointer tmp = cur; - cur = cur->next; - tmp->next = 0; - int i = 0; - while(counter[i] != 0) - { - tmp = _merge(tmp,counter[i], _p); - counter[i]=0; - i++; - } - counter[i] = tmp; - // if(i > fill) - // fill = i; - } - for(int i = 1; i < __BSL_LIST_STACK_DEPTH ; i++) - { - counter[i] = _merge(counter[i-1], counter[i], _p); - } - _header = counter[__BSL_LIST_STACK_DEPTH - 1]; - return 0; - } - - /** - * @brief - * 将两个已排序的链表合并,合并后,__other将为空 - * @param [in/out] __other : self& - * @return int - * @retval - * @see - * @author yufan - * @date 2008/08/19 20:55:46 - **/ - int merge(self & __other) - { - return merge(__other, std::less<_Tp>()); - } - - /** - * @brief - * 将两个已排序的链表合并,合并后,__other将为空 - * @param [in/out] __other : self& - * @param [in/out] __p : _Predicator - * @return template int - * @retval - * @see - * @author yufan - * @date 2008/08/19 20:55:58 - **/ - template - int merge(self & __other, _Predicator __p) - { - if(_header != 0 && __other._header != 0) - { - size_type other_size = __other.size(); - _node_allocator.merge(__other._node_allocator); - _header = _merge(_header, __other._header, __p); - __other._header = 0; - _size += other_size; - __other._size = 0; - return 0; - } - else if(__other._header != 0) - { - return swap(__other); - } - else - { - return 0; - } - } - /** - * @brief - * 从链表中删除与__x值相同的实例 - * @param [in] __x : const value_type& - * @return int - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 15:54:50 - **/ - int remove(const value_type & __x) - { - return remove_if(std::bind2nd(std::equal_to<_Tp>(), __x)); - } - /** - * @brief - * 根据条件函数删除元素 - * @param [in] __p : Predicate - * @return template 当Predicate返回true时,元素被移除 - * @retval 成功返回0,其他返回-1 - * @see - * @author yufan - * @date 2008/08/11 15:56:19 - **/ - template - int remove_if(Predicate __p) - { - //为了避免对头节点特殊处理,这里强制将_header看作特殊的节点。 - node_pointer cur = reinterpret_cast(&_header); - while(cur->next != 0) - { - if(__p(cur->next->val)) - { - node_pointer tmp = cur->next; - cur->next = tmp->next; - bsl::bsl_destruct(&(tmp->val)); - _node_allocator.deallocate(tmp, 1); - --_size; - } - else - { - cur = cur->next; - } - } - return 0; - } -private: - - void _reset(){ - _header = 0; - _size = 0; - } - - template - inline node_pointer _merge(node_pointer list1, node_pointer list2, const _Predicate &_p) - { - if(0 == list2) { - return list1; - } - if(0 == list1) { - return list2; - } - volatile node_pointer tmp_root; - //为了避免对头节点特殊处理,这里强制将_header看作特殊的节点。 - node_pointer tp = (node_pointer)(&tmp_root); - node_pointer a = list1; - node_pointer b = list2; - while(true) - { - if(_p(a->val,b->val)) - { - tp->next = a; - if(a->next != 0) - { - tp = a; - a = a->next; - } - else - { - a->next = b; - return tmp_root; - } - - } - else - { - tp->next = b; - if(b->next != 0) - { - tp = b; - b = b->next; - } - else - { - b->next = a; - return tmp_root; - } - } - } - } -}; - -} - -#endif diff --git a/bsl/containers/string/CMakeLists.txt b/bsl/containers/string/CMakeLists.txt deleted file mode 100644 index 3d0c2997243c7ff472ee9d6344f103b76098bf26..0000000000000000000000000000000000000000 --- a/bsl/containers/string/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/containers/string/Makefile b/bsl/containers/string/Makefile deleted file mode 100644 index dee4b77acb1ca7c9c35068df4bdf6b7e55a9e532..0000000000000000000000000000000000000000 --- a/bsl/containers/string/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -BSL=../../ -OUTINC=$(BSL)/output/include/bsl/containers/string -all : - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - cp *.h $(OUTINC) - -clean : - rm -rf $(OUTINC) - diff --git a/bsl/containers/string/bsl_string.h b/bsl/containers/string/bsl_string.h deleted file mode 100644 index d9ee2d6e5d2137b57906811fe89bc1024978f3e9..0000000000000000000000000000000000000000 --- a/bsl/containers/string/bsl_string.h +++ /dev/null @@ -1,1573 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_string.h,v 1.26 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_basic_string.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/10 19:41:57 - * @version $Revision: 1.26 $ - * @brief - * - **/ -#ifndef __BSL_STRING_H__ -#define __BSL_STRING_H__ -#include -#include -#include //for char_traits -#include -#include -#if __GNUC__ >= 4 // 4.3 or greater -#include -#elif __GNUC__ >= 3 -#include -#else -#include -#endif -#include "bsl/exception/bsl_exception.h" -#include "bsl/pool/bsl_poolalloc.h" -#include "bsl/archive/bsl_serialization.h" -#include "bsl/utils/bsl_memcpy.h" -#include "bsl/containers/hash/bsl_hash_fun.h" - - -namespace bsl{ - template class basic_string; - typedef basic_string > string; - /** - * @brief 字符串类 - * - * 这是一个比较简单的字符串类。为解决std::string在g++2.96下的多线程bug而设计,接口尽量与std::string保持一致。复制使用立即深复制算法,目前没有使用引用计数。(以后可能改进) - * 初始化时_str保证指向一个值为0的静态空间(没有malloc的开销),因此_str总是一个合法的字符串,但是这样basic_string就没有trivial default constructor了。 - * 另一种替代算法是构造时_str被初始化为NULL,从而使string拥有trivial default constructor,但在很多的函数调用里都需要检查_str是否指向NULL,考虑到多数string对象被构造后都会被多次调用,因此效率上可能得不偿失 - * - * 注意!该类不接受NULL作为合法的C风格字符串(与std::string行为相同),对于const_pointer(NULL)参数,一律抛出bsl::NullPointerException - * - * 目前bsl::string与std::string接口的主要不同点: - * 模板参数: - * bsl::string比std::string少了一个模板参数:_TraitsT,原因为: - * 该参数很少使用; - * 该参数不能兼容g++2.96和g++3.4.5,若加上参数,则无论是自定义_TraitsT还是自定义_Alloc,都必须条件编译; - * 使编译后的类名短一点。 - * - * C++风格字符串的子串操作: - * std::string对不合法的子串操作(如begin_pos过大)会抛出std::out_of_range异常,而bsl::string会修正参数 - * - * 类C风格的扩展API - * 考虑到百度内大部分程序员习惯C风格的API,bsl::string引入以下扩展: - * bsl::string& setf( const char * format, ... ); - * bsl::string& vsetf( const char * format, va_list ); - * bsl::string& appendf( const char * format, ... ); - * bsl::string& vappendf( const char * format, va_list ); - * 与直接在C风格字符串上操作相比,这套API能自动扩展string的长度,而不会有访问越界问题 - * - * 迭代器,insert操作, replace操作,更多的运算符重载 - * bsl::string目前不提供这些操作,日后将会逐步加上 - * - * - * - */ - template - class basic_string{ - public: - typedef _CharT value_type; - typedef size_t size_type; - typedef long difference_type; - typedef value_type & reference; - typedef const value_type& const_reference; - typedef value_type * pointer; - typedef const value_type * const_pointer; - typedef _Alloc allocator_type; - - typedef pointer iterator; - typedef const_pointer const_iterator; - -#if __GNUC__ <= 2 - typedef string_char_traits<_CharT> traits_type; -#else - typedef std::char_traits<_CharT> traits_type; -#endif - - - - //define shallow_copy -#ifndef _BSL_STRING_SUPPORT_SHALLOW_COPY -#define _BSL_STRING_SUPPORT_SHALLOW_COPY -#endif - /** - * @brief 浅拷贝构造函数,将cstr作为自己的成员.shallow_copy==false:深拷贝构造.shallow_copy==true:浅拷贝构造 - * @param [in] shallow_copy : false:深拷贝.true:浅拷贝 - * @throw NullPointerException()<(cstr); - } - } - - - - //ctors and dtors - - /** - * @brief 默认构造函数,无动态内存分配,无抛掷保证。 - * - * @see - * @author chenxm - * @date 2008/09/16 11:27:38 - **/ - basic_string() - : _dataplus(_s_create_cstring(0,allocator_type())), _length(0), _capacity(0),_shallow_copy(false){ } - - /** - * @brief 根据内存分配器构造string对象 - * - * 这个方法很少用到。主要为了兼容std::string的接口 - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:28:27 - **/ - explicit basic_string( const allocator_type& alloc_ ) - : _dataplus(_s_create_cstring(0, alloc_), alloc_ ), _length(0), _capacity(0),_shallow_copy(false){} - - /** - * @brief 复制构造函数 - * 当other.length() == 0时,没有动态内存分配(考虑到STL及类似容器经常使用一个默认构造的对象去复制构造一大堆对象,这样做是很有意义的) - * - * @param [in] other : const basic_string& - * @see - * @author chenxm - * @date 2008/09/13 23:35:51 - * @modified by chenyanling@baidu.com 2011/10/17 - **/ - basic_string( const basic_string& other ) - : _dataplus(NULL,other._dataplus), - _length(other._length), _capacity(other._length),_shallow_copy(other._shallow_copy) { - if(false == _shallow_copy){ - _dataplus._str = _s_clone_cstring( other._dataplus._str, _length, _dataplus ); - } - else{ - _dataplus._str = other._dataplus._str; - } - } - - /** - * @brief 复制构造other的子串 - * - * 若sub_str_len未给出或等于npos - * 则*this被构造为other上的[begin_pos, other.length())区间上的子串 - * 否则*this被构造为other上的[begin_pos, begin_pos+sub_str_len)上子串,即第begin_pos个(0-based)字符开头,长度最多为sub_str_len的子串 - * - * - * @param [in] other : const basic_string& - * @param [in] begin_pos : size_type - * @param [in] sub_str_len : size_type - * @see - * @author chenxm - * @date 2008/09/16 11:32:18 - **/ - basic_string( const basic_string& other, size_type begin_pos, size_type sub_str_len = npos, const allocator_type& alloc_ = allocator_type() ) - : _dataplus(NULL, alloc_), _length(0), _capacity(0),_shallow_copy(false){ - if ( begin_pos > other._length ){ - begin_pos = other._length; - } - if ( sub_str_len > other._length - begin_pos ){ - sub_str_len = other._length - begin_pos; - } - _length = _capacity = sub_str_len; - _dataplus._str = _s_clone_cstring( other._dataplus._str + begin_pos, _capacity, alloc_ ); - } - - /** - * @brief 复制构造C风格字符串的子串 - * - * 本函数直接复制区间[cstr, cstr+len)之间的内容,不考虑是否存在\0 - * - * @param [in] cstr : const_pointer - * @param [in] sub_str_len : size_type - * @see - * @author chenxm - * @date 2008/09/16 11:38:53 - **/ - basic_string( const_pointer cstr, size_type len, const allocator_type& alloc_= allocator_type() ) - : _dataplus(NULL,alloc_), _length(0), _capacity(0),_shallow_copy(false) { - _length = _capacity = len; - _dataplus._str = _s_clone_cstring( cstr, _length, alloc_ ); - } - - /** - * @brief 复制构造C风格字符串 - * - * 若cstr为空串或NULL,则构造结果为空串,并且没有动态内存分配。 - * @param [in] cstr : const_pointer - * @see - * @author chenxm - * @date 2008/09/16 11:41:25 - **/ - basic_string( const_pointer cstr, const allocator_type& alloc_ = allocator_type() ) - : _dataplus(NULL,alloc_), _length(0), _capacity(0),_shallow_copy(false) { - _capacity = _length = _s_cstring_len(cstr); - _dataplus._str = _s_clone_cstring(cstr, _length, alloc_); - } - - /** - * @brief 构造一个由n个chr字符组成的字符串 - * - * @param [in] n : size_type - * @param [in] chr : value_type - * @see - * @author chenxm - * @date 2008/09/16 11:41:55 - **/ - basic_string( size_type n, value_type chr, const allocator_type& alloc_ = allocator_type() ) - : _dataplus(_s_create_cstring(n, alloc_), alloc_), _length(n), _capacity(n),_shallow_copy(false){ - std::fill_n(_dataplus._str,n,chr); //会有多种特化版本来优化性能 - _dataplus._str[_length] = 0; - } - - /** - * @brief 根据区间[__begin, __end)构造字符串 - * - * 注:不检查区间内是否有'\0'值!(与std::string行为相同) - * @param [in] __begin : InputIterator - * @param [in] __end : InputIterator - * @see - * @author chenxm - * @date 2008/09/16 11:43:05 - **/ - template - basic_string( InputIterator __begin, InputIterator __end, const allocator_type& alloc_= allocator_type() ) - :_dataplus(NULL,alloc_), _length(0), _capacity(0),_shallow_copy(false) { - difference_type dis = std::distance(__begin, __end); - if ( dis > 0 ){ - pointer tmp = _dataplus._str = _s_create_cstring( dis, alloc_ ); - _length = _capacity = size_type(dis); - for(; __begin != __end; ++ __begin ){ - *tmp++ = *__begin; - } - *tmp = 0; - }else{ - _dataplus._str = _s_create_cstring(0, alloc_); - } - } - - /** - * @brief basic_string( InputIterator __begin, InputIterator __end, const allocator_type& alloc_= allocator_type() ) 在InputIterator == const_pointer时的特化 - * - * @param [in] __begin : const_pointer - * @param [in] __end : const_pointer - * @param [in] alloc_ : const allocator_type& - * @see - * @author chenxm - * @date 2009/06/02 12:47:52 - **/ - basic_string( const_pointer __begin, const_pointer __end, const allocator_type& alloc_= allocator_type() ) - :_dataplus(NULL, alloc_), _length(0), _capacity(0),_shallow_copy(false){ - if ( __begin == NULL || __end == NULL ){ - throw NullPointerException()<(__begin)<<"] > __end["<(__end)<<"]"; - } - if ( __begin <= __end ){ - _length = _capacity = __end - __begin; - _dataplus._str = _s_clone_cstring( __begin, _length, alloc_ ); - }else{ - _dataplus._str = _s_create_cstring(0, alloc_); - } - } - - /** - * @brief basic_string( InputIterator __begin, InputIterator __end, const allocator_type& alloc_= allocator_type() ) 在InputIterator == pointer时的特化 - * - * @param [in] __begin : pointer - * @param [in] __end : pointer - * @param [in] alloc_ : const allocator_type& - * @see - * @author chenxm - * @date 2009/06/02 12:48:22 - **/ - basic_string( pointer __begin, pointer __end, const allocator_type& alloc_= allocator_type() ) - :_dataplus(NULL, alloc_), _length(0), _capacity(0),_shallow_copy(false){ - if ( __begin == NULL || __end == NULL ){ - throw NullPointerException()<(__begin)<<"] > __end["<(__end)<<"]"; - } - if ( __begin <= __end ){ - _length = _capacity = __end - __begin; - _dataplus._str = _s_clone_cstring( __begin, _length, alloc_ ); - }else{ - _dataplus._str = _s_create_cstring(0, alloc_); - } - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2008/09/16 11:44:02 - **/ - ~basic_string() { - _s_destroy_cstring(_dataplus._str, _capacity, _dataplus); - } - - //substr - basic_string substr(size_t pos = 0, size_t n = npos ) const { - return basic_string(*this, pos, n); - } - - //serialization - - /** - * @brief const版本的串行化函数 - * - * 这个是正常版本的串行化函数 - * @param [in] ar : _Archive& - * @return int - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:45:22 - **/ - template - int serialization(_Archive &ar) const { - if (ar.push(&_length, sizeof(_length)) != 0) { - __BSL_ERROR("push siz[%lu] err", _length); - return -1; - } - if ( _length && ar.push(_dataplus._str, _length*sizeof(value_type)) != 0) { - __BSL_ERROR("push str[%p] err", _dataplus._str); - return -1; - } - return 0; - } - - /** - * @brief 反串行化函数 - * - * 当反串行化失败时,该函数返回-1,强异常安全保证 - * @param [in] ar : _Archive& - * @return int - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:46:22 - **/ - template - int deserialization(_Archive &ar) { - size_type siz = 0; - if (ar.pop(&siz, sizeof(siz)) != 0) { - __BSL_ERROR("pop siz err"); - return -1; - } - pointer ptr = _s_create_cstring(siz, _dataplus); //throw - if (ar.pop(ptr, sizeof(value_type)*siz) != 0 ) { - __BSL_ERROR("pop str err"); - _s_destroy_cstring(ptr, siz, _dataplus); - return -1; - } - - ptr[siz] = 0; - _s_destroy_cstring( _dataplus._str, _length, _dataplus ); - _dataplus._str = ptr; - _length = _capacity = siz; - - return 0; - } - - // getters - /** - * @brief 返回C风格字符串,O(1) - * - * @return const_pointer - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:48:59 - **/ - const_pointer c_str() const { - return _dataplus._str; - } - - /** - * @brief 返回该字符串是否为空 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:49:24 - **/ - bool empty() const { - return _length == 0; - } - - /** - * @brief 返回字符串的长度 - * - * @return size_type - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:49:39 - **/ - size_type size() const { - return _length; - } - - /** - * @brief 返回字符串的长度 - * - * @return size_type - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:49:59 - **/ - size_type length() const { - return _length; - } - - /** - * @brief 返回字符串的容量 - * - * 容量的定义为:在不重新进行内存分配的情况下,本字符串最多能容纳的字符数(不包括'\0') - * @return size_type - * @retval - * @see - * @author chenxm - * @date 2008/09/10 21:38:24 - **/ - size_type capacity() const { - return _capacity; - } - - /** - * @brief 返回第index个字符(const 版本) - * - * 若0 <= index < (int)length() - * 则返回顺数第index个字符; - * 若-(int)length() < index < 0 - * 则返回倒数第index个字符; - * 否则 - * 结果未定义。 - * @param [in] index : int - * @return value_type[] - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:51:12 - **/ - const_reference operator []( int idx ) const { - if (idx >= 0 && idx < int(_length)){ - return _dataplus._str[idx]; - } - if (idx < 0 && idx >= -int(_length) ){ - return _dataplus._str[int(_length)+idx]; - } - throw OutOfBoundException()<= 0 && idx < int(_length)){ - return _dataplus._str[idx]; - } - if (idx < 0 && idx >= -int(_length) ){ - return _dataplus._str[int(_length)+idx]; - } - throw OutOfBoundException()<find(str._dataplus._str, pos, str._length); - } - - size_type find(const _CharT* s, size_type pos = 0) const { - return this->find(s, pos, _s_cstring_len(s)); - } - - size_type find(_CharT c, size_type pos = 0) const{ - const_pointer b = _dataplus._str + pos; - const_pointer e = _dataplus._str + _length; - for(; b < e; ++b){ - if ( *b == c ){ - return b - _dataplus._str; - } - } - return npos; - } - - - size_type rfind(const basic_string& str, size_type pos = npos) const { - return this->rfind(str._dataplus._str, pos, str._length); - } - - size_type rfind(const _CharT* s, size_type pos, size_type n) const{ - if ( s == NULL ){ - throw bsl::NullPointerException()<= n ){ - const_pointer tb = _dataplus._str + std::min(size_t(_length - n), pos); - for(; tb >= _dataplus._str; --tb ){ - if ( traits_type::compare( tb, s, n ) == 0 ){ - return tb - _dataplus._str; - } - } - } - return npos; - } - - size_type rfind(const _CharT* s, size_type pos = npos) const { - return this->rfind(s, pos, _s_cstring_len(s)); - } - - size_type rfind(_CharT c, size_type pos = npos) const{ - const_pointer b = _dataplus._str + (pos >= _length ? _length - 1 : pos); - const_pointer e = _dataplus._str; - for(; b >= e; --b){ - if ( *b == c ){ - return b - _dataplus._str; - } - } - return npos; - } - - /** - * @brief 追加另外一个bsl::string - * - * @param [in] other : const basic_string& - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/08 23:35:28 - **/ - basic_string& append( const basic_string& other ){ - reserve( _length + other._length ); - xmemcpy( _dataplus._str + _length, other._dataplus._str, sizeof(value_type) * other._length ); // 1 for '\0' - _length += other._length; - _dataplus._str[_length] = 0; - return *this; - } - - /** - * @brief 追加另一个bsl::string的子串 - * - * 若begin_pos >= other._length,*this不会被修改 - * 若begin_pos + sub_str_len >= other.length(),则sub_str_len被调整为other.length() - begin_pos - * - * @param [in] other : const basic_string& - * @param [in] begin_pos : size_type - * @param [in] sub_str_len : size_type - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/08 23:36:42 - **/ - basic_string& append( const basic_string& other, size_type begin_pos, size_type sub_str_len = npos ){ - if ( begin_pos >= other._length ){ - return *this; - } - if ( sub_str_len > other._length - begin_pos ){ - sub_str_len = other._length - begin_pos; - } - reserve( _length + sub_str_len ); - xmemcpy( _dataplus._str + _length, other._dataplus._str + begin_pos, sizeof(value_type) * sub_str_len ); - _length += sub_str_len; - _dataplus._str[_length] = 0; - return *this; - } - - /** - * @brief 追加一个C风格字符串 - * - * 如果已经确切知道cstr的长度,使用append( cstr, len)可以快4~8倍 - * - * @param [in] cstr : const_pointer - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/08 23:53:09 - **/ - basic_string& append( const_pointer cstr ){ - size_t cstr_len = _s_cstring_len( cstr ); - reserve( _length + cstr_len ); - xmemcpy( _dataplus._str + _length, cstr, sizeof(value_type) * cstr_len ); - _length += cstr_len; - _dataplus._str[_length] = 0; - return *this; - } - - /** - * @brief 追加C风格字符串的子串 - * - * 本函数直接复制追加区间[cstr, cstr+len)之间的内容,不考虑是否存在\0 - * - * @param [in] cstr : const_pointer - * @param [in] sub_str_len : size_type - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/08 23:55:50 - **/ - basic_string& append( const_pointer cstr, size_type len ){ - if ( cstr == NULL ){ - throw bsl::NullPointerException()< basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/20 14:30:05 - **/ - template - basic_string& append( InputIterator __begin, InputIterator __end ){ - difference_type dis = std::distance(__begin, __end); - if ( dis > 0 ){ - reserve( _length + dis ); - for( pointer p = _dataplus._str + _length; __begin != __end; ++p, ++ __begin ){ - *p = *__begin; - } - _length += size_type(dis); - _dataplus._str[_length] = 0; - }else{ - //pass - } - return *this; - } - - /** - * @brief basic_string& append( InputIterator __begin, InputIterator __end )在InputIterator == const_pointer时的特化 - * - * @param [in] __begin : const_pointer - * @param [in] __end : const_pointer - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2009/06/02 12:49:35 - **/ - basic_string& append( const_pointer __begin, const_pointer __end ){ - if ( __begin == NULL || __end == NULL ){ - throw NullPointerException()<(__begin)<<"] > __end["<(__end)<<"]"; - } - if ( __begin < __end ){ - return append( __begin, __end - __begin ); - }else{ - //pass - return *this; - } - } - - /** - * @brief basic_string& append( InputIterator __begin, InputIterator __end )在InputIterator == pointer时的特化 - * - * @param [in] __begin : pointer - * @param [in] __end : pointer - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2009/06/02 12:49:35 - **/ - basic_string& append( pointer __begin, pointer __end ){ - if ( __begin == NULL || __end == NULL ){ - throw NullPointerException()<(__begin)<<"] > __end["<(__end)<<"]"; - } - if ( __begin < __end ){ - return append( __begin, __end - __begin ); - }else{ - //pass - return *this; - } - } - - void push_back( value_type chr ){ - if ( _length >= _capacity ){ - reserve( _length + 1 ); - } - _dataplus._str[_length] = chr; - _dataplus._str[++_length] = 0; - } - - // setters - /** - * @brief 把本字符串置为空串 - * - * 注:若本字符串使用的动态分配的内存,该内存不会被释放。若确实需要释放内存,可使用swap惯用法:big_str.swap(string()); - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:54:44 - **/ - void clear(){ - _length = 0; - _dataplus._str[0] = 0; - } - - /** - * @brief 扩充字符串的容量至__capacity或以上 - * - * 容量的定义参见capacity() - * 若__capacity > capacity() 则内存将被重新分配以保证capacity()>=__capacity,但内容保持不变; - * 否则,本方法无操作。 - * - * @param [in] __capacity : size_type - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/09/16 11:57:46 - **/ - void reserve( size_type __capacity ){ - if ( __capacity > _capacity ){ - if ( __capacity < _capacity + _capacity ){ - __capacity = _capacity + _capacity; - } - pointer tmp = _s_create_cstring( __capacity, _dataplus ); //throw - xmemcpy( tmp, _dataplus._str, (_length+1)*sizeof(value_type) ); - _s_destroy_cstring( _dataplus._str, _capacity, _dataplus ); - _dataplus._str = tmp; - _capacity = __capacity; - } - } - - /** - * @brief 交互两个字符串,O(1),无抛掷保证 - * - * 平凡但非常有用的一个函数。灵活使用“swap惯用法“可以完成很多有用的功能,如编写强异常安全的上层函数,或把字符串“trim to size“等 - * - * @param [in] other : basic_string& - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/09/16 18:46:43 - **/ - void swap( basic_string& other ) { - std::swap(_dataplus._str, other._dataplus._str); - std::swap(_length, other._length); - std::swap(_capacity, other._capacity); - } - - /** - * @brief 为本字符串赋值 - * - * 若other.length() <= this->capacity,则内存不会被重新分配 - * - * @param [in] other : const basic_string& - * @return basic_string& operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:00:42 - **/ - basic_string& operator = ( const basic_string& other ){ - if ( other._dataplus._str[0] == 0 ){ - _dataplus._str[0] = 0; - _length = 0; - }else if ( &other != this ){ - if ( other._length > _capacity ){ - pointer tmp = _s_create_cstring( other._length, _dataplus ); //throw - _s_destroy_cstring( _dataplus._str, _capacity, _dataplus ); - _dataplus._str = tmp; - _capacity = other._length; - } - _length = other._length; - xmemcpy( _dataplus._str, other._dataplus._str, (_length+1)*sizeof(value_type) ); - } - return *this; - } - - /** - * @brief 使用C风格字符串为本字符串赋值 - * - * 若cstr的长度 <= capacity(),则内存不会被重新分配 - * @param [in] cstr : const_pointer - * @return basic_string& operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:02:31 - **/ - basic_string& operator = ( const_pointer cstr ){ - if ( cstr == NULL ){ - _dataplus._str[0] = 0; - _length = 0; - }else if ( cstr[0] == 0 ){ - _dataplus._str[0] = 0; - _length = 0; - }else if ( cstr != _dataplus._str){ - size_type len = _s_cstring_len( cstr ); - if ( len > _capacity ){ - pointer tmp = _s_create_cstring( len, _dataplus ); //throw - _s_destroy_cstring( _dataplus._str, _capacity, _dataplus ); - _dataplus._str = tmp; - _capacity = len; - } - _length = len; - xmemcpy( _dataplus._str, cstr, (len+1)*sizeof(value_type) ); - } - return *this; - } - - - //comparers - int compare( const basic_string& other ) const { - const size_type len = _length < other._length ? _length : other._length; - int ret = traits_type::compare( _dataplus._str, other._dataplus._str, len ); - if ( ret == 0 ){ - if (_length > other._length) { - return 1; - } else if (_length == other._length) { - return 0; - } else { - return -1; - } - }else{ - return ret; - } - } - - int compare( const_pointer cstr ) const { - const size_type cstr_len = _s_cstring_len(cstr); - const size_type len = _length < cstr_len ? _length : cstr_len; - int ret = traits_type::compare( _dataplus._str, cstr, len ); - if ( ret == 0 ){ - if (_length > cstr_len) { - return 1; - } else if (_length == cstr_len) { - return 0; - } else { - return -1; - } - }else{ - return ret; - } - } - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:03:49 - **/ - friend inline bool operator == (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1._length == sstr2._length && sstr1.compare( sstr2 ) == 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:24 - **/ - friend inline bool operator == (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) == 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:28 - **/ - friend inline bool operator == (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) == 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:32 - **/ - friend inline bool operator != (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1._length != sstr2._length || sstr1.compare( sstr2 ) != 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:36 - **/ - friend inline bool operator != (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) != 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:39 - **/ - friend inline bool operator != (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) != 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:47 - **/ - friend inline bool operator < (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1.compare( sstr2 ) < 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:14:51 - **/ - friend inline bool operator < (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) < 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:00 - **/ - friend inline bool operator < (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) > 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:04 - **/ - friend inline bool operator > (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1.compare( sstr2 ) > 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:09 - **/ - friend inline bool operator > (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) > 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:12 - **/ - friend inline bool operator > (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) < 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:16 - **/ - friend inline bool operator <= (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1.compare( sstr2 ) <= 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:21 - **/ - friend inline bool operator <= (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) <= 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:25 - **/ - friend inline bool operator <= (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) >= 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr1 : const basic_string& - * @param [in] sstr2 : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:28 - **/ - friend inline bool operator >= (const basic_string& sstr1, const basic_string& sstr2){ - return sstr1.compare( sstr2 ) >= 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] sstr : const basic_string& - * @param [in] cstr : const_pointer - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:33 - **/ - friend inline bool operator >= (const basic_string& sstr, const_pointer cstr ){ - return sstr.compare( cstr ) >= 0; - } - - /** - * @brief 判断两字符串字典序的大小关系 - * - * @param [in] cstr : const_pointer - * @param [in] sstr : const basic_string& - * @return friend inline bool operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:36 - **/ - friend inline bool operator >= (const_pointer cstr, const basic_string& sstr ){ - return sstr.compare( cstr ) <= 0; - } - -#if __GNUC__ <= 2 - /** - * @brief 把本字符串输出到流 - * - * 本函数使bsl::string可以使用cout、cerr或者stringstream等类型来输出 - * @param [in] os : std::ostream& - * @param [in] sstr : const basic_string& - * @return friend inline std::ostream& operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:41 - **/ - friend inline std::ostream& - operator << ( std::ostream& os, const basic_string& sstr ){ - //TODO: implementation for value_type = ushort or uint required - for( const_pointer p = sstr._dataplus._str; *p; ++ p){ - os << *p; - } - return os; - } -#else - /** - * @brief 把本字符串输出到流 - * - * 本函数使bsl::string可以使用cout、cerr或者stringstream等类型来输出 - * @param [in] os : std::ostream& - * @param [in] sstr : const basic_string& - * @return friend inline std::ostream& operator - * @retval - * @see - * @author chenxm - * @date 2008/09/16 12:15:41 - **/ - friend inline std::basic_ostream& - operator << ( std::basic_ostream& os, const basic_string& sstr ){ - //TODO: implementation for value_type = ushort or uint required - for( const_pointer p = sstr._dataplus._str; *p; ++ p){ - os << *p; - } - return os; - } -#endif - public: - //非标准扩展 - /** - * @brief 接口与标准C函数printf()相同,输出值作为*this的新值,若容量不够,会自动扩充 - * - * @param [in] format : const char* - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/09 15:44:39 - **/ - basic_string& setf( const char * format, ... )__attribute__ ((format (printf, 2, 3) )); - - /** - * @brief 接口与标准C函数printf()相同,输出值追加到原字符串尾,若容量不够,会自动扩充 - * - * @param [in] format : const char* - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/09 16:37:26 - **/ - basic_string& appendf( const char * format, ... )__attribute__ ((format (printf, 2, 3) )); - - /** - * @brief - * - * @brief this function is removed because g++2.96 and the corresponding glibc doesn't support vsscanf function - * @param [in/out] format : const char* - * @return int - * @retval - * @see - * @author chenxm - * @date 2008/11/07 16:36:44 - **/ - /* - int getf( const char * format, ... ) const { - va_list ap; - va_start( ap, format ); - int res = vsscanf( _dataplus._str, format, ap ); - va_end( ap ); - return res; - }*/ - - - /** - * @brief this function is removed because g++2.96 and the corresponding glibc doesn't support vsscanf function - * - * @param [in/out] format : const char* - * @param [in/out] ap : va_list - * @return int - * @retval - * @see - * @author chenxm - * @date 2008/11/07 16:37:45 - **/ - /* - int vgetf( const char * format, va_list ap ) const { - return vsscanf( _dataplus._str, format, ap ); - } - */ - - /** - * @brief 接口与标准C函数vprintf()相同,输出值作为*this的新值,若容量不够,会自动扩充 - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/09 16:38:21 - **/ - basic_string& vsetf( const char * format, va_list ap ){ - clear(); - return vappendf( format, ap ); - } - - /** - * @brief 接口与标准C函数vprintf()相同,输出值追加到原字符串尾,若容量不够,会自动扩充 - * - * 无论_CharT是什么,format总是const char * - * - * @param [in] format : const char* - * @param [in] ap : va_list - * @return basic_string& - * @retval - * @see - * @author chenxm - * @date 2008/11/09 16:39:15 - **/ - basic_string& vappendf( const char * format, va_list ap ){ - _do_vappendf( format, ap, _CharT() ); //特化_CharT == char 以改善性能 - return *this; - } - - - private: - - static size_t _s_cstring_len( const_pointer cstr ) { - if ( !cstr ){ - throw NullPointerException()< int(_capacity - _length) ){ - reserve( _length + len ); //扩充容量 _capacity = _length + len - va_copy( aq, ap ); - vsnprintf( _dataplus._str + _length, _capacity - _length + 1, format, aq ); //重试 - va_end( aq ); - _length += len; - }else if ( len >= 0 ){ - //pass - _length += len; - }else{ //len < 0 - //pass - } - } - - - - /** - * @brief vappendf的泛化函数 - * - * _CharType == wchar_t时也不能使用vswprintf(),这是因为vswprintf()与vsnprintf()接口不一致造成的 - * - * @param [in] format : const _CharT* - * @param [in] ap : va_list - * @return template static int - * @retval - * @see - * @author chenxm - * @date 2008/11/10 18:20:00 - **/ - template - void _do_vappendf( const char * format, va_list ap, _CharType /*type tag*/ ){ - va_list aq; - va_copy( aq, ap ); - int append_len = vsnprintf( NULL, 0, format, aq ); //just get the length; - va_end( aq ); - if ( append_len < 0 ){ //bad format - return; //pass - } - if ( append_len > int(_capacity - _length) ){ - reserve( _length + append_len ); - } - // 先抄到tmp中去 - typedef typename _Alloc::template rebind::other char_alloc_t; - basic_string tmp; - tmp.reserve(append_len); - va_copy( aq, ap ); - tmp.vappendf( format, aq ); //只会写一次 - va_end( aq ); - - //再逐字抄回来 - const char * tmp_str = tmp.c_str(); - for( int i = 0; i< append_len; ++ i ){ - _dataplus._str[_length+i] = tmp_str[i]; - } - _length += append_len; - _dataplus._str[_length] = 0; - } - - - public: - static const size_type npos = static_cast(-1); - - private: - - // Use empty-base optimization: http://www.cantrip.org/emptyopt.html - struct _alloc_hider_t: allocator_type{ - _alloc_hider_t( pointer p) - :allocator_type(), _str(p) {} - - _alloc_hider_t( pointer p, allocator_type alloc_) - :allocator_type(alloc_), _str(p) {} - - pointer _str; - }; - _alloc_hider_t _dataplus; - size_type _length; - size_type _capacity; - bool _shallow_copy; - }; - - template - basic_string<_CharT,_Alloc>& basic_string<_CharT,_Alloc>::setf( const char * format, ... ){ - va_list ap; - va_start( ap, format ); - clear(); - vappendf( format, ap ); - va_end( ap ); - return *this; - } - - template - basic_string<_CharT,_Alloc>& basic_string<_CharT,_Alloc>::appendf( const char * format, ... ){ - va_list ap; - va_start( ap, format ); - vappendf( format, ap ); - va_end( ap ); - return *this; - } - - /** - * @brief 把bsl::string的内容追加到bsl::AutoBuffer - * - * 暂不支持其它_CharT及_AllocT - * - * @param [in] buf : bsl::AutoBuffer& - * @param [in] str : bsl::string& - * @return bsl::AutoBuffer& operator - * @retval - * @see - * @author chenxm - * @date 2009/05/07 16:07:16 - **/ - inline bsl::AutoBuffer& operator <<( bsl::AutoBuffer& buf, bsl::string& str ){ - return buf << str.c_str(); - } -} // namespace bsl - -#if __GNUC__ >= 3 -namespace __gnu_cxx{ -#else -namespace std{ -#endif - /** - * @brief 针对__gnu_cxx::hash编写的hasher - * - * 目前只支持char类型,但allocator类型为任意类型。 - * 使用与const char*相同的hash算法。 - */ - template - struct hash >{ - size_t operator()(const bsl::basic_string& bs ) const { - return __stl_hash_string(bs.c_str()); - } - }; -} // namespace __gnu_cxx/std - -namespace bsl{ - /** - * @brief 针对bsl::xhash编写的hasher - * - * 目前只支持char类型,但allocator类型为任意类型。 - * 使用与const char*相同的hash算法。 - */ - template - struct xhash >{ - size_t operator()(const bsl::basic_string& bs ) const { - return __bsl_hash_string(bs.c_str()); - } - }; -} // namespace bsl - -#endif // __BSL_STRING_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/cxxtest/README b/bsl/cxxtest/README deleted file mode 100755 index 40722cd94124ee6e00736329bfe3985584227b64..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/README +++ /dev/null @@ -1,63 +0,0 @@ -Introduction ------------- - -CxxTest is a JUnit/CppUnit/xUnit-like framework for C++. - -Its advantages over existing alternatives are that it: - - Doesn't require RTTI - - Doesn't require member template functions - - Doesn't require exception handling - - Doesn't require any external libraries (including memory management, - file/console I/O, graphics libraries) - -This makes it extremely portable and usable. - -CxxTest is available under the GNU Lesser General Public Licence (LGPL). -See http://www.gnu.org/copyleft/lesser.html for the license. - -Simple user's guide -------------------- - -1. Create a test suite header file: - -MyTest.h: - #include - - class MyTestSuite : public CxxTest::TestSuite - { - public: - void testAddition( void ) - { - TS_ASSERT( 1 + 1 > 1 ); - TS_ASSERT_EQUALS( 1 + 1, 2 ); - } - }; - - -2. Generate the tests file: - - # cxxtestgen.pl -o tests.cpp MyTestSuite.h - - -3. Create a main function that runs the tests - -main.cpp: - #include - - int main( void ) - { - CxxText::ErrorPrinter::runAllTests(); - return 0; - } - - -4. Compile and run! - - # g++ -o main main.cpp tests.cpp - # ./main - Running 1 test(s).OK! - - -Advanced User's Guide ---------------------- -See docs/guide.html. diff --git a/bsl/cxxtest/TODO b/bsl/cxxtest/TODO deleted file mode 100755 index 7a7f926e507bdc01de0c44868500b7c491616906..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/TODO +++ /dev/null @@ -1,34 +0,0 @@ -This is an -*- Outline -*- of ideas for future versions of CxxTest. -It is not meant to be "human readable". - -* CxxTest To Do list - -** Mock framework - -Write some mocks - -*** Distribution -Seperate packages (w/ binaries)? How would that be used? -For Windows: .lib for "Real" and "Mock" parts. -For Linux: Maybe. Different compilers etc. -So probably only source release with Makefiles and .ds[pw]? Or just Win32 binary. - -**** Installation? -extract cxxtest-x.y.z.tar.gz -(extract cxxtest-mock-x.y.z.tar.gz) ? -make -C cxxtest/Real -make -C cxxtest/Mock - -or maybe make -C cxxtest -f Makefile.mock -but then Makefile.mock.bcc32, Makefile.mock.msvc, Makefile.mock.gcc, and heaven knows what else. - -Could put the Makefile.mock.* in cxxtest/Real and cxxtest/Mock or in cxxtest/T - -Maybe this should be a different package altogether? -Seems logical, since they evolve separately. But then you'd want to download both. - -** Thoughts --fomit-frame-pointer - -** TS_HEX - diff --git a/bsl/cxxtest/Versions b/bsl/cxxtest/Versions deleted file mode 100755 index b35cba20ab60b073cd0c79d4dafed1413bd6d036..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/Versions +++ /dev/null @@ -1,152 +0,0 @@ -CxxTest Releases -================ - -Version 3.10.1 (2004-12-01): ----------------------------- - - Improved support for VC7 - - Fixed clash with some versions of STL - -Version 3.10.0 (2004-11-20): ----------------------------- - - Added mock framework for global functions - - Added TS_ASSERT_THROWS_ASSERT and TS_ASSERT_THROWS_EQUALS - - Added CXXTEST_ENUM_TRAITS - - Improved support for STL classes (vector, map etc.) - - Added support for Digital Mars compiler - - Reduced root/part compilation time and binary size - - Support C++-style commenting of tests - -Version 3.9.1 (2004-01-19): ---------------------------- - - Fixed small bug with runner exit code - - Embedded test suites are now deprecated - -Version 3.9.0 (2004-01-17): ---------------------------- - - Added TS_TRACE - - Added --no-static-init - - CxxTest::setAbortTestOnFail() works even without --abort-on-fail - -Version 3.8.5 (2004-01-08): ---------------------------- - - Added --no-eh - - Added CxxTest::setAbortTestOnFail() and CXXTEST_DEFAULT_ABORT - - Added CxxTest::setMaxDumpSize() - - Added StdioFilePrinter - -Version 3.8.4 (2003-12-31): ---------------------------- - - Split distribution into cxxtest and cxxtest-selftest - - Added `sample/msvc/FixFiles.bat' - -Version 3.8.3 (2003-12-24): ---------------------------- - - Added TS_ASSERT_PREDICATE - - Template files can now specify where to insert the preamble - - Added a sample Visual Studio workspace in `sample/msvc' - - Can compile in MSVC with warning level 4 - - Changed output format slightly - -Version 3.8.1 (2003-12-21): ---------------------------- - - Fixed small bug when using multiple --part files. - - Fixed X11 GUI crash when there's no X server. - - Added GlobalFixture::setUpWorld()/tearDownWorld() - - Added leaveOnly(), activateAllTests() and `sample/only.tpl' - - Should now run without warnings on Sun compiler. - -Version 3.8.0 (2003-12-13): ---------------------------- - - Fixed bug where `Root.cpp' needed exception handling - - Added TS_ASSERT_RELATION - - TSM_ macros now also tell you what went wrong - - Renamed Win32Gui::free() to avoid clashes - - Now compatible with more versions of Borland compiler - - Improved the documentation - -Version 3.7.1 (2003-09-29): ---------------------------- - - Added --version - - Compiles with even more exotic g++ warnings - - Win32 Gui compiles with UNICODE - - Should compile on some more platforms (Sun Forte, HP aCC) - -Version 3.7.0 (2003-09-20): ---------------------------- - - Added TS_ASSERT_LESS_THAN_EQUALS - - Minor cleanups - -Version 3.6.1 (2003-09-15): ---------------------------- - - Improved QT GUI - - Improved portability some more - -Version 3.6.0 (2003-09-04): ---------------------------- - - Added --longlong - - Some portability improvements - -Version 3.5.1 (2003-09-03): ---------------------------- - - Major internal rewrite of macros - - Added TS_ASSERT_SAME_DATA - - Added --include option - - Added --part and --root to enable splitting the test runner - - Added global fixtures - - Enhanced Win32 GUI with timers, -keep and -title - - Now compiles with strict warnings - -Version 3.1.1 (2003-08-27): ---------------------------- - - Fixed small bug in TS_ASSERT_THROWS_*() - -Version 3.1.0 (2003-08-23): ---------------------------- - - Default ValueTraits now dumps value as hex bytes - - Fixed double invocation bug (e.g. TS_FAIL(functionWithSideEffects())) - - TS_ASSERT_THROWS*() are now "abort on fail"-friendly - - Win32 GUI now supports Windows 98 and doesn't need comctl32.lib - -Version 3.0.1 (2003-08-07): ---------------------------- - - Added simple GUI for X11, Win32 and Qt - - Added TS_WARN() macro - - Removed --exit-code - - Improved samples - - Improved support for older (pre-std::) compilers - - Made a PDF version of the User's Guide - -Version 2.8.4 (2003-07-21): ---------------------------- - - Now supports g++-3.3 - - Added --have-eh - - Fixed bug in numberToString() - -Version 2.8.3 (2003-06-30): ---------------------------- - - Fixed bugs in cxxtestgen.pl - - Fixed warning for some compilers in ErrorPrinter/StdioPrinter - - Thanks Martin Jost for pointing out these problems! - -Version 2.8.2 (2003-06-10): ---------------------------- - - Fixed bug when using CXXTEST_ABORT_TEST_ON_FAIL without standard library - - Added CXXTEST_USER_TRAITS - - Added --abort-on-fail - -Version 2.8.1 (2003-01-16): ---------------------------- - - Fixed charToString() for negative chars - -Version 2.8.0 (2003-01-13): ---------------------------- - - Added CXXTEST_ABORT_TEST_ON_FAIL for xUnit-like behaviour - - Added `sample/winddk' - - Improved ValueTraits - - Improved output formatter - - Started version history - -Version 2.7.0 (2002-09-29): ---------------------------- - - Added embedded test suites - - Major internal improvements diff --git a/bsl/cxxtest/comtest.h b/bsl/cxxtest/comtest.h deleted file mode 100644 index bf519939349d11215d3f083fe285e6b2100ea910..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/comtest.h +++ /dev/null @@ -1,77 +0,0 @@ -typedef struct _comtest_sysinfo { - char vmsize[10]; - char vmlock[10]; - char vmstat[10]; - char vmdata[10]; - char vmstk[10]; - char vmexe[10]; - char vmlib[10]; -} comtest_sysinfo; - -typedef enum _comtest_systype { - vmsize = 0, - vmlock, - vmstat, - vmdata, - vmstk, - vmexe, - vmlib, - vmend -} comtest_systype; - - -int getsysinfo(comtest_sysinfo *sysinfo) -{ - int procid; - procid = getpid(); - FILE *fp; - char memfile[100]; - char strinfo[vmend][10] = {"VmSize", "VmLock", "VmStat", "VmData", "VmStk", "VmExe", "VmLib"}; - char buff[100], *tmp; - - sprintf(memfile, "/proc/%d/status", procid); - fp = fopen(memfile, "r"); - if (fp == NULL) - return -1; - while (fgets(buff, 100, fp)) - { - for (int i=0; ivmsize, "%s", tmp); - break; - case 1: - sprintf(sysinfo->vmlock, "%s", tmp); - break; - case 2: - sprintf(sysinfo->vmstat, "%s", tmp); - break; - case 3: - sprintf(sysinfo->vmdata, "%s", tmp); - break; - case 4: - sprintf(sysinfo->vmstk, "%s", tmp); - break; - case 5: - sprintf(sysinfo->vmexe, "%s", tmp); - break; - case 6: - sprintf(sysinfo->vmlib, "%s", tmp); - break; - default : - break; - } - break; - } - } - - fclose(fp); - return 1; -} - diff --git a/bsl/cxxtest/cxxtest.spec b/bsl/cxxtest/cxxtest.spec deleted file mode 100755 index 0f1ded6c534a8f5882cfc6b64b012a3dda225b5b..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest.spec +++ /dev/null @@ -1,40 +0,0 @@ -Name: cxxtest -Summary: CxxTest Testing Framework for C++ -Version: 3.10.1 -Release: 1 -Copyright: LGPL -Group: Development/C++ -Source: cxxtest-%{version}.tar.gz -BuildRoot: /tmp/cxxtest-build -BuildArch: noarch -Prefix: /usr - -%description -CxxTest is a JUnit/CppUnit/xUnit-like framework for C++. -Its advantages over existing alternatives are that it: - - Doesn't require RTTI - - Doesn't require member template functions - - Doesn't require exception handling - - Doesn't require any external libraries (including memory management, - file/console I/O, graphics libraries) - -%prep -%setup -n cxxtest - -%build - -%install -install -m 755 -d $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/usr/include/cxxtest -install -m 755 cxxtestgen.p[ly] $RPM_BUILD_ROOT/usr/bin/ -install -m 644 cxxtest/* $RPM_BUILD_ROOT/usr/include/cxxtest/ - -%clean -rm -rf $RPM_BUILD_ROOT - -%files -%attr(-, root, root) %doc README -%attr(-, root, root) %doc sample -%attr(-, root, root) /usr/include/cxxtest -%attr(-, root, root) /usr/bin/cxxtestgen.pl -%attr(-, root, root) /usr/bin/cxxtestgen.py - diff --git a/bsl/cxxtest/cxxtest/Descriptions.cpp b/bsl/cxxtest/cxxtest/Descriptions.cpp deleted file mode 100755 index 143f8f8fd82536d6e07698bf6644d7b9a653866e..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Descriptions.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __cxxtest__Descriptions_cpp__ -#define __cxxtest__Descriptions_cpp__ - -#include - -namespace CxxTest -{ - TestDescription::~TestDescription() {} - SuiteDescription::~SuiteDescription() {} - WorldDescription::~WorldDescription() {} - - // - // Convert total tests to string - // -#ifndef _CXXTEST_FACTOR - char *WorldDescription::strTotalTests( char *s ) const - { - numberToString( numTotalTests(), s ); - return s; - } -#else // _CXXTEST_FACTOR - char *WorldDescription::strTotalTests( char *s ) const - { - char *p = numberToString( numTotalTests(), s ); - - if ( numTotalTests() <= 1 ) - return s; - - unsigned n = numTotalTests(); - unsigned numFactors = 0; - - for ( unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2 ) { - unsigned power; - - for ( power = 0; (n % factor) == 0; n /= factor ) - ++ power; - - if ( !power ) - continue; - - p = numberToString( factor, copyString( p, (numFactors == 0) ? " = " : " * " ) ); - if ( power > 1 ) - p = numberToString( power, copyString( p, "^" ) ); - ++ numFactors; - } - - if ( n > 1 ) { - if ( !numFactors ) - copyString( p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)" ); - else - numberToString( n, copyString( p, " * " ) ); - } - return s; - } -#endif // _CXXTEST_FACTOR -}; - -#endif // __cxxtest__Descriptions_cpp__ diff --git a/bsl/cxxtest/cxxtest/Descriptions.h b/bsl/cxxtest/cxxtest/Descriptions.h deleted file mode 100755 index bd373ec76229a1e285d0eea61d6e1094a94c7dce..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Descriptions.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __cxxtest__Descriptions_h__ -#define __cxxtest__Descriptions_h__ - -// -// TestDescription, SuiteDescription and WorldDescription -// hold information about tests so they can be run and reported. -// - -#include - -namespace CxxTest -{ - class TestSuite; - - class TestDescription : public Link - { - public: - virtual ~TestDescription(); - - virtual const char *file() const = 0; - virtual unsigned line() const = 0; - virtual const char *testName() const = 0; - virtual const char *suiteName() const = 0; - - virtual void run() = 0; - - virtual const TestDescription *next() const = 0; - virtual TestDescription *next() = 0; - }; - - class SuiteDescription : public Link - { - public: - virtual ~SuiteDescription(); - - virtual const char *file() const = 0; - virtual unsigned line() const = 0; - virtual const char *suiteName() const = 0; - virtual TestSuite *suite() const = 0; - - virtual unsigned numTests() const = 0; - virtual const TestDescription &testDescription( unsigned /*i*/ ) const = 0; - - virtual TestDescription *firstTest() = 0; - virtual const TestDescription *firstTest() const = 0; - virtual SuiteDescription *next() = 0; - virtual const SuiteDescription *next() const = 0; - - virtual void activateAllTests() = 0; - virtual bool leaveOnly( const char * /*testName*/ ) = 0; - }; - - class WorldDescription : public Link - { - public: - virtual ~WorldDescription(); - - virtual unsigned numSuites( void ) const = 0; - virtual unsigned numTotalTests( void ) const = 0; - virtual const SuiteDescription &suiteDescription( unsigned /*i*/ ) const = 0; - - enum { MAX_STRLEN_TOTAL_TESTS = 32 }; - char *strTotalTests( char * /*buffer*/ ) const; - - virtual SuiteDescription *firstSuite() = 0; - virtual const SuiteDescription *firstSuite() const = 0; - - virtual void activateAllTests() = 0; - virtual bool leaveOnly( const char * /*suiteName*/, const char * /*testName*/ = 0 ) = 0; - }; -} - -#endif // __cxxtest__Descriptions_h__ - diff --git a/bsl/cxxtest/cxxtest/DummyDescriptions.cpp b/bsl/cxxtest/cxxtest/DummyDescriptions.cpp deleted file mode 100755 index c862e439d8a1f1d50588fe593c44a8300138779f..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/DummyDescriptions.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include - -namespace CxxTest -{ - DummyTestDescription::DummyTestDescription() {} - - const char *DummyTestDescription::file() const { return ""; } - unsigned DummyTestDescription::line() const { return 0; } - const char *DummyTestDescription::testName() const { return ""; } - const char *DummyTestDescription::suiteName() const { return ""; } - bool DummyTestDescription::setUp() { return true;} - void DummyTestDescription::run() {} - bool DummyTestDescription::tearDown() { return true;} - - TestDescription *DummyTestDescription::next() { return 0; } - const TestDescription *DummyTestDescription::next() const { return 0; } - - DummySuiteDescription::DummySuiteDescription() : _test() {} - - const char *DummySuiteDescription::file() const { return ""; } - unsigned DummySuiteDescription::line() const { return 0; } - const char *DummySuiteDescription::suiteName() const { return ""; } - TestSuite *DummySuiteDescription::suite() const { return 0; } - unsigned DummySuiteDescription::numTests() const { return 0; } - const TestDescription &DummySuiteDescription::testDescription( unsigned ) const { return _test; } - SuiteDescription *DummySuiteDescription::next() { return 0; } - TestDescription *DummySuiteDescription::firstTest() { return 0; } - const SuiteDescription *DummySuiteDescription::next() const { return 0; } - const TestDescription *DummySuiteDescription::firstTest() const { return 0; } - void DummySuiteDescription::activateAllTests() {} - bool DummySuiteDescription::leaveOnly( const char * /*testName*/ ) { return false; } - - bool DummySuiteDescription::setUp() { return true;} - bool DummySuiteDescription::tearDown() { return true;} - - DummyWorldDescription::DummyWorldDescription() : _suite() {} - - unsigned DummyWorldDescription::numSuites( void ) const { return 0; } - unsigned DummyWorldDescription::numTotalTests( void ) const { return 0; } - const SuiteDescription &DummyWorldDescription::suiteDescription( unsigned ) const { return _suite; } - SuiteDescription *DummyWorldDescription::firstSuite() { return 0; } - const SuiteDescription *DummyWorldDescription::firstSuite() const { return 0; } - void DummyWorldDescription::activateAllTests() {} - bool DummyWorldDescription::leaveOnly( const char * /*suiteName*/, const char * /*testName*/ ) { return false; } - - bool DummyWorldDescription::setUp() { return true;} - bool DummyWorldDescription::tearDown() { return true;} -} - diff --git a/bsl/cxxtest/cxxtest/DummyDescriptions.h b/bsl/cxxtest/cxxtest/DummyDescriptions.h deleted file mode 100755 index c9215d125f9ee4fd04e5165f596d56d56873dc44..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/DummyDescriptions.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef __cxxtest__DummyDescriptions_h__ -#define __cxxtest__DummyDescriptions_h__ - -// -// DummyTestDescription, DummySuiteDescription and DummyWorldDescription -// - -#include - -namespace CxxTest -{ - class DummyTestDescription : public TestDescription - { - public: - DummyTestDescription(); - - const char *file() const; - unsigned line() const; - const char *testName() const; - const char *suiteName() const; - bool setUp(); - void run(); - bool tearDown(); - - TestDescription *next(); - const TestDescription *next() const; - }; - - class DummySuiteDescription : public SuiteDescription - { - public: - DummySuiteDescription(); - - const char *file() const; - unsigned line() const; - const char *suiteName() const; - TestSuite *suite() const; - unsigned numTests() const; - const TestDescription &testDescription( unsigned ) const; - SuiteDescription *next(); - TestDescription *firstTest(); - const SuiteDescription *next() const; - const TestDescription *firstTest() const; - void activateAllTests(); - bool leaveOnly( const char * /*testName*/ ); - - bool setUp(); - bool tearDown(); - - private: - DummyTestDescription _test; - }; - - class DummyWorldDescription : public WorldDescription - { - public: - DummyWorldDescription(); - - unsigned numSuites( void ) const; - unsigned numTotalTests( void ) const; - const SuiteDescription &suiteDescription( unsigned ) const; - SuiteDescription *firstSuite(); - const SuiteDescription *firstSuite() const; - void activateAllTests(); - bool leaveOnly( const char * /*suiteName*/, const char * /*testName*/ = 0 ); - - bool setUp(); - bool tearDown(); - - private: - DummySuiteDescription _suite; - }; -} - -#endif // __cxxtest__DummyDescriptions_h__ - diff --git a/bsl/cxxtest/cxxtest/ErrorFormatter.h b/bsl/cxxtest/cxxtest/ErrorFormatter.h deleted file mode 100755 index 968c310c2a6a0a28f00a1669c3a03a558904720c..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/ErrorFormatter.h +++ /dev/null @@ -1,281 +0,0 @@ -#ifndef __cxxtest__ErrorFormatter_h__ -#define __cxxtest__ErrorFormatter_h__ - -// -// The ErrorFormatter is a TestListener that -// prints reports of the errors to an output -// stream. Since we cannot rely ou the standard -// iostreams, this header defines a base class -// analogout to std::ostream. -// - -#include -#include -#include -#include - -namespace CxxTest -{ - class OutputStream - { - public: - virtual ~OutputStream() {} - virtual void flush() {}; - virtual OutputStream &operator<<( unsigned /*number*/ ) { return *this; } - virtual OutputStream &operator<<( const char * /*string*/ ) { return *this; } - - typedef void (*Manipulator)( OutputStream & ); - - virtual OutputStream &operator<<( Manipulator m ) { m( *this ); return *this; } - static void endl( OutputStream &o ) { (o << "\n").flush(); } - }; - - class ErrorFormatter : public TestListener - { - public: - ErrorFormatter( OutputStream *o, const char *preLine = ":", const char *postLine = "" ) : - _dotting( true ), - _reported( false ), - _o(o), - _preLine(preLine), - _postLine(postLine) - { - } - - int run() - { - TestRunner::runAllTests( *this ); - return tracker().failedTests(); - } - - void enterWorld( const WorldDescription & /*desc*/ ) - { - (*_o) << "Running " << totalTests; - _o->flush(); - _dotting = true; - _reported = false; - } - - static void totalTests( OutputStream &o ) - { - char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS]; - const WorldDescription &wd = tracker().world(); - o << wd.strTotalTests( s ) << (wd.numTotalTests() == 1 ? " test" : " tests"); - } - - void enterSuite( const SuiteDescription & ) - { - _reported = false; - } - - void enterTest( const TestDescription & ) - { - _reported = false; - } - - void leaveTest( const TestDescription & ) - { - if ( !tracker().testFailed() ) { - ((*_o) << ".").flush(); - _dotting = true; - } - } - - void leaveWorld( const WorldDescription &desc ) - { - if ( !tracker().failedTests() ) { - (*_o) << "OK!" << endl; - return; - } - newLine(); - (*_o) << "Failed " << tracker().failedTests() << " of " << totalTests << endl; - unsigned numPassed = desc.numTotalTests() - tracker().failedTests(); - (*_o) << "Success rate: " << (numPassed * 100 / desc.numTotalTests()) << "%" << endl; - } - - void trace( const char *file, unsigned line, const char *expression ) - { - stop( file, line ) << "Trace: " << - expression << endl; - } - - void warning( const char *file, unsigned line, const char *expression ) - { - stop( file, line ) << "Warning: " << - expression << endl; - } - - void failedTest( const char *file, unsigned line, const char *expression ) - { - stop( file, line ) << "Error: Test failed: " << - expression << endl; - } - - void failedAssert( const char *file, unsigned line, const char *expression ) - { - stop( file, line ) << "Error: Assertion failed: " << - expression << endl; - } - - void failedAssertEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - stop( file, line ) << "Error: Expected (" << - xStr << " == " << yStr << "), found (" << - x << " != " << y << ")" << endl; - } - - void failedAssertSameData( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *sizeStr, const void *x, - const void *y, unsigned size ) - { - stop( file, line ) << "Error: Expected " << sizeStr << " (" << size << ") bytes to be equal at (" << - xStr << ") and (" << yStr << "), found:" << endl; - dump( x, size ); - (*_o) << " differs from" << endl; - dump( y, size ); - } - - void failedAssertDelta( const char *file, unsigned line, - const char *xStr, const char *yStr, const char *dStr, - const char *x, const char *y, const char *d ) - { - stop( file, line ) << "Error: Expected (" << - xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" << - x << " != " << y << ")" << endl; - } - - void failedAssertDiffers( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *value ) - { - stop( file, line ) << "Error: Expected (" << - xStr << " != " << yStr << "), found (" << - value << ")" << endl; - } - - void failedAssertLessThan( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - stop( file, line ) << "Error: Expected (" << - xStr << " < " << yStr << "), found (" << - x << " >= " << y << ")" << endl; - } - - void failedAssertLessThanEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - stop( file, line ) << "Error: Expected (" << - xStr << " <= " << yStr << "), found (" << - x << " > " << y << ")" << endl; - } - - void failedAssertRelation( const char *file, unsigned line, - const char *relation, const char *xStr, const char *yStr, - const char *x, const char *y ) - { - stop( file, line ) << "Error: Expected " << relation << "( " << - xStr << ", " << yStr << " ), found !" << relation << "( " << x << ", " << y << " )" << endl; - } - - void failedAssertPredicate( const char *file, unsigned line, - const char *predicate, const char *xStr, const char *x ) - { - stop( file, line ) << "Error: Expected " << predicate << "( " << - xStr << " ), found !" << predicate << "( " << x << " )" << endl; - } - - void failedAssertThrows( const char *file, unsigned line, - const char *expression, const char *type, - bool otherThrown ) - { - stop( file, line ) << "Error: Expected (" << expression << ") to throw (" << - type << ") but it " << (otherThrown ? "threw something else" : "didn't throw") << - endl; - } - - void failedAssertThrowsNot( const char *file, unsigned line, const char *expression ) - { - stop( file, line ) << "Error: Expected (" << expression << ") not to throw, but it did" << - endl; - } - - protected: - OutputStream *outputStream() const - { - return _o; - } - - private: - ErrorFormatter( const ErrorFormatter & ); - ErrorFormatter &operator=( const ErrorFormatter & ); - - OutputStream &stop( const char *file, unsigned line ) - { - newLine(); - reportTest(); - return (*_o) << file << _preLine << line << _postLine << ": "; - } - - void newLine( void ) - { - if ( _dotting ) { - (*_o) << endl; - _dotting = false; - } - } - - void reportTest( void ) - { - if( _reported ) - return; - (*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl; - _reported = true; - } - - void dump( const void *buffer, unsigned size ) - { - if ( !buffer ) - dumpNull(); - else - dumpBuffer( buffer, size ); - } - - void dumpNull() - { - (*_o) << " (null)" << endl; - } - - void dumpBuffer( const void *buffer, unsigned size ) - { - unsigned dumpSize = size; - if ( maxDumpSize() && dumpSize > maxDumpSize() ) - dumpSize = maxDumpSize(); - - const unsigned char *p = (const unsigned char *)buffer; - (*_o) << " { "; - for ( unsigned i = 0; i < dumpSize; ++ i ) - (*_o) << byteToHex( *p++ ) << " "; - if ( dumpSize < size ) - (*_o) << "... "; - (*_o) << "}" << endl; - } - - static void endl( OutputStream &o ) - { - OutputStream::endl( o ); - } - - bool _dotting; - bool _reported; - OutputStream *_o; - const char *_preLine; - const char *_postLine; - }; -}; - -#endif // __cxxtest__ErrorFormatter_h__ diff --git a/bsl/cxxtest/cxxtest/ErrorPrinter.h b/bsl/cxxtest/cxxtest/ErrorPrinter.h deleted file mode 100755 index 53d942532bf4a52c2deaff0edb65cbfc2d83fd27..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/ErrorPrinter.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __cxxtest__ErrorPrinter_h__ -#define __cxxtest__ErrorPrinter_h__ - -// -// The ErrorPrinter is a simple TestListener that -// just prints "OK" if everything goes well, otherwise -// reports the error in the format of compiler messages. -// The ErrorPrinter uses std::cout -// - -#include - -#ifndef _CXXTEST_HAVE_STD -# define _CXXTEST_HAVE_STD -#endif // _CXXTEST_HAVE_STD - -#include -#include - -#ifdef _CXXTEST_OLD_STD -# include -#else // !_CXXTEST_OLD_STD -# include -#endif // _CXXTEST_OLD_STD - -namespace CxxTest -{ - class ErrorPrinter : public ErrorFormatter - { - public: - ErrorPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "" ) : - ErrorFormatter( new Adapter(o), preLine, postLine ) {} - virtual ~ErrorPrinter() { delete outputStream(); } - - private: - class Adapter : public OutputStream - { - CXXTEST_STD(ostream) &_o; - public: - Adapter( CXXTEST_STD(ostream) &o ) : _o(o) {} - void flush() { _o.flush(); } - OutputStream &operator<<( const char *s ) { _o << s; return *this; } - OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); } - OutputStream &operator<<( unsigned i ) - { - char s[1 + 3 * sizeof(unsigned)]; - numberToString( i, s ); - _o << s; - return *this; - } - }; - }; -} - -#endif // __cxxtest__ErrorPrinter_h__ diff --git a/bsl/cxxtest/cxxtest/Flags.h b/bsl/cxxtest/cxxtest/Flags.h deleted file mode 100755 index be2f9f28850337124b7325d21ac67d3054fb5b54..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Flags.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef __cxxtest__Flags_h__ -#define __cxxtest__Flags_h__ - -// -// These are the flags that control CxxTest -// - -#if !defined(CXXTEST_FLAGS) -# define CXXTEST_FLAGS -#endif // !CXXTEST_FLAGS - -#if defined(CXXTEST_HAVE_EH) && !defined(_CXXTEST_HAVE_EH) -# define _CXXTEST_HAVE_EH -#endif // CXXTEST_HAVE_EH - -#if defined(CXXTEST_HAVE_STD) && !defined(_CXXTEST_HAVE_STD) -# define _CXXTEST_HAVE_STD -#endif // CXXTEST_HAVE_STD - -#if defined(CXXTEST_OLD_TEMPLATE_SYNTAX) && !defined(_CXXTEST_OLD_TEMPLATE_SYNTAX) -# define _CXXTEST_OLD_TEMPLATE_SYNTAX -#endif // CXXTEST_OLD_TEMPLATE_SYNTAX - -#if defined(CXXTEST_OLD_STD) && !defined(_CXXTEST_OLD_STD) -# define _CXXTEST_OLD_STD -#endif // CXXTEST_OLD_STD - -#if defined(CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_ABORT_TEST_ON_FAIL) -# define _CXXTEST_ABORT_TEST_ON_FAIL -#endif // CXXTEST_ABORT_TEST_ON_FAIL - -#if defined(CXXTEST_NO_COPY_CONST) && !defined(_CXXTEST_NO_COPY_CONST) -# define _CXXTEST_NO_COPY_CONST -#endif // CXXTEST_NO_COPY_CONST - -#if defined(CXXTEST_FACTOR) && !defined(_CXXTEST_FACTOR) -# define _CXXTEST_FACTOR -#endif // CXXTEST_FACTOR - -#if defined(CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION) && !defined(_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION) -# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -#endif // CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION - -#if defined(CXXTEST_LONGLONG) -# if defined(_CXXTEST_LONGLONG) -# undef _CXXTEST_LONGLONG -# endif -# define _CXXTEST_LONGLONG CXXTEST_LONGLONG -#endif // CXXTEST_LONGLONG - -#ifndef CXXTEST_MAX_DUMP_SIZE -# define CXXTEST_MAX_DUMP_SIZE 0 -#endif // CXXTEST_MAX_DUMP_SIZE - -#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(CXXTEST_DEFAULT_ABORT) -# define CXXTEST_DEFAULT_ABORT true -#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !CXXTEST_DEFAULT_ABORT - -#if !defined(CXXTEST_DEFAULT_ABORT) -# define CXXTEST_DEFAULT_ABORT false -#endif // !CXXTEST_DEFAULT_ABORT - -#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_HAVE_EH) -# warning "CXXTEST_ABORT_TEST_ON_FAIL is meaningless without CXXTEST_HAVE_EH" -# undef _CXXTEST_ABORT_TEST_ON_FAIL -#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !_CXXTEST_HAVE_EH - -// -// Some minimal per-compiler configuration to allow us to compile -// - -#ifdef __BORLANDC__ -# if __BORLANDC__ <= 0x520 // Borland C++ 5.2 or earlier -# ifndef _CXXTEST_OLD_STD -# define _CXXTEST_OLD_STD -# endif -# ifndef _CXXTEST_OLD_TEMPLATE_SYNTAX -# define _CXXTEST_OLD_TEMPLATE_SYNTAX -# endif -# endif -# if __BORLANDC__ >= 0x540 // C++ Builder 4.0 or later -# ifndef _CXXTEST_NO_COPY_CONST -# define _CXXTEST_NO_COPY_CONST -# endif -# ifndef _CXXTEST_LONGLONG -# define _CXXTEST_LONGLONG __int64 -# endif -# endif -#endif // __BORLANDC__ - -#ifdef _MSC_VER // Visual C++ -# ifndef _CXXTEST_LONGLONG -# define _CXXTEST_LONGLONG __int64 -# endif -# if (_MSC_VER >= 0x51E) -# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -# endif -# endif -# pragma warning( disable : 4127 ) -# pragma warning( disable : 4290 ) -# pragma warning( disable : 4511 ) -# pragma warning( disable : 4512 ) -# pragma warning( disable : 4514 ) -#endif // _MSC_VER - -#ifdef __GNUC__ -# if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9) -# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -# endif -# endif -#endif // __GNUC__ - -#ifdef __DMC__ // Digital Mars -# ifndef _CXXTEST_OLD_STD -# define _CXXTEST_OLD_STD -# endif -#endif - -#endif // __cxxtest__Flags_h__ diff --git a/bsl/cxxtest/cxxtest/GlobalFixture.cpp b/bsl/cxxtest/cxxtest/GlobalFixture.cpp deleted file mode 100755 index 29c6ab83a6269a17d7dc305fb9a717cd397af59c..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/GlobalFixture.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __cxxtest__GlobalFixture_cpp__ -#define __cxxtest__GlobalFixture_cpp__ - -#include - -namespace CxxTest -{ - bool GlobalFixture::setUpWorld() { return true; } - bool GlobalFixture::tearDownWorld() { return true; } - bool GlobalFixture::setUp() { return true; } - bool GlobalFixture::tearDown() { return true; } - - GlobalFixture::GlobalFixture() { attach( _list ); } - GlobalFixture::~GlobalFixture() { detach( _list ); } - - GlobalFixture *GlobalFixture::firstGlobalFixture() { return (GlobalFixture *)_list.head(); } - GlobalFixture *GlobalFixture::lastGlobalFixture() { return (GlobalFixture *)_list.tail(); } - GlobalFixture *GlobalFixture::nextGlobalFixture() { return (GlobalFixture *)next(); } - GlobalFixture *GlobalFixture::prevGlobalFixture() { return (GlobalFixture *)prev(); } -} - -#endif // __cxxtest__GlobalFixture_cpp__ - diff --git a/bsl/cxxtest/cxxtest/GlobalFixture.h b/bsl/cxxtest/cxxtest/GlobalFixture.h deleted file mode 100755 index c8173633f6f3ae638e6889d02a7f9ec7b03d90d8..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/GlobalFixture.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __cxxtest__GlobalFixture_h__ -#define __cxxtest__GlobalFixture_h__ - -#include - -namespace CxxTest -{ - class GlobalFixture : public Link - { - public: - virtual bool setUpWorld(); - virtual bool tearDownWorld(); - virtual bool setUp(); - virtual bool tearDown(); - - GlobalFixture(); - ~GlobalFixture(); - - static GlobalFixture *firstGlobalFixture(); - static GlobalFixture *lastGlobalFixture(); - GlobalFixture *nextGlobalFixture(); - GlobalFixture *prevGlobalFixture(); - - private: - static List _list; - }; -} - -#endif // __cxxtest__GlobalFixture_h__ - diff --git a/bsl/cxxtest/cxxtest/Gui.h b/bsl/cxxtest/cxxtest/Gui.h deleted file mode 100755 index ac53b298f56ed8d5569b78f9b2ec3239d9655a44..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Gui.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef __CXXTEST__GUI_H -#define __CXXTEST__GUI_H - -// -// GuiListener is a simple base class for the differes GUIs -// GuiTuiRunner combines a GUI with a text-mode error formatter -// - -#include - -namespace CxxTest -{ - class GuiListener : public TestListener - { - public: - GuiListener() : _state( GREEN_BAR ) {} - virtual ~GuiListener() {} - - virtual void runGui( int &argc, char **argv, TestListener &listener ) - { - enterGui( argc, argv ); - TestRunner::runAllTests( listener ); - leaveGui(); - } - - virtual void enterGui( int & /*argc*/, char ** /*argv*/ ) {} - virtual void leaveGui() {} - - // - // The easy way is to implement these functions: - // - virtual void guiEnterWorld( unsigned /*numTotalTests*/ ) {} - virtual void guiEnterSuite( const char * /*suiteName*/ ) {} - virtual void guiEnterTest( const char * /*suiteName*/, const char * /*testName*/ ) {} - virtual void yellowBar() {} - virtual void redBar() {} - - // - // The hard way is this: - // - void enterWorld( const WorldDescription &d ) { guiEnterWorld( d.numTotalTests() ); } - void enterSuite( const SuiteDescription &d ) { guiEnterSuite( d.suiteName() ); } - void enterTest( const TestDescription &d ) { guiEnterTest( d.suiteName(), d.testName() ); } - void leaveTest( const TestDescription & ) {} - void leaveSuite( const SuiteDescription & ) {} - void leaveWorld( const WorldDescription & ) {} - - void warning( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) - { - yellowBarSafe(); - } - - void failedTest( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) - { - redBarSafe(); - } - - void failedAssert( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) - { - redBarSafe(); - } - - void failedAssertEquals( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) - { - redBarSafe(); - } - - void failedAssertSameData( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*sizeStr*/, const void * /*x*/, - const void * /*y*/, unsigned /*size*/ ) - { - redBarSafe(); - } - - void failedAssertDelta( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, const char * /*dStr*/, - const char * /*x*/, const char * /*y*/, const char * /*d*/ ) - { - redBarSafe(); - } - - void failedAssertDiffers( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*value*/ ) - { - redBarSafe(); - } - - void failedAssertLessThan( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) - { - redBarSafe(); - } - - void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) - { - redBarSafe(); - } - - void failedAssertPredicate( const char * /*file*/, unsigned /*line*/, - const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ ) - { - redBarSafe(); - } - - void failedAssertRelation( const char * /*file*/, unsigned /*line*/, - const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) - { - redBarSafe(); - } - - void failedAssertThrows( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/, const char * /*type*/, - bool /*otherThrown*/ ) - { - redBarSafe(); - } - - void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) - { - redBarSafe(); - } - - protected: - void yellowBarSafe() - { - if ( _state < YELLOW_BAR ) { - yellowBar(); - _state = YELLOW_BAR; - } - } - - void redBarSafe() - { - if ( _state < RED_BAR ) { - redBar(); - _state = RED_BAR; - } - } - - private: - enum { GREEN_BAR, YELLOW_BAR, RED_BAR } _state; - }; - - template - class GuiTuiRunner : public TeeListener - { - int &_argc; - char **_argv; - GuiT _gui; - TuiT _tui; - - public: - GuiTuiRunner( int &argc, char **argv ) : - _argc( argc ), - _argv( argv ) - { - setFirst( _gui ); - setSecond( _tui ); - } - - int run() - { - _gui.runGui( _argc, _argv, *this ); - return tracker().failedTests(); - } - }; -}; - -#endif //__CXXTEST__GUI_H diff --git a/bsl/cxxtest/cxxtest/LinkedList.cpp b/bsl/cxxtest/cxxtest/LinkedList.cpp deleted file mode 100755 index fb81d64caea3ba3f29022d9abe5f5cf612a370b1..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/LinkedList.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef __cxxtest__LinkedList_cpp__ -#define __cxxtest__LinkedList_cpp__ - -#include - -namespace CxxTest -{ - List GlobalFixture::_list = { 0, 0 }; - List RealSuiteDescription::_suites = { 0, 0 }; - - void List::initialize() - { - _head = _tail = 0; - } - - Link *List::head() - { - Link *l = _head; - while ( l && !l->active() ) - l = l->next(); - return l; - } - - const Link *List::head() const - { - Link *l = _head; - while ( l && !l->active() ) - l = l->next(); - return l; - } - - Link *List::tail() - { - Link *l = _tail; - while ( l && !l->active() ) - l = l->prev(); - return l; - } - - const Link *List::tail() const - { - Link *l = _tail; - while ( l && !l->active() ) - l = l->prev(); - return l; - } - - bool List::empty() const - { - return (_head == 0); - } - - unsigned List::size() const - { - unsigned count = 0; - for ( const Link *l = head(); l != 0; l = l->next() ) - ++ count; - return count; - } - - Link *List::nth( unsigned n ) - { - Link *l = head(); - while ( n -- ) - l = l->next(); - return l; - } - - void List::activateAll() - { - for ( Link *l = _head; l != 0; l = l->justNext() ) - l->setActive( true ); - } - - void List::leaveOnly( const Link &link ) - { - for ( Link *l = head(); l != 0; l = l->next() ) - if ( l != &link ) - l->setActive( false ); - } - - Link::Link() : - _next( 0 ), - _prev( 0 ), - _active( true ) - { - } - - Link::~Link() - { - } - - bool Link::active() const - { - return _active; - } - - void Link::setActive( bool value ) - { - _active = value; - } - - Link * Link::justNext() - { - return _next; - } - - Link * Link::justPrev() - { - return _prev; - } - - Link * Link::next() - { - Link *l = _next; - while ( l && !l->_active ) - l = l->_next; - return l; - } - - Link * Link::prev() - { - Link *l = _prev; - while ( l && !l->_active ) - l = l->_prev; - return l; - } - - const Link * Link::next() const - { - Link *l = _next; - while ( l && !l->_active ) - l = l->_next; - return l; - } - - const Link * Link::prev() const - { - Link *l = _prev; - while ( l && !l->_active ) - l = l->_prev; - return l; - } - - void Link::attach( List &l ) - { - if ( l._tail ) - l._tail->_next = this; - - _prev = l._tail; - _next = 0; - - if ( l._head == 0 ) - l._head = this; - l._tail = this; - } - - void Link::detach( List &l ) - { - if ( _prev ) - _prev->_next = _next; - else - l._head = _next; - - if ( _next ) - _next->_prev = _prev; - else - l._tail = _prev; - } -}; - -#endif // __cxxtest__LinkedList_cpp__ diff --git a/bsl/cxxtest/cxxtest/LinkedList.h b/bsl/cxxtest/cxxtest/LinkedList.h deleted file mode 100755 index 983a6e244cf1fb3d43e69a9172dc6e08b5a85df8..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/LinkedList.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef __cxxtest__LinkedList_h__ -#define __cxxtest__LinkedList_h__ - -#include - -namespace CxxTest -{ - struct List; - class Link; - - struct List - { - Link *_head; - Link *_tail; - - void initialize(); - - Link *head(); - const Link *head() const; - Link *tail(); - const Link *tail() const; - - bool empty() const; - unsigned size() const; - Link *nth( unsigned n ); - - void activateAll(); - void leaveOnly( const Link &link ); - }; - - class Link - { - public: - Link(); - virtual ~Link(); - - bool active() const; - void setActive( bool value = true ); - - Link *justNext(); - Link *justPrev(); - - Link *next(); - Link *prev(); - const Link *next() const; - const Link *prev() const; - - virtual bool setUp() = 0; - virtual bool tearDown() = 0; - - void attach( List &l ); - void detach( List &l ); - - private: - Link *_next; - Link *_prev; - bool _active; - - Link( const Link & ); - Link &operator=( const Link & ); - }; -} - -#endif // __cxxtest__LinkedList_h__ - diff --git a/bsl/cxxtest/cxxtest/Mock.h b/bsl/cxxtest/cxxtest/Mock.h deleted file mode 100755 index 647088e8073fa32dbfcf0020bb85b1acd9d49bce..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Mock.h +++ /dev/null @@ -1,350 +0,0 @@ -#ifndef __cxxtest__Mock_h__ -#define __cxxtest__Mock_h__ - -// -// The default namespace is T:: -// -#ifndef CXXTEST_MOCK_NAMESPACE -# define CXXTEST_MOCK_NAMESPACE T -#endif // CXXTEST_MOCK_NAMESPACE - -// -// MockTraits: What to return when no mock object has been created -// -#define __CXXTEST_MOCK__TRAITS \ - namespace CXXTEST_MOCK_NAMESPACE \ - { \ - template \ - class MockTraits \ - { \ - public: \ - static T defaultValue() { return 0; } \ - }; \ - }; - -// -// extern "C" when needed -// -#ifdef __cplusplus -# define CXXTEST_EXTERN_C extern "C" -#else -# define CXXTEST_EXTERN_C -#endif // __cplusplus - -// -// Prototypes: For "normal" headers -// -#define __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS; } - -#define __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL ) - -#define __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - TYPE REAL ARGS; - -#define __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL ) - -// -// Class declarations: For test files -// -#define __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - class Base_##MOCK : public CxxTest::Link \ - { \ - public: \ - Base_##MOCK(); \ - ~Base_##MOCK(); \ - bool setUp(); \ - bool tearDown(); \ - \ - static Base_##MOCK ¤t(); \ - \ - virtual TYPE NAME ARGS = 0; \ - \ - private: \ - static CxxTest::List _list; \ - }; \ - \ - class Real_##MOCK : public Base_##MOCK \ - { \ - public: \ - TYPE NAME ARGS; \ - }; \ - \ - class _Unimplemented_##MOCK : public Base_##MOCK \ - { \ - public: \ - TYPE NAME ARGS; \ - }; \ - } - -#define __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL ) - -#define __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - class Base_##MOCK : public CxxTest::Link \ - { \ - public: \ - Base_##MOCK(); \ - ~Base_##MOCK(); \ - bool setUp(); \ - bool tearDown(); \ - \ - static Base_##MOCK ¤t(); \ - \ - virtual TYPE NAME ARGS = 0; \ - \ - private: \ - static CxxTest::List _list; \ - }; \ - \ - class _Unimplemented_##MOCK : public Base_##MOCK \ - { \ - public: \ - TYPE NAME ARGS; \ - }; \ - } - -#define __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL ) - -// -// Class implementation: For test source files -// -#define __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - \ - CxxTest::List Base_##MOCK::_list = { 0, 0 }; \ - \ - Base_##MOCK::Base_##MOCK() { attach( _list ); } \ - Base_##MOCK::~Base_##MOCK() { detach( _list ); } \ - bool Base_##MOCK::setUp() { return true; } \ - bool Base_##MOCK::tearDown() { return true; } \ - \ - Base_##MOCK &Base_##MOCK::current() \ - { \ - if ( _list.empty() ) \ - static _Unimplemented_##MOCK unimplemented; \ - return *(Base_##MOCK *)_list.tail(); \ - } \ - } - -#define __CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - TYPE Real_##MOCK::NAME ARGS \ - { \ - return REAL CALL; \ - } \ - \ - TYPE _Unimplemented_##MOCK::NAME ARGS \ - { \ - while ( false ) \ - return NAME CALL; \ - __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \ - return MockTraits::defaultValue(); \ - } \ - \ - TYPE NAME ARGS \ - { \ - return Base_##MOCK::current().NAME CALL; \ - } \ - } - -#define __CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - void Real_##MOCK::NAME ARGS \ - { \ - REAL CALL; \ - } \ - \ - void _Unimplemented_##MOCK::NAME ARGS \ - { \ - while ( false ) \ - NAME CALL; \ - __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \ - } \ - \ - void NAME ARGS \ - { \ - Base_##MOCK::current().NAME CALL; \ - } \ - } - -#define __CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - TYPE _Unimplemented_##MOCK::NAME ARGS \ - { \ - while ( false ) \ - return NAME CALL; \ - __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \ - return MockTraits::defaultValue(); \ - } \ - } \ - \ - TYPE REAL ARGS \ - { \ - return CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \ - } - -#define __CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \ - namespace CXXTEST_MOCK_NAMESPACE { \ - void _Unimplemented_##MOCK::NAME ARGS \ - { \ - while ( false ) \ - NAME CALL; \ - __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \ - } \ - } \ - \ - void REAL ARGS \ - { \ - CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \ - } \ - -// -// Error for calling mock function w/o object -// -#define __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ) \ - TS_FAIL( CXXTEST_MOCK_NAMESPACE_STR #NAME #ARGS " called with no " \ - CXXTEST_MOCK_NAMESPACE_STR "Base_" #NAME " object" ); \ - -#define CXXTEST_MOCK_NAMESPACE_STR __CXXTEST_STR(CXXTEST_MOCK_NAMESPACE) "::" -#define __CXXTEST_STR(X) __CXXTEST_XSTR(X) -#define __CXXTEST_XSTR(X) #X - -#if defined(CXXTEST_MOCK_TEST_SOURCE_FILE) -// -// Test source file: Prototypes, class declarations and implementation -// -#include - -__CXXTEST_MOCK__TRAITS; - -#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) - -#elif defined(CXXTEST_FLAGS) || defined(CXXTEST_RUNNING) -// -// Test file other than source: Prototypes and class declarations -// -#include - -__CXXTEST_MOCK__TRAITS; - -#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) - -#elif defined(CXXTEST_MOCK_REAL_SOURCE_FILE) -// -// Real source file: "Real" implementations -// -#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS { return REAL CALL; } } - -#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - namespace CXXTEST_MOCK_NAMESPACE { void NAME ARGS { REAL CALL; } } - -#else -// -// Ordinary header file: Just prototypes -// - -#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \ - __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) - -#endif // Ordinary header file - -// -// How to supply extern "C" functions -// -#define CXXTEST_SUPPLY_C( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - CXXTEST_EXTERN_C __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \ - CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) - -#define CXXTEST_SUPPLY_VOID_C( MOCK, NAME, ARGS, REAL, CALL ) \ - CXXTEST_EXTERN_C __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \ - CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) - -// -// Usually we mean the global namespace -// -#define CXXTEST_MOCK_GLOBAL( TYPE, NAME, ARGS, CALL ) \ - CXXTEST_MOCK( NAME, TYPE, NAME, ARGS, ::NAME, CALL ) - -#define CXXTEST_MOCK_VOID_GLOBAL( NAME, ARGS, CALL ) \ - CXXTEST_MOCK_VOID( NAME, NAME, ARGS, ::NAME, CALL ) - -#define CXXTEST_SUPPLY_GLOBAL( TYPE, NAME, ARGS, CALL ) \ - CXXTEST_SUPPLY( NAME, TYPE, NAME, ARGS, NAME, CALL ) - -#define CXXTEST_SUPPLY_VOID_GLOBAL( NAME, ARGS, CALL ) \ - CXXTEST_SUPPLY_VOID( NAME, NAME, ARGS, NAME, CALL ) - -#define CXXTEST_SUPPLY_GLOBAL_C( TYPE, NAME, ARGS, CALL ) \ - CXXTEST_SUPPLY_C( NAME, TYPE, NAME, ARGS, NAME, CALL ) - -#define CXXTEST_SUPPLY_VOID_GLOBAL_C( NAME, ARGS, CALL ) \ - CXXTEST_SUPPLY_VOID_C( NAME, NAME, ARGS, NAME, CALL ) - -// -// What to return when no mock object has been created. -// The default value of 0 usually works, but some cases may need this. -// -#define CXXTEST_MOCK_DEFAULT_VALUE( TYPE, VALUE ) \ - namespace CXXTEST_MOCK_NAMESPACE \ - { \ - template<> \ - class MockTraits \ - { \ - public: \ - static TYPE defaultValue() { return VALUE; } \ - }; \ - } - -#endif // __cxxtest__Mock_h__ diff --git a/bsl/cxxtest/cxxtest/ParenPrinter.h b/bsl/cxxtest/cxxtest/ParenPrinter.h deleted file mode 100755 index 9ecf31053289c9ffb630b411197cdd541b1c86e1..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/ParenPrinter.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __cxxtest__ParenPrinter_h__ -#define __cxxtest__ParenPrinter_h__ - -// -// The ParenPrinter is identical to the ErrorPrinter, except it -// prints the line number in a format expected by some compilers -// (notably, MSVC). -// - -#include - -namespace CxxTest -{ - class ParenPrinter : public ErrorPrinter - { - public: - ParenPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout) ) : ErrorPrinter( o, "(", ")" ) {} - }; -} - -#endif // __cxxtest__ParenPrinter_h__ diff --git a/bsl/cxxtest/cxxtest/QtGui.h b/bsl/cxxtest/cxxtest/QtGui.h deleted file mode 100755 index 889825106ab5f49ef35923670abf8074474eb894..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/QtGui.h +++ /dev/null @@ -1,271 +0,0 @@ -#ifndef __cxxtest__QtGui_h__ -#define __cxxtest__QtGui_h__ - -// -// The QtGui displays a simple progress bar using the Qt Toolkit. It -// has been tested with versions 2.x and 3.x. -// -// Apart from normal Qt command-line arguments, it accepts the following options: -// -minimized Start minimized, pop up on error -// -keep Don't close the window at the end -// -title TITLE Set the window caption -// -// If both are -minimized and -keep specified, GUI will only keep the -// window if it's in focus. -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CxxTest -{ - class QtGui : public GuiListener - { - public: - void enterGui( int &argc, char **argv ) - { - parseCommandLine( argc, argv ); - createApplication( argc, argv ); - } - - void enterWorld( const WorldDescription &wd ) - { - createWindow( wd ); - processEvents(); - } - - void guiEnterSuite( const char *suiteName ) - { - showSuiteName( suiteName ); - } - - void guiEnterTest( const char *suiteName, const char *testName ) - { - setCaption( suiteName, testName ); - advanceProgressBar(); - showTestName( testName ); - showTestsDone( _progressBar->progress() ); - processEvents(); - } - - void yellowBar() - { - setColor( 255, 255, 0 ); - setIcon( QMessageBox::Warning ); - getTotalTests(); - processEvents(); - } - - void redBar() - { - if ( _startMinimized && _mainWindow->isMinimized() ) - showNormal(); - setColor( 255, 0, 0 ); - setIcon( QMessageBox::Critical ); - getTotalTests(); - processEvents(); - } - - void leaveGui() - { - if ( keep() ) { - showSummary(); - _application->exec(); - } - else - _mainWindow->close( true ); - } - - private: - QString _title; - bool _startMinimized, _keep; - unsigned _numTotalTests; - QString _strTotalTests; - QApplication *_application; - QWidget *_mainWindow; - QVBoxLayout *_layout; - QProgressBar *_progressBar; - QStatusBar *_statusBar; - QLabel *_suiteName, *_testName, *_testsDone; - - void parseCommandLine( int argc, char **argv ) - { - _startMinimized = _keep = false; - _title = argv[0]; - - for ( int i = 1; i < argc; ++ i ) { - QString arg( argv[i] ); - if ( arg == "-minimized" ) - _startMinimized = true; - else if ( arg == "-keep" ) - _keep = true; - else if ( arg == "-title" && (i + 1 < argc) ) - _title = argv[++i]; - } - } - - void createApplication( int &argc, char **argv ) - { - _application = new QApplication( argc, argv ); - } - - void createWindow( const WorldDescription &wd ) - { - getTotalTests( wd ); - createMainWindow(); - createProgressBar(); - createStatusBar(); - setMainWidget(); - if ( _startMinimized ) - showMinimized(); - else - showNormal(); - } - - void getTotalTests() - { - getTotalTests( tracker().world() ); - } - - void getTotalTests( const WorldDescription &wd ) - { - _numTotalTests = wd.numTotalTests(); - char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS]; - _strTotalTests = wd.strTotalTests( s ); - } - - void createMainWindow() - { - _mainWindow = new QWidget(); - _layout = new QVBoxLayout( _mainWindow ); - } - - void createProgressBar() - { - _layout->addWidget( _progressBar = new QProgressBar( _numTotalTests, _mainWindow ) ); - _progressBar->setProgress( 0 ); - setColor( 0, 255, 0 ); - setIcon( QMessageBox::Information ); - } - - void createStatusBar() - { - _layout->addWidget( _statusBar = new QStatusBar( _mainWindow ) ); - _statusBar->addWidget( _suiteName = new QLabel( _statusBar ), 2 ); - _statusBar->addWidget( _testName = new QLabel( _statusBar ), 4 ); - _statusBar->addWidget( _testsDone = new QLabel( _statusBar ), 1 ); - } - - void setMainWidget() - { - _application->setMainWidget( _mainWindow ); - } - - void showMinimized() - { - _mainWindow->showMinimized(); - } - - void showNormal() - { - _mainWindow->showNormal(); - centerWindow(); - } - - void setCaption( const QString &suiteName, const QString &testName ) - { - _mainWindow->setCaption( _title + " - " + suiteName + "::" + testName + "()" ); - } - - void showSuiteName( const QString &suiteName ) - { - _suiteName->setText( "class " + suiteName ); - } - - void advanceProgressBar() - { - _progressBar->setProgress( _progressBar->progress() + 1 ); - } - - void showTestName( const QString &testName ) - { - _testName->setText( testName + "()" ); - } - - void showTestsDone( unsigned testsDone ) - { - _testsDone->setText( asString( testsDone ) + " of " + _strTotalTests ); - } - - static QString asString( unsigned n ) - { - return QString::number( n ); - } - - void setColor( int r, int g, int b ) - { - QPalette palette = _progressBar->palette(); - palette.setColor( QColorGroup::Highlight, QColor( r, g, b ) ); - _progressBar->setPalette( palette ); - } - - void setIcon( QMessageBox::Icon icon ) - { -#if QT_VERSION >= 0x030000 - _mainWindow->setIcon( QMessageBox::standardIcon( icon ) ); -#else // Qt version < 3.0.0 - _mainWindow->setIcon( QMessageBox::standardIcon( icon, QApplication::style().guiStyle() ) ); -#endif // QT_VERSION - } - - void processEvents() - { - _application->processEvents(); - } - - void centerWindow() - { - QWidget *desktop = QApplication::desktop(); - int xCenter = desktop->x() + (desktop->width() / 2); - int yCenter = desktop->y() + (desktop->height() / 2); - - int windowWidth = (desktop->width() * 4) / 5; - int windowHeight = _mainWindow->height(); - _mainWindow->setGeometry( xCenter - (windowWidth / 2), yCenter - (windowHeight / 2), windowWidth, windowHeight ); - } - - bool keep() - { - if ( !_keep ) - return false; - if ( !_startMinimized ) - return true; - return (_mainWindow == _application->activeWindow()); - } - - void showSummary() - { - QString summary = _strTotalTests + (_numTotalTests == 1 ? " test" : " tests"); - if ( tracker().failedTests() ) - summary = "Failed " + asString( tracker().failedTests() ) + " of " + summary; - else - summary = summary + " passed"; - - _mainWindow->setCaption( _title + " - " + summary ); - - _statusBar->removeWidget( _suiteName ); - _statusBar->removeWidget( _testName ); - _testsDone->setText( summary ); - } - }; -}; - -#endif // __cxxtest__QtGui_h__ diff --git a/bsl/cxxtest/cxxtest/RealDescriptions.cpp b/bsl/cxxtest/cxxtest/RealDescriptions.cpp deleted file mode 100755 index 1e21ca7625fd86408df96c51a4748eb56c5a40ac..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/RealDescriptions.cpp +++ /dev/null @@ -1,311 +0,0 @@ -#ifndef __cxxtest__RealDescriptions_cpp__ -#define __cxxtest__RealDescriptions_cpp__ - -// -// NOTE: If an error occur during world construction/deletion, CxxTest cannot -// know where the error originated. -// - -#include - -namespace CxxTest -{ - RealTestDescription::RealTestDescription() - { - } - - RealTestDescription::RealTestDescription( List &argList, - SuiteDescription &argSuite, - unsigned argLine, - const char *argTestName ) - { - initialize( argList, argSuite, argLine, argTestName ); - } - - void RealTestDescription::initialize( List &argList, - SuiteDescription &argSuite, - unsigned argLine, - const char *argTestName ) - { - _suite = &argSuite; - _line = argLine; - _testName = argTestName; - attach( argList ); - } - - bool RealTestDescription::setUp() - { - if ( !suite() ) - return false; - - for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) { - bool ok; - _TS_TRY { ok = gf->setUp(); } - _TS_LAST_CATCH( { ok = false; } ); - - if ( !ok ) { - doFailTest( file(), line(), "Error in GlobalFixture::setUp()" ); - return false; - } - } - - _TS_TRY { - _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from setUp()", suite()->setUp() ); - } - _TS_CATCH_ABORT( { return false; } ); - - return true; - } - - bool RealTestDescription::tearDown() - { - if ( !suite() ) - return false; - - _TS_TRY { - _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from tearDown()", suite()->tearDown() ); - } - _TS_CATCH_ABORT( { return false; } ); - - for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) { - bool ok; - _TS_TRY { ok = gf->tearDown(); } - _TS_LAST_CATCH( { ok = false; } ); - - if ( !ok ) { - doFailTest( file(), line(), "Error in GlobalFixture::tearDown()" ); - return false; - } - } - - return true; - } - - const char *RealTestDescription::file() const { return _suite->file(); } - unsigned RealTestDescription::line() const { return _line; } - const char *RealTestDescription::testName() const { return _testName; } - const char *RealTestDescription::suiteName() const { return _suite->suiteName(); } - - TestDescription *RealTestDescription::next() { return (RealTestDescription *)Link::next(); } - const TestDescription *RealTestDescription::next() const { return (const RealTestDescription *)Link::next(); } - - TestSuite *RealTestDescription::suite() const { return _suite->suite(); } - - void RealTestDescription::run() - { - _TS_TRY { runTest(); } - _TS_CATCH_ABORT( {} ) - ___TSM_CATCH( file(), line(), "Exception thrown from test" ); - } - - RealSuiteDescription::RealSuiteDescription() {} - RealSuiteDescription::RealSuiteDescription( const char *argFile, - unsigned argLine, - const char *argSuiteName, - List &argTests ) - { - initialize( argFile, argLine, argSuiteName, argTests ); - } - - void RealSuiteDescription::initialize( const char *argFile, - unsigned argLine, - const char *argSuiteName, - List &argTests ) - { - _file = argFile; - _line = argLine; - _suiteName = argSuiteName; - _tests = &argTests; - - attach( _suites ); - } - - const char *RealSuiteDescription::file() const { return _file; } - unsigned RealSuiteDescription::line() const { return _line; } - const char *RealSuiteDescription::suiteName() const { return _suiteName; } - - TestDescription *RealSuiteDescription::firstTest() { return (RealTestDescription *)_tests->head(); } - const TestDescription *RealSuiteDescription::firstTest() const { return (const RealTestDescription *)_tests->head(); } - SuiteDescription *RealSuiteDescription::next() { return (RealSuiteDescription *)Link::next(); } - const SuiteDescription *RealSuiteDescription::next() const { return (const RealSuiteDescription *)Link::next(); } - - unsigned RealSuiteDescription::numTests() const { return _tests->size(); } - - const TestDescription &RealSuiteDescription::testDescription( unsigned i ) const - { - return *(RealTestDescription *)_tests->nth( i ); - } - - void RealSuiteDescription::activateAllTests() - { - _tests->activateAll(); - } - - bool RealSuiteDescription::leaveOnly( const char *testName ) - { - for ( TestDescription *td = firstTest(); td != 0; td = td->next() ) { - if ( stringsEqual( td->testName(), testName ) ) { - _tests->leaveOnly( *td ); - return true; - } - } - return false; - } - - StaticSuiteDescription::StaticSuiteDescription() {} - StaticSuiteDescription::StaticSuiteDescription( const char *argFile, unsigned argLine, - const char *argSuiteName, TestSuite &argSuite, - List &argTests ) : - RealSuiteDescription( argFile, argLine, argSuiteName, argTests ) - { - doInitialize( argSuite ); - } - - void StaticSuiteDescription::initialize( const char *argFile, unsigned argLine, - const char *argSuiteName, TestSuite &argSuite, - List &argTests ) - { - RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests ); - doInitialize( argSuite ); - } - - void StaticSuiteDescription::doInitialize( TestSuite &argSuite ) - { - _suite = &argSuite; - } - - TestSuite *StaticSuiteDescription::suite() const - { - return _suite; - } - - bool StaticSuiteDescription::setUp() { return true; } - bool StaticSuiteDescription::tearDown() { return true; } - - CommonDynamicSuiteDescription::CommonDynamicSuiteDescription() {} - CommonDynamicSuiteDescription::CommonDynamicSuiteDescription( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - unsigned argCreateLine, unsigned argDestroyLine ) : - RealSuiteDescription( argFile, argLine, argSuiteName, argTests ) - { - doInitialize( argCreateLine, argDestroyLine ); - } - - void CommonDynamicSuiteDescription::initialize( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - unsigned argCreateLine, unsigned argDestroyLine ) - { - RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests ); - doInitialize( argCreateLine, argDestroyLine ); - } - - void CommonDynamicSuiteDescription::doInitialize( unsigned argCreateLine, unsigned argDestroyLine ) - { - _createLine = argCreateLine; - _destroyLine = argDestroyLine; - } - - List &RealWorldDescription::suites() - { - return RealSuiteDescription::_suites; - } - - unsigned RealWorldDescription::numSuites( void ) const - { - return suites().size(); - } - - unsigned RealWorldDescription::numTotalTests( void ) const - { - unsigned count = 0; - for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) - count += sd->numTests(); - return count; - } - - SuiteDescription *RealWorldDescription::firstSuite() - { - return (RealSuiteDescription *)suites().head(); - } - - const SuiteDescription *RealWorldDescription::firstSuite() const - { - return (const RealSuiteDescription *)suites().head(); - } - - const SuiteDescription &RealWorldDescription::suiteDescription( unsigned i ) const - { - return *(const RealSuiteDescription *)suites().nth( i ); - } - - void RealWorldDescription::activateAllTests() - { - suites().activateAll(); - for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) - sd->activateAllTests(); - } - - bool RealWorldDescription::leaveOnly( const char *suiteName, const char *testName ) - { - for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) { - if ( stringsEqual( sd->suiteName(), suiteName ) ) { - if ( testName ) - if ( !sd->leaveOnly( testName ) ) - return false; - suites().leaveOnly( *sd ); - return true; - } - } - return false; - } - - bool RealWorldDescription::setUp() - { - for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) { - bool ok; - _TS_TRY { ok = gf->setUpWorld(); } - _TS_LAST_CATCH( { ok = false; } ); - - if ( !ok ) { - reportError( "Error setting up world" ); - return false; - } - } - - return true; - } - - bool RealWorldDescription::tearDown() - { - for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) { - bool ok; - _TS_TRY { ok = gf->tearDownWorld(); } - _TS_LAST_CATCH( { ok = false; } ); - - if ( !ok ) { - reportError( "Error tearing down world" ); - return false; - } - } - - return true; - } - - void RealWorldDescription::reportError( const char *message ) - { - doWarn( __FILE__, 5, message ); - } - - void activateAllTests() - { - RealWorldDescription().activateAllTests(); - } - - bool leaveOnly( const char *suiteName, const char *testName ) - { - return RealWorldDescription().leaveOnly( suiteName, testName ); - } -} - -#endif // __cxxtest__RealDescriptions_cpp__ - diff --git a/bsl/cxxtest/cxxtest/RealDescriptions.h b/bsl/cxxtest/cxxtest/RealDescriptions.h deleted file mode 100755 index 14c457de7ef75e7d2a73b3920d7160ca44e478b8..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/RealDescriptions.h +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef __cxxtest__RealDescriptions_h__ -#define __cxxtest__RealDescriptions_h__ - -// -// The "real" description classes -// - -#include -#include -#include - -namespace CxxTest -{ - class RealTestDescription : public TestDescription - { - public: - RealTestDescription(); - RealTestDescription( List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName ); - void initialize( List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName ); - - const char *file() const; - unsigned line() const; - const char *testName() const; - const char *suiteName() const; - - TestDescription *next(); - const TestDescription *next() const; - - TestSuite *suite() const; - - bool setUp(); - void run(); - bool tearDown(); - - private: - RealTestDescription( const RealTestDescription & ); - RealTestDescription &operator=( const RealTestDescription & ); - - virtual void runTest() = 0; - - SuiteDescription *_suite; - unsigned _line; - const char *_testName; - }; - - class RealSuiteDescription : public SuiteDescription - { - public: - RealSuiteDescription(); - RealSuiteDescription( const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests ); - - void initialize( const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests ); - - const char *file() const; - unsigned line() const; - const char *suiteName() const; - - TestDescription *firstTest(); - const TestDescription *firstTest() const; - SuiteDescription *next(); - const SuiteDescription *next() const; - - unsigned numTests() const; - const TestDescription &testDescription( unsigned i ) const; - - void activateAllTests(); - bool leaveOnly( const char *testName ); - - private: - RealSuiteDescription( const RealSuiteDescription & ); - RealSuiteDescription &operator=( const RealSuiteDescription & ); - - const char *_file; - unsigned _line; - const char *_suiteName; - List *_tests; - - static List _suites; - friend class RealWorldDescription; - }; - - class StaticSuiteDescription : public RealSuiteDescription - { - public: - StaticSuiteDescription(); - StaticSuiteDescription( const char *argFile, unsigned argLine, - const char *argSuiteName, TestSuite &argSuite, - List &argTests ); - - void initialize( const char *argFile, unsigned argLine, - const char *argSuiteName, TestSuite &argSuite, - List &argTests ); - TestSuite *suite() const; - - bool setUp(); - bool tearDown(); - - private: - StaticSuiteDescription( const StaticSuiteDescription & ); - StaticSuiteDescription &operator=( const StaticSuiteDescription & ); - - void doInitialize( TestSuite &argSuite ); - - TestSuite *_suite; - }; - - class CommonDynamicSuiteDescription : public RealSuiteDescription - { - public: - CommonDynamicSuiteDescription(); - CommonDynamicSuiteDescription( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - unsigned argCreateLine, unsigned argDestroyLine ); - - void initialize( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - unsigned argCreateLine, unsigned argDestroyLine ); - - protected: - unsigned _createLine, _destroyLine; - - private: - void doInitialize( unsigned argCreateLine, unsigned argDestroyLine ); - }; - - template - class DynamicSuiteDescription : public CommonDynamicSuiteDescription - { - public: - DynamicSuiteDescription() {} - DynamicSuiteDescription( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - S *&argSuite, unsigned argCreateLine, - unsigned argDestroyLine ) : - CommonDynamicSuiteDescription( argFile, argLine, argSuiteName, argTests, argCreateLine, argDestroyLine ) - { - _suite = &argSuite; - } - - void initialize( const char *argFile, unsigned argLine, - const char *argSuiteName, List &argTests, - S *&argSuite, unsigned argCreateLine, - unsigned argDestroyLine ) - { - CommonDynamicSuiteDescription::initialize( argFile, argLine, - argSuiteName, argTests, - argCreateLine, argDestroyLine ); - _suite = &argSuite; - } - - TestSuite *suite() const { return realSuite(); } - - bool setUp(); - bool tearDown(); - - private: - S *realSuite() const { return *_suite; } - void setSuite( S *s ) { *_suite = s; } - - void createSuite() - { - setSuite( S::createSuite() ); - } - - void destroySuite() - { - S *s = realSuite(); - setSuite( 0 ); - S::destroySuite( s ); - } - - S **_suite; - }; - - template - bool DynamicSuiteDescription::setUp() - { - _TS_TRY { - _TSM_ASSERT_THROWS_NOTHING( file(), _createLine, "Exception thrown from createSuite()", createSuite() ); - _TSM_ASSERT( file(), _createLine, "createSuite() failed", suite() != 0 ); - } - _TS_CATCH_ABORT( { return false; } ); - - return (suite() != 0); - } - - template - bool DynamicSuiteDescription::tearDown() - { - if ( !_suite ) - return true; - - _TS_TRY { - _TSM_ASSERT_THROWS_NOTHING( file(), _destroyLine, "destroySuite() failed", destroySuite() ); - } - _TS_CATCH_ABORT( { return false; } ); - - return true; - } - - class RealWorldDescription : public WorldDescription - { - public: - static List &suites(); - unsigned numSuites( void ) const; - unsigned numTotalTests( void ) const; - SuiteDescription *firstSuite(); - const SuiteDescription *firstSuite() const; - const SuiteDescription &suiteDescription( unsigned i ) const; - void activateAllTests(); - bool leaveOnly( const char *suiteName, const char *testName = 0 ); - - bool setUp(); - bool tearDown(); - static void reportError( const char *message ); - }; - - void activateAllTests(); - bool leaveOnly( const char *suiteName, const char *testName = 0 ); -} - -#endif // __cxxtest__RealDescriptions_h__ - diff --git a/bsl/cxxtest/cxxtest/Root.cpp b/bsl/cxxtest/cxxtest/Root.cpp deleted file mode 100755 index c4320fde7202d7d70c96d7119c25a5b159e0455e..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Root.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __cxxtest__Root_cpp__ -#define __cxxtest__Root_cpp__ - -// -// This file holds the "root" of CxxTest, i.e. -// the parts that must be in a source file file. -// - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // __cxxtest__Root_cpp__ diff --git a/bsl/cxxtest/cxxtest/SelfTest.h b/bsl/cxxtest/cxxtest/SelfTest.h deleted file mode 100755 index 6d6b96e7d90a2955e67658722b1c357b88a32467..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/SelfTest.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __cxxtest_SelfTest_h__ -#define __cxxtest_SelfTest_h__ - -#define CXXTEST_SUITE(name) -#define CXXTEST_CODE(member) - -#endif // __cxxtest_SelfTest_h__ diff --git a/bsl/cxxtest/cxxtest/StdHeaders.h b/bsl/cxxtest/cxxtest/StdHeaders.h deleted file mode 100755 index 7c80b76f9a504ed036fe1cf1e94d1e3b2ff985b1..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/StdHeaders.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __cxxtest_StdHeaders_h__ -#define __cxxtest_StdHeaders_h__ - -// -// This file basically #includes the STL headers. -// It exists to support warning level 4 in Visual C++ -// - -#ifdef _MSC_VER -# pragma warning( push, 1 ) -#endif // _MSC_VER - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -# pragma warning( pop ) -#endif // _MSC_VER - -#endif // __cxxtest_StdHeaders_h__ diff --git a/bsl/cxxtest/cxxtest/StdValueTraits.h b/bsl/cxxtest/cxxtest/StdValueTraits.h deleted file mode 100755 index 036796b0df3c1a8c41e8ead510932c5987ba7c84..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/StdValueTraits.h +++ /dev/null @@ -1,229 +0,0 @@ -#ifndef __cxxtest_StdValueTraits_h__ -#define __cxxtest_StdValueTraits_h__ - -// -// This file defines ValueTraits for std:: stuff. -// It is #included by if you -// define CXXTEST_HAVE_STD -// - -#include -#include - -#ifdef _CXXTEST_OLD_STD -# define CXXTEST_STD(x) x -#else // !_CXXTEST_OLD_STD -# define CXXTEST_STD(x) std::x -#endif // _CXXTEST_OLD_STD - -#ifndef CXXTEST_USER_VALUE_TRAITS - -namespace CxxTest -{ - // - // NOTE: This should have been - // template - // class ValueTraits< std::basic_string > {}; - // But MSVC doesn't support it (yet). - // - - // - // If we have std::string, we might as well use it - // - class StdTraitsBase - { - public: - StdTraitsBase &operator<<( const CXXTEST_STD(string) &s ) { _s += s; return *this; } - const char *asString() const { return _s.c_str(); } - - private: - CXXTEST_STD(string) _s; - }; - - // - // std::string - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(string) &s ) - { - *this << "\""; - for ( unsigned i = 0; i < s.length(); ++ i ) { - char c[sizeof("\\xXX")]; - charToString( s[i], c ); - *this << c; - } - *this << "\""; - } - }; - - CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(string) ); - -#ifndef _CXXTEST_OLD_STD - // - // std::wstring - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits)> : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(basic_string) &s ) - { - *this << "L\""; - for ( unsigned i = 0; i < s.length(); ++ i ) { - char c[sizeof("\\x12345678")]; - charToString( (unsigned long)s[i], c ); - *this << c; - } - *this << "\""; - } - }; - - CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(basic_string) ); -#endif // _CXXTEST_OLD_STD - - // - // Convert a range defined by iterators to a string - // This is useful for almost all STL containers - // - template - void dumpRange( Stream &s, Iterator first, Iterator last ) - { - s << "{ "; - while ( first != last ) { - s << TS_AS_STRING(*first); - ++ first; - s << ((first == last) ? " }" : ", "); - } - } - -#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION - // - // std::pair - // - template - class ValueTraits< CXXTEST_STD(pair) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(pair) &p ) - { - *this << "<" << TS_AS_STRING( p.first ) << ", " << TS_AS_STRING( p.second ) << ">"; - } - }; - - // - // std::vector - // - template - class ValueTraits< CXXTEST_STD(vector) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(vector) &v ) - { - dumpRange( *this, v.begin(), v.end() ); - } - }; - - // - // std::list - // - template - class ValueTraits< CXXTEST_STD(list) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(list) &l ) - { - dumpRange( *this, l.begin(), l.end() ); - } - }; - - // - // std::set - // - template - class ValueTraits< CXXTEST_STD(set) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(set) &s ) - { - dumpRange( *this, s.begin(), s.end() ); - } - }; - - // - // std::map - // - template - class ValueTraits< CXXTEST_STD(map) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(map) &m ) - { - dumpRange( *this, m.begin(), m.end() ); - } - }; - - // - // std::deque - // - template - class ValueTraits< CXXTEST_STD(deque) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(deque) &d ) - { - dumpRange( *this, d.begin(), d.end() ); - } - }; - - // - // std::multiset - // - template - class ValueTraits< CXXTEST_STD(multiset) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(multiset) &ms ) - { - dumpRange( *this, ms.begin(), ms.end() ); - } - }; - - // - // std::multimap - // - template - class ValueTraits< CXXTEST_STD(multimap) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(multimap) &mm ) - { - dumpRange( *this, mm.begin(), mm.end() ); - } - }; - - // - // std::complex - // - template - class ValueTraits< CXXTEST_STD(complex) > : public StdTraitsBase - { - public: - ValueTraits( const CXXTEST_STD(complex) &c ) - { - if ( !c.imag() ) - *this << TS_AS_STRING(c.real()); - else if ( !c.real() ) - *this << "(" << TS_AS_STRING(c.imag()) << " * i)"; - else - *this << "(" << TS_AS_STRING(c.real()) << " + " << TS_AS_STRING(c.imag()) << " * i)"; - } - }; -#endif // _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION -}; - -#endif // CXXTEST_USER_VALUE_TRAITS - -#endif // __cxxtest_StdValueTraits_h__ diff --git a/bsl/cxxtest/cxxtest/StdioFilePrinter.h b/bsl/cxxtest/cxxtest/StdioFilePrinter.h deleted file mode 100755 index 47984b69b9b534d7506eae30c4c4915002374cff..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/StdioFilePrinter.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __cxxtest__StdioFilePrinter_h__ -#define __cxxtest__StdioFilePrinter_h__ - -// -// The StdioFilePrinter is a simple TestListener that -// just prints "OK" if everything goes well, otherwise -// reports the error in the format of compiler messages. -// This class uses , i.e. FILE * and fprintf(). -// - -#include -#include - -namespace CxxTest -{ - class StdioFilePrinter : public ErrorFormatter - { - public: - StdioFilePrinter( FILE *o, const char *preLine = ":", const char *postLine = "" ) : - ErrorFormatter( new Adapter(o), preLine, postLine ) {} - virtual ~StdioFilePrinter() { delete outputStream(); } - - private: - class Adapter : public OutputStream - { - Adapter( const Adapter & ); - Adapter &operator=( const Adapter & ); - - FILE *_o; - - public: - Adapter( FILE *o ) : _o(o) {} - void flush() { fflush( _o ); } - OutputStream &operator<<( unsigned i ) { fprintf( _o, "%u", i ); return *this; } - OutputStream &operator<<( const char *s ) { fputs( s, _o ); return *this; } - OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); } - }; - }; -} - -#endif // __cxxtest__StdioFilePrinter_h__ diff --git a/bsl/cxxtest/cxxtest/StdioPrinter.h b/bsl/cxxtest/cxxtest/StdioPrinter.h deleted file mode 100755 index af5bc6b639baba80ca607b24576b4ae9fa5bac34..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/StdioPrinter.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __cxxtest__StdioPrinter_h__ -#define __cxxtest__StdioPrinter_h__ - -// -// The StdioPrinter is an StdioFilePrinter which defaults to stdout. -// This should have been called StdOutPrinter or something, but the name -// has been historically used. -// - -#include - -namespace CxxTest -{ - class StdioPrinter : public StdioFilePrinter - { - public: - StdioPrinter( FILE *o = stdout, const char *preLine = ":", const char *postLine = "" ) : - StdioFilePrinter( o, preLine, postLine ) {} - }; -} - -#endif // __cxxtest__StdioPrinter_h__ diff --git a/bsl/cxxtest/cxxtest/TeeListener.h b/bsl/cxxtest/cxxtest/TeeListener.h deleted file mode 100755 index 88afdd3ed66956c7b8b210b2d5a82567cbbe587a..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TeeListener.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef __cxxtest__TeeListener_h__ -#define __cxxtest__TeeListener_h__ - -// -// A TeeListener notifies two "reular" TestListeners -// - -#include -#include - -namespace CxxTest -{ - class TeeListener : public TestListener - { - public: - TeeListener() - { - setFirst( _dummy ); - setSecond( _dummy ); - } - - virtual ~TeeListener() - { - } - - void setFirst( TestListener &first ) - { - _first = &first; - } - - void setSecond( TestListener &second ) - { - _second = &second; - } - - void enterWorld( const WorldDescription &d ) - { - _first->enterWorld( d ); - _second->enterWorld( d ); - } - - void enterSuite( const SuiteDescription &d ) - { - _first->enterSuite( d ); - _second->enterSuite( d ); - } - - void enterTest( const TestDescription &d ) - { - _first->enterTest( d ); - _second->enterTest( d ); - } - - void trace( const char *file, unsigned line, const char *expression ) - { - _first->trace( file, line, expression ); - _second->trace( file, line, expression ); - } - - void warning( const char *file, unsigned line, const char *expression ) - { - _first->warning( file, line, expression ); - _second->warning( file, line, expression ); - } - - void failedTest( const char *file, unsigned line, const char *expression ) - { - _first->failedTest( file, line, expression ); - _second->failedTest( file, line, expression ); - } - - void failedAssert( const char *file, unsigned line, const char *expression ) - { - _first->failedAssert( file, line, expression ); - _second->failedAssert( file, line, expression ); - } - - void failedAssertEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - _first->failedAssertEquals( file, line, xStr, yStr, x, y ); - _second->failedAssertEquals( file, line, xStr, yStr, x, y ); - } - - void failedAssertSameData( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *sizeStr, const void *x, - const void *y, unsigned size ) - { - _first->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, y, size ); - _second->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, y, size ); - } - - void failedAssertDelta( const char *file, unsigned line, - const char *xStr, const char *yStr, const char *dStr, - const char *x, const char *y, const char *d ) - { - _first->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d ); - _second->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d ); - } - - void failedAssertDiffers( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *value ) - { - _first->failedAssertDiffers( file, line, xStr, yStr, value ); - _second->failedAssertDiffers( file, line, xStr, yStr, value ); - } - - void failedAssertLessThan( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - _first->failedAssertLessThan( file, line, xStr, yStr, x, y ); - _second->failedAssertLessThan( file, line, xStr, yStr, x, y ); - } - - void failedAssertLessThanEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - _first->failedAssertLessThanEquals( file, line, xStr, yStr, x, y ); - _second->failedAssertLessThanEquals( file, line, xStr, yStr, x, y ); - } - - void failedAssertPredicate( const char *file, unsigned line, - const char *predicate, const char *xStr, const char *x ) - { - _first->failedAssertPredicate( file, line, predicate, xStr, x ); - _second->failedAssertPredicate( file, line, predicate, xStr, x ); - } - - void failedAssertRelation( const char *file, unsigned line, - const char *relation, const char *xStr, const char *yStr, - const char *x, const char *y ) - { - _first->failedAssertRelation( file, line, relation, xStr, yStr, x, y ); - _second->failedAssertRelation( file, line, relation, xStr, yStr, x, y ); - } - - void failedAssertThrows( const char *file, unsigned line, - const char *expression, const char *type, - bool otherThrown ) - { - _first->failedAssertThrows( file, line, expression, type, otherThrown ); - _second->failedAssertThrows( file, line, expression, type, otherThrown ); - } - - void failedAssertThrowsNot( const char *file, unsigned line, - const char *expression ) - { - _first->failedAssertThrowsNot( file, line, expression ); - _second->failedAssertThrowsNot( file, line, expression ); - } - - void leaveTest( const TestDescription &d ) - { - _first->leaveTest(d); - _second->leaveTest(d); - } - - void leaveSuite( const SuiteDescription &d ) - { - _first->leaveSuite(d); - _second->leaveSuite(d); - } - - void leaveWorld( const WorldDescription &d ) - { - _first->leaveWorld(d); - _second->leaveWorld(d); - } - - private: - TestListener *_first, *_second; - TestListener _dummy; - }; -}; - - -#endif // __cxxtest__TeeListener_h__ diff --git a/bsl/cxxtest/cxxtest/TestListener.h b/bsl/cxxtest/cxxtest/TestListener.h deleted file mode 100755 index 0eeb5234ea6d4558e721b7392dae5b96f246b811..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestListener.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __cxxtest__TestListener_h__ -#define __cxxtest__TestListener_h__ - -// -// TestListener is the base class for all "listeners", -// i.e. classes that receive notifications of the -// testing process. -// -// The names of the parameters are in comments to avoid -// "unused parameter" warnings. -// - -#include - -namespace CxxTest -{ - class TestListener - { - public: - TestListener() {} - virtual ~TestListener() {} - - virtual void enterWorld( const WorldDescription & /*desc*/ ) {} - virtual void enterSuite( const SuiteDescription & /*desc*/ ) {} - virtual void enterTest( const TestDescription & /*desc*/ ) {} - virtual void trace( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) {} - virtual void warning( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) {} - virtual void failedTest( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) {} - virtual void failedAssert( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) {} - virtual void failedAssertEquals( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) {} - virtual void failedAssertSameData( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*sizeStr*/, const void * /*x*/, - const void * /*y*/, unsigned /*size*/ ) {} - virtual void failedAssertDelta( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*dStr*/, const char * /*x*/, - const char * /*y*/, const char * /*d*/ ) {} - virtual void failedAssertDiffers( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*value*/ ) {} - virtual void failedAssertLessThan( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) {} - virtual void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/, - const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) {} - virtual void failedAssertPredicate( const char * /*file*/, unsigned /*line*/, - const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ ) {} - virtual void failedAssertRelation( const char * /*file*/, unsigned /*line*/, - const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/, - const char * /*x*/, const char * /*y*/ ) {} - virtual void failedAssertThrows( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/, const char * /*type*/, - bool /*otherThrown*/ ) {} - virtual void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/, - const char * /*expression*/ ) {} - virtual void leaveTest( const TestDescription & /*desc*/ ) {} - virtual void leaveSuite( const SuiteDescription & /*desc*/ ) {} - virtual void leaveWorld( const WorldDescription & /*desc*/ ) {} - }; -} - -#endif // __cxxtest__TestListener_h__ diff --git a/bsl/cxxtest/cxxtest/TestRunner.h b/bsl/cxxtest/cxxtest/TestRunner.h deleted file mode 100755 index 43f0832e2aea62298aaef824a9c1c83886f78433..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestRunner.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef __cxxtest_TestRunner_h__ -#define __cxxtest_TestRunner_h__ - -// -// TestRunner is the class that runs all the tests. -// To use it, create an object that implements the TestListener -// interface and call TestRunner::runAllTests( myListener ); -// - -#include -#include -#include -#include - -namespace CxxTest -{ - class TestRunner - { - public: - static void runAllTests( TestListener &listener ) - { - tracker().setListener( &listener ); - _TS_TRY { TestRunner().runWorld(); } - _TS_LAST_CATCH( { tracker().failedTest( __FILE__, __LINE__, "Exception thrown from world" ); } ); - tracker().setListener( 0 ); - } - - static void runAllTests( TestListener *listener ) - { - if ( listener ) { - listener->warning( __FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )" ); - runAllTests( *listener ); - } - } - - private: - void runWorld() - { - RealWorldDescription wd; - WorldGuard sg; - - tracker().enterWorld( wd ); - if ( wd.setUp() ) { - for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() ) - if ( sd->active() ) - runSuite( *sd ); - - wd.tearDown(); - } - tracker().leaveWorld( wd ); - } - - void runSuite( SuiteDescription &sd ) - { - StateGuard sg; - - tracker().enterSuite( sd ); - if ( sd.setUp() ) { - for ( TestDescription *td = sd.firstTest(); td; td = td->next() ) - if ( td->active() ) - runTest( *td ); - - sd.tearDown(); - } - tracker().leaveSuite( sd ); - } - - void runTest( TestDescription &td ) - { - StateGuard sg; - - tracker().enterTest( td ); - if ( td.setUp() ) { - td.run(); - td.tearDown(); - } - tracker().leaveTest( td ); - } - - class StateGuard - { -#ifdef _CXXTEST_HAVE_EH - bool _abortTestOnFail; -#endif // _CXXTEST_HAVE_EH - unsigned _maxDumpSize; - - public: - StateGuard() - { -#ifdef _CXXTEST_HAVE_EH - _abortTestOnFail = abortTestOnFail(); -#endif // _CXXTEST_HAVE_EH - _maxDumpSize = maxDumpSize(); - } - - ~StateGuard() - { -#ifdef _CXXTEST_HAVE_EH - setAbortTestOnFail( _abortTestOnFail ); -#endif // _CXXTEST_HAVE_EH - setMaxDumpSize( _maxDumpSize ); - } - }; - - class WorldGuard : public StateGuard - { - public: - WorldGuard() : StateGuard() - { -#ifdef _CXXTEST_HAVE_EH - setAbortTestOnFail( CXXTEST_DEFAULT_ABORT ); -#endif // _CXXTEST_HAVE_EH - setMaxDumpSize( CXXTEST_MAX_DUMP_SIZE ); - } - }; - }; - - // - // For --no-static-init - // - void initialize(); -}; - - -#endif // __cxxtest_TestRunner_h__ diff --git a/bsl/cxxtest/cxxtest/TestSuite.cpp b/bsl/cxxtest/cxxtest/TestSuite.cpp deleted file mode 100755 index bc14c2cd87719ee0746521c0fa6b57e80197e9de..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestSuite.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef __cxxtest__TestSuite_cpp__ -#define __cxxtest__TestSuite_cpp__ - -#include - -namespace CxxTest -{ - // - // TestSuite members - // - TestSuite::~TestSuite() {} - void TestSuite::setUp() {} - void TestSuite::tearDown() {} - - // - // Test-aborting stuff - // - static bool currentAbortTestOnFail = false; - - bool abortTestOnFail() - { - return currentAbortTestOnFail; - } - - void setAbortTestOnFail( bool value ) - { - currentAbortTestOnFail = value; - } - - void doAbortTest() - { -# if defined(_CXXTEST_HAVE_EH) - if ( currentAbortTestOnFail ) - throw AbortTest(); -# endif // _CXXTEST_HAVE_EH - } - - // - // Max dump size - // - static unsigned currentMaxDumpSize = CXXTEST_MAX_DUMP_SIZE; - - unsigned maxDumpSize() - { - return currentMaxDumpSize; - } - - void setMaxDumpSize( unsigned value ) - { - currentMaxDumpSize = value; - } - - // - // Some non-template functions - // - void doTrace( const char *file, unsigned line, const char *message ) - { - tracker().trace( file, line, message ); - } - - void doWarn( const char *file, unsigned line, const char *message ) - { - tracker().warning( file, line, message ); - } - - void doFailTest( const char *file, unsigned line, const char *message ) - { - tracker().failedTest( file, line, message ); - TS_ABORT(); - } - - void doFailAssert( const char *file, unsigned line, - const char *expression, const char *message ) - { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssert( file, line, expression ); - TS_ABORT(); - } - - bool sameData( const void *x, const void *y, unsigned size ) - { - if ( size == 0 ) - return true; - - if ( x == y ) - return true; - - if ( !x || !y ) - return false; - - const char *cx = (const char *)x; - const char *cy = (const char *)y; - while ( size -- ) - if ( *cx++ != *cy++ ) - return false; - - return true; - } - - void doAssertSameData( const char *file, unsigned line, - const char *xExpr, const void *x, - const char *yExpr, const void *y, - const char *sizeExpr, unsigned size, - const char *message ) - { - if ( !sameData( x, y, size ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertSameData( file, line, xExpr, yExpr, sizeExpr, x, y, size ); - TS_ABORT(); - } - } - - void doFailAssertThrows( const char *file, unsigned line, - const char *expr, const char *type, - bool otherThrown, - const char *message ) - { - if ( message ) - tracker().failedTest( file, line, message ); - - tracker().failedAssertThrows( file, line, expr, type, otherThrown ); - TS_ABORT(); - } - - void doFailAssertThrowsNot( const char *file, unsigned line, - const char *expression, const char *message ) - { - if ( message ) - tracker().failedTest( file, line, message ); - - tracker().failedAssertThrowsNot( file, line, expression ); - TS_ABORT(); - } -}; - -#endif // __cxxtest__TestSuite_cpp__ diff --git a/bsl/cxxtest/cxxtest/TestSuite.h b/bsl/cxxtest/cxxtest/TestSuite.h deleted file mode 100755 index fc5a206a7d84277c200d32f9dd402295c016362b..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestSuite.h +++ /dev/null @@ -1,512 +0,0 @@ -#ifndef __cxxtest__TestSuite_h__ -#define __cxxtest__TestSuite_h__ - -// -// class TestSuite is the base class for all test suites. -// To define a test suite, derive from this class and add -// member functions called void test*(); -// - -#include -#include -#include -#include - -#ifdef _CXXTEST_HAVE_STD -# include -#endif // _CXXTEST_HAVE_STD - -namespace CxxTest -{ - class TestSuite - { - public: - virtual ~TestSuite(); - virtual void setUp(); - virtual void tearDown(); - }; - - class AbortTest {}; - void doAbortTest(); -# define TS_ABORT() CxxTest::doAbortTest() - - bool abortTestOnFail(); - void setAbortTestOnFail( bool value = CXXTEST_DEFAULT_ABORT ); - - unsigned maxDumpSize(); - void setMaxDumpSize( unsigned value = CXXTEST_MAX_DUMP_SIZE ); - - void doTrace( const char *file, unsigned line, const char *message ); - void doWarn( const char *file, unsigned line, const char *message ); - void doFailTest( const char *file, unsigned line, const char *message ); - void doFailAssert( const char *file, unsigned line, const char *expression, const char *message ); - - template - bool equals( X x, Y y ) - { - return (x == y); - } - - template - void doAssertEquals( const char *file, unsigned line, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *message ) - { - if ( !equals( x, y ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); - TS_ABORT(); - } - } - - void doAssertSameData( const char *file, unsigned line, - const char *xExpr, const void *x, - const char *yExpr, const void *y, - const char *sizeExpr, unsigned size, - const char *message ); - - template - bool differs( X x, Y y ) - { - return !(x == y); - } - - template - void doAssertDiffers( const char *file, unsigned line, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *message ) - { - if ( !differs( x, y ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertDiffers( file, line, xExpr, yExpr, TS_AS_STRING(x) ); - TS_ABORT(); - } - } - - template - bool lessThan( X x, Y y ) - { - return (x < y); - } - - template - void doAssertLessThan( const char *file, unsigned line, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *message ) - { - if ( !lessThan(x, y) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertLessThan( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); - TS_ABORT(); - } - } - - template - bool lessThanEquals( X x, Y y ) - { - return (x <= y); - } - - template - void doAssertLessThanEquals( const char *file, unsigned line, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *message ) - { - if ( !lessThanEquals( x, y ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertLessThanEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); - TS_ABORT(); - } - } - - template - void doAssertPredicate( const char *file, unsigned line, - const char *pExpr, const P &p, - const char *xExpr, X x, - const char *message ) - { - if ( !p( x ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertPredicate( file, line, pExpr, xExpr, TS_AS_STRING(x) ); - TS_ABORT(); - } - } - - template - void doAssertRelation( const char *file, unsigned line, - const char *rExpr, const R &r, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *message ) - { - if ( !r( x, y ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - tracker().failedAssertRelation( file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); - TS_ABORT(); - } - } - - template - bool delta( X x, Y y, D d ) - { - return ((y >= x - d) && (y <= x + d)); - } - - template - void doAssertDelta( const char *file, unsigned line, - const char *xExpr, X x, - const char *yExpr, Y y, - const char *dExpr, D d, - const char *message ) - { - if ( !delta( x, y, d ) ) { - if ( message ) - tracker().failedTest( file, line, message ); - - tracker().failedAssertDelta( file, line, xExpr, yExpr, dExpr, - TS_AS_STRING(x), TS_AS_STRING(y), TS_AS_STRING(d) ); - TS_ABORT(); - } - } - - void doFailAssertThrows( const char *file, unsigned line, - const char *expr, const char *type, - bool otherThrown, - const char *message ); - - void doFailAssertThrowsNot( const char *file, unsigned line, - const char *expression, const char *message ); - -# ifdef _CXXTEST_HAVE_EH -# define _TS_TRY try -# define _TS_CATCH_TYPE(t, b) catch t b -# define _TS_CATCH_ABORT(b) _TS_CATCH_TYPE( (const CxxTest::AbortTest &), b ) -# define _TS_LAST_CATCH(b) _TS_CATCH_TYPE( (...), b ) -# define _TSM_LAST_CATCH(f,l,m) _TS_LAST_CATCH( { (CxxTest::tracker()).failedTest(f,l,m); } ) -# ifdef _CXXTEST_HAVE_STD -# define ___TSM_CATCH(f,l,m) \ - catch(const std::exception &e) { (CxxTest::tracker()).failedTest(f,l,e.what()); } \ - _TSM_LAST_CATCH(f,l,m) -# else // !_CXXTEST_HAVE_STD -# define ___TSM_CATCH(f,l,m) _TSM_LAST_CATCH(f,l,m) -# endif // _CXXTEST_HAVE_STD -# define __TSM_CATCH(f,l,m) \ - _TS_CATCH_ABORT( { throw; } ) \ - ___TSM_CATCH(f,l,m) -# define __TS_CATCH(f,l) __TSM_CATCH(f,l,"Unhandled exception") -# define _TS_CATCH __TS_CATCH(__FILE__,__LINE__) -# else // !_CXXTEST_HAVE_EH -# define _TS_TRY -# define ___TSM_CATCH(f,l,m) -# define __TSM_CATCH(f,l,m) -# define __TS_CATCH(f,l) -# define _TS_CATCH -# define _TS_CATCH_TYPE(t, b) -# define _TS_LAST_CATCH(b) -# define _TS_CATCH_ABORT(b) -# endif // _CXXTEST_HAVE_EH - - // TS_TRACE -# define _TS_TRACE(f,l,e) CxxTest::doTrace( (f), (l), TS_AS_STRING(e) ) -# define TS_TRACE(e) _TS_TRACE( __FILE__, __LINE__, e ) - - // TS_WARN -# define _TS_WARN(f,l,e) CxxTest::doWarn( (f), (l), TS_AS_STRING(e) ) -# define TS_WARN(e) _TS_WARN( __FILE__, __LINE__, e ) - - // TS_FAIL -# define _TS_FAIL(f,l,e) CxxTest::doFailTest( (f), (l), TS_AS_STRING(e) ) -# define TS_FAIL(e) _TS_FAIL( __FILE__, __LINE__, e ) - - // TS_ASSERT -# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) CxxTest::doFailAssert( (f), (l), #e, (m) ); } -# define ___TS_ASSERT(f,l,e,m) { _TS_TRY { ___ETS_ASSERT(f,l,e,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0) -# define _TS_ASSERT(f,l,e) ___TS_ASSERT(f,l,e,0) - -# define ETS_ASSERT(e) _ETS_ASSERT(__FILE__,__LINE__,e) -# define TS_ASSERT(e) _TS_ASSERT(__FILE__,__LINE__,e) - -# define _ETSM_ASSERT(f,l,m,e) ___ETS_ASSERT(f,l,e,TS_AS_STRING(m) ) -# define _TSM_ASSERT(f,l,m,e) ___TS_ASSERT(f,l,e,TS_AS_STRING(m) ) - -# define ETSM_ASSERT(m,e) _ETSM_ASSERT(__FILE__,__LINE__,m,e) -# define TSM_ASSERT(m,e) _TSM_ASSERT(__FILE__,__LINE__,m,e) - - // TS_ASSERT_EQUALS -# define ___ETS_ASSERT_EQUALS(f,l,x,y,m) CxxTest::doAssertEquals( (f), (l), #x, (x), #y, (y), (m) ) -# define ___TS_ASSERT_EQUALS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_EQUALS(f,l,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,0) -# define _TS_ASSERT_EQUALS(f,l,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,0) - -# define ETS_ASSERT_EQUALS(x,y) _ETS_ASSERT_EQUALS(__FILE__,__LINE__,x,y) -# define TS_ASSERT_EQUALS(x,y) _TS_ASSERT_EQUALS(__FILE__,__LINE__,x,y) - -# define _ETSM_ASSERT_EQUALS(f,l,m,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m)) -# define _TSM_ASSERT_EQUALS(f,l,m,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m)) - -# define ETSM_ASSERT_EQUALS(m,x,y) _ETSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y) -# define TSM_ASSERT_EQUALS(m,x,y) _TSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y) - - // TS_ASSERT_SAME_DATA -# define ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m) CxxTest::doAssertSameData( (f), (l), #x, (x), #y, (y), #s, (s), (m) ) -# define ___TS_ASSERT_SAME_DATA(f,l,x,y,s,m) { _TS_TRY { ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_SAME_DATA(f,l,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,0) -# define _TS_ASSERT_SAME_DATA(f,l,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,0) - -# define ETS_ASSERT_SAME_DATA(x,y,s) _ETS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s) -# define TS_ASSERT_SAME_DATA(x,y,s) _TS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s) - -# define _ETSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m)) -# define _TSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m)) - -# define ETSM_ASSERT_SAME_DATA(m,x,y,s) _ETSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s) -# define TSM_ASSERT_SAME_DATA(m,x,y,s) _TSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s) - - // TS_ASSERT_DIFFERS -# define ___ETS_ASSERT_DIFFERS(f,l,x,y,m) CxxTest::doAssertDiffers( (f), (l), #x, (x), #y, (y), (m) ) -# define ___TS_ASSERT_DIFFERS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_DIFFERS(f,l,x,y,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_DIFFERS(f,l,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,0) -# define _TS_ASSERT_DIFFERS(f,l,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,0) - -# define ETS_ASSERT_DIFFERS(x,y) _ETS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y) -# define TS_ASSERT_DIFFERS(x,y) _TS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y) - -# define _ETSM_ASSERT_DIFFERS(f,l,m,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m)) -# define _TSM_ASSERT_DIFFERS(f,l,m,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m)) - -# define ETSM_ASSERT_DIFFERS(m,x,y) _ETSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y) -# define TSM_ASSERT_DIFFERS(m,x,y) _TSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y) - - // TS_ASSERT_LESS_THAN -# define ___ETS_ASSERT_LESS_THAN(f,l,x,y,m) CxxTest::doAssertLessThan( (f), (l), #x, (x), #y, (y), (m) ) -# define ___TS_ASSERT_LESS_THAN(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_LESS_THAN(f,l,x,y,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_LESS_THAN(f,l,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,0) -# define _TS_ASSERT_LESS_THAN(f,l,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,0) - -# define ETS_ASSERT_LESS_THAN(x,y) _ETS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y) -# define TS_ASSERT_LESS_THAN(x,y) _TS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y) - -# define _ETSM_ASSERT_LESS_THAN(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m)) -# define _TSM_ASSERT_LESS_THAN(f,l,m,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m)) - -# define ETSM_ASSERT_LESS_THAN(m,x,y) _ETSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y) -# define TSM_ASSERT_LESS_THAN(m,x,y) _TSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y) - - // TS_ASSERT_LESS_THAN_EQUALS -# define ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \ - CxxTest::doAssertLessThanEquals( (f), (l), #x, (x), #y, (y), (m) ) -# define ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \ - { _TS_TRY { ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0) -# define _TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0) - -# define ETS_ASSERT_LESS_THAN_EQUALS(x,y) _ETS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y) -# define TS_ASSERT_LESS_THAN_EQUALS(x,y) _TS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y) - -# define _ETSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m)) -# define _TSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m)) - -# define ETSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _ETSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y) -# define TSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _TSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y) - - // TS_ASSERT_PREDICATE -# define ___ETS_ASSERT_PREDICATE(f,l,p,x,m) \ - CxxTest::doAssertPredicate( (f), (l), #p, p(), #x, (x), (m) ) -# define ___TS_ASSERT_PREDICATE(f,l,p,x,m) \ - { _TS_TRY { ___ETS_ASSERT_PREDICATE(f,l,p,x,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_PREDICATE(f,l,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,0) -# define _TS_ASSERT_PREDICATE(f,l,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,0) - -# define ETS_ASSERT_PREDICATE(p,x) _ETS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x) -# define TS_ASSERT_PREDICATE(p,x) _TS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x) - -# define _ETSM_ASSERT_PREDICATE(f,l,m,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m)) -# define _TSM_ASSERT_PREDICATE(f,l,m,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m)) - -# define ETSM_ASSERT_PREDICATE(m,p,x) _ETSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x) -# define TSM_ASSERT_PREDICATE(m,p,x) _TSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x) - - // TS_ASSERT_RELATION -# define ___ETS_ASSERT_RELATION(f,l,r,x,y,m) \ - CxxTest::doAssertRelation( (f), (l), #r, r(), #x, (x), #y, (y), (m) ) -# define ___TS_ASSERT_RELATION(f,l,r,x,y,m) \ - { _TS_TRY { ___ETS_ASSERT_RELATION(f,l,r,x,y,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_RELATION(f,l,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,0) -# define _TS_ASSERT_RELATION(f,l,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,0) - -# define ETS_ASSERT_RELATION(r,x,y) _ETS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y) -# define TS_ASSERT_RELATION(r,x,y) _TS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y) - -# define _ETSM_ASSERT_RELATION(f,l,m,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m)) -# define _TSM_ASSERT_RELATION(f,l,m,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m)) - -# define ETSM_ASSERT_RELATION(m,r,x,y) _ETSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y) -# define TSM_ASSERT_RELATION(m,r,x,y) _TSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y) - - // TS_ASSERT_DELTA -# define ___ETS_ASSERT_DELTA(f,l,x,y,d,m) CxxTest::doAssertDelta( (f), (l), #x, (x), #y, (y), #d, (d), (m) ) -# define ___TS_ASSERT_DELTA(f,l,x,y,d,m) { _TS_TRY { ___ETS_ASSERT_DELTA(f,l,x,y,d,m); } __TS_CATCH(f,l) } - -# define _ETS_ASSERT_DELTA(f,l,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,0) -# define _TS_ASSERT_DELTA(f,l,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,0) - -# define ETS_ASSERT_DELTA(x,y,d) _ETS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d) -# define TS_ASSERT_DELTA(x,y,d) _TS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d) - -# define _ETSM_ASSERT_DELTA(f,l,m,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m)) -# define _TSM_ASSERT_DELTA(f,l,m,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m)) - -# define ETSM_ASSERT_DELTA(m,x,y,d) _ETSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d) -# define TSM_ASSERT_DELTA(m,x,y,d) _TSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d) - - // TS_ASSERT_THROWS -# define ___TS_ASSERT_THROWS(f,l,e,t,m) { \ - bool _ts_threw_expected = false, _ts_threw_else = false; \ - _TS_TRY { e; } \ - _TS_CATCH_TYPE( (t), { _ts_threw_expected = true; } ) \ - _TS_CATCH_ABORT( { throw; } ) \ - _TS_LAST_CATCH( { _ts_threw_else = true; } ) \ - if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } } - -# define _TS_ASSERT_THROWS(f,l,e,t) ___TS_ASSERT_THROWS(f,l,e,t,0) -# define TS_ASSERT_THROWS(e,t) _TS_ASSERT_THROWS(__FILE__,__LINE__,e,t) - -# define _TSM_ASSERT_THROWS(f,l,m,e,t) ___TS_ASSERT_THROWS(f,l,e,t,TS_AS_STRING(m)) -# define TSM_ASSERT_THROWS(m,e,t) _TSM_ASSERT_THROWS(__FILE__,__LINE__,m,e,t) - - // TS_ASSERT_THROWS_ASSERT -# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \ - bool _ts_threw_expected = false, _ts_threw_else = false; \ - _TS_TRY { e; } \ - _TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) \ - _TS_CATCH_ABORT( { throw; } ) \ - _TS_LAST_CATCH( { _ts_threw_else = true; } ) \ - if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } } - -# define _TS_ASSERT_THROWS_ASSERT(f,l,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,0) -# define TS_ASSERT_THROWS_ASSERT(e,t,a) _TS_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,e,t,a) - -# define _TSM_ASSERT_THROWS_ASSERT(f,l,m,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,TS_AS_STRING(m)) -# define TSM_ASSERT_THROWS_ASSERT(m,e,t,a) _TSM_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,m,e,t,a) - - // TS_ASSERT_THROWS_EQUALS -# define TS_ASSERT_THROWS_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_EQUALS(x,y)) -# define TSM_ASSERT_THROWS_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_EQUALS(m,x,y)) - - // TS_ASSERT_THROWS_DIFFERS -# define TS_ASSERT_THROWS_DIFFERS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DIFFERS(x,y)) -# define TSM_ASSERT_THROWS_DIFFERS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DIFFERS(m,x,y)) - - // TS_ASSERT_THROWS_DELTA -# define TS_ASSERT_THROWS_DELTA(e,t,x,y,d) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DELTA(x,y,d)) -# define TSM_ASSERT_THROWS_DELTA(m,e,t,x,y,d) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DELTA(m,x,y,d)) - - // TS_ASSERT_THROWS_SAME_DATA -# define TS_ASSERT_THROWS_SAME_DATA(e,t,x,y,s) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_SAME_DATA(x,y,s)) -# define TSM_ASSERT_THROWS_SAME_DATA(m,e,t,x,y,s) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_SAME_DATA(m,x,y,s)) - - // TS_ASSERT_THROWS_LESS_THAN -# define TS_ASSERT_THROWS_LESS_THAN(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN(x,y)) -# define TSM_ASSERT_THROWS_LESS_THAN(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN(m,x,y)) - - // TS_ASSERT_THROWS_LESS_THAN_EQUALS -# define TS_ASSERT_THROWS_LESS_THAN_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN_EQUALS(x,y)) -# define TSM_ASSERT_THROWS_LESS_THAN_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN_EQUALS(m,x,y)) - - // TS_ASSERT_THROWS_PREDICATE -# define TS_ASSERT_THROWS_PREDICATE(e,t,p,v) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_PREDICATE(p,v)) -# define TSM_ASSERT_THROWS_PREDICATE(m,e,t,p,v) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_PREDICATE(m,p,v)) - - // TS_ASSERT_THROWS_RELATION -# define TS_ASSERT_THROWS_RELATION(e,t,r,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_RELATION(r,x,y)) -# define TSM_ASSERT_THROWS_RELATION(m,e,t,r,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_RELATION(m,r,x,y)) - - // TS_ASSERT_THROWS_ANYTHING -# define ___TS_ASSERT_THROWS_ANYTHING(f,l,e,m) { \ - bool _ts_threw = false; \ - _TS_TRY { e; } \ - _TS_LAST_CATCH( { _ts_threw = true; } ) \ - if ( !_ts_threw ) { CxxTest::doFailAssertThrows( (f), (l), #e, "...", false, (m) ); } } - -# define _TS_ASSERT_THROWS_ANYTHING(f,l,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,0) -# define TS_ASSERT_THROWS_ANYTHING(e) _TS_ASSERT_THROWS_ANYTHING(__FILE__, __LINE__, e) - -# define _TSM_ASSERT_THROWS_ANYTHING(f,l,m,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,TS_AS_STRING(m)) -# define TSM_ASSERT_THROWS_ANYTHING(m,e) _TSM_ASSERT_THROWS_ANYTHING(__FILE__,__LINE__,m,e) - - // TS_ASSERT_THROWS_NOTHING -# define ___TS_ASSERT_THROWS_NOTHING(f,l,e,m) { \ - _TS_TRY { e; } \ - _TS_CATCH_ABORT( { throw; } ) \ - _TS_LAST_CATCH( { CxxTest::doFailAssertThrowsNot( (f), (l), #e, (m) ); } ) } - -# define _TS_ASSERT_THROWS_NOTHING(f,l,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,0) -# define TS_ASSERT_THROWS_NOTHING(e) _TS_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,e) - -# define _TSM_ASSERT_THROWS_NOTHING(f,l,m,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,TS_AS_STRING(m)) -# define TSM_ASSERT_THROWS_NOTHING(m,e) _TSM_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,m,e) - - - // - // This takes care of "signed <-> unsigned" warnings - // -# define CXXTEST_COMPARISONS(CXXTEST_X, CXXTEST_Y, CXXTEST_T) \ - inline bool equals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) == ((CXXTEST_T)y)); } \ - inline bool equals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) == ((CXXTEST_T)x)); } \ - inline bool differs( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) != ((CXXTEST_T)y)); } \ - inline bool differs( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) != ((CXXTEST_T)x)); } \ - inline bool lessThan( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) < ((CXXTEST_T)y)); } \ - inline bool lessThan( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) < ((CXXTEST_T)x)); } \ - inline bool lessThanEquals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) <= ((CXXTEST_T)y)); } \ - inline bool lessThanEquals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) <= ((CXXTEST_T)x)); } - -# define CXXTEST_INTEGRAL(CXXTEST_T) \ - CXXTEST_COMPARISONS( signed CXXTEST_T, unsigned CXXTEST_T, unsigned CXXTEST_T ) - - CXXTEST_INTEGRAL( char ) - CXXTEST_INTEGRAL( short ) - CXXTEST_INTEGRAL( int ) - CXXTEST_INTEGRAL( long ) -# ifdef _CXXTEST_LONGLONG - CXXTEST_INTEGRAL( _CXXTEST_LONGLONG ) -# endif // _CXXTEST_LONGLONG - -# define CXXTEST_SMALL_BIG(CXXTEST_SMALL, CXXTEST_BIG) \ - CXXTEST_COMPARISONS( signed CXXTEST_SMALL, unsigned CXXTEST_BIG, unsigned CXXTEST_BIG ) \ - CXXTEST_COMPARISONS( signed CXXTEST_BIG, unsigned CXXTEST_SMALL, unsigned CXXTEST_BIG ) - - CXXTEST_SMALL_BIG( char, short ) - CXXTEST_SMALL_BIG( char, int ) - CXXTEST_SMALL_BIG( short, int ) - CXXTEST_SMALL_BIG( char, long ) - CXXTEST_SMALL_BIG( short, long ) - CXXTEST_SMALL_BIG( int, long ) - -# ifdef _CXXTEST_LONGLONG - CXXTEST_SMALL_BIG( char, _CXXTEST_LONGLONG ) - CXXTEST_SMALL_BIG( short, _CXXTEST_LONGLONG ) - CXXTEST_SMALL_BIG( int, _CXXTEST_LONGLONG ) - CXXTEST_SMALL_BIG( long, _CXXTEST_LONGLONG ) -# endif // _CXXTEST_LONGLONG -} - -#endif // __cxxtest__TestSuite_h__ diff --git a/bsl/cxxtest/cxxtest/TestTracker.cpp b/bsl/cxxtest/cxxtest/TestTracker.cpp deleted file mode 100755 index f3ce781880b0e3c421149e6f2b548c29a7a2bda6..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestTracker.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#ifndef __cxxtest__TestTracker_cpp__ -#define __cxxtest__TestTracker_cpp__ - -#include - -namespace CxxTest -{ - bool TestTracker::_created = false; - - TestTracker::TestTracker() - { - if ( !_created ) { - initialize(); - _created = true; - } - } - - TestTracker::~TestTracker() - { - } - - TestTracker & TestTracker::tracker() - { - static TestTracker theTracker; - return theTracker; - } - - void TestTracker::initialize() - { - _warnings = 0; - _failedTests = 0; - _testFailedAsserts = 0; - _suiteFailedTests = 0; - _failedSuites = 0; - setListener( 0 ); - _world = 0; - _suite = 0; - _test = 0; - } - - const TestDescription *TestTracker::fixTest( const TestDescription *d ) const - { - return d ? d : &dummyTest(); - } - - const SuiteDescription *TestTracker::fixSuite( const SuiteDescription *d ) const - { - return d ? d : &dummySuite(); - } - - const WorldDescription *TestTracker::fixWorld( const WorldDescription *d ) const - { - return d ? d : &dummyWorld(); - } - - const TestDescription &TestTracker::dummyTest() const - { - return dummySuite().testDescription(0); - } - - const SuiteDescription &TestTracker::dummySuite() const - { - return dummyWorld().suiteDescription(0); - } - - const WorldDescription &TestTracker::dummyWorld() const - { - return _dummyWorld; - } - - void TestTracker::setListener( TestListener *l ) - { - _l = l ? l : &_dummyListener; - } - - void TestTracker::enterWorld( const WorldDescription &wd ) - { - setWorld( &wd ); - _warnings = _failedTests = _testFailedAsserts = _suiteFailedTests = _failedSuites = 0; - _l->enterWorld( wd ); - } - - void TestTracker::enterSuite( const SuiteDescription &sd ) - { - setSuite( &sd ); - _testFailedAsserts = _suiteFailedTests = 0; - _l->enterSuite(sd); - } - - void TestTracker::enterTest( const TestDescription &td ) - { - setTest( &td ); - _testFailedAsserts = false; - _l->enterTest(td); - } - - void TestTracker::leaveTest( const TestDescription &td ) - { - _l->leaveTest( td ); - setTest( 0 ); - } - - void TestTracker::leaveSuite( const SuiteDescription &sd ) - { - _l->leaveSuite( sd ); - setSuite( 0 ); - } - - void TestTracker::leaveWorld( const WorldDescription &wd ) - { - _l->leaveWorld( wd ); - setWorld( 0 ); - } - - void TestTracker::trace( const char *file, unsigned line, const char *expression ) - { - _l->trace( file, line, expression ); - } - - void TestTracker::warning( const char *file, unsigned line, const char *expression ) - { - countWarning(); - _l->warning( file, line, expression ); - } - - void TestTracker::failedTest( const char *file, unsigned line, const char *expression ) - { - countFailure(); - _l->failedTest( file, line, expression ); - } - - void TestTracker::failedAssert( const char *file, unsigned line, const char *expression ) - { - countFailure(); - _l->failedAssert( file, line, expression ); - } - - void TestTracker::failedAssertEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - countFailure(); - _l->failedAssertEquals( file, line, xStr, yStr, x, y ); - } - - void TestTracker::failedAssertSameData( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *sizeStr, const void *x, - const void *y, unsigned size ) - { - countFailure(); - _l->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, y, size ); - } - - void TestTracker::failedAssertDelta( const char *file, unsigned line, - const char *xStr, const char *yStr, const char *dStr, - const char *x, const char *y, const char *d ) - { - countFailure(); - _l->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d ); - } - - void TestTracker::failedAssertDiffers( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *value ) - { - countFailure(); - _l->failedAssertDiffers( file, line, xStr, yStr, value ); - } - - void TestTracker::failedAssertLessThan( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - countFailure(); - _l->failedAssertLessThan( file, line, xStr, yStr, x, y ); - } - - void TestTracker::failedAssertLessThanEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ) - { - countFailure(); - _l->failedAssertLessThanEquals( file, line, xStr, yStr, x, y ); - } - - void TestTracker::failedAssertPredicate( const char *file, unsigned line, - const char *predicate, const char *xStr, const char *x ) - { - countFailure(); - _l->failedAssertPredicate( file, line, predicate, xStr, x ); - } - - void TestTracker::failedAssertRelation( const char *file, unsigned line, - const char *relation, const char *xStr, const char *yStr, - const char *x, const char *y ) - { - countFailure(); - _l->failedAssertRelation( file, line, relation, xStr, yStr, x, y ); - } - - void TestTracker::failedAssertThrows( const char *file, unsigned line, - const char *expression, const char *type, - bool otherThrown ) - { - countFailure(); - _l->failedAssertThrows( file, line, expression, type, otherThrown ); - } - - void TestTracker::failedAssertThrowsNot( const char *file, unsigned line, const char *expression ) - { - countFailure(); - _l->failedAssertThrowsNot( file, line, expression ); - } - - void TestTracker::setWorld( const WorldDescription *w ) - { - _world = fixWorld( w ); - setSuite( 0 ); - } - - void TestTracker::setSuite( const SuiteDescription *s ) - { - _suite = fixSuite( s ); - setTest( 0 ); - } - - void TestTracker::setTest( const TestDescription *t ) - { - _test = fixTest( t ); - } - - void TestTracker::countWarning() - { - ++ _warnings; - } - - void TestTracker::countFailure() - { - if ( ++ _testFailedAsserts == 1 ) { - ++ _failedTests; - if ( ++ _suiteFailedTests == 1 ) - ++ _failedSuites; - } - } -}; - -#endif // __cxxtest__TestTracker_cpp__ diff --git a/bsl/cxxtest/cxxtest/TestTracker.h b/bsl/cxxtest/cxxtest/TestTracker.h deleted file mode 100755 index c85abff141aceec673da07db706479fa807f2438..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/TestTracker.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef __cxxtest__TestTracker_h__ -#define __cxxtest__TestTracker_h__ - -// -// The TestTracker tracks running tests -// The actual work is done in CountingListenerProxy, -// but this way avoids cyclic references TestListener<->CountingListenerProxy -// - -#include -#include - -namespace CxxTest -{ - class TestListener; - - class TestTracker : public TestListener - { - public: - virtual ~TestTracker(); - - static TestTracker &tracker(); - - const TestDescription *fixTest( const TestDescription *d ) const; - const SuiteDescription *fixSuite( const SuiteDescription *d ) const; - const WorldDescription *fixWorld( const WorldDescription *d ) const; - - const TestDescription &test() const { return *_test; } - const SuiteDescription &suite() const { return *_suite; } - const WorldDescription &world() const { return *_world; } - - bool testFailed() const { return (testFailedAsserts() > 0); } - bool suiteFailed() const { return (suiteFailedTests() > 0); } - bool worldFailed() const { return (failedSuites() > 0); } - - unsigned warnings() const { return _warnings; } - unsigned failedTests() const { return _failedTests; } - unsigned testFailedAsserts() const { return _testFailedAsserts; } - unsigned suiteFailedTests() const { return _suiteFailedTests; } - unsigned failedSuites() const { return _failedSuites; } - - void enterWorld( const WorldDescription &wd ); - void enterSuite( const SuiteDescription &sd ); - void enterTest( const TestDescription &td ); - void leaveTest( const TestDescription &td ); - void leaveSuite( const SuiteDescription &sd ); - void leaveWorld( const WorldDescription &wd ); - void trace( const char *file, unsigned line, const char *expression ); - void warning( const char *file, unsigned line, const char *expression ); - void failedTest( const char *file, unsigned line, const char *expression ); - void failedAssert( const char *file, unsigned line, const char *expression ); - void failedAssertEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ); - void failedAssertSameData( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *sizeStr, const void *x, - const void *y, unsigned size ); - void failedAssertDelta( const char *file, unsigned line, - const char *xStr, const char *yStr, const char *dStr, - const char *x, const char *y, const char *d ); - void failedAssertDiffers( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *value ); - void failedAssertLessThan( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ); - void failedAssertLessThanEquals( const char *file, unsigned line, - const char *xStr, const char *yStr, - const char *x, const char *y ); - void failedAssertPredicate( const char *file, unsigned line, - const char *predicate, const char *xStr, const char *x ); - void failedAssertRelation( const char *file, unsigned line, - const char *relation, const char *xStr, const char *yStr, - const char *x, const char *y ); - void failedAssertThrows( const char *file, unsigned line, - const char *expression, const char *type, - bool otherThrown ); - void failedAssertThrowsNot( const char *file, unsigned line, const char *expression ); - - private: - TestTracker( const TestTracker & ); - TestTracker &operator=( const TestTracker & ); - - static bool _created; - TestListener _dummyListener; - DummyWorldDescription _dummyWorld; - unsigned _warnings, _failedTests, _testFailedAsserts, _suiteFailedTests, _failedSuites; - TestListener *_l; - const WorldDescription *_world; - const SuiteDescription *_suite; - const TestDescription *_test; - - const TestDescription &dummyTest() const; - const SuiteDescription &dummySuite() const; - const WorldDescription &dummyWorld() const; - - void setWorld( const WorldDescription *w ); - void setSuite( const SuiteDescription *s ); - void setTest( const TestDescription *t ); - void countWarning(); - void countFailure(); - - friend class TestRunner; - - TestTracker(); - void initialize(); - void setListener( TestListener *l ); - }; - - inline TestTracker &tracker() { return TestTracker::tracker(); } -}; - -#endif // __cxxtest__TestTracker_h__ diff --git a/bsl/cxxtest/cxxtest/ValueTraits.cpp b/bsl/cxxtest/cxxtest/ValueTraits.cpp deleted file mode 100755 index 7d29ada9d2922694af6c066c16de26f915716311..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/ValueTraits.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef __cxxtest__ValueTraits_cpp__ -#define __cxxtest__ValueTraits_cpp__ - -#include - -namespace CxxTest -{ - // - // Non-inline functions from ValueTraits.h - // - - char digitToChar( unsigned digit ) - { - if ( digit < 10 ) - return (char)('0' + digit); - if ( digit <= 10 + 'Z' - 'A' ) - return (char)('A' + digit - 10); - return '?'; - } - - const char *byteToHex( unsigned char byte ) - { - static char asHex[3]; - asHex[0] = digitToChar( byte >> 4 ); - asHex[1] = digitToChar( byte & 0x0F ); - asHex[2] = '\0'; - return asHex; - } - - char *copyString( char *dst, const char *src ) - { - while ( (*dst = *src) != '\0' ) { - ++ dst; - ++ src; - } - return dst; - } - - bool stringsEqual( const char *s1, const char *s2 ) - { - char c; - while ( (c = *s1++) == *s2++ ) - if ( c == '\0' ) - return true; - return false; - } - - char *charToString( unsigned long c, char *s ) - { - switch( c ) { - case '\\': return copyString( s, "\\\\" ); - case '\"': return copyString( s, "\\\"" ); - case '\'': return copyString( s, "\\\'" ); - case '\0': return copyString( s, "\\0" ); - case '\a': return copyString( s, "\\a" ); - case '\b': return copyString( s, "\\b" ); - case '\n': return copyString( s, "\\n" ); - case '\r': return copyString( s, "\\r" ); - case '\t': return copyString( s, "\\t" ); - } - if ( c >= 32 && c <= 127 ) { - s[0] = (char)c; - s[1] = '\0'; - return s + 1; - } - else { - s[0] = '\\'; - s[1] = 'x'; - if ( c < 0x10 ) { - s[2] = '0'; - ++ s; - } - return numberToString( c, s + 2, 16UL ); - } - } - - char *charToString( char c, char *s ) - { - return charToString( (unsigned long)(unsigned char)c, s ); - } - - char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s ) - { - bool truncate = (numBytes > maxBytes); - if ( truncate ) - numBytes = maxBytes; - - s = copyString( s, "{ " ); - for ( unsigned i = 0; i < numBytes; ++ i, ++ bytes ) - s = copyString( copyString( s, byteToHex( *bytes ) ), " " ); - if ( truncate ) - s = copyString( s, "..." ); - return copyString( s, " }" ); - } - -#ifndef CXXTEST_USER_VALUE_TRAITS - unsigned ValueTraits::requiredDigitsOnLeft( double t ) - { - unsigned digits = 1; - for ( t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE ) - ++ digits; - return digits; - } - - char *ValueTraits::doNegative( double &t ) - { - if ( t >= 0 ) - return _asString; - _asString[0] = '-'; - t = -t; - return _asString + 1; - } - - void ValueTraits::hugeNumber( double t ) - { - char *s = doNegative( t ); - s = doubleToString( t, s, 0, 1 ); - s = copyString( s, "." ); - s = doubleToString( t, s, 1, DIGITS_ON_RIGHT ); - s = copyString( s, "E" ); - s = numberToString( requiredDigitsOnLeft( t ) - 1, s ); - } - - void ValueTraits::normalNumber( double t ) - { - char *s = doNegative( t ); - s = doubleToString( t, s ); - s = copyString( s, "." ); - for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i ) - s = numberToString( (unsigned)(t *= BASE) % BASE, s ); - } - - char *ValueTraits::doubleToString( double t, char *s, unsigned skip, unsigned max ) - { - return numberToString( t, s, BASE, skip, max ); - } -#endif // !CXXTEST_USER_VALUE_TRAITS -}; - -#endif // __cxxtest__ValueTraits_cpp__ diff --git a/bsl/cxxtest/cxxtest/ValueTraits.h b/bsl/cxxtest/cxxtest/ValueTraits.h deleted file mode 100755 index 71145ada7a22147634af63b6915c39b66c1ad742..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/ValueTraits.h +++ /dev/null @@ -1,377 +0,0 @@ -#ifndef __cxxtest__ValueTraits_h__ -#define __cxxtest__ValueTraits_h__ - -// -// ValueTraits are used by CxxTest to convert arbitrary -// values used in TS_ASSERT_EQUALS() to a string representation. -// -// This header file contains value traits for builtin integral types. -// To declare value traits for new types you should instantiate the class -// ValueTraits. -// - -#include - -#ifdef _CXXTEST_OLD_TEMPLATE_SYNTAX -# define CXXTEST_TEMPLATE_INSTANTIATION -#else // !_CXXTEST_OLD_TEMPLATE_SYNTAX -# define CXXTEST_TEMPLATE_INSTANTIATION template<> -#endif // _CXXTEST_OLD_TEMPLATE_SYNTAX - -namespace CxxTest -{ - // - // This is how we use the value traits - // -# define TS_AS_STRING(x) CxxTest::traits(x).asString() - - // - // Char representation of a digit - // - char digitToChar( unsigned digit ); - - // - // Convert byte value to hex digits - // Returns pointer to internal buffer - // - const char *byteToHex( unsigned char byte ); - - // - // Convert byte values to string - // Returns one past the copied data - // - char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s ); - - // - // Copy a string. - // Returns one past the end of the destination string - // Remember -- we can't use the standard library! - // - char *copyString( char *dst, const char *src ); - - // - // Compare two strings. - // Remember -- we can't use the standard library! - // - bool stringsEqual( const char *s1, const char *s2 ); - - // - // Represent a character value as a string - // Returns one past the end of the string - // This will be the actual char if printable or '\xXXXX' otherwise - // - char *charToString( unsigned long c, char *s ); - - // - // Prevent problems with negative (signed char)s - // - char *charToString( char c, char *s ); - - // - // The default ValueTraits class dumps up to 8 bytes as hex values - // - template - class ValueTraits - { - enum { MAX_BYTES = 8 }; - char _asString[sizeof("{ ") + sizeof("XX ") * MAX_BYTES + sizeof("... }")]; - - public: - ValueTraits( const T &t ) { bytesToString( (const unsigned char *)&t, sizeof(T), MAX_BYTES, _asString ); } - const char *asString( void ) const { return _asString; } - }; - - // - // traits( T t ) - // Creates an object of type ValueTraits - // - template - inline ValueTraits traits( T t ) - { - return ValueTraits( t ); - } - - // - // You can duplicate the implementation of an existing ValueTraits - // -# define CXXTEST_COPY_TRAITS(CXXTEST_NEW_CLASS, CXXTEST_OLD_CLASS) \ - CXXTEST_TEMPLATE_INSTANTIATION \ - class ValueTraits< CXXTEST_NEW_CLASS > \ - { \ - ValueTraits< CXXTEST_OLD_CLASS > _old; \ - public: \ - ValueTraits( CXXTEST_NEW_CLASS n ) : _old( (CXXTEST_OLD_CLASS)n ) {} \ - const char *asString( void ) const { return _old.asString(); } \ - } - - // - // Certain compilers need separate declarations for T and const T - // -# ifdef _CXXTEST_NO_COPY_CONST -# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) -# else // !_CXXTEST_NO_COPY_CONST -# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) CXXTEST_COPY_TRAITS(CXXTEST_CLASS, const CXXTEST_CLASS) -# endif // _CXXTEST_NO_COPY_CONST - - // - // Avoid compiler warnings about unsigned types always >= 0 - // - template inline bool negative( N n ) { return n < 0; } - template inline N abs( N n ) { return negative(n) ? -n : n; } - -# define CXXTEST_NON_NEGATIVE(Type) \ - CXXTEST_TEMPLATE_INSTANTIATION \ - inline bool negative( Type ) { return false; } \ - CXXTEST_TEMPLATE_INSTANTIATION \ - inline Type abs( Type value ) { return value; } - - CXXTEST_NON_NEGATIVE( bool ) - CXXTEST_NON_NEGATIVE( unsigned char ) - CXXTEST_NON_NEGATIVE( unsigned short int ) - CXXTEST_NON_NEGATIVE( unsigned int ) - CXXTEST_NON_NEGATIVE( unsigned long int ) -# ifdef _CXXTEST_LONGLONG - CXXTEST_NON_NEGATIVE( unsigned _CXXTEST_LONGLONG ) -# endif // _CXXTEST_LONGLONG - - // - // Represent (integral) number as a string - // Returns one past the end of the string - // Remember -- we can't use the standard library! - // - template - char *numberToString( N n, char *s, - N base = 10, - unsigned skipDigits = 0, - unsigned maxDigits = (unsigned)-1 ) - { - if ( negative(n) ) { - *s++ = '-'; - n = abs(n); - } - - N digit = 1; - while ( digit <= (n / base) ) - digit *= base; - N digitValue; - for ( ; digit >= 1 && skipDigits; n -= digit * digitValue, digit /= base, -- skipDigits ) - digitValue = (unsigned)(n / digit); - for ( ; digit >= 1 && maxDigits; n -= digit * digitValue, digit /= base, -- maxDigits ) - *s++ = digitToChar( (unsigned)(digitValue = (unsigned)(n / digit)) ); - - *s = '\0'; - return s; - } - - // - // All the specific ValueTraits follow. - // You can #define CXXTEST_USER_VALUE_TRAITS if you don't want them - // - -#ifndef CXXTEST_USER_VALUE_TRAITS - // - // ValueTraits: const char * const & - // This is used for printing strings, as in TS_FAIL( "Message" ) - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - ValueTraits &operator=( const ValueTraits & ); - const char *_asString; - - public: - ValueTraits( const char * const &value ) : _asString( value ) {} - ValueTraits( const ValueTraits &other ) : _asString( other._asString ) {} - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_TRAITS( const char *, const char * const & ); - CXXTEST_COPY_TRAITS( char *, const char * const & ); - - // - // ValueTraits: bool - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - bool _value; - - public: - ValueTraits( const bool value ) : _value( value ) {} - const char *asString( void ) const { return _value ? "true" : "false"; } - }; - - CXXTEST_COPY_CONST_TRAITS( bool ); - -# ifdef _CXXTEST_LONGLONG - // - // ValueTraits: signed long long - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - typedef _CXXTEST_LONGLONG T; - char _asString[2 + 3 * sizeof(T)]; - public: - ValueTraits( T t ) { numberToString( t, _asString ); } - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( signed _CXXTEST_LONGLONG ); - - // - // ValueTraits: unsigned long long - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - typedef unsigned _CXXTEST_LONGLONG T; - char _asString[1 + 3 * sizeof(T)]; - public: - ValueTraits( T t ) { numberToString( t, _asString ); } - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( unsigned _CXXTEST_LONGLONG ); -# endif // _CXXTEST_LONGLONG - - // - // ValueTraits: signed long - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - typedef signed long int T; - char _asString[2 + 3 * sizeof(T)]; - public: - ValueTraits( T t ) { numberToString( t, _asString ); } - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( signed long int ); - - // - // ValueTraits: unsigned long - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - typedef unsigned long int T; - char _asString[1 + 3 * sizeof(T)]; - public: - ValueTraits( T t ) { numberToString( t, _asString ); } - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( unsigned long int ); - - // - // All decimals are the same as the long version - // - - CXXTEST_COPY_TRAITS( const signed int, const signed long int ); - CXXTEST_COPY_TRAITS( const unsigned int, const unsigned long int ); - CXXTEST_COPY_TRAITS( const signed short int, const signed long int ); - CXXTEST_COPY_TRAITS( const unsigned short int, const unsigned long int ); - CXXTEST_COPY_TRAITS( const unsigned char, const unsigned long int ); - - CXXTEST_COPY_CONST_TRAITS( signed int ); - CXXTEST_COPY_CONST_TRAITS( unsigned int ); - CXXTEST_COPY_CONST_TRAITS( signed short int ); - CXXTEST_COPY_CONST_TRAITS( unsigned short int ); - CXXTEST_COPY_CONST_TRAITS( unsigned char ); - - // - // ValueTraits: char - // Returns 'x' for printable chars, '\x??' for others - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - char _asString[sizeof("'\\xXX'")]; - public: - ValueTraits( char c ) { copyString( charToString( c, copyString( _asString, "'" ) ), "'" ); } - const char *asString( void ) const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( char ); - - // - // ValueTraits: signed char - // Same as char, some compilers need it - // - CXXTEST_COPY_TRAITS( const signed char, const char ); - CXXTEST_COPY_CONST_TRAITS( signed char ); - - // - // ValueTraits: double - // - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - public: - ValueTraits( double t ) - { - ( requiredDigitsOnLeft( t ) > MAX_DIGITS_ON_LEFT ) ? - hugeNumber( t ) : - normalNumber( t ); - } - - const char *asString( void ) const { return _asString; } - - private: - enum { MAX_DIGITS_ON_LEFT = 24, DIGITS_ON_RIGHT = 4, BASE = 10 }; - char _asString[1 + MAX_DIGITS_ON_LEFT + 1 + DIGITS_ON_RIGHT + 1]; - - static unsigned requiredDigitsOnLeft( double t ); - char *doNegative( double &t ); - void hugeNumber( double t ); - void normalNumber( double t ); - char *doubleToString( double t, char *s, unsigned skip = 0, unsigned max = (unsigned)-1 ); - }; - - CXXTEST_COPY_CONST_TRAITS( double ); - - // - // ValueTraits: float - // - CXXTEST_COPY_TRAITS( const float, const double ); - CXXTEST_COPY_CONST_TRAITS( float ); -#endif // !CXXTEST_USER_VALUE_TRAITS -}; - -#ifdef _CXXTEST_HAVE_STD -# include -#endif // _CXXTEST_HAVE_STD - -// -// CXXTEST_ENUM_TRAITS -// -#define CXXTEST_ENUM_TRAITS( TYPE, VALUES ) \ - namespace CxxTest \ - { \ - CXXTEST_TEMPLATE_INSTANTIATION \ - class ValueTraits \ - { \ - TYPE _value; \ - char _fallback[sizeof("(" #TYPE ")") + 3 * sizeof(TYPE)]; \ - public: \ - ValueTraits( TYPE value ) { \ - _value = value; \ - numberToString( _value, copyString( _fallback, "(" #TYPE ")" ) ); \ - } \ - const char *asString( void ) const \ - { \ - switch ( _value ) \ - { \ - VALUES \ - default: return _fallback; \ - } \ - } \ - }; \ - } - -#define CXXTEST_ENUM_MEMBER( MEMBER ) \ - case MEMBER: return #MEMBER; - -#endif // __cxxtest__ValueTraits_h__ diff --git a/bsl/cxxtest/cxxtest/Win32Gui.h b/bsl/cxxtest/cxxtest/Win32Gui.h deleted file mode 100755 index 6b3e7583a5c2f0831d444c8b63e1bec6658aa06f..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/Win32Gui.h +++ /dev/null @@ -1,531 +0,0 @@ -#ifndef __cxxtest__Win32Gui_h__ -#define __cxxtest__Win32Gui_h__ - -// -// The Win32Gui displays a simple progress bar using the Win32 API. -// -// It accepts the following command line options: -// -minimized Start minimized, pop up on error -// -keep Don't close the window at the end -// -title TITLE Set the window caption -// -// If both -minimized and -keep are specified, GUI will only keep the -// window if it's in focus. -// -// N.B. If you're wondering why this class doesn't use any standard -// library or STL ( would have been nice) it's because it only -// uses "straight" Win32 API. -// - -#include - -#include -#include - -namespace CxxTest -{ - class Win32Gui : public GuiListener - { - public: - void enterGui( int &argc, char **argv ) - { - parseCommandLine( argc, argv ); - } - - void enterWorld( const WorldDescription &wd ) - { - getTotalTests( wd ); - _testsDone = 0; - startGuiThread(); - } - - void guiEnterSuite( const char *suiteName ) - { - showSuiteName( suiteName ); - reset( _suiteStart ); - } - - void guiEnterTest( const char *suiteName, const char *testName ) - { - ++ _testsDone; - setTestCaption( suiteName, testName ); - showTestName( testName ); - showTestsDone(); - progressBarMessage( PBM_STEPIT ); - reset( _testStart ); - } - - void yellowBar() - { - setColor( 255, 255, 0 ); - setIcon( IDI_WARNING ); - getTotalTests(); - } - - void redBar() - { - if ( _startMinimized ) - showMainWindow( SW_SHOWNORMAL ); - setColor( 255, 0, 0 ); - setIcon( IDI_ERROR ); - getTotalTests(); - } - - void leaveGui() - { - if ( keep() ) - { - showSummary(); - WaitForSingleObject( _gui, INFINITE ); - } - DestroyWindow( _mainWindow ); - } - - private: - const char *_title; - bool _startMinimized, _keep; - HANDLE _gui; - WNDCLASSEX _windowClass; - HWND _mainWindow, _progressBar, _statusBar; - HANDLE _canStartTests; - unsigned _numTotalTests, _testsDone; - char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]; - enum { - STATUS_SUITE_NAME, STATUS_SUITE_TIME, - STATUS_TEST_NAME, STATUS_TEST_TIME, - STATUS_TESTS_DONE, STATUS_WORLD_TIME, - STATUS_TOTAL_PARTS - }; - int _statusWidths[STATUS_TOTAL_PARTS]; - unsigned _statusOffsets[STATUS_TOTAL_PARTS]; - unsigned _statusTotal; - char _statusTestsDone[sizeof("1000000000 of (100%)") + WorldDescription::MAX_STRLEN_TOTAL_TESTS]; - DWORD _worldStart, _suiteStart, _testStart; - char _timeString[sizeof("00:00:00")]; - - void parseCommandLine( int argc, char **argv ) - { - _startMinimized = _keep = false; - _title = argv[0]; - - for ( int i = 1; i < argc; ++ i ) - { - if ( !lstrcmpA( argv[i], "-minimized" ) ) - _startMinimized = true; - else if ( !lstrcmpA( argv[i], "-keep" ) ) - _keep = true; - else if ( !lstrcmpA( argv[i], "-title" ) && (i + 1 < argc) ) - _title = argv[++i]; - } - } - - void getTotalTests() - { - getTotalTests( tracker().world() ); - } - - void getTotalTests( const WorldDescription &wd ) - { - _numTotalTests = wd.numTotalTests(); - wd.strTotalTests( _strTotalTests ); - } - - void startGuiThread() - { - _canStartTests = CreateEvent( NULL, TRUE, FALSE, NULL ); - DWORD threadId; - _gui = CreateThread( NULL, 0, &(Win32Gui::guiThread), (LPVOID)this, 0, &threadId ); - WaitForSingleObject( _canStartTests, INFINITE ); - } - - static DWORD WINAPI guiThread( LPVOID parameter ) - { - ((Win32Gui *)parameter)->gui(); - return 0; - } - - void gui() - { - registerWindowClass(); - createMainWindow(); - initCommonControls(); - createProgressBar(); - createStatusBar(); - centerMainWindow(); - showMainWindow(); - startTimer(); - startTests(); - - messageLoop(); - } - - void registerWindowClass() - { - _windowClass.cbSize = sizeof(_windowClass); - _windowClass.style = CS_HREDRAW | CS_VREDRAW; - _windowClass.lpfnWndProc = &(Win32Gui::windowProcedure); - _windowClass.cbClsExtra = 0; - _windowClass.cbWndExtra = sizeof(LONG); - _windowClass.hInstance = (HINSTANCE)NULL; - _windowClass.hIcon = (HICON)NULL; - _windowClass.hCursor = (HCURSOR)NULL; - _windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - _windowClass.lpszMenuName = NULL; - _windowClass.lpszClassName = TEXT("CxxTest Window Class"); - _windowClass.hIconSm = (HICON)NULL; - - RegisterClassEx( &_windowClass ); - } - - void createMainWindow() - { - _mainWindow = createWindow( _windowClass.lpszClassName, WS_OVERLAPPEDWINDOW ); - } - - void initCommonControls() - { - HMODULE dll = LoadLibraryA( "comctl32.dll" ); - if ( !dll ) - return; - - typedef void (WINAPI *FUNC)( void ); - FUNC func = (FUNC)GetProcAddress( dll, "InitCommonControls" ); - if ( !func ) - return; - - func(); - } - - void createProgressBar() - { - _progressBar = createWindow( PROGRESS_CLASS, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, _mainWindow ); - -#ifdef PBM_SETRANGE32 - progressBarMessage( PBM_SETRANGE32, 0, _numTotalTests ); -#else // No PBM_SETRANGE32, use PBM_SETRANGE - progressBarMessage( PBM_SETRANGE, 0, MAKELPARAM( 0, (WORD)_numTotalTests ) ); -#endif // PBM_SETRANGE32 - progressBarMessage( PBM_SETPOS, 0 ); - progressBarMessage( PBM_SETSTEP, 1 ); - greenBar(); - UpdateWindow( _progressBar ); - } - - void createStatusBar() - { - _statusBar = createWindow( STATUSCLASSNAME, WS_CHILD | WS_VISIBLE, _mainWindow ); - setRatios( 4, 1, 3, 1, 3, 1 ); - } - - void setRatios( unsigned suiteNameRatio, unsigned suiteTimeRatio, - unsigned testNameRatio, unsigned testTimeRatio, - unsigned testsDoneRatio, unsigned worldTimeRatio ) - { - _statusTotal = 0; - _statusOffsets[STATUS_SUITE_NAME] = (_statusTotal += suiteNameRatio); - _statusOffsets[STATUS_SUITE_TIME] = (_statusTotal += suiteTimeRatio); - _statusOffsets[STATUS_TEST_NAME] = (_statusTotal += testNameRatio); - _statusOffsets[STATUS_TEST_TIME] = (_statusTotal += testTimeRatio); - _statusOffsets[STATUS_TESTS_DONE] = (_statusTotal += testsDoneRatio); - _statusOffsets[STATUS_WORLD_TIME] = (_statusTotal += worldTimeRatio); - } - - HWND createWindow( LPCTSTR className, DWORD style, HWND parent = (HWND)NULL ) - { - return CreateWindow( className, NULL, style, 0, 0, 0, 0, parent, - (HMENU)NULL, (HINSTANCE)NULL, (LPVOID)this ); - } - - void progressBarMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 ) - { - SendMessage( _progressBar, message, wParam, lParam ); - } - - void centerMainWindow() - { - RECT screen; - getScreenArea( screen ); - - LONG screenWidth = screen.right - screen.left; - LONG screenHeight = screen.bottom - screen.top; - - LONG xCenter = (screen.right + screen.left) / 2; - LONG yCenter = (screen.bottom + screen.top) / 2; - - LONG windowWidth = (screenWidth * 4) / 5; - LONG windowHeight = screenHeight / 10; - LONG minimumHeight = 2 * (GetSystemMetrics( SM_CYCAPTION ) + GetSystemMetrics( SM_CYFRAME )); - if ( windowHeight < minimumHeight ) - windowHeight = minimumHeight; - - SetWindowPos( _mainWindow, HWND_TOP, - xCenter - (windowWidth / 2), yCenter - (windowHeight / 2), - windowWidth, windowHeight, 0 ); - } - - void getScreenArea( RECT &area ) - { - if ( !getScreenAreaWithoutTaskbar( area ) ) - getWholeScreenArea( area ); - } - - bool getScreenAreaWithoutTaskbar( RECT &area ) - { - return (SystemParametersInfo( SPI_GETWORKAREA, sizeof(RECT), &area, 0 ) != 0); - } - - void getWholeScreenArea( RECT &area ) - { - area.left = area.top = 0; - area.right = GetSystemMetrics( SM_CXSCREEN ); - area.bottom = GetSystemMetrics( SM_CYSCREEN ); - } - - void showMainWindow() - { - showMainWindow( _startMinimized ? SW_MINIMIZE : SW_SHOWNORMAL ); - UpdateWindow( _mainWindow ); - } - - void showMainWindow( int mode ) - { - ShowWindow( _mainWindow, mode ); - } - - enum { TIMER_ID = 1, TIMER_DELAY = 1000 }; - - void startTimer() - { - reset( _worldStart ); - reset( _suiteStart ); - reset( _testStart ); - SetTimer( _mainWindow, TIMER_ID, TIMER_DELAY, 0 ); - } - - void reset( DWORD &tick ) - { - tick = GetTickCount(); - } - - void startTests() - { - SetEvent( _canStartTests ); - } - - void messageLoop() - { - MSG message; - while ( BOOL haveMessage = GetMessage( &message, NULL, 0, 0 ) ) - if ( haveMessage != -1 ) - DispatchMessage( &message ); - } - - static LRESULT CALLBACK windowProcedure( HWND window, UINT message, WPARAM wParam, LPARAM lParam ) - { - if ( message == WM_CREATE ) - setUp( window, (LPCREATESTRUCT)lParam ); - - Win32Gui *that = (Win32Gui *)GetWindowLong( window, GWL_USERDATA ); - return that->handle( window, message, wParam, lParam ); - } - - static void setUp( HWND window, LPCREATESTRUCT create ) - { - SetWindowLong( window, GWL_USERDATA, (LONG)create->lpCreateParams ); - } - - LRESULT handle( HWND window, UINT message, WPARAM wParam, LPARAM lParam ) - { - switch ( message ) - { - case WM_SIZE: resizeControls(); break; - - case WM_TIMER: updateTime(); break; - - case WM_CLOSE: - case WM_DESTROY: - case WM_QUIT: - ExitProcess( 0 ); - - default: return DefWindowProc( window, message, wParam, lParam ); - } - return 0; - } - - void resizeControls() - { - RECT r; - GetClientRect( _mainWindow, &r ); - LONG width = r.right - r.left; - LONG height = r.bottom - r.top; - - GetClientRect( _statusBar, &r ); - LONG statusHeight = r.bottom - r.top; - LONG resizeGripWidth = statusHeight; - LONG progressHeight = height - statusHeight; - - SetWindowPos( _progressBar, HWND_TOP, 0, 0, width, progressHeight, 0 ); - SetWindowPos( _statusBar, HWND_TOP, 0, progressHeight, width, statusHeight, 0 ); - setStatusParts( width - resizeGripWidth ); - } - - void setStatusParts( LONG width ) - { - for ( unsigned i = 0; i < STATUS_TOTAL_PARTS; ++ i ) - _statusWidths[i] = (width * _statusOffsets[i]) / _statusTotal; - - statusBarMessage( SB_SETPARTS, STATUS_TOTAL_PARTS, _statusWidths ); - } - - void statusBarMessage( UINT message, WPARAM wParam = 0, const void *lParam = 0 ) - { - SendMessage( _statusBar, message, wParam, (LPARAM)lParam ); - } - - void greenBar() - { - setColor( 0, 255, 0 ); - setIcon( IDI_INFORMATION ); - } - -#ifdef PBM_SETBARCOLOR - void setColor( BYTE red, BYTE green, BYTE blue ) - { - progressBarMessage( PBM_SETBARCOLOR, 0, RGB( red, green, blue ) ); - } -#else // !PBM_SETBARCOLOR - void setColor( BYTE, BYTE, BYTE ) - { - } -#endif // PBM_SETBARCOLOR - - void setIcon( LPCTSTR icon ) - { - SendMessage( _mainWindow, WM_SETICON, ICON_BIG, (LPARAM)loadStandardIcon( icon ) ); - } - - HICON loadStandardIcon( LPCTSTR icon ) - { - return LoadIcon( (HINSTANCE)NULL, icon ); - } - - void setTestCaption( const char *suiteName, const char *testName ) - { - setCaption( suiteName, "::", testName, "()" ); - } - - void setCaption( const char *a = "", const char *b = "", const char *c = "", const char *d = "" ) - { - unsigned length = lstrlenA( _title ) + sizeof( " - " ) + - lstrlenA( a ) + lstrlenA( b ) + lstrlenA( c ) + lstrlenA( d ); - char *name = allocate( length ); - lstrcpyA( name, _title ); - lstrcatA( name, " - " ); - lstrcatA( name, a ); - lstrcatA( name, b ); - lstrcatA( name, c ); - lstrcatA( name, d ); - SetWindowTextA( _mainWindow, name ); - deallocate( name ); - } - - void showSuiteName( const char *suiteName ) - { - setStatusPart( STATUS_SUITE_NAME, suiteName ); - } - - void showTestName( const char *testName ) - { - setStatusPart( STATUS_TEST_NAME, testName ); - } - - void showTestsDone() - { - wsprintfA( _statusTestsDone, "%u of %s (%u%%)", - _testsDone, _strTotalTests, - (_testsDone * 100) / _numTotalTests ); - setStatusPart( STATUS_TESTS_DONE, _statusTestsDone ); - } - - void updateTime() - { - setStatusTime( STATUS_WORLD_TIME, _worldStart ); - setStatusTime( STATUS_SUITE_TIME, _suiteStart ); - setStatusTime( STATUS_TEST_TIME, _testStart ); - } - - void setStatusTime( unsigned part, DWORD start ) - { - unsigned total = (GetTickCount() - start) / 1000; - unsigned hours = total / 3600; - unsigned minutes = (total / 60) % 60; - unsigned seconds = total % 60; - - if ( hours ) - wsprintfA( _timeString, "%u:%02u:%02u", hours, minutes, seconds ); - else - wsprintfA( _timeString, "%02u:%02u", minutes, seconds ); - - setStatusPart( part, _timeString ); - } - - bool keep() - { - if ( !_keep ) - return false; - if ( !_startMinimized ) - return true; - return (_mainWindow == GetForegroundWindow()); - } - - void showSummary() - { - stopTimer(); - setSummaryStatusBar(); - setSummaryCaption(); - } - - void setStatusPart( unsigned part, const char *text ) - { - statusBarMessage( SB_SETTEXTA, part, text ); - } - - void stopTimer() - { - KillTimer( _mainWindow, TIMER_ID ); - setStatusTime( STATUS_WORLD_TIME, _worldStart ); - } - - void setSummaryStatusBar() - { - setRatios( 0, 0, 0, 0, 1, 1 ); - resizeControls(); - - const char *tests = (_numTotalTests == 1) ? "test" : "tests"; - if ( tracker().failedTests() ) - wsprintfA( _statusTestsDone, "Failed %u of %s %s", - tracker().failedTests(), _strTotalTests, tests ); - else - wsprintfA( _statusTestsDone, "%s %s passed", _strTotalTests, tests ); - - setStatusPart( STATUS_TESTS_DONE, _statusTestsDone ); - } - - void setSummaryCaption() - { - setCaption( _statusTestsDone ); - } - - char *allocate( unsigned length ) - { - return (char *)HeapAlloc( GetProcessHeap(), 0, length ); - } - - void deallocate( char *data ) - { - HeapFree( GetProcessHeap(), 0, data ); - } - }; -}; - -#endif // __cxxtest__Win32Gui_h__ diff --git a/bsl/cxxtest/cxxtest/X11Gui.h b/bsl/cxxtest/cxxtest/X11Gui.h deleted file mode 100755 index f14431d94ffcbeec0e7e10c0d7a2370e336681bb..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/X11Gui.h +++ /dev/null @@ -1,327 +0,0 @@ -#ifndef __cxxtest__X11Gui_h__ -#define __cxxtest__X11Gui_h__ - -// -// X11Gui displays a simple progress bar using X11 -// -// It accepts the following command-line arguments: -// -title - Sets the application title -// -fn or -font <font> - Sets the font -// -bg or -background <color> - Sets the background color (default=Grey) -// -fg or -foreground <color> - Sets the text color (default=Black) -// -green/-yellow/-red <color> - Sets the colors of the bar -// - -#include <cxxtest/Gui.h> - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -namespace CxxTest -{ - class X11Gui : public GuiListener - { - public: - void enterGui( int &argc, char **argv ) - { - parseCommandLine( argc, argv ); - } - - void enterWorld( const WorldDescription &wd ) - { - openDisplay(); - if ( _display ) { - createColors(); - createWindow(); - createGc(); - createFont(); - centerWindow(); - initializeEvents(); - initializeBar( wd ); - processEvents(); - } - } - - void guiEnterTest( const char *suiteName, const char *testName ) - { - if ( _display ) { - ++ _testsDone; - setWindowName( suiteName, testName ); - redraw(); - } - } - - void yellowBar() - { - if ( _display ) { - _barColor = getColor( _yellowName ); - getTotalTests(); - processEvents(); - } - } - - void redBar() - { - if ( _display ) { - _barColor = getColor( _redName ); - getTotalTests(); - processEvents(); - } - } - - void leaveGui() - { - if ( _display ) { - freeFontInfo(); - destroyGc(); - destroyWindow(); - closeDisplay(); - } - } - - private: - const char *_programName; - Display *_display; - Window _window; - unsigned _numTotalTests, _testsDone; - char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]; - const char *_foregroundName, *_backgroundName; - const char *_greenName, *_yellowName, *_redName; - unsigned long _foreground, _background, _barColor; - int _width, _height; - GC _gc; - const char *_fontName; - XID _fontId; - XFontStruct *_fontInfo; - int _textHeight, _textDescent; - long _eventMask; - Colormap _colormap; - - void parseCommandLine( int &argc, char **argv ) - { - _programName = argv[0]; - - _fontName = 0; - _foregroundName = "Black"; - _backgroundName = "Grey"; - _greenName = "Green"; - _yellowName = "Yellow"; - _redName = "Red"; - - for ( int i = 1; i + 1 < argc; ++ i ) { - if ( !strcmp( argv[i], "-title" ) ) - _programName = argv[++ i]; - else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) ) - _fontName = argv[++ i]; - else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) ) - _foregroundName = argv[++ i]; - else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) ) - _backgroundName = argv[++ i]; - else if ( !strcmp( argv[i], "-green" ) ) - _greenName = argv[++ i]; - else if ( !strcmp( argv[i], "-yellow" ) ) - _yellowName = argv[++ i]; - else if ( !strcmp( argv[i], "-red" ) ) - _redName = argv[++ i]; - } - } - - void openDisplay() - { - _display = XOpenDisplay( NULL ); - } - - void createColors() - { - _colormap = DefaultColormap( _display, 0 ); - _foreground = getColor( _foregroundName ); - _background = getColor( _backgroundName ); - } - - unsigned long getColor( const char *colorName ) - { - XColor color; - XParseColor( _display, _colormap, colorName, &color ); - XAllocColor( _display, _colormap, &color ); - return color.pixel; - } - - void createWindow() - { - _window = XCreateSimpleWindow( _display, RootWindow( _display, 0 ), 0, 0, 1, 1, 0, 0, _background ); - } - - void createGc() - { - _gc = XCreateGC( _display, _window, 0, 0 ); - } - - void createFont() - { - if ( !loadFont() ) - useDefaultFont(); - getFontInfo(); - _textHeight = _fontInfo->ascent + _fontInfo->descent; - _textDescent = _fontInfo->descent; - } - - bool loadFont() - { - if ( !_fontName ) - return false; - _fontId = XLoadFont( _display, _fontName ); - return (XSetFont( _display, _gc, _fontId ) == Success); - } - - void useDefaultFont() - { - _fontId = XGContextFromGC( _gc ); - } - - void getFontInfo() - { - _fontInfo = XQueryFont( _display, _fontId ); - } - - void freeFontInfo() - { - XFreeFontInfo( NULL, _fontInfo, 1 ); - } - - void initializeEvents() - { - _eventMask = ExposureMask; - XSelectInput( _display, _window, _eventMask ); - } - - void initializeBar( const WorldDescription &wd ) - { - getTotalTests( wd ); - _testsDone = 0; - _barColor = getColor( _greenName ); - } - - void getTotalTests() - { - getTotalTests( tracker().world() ); - } - - void getTotalTests( const WorldDescription &wd ) - { - _numTotalTests = wd.numTotalTests(); - wd.strTotalTests( _strTotalTests ); - } - - void centerWindow() - { - XMapWindow( _display, _window ); - - Screen *screen = XDefaultScreenOfDisplay( _display ); - int screenWidth = WidthOfScreen( screen ); - int screenHeight = HeightOfScreen( screen ); - int xCenter = screenWidth / 2; - int yCenter = screenHeight / 2; - - _width = (screenWidth * 4) / 5; - _height = screenHeight / 14; - - XMoveResizeWindow( _display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height ); - } - - void processEvents() - { - redraw(); - - XEvent event; - while( XCheckMaskEvent( _display, _eventMask, &event ) ) - redraw(); - } - - void setWindowName( const char *suiteName, const char *testName ) - { - unsigned length = strlen( _programName ) + strlen( suiteName ) + strlen( testName ) + sizeof( " - ::()" ); - char *name = (char *)malloc( length ); - sprintf( name, "%s - %s::%s()", _programName, suiteName, testName ); - XSetStandardProperties( _display, _window, name, 0, 0, 0, 0, 0 ); - free( name ); - } - - void redraw() - { - getWindowSize(); - drawSolidBar(); - drawDividers(); - drawPercentage(); - flush(); - } - - void getWindowSize() - { - XWindowAttributes attributes; - XGetWindowAttributes( _display, _window, &attributes ); - _width = attributes.width; - _height = attributes.height; - } - - void drawSolidBar() - { - unsigned barWidth = (_width * _testsDone) / _numTotalTests; - - XSetForeground( _display, _gc, _barColor ); - XFillRectangle( _display, _window, _gc, 0, 0, barWidth, _height ); - - XSetForeground( _display, _gc, _background ); - XFillRectangle( _display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height ); - } - - void drawDividers() - { - if(_width / _numTotalTests < 5) - return; - for ( unsigned i = 1; i < _testsDone; ++ i ) { - int x = (_width * i) / _numTotalTests; - XDrawLine( _display, _window, _gc, x, 0, x, _height); - } - } - - void drawPercentage() - { - XSetForeground( _display, _gc, _foreground ); - - char str[sizeof("1000000000 of ") + sizeof(_strTotalTests) + sizeof(" (100%)")]; - sprintf( str, "%u of %s (%u%%)", _testsDone, _strTotalTests, (_testsDone * 100) / _numTotalTests ); - unsigned len = strlen( str ); - - int textWidth = XTextWidth( _fontInfo, str, len ); - - XDrawString( _display, _window, _gc, - (_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent, - str, len ); - } - - void flush() - { - XFlush( _display ); - } - - void destroyGc() - { - XFreeGC( _display, _gc ); - } - - void destroyWindow() - { - XDestroyWindow( _display, _window ); - } - - void closeDisplay() - { - XCloseDisplay( _display ); - } - }; -}; - -#endif //__cxxtest__X11Gui_h__ diff --git a/bsl/cxxtest/cxxtest/YesNoRunner.h b/bsl/cxxtest/cxxtest/YesNoRunner.h deleted file mode 100755 index e7b83b6bb841e7632cb424dfa5740cb70382c216..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtest/YesNoRunner.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __cxxtest__YesNoRunner_h__ -#define __cxxtest__YesNoRunner_h__ - -// -// The YesNoRunner is a simple TestListener that -// just returns true iff all tests passed. -// - -#include <cxxtest/TestRunner.h> -#include <cxxtest/TestListener.h> - -namespace CxxTest -{ - class YesNoRunner : public TestListener - { - public: - YesNoRunner() - { - } - - int run() - { - TestRunner::runAllTests( *this ); - return tracker().failedTests(); - } - }; -} - -#endif // __cxxtest__YesNoRunner_h__ diff --git a/bsl/cxxtest/cxxtestgen.pl b/bsl/cxxtest/cxxtestgen.pl deleted file mode 100755 index 378b0a38e518e307fbb7a541d711dbbf2c09a125..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtestgen.pl +++ /dev/null @@ -1,551 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use Getopt::Long; - -sub usage() { - print STDERR "Usage: $0 [OPTIONS] <input file(s)>\n"; - print STDERR "Generate test source file for CxxTest.\n"; - print STDERR "\n"; - print STDERR " -v, --version Write CxxTest version\n"; - print STDERR " -o, --output=NAME Write output to file NAME\n"; - print STDERR " --runner=CLASS Create a main() function that runs CxxTest::CLASS\n"; - print STDERR " --gui=CLASS Like --runner, with GUI component\n"; - print STDERR " --error-printer Same as --runner=ErrorPrinter\n"; - print STDERR " --abort-on-fail Abort tests on failed asserts (like xUnit)\n"; - print STDERR " --have-std Use standard library (even if not found in tests)\n"; - print STDERR " --no-std Don't use standard library (even if found in tests)\n"; - print STDERR " --have-eh Use exception handling (even if not found in tests)\n"; - print STDERR " --no-eh Don't use exception handling (even if found in tests)\n"; - print STDERR " --longlong=[TYPE] Use TYPE as `long long' (defaut = long long)\n"; - print STDERR " --template=TEMPLATE Use TEMPLATE file to generate the test runner\n"; - print STDERR " --include=HEADER Include \"HEADER\" in test runner before other headers\n"; - print STDERR " --root Write CxxTest globals\n"; - print STDERR " --part Don't write CxxTest globals\n"; - print STDERR " --no-static-init Don't rely on static initialization\n"; - exit -1; -} - -main(); - -sub main { - parseCommandline(); - scanInputFiles(); - writeOutput(); -} - -# -# Handling the command line -# - -my ($output, $runner, $gui, $template, $abortOnFail, $haveEh, $noEh, $haveStd, $noStd); -my ($root, $part, $noStaticInit, $longlong, $factor); -my @headers = (); - -sub parseCommandline() { - @ARGV = expandWildcards(@ARGV); - GetOptions( 'version' => \&printVersion, - 'output=s' => \$output, - 'template=s' => \$template, - 'runner=s' => \$runner, - 'gui=s', => \$gui, - 'error-printer' => sub { $runner = 'ErrorPrinter'; $haveStd = 1; }, - 'abort-on-fail' => \$abortOnFail, - 'have-eh' => \$haveEh, - 'no-eh' => \$noEh, - 'have-std' => \$haveStd, - 'no-std' => \$noStd, - 'include=s' => \@headers, - 'root' => \$root, - 'part' => \$part, - 'no-static-init' => \$noStaticInit, - 'factor' => \$factor, - 'longlong:s' => \$longlong - ) or usage(); - scalar @ARGV or $root or usage(); - - if ( defined($noStaticInit) && (defined($root) || defined($part)) ) { - die "--no-static-init cannot be used with --root/--part\n"; - } - - if ( $gui && !$runner ) { - $runner = 'StdioPrinter'; - } - - if ( defined($longlong) && !$longlong ) { - $longlong = 'long long'; - } - - foreach my $header (@headers) { - if ( !($header =~ m/^["<].*[>"]$/) ) { - $header = "\"$header\""; - } - } -} - -sub printVersion() { - print "This is CxxTest version 3.10.1.\n"; - exit 0; -} - -sub expandWildcards() { - my @result = (); - while( my $fn = shift @_ ) { - push @result, glob($fn); - } - return @result; -} - -# -# Reading the input files and scanning for test cases -# - -my (@suites, $suite, $test, $inBlock); -my $numTotalTests = 0; - -sub scanInputFiles() { - foreach my $file (@ARGV) { - scanInputFile( $file ); - } - scalar @suites or $root or die("No tests defined\n"); -} - -sub scanInputFile($) { - my ($file) = @_; - open FILE, "<$file" or die("Cannot open input file \"$file\"\n"); - - my $line; - while (defined($line = <FILE>)) { - scanLineForExceptionHandling( $line ); - scanLineForStandardLibrary( $line ); - - scanLineForSuiteStart( $file, $., $line ); - - if ( $suite ) { - if ( lineBelongsToSuite( $suite, $., $line ) ) { - scanLineForTest( $., $line ); - scanLineForCreate( $., $line ); - scanLineForDestroy( $., $line ); - } - } - } - closeSuite(); - close FILE; -} - -sub lineBelongsToSuite($$$) { - my ($suite, $lineNo, $line) = @_; - if ( !$suite->{'generated'} ) { - return 1; - } - - if ( !$inBlock ) { - $inBlock = lineStartsBlock( $line ); - } - if ( $inBlock ) { - addLineToBlock( $suite->{'file'}, $lineNo, $line ); - } - return $inBlock; -} - -sub scanLineForExceptionHandling($) { - my ($line) = @_; - if ( $line =~ m/\b(try|throw|catch|TSM?_ASSERT_THROWS[A-Z_]*)\b/ ) { - addExceptionHandling(); - } -} - -sub scanLineForStandardLibrary($) { - my ($line) = @_; - if ( $line =~ m/\b(std\s*::|CXXTEST_STD|using\s+namespace\s+std\b|^\s*\#\s*include\s+<[a-z0-9]+>)/ ) { - addStandardLibrary(); - } -} - -sub scanLineForSuiteStart($$$) { - my ($fileName, $lineNo, $line) = @_; - if ( $line =~ m/\bclass\s+(\w+)\s*:\s*public\s+((::)?\s*CxxTest\s*::\s*)?TestSuite\b/ ) { - startSuite( $1, $fileName, $lineNo, 0 ); - } - if ( $line =~ m/\bCXXTEST_SUITE\s*\(\s*(\w*)\s*\)/ ) { - print "$fileName:$lineNo: Warning: Inline test suites are deprecated.\n"; - startSuite( $1, $fileName, $lineNo, 1 ); - } -} - -sub startSuite($$$$) { - my ($name, $file, $line, $generated) = @_; - closeSuite(); - $suite = { 'name' => $name, - 'file' => $file, - 'line' => $line, - 'generated' => $generated, - 'create' => 0, - 'destroy' => 0, - 'tests' => [], - 'lines' => [] }; -} - -sub lineStartsBlock($) { - my ($line) = @_; - return $line =~ m/\bCXXTEST_CODE\s*\(/; -} - -sub scanLineForTest($$) { - my ($lineNo, $line) = @_; - if ( $line =~ m/^([^\/]|\/[^\/])*\bvoid\s+([Tt]est\w+)\s*\(\s*(void)?\s*\)/ ) { - addTest( $2, $lineNo ); - } -} - -sub addTest($$$) { - my ($name, $line) = @_; - $test = { 'name' => $name, - 'line' => $line }; - push @{suiteTests()}, $test; -} - -sub addLineToBlock($$$) { - my ($fileName, $lineNo, $line) = @_; - $line = fixBlockLine( $fileName, $lineNo, $line ); - $line =~ s/^.*\{\{//; - my $end = ($line =~ s/\}\}.*//s); - push @{$suite->{'lines'}}, $line; - if ( $end ) { - $inBlock = 0; - } -} - -sub fixBlockLine($$$) { - my ($fileName, $lineNo, $line) = @_; - my $fileLine = cstr($fileName) . "," . $lineNo; - $line =~ s/\b(E?TSM?_(ASSERT[A-Z_]*|FAIL))\s*\(/_$1($fileLine,/g; - return $line; -} - -sub scanLineForCreate($$) { - my ($lineNo, $line) = @_; - if ( $line =~ m/\bstatic\s+\w+\s*\*\s*createSuite\s*\(\s*(void)?\s*\)/ ) { - addCreateSuite( $lineNo ); - } -} - -sub scanLineForDestroy($$) { - my ($lineNo, $line) = @_; - if ( $line =~ m/\bstatic\s+void\s+destroySuite\s*\(\s*\w+\s*\*\s*\w*\s*\)/ ) { - addDestroySuite( $lineNo ); - } -} - -sub closeSuite() { - if ( $suite && scalar @{suiteTests()} ) { - verifySuite(); - rememberSuite(); - } - undef $suite; -} - -sub addCreateSuite($) { - $suite->{'createSuite'} = $_[0]; -} - -sub addDestroySuite($) { - $suite->{'destroySuite'} = $_[0]; -} - -sub addExceptionHandling() { - $haveEh = 1 unless defined($noEh); -} - -sub addStandardLibrary() { - $haveStd = 1 unless defined($noStd); -} - -sub verifySuite() { - if (suiteCreateLine() || suiteDestroyLine()) { - die("Suite ", suiteName(), " must have both createSuite() and destroySuite()\n") - unless (suiteCreateLine() && suiteDestroyLine()); - } -} - -sub rememberSuite() { - push @suites, $suite; - $numTotalTests += scalar @{$suite->{'tests'}}; -} - -sub suiteName() { return $suite->{'name'}; } -sub suiteTests() { return $suite->{'tests'}; } -sub suiteCreateLine() { return $suite->{'createSuite'}; } -sub suiteDestroyLine() { return $suite->{'destroySuite'}; } -sub fileName() { return $suite->{'file'}; } -sub fileString() { return cstr(fileName()); } -sub testName() { return $test->{'name'}; } -sub testLine() { return $test->{'line'}; } - -sub suiteObject() { return "suite_".suiteName(); } - -sub cstr($) { - my $file = $_[0]; - $file =~ s/\\/\\\\/g; - return "\"".$file."\""; -} - -# -# Writing the test source file -# - -sub writeOutput() { - $template ? writeTemplateOutput() : writeSimpleOutput(); -} - -sub startOutputFile() { - if ( !standardOutput() ) { - open OUTPUT_FILE,">$output" or die("Cannot create output file \"$output\"\n"); - select OUTPUT_FILE; - } - print "/* Generated file, do not edit */\n\n"; -} - -sub standardOutput() { - return !$output; -} - -sub writeSimpleOutput() { - startOutputFile(); - writePreamble(); - writeMain(); - writeWorld(); -} - -my ($didPreamble, $didWorld); - -sub writeTemplateOutput() { - openTemplateFile(); - startOutputFile(); - my $line; - while (defined($line = <TEMPLATE_FILE>)) { - if ( $line =~ m/^\s*\#\s*include\s*<cxxtest\// ) { - writePreamble(); - print $line; - } elsif ( $line =~ m/^\s*<CxxTest\s+preamble>\s*$/ ) { - writePreamble(); - } elsif ( $line =~ m/^\s*<CxxTest\s+world>\s*$/ ) { - writeWorld(); - } else { - print $line; - } - } -} - -sub openTemplateFile() { - open TEMPLATE_FILE, "<$template" or die("Cannot open template file \"$template\"\n"); -} - -sub writePreamble() { - return if $didPreamble; - print "#ifndef CXXTEST_RUNNING\n"; - print "#define CXXTEST_RUNNING\n"; - print "#endif\n"; - print "\n"; - if ( $haveStd ) { - print "#define _CXXTEST_HAVE_STD\n"; - } - if ( $haveEh ) { - print "#define _CXXTEST_HAVE_EH\n"; - } - if ( $abortOnFail ) { - print "#define _CXXTEST_ABORT_TEST_ON_FAIL\n"; - } - if ( $longlong ) { - print "#define _CXXTEST_LONGLONG $longlong\n"; - } - if ( $factor ) { - print "#define _CXXTEST_FACTOR\n"; - } - foreach my $header (@headers) { - print "#include $header\n"; - } - print "#include <cxxtest/TestListener.h>\n"; - print "#include <cxxtest/TestTracker.h>\n"; - print "#include <cxxtest/TestRunner.h>\n"; - print "#include <cxxtest/RealDescriptions.h>\n"; - print "#include <cxxtest/$runner.h>\n" if $runner; - print "#include <cxxtest/$gui.h>\n" if $gui; - print "\n"; - $didPreamble = 1; -} - -sub writeWorld() { - return if $didWorld; - writePreamble(); - writeSuites(); - ($root or !$part) and writeRoot(); - $noStaticInit and writeInitialize(); - $didWorld = 1; -} - -sub writeSuites() { - foreach (@suites) { - $suite = $_; - writeInclude(fileName()); - if ( $suite->{'generated'} ) { generateSuite(); } - dynamicSuite() ? writeSuitePointer() : writeSuiteObject(); - writeTestList(); - writeSuiteDescription(); - writeTestDescriptions(); - } -} - -sub dynamicSuite() { - return suiteCreateLine(); -} - -my $lastIncluded; - -sub writeInclude($) { - my $file = $_[0]; - return if $lastIncluded && ($file eq $lastIncluded); - print "#include \"$file\"\n\n"; - $lastIncluded = $file; -} - -sub generateSuite() { - print "class ", suiteName(), " : public CxxTest::TestSuite {\n"; - print "public:\n"; - foreach my $line (@{$suite->{'lines'}}) { - print $line; - } - print "};\n\n"; -} - -sub writeTestDescriptionsBase() { - my $class = "TestDescriptionBase_" . suiteName(); - print "class $class : public CxxTest::TestDescription {\n"; - print "public:\n"; - print " const char *file() const { return ", fileString(), "; }\n"; - print " const char *suiteName() const { return \"", suiteName(), "\"; }\n"; - print "};\n\n"; -} - -sub writeSuitePointer() { - if ( $noStaticInit ) { - print "static ", suiteName(), " *", suiteObject(), ";\n\n"; - } else { - print "static ", suiteName(), " *", suiteObject(), " = 0;\n\n"; - } -} - -sub writeSuiteObject() { - print "static ", suiteName(), " ", suiteObject(), ";\n\n"; -} - -sub testList() { - return "Tests_" . suiteName(); -} - -sub writeTestList() { - if ( $noStaticInit ) { - printf "static CxxTest::List %s;\n", testList(); - } else { - printf "static CxxTest::List %s = { 0, 0 };\n", testList(); - } -} - -sub writeTestDescriptions() { - foreach (@{suiteTests()}) { - $test = $_; - writeTestDescription(); - } -} - -sub suiteDescription() { - return "suiteDescription_" . suiteName(); -} - -sub writeTestDescription() { - my $class = "TestDescription_" . suiteName() . "_" . testName(); - printf "static class $class : public CxxTest::RealTestDescription {\n"; - printf "public:\n"; - $noStaticInit or - printf " $class() : CxxTest::RealTestDescription( %s, %s, %s, \"%s\" ) {}\n", - testList(), suiteDescription(), testLine(), testName(); - printf " void runTest() { %s }\n", dynamicSuite() ? dynamicRun() : staticRun(); - printf "} testDescription_%s_%s;\n\n", suiteName(), testName(); -} - -sub dynamicRun() { - return sprintf( "if ( %s ) %s->%s();", suiteObject(), suiteObject(), testName() ); -} - -sub staticRun() { - return sprintf( "%s.%s();", suiteObject(), testName() ); -} - -sub writeSuiteDescription() { - dynamicSuite() ? writeDynamicDescription() : writeStaticDescription(); -} - -sub writeDynamicDescription() { - printf "CxxTest::DynamicSuiteDescription<%s> %s", suiteName(), suiteDescription(); - if ( !$noStaticInit ) { - printf "( %s, %s, \"%s\", %s, %s, %s, %s )", - fileString(), $suite->{'line'}, suiteName(), testList(), - suiteObject(), suiteCreateLine(), suiteDestroyLine(); - } - print ";\n\n"; -} - -sub writeStaticDescription() { - printf "CxxTest::StaticSuiteDescription %s", suiteDescription(); - if ( !$noStaticInit ) { - printf "( %s, %s, \"%s\", %s, %s )", fileString(), $suite->{'line'}, suiteName(), suiteObject(), testList(); - } - print ";\n\n"; -} - -sub writeRoot() { - print "#include <cxxtest/Root.cpp>\n"; -} - -sub writeInitialize() { - print "namespace CxxTest {\n"; - print " void initialize()\n"; - print " {\n"; - foreach (@suites) { - $suite = $_; - printf " %s.initialize();\n", testList(); - if ( dynamicSuite() ) { - printf " %s = 0;\n", suiteObject(); - printf " %s.initialize( %s, %s, \"%s\", %s, %s, %s, %s );\n", - suiteDescription(), fileString(), $suite->{'line'}, suiteName(), testList(), - suiteObject(), suiteCreateLine(), suiteDestroyLine(); - } else { - printf " %s.initialize( %s, %s, \"%s\", %s, %s );\n", - suiteDescription(), fileString(), $suite->{'line'}, suiteName(), suiteObject(), testList(); - } - - foreach (@{suiteTests()}) { - $test = $_; - printf " testDescription_%s_%s.initialize( %s, %s, %s, \"%s\" );\n", - suiteName(), testName(), testList(), suiteDescription(), testLine(), testName(); - } - } - print " }\n"; - print "}\n"; -} - -sub writeMain() { - if ( $gui ) { - print "int main( int argc, char *argv[] ) {\n"; - $noStaticInit && - print " CxxTest::initialize();\n"; - print " return CxxTest::GuiTuiRunner<CxxTest::$gui, CxxTest::$runner>( argc, argv ).run();\n"; - print "}\n"; - } - elsif ( $runner ) { - print "int main() {\n"; - $noStaticInit && - print " CxxTest::initialize();\n"; - print " return CxxTest::$runner().run();\n"; - print "}\n"; - } -} diff --git a/bsl/cxxtest/cxxtestgen.py b/bsl/cxxtest/cxxtestgen.py deleted file mode 100755 index 831d23ab41bbf3ac7c10eed5319a0640ad817759..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/cxxtestgen.py +++ /dev/null @@ -1,593 +0,0 @@ -#!/usr/bin/python -'''Usage: %s [OPTIONS] <input file(s)> -Generate test source file for CxxTest. - - -v, --version Write CxxTest version - -o, --output=NAME Write output to file NAME - --runner=CLASS Create a main() function that runs CxxTest::CLASS - --gui=CLASS Like --runner, with GUI component - --error-printer Same as --runner=ErrorPrinter - --abort-on-fail Abort tests on failed asserts (like xUnit) - --have-std Use standard library (even if not found in tests) - --no-std Don\'t use standard library (even if found in tests) - --have-eh Use exception handling (even if not found in tests) - --no-eh Don\'t use exception handling (even if found in tests) - --longlong=[TYPE] Use TYPE (default: long long) as long long - --template=TEMPLATE Use TEMPLATE file to generate the test runner - --include=HEADER Include HEADER in test runner before other headers - --root Write CxxTest globals - --part Don\'t write CxxTest globals - --no-static-init Don\'t rely on static initialization -''' - -import re -import sys -import getopt -import glob -import string - -# Global variables -suites = [] -suite = None -inBlock = 0 - -outputFileName = None -runner = None -gui = None -root = None -part = None -noStaticInit = None -templateFileName = None -headers = [] - -haveExceptionHandling = 0 -noExceptionHandling = 0 -haveStandardLibrary = 0 -noStandardLibrary = 0 -abortOnFail = 0 -factor = 0 -longlong = 0 - -def main(): - '''The main program''' - files = parseCommandline() - scanInputFiles( files ) - writeOutput() - -def usage( problem = None ): - '''Print usage info and exit''' - if problem is None: - print usageString() - sys.exit(0) - else: - sys.stderr.write( usageString() ) - abort( problem ) - -def usageString(): - '''Construct program usage string''' - return __doc__ % sys.argv[0] - -def abort( problem ): - '''Print error message and exit''' - sys.stderr.write( '\n' ) - sys.stderr.write( problem ) - sys.stderr.write( '\n\n' ) - sys.exit(2) - -def parseCommandline(): - '''Analyze command line arguments''' - try: - options, patterns = getopt.getopt( sys.argv[1:], 'o:r:', - ['version', 'output=', 'runner=', 'gui=', - 'error-printer', 'abort-on-fail', 'have-std', 'no-std', - 'have-eh', 'no-eh', 'template=', 'include=', - 'root', 'part', 'no-static-init', 'factor', 'longlong='] ) - except getopt.error, problem: - usage( problem ) - setOptions( options ) - return setFiles( patterns ) - -def setOptions( options ): - '''Set options specified on command line''' - global outputFileName, templateFileName, runner, gui, haveStandardLibrary, factor, longlong - global haveExceptionHandling, noExceptionHandling, abortOnFail, headers, root, part, noStaticInit - for o, a in options: - if o in ('-v', '--version'): - printVersion() - elif o in ('-o', '--output'): - outputFileName = a - elif o == '--template': - templateFileName = a - elif o == '--runner': - runner = a - elif o == '--gui': - gui = a - elif o == '--include': - if not re.match( r'^["<].*[>"]$', a ): - a = ('"%s"' % a) - headers.append( a ) - elif o == '--error-printer': - runner = 'ErrorPrinter' - haveStandardLibrary = 1 - elif o == '--abort-on-fail': - abortOnFail = 1 - elif o == '--have-std': - haveStandardLibrary = 1 - elif o == '--no-std': - noStandardLibrary = 1 - elif o == '--have-eh': - haveExceptionHandling = 1 - elif o == '--no-eh': - noExceptionHandling = 1 - elif o == '--root': - root = 1 - elif o == '--part': - part = 1 - elif o == '--no-static-init': - noStaticInit = 1 - elif o == '--factor': - factor = 1 - elif o == '--longlong': - if a: - longlong = a - else: - longlong = 'long long' - - if noStaticInit and (root or part): - abort( '--no-static-init cannot be used with --root/--part' ) - - if gui and not runner: - runner = 'StdioPrinter' - -def printVersion(): - '''Print CxxTest version and exit''' - sys.stdout.write( "This is CxxTest version 3.10.1.\n" ) - sys.exit(0) - -def setFiles( patterns ): - '''Set input files specified on command line''' - files = expandWildcards( patterns ) - if len(files) is 0 and not root: - usage( "No input files found" ) - return files - -def expandWildcards( patterns ): - '''Expand all wildcards in an array (glob)''' - fileNames = [] - for pathName in patterns: - patternFiles = glob.glob( pathName ) - for fileName in patternFiles: - fileNames.append( fixBackslashes( fileName ) ) - return fileNames - -def fixBackslashes( fileName ): - '''Convert backslashes to slashes in file name''' - return re.sub( r'\\', '/', fileName, 0 ) - -def scanInputFiles(files): - '''Scan all input files for test suites''' - for file in files: - scanInputFile(file) - global suites - if len(suites) is 0 and not root: - abort( 'No tests defined' ) - -def scanInputFile(fileName): - '''Scan single input file for test suites''' - file = open(fileName) - lineNo = 0 - while 1: - line = file.readline() - if not line: - break - lineNo = lineNo + 1 - - scanInputLine( fileName, lineNo, line ) - closeSuite() - file.close() - -def scanInputLine( fileName, lineNo, line ): - '''Scan single input line for interesting stuff''' - scanLineForExceptionHandling( line ) - scanLineForStandardLibrary( line ) - - scanLineForSuiteStart( fileName, lineNo, line ) - - global suite - if suite: - scanLineInsideSuite( suite, lineNo, line ) - -def scanLineInsideSuite( suite, lineNo, line ): - '''Analyze line which is part of a suite''' - global inBlock - if lineBelongsToSuite( suite, lineNo, line ): - scanLineForTest( suite, lineNo, line ) - scanLineForCreate( suite, lineNo, line ) - scanLineForDestroy( suite, lineNo, line ) - -def lineBelongsToSuite( suite, lineNo, line ): - '''Returns whether current line is part of the current suite. - This can be false when we are in a generated suite outside of CXXTEST_CODE() blocks - If the suite is generated, adds the line to the list of lines''' - if not suite['generated']: - return 1 - - global inBlock - if not inBlock: - inBlock = lineStartsBlock( line ) - if inBlock: - inBlock = addLineToBlock( suite, lineNo, line ) - return inBlock - - -std_re = re.compile( r"\b(std\s*::|CXXTEST_STD|using\s+namespace\s+std\b|^\s*\#\s*include\s+<[a-z0-9]+>)" ) -def scanLineForStandardLibrary( line ): - '''Check if current line uses standard library''' - global haveStandardLibrary, noStandardLibrary - if not haveStandardLibrary and std_re.search(line): - if not noStandardLibrary: - haveStandardLibrary = 1 - -exception_re = re.compile( r"\b(throw|try|catch|TSM?_ASSERT_THROWS[A-Z_]*)\b" ) -def scanLineForExceptionHandling( line ): - '''Check if current line uses exception handling''' - global haveExceptionHandling, noExceptionHandling - if not haveExceptionHandling and exception_re.search(line): - if not noExceptionHandling: - haveExceptionHandling = 1 - -suite_re = re.compile( r'\bclass\s+(\w+)\s*:\s*public\s+((::)?\s*CxxTest\s*::\s*)?TestSuite\b' ) -generatedSuite_re = re.compile( r'\bCXXTEST_SUITE\s*\(\s*(\w*)\s*\)' ) -def scanLineForSuiteStart( fileName, lineNo, line ): - '''Check if current line starts a new test suite''' - m = suite_re.search( line ) - if m: - startSuite( m.group(1), fileName, lineNo, 0 ) - m = generatedSuite_re.search( line ) - if m: - sys.stdout.write( "%s:%s: Warning: Inline test suites are deprecated.\n" % (fileName, lineNo) ) - startSuite( m.group(1), fileName, lineNo, 1 ) - -def startSuite( name, file, line, generated ): - '''Start scanning a new suite''' - global suite - closeSuite() - suite = { 'name' : name, - 'file' : file, - 'cfile' : cstr(file), - 'line' : line, - 'generated' : generated, - 'object' : 'suite_%s' % name, - 'dobject' : 'suiteDescription_%s' % name, - 'tlist' : 'Tests_%s' % name, - 'tests' : [], - 'lines' : [] } - -def lineStartsBlock( line ): - '''Check if current line starts a new CXXTEST_CODE() block''' - return re.search( r'\bCXXTEST_CODE\s*\(', line ) is not None - -test_re = re.compile( r'^([^/]|/[^/])*\bvoid\s+([Tt]est\w+)\s*\(\s*(void)?\s*\)' ) -def scanLineForTest( suite, lineNo, line ): - '''Check if current line starts a test''' - m = test_re.search( line ) - if m: - addTest( suite, m.group(2), lineNo ) - -def addTest( suite, name, line ): - '''Add a test function to the current suite''' - test = { 'name' : name, - 'suite' : suite, - 'class' : 'TestDescription_%s_%s' % (suite['name'], name), - 'object' : 'testDescription_%s_%s' % (suite['name'], name), - 'line' : line, - } - suite['tests'].append( test ) - -def addLineToBlock( suite, lineNo, line ): - '''Append the line to the current CXXTEST_CODE() block''' - line = fixBlockLine( suite, lineNo, line ) - line = re.sub( r'^.*\{\{', '', line ) - - e = re.search( r'\}\}', line ) - if e: - line = line[:e.start()] - suite['lines'].append( line ) - return e is None - -def fixBlockLine( suite, lineNo, line): - '''Change all [E]TS_ macros used in a line to _[E]TS_ macros with the correct file/line''' - return re.sub( r'\b(E?TSM?_(ASSERT[A-Z_]*|FAIL))\s*\(', - r'_\1(%s,%s,' % (suite['cfile'], lineNo), - line, 0 ) - -create_re = re.compile( r'\bstatic\s+\w+\s*\*\s*createSuite\s*\(\s*(void)?\s*\)' ) -def scanLineForCreate( suite, lineNo, line ): - '''Check if current line defines a createSuite() function''' - if create_re.search( line ): - addSuiteCreateDestroy( suite, 'create', lineNo ) - -destroy_re = re.compile( r'\bstatic\s+void\s+destroySuite\s*\(\s*\w+\s*\*\s*\w*\s*\)' ) -def scanLineForDestroy( suite, lineNo, line ): - '''Check if current line defines a destroySuite() function''' - if destroy_re.search( line ): - addSuiteCreateDestroy( suite, 'destroy', lineNo ) - -def cstr( str ): - '''Convert a string to its C representation''' - return '"' + string.replace( str, '\\', '\\\\' ) + '"' - - -def addSuiteCreateDestroy( suite, which, line ): - '''Add createSuite()/destroySuite() to current suite''' - if suite.has_key(which): - abort( '%s:%s: %sSuite() already declared' % ( suite['file'], str(line), which ) ) - suite[which] = line - -def closeSuite(): - '''Close current suite and add it to the list if valid''' - global suite - if suite is not None: - if len(suite['tests']) is not 0: - verifySuite(suite) - rememberSuite(suite) - suite = None - -def verifySuite(suite): - '''Verify current suite is legal''' - if suite.has_key('create') and not suite.has_key('destroy'): - abort( '%s:%s: Suite %s has createSuite() but no destroySuite()' % - (suite['file'], suite['create'], suite['name']) ) - if suite.has_key('destroy') and not suite.has_key('create'): - abort( '%s:%s: Suite %s has destroySuite() but no createSuite()' % - (suite['file'], suite['destroy'], suite['name']) ) - -def rememberSuite(suite): - '''Add current suite to list''' - global suites - suites.append( suite ) - -def writeOutput(): - '''Create output file''' - if templateFileName: - writeTemplateOutput() - else: - writeSimpleOutput() - -def writeSimpleOutput(): - '''Create output not based on template''' - output = startOutputFile() - writePreamble( output ) - writeMain( output ) - writeWorld( output ) - output.close() - -include_re = re.compile( r"\s*\#\s*include\s+<cxxtest/" ) -preamble_re = re.compile( r"^\s*<CxxTest\s+preamble>\s*$" ) -world_re = re.compile( r"^\s*<CxxTest\s+world>\s*$" ) -def writeTemplateOutput(): - '''Create output based on template file''' - template = open(templateFileName) - output = startOutputFile() - while 1: - line = template.readline() - if not line: - break; - if include_re.search( line ): - writePreamble( output ) - output.write( line ) - elif preamble_re.search( line ): - writePreamble( output ) - elif world_re.search( line ): - writeWorld( output ) - else: - output.write( line ) - template.close() - output.close() - -def startOutputFile(): - '''Create output file and write header''' - if outputFileName is not None: - output = open( outputFileName, 'w' ) - else: - output = sys.stdout - output.write( "/* Generated file, do not edit */\n\n" ) - return output - -wrotePreamble = 0 -def writePreamble( output ): - '''Write the CxxTest header (#includes and #defines)''' - global wrotePreamble, headers, longlong - if wrotePreamble: return - output.write( "#ifndef CXXTEST_RUNNING\n" ) - output.write( "#define CXXTEST_RUNNING\n" ) - output.write( "#endif\n" ) - output.write( "\n" ) - if haveStandardLibrary: - output.write( "#define _CXXTEST_HAVE_STD\n" ) - if haveExceptionHandling: - output.write( "#define _CXXTEST_HAVE_EH\n" ) - if abortOnFail: - output.write( "#define _CXXTEST_ABORT_TEST_ON_FAIL\n" ) - if longlong: - output.write( "#define _CXXTEST_LONGLONG %s\n" % longlong ) - if factor: - output.write( "#define _CXXTEST_FACTOR\n" ) - for header in headers: - output.write( "#include %s\n" % header ) - output.write( "#include <cxxtest/TestListener.h>\n" ) - output.write( "#include <cxxtest/TestTracker.h>\n" ) - output.write( "#include <cxxtest/TestRunner.h>\n" ) - output.write( "#include <cxxtest/RealDescriptions.h>\n" ) - if runner: - output.write( "#include <cxxtest/%s.h>\n" % runner ) - if gui: - output.write( "#include <cxxtest/%s.h>\n" % gui ) - output.write( "\n" ) - wrotePreamble = 1 - -def writeMain( output ): - '''Write the main() function for the test runner''' - if gui: - output.write( 'int main( int argc, char *argv[] ) {\n' ) - if noStaticInit: - output.write( ' CxxTest::initialize();\n' ) - output.write( ' return CxxTest::GuiTuiRunner<CxxTest::%s, CxxTest::%s>( argc, argv ).run();\n' % (gui, runner) ) - output.write( '}\n' ) - elif runner: - output.write( 'int main() {\n' ) - if noStaticInit: - output.write( ' CxxTest::initialize();\n' ) - output.write( ' return CxxTest::%s().run();\n' % runner ) - output.write( '}\n' ) - -wroteWorld = 0 -def writeWorld( output ): - '''Write the world definitions''' - global wroteWorld, part - if wroteWorld: return - writePreamble( output ) - writeSuites( output ) - if root or not part: - writeRoot( output ) - if noStaticInit: - writeInitialize( output ) - wroteWorld = 1 - -def writeSuites(output): - '''Write all TestDescriptions and SuiteDescriptions''' - for suite in suites: - writeInclude( output, suite['file'] ) - if isGenerated(suite): - generateSuite( output, suite ) - if isDynamic(suite): - writeSuitePointer( output, suite ) - else: - writeSuiteObject( output, suite ) - writeTestList( output, suite ) - writeSuiteDescription( output, suite ) - writeTestDescriptions( output, suite ) - -def isGenerated(suite): - '''Checks whether a suite class should be created''' - return suite['generated'] - -def isDynamic(suite): - '''Checks whether a suite is dynamic''' - return suite.has_key('create') - -lastIncluded = '' -def writeInclude(output, file): - '''Add #include "file" statement''' - global lastIncluded - if file == lastIncluded: return - output.writelines( [ '#include "', file, '"\n\n' ] ) - lastIncluded = file - -def generateSuite( output, suite ): - '''Write a suite declared with CXXTEST_SUITE()''' - output.write( 'class %s : public CxxTest::TestSuite {\n' % suite['name'] ) - output.write( 'public:\n' ) - for line in suite['lines']: - output.write(line) - output.write( '};\n\n' ) - -def writeSuitePointer( output, suite ): - '''Create static suite pointer object for dynamic suites''' - if noStaticInit: - output.write( 'static %s *%s;\n\n' % (suite['name'], suite['object']) ) - else: - output.write( 'static %s *%s = 0;\n\n' % (suite['name'], suite['object']) ) - -def writeSuiteObject( output, suite ): - '''Create static suite object for non-dynamic suites''' - output.writelines( [ "static ", suite['name'], " ", suite['object'], ";\n\n" ] ) - -def writeTestList( output, suite ): - '''Write the head of the test linked list for a suite''' - if noStaticInit: - output.write( 'static CxxTest::List %s;\n' % suite['tlist'] ) - else: - output.write( 'static CxxTest::List %s = { 0, 0 };\n' % suite['tlist'] ) - -def writeTestDescriptions( output, suite ): - '''Write all test descriptions for a suite''' - for test in suite['tests']: - writeTestDescription( output, suite, test ) - -def writeTestDescription( output, suite, test ): - '''Write test description object''' - output.write( 'static class %s : public CxxTest::RealTestDescription {\n' % test['class'] ) - output.write( 'public:\n' ) - if not noStaticInit: - output.write( ' %s() : CxxTest::RealTestDescription( %s, %s, %s, "%s" ) {}\n' % - (test['class'], suite['tlist'], suite['dobject'], test['line'], test['name']) ) - output.write( ' void runTest() { %s }\n' % runBody( suite, test ) ) - output.write( '} %s;\n\n' % test['object'] ) - -def runBody( suite, test ): - '''Body of TestDescription::run()''' - if isDynamic(suite): return dynamicRun( suite, test ) - else: return staticRun( suite, test ) - -def dynamicRun( suite, test ): - '''Body of TestDescription::run() for test in a dynamic suite''' - return 'if ( ' + suite['object'] + ' ) ' + suite['object'] + '->' + test['name'] + '();' - -def staticRun( suite, test ): - '''Body of TestDescription::run() for test in a non-dynamic suite''' - return suite['object'] + '.' + test['name'] + '();' - -def writeSuiteDescription( output, suite ): - '''Write SuiteDescription object''' - if isDynamic( suite ): - writeDynamicDescription( output, suite ) - else: - writeStaticDescription( output, suite ) - -def writeDynamicDescription( output, suite ): - '''Write SuiteDescription for a dynamic suite''' - output.write( 'CxxTest::DynamicSuiteDescription<%s> %s' % (suite['name'], suite['dobject']) ) - if not noStaticInit: - output.write( '( %s, %s, "%s", %s, %s, %s, %s )' % - (suite['cfile'], suite['line'], suite['name'], suite['tlist'], - suite['object'], suite['create'], suite['destroy']) ) - output.write( ';\n\n' ) - -def writeStaticDescription( output, suite ): - '''Write SuiteDescription for a static suite''' - output.write( 'CxxTest::StaticSuiteDescription %s' % suite['dobject'] ) - if not noStaticInit: - output.write( '( %s, %s, "%s", %s, %s )' % - (suite['cfile'], suite['line'], suite['name'], suite['object'], suite['tlist']) ) - output.write( ';\n\n' ) - -def writeRoot(output): - '''Write static members of CxxTest classes''' - output.write( '#include <cxxtest/Root.cpp>\n' ) - -def writeInitialize(output): - '''Write CxxTest::initialize(), which replaces static initialization''' - output.write( 'namespace CxxTest {\n' ) - output.write( ' void initialize()\n' ) - output.write( ' {\n' ) - for suite in suites: - output.write( ' %s.initialize();\n' % suite['tlist'] ) - if isDynamic(suite): - output.write( ' %s = 0;\n' % suite['object'] ) - output.write( ' %s.initialize( %s, %s, "%s", %s, %s, %s, %s );\n' % - (suite['dobject'], suite['cfile'], suite['line'], suite['name'], - suite['tlist'], suite['object'], suite['create'], suite['destroy']) ) - else: - output.write( ' %s.initialize( %s, %s, "%s", %s, %s );\n' % - (suite['dobject'], suite['cfile'], suite['line'], suite['name'], - suite['object'], suite['tlist']) ) - - for test in suite['tests']: - output.write( ' %s.initialize( %s, %s, %s, "%s" );\n' % - (test['object'], suite['tlist'], suite['dobject'], test['line'], test['name']) ) - - output.write( ' }\n' ) - output.write( '}\n' ) - -main() diff --git a/bsl/cxxtest/demo/Makefile b/bsl/cxxtest/demo/Makefile deleted file mode 100644 index ba4e910c6fec0597e944f7d111992bd9c7ca0c17..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/demo/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -CXX = ../ - -INCLUDE = -I ./\ - -I$(CXX) \ - -LIB = - -CFLAG = -fsigned-char -Wall -g -D_REENTRANT -D_FILTER -DNDEBUG -fPIC $(INCLUDE) -CPPFLAG = -fsigned-char -Wall -g -D_REENTRANT -D_FILTER -fPIC $(INCLUDE) - -CXXTEST = $(CXX)/cxxtestgen.pl -OUTPUT = --error-printer --have-std --have-eh - -CC = gcc -CPP = g++ -PERL = perl -PY = python - -ALLTESTS=$(wildcard *.h) -CPPFILE=$(ALLTESTS:.h=.cpp) -EXE=$(basename $(ALLTESTS)) - -#$(CPPFILE) : $(ALLTESTS) -.h.cpp : - $(CXXTEST) $(OUTPUT) -o $*.cpp $*.h - -all : $(EXE) - -$(EXE) : $(CPPFILE) - $(CPP) $(CPPFLAG) -o $@ $@.cpp $(LIB) - -#========================================================================= -.PHONY : clean all test - -clean : - rm -f $(CPPFILE) $(EXE) -test : $(EXE) - @failed=0; - @for exe in $(EXE) ; do echo; echo -n doing $$exe ">>>>>>>>";echo;echo;\ - ./$$exe ; \ - echo done ; \ - echo ;\ - done; - diff --git a/bsl/cxxtest/demo/bsl_test_fun.h b/bsl/cxxtest/demo/bsl_test_fun.h deleted file mode 100644 index a034f8f2fe57eaeeb8926535a88073cee5ac5d6a..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/demo/bsl_test_fun.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_fun.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_fun.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 17:44:12 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - - #ifndef __BSL_TEST_FUN_ - #define __BSL_TEST_FUN_ - #include <cxxtest/TestSuite.h> - - -class bsl_test_fun : public CxxTest::TestSuite -{ - public: - void test_normal_1(void) - { - int val = 0; - TSM_ASSERT(val, val == 0); - } - void test_normal_2(void) - { - int val = 0; - TSM_ASSERT(val, val != 0); - } -}; - - -#endif - - - - - - - - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/cxxtest/demo/bsl_test_fun2.h b/bsl/cxxtest/demo/bsl_test_fun2.h deleted file mode 100644 index 6088dbe70f8a11fce463fa67c43da5476047e24b..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/demo/bsl_test_fun2.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_fun2.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_fun.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 17:44:12 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - - #ifndef __BSL_TEST_FUN_ - #define __BSL_TEST_FUN_ - #include <cxxtest/TestSuite.h> - - -class bsl_test_fun2 : public CxxTest::TestSuite -{ - public: - void test_normal_1(void) - { - int val = 0; - TSM_ASSERT(val, val == 0); - } - void test_normal_2(void) - { - int val = 0; - TSM_ASSERT(val, val == 0); - } -}; - - -#endif - - - - - - - - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/cxxtest/docs/convert.pl b/bsl/cxxtest/docs/convert.pl deleted file mode 100755 index 9d83f1c0cf0d88867e09d89add355da1324fd831..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/docs/convert.pl +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/perl - -die "Usage: $0 <text file> <html file> <TexInfo file>\n" - unless scalar @ARGV == 3; - -my ($text, $html, $texi) = @ARGV; - -open TEXT, "<$text" or die "Cannot open text file \"$text\"\n"; -open HTML, ">$html" or die "Cannot create html file \"$html\"\n"; -open TEXI, ">$texi" or die "Cannot create TexInfo file \"$texi\"\n"; - -print HTML "<html>"; - -sub analyze($) { - my ($line) = @_; - my ($htmlLine, $texiLine) = ($line, $line); - - # command line options - $texiLine =~ s/ (--?[a-z-]*)/ \@option{$1}/g; - $htmlLine =~ s/ (--?[a-z-]*)/ <tt>$1<\/tt>/g; - - # [Class::]function() - $texiLine =~ s/([^A-Za-z])(([A-Z][A-Za-z0-9]*::)?[A-Za-z0-9]+\(\))/$1\@code{$2}/g; - $htmlLine =~ s/([^A-Za-z])(([A-Z][A-Za-z0-9]*::)?[A-Za-z0-9]+\(\))/$1<code>$2<\/code>/g; - - # `file' - $texiLine =~ s/`([A-Za-z.\/]*)'/\@file{$1}/g; - $htmlLine =~ s/`([A-Za-z.\/]*)'/<tt>`$1'<\/tt>/g; - - # TS... - $texiLine =~ s/(^|[^A-Z])(TS[A-Za-z_*()]*)/$1\@code{$2}/g; - $htmlLine =~ s/(^|[^A-Z])(TS[A-Za-z_*()]*)/$1<code>$2<\/code>/g; - - # CXXTEST_ - $texiLine =~ s/(CXXTEST_[A-Z_]*)/\@code{$1}/g; - $htmlLine =~ s/(CXXTEST_[A-Z_]*)/<tt>$1<\/tt>/g; - - return ($htmlLine, $texiLine); -} - -my $line; -my $inRelease = 0; -while ( defined( $line = <TEXT> ) ) { - chomp $line; - if ( $line =~ m/^CxxTest Releases/ ) { - print HTML "<title>CxxTest Releases\n"; - print HTML "

    CxxTest Releases

    \n\n"; - - print TEXI "\@appendix Version history\n"; - print TEXI "\@itemize \@bullet\n"; - } - elsif ( $line =~ m/^(.*):$/ ) { - if ( $inRelease ) { - print HTML "\n\n"; - print TEXI "\@end itemize\n"; - } - - print HTML "

    $1

    \n"; - print HTML "
      \n"; - - print TEXI "\@item\n\@strong{$1}\n"; - print TEXI "\@itemize \@minus\n"; - - $inRelease = 1; - } - elsif ( $line =~ m/^ - (.*)$/ ) { - my ($htmlLine, $texiLine) = analyze($1); - print HTML "
    • $htmlLine
    • \n"; - print TEXI "\@item\n$texiLine\n"; - } -} - -if ( $inRelease ) { - print HTML "
    \n\n"; - print TEXI "\@end itemize\n\n"; -} - -print HTML "\n"; -print TEXI "\@end itemize\n"; - -close TEXT or die "Error closing text file \"$text\"\n"; -close HTML or die "Error closing html file \"$html\"\n"; -close TEXI or die "Error closing TexInfo file \"$texi\"\n"; diff --git a/bsl/cxxtest/docs/guide.html b/bsl/cxxtest/docs/guide.html deleted file mode 100755 index fb435fb8f1ff76f70cff92b13ab7abf59ae54e08..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/docs/guide.html +++ /dev/null @@ -1,1960 +0,0 @@ - - -CxxTest User's Guide - - - - - - -

    CxxTest User's Guide

    -Table of contents - -

    1 Introduction

    - -

    CxxTest is a JUnit/CppUnit/xUnit-like framework for C++. - -

    Its advantages over existing alternatives are that it: -

      -
    • Doesn't require RTTI -
    • Doesn't require member template functions -
    • Doesn't require exception handling -
    • Doesn't require any external libraries (including memory management, file/console I/O, graphics libraries) -
    - In other words, CxxTest is designed to be as portable as possible. Its -only requirements are a reasonably modern C++ compiler and either Perl -or Python. However, when advanced features are supported in your -environment, CxxTest can use them, e.g. catch unhandled exceptions and -even display a GUI. - -

    In addition, CxxTest is slightly easier to use than the C++ -alternatives, since you don't need to "register" your tests. It also -features some extras like a richer set of assertions and even support -for a "to do" list (see TS_WARN()). - -

    CxxTest is available under the -GNU Lesser General Public License. - -

    1.1 About this guide

    - -

    This guide is not intended as an introduction to Extreme Progamming -and/or unit testing. It describes the design and usage of CxxTest. - -

    2 Getting started

    - -

    2.1 Getting CxxTest

    - -

    The homepage for CxxTest is http://cxxtest.sourceforge.net. You -can always get the latest release from the SourceForge download page, -here -or here. The latest version -of this guide is available online at -http://cxxtest.sourceforge.net/guide.html. A PDF version is also -available at http://cxxtest.sourceforge.net/guide.pdf. - -

    2.2 Your first test!

    - -

    Here's a simple step-by-step guide: - -

      - -
    1. Tests are organized into "Test Suites". - Test suites are written in header files. - -

      A test suite is a class that inherits from CxxTest::TestSuite. - A test is a public void (void) member function of that class whose name starts with test, - e.g. testDirectoryScanner(), test_cool_feature() and even TestImportantBugFix(). - -

      -          
      -          // MyTestSuite.h
      -          #include <cxxtest/TestSuite.h>
      -          
      -          class MyTestSuite : public CxxTest::TestSuite 
      -          {
      -          public:
      -             void testAddition( void )
      -             {
      -                TS_ASSERT( 1 + 1 > 1 );
      -                TS_ASSERT_EQUALS( 1 + 1, 2 );
      -             }
      -          };
      -          
      -
      - -

    2. After you have your test suites, you use CxxTest to generate a "test runner" source file: - -
      -     # cxxtestgen.pl --error-printer -o runner.cpp MyTestSuite.h
      -     
      - -

      or, for those less fortunate: - -

      -     C:\tmp> perl -w cxxtestgen.pl --error-printer -o runner.cpp MyTestSuite.h
      -     
      - -

    3. You would then simply compile the resulting file: - -
      -     # g++ -o runner runner.cpp
      -     
      - -

      or perhaps - -

      -     C:\tmp> cl -GX -o runner.exe runner.cpp
      -     
      - -

      or maybe even - -

      -     C:\tmp> bcc32 -erunner.exe runner.cpp
      -     
      - -

    4. Finally, you run the tests and enjoy a well tested piece of software: - -
      -     # ./runner
      -     Running 1 test.OK!
      -     
      - -
    - -

    2.3 Your second test

    - -

    Now let's see what failed tests look like. -We will add a failing test to the previous example: - -

    -     
    -     // MyTestSuite.h
    -     #include <cxxtest/TestSuite.h>
    -     
    -     class MyTestSuite : public CxxTest::TestSuite 
    -     {
    -     public:
    -        void testAddition( void )
    -        {
    -           TS_ASSERT( 1 + 1 > 1 );
    -           TS_ASSERT_EQUALS( 1 + 1, 2 );
    -        }
    -     
    -        void testMultiplication( void )
    -        {
    -           TS_ASSERT_EQUALS( 2 * 2, 5 );
    -        }
    -     };
    -     
    -
    - -

    Generate, compile and run the test runner, and you will get this: - -

    -     
    -     # ./runner
    -     Running 2 tests.
    -     MyTestSuite.h:15: Expected (2 * 2 == 5), found (4 != 5)
    -     Failed 1 of 2 tests
    -     Success rate: 50%
    -     
    -
    - -

    Fixing the bug is left as an excercise to the reader. - -

    2.4 Graphical user interface

    - - (v3.0.1) -CxxTest can also display a simple GUI. The way to do this is depends on -your compiler, OS and environment, but try the following pointers: -
      - -
    • Under Windows with Visual C++, run perl cxxtestgen.pl -o runner.cpp ---gui=Win32Gui MyTestSuite.h. - -
    • Under X-Windows, try ./cxxtestgen.pl -o runner.cpp ---gui=X11Gui MyTestSuite. You may need to tell the compiler -where to find X, usually something like g++ -o runner --L/usr/X11R6/lib runner.cpp -lX11. - -
    • If you have Qt installed, try running -cxxtestgen.pl with the option --gui=QtGui. As -always, compile and link the the Qt headers and libraries. - -
    - -

    See Graphical user interface and Running the samples for -more information. - -

    3 Really using CxxTest

    - -

    There is much more to CxxTest than seeing if two times two is four. -You should probably take a look at the samples in the CxxTest distribution. -Other than that, here are some more in-depth explanations. - -

    3.1 What can you test

    - -

    Here are the different "assertions" you can use in your tests: - -

    Macro Description Example - -
    TS_FAIL(message) -Fail unconditionally -TS_FAIL("Test not implemented"); - -
    TS_ASSERT(expr) -Verify (expr) is true -TS_ASSERT(messageReceived()); - -
    TS_ASSERT_EQUALS(x, y) -Verify (x==y) -TS_ASSERT_EQUALS(nodeCount(), 14); - -
    TS_ASSERT_SAME_DATA(x, y, size) -Verify two buffers are equal -TS_ASSERT_SAME_DATA(input, output,, size); - -
    TS_ASSERT_DELTA(x, y, d) -Verify (x==y) up to d -TS_ASSERT_DELTA(sqrt(4.0), 2.0, 0.0001); - -
    TS_ASSERT_DIFFERS(x, y) -Verify !(x==y) -TS_ASSERT_DIFFERS(exam.numTook(), exam.numPassed()); - -
    TS_ASSERT_LESS_THAN(x, y) -Verify (x<y) -TS_ASSERT_LESS_THAN(ship.speed(), SPEED_OF_LIGHT); - -
    TS_ASSERT_LESS_THAN_EQUALS(x, y) -Verify (x<=y) -TS_ASSERT_LESS_THAN_EQUALS(requests, items); - -
    TS_ASSERT_PREDICATE(R, x) -Verify P(x) -TS_ASSERT_PREDICATE(SeemsReasonable, salary); - -
    TS_ASSERT_RELATION(R, x, y) -Verify x R y -TS_ASSERT_RELATION(std::greater, salary, average); - -
    TS_ASSERT_THROWS(expr, type) -Verify that (expr) throws a specific type of exception -TS_ASSERT_THROWS(parse(file), Parser::ReadError); - -
    TS_ASSERT_THROWS_EQUALS(expr, arg, x, y) -Verify type and value of what (expr) throws -(See text) - -
    TS_ASSERT_THROWS_ASSERT(expr, arg, assertion) -Verify type and value of what (expr) throws -(See text) - -
    TS_ASSERT_THROWS_ANYTHING(expr) -Verify that (expr) throws an exception -TS_ASSERT_THROWS_ANYTHING(buggy()); - -
    TS_ASSERT_THROWS_NOTHING(expr) -Verify that (expr) doesn't throw anything -TS_ASSERT_THROWS_NOTHING(robust()); - -
    TS_WARN(message) -Print message as a warning -TS_WARN("TODO: Check invalid parameters"); - -
    TS_TRACE(message) -Print message as an informational message -TS_TRACE(errno); - -
    - -

    3.1.1 TS_FAIL

    - -

    - -

    TS_FAIL just fails the test. -It is like an assert(false) with an error message. -For example: - -

    -     
    -     void testSomething( void )
    -     {
    -        TS_FAIL( "I don't know how to test this!" );
    -     }
    -     
    -
    - -

    3.1.2 TS_ASSERT

    - -

    - -

    TS_ASSERT is the basic all-around tester. It works just like the -well-respected assert() macro (which I sincerely hope you know and -use!) An example: - -

    -     
    -     void testSquare( void )
    -     {
    -        MyFileLibrary::createEmptyFile( "test.bin" );
    -        TS_ASSERT( access( "test.bin", 0 ) == 0 );
    -     }
    -     
    -
    - -

    3.1.3 TS_ASSERT_EQUALS

    - -

    - -

    This is the second most useful tester. -As the name hints, it is used to test if two values are equal. - -

    -     
    -     void testSquare( void )
    -     {
    -        TS_ASSERT_EQUALS( square(-5), 25 );
    -     }
    -     
    -
    - -

    3.1.4 TS_ASSERT_SAME_DATA

    - -

    - - (v3.5.1) -This assertion is similar to TS_ASSERT_EQUALS(), except that it -compares the contents of two buffers in memory. If the comparison -fails, the standard runner dumps the contents of both buffers as hex -values. - -

    -     
    -     void testCopyMemory( void )
    -     {
    -        char input[77], output[77];
    -        myCopyMemory( output, input, 77 );
    -        TS_ASSERT_SAME_DATA( input, output, 77 );
    -     }
    -     
    -
    - -

    3.1.5 TS_ASSERT_DELTA

    - -

    - -

    Similar to TS_ASSERT_EQUALS(), this macro -verifies two values are equal up to a delta. -This is basically used for floating-point values. - -

    -     
    -     void testSquareRoot( void )
    -     {
    -        TS_ASSERT_DELTA( squareRoot(4.0), 2.0, 0.00001 );
    -     }
    -     
    -
    - -

    3.1.6 TS_ASSERT_DIFFERS

    - -

    - -

    The opposite of TS_ASSERT_EQUALS(), this macro is used to assert -that two values are not equal. - -

    -     
    -     void testNumberGenerator( void )
    -     {
    -        int first = generateNumber();
    -        int second = generateNumber();
    -        TS_ASSERT_DIFFERS( first, second );
    -     }
    -     
    -
    - -

    3.1.7 TS_ASSERT_LESS_THAN

    - -

    - -

    This macro asserts that the first operand is less than the second. - -

    -     
    -     void testFindLargerNumber( void )
    -     {
    -        TS_ASSERT_LESS_THAN( 23, findLargerNumber(23) );
    -     }
    -     
    -
    - -

    3.1.8 TS_ASSERT_LESS_THAN_EQUALS

    - -

    - - (v3.7.0) -Not surprisingly, this macro asserts that the first operand is less than or equals the second. - -

    -     
    -     void testBufferSize( void )
    -     {
    -        TS_ASSERT_LESS_THAN_EQUALS( bufferSize(), MAX_BUFFER_SIZE );
    -     }
    -     
    -
    - -

    3.1.9 TS_ASSERT_PREDICATE

    - -

    - - (v3.8.2) -This macro can be seen as a generalization of -TS_ASSERT(). It takes as an argument the name of a class, -similar to an STL unary_function, and evaluates -operator(). The advantage this has over -TS_ASSERT() is that you can see the failed value. - -

    -     
    -     class IsPrime
    -     {
    -     public:
    -        bool operator()( unsigned ) const;
    -     };
    -     
    -     // ...
    -     
    -     void testPrimeGenerator( void )
    -     {
    -        TS_ASSERT_PREDICATE( IsPrime, generatePrime() );
    -     }
    -     
    -
    - -

    3.1.10 TS_ASSERT_RELATION

    - -

    - - (v3.8.0) -Closely related to -TS_ASSERT_PREDICATE(), this macro can be seen as a -generalization of TS_ASSERT_EQUALS(), -TS_ASSERT_DIFFERS(), -TS_ASSERT_LESS_THAN() and -TS_ASSERT_LESS_THAN_EQUALS(). It takes as an argument the -name of a class, similar to an STL binary_function, and evaluates -operator(). This can be used to very simply assert comparisons -which are not covered by the builtin macros. - -

    -     
    -     void testGreater( void )
    -     {
    -        TS_ASSERT_RELATION( std::greater<int>, ticketsSold(), 1000 );
    -     }
    -     
    -
    - -

    3.1.11 TS_ASSERT_THROWS and friends

    - -

    - -

    These assertions are used to test whether an expression throws an exception. -TS_ASSERT_THROWS is used when you want to verify the type of exception -thrown, and TS_ASSERT_THROWS_ANYTHING is used to just make sure something -is thrown. As you might have guessed, TS_ASSERT_THROWS_NOTHING asserts -that nothing is thrown. - - (v3.10.0) -TS_ASSERT_THROWS_EQUALS checks the type of the -exception as in TS_ASSERT_THROWS then allows you to compare two -value (one of which will presumably be the caught object). -TS_ASSERT_THROWS_ASSERT is the general case, and allows you to -make any assertion about the thrown value. These macros may seem a -little complicated, but they can be very useful; see below for an -example. - -

    -     
    -     void testFunctionsWhichThrowExceptions( void )
    -     {
    -        TS_ASSERT_THROWS_NOTHING( checkInput(1) );
    -        TS_ASSERT_THROWS( checkInput(-11), std::runtime_error );
    -        TS_ASSERT_THROWS_ANYTHING( thirdPartyFunction() );
    -     
    -        TS_ASSERT_THROWS_EQUALS( validate(), const std::exception &e, 
    -                                 e.what(), "Invalid value" );
    -        TS_ASSERT_THROWS_ASSERT( validate(), const Error &e, 
    -                                 TS_ASSERT_DIFFERS( e.code(), SUCCESS ) );
    -     }
    -     
    -
    - -

    3.1.12 TS_TRACE and TS_WARN

    - -

    - - - (v3.0.1) -TS_WARN just prints out a message, like the -#warning preprocessor directive. I find it very useful for "to -do" items. For example: - -

    -     
    -     void testToDoList( void )
    -     {
    -        TS_WARN( "TODO: Write some tests!" );
    -        TS_WARN( "TODO: Make $$$ fast!" );
    -     }
    -     
    -
    - -

    In the GUI, TS_WARN sets the bar color to yellow (unless it was -already red). - - (v3.9.0) -TS_TRACE is the same, except that it -doesn't change the color of the progress bar. - -

    3.1.13 The ETS_ macros

    - -

    The TS_ macros mentioned above will catch exceptions thrown from tested code -and fail the test, as if you called TS_FAIL(). -Sometimes, however, you may want to catch the exception yourself; when you do, you can -use the ETS_ versions of the macros. - -

    -     
    -     void testInterestingThrower()
    -     {
    -        // Normal way: if an exception is caught we can't examine it
    -        TS_ASSERT_EQUALS( foo(2), 4 );
    -     
    -        // More elaborate way:
    -        try { ETS_ASSERT_EQUALS( foo(2), 4 ); } 
    -        catch( const BadFoo &e ) { TS_FAIL( e.bar() ); }
    -     }
    -     
    -
    - -

    3.1.14 The TSM_ macros

    - -

    Sometimes the default output generated by the ErrorPrinter doesn't give you enough -information. This often happens when you move common test functionality to helper functions -inside the test suite; when an assertion fails, you do not know its origin. - -

    In the example below (which is the file sample/MessageTest.h from the CxxTest distribution), -we need the message feature to know which invocation of checkValue() failed: - -

    -     
    -     class MessageTest : public CxxTest::TestSuite
    -     {
    -     public:
    -        void testValues()
    -        {
    -           checkValue( 0, "My hovercraft" );
    -           checkValue( 1, "is full" );
    -           checkValue( 2, "of eels" );
    -        }
    -     
    -        void checkValue( unsigned value, const char *message )
    -        {
    -           TSM_ASSERT( message, value );
    -           TSM_ASSERT_EQUALS( message, value, value * value );
    -        }
    -     };
    -     
    -
    - -
    3.1.14.1 The ETSM_ macros
    - -

    Note: As with normal asserts, all TSM_ macros have their -non-exception-safe counterparts, the ETSM_ macros. - -

    3.2 Running the samples

    - -

    - -

    CxxTest comes with some samples in the sample/ subdirectory of -the distribution. If you look in that directory, you will see three -Makefiles: Makefile.unix, Makefile.msvc and -Makefile.bcc32 which are for Linux/Unix, MS Visual C++ and -Borland C++, repectively. These files are provided as a starting point, -and some options may need to be tweaked in them for your system. - -

    If you are running under Windows, a good guess would be to run -nmake -fMakefile.msvc run_win32 (you may need to run -VCVARS32.BAT first). Under Linux, make --fMakefile.unix run_x11 should probably work. - -

    3.3 Test fixtures

    - -

    When you have several test cases for the same module, -you often find that all of them start with more or less -the same code--creating objects, files, inputs, etc. -They may all have a common ending, too--cleaning up -the mess you left. - -

    You can (and should) put all this code in a common place by overriding -the virtual functions TestSuite::setUp() and -TestSuite::tearDown(). setUp() will -then be called before each test, and tearDown() -after each test. - -

    -     
    -     class TestFileOps : public CxxTest::TestSuite 
    -     {
    -     public:
    -        void setUp() { mkdir( "playground" ); }
    -        void tearDown() { system( "rm -Rf playground"); }
    -     
    -        void testCreateFile()
    -        {
    -           FileCreator fc( "playground" );
    -           fc.createFile( "test.bin" );
    -           TS_ASSERT_EQUALS( access( "playground/test.bin", 0 ), 0 );
    -        }
    -     };
    -     
    -
    - -

    Note new users: This is probably the single most important -feature to use when your tests become non-trivial. - -

    3.3.1 Test suite level fixtures

    - -

    setUp()/tearDown() are executed around each test case. If -you need a fixture on the test suite level, i.e. something that gets -constructed once before all the tests in the test suite are run, see -Dynamically creating test suites below. - -

    3.4 Integrating with your build environment

    - -

    It's very hard to maintain your tests if you have to generate, compile and run the test runner -manually all the time. -Fortunately, that's why we have build tools! - -

    3.4.1 Overview

    - -

    Let's assume you're developing an application. -What I usually do is the following: -

      -
    • Split the application into a library and a main module that just calls - the library classes. - This way, the test runner will be able to access all your classes through - the library. -
    • Create another application (or target, or project, or whatever) for the test runner. - Make the build tool generate it automatically. -
    • For extra points, make the build tool run the tests automatically. -
    - -

    3.4.2 Actually doing it

    - -

    Unfortunately, there are way too many different build tools and IDE's for me -to give ways to use CxxTest with all of them. - -

    I will try to outline the usage for some cases. - -

    3.4.2.1 Using Makefiles
    - -

    Generating the tests with a makefile is pretty straightforward. -Simply add rules to generate, compile and run the test runner. - -

    -     
    -     all: lib run_tests app
    -     
    -     # Rules to build your targets
    -     lib: ...
    -     
    -     app: ...
    -     
    -     # A rule that runs the unit tests
    -     run_tests: runner
    -             ./runner
    -     
    -     # How to build the test runner
    -     runner: runner.cpp lib
    -             g++ -o $@ $^
    -     
    -     # How to generate the test runner
    -     runner.cpp: SimpleTest.h ComplicatedTest.h
    -              cxxtestgen.pl -o $@ --error-printer $^
    -     
    -
    - -
    3.4.2.2 Using Cons
    - - Cons is a powerful and -versatile make replacement which uses Perl scripts instead of Makefiles. - -

    See sample/Construct in the CxxTest distribution for an example of building CxxTest test runners -with Cons. - -

    3.4.2.3 Using Microsoft Visual Studio
    - -

    I have tried several ways to integrate CxxTest with visual studio, none of -which is perfect. Take a look at sample/msvc in the distribution -to see the best solution I'm aware of. Basically, the workspace has three -projects: - -

      -
    • The project CxxTest_3_Generate runs cxxtestgen. - -
    • The project CxxTest_2_Build compiles the generated file. - -
    • The project CxxTest_1_Run runs the tests. -
    - -

    This method certainly works, and the test results are conveniently -displayed as compilation errors and warnings (for -TS_WARN()). However, there are still a few things missing; -to integrate this approach with your own project, you usually need to -work a little bit and tweak some makefiles and project options. I have -provided a small script in sample/msvc/FixFiles.bat to automate -some of the process. - -

    3.4.2.4 Using Microsoft Windows DDK
    - -

    Unit testing for device drivers?! Why not? -And besides, the build utility can also be used to build -user-mode application. - -

    To use CxxTest with the build utility, -you add the generated tests file as an extra dependency -using the NTBUILDTARGET0 macro and the Makefile.inc -file. - -

    You can see an example of how to do this in the CxxTest distribution -under sample/winddk. - -

    3.5 Graphical user interface

    - -

    - -

    There are currently three GUIs implemented: native Win32, native X11 and -Qt. To use this feature, just specify --gui=X11Gui, ---gui=Win32Gui or --gui=QtGui as a parameter for -cxxtestgen (instead of e.g. --error-printer). A -progress bar is displayed, but the results are still written to standard -output, where they can be processed by your IDE (e.g. Emacs or Visual -Studio). The default behavior of the GUI is to close the window after -the last test. - -

    Note that whatevr GUI you use, you can combine it with the ---runner option to control the formatting of the text output, -e.g. Visual Studio likes it better if you use ---runner=ParenPrinter. - -

    3.5.1 Starting the GUI minimized

    - -

    If you run the generated Win32 or Qt GUIs with the command line --minimized, the test window will start minimized (iconified) -and only pop up if there is an error (the bar turns red). This is useful -if you find the progress bar distracting and only want to check it if -something happens. - -

    3.5.2 Leaving the GUI open

    - -

    The Win32 GUI accepts the -keep which instructs it to leave the -window open after the tests are done. This allows you to see how many -tests failed and how much time it took. - -

    3.5.3 Screenshots!

    - -

    As with any self-respecting GUI application, here are some screenshots for -you to enjoy: - -

      - -
    • Using the Qt GUI on Linux (with the WindowMaker window manager): -
      qt.png
      -

      -

    • Using the Win32 GUI on Windows 98: -
      win32.png
      -

      -

    • Using the X11 GUI (with the venerable TWM): -
      x11.png
      -

      -

    • And of course, no GUI is complete without the ability to mess around with -its appearance: -
      qt2.png
      -

      -

      Ahhh. Nothing like a beautiful user interface. - -

    - -

    4 Advanced topics

    - -

    Topics in this section are more technical, and you probably won't find them -interesting unless you need them. - -

    4.1 Aborting tests after failures

    - -

    Usually, when a TS_ASSERT_* macro fails, CxxTest moves on to the -next line. In many cases, however, this is not the desired behavior. -Consider the following code: - -

    -     
    -     void test_memset()
    -     {
    -        char *buffer = new char[1024];
    -        TS_ASSERT( buffer );
    -        memset( buffer, 0, 1024 ); // But what if buffer == 0?
    -     }
    -     
    -
    - -

    If you have exception handling enabled, you can make CxxTest exit each -test as soon as a failure occurs. To do this, you need to define -CXXTEST_ABORT_TEST_ON_FAIL before including the CxxTest -headers. This can be done using the --abort-on-fail -command-line option or in a template file; see -sample/aborter.tpl in the distribution. Note that if CxxTest -doesn't find evidence of exception handling when scanning your files, -this feature will not work. To overcome this, use the ---have-eh command-line option. - -

    4.1.1 Controlling this behavior at runtime

    - - (v3.8.5) -In some scenarios, you may want some tests to abort on -failed assertions and others to continue. To do this you use the ---abort-on-fail option and call the function -CxxTest::setAbortTestOnFail( bool ) to change the runtime -behavior. This flag is reset (normally, to true) after each -test, but you can set it in your test suite's setUp() function to -modify the behavior for all tests in a suite. - - (v3.9.0) -Note that this behavior is available whenever you have -exception handling (--have-eh or CXXTEST_HAVE_EH); all ---abort-on-fail does is set the default to true. - -

    4.2 Commenting out tests

    - -

    CxxTest does a very simple analysis of the input files, which is sufficient in most cases. -This means, for example, that you can't indent you test code in "weird" ways. - -

    A slight inconvenience arises, however, when you want to comment out -tests. Commenting out the tests using C-style comments or the -preprocessor will not work: - -

    -     
    -     class MyTest : public CxxTest::TestSuite
    -     {
    -     public:
    -     /*
    -        void testCommentedOutStillGetsCalled()
    -        {
    -        }
    -     */
    -     
    -     #if 0
    -        void testMarkedOutStillGetsCalled()
    -        {
    -        }
    -     #endif
    -     };
    -     
    -
    - - (v3.10.0) -If you need to comment out tests, use C++-style -comments. Also, if you just don't want CxxTest to run a specific test -function, you can temporarily change its name, e.g. by prefixing it with -x: - -
    -     
    -     class MyTest : public CxxTest::TestSuite
    -     {
    -     public:
    -     // void testFutureStuff()
    -     // {
    -     // }
    -     
    -        void xtestFutureStuff()
    -        {
    -        }
    -     };
    -     
    -
    - -

    4.3 Comparing equality for your own types

    - -

    You may have noticed that TS_ASSERT_EQUALS() only works for built-in -types. -This is because CxxTest needs a way to compare object and to convert them to strings, -in order to print them should the test fail. - -

    If you do want to use TS_ASSERT_EQUALS() on your own data types, -this is how you do it. - -

    4.3.1 The equality operator

    - -

    First of all, don't forget to implement the equality operator (operator==()) -on your data types! - -

    4.3.2 Value traits

    - -

    Since CxxTest tries not to rely on any external library (including the standard library, -which is not always available), conversion from arbitrary data types to strings -is done using value traits. - -

    For example, to convert an integer to a string, CxxTest does the following actions: -

      -
    • int i = value to convert; -
    • CxxTest::ValueTraits<int> converter(i); -
    • string = converter.asString(); -
    - -

    CxxTest comes with predefined ValueTraits for int, -char, dobule etc. in cxxtest/ValueTraits.h in the -cxxtest-selftest archive. - -

    4.3.3 Unknown types

    - -

    Obviously, CxxTest doesn't "know" about all possible types. -The default ValueTraits class for unknown types dumps up to 8 bytes of the value in hex format. - -

    For example, the following code -

    -     
    -     #include <cxxtest/TestSuite.h>
    -     
    -     class TestMyData : public CxxTest::TestSuite 
    -     {
    -     public:
    -        struct Data
    -        {
    -           char data[3];
    -        };
    -     
    -        void testCompareData()
    -        {
    -           Data x, y;
    -           memset( x.data, 0x12, sizeof(x.data) );
    -           memset( y.data, 0xF6, sizeof(y.data) );
    -           TS_ASSERT_EQUALS( x, y );
    -        }
    -     };
    -     
    -
    - would output -
    -     
    -     Running 1 test.
    -     TestMyData.h:16: Expected (x == y), found ({ 12 12 12 } != { F6 F6 F6 })
    -     Failed 1 of 1 test
    -     Success rate: 0%
    -     
    -
    - -

    4.3.4 Enumeration traits

    - - (v3.10.0) -CxxTest provides a simple way to define value traits for -your enumeration types, which is very handy for things like status -codes. To do this, simply use CXXTEST_VALUE_TRAITS as in the -following example: - -
    -     
    -     enum Status { STATUS_IDLE, STATUS_BUSY, STATUS_ERROR };
    -     
    -     CXXTEST_ENUM_TRAITS( Status,
    -                          CXXTEST_ENUM_MEMBER( STATUS_IDLE )
    -                          CXXTEST_ENUM_MEMBER( STATUS_BUSY )
    -                          CXXTEST_ENUM_MEMBER( STATUS_ERROR ) );
    -     
    -
    - -

    See sample/EnumTraits.h for a working sample. - -

    4.3.5 Defining new value traits

    - -

    Defining value traits for new (non-enumeration) types is easy. All you -need is to define a way to convert an object of your class to a -string. You can use this example as a possible skeleton: - -

    -     
    -     class MyClass 
    -     {
    -        int _value;
    -     
    -     public:
    -        MyClass( int value ) : _value( value ) {}
    -        int value() const { return _value; }
    -     
    -        // CxxTest requires a copy constructor
    -        MyClass( const MyClass &other ) : _value( other._value ) {}
    -     
    -        // If you want to use TS_ASSERT_EQUALS
    -        bool operator== ( const MyClass &other ) const { return _value == other._value; }
    -     
    -        // If you want to use TS_ASSERT_LESS_THAN
    -        bool operator== ( const MyClass &other ) const { return _value < other._value; }
    -     };
    -     
    -     #ifdef CXXTEST_RUNNING
    -     #include <cxxtest/ValueTraits.h>
    -     #include <stdio.h>
    -     
    -     namespace CxxTest 
    -     {
    -        CXXTEST_TEMPLATE_INSTANTIATION
    -        class ValueTraits<MyClass> 
    -        {
    -           char _s[256];
    -     
    -        public:
    -           ValueTraits( const MyClass &m ) { sprintf( _s, "MyClass( %i )", m.value() ); }
    -           const char *asString() const { return _s; }
    -        };
    -     };
    -     #endif // CXXTEST_RUNNING
    -     
    -
    - -
    4.3.5.1 Defining value traits for template classes
    - -

    A simple modification to the above scheme allows you to define value -traits for your template classes. Unfortunately, this syntax (partial -template specialization) is not supported by some popular C++ compilers. -Here is an example: - -

    -     
    -     template<class T>
    -     class TMyClass
    -     {
    -        T _value;
    -     
    -     public:
    -        TMyClass( const T &value ) : _value( value );
    -        const T &value() const { return _value; }
    -     
    -        // CxxTest requires a copy constructor
    -        TMyClass( const TMyClass<T> &other ) : _value( other._value ) {}
    -        
    -        // If you want to use TS_ASSERT_EQUALS
    -        bool operator== ( const TMyClass<T> &other ) const { return _value == other._value; }
    -     };
    -     
    -     #ifdef CXXTEST_RUNNING
    -     #include <cxxtest/ValueTraits.h>
    -     #include <typeinfo>
    -     #include <sstream>
    -     
    -     namespace CxxTest 
    -     {
    -        template<class T>
    -        class ValueTraits< TMyClass<T> > 
    -        {
    -           std::ostringstream _s;
    -     
    -        public:
    -           ValueTraits( const TMyClass<T> &t ) 
    -              { _s << typeid(t).name() << "( " << t.value() << " )"; }
    -           const char *asString() const { return _s.str().c_str(); }
    -        };
    -     };
    -     #endif // CXXTEST_RUNNING
    -     
    -
    - -

    4.3.6 Overriding the default value traits

    - - (v2.8.2) -If you don't like the way CxxTest defines the default ValueTraits, -you can override them by #define-ing CXXTEST_USER_VALUE_TRAITS; -this causes CxxTest to omit the default definitions, and from there on you are -free to implement them as you like. - -

    You can see a sample of this technique in test/UserTraits.tpl in -the cxxtest-selftest archive. - -

    4.4 Global Fixtures

    - - (v3.5.1) -The setUp() and tearDown() functions allow -to to have code executed before and after each test. What if you want -some code to be executed before all tests in all test suites? -Rather than duplicate that code, you can use global fixtures. -These are basically classes that inherit from -CxxTest::GlobalFixture. All objects of such classes are -automatically notified before and after each test case. It is best to -create them as static objects so they get called right from the start. -Look at test/GlobalFixtures.h in the cxxtest-selftest -archive. - -

    Note: Unlike setUp() and tearDown() in -TestSuite, global fixtures should return a bool value to -indicate success/failure. - -

    4.4.1 World fixtures

    - - (v3.8.1) -CxxTest also allows you to specify code which is executed -once at the start of the testing process (and the corresponding cleanup -code). To do this, create (one or more) global fixture objects and -implement setUpWorld()/tearDownWorld(). For an example, -see test/WorldFixtures.h in the cxxtest-selftest archive. - -

    4.5 Mock Objects

    - - (v3.10.0) -Mock Objects are a very useful testing tool, which -consists (in a nutshell) of passing special objects to tested code. For -instance, to test a class that implements some protocol over TCP, you -might have it use an abstract ISocket interface and in the tests -pass it a MockSocket object. This MockSocket object can -then do anything your tests find useful, e.g. keep a log of all data -"sent" to verify later. - -

    So far, so good. But the problem when developing in C/C++ is that your -code probably needs to call global functions which you cannot -override. Just consider any code which uses fopen(), -fwrite() and fclose(). It is not very elegant to have -this code actually create files while being tested. Even more -importantly, you (should) want to test how the code behaves when "bad" -things happen, say when fopen() fails. Although for some cases -you can cause the effects to happen in the test code, this quickly -becomes "hairy" and unmaintainable. - -

    CxxTest solves this problem by allowing you to override any global -function while testing. Here is an outline of how it works, before we -see an actual example: -

      - -
    • For each function you want to override, you use the macro -CXXTEST_MOCK_GLOBAL to "prepare" the function (all is explained -below in excruciating detail). - -
    • In the tested code you do not call the global functions directly; -rather, you access them in the T (for Test) namespace. For -instance, your code needs to call T::fopen() instead of -fopen(). This is the equivalent of using abstract interfaces -instead of concrete classes. - -
    • You link the "real" binary with a source file that implements -T::fopen() by simply calling the original fopen(). - -
    • You link the test binary with a source file that implements -T::fopen() by calling a mock object. - -
    • To test, you should create a class that inherits T::Base_fopen -and implement its fopen() function. Simply by creating an object -of this class, calls made to T::fopen() will be redirected to it. - -
    - -

    This may seem daunting at first, so let us work our way through a simple -example. Say we want to override the well known standard library -function time(). - -

      - -
    • Prepare a header file to be used by both the real and test code. -
      -          
      -          // T/time.h
      -          #include <time.h>
      -          #include <cxxtest/Mock.h>
      -          
      -          CXXTEST_MOCK_GLOBAL( time_t,        /* Return type          */
      -                               time,          /* Name of the function */
      -                               ( time_t *t ), /* Prototype            */
      -                               ( t )          /* Argument list        */ );
      -          
      -
      - -
    • In our tested code, we now include the special header instead of the -system-supplied one, and call T::time() instead of time(). -
      -          
      -          // code.cpp
      -          #include <T/time.h>
      -          
      -          int generateRandomNumber()
      -          {
      -              return T::time( NULL ) * 3;
      -          }
      -          
      -
      - -
    • We also need to create a source file that implements T::time() by -calling the real function. This is extremely easy: just define -CXXTEST_MOCK_REAL_SOURCE_FILE before you include the header file: -
      -          
      -          // real_time.cpp
      -          #define CXXTEST_MOCK_REAL_SOURCE_FILE
      -          #include <T/time.h>
      -          
      -
      - -
    • Before we can start testing, we need a different implementation of -T::time() for our tests. This is just as easy as the previous -one: -
      -          
      -          // mock_time.cpp
      -          #define CXXTEST_MOCK_TEST_SOURCE_FILE
      -          #include <T/time.h>
      -          
      -
      - -
    • Now comes the fun part. In our test code, all we need to do is create a -mock, and the tested code will magically call it: -
      -          
      -          // TestRandom.h
      -          #include <cxxtest/TestSuite.h>
      -          #include <T/time.h>
      -          
      -          class TheTimeIsOne : public T::Base_time
      -          {
      -          public:
      -              time_t time( time_t * ) { return 1; }
      -          };
      -          
      -          class TestRandom : public CxxTest::TestSuite
      -          {
      -          public:
      -              void test_Random()
      -              {
      -                  TheTimeIsOne t;
      -                  TS_ASSERT_EQUALS( generateRandomNumber(), 3 );
      -              }
      -          };
      -          
      -
      - -
    - -

    4.5.1 Actually doing it

    - -

    I know that this might seem a bit heavy at first glance, but once you -start using mock objects you will never go back. The hardest part may -be getting this to work with your build system, which is why I have -written a simple example much like this one in sample/mock, which -uses GNU Make and G++. - -

    4.5.2 Advanced topic with mock functions

    - -
    4.5.2.1 Void functions
    - -

    Void function are a little different, and you use -CXXTEST_MOCK_VOID_GLOBAL to override them. This is identical to -CXXTEST_MOCK_GLOBAL except that it doesn't specify the return -type. Take a look in sample/mock/T/stdlib.h for a demonstation. - -

    4.5.2.2 Calling the real functions while testing
    - -

    From time to time, you might want to let the tested code call the real -functions (while being tested). To do this, you create a special mock -object called e.g. T::Real_time. While an object of this class -is present, calls to T::time() will be redirected to the real -function. - -

    4.5.2.3 When there is no real function
    - -

    Sometimes your code needs to call functions which are not available when -testing. This happens for example when you test driver code using a -user-mode test runner, and you need to call kernel functions. You can -use CxxTest's mock framework to provide testable implementations for the -test code, while maintaing the original functions for the real code. -This you do with CXXTEST_SUPPLY_GLOBAL (and -CXXTEST_SUPPLY_VOID_GLOBAL). For example, say you want to supply -your code with the Win32 kernel function IoCallDriver: -

    -     
    -     CXXTEST_SUPPLY_GLOBAL( NTSTATUS,                /* Return type */
    -                            IoCallDriver,            /* Name        */
    -                            ( PDEVICE_OBJECT Device, /* Prototype   */
    -                              PIRP Irp ),
    -                            ( Device, Irp )          /* How to call */ );
    -     
    -
    - The tested code (your driver) can now call IoCallDriver() -normally (no need for T::), and the test code uses -T::Base_IoCallDriver as with normal mock objects. - -

    Note: Since these macros can also be used to actually declare -the function prototypes (e.g. in the above example you might not be able -to include the real <ntddk.h> from test code), they also have an -extern "C" version which declares the functions with C -linkage. These are CXXTEST_SUPPLY_GLOBAL_C and -CXXTEST_SUPPLY_GLOBAL_VOID_C. - -

    4.5.2.4 Functions in namespaces
    - -

    Sometimes the functions you want to override are not in the global -namespace like time(): they may be global functions in other -namespaces or even static class member functions. The default mock -implementation isn't suitable for these. For them, you can use the -generic CXXTEST_MOCK, which is best explained by example. Say you -have a namespace Files, and you want to override the function -bool Files::FileExists( const String &name ), so that the mock -class will be called T::Base_Files_FileExists and the function to -implement would be fileExists. You would define it thus (of -course, you would normally want the mock class name and member function -to be the same as the real function): -

    -     
    -     CXXTEST_MOCK( Files_FileExists,       /* Suffix of mock class  */
    -                   bool,                   /* Return type           */
    -                   fileExists,             /* Name of mock member   */
    -                   ( const String &name ), /* Prototype             */
    -                   Files::FileExists,      /* Name of real function */
    -                   ( name )                /* Parameter list        */ );
    -     
    -
    - Needless to say, there is also CXXTEST_MOCK_VOID for void functions. - -

    There is also an equivalent version for CXXTEST_SUPPLY_GLOBAL, as -demonstrated by another function from the Win32 DDK: -

    -     
    -     CXXTEST_SUPPLY( AllocateIrp,         /* => T::Base_AllocateIrp */
    -                     PIRP,                /* Return type            */
    -                     allocateIrp,         /* Name of mock member    */
    -                     ( CCHAR StackSize ), /* Prototype              */
    -                     IoAllocateIrp,       /* Name of real function  */
    -                     ( StackSize )        /* Parameter list         */ );
    -     
    -
    - And, with this macro you have CXXTEST_SUPPLY_VOID and of course -CXXTEST_SUPPLY_C and CXXTEST_SUPPLY_VOID_C. - -
    4.5.2.5 Overloaded functions
    - -

    If you have two or more global functions which have the same name, you -cannot create two mock classes with the same name. The solution is to -use the general CXXTEST_MOCK/CXXTEST_MOCK_VOID as above: -just give the two mock classes different names. - -

    4.5.2.6 Changing the mock namespace
    - -

    Finally, if you don't like or for some reason can't use the T:: -namespace for mock functions, you can change it by defining -CXXTEST_MOCK_NAMESPACE. Have fun. - -

    4.6 Test Listeners and Test Runners

    - -

    A TestListener is a class that receives notifications about -the testing process, notably which assertions failed. CxxTest defines -a standard test listener class, ErrorPrinter, which is -responsible for printing the dots and messages seen above. When the -test runners generated in the examples run, they create an -ErrorPrinter and pass it to -TestRunner::runAllTests(). As you might have guessed, this -functions runs all the test you've defined and reports to the -TestListener it was passed. - -

    4.6.1 Other test listeners

    - -

    If you don't like or can't use the ErrorPrinter, you can use -any other test listener. -To do this you have to omit the --error-printer, --runner= -or --gui= switch when generating the tests file. -It is then up to you to write the main() function, using the -test listener of your fancy. - -

    4.6.1.1 The stdio printer
    - -

    If the ErrorPrinter's usage of std::cout clashes -with your environment or is unsupported by your compiler, don't dispair! -You may still be able to use the StdioPrinter, which does the -exact same thing but uses good old printf(). - -

    To use it, invoke cxxtestgen.pl with the --runner=StdioPrinter option. - - (v3.8.5) -Note: cxxtest/StdioPrinter makes -reference to stdout as the default output stream. In some -environments you may have <stdio.h> but not stdout, which -will cause compiler errors. To overcome this problem, use ---runner=StdioFilePrinter, which is exactly the same as ---runner=StdioPrinter, but with no default output stream. - -

    4.6.1.2 The Yes/No runner
    - -

    As an example, CxxTest also provides the simplest possible test listener, -one that just reports if there were any failures. -You can see an example of using this listener in sample/yes_no_runner.cpp. - -

    4.6.1.3 Template files
    - -

    To use you own test runner, or to use the supplied ones in different ways, you can use -CxxTest template files. These are ordinary source files with the embedded "command" -<CxxTest world> which tells cxxtestgen.pl to insert the world definition -at that point. You then specify the template file using the --template option. - -

    See samples/file_printer.tpl for an example. - -

    Note: CxxTest needs to insert certain definitions and -#include directives in the runner file. It normally does that -before the first #include <cxxtest/*.h> found in the template -file. If this behvaior is not what you need, use the "command" -<CxxTest preamble>. See test/preamble.tpl in the -cxxtest-selftest archive for an example of this. - -

    4.7 Dynamically creating test suites

    - -

    -Usually, your test suites are instantiated statically in the tests file, i.e. say you -defined class MyTest : public CxxTest::TestSuite, the generated file will -contain something like static MyTest g_MyTest;. - -

    If, however, your test suite must be created dynamically (it may need a constructor, -for instance), CxxTest doesn't know how to create it unless you tell it how. -You do this by writing two static functions, createSuite() and destroySuite(). - -

    See sample/CreatedTest.h for a demonstration. - -

    4.8 Static initialization

    - - (v3.9.0) -The generated runner source file depends quite -heavily on static initialization of the various "description" object -used to run your tests. If your compiler/linker has a problem with this -approach, use the --no-static-init option. - -

    Appendix A Command line options

    - -

    Here are the different command line options for cxxtestgen: - -

    A.1 --version

    - - (v3.7.1) -Specify --version or -v to see the version of CxxTest you are using. - -

    A.2 --output

    - -

    Specify --output=FILE or -o FILE to determine the output file name. - -

    A.3 --error-printer

    - -

    This option creates a test runner which uses the standard error printer class. - -

    A.4 --runner

    - -

    Specify --runner=CLASS to generate a test -runner that #includes <cxxtest/CLASS.h> and uses -CxxTest::CLASS as the test runner. - -

    The currently available runners are: -

    -
    --runner=ErrorPrinter -
    This is the standard error printer, which formats its output to std::cout. - -
    --runner=ParenPrinter -
    Identical to ErrorPrinter except that it prints line numbers in parantheses. -This is the way Visual Studio expects it. - -
    --runner=StdioPrinter -
    The same as ErrorPrinter except that it uses printf -instead of cout. - -
    --runner=YesNoRunner -
    This runner doesn't produce any output, merely returns a true/false result. - -
    - -

    A.5 --gui

    - -

    Specify --gui=CLASS to generate a test runner that -#includes <cxxtest/CLASS.h> and uses CxxTest::CLASS -to display a graphical user interface. This option can be combined with -the --runner option to determine the text-mode output format. -The default is the standard error printer. - -

    There are three different GUIs: -

    -
    --gui=Win32Gui -
    A native Win32 GUI. It has been tested on Windows 98, 2000 and XP and -should work unmodified on other 32-bit versions of Windows. - -
    --gui=X11Gui -
    A native XLib GUI. This GUI is very spartan and should work on any X server. - -
    --gui=QtGui -
    A GUI that uses the Qt library from Troll. It has been tested with Qt versiond 2.2.1 and 3.0.1. -
    - -

    A.6 --include

    - - (v3.5.1) -If you specify --include=FILE, cxxtestgen will add -#include "FILE" to the runner before including any other header. -This allows you to define things that modify the behavior of CxxTest, -e.g. your own ValueTraits. - -

    Note: If you want the runner to #inculde <FILE>, specify -it on the command line, e.g. --include=<FILE>. You will most -likely need to use shell escapes, e.g. "--include=<FILE>" or ---include=\<FILE\>. - -

    Examples: --include=TestDefs.h or --include=\<GlobalDefs.h\>. - -

    A.7 --template

    - -

    Specify --template=FILE to use FILE as a template file. -This is for cases for which --runner and/or --include -are not enough. One example is the Windows DDK; see -sample/winddk in the distribution. - -

    A.8 --have-eh

    - - (v2.8.4) -cxxtestgen will scan its input files for uses of exception -handling; if found, the TS_ macros will catch exceptions, -allowing the testing to continue. Use --have-eh to tell -cxxtestgen to enable that functionality even if exceptions -are not used in the input files. - -

    A.9 --no-eh

    - - (v3.8.5) -If you want cxxtestgen to ignore what may look as uses of -exception handling in your test files, specify --no-eh. - -

    A.10 --have-std

    - - (v3.10.0) -Same as --have-eh but for the standard library; -basically, if you use this flag, CxxTest will print the values of -std::string. - -

    Note: If you reference the standard library anywhere in your -test files, CxxTest will (usually) recognize it and automatically define -this. - -

    A.11 --no-std

    - - (v3.10.0) -The counterpart to --have-std, this tells -CxxTest to ignore any evidence it finds for the std:: namespace -in your code. Use it if your environment does not support std:: -but cxxtestgen thinks it does. - -

    A.12 --longlong

    - - (v3.6.0) -Specify --longlong=TYPE to have CxxTest recognize TYPE -as "long long" (e.g. --longlong=__int64). If you specify -just --longlong= (no type), CxxTest will use the default type -name of long long. - -

    A.13 --abort-on-fail

    - - (v2.8.2) -This useful option tells CxxTest to abort the current test when any -TS_ASSERT macro has failed. - -

    A.14 --part

    - - (v3.5.1) -This option tells CxxTest now to write the CxxTest globals in the output -file. Use this to link together more than one generated file. - -

    A.15 --root

    - - (v3.5.1) -This is the counterpart of --part; it makes sure that the -Cxxtest globals are written to the output file. If you specify this -option, you can use cxxtestgen without any input files to -create a file that hold only the "root" runner. - -

    A.16 --no-static-init

    - - (v3.9.0) -Use this option if you encounter problems with the static -initializations in the test runner. - -

    Appendix B Controlling the behavior of CxxTest

    - -

    Here are various #defines you can use to modify how CxxTest -works. You will need to #define them before including any -of the CxxTest headers, so use them in a template file or with the ---include option. - -

    B.1 CXXTEST_HAVE_STD

    - -

    This is equivalent to the --have-std option. - -

    B.2 CXXTEST_HAVE_EH

    - -

    This is equivalent to the --have-eh option. - -

    B.3 CXXTEST_ABORT_TEST_ON_FAIL

    - - (v2.8.0) -This is equivalent to the --abort-on-fail option. - -

    B.4 CXXTEST_USER_VALUE_TRAITS

    - -

    This tells CxxTest you wish to define you own ValueTraits. It will only -declare the default traits, which dump up to 8 bytes of the data as hex -values. - -

    B.5 CXXTEST_OLD_TEMPLATE_SYNTAX

    - -

    Some compilers (e.g. Borland C++ 5) don't support the standard way of -instantiating template classes. Use this define to overcome the problem. - -

    B.6 CXXTEST_OLD_STD

    - -

    Again, this is used to support pre-std:: standard libraries. - -

    B.7 CXXTEST_MAX_DUMP_SIZE

    - -

    This sets the standard maximum number of bytes to dump if -TS_ASSERT_SAME_DATA() fails. The default is 0, meaning -no limit. - -

    B.8 CXXTEST_DEFAULT_ABORT

    - -

    This sets the default value of the dynamic "abort on fail" flag. Of -course, this flag is only used when "abort on fail" is enabled. - -

    B.9 CXXTEST_LONGLONG

    - -

    This is equivalent to --longlong. - -

    Appendix C Runtime options

    - -

    The following functions can be called during runtime (i.e. from your -tests) to control the behavior of CxxTest. They are reset to their -default values after each test is executed (more precisely, after -tearDown() is called). Consequently, if you set them in the -setUp() function, they will be valid for the entire test suite. - -

    C.1 setAbortTestOnFail( bool )

    - -

    This only works when you have exception handling. It can be used to -tell CxxTest to temporarily change its behavior. The default value of -the flag is false, true if you set --abort-on-fail, -or CXXTEST_DEFAULT_ABORT if you #define it. - -

    C.2 setMaxDumpSize( unsigned )

    - -

    This temporarily sets the maximum number of bytes to dump if -TS_ASSERT_SAME_DATA() fails. The default is 0, meaning -no limit, or CXXTEST_MAX_DUMP_SIZE if you #define it. - -

    Appendix D Version history

    - -
      -
    • Version 3.10.0 (2004-11-20) -
        -
      • Added mock framework for global functions -
      • Added TS_ASSERT_THROWS_ASSERT and TS_ASSERT_THROWS_EQUALS -
      • Added CXXTEST_ENUM_TRAITS -
      • Improved support for STL classes (vector, map etc.) -
      • Added support for Digital Mars compiler -
      • Reduced root/part compilation time and binary size -
      • Support C++-style commenting of tests -
      -
    • Version 3.9.1 (2004-01-19) -
        -
      • Fixed small bug with runner exit code -
      • Embedded test suites are now deprecated -
      -
    • Version 3.9.0 (2004-01-17) -
        -
      • Added TS_TRACE -
      • Added --no-static-init -
      • CxxTest::setAbortTestOnFail() works even without --abort-on-fail -
      -
    • Version 3.8.5 (2004-01-08) -
        -
      • Added --no-eh -
      • Added CxxTest::setAbortTestOnFail() and CXXTEST_DEFAULT_ABORT -
      • Added CxxTest::setMaxDumpSize() -
      • Added StdioFilePrinter -
      -
    • Version 3.8.4 (2003-12-31) -
        -
      • Split distribution into cxxtest and cxxtest-selftest -
      • Added sample/msvc/FixFiles.bat -
      -
    • Version 3.8.3 (2003-12-24) -
        -
      • Added TS_ASSERT_PREDICATE -
      • Template files can now specify where to insert the preamble -
      • Added a sample Visual Studio workspace in sample/msvc -
      • Can compile in MSVC with warning level 4 -
      • Changed output format slightly -
      -
    • Version 3.8.1 (2003-12-21) -
        -
      • Fixed small bug when using multiple --part files. -
      • Fixed X11 GUI crash when there's no X server. -
      • Added GlobalFixture::setUpWorld()/tearDownWorld() -
      • Added leaveOnly(), activateAllTests() and sample/only.tpl -
      • Should now run without warnings on Sun compiler. -
      -
    • Version 3.8.0 (2003-12-13) -
        -
      • Fixed bug where Root.cpp needed exception handling -
      • Added TS_ASSERT_RELATION -
      • TSM_ macros now also tell you what went wrong -
      • Renamed Win32Gui::free() to avoid clashes -
      • Now compatible with more versions of Borland compiler -
      • Improved the documentation -
      -
    • Version 3.7.1 (2003-09-29) -
        -
      • Added --version -
      • Compiles with even more exotic g++ warnings -
      • Win32 Gui compiles with UNICODE -
      • Should compile on some more platforms (Sun Forte, HP aCC) -
      -
    • Version 3.7.0 (2003-09-20) -
        -
      • Added TS_ASSERT_LESS_THAN_EQUALS -
      • Minor cleanups -
      -
    • Version 3.6.1 (2003-09-15) -
        -
      • Improved QT GUI -
      • Improved portability some more -
      -
    • Version 3.6.0 (2003-09-04) -
        -
      • Added --longlong -
      • Some portability improvements -
      -
    • Version 3.5.1 (2003-09-03) -
        -
      • Major internal rewrite of macros -
      • Added TS_ASSERT_SAME_DATA -
      • Added --include option -
      • Added --part and --root to enable splitting the test runner -
      • Added global fixtures -
      • Enhanced Win32 GUI with timers, -keep and -title -
      • Now compiles with strict warnings -
      -
    • Version 3.1.1 (2003-08-27) -
        -
      • Fixed small bug in TS_ASSERT_THROWS_*() -
      -
    • Version 3.1.0 (2003-08-23) -
        -
      • Default ValueTraits now dumps value as hex bytes -
      • Fixed double invocation bug (e.g. TS_FAIL(functionWithSideEffects())) -
      • TS_ASSERT_THROWS*() are now "abort on fail"-friendly -
      • Win32 GUI now supports Windows 98 and doesn't need comctl32.lib -
      -
    • Version 3.0.1 (2003-08-07) -
        -
      • Added simple GUI for X11, Win32 and Qt -
      • Added TS_WARN() macro -
      • Removed --exit-code -
      • Improved samples -
      • Improved support for older (pre-std::) compilers -
      • Made a PDF version of the User's Guide -
      -
    • Version 2.8.4 (2003-07-21) -
        -
      • Now supports g++-3.3 -
      • Added --have-eh -
      • Fixed bug in numberToString() -
      -
    • Version 2.8.3 (2003-06-30) -
        -
      • Fixed bugs in cxxtestgen.pl -
      • Fixed warning for some compilers in ErrorPrinter/StdioPrinter -
      • Thanks Martin Jost for pointing out these problems! -
      -
    • Version 2.8.2 (2003-06-10) -
        -
      • Fixed bug when using CXXTEST_ABORT_TEST_ON_FAIL without standard library -
      • Added CXXTEST_USER_TRAITS -
      • Added --abort-on-fail -
      -
    • Version 2.8.1 (2003-01-16) -
        -
      • Fixed charToString() for negative chars -
      -
    • Version 2.8.0 (2003-01-13) -
        -
      • Added CXXTEST_ABORT_TEST_ON_FAIL for xUnit-like behaviour -
      • Added sample/winddk -
      • Improved ValueTraits -
      • Improved output formatter -
      • Started version history -
      -
    • Version 2.7.0 (2002-09-29) -
        -
      • Added embedded test suites -
      • Major internal improvements -
      - -
    - -

    - -

    -

    Table of Contents

    - -
    - - - - diff --git a/bsl/cxxtest/docs/index.html b/bsl/cxxtest/docs/index.html deleted file mode 100755 index 05ac5b3bab4d204338df71a094f3ef6ac5027929..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/docs/index.html +++ /dev/null @@ -1,56 +0,0 @@ - -CxxTest -

    Introduction

    - -

    CxxTest is a JUnit/CppUnit/xUnit-like framework for C++. - -

    Its advantages over existing alternatives are that it: -

      -
    • Doesn't require RTTI -
    • Doesn't require member template functions -
    • Doesn't require exception handling -
    • Doesn't require any external libraries (including memory management, - file/console I/O, graphics libraries) -
    • Is distributed entirely as a set of header files -
    - -

    This makes it extremely portable and usable. - -

    CxxTest is available under the GNU -Lesser General Public License. - -

    See the user's guide for information. -It is also available as a PDF file. - -

    The version history is available here. - -

    Getting CxxTest

    -You can always get the latest release from -here or -here. - -

    There are several files you can download: -

      -
    • cxxtest-version-1.noarch.rpm -
    • cxxtest-version.tar.gz -
    • cxxtest-version.zip -
    • cxxtest-guide-version.pdf (the user's guide) -
    -Note that, since CxxTest consists entirely of header files, -there is no distinction between source and binary distribution. - -

    There are also files called cxxtest-selftest-*: these -are used (usually by me) to test the portability of CxxTest, so you -can probably do without them. - -

    If you just can't wait for the next release, I sometimes upload betas -to here. - -

    Getting started

    -Get the sources and build the samples in the sample subdirectory. - -
    -

    - SourceForge Logo - - diff --git a/bsl/cxxtest/docs/qt.png b/bsl/cxxtest/docs/qt.png deleted file mode 100755 index 56a7a67478772098b321733e9ee36b737f13f40a..0000000000000000000000000000000000000000 Binary files a/bsl/cxxtest/docs/qt.png and /dev/null differ diff --git a/bsl/cxxtest/docs/qt2.png b/bsl/cxxtest/docs/qt2.png deleted file mode 100755 index 918a1f4b497e162f3bae8aacf73f80976afed837..0000000000000000000000000000000000000000 Binary files a/bsl/cxxtest/docs/qt2.png and /dev/null differ diff --git a/bsl/cxxtest/docs/win32.png b/bsl/cxxtest/docs/win32.png deleted file mode 100755 index 5de325bb1905c915793f7ac637dc38715068ddb5..0000000000000000000000000000000000000000 Binary files a/bsl/cxxtest/docs/win32.png and /dev/null differ diff --git a/bsl/cxxtest/docs/x11.png b/bsl/cxxtest/docs/x11.png deleted file mode 100755 index 9be8c195aaca1521d3d337c0834241bc22d1ca8d..0000000000000000000000000000000000000000 Binary files a/bsl/cxxtest/docs/x11.png and /dev/null differ diff --git a/bsl/cxxtest/sample/Construct b/bsl/cxxtest/sample/Construct deleted file mode 100755 index b8019616a9084453315342c064be5e5f0a3dc13f..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/Construct +++ /dev/null @@ -1,64 +0,0 @@ -# -*- Perl -*- - -# -# This file shows how to use CxxTest with Cons -# - -$env = new cons( CXX => ("$^O" eq 'MSWin32') ? 'cl -nologo -GX' : 'c++', - CPPPATH => '..', - CXXTESTGEN => 'perl -w ../cxxtestgen.pl' ); - -@tests = <*.h>; - -# The error printer is the most basic runner -CxxTestErrorPrinter $env 'error_printer', @tests; - -# You can also specify which runner you want to use -CxxTestRunner $env 'stdio_printer', 'StdioPrinter', @tests; - -# For more control, use template files -CxxTestTemplate $env 'file_printer', 'file_printer.tpl', @tests; - -# Or, you can always separate the tests from the runner -CxxTest $env 'tests.cpp', '', @tests; -Program $env 'yes_no_runner', ('yes_no_runner.cpp', 'tests.cpp'); - - -# -# Here is the code used to build these files -# You can use this in your own Construct files -# - -# cons::CxxTest $env $dst, $options, @srcs -# Generates a CxxTest source file, passing the specified options to cxxtestgen -sub cons::CxxTest($$$@) { - my ($env, $dst, $options, @srcs) = @_; - Command $env $dst, @srcs, "%CXXTESTGEN -o %> ${options} %<"; -} - -# cons::CxxTestTemplate $env $dst, $template, @srcs -# Generates and builds a CxxTest runner using a template file -sub cons::CxxTestTemplate($$$@) { - my ($env, $dst, $template, @srcs) = @_; - my $source = "${dst}.cpp"; - CxxTest $env $source, "--template=${template}", ($template, @srcs); - Program $env $dst, $source; -} - -# cons::CxxTestRunner $env $dst, $runner, @srcs -# Generates and builds a CxxTest runner using the --runner option -sub cons::CxxTestRunner($$$@) { - my ($env, $dst, $runner, @srcs) = @_; - my $source = "${dst}.cpp"; - CxxTest $env $source, "--runner=${runner}", @srcs; - Program $env $dst, $source; -} - -# cons::CxxTestErrorPrinter $env $dst, @srcs -# Generates and builds a CxxTest ErrorPrinter -sub cons::CxxTestErrorPrinter($$@) { - my ($env, $dst, @srcs) = @_; - CxxTestRunner $env $dst, 'ErrorPrinter', @srcs; -} - - diff --git a/bsl/cxxtest/sample/CreatedTest.h b/bsl/cxxtest/sample/CreatedTest.h deleted file mode 100755 index 84e8ae8a4bf1def0534ff69058d9932af881dd36..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/CreatedTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __CREATEDTEST_H -#define __CREATEDTEST_H - -#include -#include -#include - -// -// This test suite shows what to do when your test case -// class cannot be instantiated statically. -// As an example, this test suite requires a non-default constructor. -// - -class CreatedTest : public CxxTest::TestSuite -{ - char *_buffer; -public: - CreatedTest( unsigned size ) : _buffer( new char[size] ) {} - virtual ~CreatedTest() { delete [] _buffer; } - - static CreatedTest *createSuite() { return new CreatedTest( 16 ); } - static void destroySuite( CreatedTest *suite ) { delete suite; } - - void test_nothing() - { - TS_FAIL( "Nothing to test" ); - } -}; - - -#endif // __CREATEDTEST_H diff --git a/bsl/cxxtest/sample/DeltaTest.h b/bsl/cxxtest/sample/DeltaTest.h deleted file mode 100755 index 7223c3af258f6dfc53f96c96b041eb4c1f859e7f..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/DeltaTest.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __DELTATEST_H -#define __DELTATEST_H - -#include -#include - -class DeltaTest : public CxxTest::TestSuite -{ - double _pi, _delta; - -public: - void setUp() - { - _pi = 3.1415926535; - _delta = 0.0001; - } - - void testSine() - { - TS_ASSERT_DELTA( sin(0.0), 0.0, _delta ); - TS_ASSERT_DELTA( sin(_pi / 6), 0.5, _delta ); - TS_ASSERT_DELTA( sin(_pi / 2), 1.0, _delta ); - TS_ASSERT_DELTA( sin(_pi), 0.0, _delta ); - } -}; - -#endif // __DELTATEST_H diff --git a/bsl/cxxtest/sample/EnumTraits.h b/bsl/cxxtest/sample/EnumTraits.h deleted file mode 100755 index 1a987318f65039d3195fcf69d7634d74e42e7655..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/EnumTraits.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// This is a test of CxxTest's ValueTraits for enumerations. -// -#include - -// -// First define your enumeration -// -enum Answer { - Yes, - No, - Maybe, - DontKnow, - DontCare -}; - -// -// Now make CxxTest aware of it -// -CXXTEST_ENUM_TRAITS( Answer, - CXXTEST_ENUM_MEMBER( Yes ) - CXXTEST_ENUM_MEMBER( No ) - CXXTEST_ENUM_MEMBER( Maybe ) - CXXTEST_ENUM_MEMBER( DontKnow ) - CXXTEST_ENUM_MEMBER( DontCare ) ); - -class EnumTraits : public CxxTest::TestSuite -{ -public: - void test_Enum_traits() - { - TS_FAIL( Yes ); - TS_FAIL( No ); - TS_FAIL( Maybe ); - TS_FAIL( DontKnow ); - TS_FAIL( DontCare ); - TS_FAIL( (Answer)1000 ); - } -}; diff --git a/bsl/cxxtest/sample/ExceptionTest.h b/bsl/cxxtest/sample/ExceptionTest.h deleted file mode 100755 index 68363c87401860f8873ef5be334fdb7e1bcf815d..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/ExceptionTest.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef __EXCEPTIONTEST_H -#define __EXCEPTIONTEST_H - -#include - -// -// This test suite demonstrates the use of TS_ASSERT_THROWS -// - -class ExceptionTest : public CxxTest::TestSuite -{ -public: - void testAssertion( void ) - { - // This assert passes, since throwThis() throws (Number) - TS_ASSERT_THROWS( throwThis(3), const Number & ); - // This assert passes, since throwThis() throws something - TS_ASSERT_THROWS_ANYTHING( throwThis(-30) ); - // This assert fails, since throwThis() doesn't throw char * - TS_ASSERT_THROWS( throwThis(5), const char * ); - // This assert fails since goodFunction() throws nothing - TS_ASSERT_THROWS_ANYTHING( goodFunction(1) ); - // The regular TS_ASSERT macros will catch unhandled exceptions - TS_ASSERT_EQUALS( throwThis(3), 333 ); - // You can assert that a function throws nothing - TS_ASSERT_THROWS_NOTHING( throwThis(-1) ); - // If you want to catch the exceptions yourself, use the ETS_ marcos - try { - ETS_ASSERT_EQUALS( throwThis(3), 333 ); - } catch( const Number & ) { - TS_FAIL( "throwThis(3) failed" ); - } - } - -private: - void goodFunction( int ) - { - } - - class Number - { - public: - Number( int ) {} - }; - - int throwThis( int i ) - { - throw Number( i ); - } -}; - -#endif // __EXCEPTIONTEST_H diff --git a/bsl/cxxtest/sample/FixtureTest.h b/bsl/cxxtest/sample/FixtureTest.h deleted file mode 100755 index 653c7a14ae7f12a9a1ce0c69376ab173797644d8..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/FixtureTest.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __FIXTURETEST_H -#define __FIXTURETEST_H - -#include -#include - -// -// This test suite shows how to use setUp() and tearDown() -// to initialize data common to all tests. -// setUp()/tearDown() will be called before and after each -// test. -// - -class FixtureTest : public CxxTest::TestSuite -{ - char *_buffer; -public: - void setUp() - { - _buffer = new char[1024]; - } - - void tearDown() - { - delete [] _buffer; - } - - void test_strcpy() - { - strcpy( _buffer, "Hello, world!" ); - TS_ASSERT_EQUALS( _buffer[0], 'H' ); - TS_ASSERT_EQUALS( _buffer[1], 'E' ); - } -}; - - -#endif // __FIXTURETEST_H diff --git a/bsl/cxxtest/sample/Makefile.PL b/bsl/cxxtest/sample/Makefile.PL deleted file mode 100755 index d29afcc68838584b17593cd9c4eace09e9cfcc49..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/Makefile.PL +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl -# -# This isn't a "real" `Makefile.PL' -# It just copies the correct `Makefile.*' to `Makefile' -# -use strict; -use Getopt::Long; -use File::Copy; - -sub usage() { - die "Usage: $0 [--bcc32]\n"; -} - -my $source; -my $target = 'Makefile'; -my $windows = $ENV{'windir'}; - -GetOptions( 'bcc32' => sub { $source = 'Makefile.bcc32' } ) or usage(); -if ( !defined( $source ) ) { - $source = $windows ? 'Makefile.msvc' : 'Makefile.unix'; -} - -unlink($target); -$windows ? copy($source, $target) : symlink($source, $target); - -print "`Makefile' is now `$source'.\n"; - -# -# Local Variables: -# compile-command: "perl Makefile.PL" -# End: -# diff --git a/bsl/cxxtest/sample/Makefile.bcc32 b/bsl/cxxtest/sample/Makefile.bcc32 deleted file mode 100755 index f000f30114b2bf2a84c643f5c483389171f1474a..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/Makefile.bcc32 +++ /dev/null @@ -1,94 +0,0 @@ -# -# Makefile for Borland C++ -# Make sure bcc32.exe is in the PATH or change CXXC below -# - -# For the Win32 GUI -#WIN32_FLAGS = user32.lib comctl32.lib - -# For the Qt GUI -#QTDIR = c:\qt -QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib - - -TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe -GUI_TARGETS = win32_runner.exe qt_runner.exe -TESTS = *.h -GUI_TESTS = gui/GreenYellowRed.h $(TESTS) -TESTGEN = perl -w ../cxxtestgen.pl -CXXC = bcc32.exe -w- -I. -I.. - -all: $(TARGETS) - -clean: - del *~ *.o *.obj - del $(TARGETS) - del $(GUI_TARGETS) - del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp - del win32_runner.cpp qt_runner.cpp - -distclean: clean - del Makefile - -run: error_printer.exe - error_printer.exe - -run_win32: win32_runner.exe - win32_runner.exe - -run_qt: qt_runner.exe - qt_runner.exe - -error_printer.cpp: $(TESTS) - $(TESTGEN) -o error_printer.cpp --error-printer $(TESTS) - -stdio_printer.cpp: $(TESTS) - $(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS) - -file_printer.cpp: file_printer.tpl $(TESTS) - $(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS) - -aborter.cpp: aborter.tpl $(TESTS) - $(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS) - -only.cpp: only.tpl $(TESTS) - $(TESTGEN) -o only.cpp --template=only.tpl $(TESTS) - -tests.cpp: $(TESTS) - $(TESTGEN) -o tests.cpp $(TESTS) - -win32_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS) - -qt_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS) - -error_printer.exe: error_printer.cpp - $(CXXC) -eerror_printer.exe error_printer.cpp - -stdio_printer.exe: stdio_printer.cpp - $(CXXC) -estdio_printer.exe stdio_printer.cpp - -file_printer.exe: file_printer.cpp - $(CXXC) -efile_printer.exe file_printer.cpp - -only.exe: only.cpp - $(CXXC) -eonly.exe only.cpp - -aborter.exe: aborter.cpp - $(CXXC) -eaborter.exe aborter.cpp - -yes_no_runner.exe: yes_no_runner.cpp tests.cpp - $(CXXC) -eyes_no_runner.exe yes_no_runner.cpp tests.cpp - -win32_runner.exe: win32_runner.cpp - $(CXXC) -ewin32_runner.exe win32_runner.cpp $(WIN32_FLAGS) - -qt_runner.exe: qt_runner.cpp - $(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS) - -# -# Local Variables: -# compile-command: "make -fMakefile.bcc32" -# End: -# diff --git a/bsl/cxxtest/sample/Makefile.msvc b/bsl/cxxtest/sample/Makefile.msvc deleted file mode 100755 index 35ce2f9b171a52a9e2c2a83ecfaf6c5fb5335ab7..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/Makefile.msvc +++ /dev/null @@ -1,93 +0,0 @@ -# -# Makefile for Microsoft Visual C++ -# Make sure cl.exe is in the PATH (run vcvars.bat) or change CXXC below -# - -# For the Win32 GUI -WIN32_FLAGS = user32.lib - -# For the Qt GUI -# QTDIR = c:\qt -QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib - -TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe -GUI_TARGETS = win32_runner.exe qt_runner.exe -TESTS = *.h -GUI_TESTS = gui/GreenYellowRed.h $(TESTS) -TESTGEN = perl -w ../cxxtestgen.pl -CXXC = cl.exe -GX -W3 -WX -I. -I.. - -all: $(TARGETS) - -clean: - del *~ *.o *.obj - del $(TARGETS) - del $(GUI_TARGETS) - del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp - del win32_runner.cpp qt_runner.cpp - -distclean: clean - del Makefile - -run: error_printer.exe - error_printer.exe - -run_win32: win32_runner.exe - win32_runner.exe - -run_qt: qt_runner.exe - qt_runner.exe - -error_printer.cpp: $(TESTS) - $(TESTGEN) -o error_printer.cpp --error-printer $(TESTS) - -stdio_printer.cpp: $(TESTS) - $(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS) - -file_printer.cpp: file_printer.tpl $(TESTS) - $(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS) - -aborter.cpp: aborter.tpl $(TESTS) - $(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS) - -only.cpp: only.tpl $(TESTS) - $(TESTGEN) -o only.cpp --template=only.tpl $(TESTS) - -tests.cpp: $(TESTS) - $(TESTGEN) -o tests.cpp $(TESTS) - -win32_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS) - -qt_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS) - -error_printer.exe: error_printer.cpp - $(CXXC) -o error_printer.exe error_printer.cpp - -stdio_printer.exe: stdio_printer.cpp - $(CXXC) -o stdio_printer.exe stdio_printer.cpp - -file_printer.exe: file_printer.cpp - $(CXXC) -o file_printer.exe file_printer.cpp - -only.exe: only.cpp - $(CXXC) -o only.exe only.cpp - -aborter.exe: aborter.cpp - $(CXXC) -o aborter.exe aborter.cpp - -yes_no_runner.exe: yes_no_runner.cpp tests.cpp - $(CXXC) -o yes_no_runner.exe yes_no_runner.cpp tests.cpp - -win32_runner.exe: win32_runner.cpp - $(CXXC) -o win32_runner.exe win32_runner.cpp $(WIN32_FLAGS) - -qt_runner.exe: qt_runner.cpp - $(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS) - -# -# Local Variables: -# compile-command: "nmake -fMakefile.msvc" -# End: -# diff --git a/bsl/cxxtest/sample/Makefile.unix b/bsl/cxxtest/sample/Makefile.unix deleted file mode 100755 index 6bcbb7022ffc066d6464bdc1919754a930ac15f9..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/Makefile.unix +++ /dev/null @@ -1,88 +0,0 @@ -# -# Makefile for UN*X-like systems -# - -# Change this line if you want a different compiler -CXXC = c++ -fsigned-char -Wall -W -Werror -I. -I.. - -# If you want to use python, specify USE_PYTHON=1 on the command line -ifdef USE_PYTHON - TESTGEN = ../cxxtestgen.py -else - TESTGEN = ../cxxtestgen.pl -endif - -# For the X11 GUI -X11_FLAGS = -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 - -# For the Qt GUI -#QTDIR = /usr/lib/qt -QTLIB = -lqt-mt -#QTLIB = -lqt -QT_FLAGS = -I$(QTDIR)/include -L$(QTDIR)/lib $(QTLIB) -O2 - -TARGETS = error_printer stdio_printer yes_no_runner file_printer aborter only -GUI_TARGETS = x11_runner qt_runner -TESTS = *.h -GUI_TESTS = gui/GreenYellowRed.h $(TESTS) - -all: $(TARGETS) - -clean: - rm -f *~ *.o *.obj $(TARGETS) $(GUI_TARGETS) - rm -f tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp - rm -f x11_runner.cpp qt_runner.cpp - -distclean: clean - rm -f Makefile - -run: error_printer - ./error_printer - -run_x11: x11_runner - ./x11_runner - -run_qt: qt_runner - ./qt_runner - -error_printer.cpp: $(TESTS) - $(TESTGEN) -o $@ --error-printer $(TESTS) - -stdio_printer.cpp: $(TESTS) - $(TESTGEN) -o $@ --runner=StdioPrinter $(TESTS) - -file_printer.cpp: file_printer.tpl $(TESTS) - $(TESTGEN) -o $@ --template=file_printer.tpl $(TESTS) - -aborter.cpp: aborter.tpl $(TESTS) - $(TESTGEN) -o $@ --template=aborter.tpl $(TESTS) - -only.cpp: only.tpl $(TESTS) - $(TESTGEN) -o $@ --template=only.tpl $(TESTS) - -tests.cpp: $(TESTS) - $(TESTGEN) -o $@ $(TESTS) - -x11_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o $@ --gui=X11Gui $(GUI_TESTS) - -qt_runner.cpp: $(GUI_TESTS) - $(TESTGEN) -o $@ --gui=QtGui $(GUI_TESTS) - -%: %.cpp - $(CXXC) -o $@ $< - -yes_no_runner: yes_no_runner.cpp tests.cpp - $(CXXC) -o $@ $^ - -x11_runner: x11_runner.cpp - $(CXXC) -o $@ $^ $(X11_FLAGS) - -qt_runner: qt_runner.cpp - $(CXXC) -o $@ $^ $(QT_FLAGS) - -# -# Local Variables: -# compile-command: "make -fMakefile.unix" -# End: -# diff --git a/bsl/cxxtest/sample/MessageTest.h b/bsl/cxxtest/sample/MessageTest.h deleted file mode 100755 index 621289f78d30cb8bb2f507ed7a58e0dbfa20c306..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/MessageTest.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __MESSAGETEST_H -#define __MESSAGETEST_H - -#include - -// -// The [E]TSM_ macros can be used to print a specified message -// instead of the default one. -// This is useful when you refactor your tests, as shown below -// - -class MessageTest : public CxxTest::TestSuite -{ -public: - void testValues() - { - checkValue( 0, "My hovercraft" ); - checkValue( 1, "is full" ); - checkValue( 2, "of eels" ); - } - - void checkValue( unsigned value, const char *message ) - { - TSM_ASSERT( message, value != 0 ); - TSM_ASSERT_EQUALS( message, value, value * value ); - } -}; - - -#endif // __MESSAGETEST_H diff --git a/bsl/cxxtest/sample/SimpleTest.h b/bsl/cxxtest/sample/SimpleTest.h deleted file mode 100755 index b3fae12cadfe60135bca6a981585c9e73b871749..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/SimpleTest.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __SIMPLETEST_H -#define __SIMPLETEST_H - -#include - -// -// A simple test suite: Just inherit CxxTest::TestSuite and write tests! -// - -class SimpleTest : public CxxTest::TestSuite -{ -public: - void testEquality() - { - TS_ASSERT_EQUALS( 1, 1 ); - TS_ASSERT_EQUALS( 1, 2 ); - TS_ASSERT_EQUALS( 'a', 'A' ); - TS_ASSERT_EQUALS( 1.0, -12345678900000000000000000000000000000000000000000.1234 ); - } - - void testAddition() - { - TS_ASSERT_EQUALS( 1 + 1, 2 ); - TS_ASSERT_EQUALS( 2 + 2, 5 ); - } - - void TestMultiplication() - { - TS_ASSERT_EQUALS( 2 * 2, 4 ); - TS_ASSERT_EQUALS( 4 * 4, 44 ); - TS_ASSERT_DIFFERS( -2 * -2, 4 ); - } - - void testComparison() - { - TS_ASSERT_LESS_THAN( (int)1, (unsigned long)2 ); - TS_ASSERT_LESS_THAN( -1, -2 ); - } - - void testTheWorldIsCrazy() - { - TS_ASSERT_EQUALS( true, false ); - } - - void test_Failure() - { - TS_FAIL( "Not implemented" ); - TS_FAIL( 1569779912 ); - } - - void test_TS_WARN_macro() - { - TS_WARN( "Just a friendly warning" ); - TS_WARN( "Warnings don't abort the test" ); - } -}; - - -#endif // __SIMPLETEST_H diff --git a/bsl/cxxtest/sample/TraitsTest.h b/bsl/cxxtest/sample/TraitsTest.h deleted file mode 100755 index 14659385d083506f81ad072c4417971f15e31846..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/TraitsTest.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __TRAITSTEST_H -#define __TRAITSTEST_H - -// -// This example shows how to use TS_ASSERT_EQUALS for your own classes -// -#include -#include - -// -// Define your class with operator== -// -#include -#include - -class Pet -{ - char _name[128]; -public: - Pet( const char *petName ) { strcpy( _name, petName ); } - - const char *name() const { return _name; } - - bool operator== ( const Pet &other ) const - { - return !strcmp( name(), other.name() ); - } -}; - -// -// Instantiate CxxTest::ValueTraits<*your class*> -// Note: Most compilers do not require that you define both -// ValueTraits and ValueTraits, but some do. -// -namespace CxxTest -{ - CXXTEST_TEMPLATE_INSTANTIATION - class ValueTraits - { - char _asString[256]; - - public: - ValueTraits( const Pet &pet ) { sprintf( _asString, "Pet(\"%s\")", pet.name() ); } - const char *asString() const { return _asString; } - }; - - CXXTEST_COPY_CONST_TRAITS( Pet ); -} - -// -// Here's how it works -// -class TestFunky : public CxxTest::TestSuite -{ -public: - void testPets() - { - Pet pet1("dog"), pet2("cat"); - TS_ASSERT_EQUALS( pet1, pet2 ); - Pet cat("cat"), gato("cat"); - TS_ASSERT_DIFFERS( cat, gato ); -#ifdef _CXXTEST_HAVE_STD - typedef CXXTEST_STD(string) String; - TS_ASSERT_EQUALS( String("Hello"), String("World!") ); -#endif // _CXXTEST_HAVE_STD - } -}; - -#endif // __TRAITSTEST_H diff --git a/bsl/cxxtest/sample/aborter.tpl b/bsl/cxxtest/sample/aborter.tpl deleted file mode 100755 index 14fc50d2c733bd51c380d8e728833d2ff815a997..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/aborter.tpl +++ /dev/null @@ -1,16 +0,0 @@ -// -*- C++ -*- -// This template file demonstrates the use of CXXTEST_ABORT_TEST_ON_FAIL -// - -#define CXXTEST_HAVE_STD -#define CXXTEST_ABORT_TEST_ON_FAIL -#include - -int main() -{ - return CxxTest::ErrorPrinter().run(); -} - -// The CxxTest "world" - - diff --git a/bsl/cxxtest/sample/file_printer.tpl b/bsl/cxxtest/sample/file_printer.tpl deleted file mode 100755 index a9627d6d0df1c01ffcfcd689a9681441613aa522..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/file_printer.tpl +++ /dev/null @@ -1,22 +0,0 @@ -// -*- C++ -*- -// This is a sample of a custom test runner -// using CxxTest template files. -// This prints the output to a file given on the command line. -// - -#include -#include - -int main( int argc, char *argv[] ) -{ - if ( argc != 2 ) { - fprintf( stderr, "Usage: %s \n", argv[0] ); - return -1; - } - - return CxxTest::StdioPrinter( fopen( argv[1], "w" ) ).run(); -} - -// The CxxTest "world" - - diff --git a/bsl/cxxtest/sample/only.tpl b/bsl/cxxtest/sample/only.tpl deleted file mode 100755 index b2a7277cf637f79d947900db1ee1a9aa60f69fbe..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/only.tpl +++ /dev/null @@ -1,33 +0,0 @@ -// -*- C++ -*- -#include -#include - -int main( int argc, char *argv[] ) -{ - if ( argc < 2 || argc > 3 ) { - fprintf( stderr, "Usage: only []\n\n" ); - fprintf( stderr, "Available tests:\n" ); - CxxTest::RealWorldDescription wd; - for ( CxxTest::SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() ) - for ( CxxTest::TestDescription *td = sd->firstTest(); td; td = td->next() ) - fprintf( stderr, " - %s::%s()\n", sd->suiteName(), td->testName() ); - return 1; - } - - const char *suiteName = argv[1]; - const char *testName = (argc > 2) ? argv[2] : 0; - if ( !CxxTest::leaveOnly( suiteName, testName ) ) { - if ( testName ) - fprintf( stderr, "Cannot find %s::%s()\n", argv[1], argv[2] ); - else - fprintf( stderr, "Cannot find class %s\n", argv[1] ); - return 2; - } - - return CxxTest::StdioPrinter().run(); -} - - -// The CxxTest "world" - - diff --git a/bsl/cxxtest/sample/yes_no_runner.cpp b/bsl/cxxtest/sample/yes_no_runner.cpp deleted file mode 100755 index c32b94cd5c72559f2277f19d65d9dcb35825a9ae..0000000000000000000000000000000000000000 --- a/bsl/cxxtest/sample/yes_no_runner.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// -// A sample program that uses class YesNoRunner to run all the tests -// and find out if all pass. -// - -#include - -int main() -{ - return CxxTest::YesNoRunner().run(); -} diff --git a/bsl/deque.h b/bsl/deque.h deleted file mode 100644 index 9d1d07a616763529ce8b6d07db9c6c56be5a4b17..0000000000000000000000000000000000000000 --- a/bsl/deque.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: deque.h,v 1.2 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsldeque.h - * @author xiaowei(com@baidu.com) - * @date 2009/01/13 11:38:21 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSLDEQUE_H_ -#define __BSLDEQUE_H_ - - -#include "containers/deque/bsl_deque.h" -#include "containers/deque/bsl_rwseque.h" - - - - - - - - - - - - - - - -#endif //__BSLDEQUE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/exception.h b/bsl/exception.h deleted file mode 100644 index debd79d813110e81c88628753e6566ee516684b1..0000000000000000000000000000000000000000 --- a/bsl/exception.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: exception.h,v 1.2 2009/06/26 05:23:25 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file exception.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/06/25 12:18:01 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#ifndef _BSL_EXCEPTION_H_ -#define _BSL_EXCEPTION_H_ -#include "exception/bsl_exception.h" - -#endif //__EXCEPTION_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/exception/BCLOUD b/bsl/exception/BCLOUD deleted file mode 100644 index 4923c6fd4d0b3dabc481f72de4fde4422281c704..0000000000000000000000000000000000000000 --- a/bsl/exception/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DBSL_DEBUG_FLAG -DBSL_VERSION=\"bsl1.0.2.0\" -DBSL_CVSTAG=\"bsl_1-0-2-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libexception.a') -#LIBS('$OUT/so/libexception.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources="bsl_exception.cpp stack_trace.cpp" - -#release headers -HEADERS('*.h', '$INC/bsl/exception') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('exception', Sources(user_sources)) - -#UT -#UTApplication('exception', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_exception', Sources(user_sources)) -#StaticLibrary('exception', PreBuilt(True)) - -#.so -#SharedLibrary('exception', Sources(user_sources)) -#SharedLibrary('exception', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/exception/CMakeLists.txt b/bsl/exception/CMakeLists.txt deleted file mode 100644 index 74e3f842cbbadb5acc33b3e2c87da5d37e2b9f1d..0000000000000000000000000000000000000000 --- a/bsl/exception/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -FILE(GLOB exception_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(exception ${exception_srcs}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/exception/Makefile b/bsl/exception/Makefile deleted file mode 100644 index 9d5dd23461957bbe48b490dcc03a94be397bbefb..0000000000000000000000000000000000000000 --- a/bsl/exception/Makefile +++ /dev/null @@ -1,112 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: 2008年 08月 18日 星期一 14:49:27 CST # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -TARGET = bsl_exception -BSL_ROOT = .. -include Makefile.env - -CC = g++ -OUTPUT_HEAD_PATH= $(BSL_ROOT)/output/include/bsl/exception -OUTPUT_LIB_PATH = $(BSL_ROOT)/output/lib - -##### build & test configuration ##### - -LOCAL_HEADS = $(wildcard *.h) $(wildcard *.hpp) - -HEADS = $(LOCAL_HEADS) - -OBJECTS = stack_trace.o bsl_exception.o - -TEST_TARGETS= test_bsl_exception - -INCLUDES = -LIBS = -L../output/lib/ -lbsl - -##### other ##### - -TAG_ROOT = $(BSL_ROOT) - -####################################### RULES ####################################### - -#comment the following line for debugging -.SILENT: all test output clean tag doc debug depend - -.PHONY: all test output clean tag doc debug depend - -#comment the following line to use default known suffixes (DANGEROUS!!!) -.SUFFIXES: - -all: output_heads output clean - -%: %.o $(OBJECTS) - @echo "[make] building $@ ..." - $(CC) -o $@ $^ $(BSL_LDFLAGS) $(LIBS) - -%.o: %.cpp $(HEADS) - @echo "[make] building $@ ..." - $(CC) -g -o $@ -c $< $(DEBUG) $(BSL_CXXFLAGS) $(INCLUDES) - -depend: - @for DEPENDENCY in $(DEPENDENCYS); do echo "[make] making lib $$DEPENDENCY ..."; make -C $$DEPENDENCY; done - -test: $(TEST_TARGETS) - @echo "[make] testing ..." - @for TEST_TARGET in $(TEST_TARGETS); do echo "[make] testing $$TEST_TARGET ..."; ./$$TEST_TARGET; done - -test_$(TARGET): test_$(TARGET).o $(OBJECTS) - @echo "[make] building $@ ..." - $(CC) -o $@ $^ $(BSL_LDFLAGS) $(LIBS) - -output_heads: $(LOCAL_HEADS) - @echo "[make] copying $(LOCAL_HEADS) to $(OUTPUT_HEAD_PATH) ..." - mkdir -p $(OUTPUT_HEAD_PATH) - cp $(LOCAL_HEADS) $(OUTPUT_HEAD_PATH) - -output: lib$(TARGET).a - @echo "[make] copying $< to $(OUTPUT_LIB_PATH) ..." - mkdir -p $(OUTPUT_LIB_PATH) - cp $< $(OUTPUT_LIB_PATH) - -lib$(TARGET).a: $(OBJECTS) - @echo "[make] building $@ ..." - ar cr $@ $^ - -clean: - @echo "[make] cleaning ..." - rm *.o *.a $(TEST_TARGETS) -f - -doc: - @echo "[make] generating documents ..." - doxygen - -tag: - @echo "[make] generating tags ..." - ctags --c++-kinds=+p --fields=+iaS --extra=+q -R $(TAG_ROOT); - -debug: - @echo "[make] printing variables ..." - @echo 'basic configuration' - @echo '$$(TARGET) = $(TARGET)' - @echo '' - @echo 'path configuration' - @echo '$$(WORK_ROOT) = $(WORK_ROOT)' - @echo '$$(LIB2_PATH) = $(LIB2_PATH)' - @echo '$$(BSL_ROOT) = $(BSL_ROOT)' - @echo '$$(OUTPUT_HEAD_PATH) = $(OUTPUT_HEAD_PATH)' - @echo '$$(OUTPUT_LIB_PATH) = $(OUTPUT_LIB_PATH)' - @echo '' - @echo 'build & test configuration' - @echo '$$(INCLUDES) = $(INCLUDES)' - @echo '$$(LOCAL_HEADS) = $(LOCAL_HEADS)' - @echo '$$(OBJECTS) = $(OBJECTS)' - @echo '$$(LIBS) = $(LIBS)' - @echo '$$(TEST_TARGETS) = $(TEST_TARGETS)' - @echo '' - @echo 'other' - @echo '$$(TAG_ROOT) = $(TAG_ROOT)' diff --git a/bsl/exception/Makefile.env b/bsl/exception/Makefile.env deleted file mode 100644 index 22a1ad910872b78a944b252ffae44c2bf8263150..0000000000000000000000000000000000000000 --- a/bsl/exception/Makefile.env +++ /dev/null @@ -1,41 +0,0 @@ -# Public Makefile settings for BSL -# It requires BSL_ROOT to be set before include this file - -# About the project ######################### -BSL_PROJECT_NAME= bsl -BSL_VERSION = "$(BSL_PROJECT_NAME) 1.0.2.0" -BSL_CVSTAG = "$(BSL_PROJECT_NAME)_1-0-2-0_PD_BL" - -# Paths ##################################### -WORK_ROOT = $(BSL_ROOT)/../../ -BSL_OUTPUT_PATH = $(BSL_ROOT)/output/ - - -# Machine ################################### -ifeq ($(MAC),64) -ARCH = 64 -else -ARCH = 32 -endif - - -# Compile Tools ############################# -CXX = g++ -CC = g++ -SHELL = /bin/sh - -# Public flags -DEBUG_FLAG = -DBSL_DEBUG_FLAG -PROJECT_FLAGS = \ - -DBSL_VERSION="\$(BSL_VERSION)\" \ - -DBSL_CVSTAG="\$(BSL_CVSTAG)\" \ - -DBSL_PROJECT_NAME="\"$(BSL_PROJECT_NAME)\"" - -BSL_CXXFLAGS = \ - -g -rdynamic -pipe -fPIC -finline-functions \ - -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \ - -Wconversion -Winline -Woverloaded-virtual -Wsign-promo \ - $(DEBUG_FLAG) $(PROJECT_FLAGS) -I../output/include - -BSL_LDFLAGS = -rdynamic - diff --git a/bsl/exception/bsl_auto_buffer.h b/bsl/exception/bsl_auto_buffer.h deleted file mode 100644 index 4b75644e17963c906659693908b2e92d2459f96e..0000000000000000000000000000000000000000 --- a/bsl/exception/bsl_auto_buffer.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * $Id$ - * - **************************************************************************/ - - - -/** - * @file bsl_auto_buffer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/08/18 13:32:16 - * @version $Revision$ - * @brief - * - **/ -#ifndef __BSL_EXCEPTION_AUTO_BUFFER_H_ -#define __BSL_EXCEPTION_AUTO_BUFFER_H_ - -#include "bsl/AutoBuffer.h" - -#endif //__BSL_EXCEPTION_AUTO_BUFFER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/exception/bsl_exception.cpp b/bsl/exception/bsl_exception.cpp deleted file mode 100644 index 23a746f655ab932f26a9b3d95e1b92ad558f728d..0000000000000000000000000000000000000000 --- a/bsl/exception/bsl_exception.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_exception.cpp,v 1.8 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - -/** - * @file Exception.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/04 16:44:56 - * @version $Revision: 1.8 $ - * @brief - * - **/ - -#include -#include -#include -#include -#include -#include"bsl_exception.h" - -namespace bsl{ - - size_t Exception::_s_stack_trace_level = Exception::DEFAULT_STACK_TRACE_LEVEL; - const char * const ExceptionBase::DEFAULT_FILE = ""; - const char * const ExceptionBase::DEFAULT_FUNCTION = ""; - const char * const Exception::DEFAULT_LINE_DELIMITER = ""; - char Exception::_s_line_delimiter[Exception::_S_LINE_DELIMITER_SIZE] = ""; - - const char * to_cstring(exception_level_t level){ - if ( level >= EXCEPTION_LEVEL_CORE_DUMPED ){ - return EXCEPTION_LEVEL_CORE_DUMPED_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_FATAL ){ - return EXCEPTION_LEVEL_FATAL_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_WARNING ){ - return EXCEPTION_LEVEL_WARNING_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_NOTICE ){ - return EXCEPTION_LEVEL_NOTICE_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_TRACE ){ - return EXCEPTION_LEVEL_TRACE_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_DEBUG ){ - return EXCEPTION_LEVEL_DEBUG_CSTRING; - } - if ( level >= EXCEPTION_LEVEL_SILENT ){ - return EXCEPTION_LEVEL_SILENT_CSTRING; - } - return EXCEPTION_LEVEL_UNKNOWN_CSTRING; - } - - //not considered inlining - void Exception::core_dump(){ - int tmp = 0; - tmp = 0 / tmp; // core dumped - } - - const char * Exception::all() const{ - if ( _all.empty() ){ - if ( _name.empty() ){ - demangle( _name, typeid(*this).name() ); - } - _all.reserve( 160 + _msg.size() + _stack.size() ); - _all<<"exception["<<_name<<"] was thrown at["<<_s_line_delimiter<<'\t'<<_arg._file<<':'<<_arg._line<<':'<<_arg._function - <<_s_line_delimiter<<"] with message["<<_msg<<"] stack:"<<_s_line_delimiter<<_stack; - } - return _all.c_str(); - } - -}//namespace bsl -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/exception/bsl_exception.h b/bsl/exception/bsl_exception.h deleted file mode 100644 index f5579290e39b1a2894a6048f2aeafa4d5dfb82ce..0000000000000000000000000000000000000000 --- a/bsl/exception/bsl_exception.h +++ /dev/null @@ -1,619 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_exception.h,v 1.12 2009/10/14 08:24:58 chenxm Exp $ - * - **************************************************************************/ - -/** - * @file bsl_exception.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/07/25 17:40:02 - * @version $Revision: 1.12 $ - * @brief - * - **/ - -#ifndef __BSL_EXCEPTION_H__ -#define __BSL_EXCEPTION_H__ - -#include -#include -#include -#include -#include -#include"bsl/AutoBuffer.h" -#include"bsl/exception/stack_trace.h" - -/** -* @brief 异常转日志的对应WARNING日志函数 -* -* 默认使用UB_LOG_WARNING -* 如果使用其它日志函数,请确认其接口与UB_LOG_WARNING一致 -*/ -#ifndef __BSL_LOG_WARNING__ -#define __BSL_LOG_WARNING__ UB_LOG_WARNING -#endif - -/** -* @brief 异常转日志的对应FATAL日志函数 -* -* 默认使用UB_LOG_FATAL -* 如果使用其它日志函数,请确认其接口与UB_LOG_FATAL一致 -*/ -#ifndef __BSL_LOG_FATAL__ -#define __BSL_LOG_FATAL__ UB_LOG_FATAL -#endif - -/** -* @brief 传递抛出异常位置的宏 -* -* 该宏实际上是一个bs::ExceptionArg无名对象,因而是非常安全的 -*/ -#define BSL_EARG \ - bsl::ExceptionArg( __PRETTY_FUNCTION__, __FILE__, __LINE__ ) - - -namespace bsl { - - enum exception_level_t{ - EXCEPTION_LEVEL_SILENT = -999, - EXCEPTION_LEVEL_DEBUG = 0, - EXCEPTION_LEVEL_TRACE = 100, - EXCEPTION_LEVEL_NOTICE = 200, - EXCEPTION_LEVEL_WARNING = 400, - EXCEPTION_LEVEL_FATAL = 800, - EXCEPTION_LEVEL_CORE_DUMPED= 999, - - EXCEPTION_LEVEL_DEFAULT = EXCEPTION_LEVEL_DEBUG, - - }; - - static const char * const EXCEPTION_LEVEL_SILENT_CSTRING = "EXCEPTION_LEVEL_SILENT"; - static const char * const EXCEPTION_LEVEL_DEBUG_CSTRING = "EXCEPTION_LEVEL_DEBUG"; - static const char * const EXCEPTION_LEVEL_TRACE_CSTRING = "EXCEPTION_LEVEL_TRACE"; - static const char * const EXCEPTION_LEVEL_NOTICE_CSTRING = "EXCEPTION_LEVEL_NOTICE"; - static const char * const EXCEPTION_LEVEL_WARNING_CSTRING = "EXCEPTION_LEVEL_WARNING"; - static const char * const EXCEPTION_LEVEL_FATAL_CSTRING = "EXCEPTION_LEVEL_FATAL"; - static const char * const EXCEPTION_LEVEL_CORE_DUMPED_CSTRING="EXCEPTION_LEVEL_CORE_DUMPED"; - static const char * const EXCEPTION_LEVEL_DEFAULT_CSTRING = EXCEPTION_LEVEL_DEBUG_CSTRING; - static const char * const EXCEPTION_LEVEL_UNKNOWN_CSTRING ="EXCEPTION_LEVEL_KNOWN"; - - const char * to_cstring(exception_level_t level); - - struct ExceptionArg { - ExceptionArg( const char * function, const char * file, int line ) - :_function(function), _file(file), _line(line){} - - const char *_function; - const char *_file; - int _line; - - }; - - template - class BasicException: public RealBaseExceptionT{ - public: - - template - ExceptionT& push( ValueT value ){ - this->_msg.push(value); - check_type(); - return static_cast(*this); - } - - template - ExceptionT& push( Value1T value1, Value2T value2 ){ - this->_msg.push(value1, value2); - check_type(); - return static_cast(*this); - } - - ExceptionT& pushf( const char * format, ... )__attribute__ ((format (printf, 2, 3) )); - - ExceptionT& vpushf( const char * format, va_list ap ){ - this->_msg.vpushf(ap); - check_type(); - return static_cast(*this); - } - - ExceptionT& push( const ExceptionArg& __arg ){ - this->_arg = __arg; - check_type(); - return static_cast(*this); - } - - ExceptionT& push( exception_level_t __level ){ - this->_level = __level; - if ( this->_level >= EXCEPTION_LEVEL_CORE_DUMPED ){ - this->core_dump(); - } - check_type(); - return static_cast(*this); - } - - template - ExceptionT& operator << ( ValueT value ){ - this->_msg<(*this); - } - - ExceptionT& operator << ( const ExceptionArg& __arg ){ - this->_arg = __arg; - check_type(); - return static_cast(*this); - } - - ExceptionT& operator << ( exception_level_t __level ){ - this->_level = __level; - check_type(); - return static_cast(*this); - } - - private: - virtual void check_type(){ - if ( &typeid(ExceptionT) != &typeid(*this) ){ - this->_msg.push("WARNING: invalid definition of ").push(static_cast(this)->name()); - if ( this->_level < EXCEPTION_LEVEL_WARNING ){ - this->_level = EXCEPTION_LEVEL_WARNING; - } - } - } - - - }; - - - //write this way because of a bug of g++ 2.96 - template - inline ExceptionT& BasicException::pushf( const char * format, ... ){ - va_list ap; - va_start( ap, format ); - this->_msg.vpushf( format, ap ); - va_end(ap); - check_type(); - return static_cast(*this); - } - - /** - * @brief BSL中一切异常的祖先类 - * - * 默认初始化时,各AutoBuffer会分配一个初始的容量,以减少动态内存分配次数,若容量不足,AutoBuffer会自动增加容量 - * 该Exception类可以被设置为在被抛出时和/或被接住并不再重新抛出时向屏幕/日志中打印错误消息及栈信息,以便调试和错误跟踪 - */ - class ExceptionBase: public ::std::exception { - public: - typedef ::std::exception base_type; - ExceptionBase() - : base_type(), _level(EXCEPTION_LEVEL_DEFAULT), - _stack(DEFAULT_STACK_CAPACITY), _name(DEFAULT_NAME_CAPACITY), _msg(DEFAULT_WHAT_CAPACITY), _all(0), _arg(DEFAULT_FUNCTION, DEFAULT_FILE, DEFAULT_LINE){ - } - - ExceptionBase(const ExceptionBase& other) - : base_type(other), _level(other._level), - _stack(other._stack.capacity()), _name(other._name.capacity()), _msg(other._msg.capacity()), _arg(other._arg) { - _stack.transfer_from( other._stack ); - _name.transfer_from( other._name ); - _msg.transfer_from( other._msg ); - } - - virtual ~ExceptionBase() throw() { } - - public: - static const size_t DEFAULT_MSG_CAPACITY = 64; - static const size_t DEFAULT_STACK_CAPACITY = 64; - static const size_t DEFAULT_NAME_CAPACITY = 32; - static const size_t DEFAULT_WHAT_CAPACITY = 256; - static const char * const DEFAULT_FILE; - static const char * const DEFAULT_FUNCTION; - static const int DEFAULT_LINE = 0; - protected: - exception_level_t _level; - mutable AutoBuffer _stack; - mutable AutoBuffer _name; - mutable AutoBuffer _msg; - mutable AutoBuffer _all; - ExceptionArg _arg; - - }; - - class Exception: public BasicException{ - public: - - typedef BasicException base_type; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2009/02/04 16:28:12 / modified by zhujianwei at 2010/12/27 - **/ - Exception() - :base_type(){ - stack_trace(_stack, _s_stack_trace_level, 1, MAX_STACK_TRACE_LEVEL, _s_line_delimiter); - } - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 16:28:43 - **/ - virtual ~Exception() throw() { } - - /** - * @brief 返回异常对象携带的全部信息 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/05/08 15:09:40 - **/ - virtual const char * what() const throw() { - return _msg.c_str(); - } - - /** - * @brief 返回Exception对象的类名 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:28:25 - **/ - const char * name() const { - if ( _name.empty() ){ - demangle( _name, typeid(*this).name() ); - } - return _name.c_str(); - } - - /** - * @brief 返回异常抛出时的栈跟踪信息。 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:28:57 - **/ - const char * stack() const { - return _stack.c_str(); - } - - /** - * @brief 返回异常抛出所在的函数名 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:29:34 - **/ - const char * function() const { - return _arg._function; - } - - /** - * @brief 返回异常抛出所在的文件名 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:30:07 - **/ - const char * file() const { - return _arg._file; - } - - /** - * @brief 返回异常抛出所在的行号 - * - * @return int - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:31:35 - **/ - int line() const { - return _arg._line; - } - - /** - * @brief 返回异常的严重级别 - * - * @return int - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:32:00 - **/ - int level() const { - return _level; - } - - /** - * @brief 返回异常严重级别的C风格字符串 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:32:16 - **/ - const char * level_str() const { - return to_cstring( _level ); - } - - /** - * @brief 返回包含有上述所有信息的字符串 - * - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/09/27 16:15:01 - **/ - const char * all() const; - - public: - /** - * @brief 设置当异常抛出时,栈跟踪的层数 - * - * 如果没有设置过,默认为DEFAULT_STACK_TRACE_LEVEL - * 返回设置前的栈跟踪层数 - * 注:试验性接口,将来可能会改变 - * - * @param [in] on : bool - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:32:40 - **/ - static size_t set_stack_trace_level(size_t level_){ - size_t old = _s_stack_trace_level; - _s_stack_trace_level = level_ ; - return old; - } - - /** - * @brief 设置分行符 - * - * 默认分行符为"",目的是为了防止打日志时\n影响监控。用户可根据需要设定分行符,如果不需要监控,设为"\n"即可 - * 注:试验性接口,将来可能会改变 - * - * @param [in] delimiter : const char* - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/05/14 17:12:12 - **/ - static void set_line_delimiter( const char * delimiter ){ - snprintf( _s_line_delimiter, _S_LINE_DELIMITER_SIZE, "%s", delimiter ); - } - - /** - * @brief 获取被设置的分行符 - * - * 注:试验性接口,将来可能会改变 - * - * @param [in] delimiter : const char* - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/05/14 17:16:26 - **/ - static const char *get_line_delimiter(){ - return _s_line_delimiter; - } - - /** - * @brief 默认打印栈跟踪的层数 - * - * 注:试验性接口,将来可能会改变 - */ - static const size_t DEFAULT_STACK_TRACE_LEVEL = 10; - - /** - * @brief 最大可以跟踪到的层数 - * - * 注:试验性接口,将来可能会改变 - */ - static const size_t MAX_STACK_TRACE_LEVEL = 100; - - - protected: - - /** - * @brief 手动出core,当异常级别为CORE_DUMP时被调用 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:40:03 - **/ - static void core_dump(); - - private: - static const char * const DEFAULT_LINE_DELIMITER; - static const size_t _S_LINE_DELIMITER_SIZE = 10; - static size_t _s_stack_trace_level; - static char _s_line_delimiter[_S_LINE_DELIMITER_SIZE]; - }; - - /** - * @brief 标准库异常(std::exception的子类)的包裹类。 - * - * 适合于使用了会抛异常的标准库组件包装异常用。 - */ - class StdException: public BasicException{ - public: - typedef BasicException base_type; - StdException( ::std::exception& e ) - :base_type(){ - demangle( _name, typeid(e).name() ); - _msg.push(e.what()); - } - }; - - /** - * @brief 未知异常 - * - * 应该尽量避免使用该异常。尽可能使用能描述异常原因的异常。 - */ - class UnknownException: public BasicException{}; - - /** - * @brief 类型转换失败异常 - * - * 该异常表示发生了不支持的类型转换 - */ - class BadCastException: public BasicException{}; - - /** - * @brief 访问越界异常 - * - * 该异常表示访问越界 - */ - class OutOfBoundException: public BasicException{}; - - /** - * @brief 键不存在异常 - * - * 该异常表示查找键不存在 - */ - class KeyNotFoundException: public BasicException{}; - - /** - * @brief 键已存在异常 - * - * 该异常表示查找键已经存在 - */ - class KeyAlreadyExistException: public BasicException{}; - - /** - * @brief 申请动态内存失败异常 - * - * 该异常表示动态内存申请失败 - */ - class BadAllocException: public BasicException{}; - - /** - * @brief 参数错误异常 - * - * 该异常表示调用函数的参数不合法。如果能使用其它更清楚表明参数不合法原因的异常的话,尽量避免使用本异常 - */ - class BadArgumentException: public BasicException{}; - - /** - * @brief 空指针异常 - * - * 该异常表示在不能接受空指针的地方发现了空指针 - */ - class NullPointerException: public BasicException{}; - - /** - * @brief 错误的格式字符串异常 - * - * 该异常表示格式字符串不合法。 - */ - class BadFormatStringException: public BasicException{}; - - /** - * @brief 未初始化异常 - * - * 该异常表示使用了未被初始化的对象 - */ - class UninitializedException: public BasicException{}; - - /** - * @brief 未实现异常 - * - * 该异常表示调用了未被实现的API - */ - class NotImplementedException: public BasicException{}; - - /** - * @brief 无效操作异常 - * - * 该异常表示执行了无效的操作 - */ - class InvalidOperationException: public BasicException{}; - - /** - * @brief 上溢出异常 - * - * 该异常表示数值比能接受的最大值还要大 - */ - class OverflowException: public BasicException{}; - - /** - * @brief 下溢出异常 - * - * 该异常表示数值比能接受的最小值还要小 - */ - class UnderflowException: public BasicException{}; - - /** - * @brief (语法)解析失败异常 - * - * 该异常表示语法解析失败 - */ - class ParseErrorException: public BasicException{}; - - /** - * @brief IO异常 - * - */ - class IOException : public bsl::BasicException< IOException, bsl::Exception >{}; - - /** - * @brief 找不到文件异常 - * - * - */ - class FileNotFoundException : public bsl::BasicException< FileNotFoundException, IOException >{}; - - /** - * @brief 文件信息异常 - * - * - */ - class FstatException : public bsl::BasicException< FstatException, IOException >{}; - - /** - * @brief mmap异常 - * - * - */ - class MmapException : public bsl::BasicException< MmapException, IOException >{}; - - /** - * @brief 动态链接异常 - * - * - */ - class DynamicLinkingException : public bsl::BasicException< DynamicLinkingException, IOException >{}; - - /** - * @brief 断言失败异常 - * - * - */ - class AssertionFailedException : public bsl::BasicException< AssertionFailedException, bsl::Exception >{}; - - -}//namespace bsl -#endif //__BSL_EXCEPTION_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/exception/stack.py b/bsl/exception/stack.py deleted file mode 100755 index 323bed60614336726c1133ac4491084d1c001385..0000000000000000000000000000000000000000 --- a/bsl/exception/stack.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/python -import commands; -import sys; - -if __name__ == '__main__': - if len(sys.argv) < 2 : - print 'usage: stack.py '; - exit(1); - PROGRAM = sys.argv[1]; - SPLITER = ''; - try: - while True: - line = raw_input(); - frames = line.split(SPLITER); - for frame in frames: - try: - func, addr = frame.split('[0x'); - command = 'addr2line -e %s 0x%s' % (PROGRAM, addr); - status, output = commands.getstatusoutput(command); - if status != 0: - print 'command "%s" return %d!' % (command, status) - else: - print '??:0' not in output and '%s:%s' % (output, func.strip()) or frame - except Exception, e: - print frame - except EOFError, e: - pass - - - diff --git a/bsl/exception/stack_trace.cpp b/bsl/exception/stack_trace.cpp deleted file mode 100644 index 37f59ca5642b002b1cb84fcd39991fd61fe17c32..0000000000000000000000000000000000000000 --- a/bsl/exception/stack_trace.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/** - * @file stack_trace.cpp - * @author zhujianwei(zhujianwei@baidu.com) - * @date 2010/12/27 - * @version $Revision: 1.0 - * @brief - * - **/ - -#include -#include -#include -#include -#include -#include"bsl/AutoBuffer.h" -#include"stack_trace.h" - -namespace bsl{ - -#if defined(__cplusplus) && (!defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100) //for g++ 2.96 on nasdaq - void stack_trace( AutoBuffer& buf, size_t total_level, size_t begin_level, size_t max_level, - const char* line_delimiter ){ - if ( begin_level >= max_level || total_level == 0 ){ - //begin level is too large or no need to print - return; - } - if ( begin_level + total_level > max_level ){ - total_level = max_level - begin_level; - } - - void * array[begin_level + total_level]; - int levels = backtrace(array, begin_level + total_level); //levels是可以拿到的层数 - char ** symbols = backtrace_symbols(array, levels); - if ( symbols == NULL ){ - //无法获取符号信息 - return ; - } - for (int i = begin_level; i < levels; i++) { - buf.push(" ").push(symbols[i]).push(line_delimiter); - } - - free(symbols); - } - - void demangle( AutoBuffer& buf, const char * mangled_name ){ - //TODO: 增加能兼容g++2.96的demangle版本。 - if ( mangled_name ){ - buf.push(mangled_name); - } - } - -#else //for newer versions, like g++ 3.4.5 on Friday, which supports C++ ABI -#include - - void stack_trace( AutoBuffer& buf, size_t total_level, size_t begin_level, size_t max_level, - const char * line_delimiter){ - if ( begin_level >= max_level || total_level == 0 ){ - //begin level is too large or no need to print - return; - } - if ( begin_level + total_level > max_level ){ - total_level = max_level - begin_level; - } - - void * array[begin_level + total_level]; - int levels = backtrace(array, int(begin_level + total_level)); //levels是可以拿到的层数 - char ** symbols = backtrace_symbols(array, levels); - if ( symbols == NULL ){ - //无法获取符号信息 - return; - } - char *func = NULL; - size_t size = 0; - int status; - - for (int i = int(begin_level); i < levels; i++) { - - buf.push('\t'); - char * mangled_func = strchr( symbols[i], '(' ); - char * offset_pos = NULL; - char * frame_ptr = NULL; - - if ( mangled_func != NULL ){ - ++ mangled_func; - - offset_pos = strchr( mangled_func, '+' ); - if ( offset_pos != NULL ){ - *offset_pos = 0; - ++offset_pos; - - frame_ptr = strchr( offset_pos, '[' ); - // if func == NULL, or size is not enough, func will be malloc/realloced. - // new_func is returned, size is set to new size. - // new_func can be NULL, then status can't be 0( meaning success) - // then you MUST free func! - char * new_func = abi::__cxa_demangle(mangled_func,func,&size,&status); - if ( new_func ){ - func = new_func; - } - //func is NULL(status != 0) or malloced by __cxa_demangle now - - //output - buf.push( symbols[i], mangled_func-symbols[i]-1 ).push(' '); - if ( status == 0 ){ - buf.push( func ); - }else{ - buf.push( mangled_func ).push('(').push(')'); - } - - if ( frame_ptr != NULL ){ - buf.push(' ').push(frame_ptr); - } - - buf.push(line_delimiter); - }else{ - buf.push(symbols[i]).push(line_delimiter); - } - }else{ - buf.push(symbols[i]).push(line_delimiter); - } - - } - if ( func ){ - free(func); - } - free(symbols); - } - - void demangle( AutoBuffer& buf, const char * mangled_name ){ - size_t size = 0; - int status = 0; - - // demangled name is returned, size is set to new size. - char * demangled_name = abi::__cxa_demangle(mangled_name,NULL, &size,&status); - // now name can be NULL, then status can't be 0( meaning success) - - if ( status != 0 ){ - if(demangled_name){ - free(demangled_name); - } - - buf.push(mangled_name); - }else{ - - buf.push(demangled_name); - free(demangled_name); - } - } -#endif -} //namespace bsl - diff --git a/bsl/exception/stack_trace.h b/bsl/exception/stack_trace.h deleted file mode 100644 index 0a7ac3290c119c6f5f67fb61cdf3d0e1e38cf9d7..0000000000000000000000000000000000000000 --- a/bsl/exception/stack_trace.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file stack_trace.h - * @author zhujianwei(zhujianwei@baidu.com) - * @date 2010/12/27 - * @version $Revision: 1.0 - * @brief - * - **/ - -#ifndef __BSL_STACK_TRACE_H__ -#define __BSL_STACK_TRACE_H__ - -#include "bsl/AutoBuffer.h" - -namespace bsl{ - - /** - * @brief 在运行时打印栈信息的工具函数 - * 在连接目标文件时,必须加上-rdynamic参数 - * - * @param [in] buf : AutoBuffer& - * @param [in] total_level : size_t 打出的总层 - * @param [in] begin_level : size_t 跳过栈顶的begin_level层,默认值为不打印stack_trace()本身 - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/08/12 20:55:34 / modified by zhujianwei at 2010/12/27 - **/ - void stack_trace( AutoBuffer& buf, size_t total_level, size_t begin_level, size_t max_level, - const char* line_delimiter ); - - /** - * @brief demangle - * - * @param [in] buf : AutoBuffer& - * @param [in] mangled_name : const char* - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 16:33:13 - **/ - void demangle( AutoBuffer& buf, const char * mangled_name ); - -} -//namespace bsl -#endif //__BSL_STACK_TRACE_H__ - diff --git a/bsl/exception/test_bsl_exception.cpp b/bsl/exception/test_bsl_exception.cpp deleted file mode 100644 index 9ae964388b48af6b676230e4b620db78c3d2ad1a..0000000000000000000000000000000000000000 --- a/bsl/exception/test_bsl_exception.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_bsl_exception.cpp,v 1.8 2009/10/14 08:24:59 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file test_bsl_exception.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/12/10 10:56:44 - * @version $Revision: 1.8 $ - * @brief - * - **/ - -#include "bsl_exception.h" -#include -#include //for std::bad_alloc @ g++ 2.96 - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< buf_size) - { - void *tmp = ::malloc(seg_size); - if(tmp) - { - *(void **)tmp = memlist; - memlist = tmp; - free_space = (char *)tmp + sizeof(void *); - buf_size = seg_size - sizeof(void *); - } - else - return 0; - } - buf_size -= size; - void * p = free_space; - free_space += size; - return p; - } - else - { - void *tmp = ::malloc(size + sizeof(void *)); - if(tmp) - { - *(void **)tmp = memlist; - memlist = tmp; - return ((char *)tmp + sizeof(void *)); - } - else - return 0; - - } -} - -} - - - - - - - - - - - - - - - - - - -/* vim: set expandtab ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_cachedpool.h b/bsl/pool/bsl_cachedpool.h deleted file mode 100644 index bef710c64c87622adc580351422f806bcfd76080..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_cachedpool.h +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_cachedpool.h,v 1.5 2009/01/04 09:03:34 yufan Exp $ - * - **************************************************************************/ - - - -/** - * @file /home/xiaowei/libsrc/bsl/pool/bsl_cachedpool.h - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 18:33:15 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - -#ifndef _BSL_CACHEDPOOL_H_ -#define _BSL_CACHEDPOOL_H_ - -#include "bsl_pool.h" - -namespace bsl -{ -class cached_mempool : public mempool -{ - static const int seg_size = 4096; - size_t buf_size; - char * free_space; - void * memlist; - public: - inline cached_mempool() - { - buf_size = 0; - free_space = 0; - memlist = 0; - } - virtual void * malloc(size_t size); - virtual inline void free( void *, size_t) - { - } - inline void clear() - { - if(0 == memlist) - return; - while(*(void **)memlist) - { - void * tmp = *(void **)memlist; - ::free(memlist); - memlist = tmp; - } - // 这里空间上可能会有一些浪费 - // 因为我们不知道最后一块大小内存为多少 - // 但是我们这里可以保守估计为seg_size这么大小 - // 因为每一个memlist的大小至少为seg_size. - free_space=(char*)memlist+sizeof(void*); - buf_size=seg_size-sizeof(void*); - } - inline virtual ~cached_mempool() - { - while(memlist) - { - void * tmp = *(void **)memlist; - ::free(memlist); - memlist = tmp; - } - } -}; - - -} - - - - - - - - - - - - - - - -#endif //__/HOME/XIAOWEI/LIBSRC/BSL/POOL/BSL_CACHEDPOOL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_cachedpoolappend.cpp b/bsl/pool/bsl_cachedpoolappend.cpp deleted file mode 100644 index 7caa33a3e3e2d82f48402d9478b3e111e5dc9bcd..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_cachedpoolappend.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * bsl_cachedpoolappend.cpp 2010/01/12 15:31:55 sun_xiao Exp - * - **************************************************************************/ - - - -/** - * @file bsl_cachedpoolappend.cpp - * @author sun_xiao(com@baidu.com) - * @date 2010/01/12 15:31:55 - * @brief - * - **/ - -#include "bsl_cachedpoolappend.h" - -namespace bsl -{ - void * cached_mempool_append :: malloc(size_t size) - { - if (size <= 0 || NULL == _head) { - return 0; - } - - if (_buff_freesize >= size) { - void *p = _free_space; - _buff_freesize -= size; - _free_space += size; - return p; - } - if (size <= _seg_size - sizeof(void *)) { - while (_seg_usingnum < _seg_num) { - if(size > _buff_freesize) { - ++ _seg_usingnum; - _pre_seg = _curr_seg; - _curr_seg = *(void **)_curr_seg; - _buff_freesize = _seg_size - sizeof(void *); - _free_space = (char *)_curr_seg + sizeof(void *); - } else { - void * p = _free_space; - _buff_freesize -= size; - _free_space += size; - return p; - } - } - void *tmp = ::malloc(_seg_size); - if(tmp) { - *(void **)tmp = NULL; - *(void **)_pre_seg = tmp; - _curr_seg = tmp; - ++ _seg_num; - _seg_usingnum = _seg_num - 1; - - _free_space = (char *)tmp + sizeof(void *) + size; - _buff_freesize = _seg_size - sizeof(void *) - size; - void *p = (char *)tmp + sizeof(void *); - return p; - } else { - return 0; - } - } else { - void *tmp = ::malloc(size + sizeof(void *)); - if(tmp) - { - *(void **)tmp = _bigbuf_head; - _bigbuf_head = tmp; - return ((char *)tmp + sizeof(void *)); - } - else { - return 0; - } - } - } - -} - - - - - - - - - - - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_cachedpoolappend.h b/bsl/pool/bsl_cachedpoolappend.h deleted file mode 100644 index 6f103eb7e9f7d43257e108f2799e17ed5ecdb2bc..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_cachedpoolappend.h +++ /dev/null @@ -1,190 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * bsl_cachedpoolappend.h 2010/01/11 21:03:46 sun_xiao Exp - * - **************************************************************************/ - - - -/** - * @file bsl_cachedpoolappend.h - * @author sun_xiao(com@baidu.com) - * @date 2010/01/11 21:03:46 - * @brief - * - **/ - - - -#ifndef __BSL_ADJUSTCACHEDPOOL_H_ -#define __BSL_ADJUSTCACHEDPOOL_H_ - -#include "bsl_pool.h" - -namespace bsl -{ -class cached_mempool_append : public mempool -{ -private: - unsigned int _seg_size; - unsigned int _seg_num; - unsigned int _seg_usingnum; - void * _head; - unsigned int _head_len; - void * _curr_seg; - void * _pre_seg; - char * _free_space; - unsigned int _buff_freesize; - - void * _bigbuf_head; - - int _outer_tag; -public: - inline cached_mempool_append() - { - _seg_size = 0; - _seg_num = 0; - _seg_usingnum = 0; - _head = 0; - _head_len = 0; - _free_space = 0; - _curr_seg = 0; - _pre_seg = 0; - _buff_freesize = 0; - - _bigbuf_head = 0; - _outer_tag = 0; - - } - - /** - * @brief - * - * @param [in] init_size : int 初始大小 - * @param [in] seg_size : int 步长 - * @return int - * @retval - * @see - * @author sun_xiao - * @date 2010/01/12 17:25:34 - **/ - inline int create (int init_size, int seg_size) - { - destroy(); - if (init_size <= 0 || seg_size <= 0) { - return -1; - } - - if (NULL != _head) { - return -2; - } - _head = ::malloc(init_size + sizeof(void*)); - if (NULL == _head) { - return -3; - } - *(void **)_head = NULL; - _curr_seg = _head; - _pre_seg = _head; - _head_len = init_size + sizeof(void*); - _seg_size = seg_size + sizeof(void*); - - _free_space = (char *)_head + sizeof(void*); - _buff_freesize = _head_len - sizeof(void *); - _seg_num = 1; - _seg_usingnum = 0; - return 0; - } - - inline int create(void *head, int head_size, int seg_size) - { - destroy(); - if (NULL == head || head_size <= (int)sizeof(void *) || seg_size <= 0) { - return -1; - } - _head = head; - *(void **)_head = NULL; - _curr_seg = _head; - _pre_seg = _head; - _head_len = head_size; - _seg_size = seg_size + sizeof(void *); - - _free_space = (char *)_head + sizeof(void *); - _buff_freesize = _head_len - sizeof(void *); - _seg_num = 1; - _seg_usingnum = 0; - - _outer_tag = 1; - return 0; - } - - virtual void * malloc(size_t size); - - virtual inline void free(void *, size_t) - { - } - - inline void clear() - { - while(_bigbuf_head) - { - void * tmp = *(void **)_bigbuf_head; - ::free(_bigbuf_head); - _bigbuf_head = tmp; - } - _seg_usingnum = 0; - _free_space = (char *)_head + sizeof(void*); - _buff_freesize = _head_len - sizeof(void*); - _curr_seg = _head; - _pre_seg = _head; - } - - inline void destroy() - { - while(_bigbuf_head) - { - void * tmp = *(void **)_bigbuf_head; - ::free(_bigbuf_head); - _bigbuf_head = tmp; - } - - void *tmp = 0; - if (0 == _outer_tag) { - tmp = _head; - } else { - tmp = *(void **)_head; - } - while (tmp) { - void *tmp1 = *(void **)tmp; - ::free(tmp); - tmp = tmp1; - } - _head = 0; - _outer_tag = 0; - - } - - inline virtual ~cached_mempool_append() - { - destroy(); - } -}; -} - - - - - - - - - - - - - - - -#endif //__BSL_ADJUSTCACHEDPOOL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_debugpool.h b/bsl/pool/bsl_debugpool.h deleted file mode 100644 index 443dd4e0743de13a7787429b7733a4b9de1373cc..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_debugpool.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * - **************************************************************************/ - - - -/** - * @file bsl_debugpool.h - * @author yufan(com@baidu.com) - * @date 2009/01/07 17:43:57 - * @brief - * - **/ - - - - -#ifndef __BSL_DEBUGPOOL_H_ -#define __BSL_DEBUGPOOL_H_ -#include "bsl_pool.h" -#include "bsl/exception/bsl_exception.h" -#include -namespace bsl -{ -//测试你是否传对了size - class debugpool : public mempool - { - struct info - { - size_t size; - std::string stack; - }; - std::map _table; - public: - virtual void * malloc (size_t size) { - void * ret = (size_t *)::malloc (size); - info p; - p.size = size; - try - { - throw Exception() << BSL_EARG; - } - catch(Exception &e) - { - p.stack = e.stack(); - } - _table[ret] = p; - return ret; - } - virtual void free (void *p, size_t size) { - if(_table[p].size != size) - { - ::free(0); - } - else - { - _table.erase(p); - } - ::free (p); - } - virtual ~debugpool() - { - if(_table.size() > 0) - { - for(std::map::iterator i=_table.begin(); i!=_table.end(); ++i) - { - printf("%ld %ld %s\n", (long)i->first, (long)i->second.size, i->second.stack.c_str()); - } - } - } - }; -} - - - - - - - - - - - - - -#endif //__BSL_DEBUGPOOL_H_ - -/* vim: set expandtab ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_pool.h b/bsl/pool/bsl_pool.h deleted file mode 100644 index 4dbf52a909406ca5004b3d4eb3e8e739147faa97..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_pool.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_pool.h,v 1.7 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file idl.h - * @author yufan(com@baidu.com) - * @date 2008/11/26 11:52:08 - * @version $Revision: 1.7 $ - * @brief - * - **/ - - -#ifndef __BSL_POOL_H_ -#define __BSL_POOL_H_ -#include -#include -#include -#include - -namespace bsl -{ - class mempool - { - public: - virtual void * malloc (size_t size) = 0; - virtual void free (void *p, size_t size) = 0; - inline virtual ~mempool() - { - } - }; - class syspool : public mempool - { - public: - inline virtual void * malloc (size_t size) { - return ::malloc(size); - } - inline virtual void free (void *p, size_t) { - ::free(p); - } - }; - - -} //namespace bsl - - - - - - - - - - - - - - - -#endif //__IDL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_poolalloc.h b/bsl/pool/bsl_poolalloc.h deleted file mode 100644 index fb0047bbb91ce0c7c724d448715f3e3a57b5491d..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_poolalloc.h +++ /dev/null @@ -1,169 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_poolalloc.h,v 1.7 2009/06/15 06:29:04 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_poolalloc.h - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 18:30:29 - * @version $Revision: 1.7 $ - * @brief - * - **/ - - -#ifndef __BSL_POOLALLOC_H_ -#define __BSL_POOLALLOC_H_ -#include -#include "bsl_pool.h" -#include - -namespace bsl -{ - - template - class pool_allocator; - - /** - * @brief pool_allocator对void的特化 - * - * 没有分配内存作用,只可以rebind到其它类型 - */ - template<> - class pool_allocator - { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; - typedef const void* const_pointer; - typedef void value_type; - - template - friend class pool_allocator; - - template - struct rebind - { typedef pool_allocator<_Tp1> other; }; - - pool_allocator() throw() - :_p_pool(NULL) { } - - pool_allocator(mempool *p_pool) throw() - :_p_pool(p_pool) { } - - pool_allocator(const pool_allocator & a) throw() - :_p_pool(a._p_pool){ } - - template - pool_allocator( const pool_allocator<_Tp1>& a ) throw() - :_p_pool(a._p_pool){ } - - ~pool_allocator() throw() { } - private: - mempool *_p_pool; - - }; - - template - class pool_allocator - { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp* pointer; - typedef const _Tp* const_pointer; - typedef _Tp& reference; - typedef const _Tp& const_reference; - typedef _Tp value_type; - - template - friend class pool_allocator; - - template - struct rebind { typedef pool_allocator<_Tp1> other; }; - - pool_allocator() throw() - :_p_pool(NULL) { } - - pool_allocator(mempool *p_pool) throw() - :_p_pool(p_pool) { } - - pool_allocator(const pool_allocator & a) throw() - :_p_pool(a._p_pool){ } - - template - pool_allocator( const pool_allocator<_Tp1>& a ) throw() - :_p_pool(a._p_pool){ } - - ~pool_allocator() throw() { } - - pointer - address(reference __x) const { return &__x; } - - const_pointer - address(const_reference __x) const { return &__x; } - - pointer - allocate(size_type __n, const void* = 0) - { - size_t size_ = __n * sizeof(_Tp); - pointer __ret = static_cast<_Tp*>( _p_pool ? _p_pool->malloc(size_) : malloc(size_) ); - if (!__ret){ - throw bsl::BadAllocException() << BSL_EARG << "size["<free (static_cast(__p), sizeof(_Tp) * size_); - }else{ - free( __p ); - } - } - - size_type - max_size() const throw() { - return size_t(-1) / sizeof(_Tp); - } - - void - construct(pointer __p, const _Tp& __val) - { ::new(__p) value_type(__val); } - - void - destroy(pointer __p) { __p->~_Tp(); } - - bool - operator==(const pool_allocator& other) const { - return _p_pool == other._p_pool; - } - - bool - operator!=(const pool_allocator& other) const { - return _p_pool != other._p_pool; - } - - private: - mempool *_p_pool; - }; - - -} - - - - - -#endif //__BSL_POOLALLOC_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_xcompool.cpp b/bsl/pool/bsl_xcompool.cpp deleted file mode 100644 index 399c246d2b6ba30fd86b9752c923a9d9ec66eb72..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_xcompool.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_xcompool.cpp,v 1.6 2009/01/06 14:05:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_xcompool.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 17:58:00 - * @version $Revision: 1.6 $ - * @brief - * - **/ - - -#include "bsl_xcompool.h" - -namespace bsl -{ - -int xcompool::create(size_t maxblk, size_t bmin, size_t bmax, float rate) -{ - destroy(); - _buffer = ::malloc (maxblk); - _bufsiz = maxblk; - if (_buffer == NULL) return -1; - int ret = _pool.create(_buffer, maxblk, bmin, bmax, rate); - if (ret != 0) { - destroy(); - return -1; - } - _maxblksiz = maxblk; - if (_maxblksiz < _pool.max_alloc_size()) { - _maxblksiz = _pool.max_alloc_size(); - } - - return ret; -} - -void xcompool::destroy() -{ - _pool.destroy(); - for (SET::iterator iter = _set.begin(); iter != _set.end(); ++iter) { - ::free (*iter); - } - _set.clear(); - if (_buffer) { - ::free (_buffer); - } - _buffer = 0; - _bufsiz = 0; - _maxblksiz = 0; -} - -void * xcompool::malloc (size_t size) -{ - void * ret = NULL; - if (size > _pool.max_alloc_size()) { - ret = ::malloc(size); - if (ret) { - _set.insert(ret); - } - return ret; - } - ret = _pool.malloc(size); - if (ret) return ret; - ret = ::malloc (_maxblksiz); - if (ret == NULL) return NULL; - _set.insert(ret); - _pool.addbuf(ret, _maxblksiz); - return _pool.malloc(size); -} - -void xcompool::free (void *ptr, size_t size) -{ - if (size > _pool.max_alloc_size()) { - ::free(ptr); - _set.erase(ptr); - return; - } - _pool.free(ptr, size); -} - -void xcompool::clear () -{ - _pool.clear(_buffer, _bufsiz); - for (SET::iterator iter=_set.begin(); iter != _set.end(); ++iter) { - ::free (*iter); - } - _set.clear(); -} - -}; - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_xcompool.h b/bsl/pool/bsl_xcompool.h deleted file mode 100644 index a34b69ceb3fa70d6b6a81a1aa13f0dab281e736a..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_xcompool.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_xcompool.h,v 1.5 2009/01/06 14:05:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_xcompool.h - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 17:46:07 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - -#ifndef __BSL_XCOMPOOL_H_ -#define __BSL_XCOMPOOL_H_ - - -#include "bsl_xmempool.h" -#include - -namespace bsl -{ -class xcompool : public mempool -{ - size_t _maxblksiz; - void * _buffer; - size_t _bufsiz; - xmempool _pool; - - typedef std::set SET; - SET _set; -public: - xcompool() { - _maxblksiz = 0; - _buffer = NULL; - } - ~xcompool() { - destroy(); - } - /** - * @brief 初始化内存池 - * - * @param [in/out] maxblk : size_t 每个slab管理的内存大小 - * @param [in/out] bmin : size_t slab管理的最小内存单元 - * @param [in/out] bmax : size_t slab管理的最大内存单元 - * @param [in/out] rate : float slab的递增因子 - * @return int 成功返回0, 其他失败 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 14:07:04 - **/ - int create (size_t maxblk = 1<<20, - size_t bmin = sizeof(void *), size_t bmax = (1<<16), - float rate = 2.0f); - - /** - * @brief 销毁内存池 - * - * @return void - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 14:08:27 - **/ - void destroy(); - - void * malloc (size_t size); - - void free (void *ptr, size_t size); - - /** - * @brief 回收pool分配的内存 - * - * @return void - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 14:08:53 - **/ - void clear (); - -}; -}; - - - -#endif //__BSL_XCOMPOOL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_xmempool.cpp b/bsl/pool/bsl_xmempool.cpp deleted file mode 100644 index 4094ea4c2f243dca110525621a27c47f765d47fa..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_xmempool.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_xmempool.cpp,v 1.4 2008/12/25 05:44:10 yufan Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_xmempool.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 16:27:15 - * @version $Revision: 1.4 $ - * @brief - * - **/ - -#include "bsl_xmempool.h" - -namespace bsl -{ - -#define DELSIZE(rsize, size) \ - size_t rsize = (((size) + sizeof(int) - 1) / sizeof(int) * sizeof(int)) - -#define RSIZE(rsize, size) \ - rsize = (((size) + sizeof(int) - 1) / sizeof(int) * sizeof(int)) - -xmempool::xmempool() -{ - _maxsiz = 0; - _pool = 0; - _rate = 0; -} - -xmempool::~xmempool() -{ - destroy(); -} - - -int xmempool::create(void *buf, size_t bufsiz, - size_t bmin, size_t bmax, float rate) -{ - DELSIZE(__bmin, bmin); - DELSIZE(__bmax, bmax); - if (__bmin < sizeof(void *)) __bmin = sizeof(void *); - if (__bmin > __bmax) return -1; - - if (buf == NULL || bufsiz == 0 || rate < 1.01f) return -1; - - size_t __b = __bmin; - int lvl = 1; - while (__b < __bmax) { - ++ lvl; - RSIZE(__b, (size_t)(__b * rate)); - } - - _mlc.create(buf, bufsiz); - _poolsize = lvl; - _minsiz = __bmin; - _rate = rate; - return clear(); -} - -int xmempool::clear() -{ - return clear (_mlc._buffer, _mlc._bufcap); -} - -int xmempool::clear (void *buffer, size_t size) -{ - _mlc.create (buffer, size); - _pool = (xfixmemg *)_mlc.malloc(sizeof(xfixmemg) * _poolsize); - if (_pool == NULL) return -1; - - _maxsiz = 0; - size_t m = _minsiz; - for (int i=0; i<_poolsize; ++i) { - _pool[i].create(m); - _maxsiz = m; - RSIZE(m, (size_t)(m * _rate)); - } - return 0; -} - -int xmempool::destroy() -{ - _mlc.destroy(); - _pool = 0; - _maxsiz = 0; - _minsiz = 0; - _poolsize = 0; - _rate = 0; - return 0; -} - -int xmempool::getidx(size_t size) -{ - if (size > _pool[_poolsize-1]._size) return -1; - int len = _poolsize, half=0, mid=0, first=0; - - while (len > 0) { - half = len >> 1; - mid = first + half; - if (_pool[mid]._size < size) { - first = mid + 1; - len = len - half - 1; - } else { - len = half; - } - } - return first; -} - -void * xmempool::addbuf (void *buf, size_t size) -{ - void * oldbuf = _mlc._buffer; - for (int i=_poolsize-1; i>=0; --i) { - void * ret = NULL; - while ( (ret = _mlc.malloc(_pool[i]._size)) != NULL) { - _pool[i].free (ret); - } - } - _mlc.create (buf, size); - return oldbuf; -} - -}; - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/pool/bsl_xmempool.h b/bsl/pool/bsl_xmempool.h deleted file mode 100644 index 3839a14113baf21c0f35c9e2311c9aacc407f8c2..0000000000000000000000000000000000000000 --- a/bsl/pool/bsl_xmempool.h +++ /dev/null @@ -1,306 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_xmempool.h,v 1.9 2009/06/15 06:29:04 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_xmempool.h - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 16:15:29 - * @version $Revision: 1.9 $ - * @brief - * - **/ - - -#ifndef __BSL_XMEMPOOL_H_ -#define __BSL_XMEMPOOL_H_ - -#include "bsl_pool.h" -#include -#include - -namespace bsl -{ - -union xmem_node_t -{ - xmem_node_t *next; - char data[0]; -}; - -class xfixmemg -{ -public: - xmem_node_t *_freelst; - size_t _size; -public: - inline xfixmemg() { create(0); } - inline ~xfixmemg() { create(0); } - inline void create (int size) { - _size = size; - _freelst = 0; - } - inline void destroy () { - create (0); - } - inline void * malloc () { - if (_freelst) { - xmem_node_t *node = _freelst; - _freelst = _freelst->next; - return (void *)node->data; - } - return NULL; - } - - inline void free (void *ptr) { - ((xmem_node_t *)ptr)->next = _freelst; - _freelst = (xmem_node_t *) ptr; - } -}; - -class xnofreepool : public mempool -{ -public: - char * _buffer; - size_t _bufcap; - size_t _bufleft; - - size_t _free; -public: - /** - * @brief 创建pool - * - * @param [in/out] buf : void* 托管的内存支持 - * @param [in/out] bufsiz : size_t 托管的内存大小 - * @return void - * @retval - * @see - * @note - * @author xiaowei - * @date 2009/01/05 19:54:30 - **/ - inline void create (void *buf, size_t bufsiz) { - _buffer = (char *)buf; - _bufcap = bufsiz; - _bufleft = bufsiz; - _free = 0; - } - inline void * malloc (size_t size) { - if (size > _bufleft) return NULL; - _bufleft -= size; - return _buffer + _bufleft; - } - inline void free (void *, size_t size) { - _free += size; -#ifdef BSL_NOFREEPOOL_AUTO_CLEAR - if (_free == _bufcap) { - clear(); - } -#endif - } - inline void clear () { - _bufleft = _bufcap; - _free = 0; - } - void destroy () { - _buffer = NULL; - _bufcap = 0; - _bufleft = 0; - _free = 0; - } - -}; - -class xmempool : public mempool -{ - static const int CNT = 10; - - xfixmemg *_pool; //实际内存管理器 - int _poolsize; - xnofreepool _mlc; //实际内存分配器 - size_t _minsiz; - size_t _maxsiz; //最大可分配内存 - float _rate; - -public: - xmempool (); - ~xmempool (); - - /** - * @brief 初始化内存池 - * - * @param [in] buf : void* 从哪片内存分配空间 - * @param [in] bufsiz : size_t 这片内存多大 - * @param [in] bmin : size_t 最小内存分配单元多大 - * @param [in] bmax : size_t 最大内存分配单元多大 - * @param [in] rate : float slab 内存增长率 - * @return int 成功返回0, 其他-1 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:36:45 - **/ - int create (void * buf, size_t bufsiz, - size_t bmin = sizeof(void *), size_t bmax = (1<<20), float rate = 2.0f); - - /** - * @brief 销毁pool - * - * @return int 成功返回0, 失败-1 - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:40:43 - **/ - int destroy (); - - - /** - * @brief 分配内存 - * - * @param [in/out] size : size_t - * @return void* 分配size大小的内存, 失败返回NULL - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:41:16 - **/ - inline void * malloc (size_t size) { - int idx = getidx (size); - if (idx >= 0) { - void * ret = _pool[idx].malloc(); - if (ret) return ret; - - return _mlc.malloc (_pool[idx]._size); - } - return NULL; - } - - /** - * @brief 释放内存 - * - * @param [in/out] ptr : void* - * @param [in/out] size : size_t 释放的内存大小 - * @return void - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:41:51 - **/ - inline void free (void *ptr, size_t size) { - if (ptr == NULL) return; - int idx = getidx(size); - if (idx >= 0) { - _pool[idx].free(ptr); - } - } - - /** - * @brief 允许分配的最大内存 - * - * @return size_t - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:42:16 - **/ - inline size_t max_alloc_size() { - return _maxsiz; - } - - /** - * @brief 回收所有分配内存 - * - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:43:27 - **/ - int clear (); - - - /** - * @brief 用buffer替换当前内存,并清空 - * - * @param [in/out] buffer : void* - * @param [in/out] size : size_t - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 15:05:27 - **/ - int clear (void *buffer, size_t size); - - - /** - * @brief 这个接口相当危险, 不推荐使用 - * 这个接口的功能是,让这个pool在管理新增的内存, - * 返回老内存的管理指针. - * 但是用户调用clear的时候,被替换的老内存将被无数,而不会重新分配 - * 这样造成内存泄露 的假象 - * - * 这个接口存在的意义, 是让懂实现的人,方便的利用这个pool的特性做二次开发 - * - * @param [in/out] buf : void* - * @param [in/out] size : size_t - * @return void* - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 13:41:05 - **/ - void * addbuf (void *buf, size_t size); -private: - - /** - * @brief 获取分配的内存管理指针 - * - * @param [in/out] size : size_t - * @return int - * @retval - * @see - * @note - * @author xiaowei - * @date 2008/12/24 10:43:48 - **/ - int getidx (size_t size); - -public: - /** - * @brief 根据size返回你如果要分配这个size,那么会分配给你多大的空间,主要用于调试 - * - * @param [in/out] size : size_t - * @return size_t - * @retval - * @see - * @note - * @author xiaowei - * @date 2009/01/05 20:20:59 - **/ - size_t goodsize (size_t size) { - int idx = getidx(size); - if (idx < 0 || idx >= _poolsize) return 0; - return _pool[idx]._size; - } -}; - -}; - -#endif //__BSL_XMEMPOOL_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/Makefile b/bsl/proctest/Makefile deleted file mode 100644 index 566473c985b2e2d0f3712d9b689c294c16af9f7c..0000000000000000000000000000000000000000 --- a/bsl/proctest/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -BSL=../ -BENCH=$(BSL)/yperfbench/bin/ -PYTHON=python -ifeq ($(MAC),64) - MAKECONF=make.conf - RSSH=work@tc-testing-com00.tc:xwtest/ -else - MAKECONF=make32.conf - RSSH=ziyuan@zjm-ziyuan-test01.zjm:xwtest/ - PYTHON=python2.5 -endif - -all : - chmod +x $(BENCH)/bench - make -C $(BSL)/yperfbench - $(PYTHON) $(BENCH)/bench -dconf/ -c$(MAKECONF) -C -V - -test : - $(PYTHON) $(BENCH)/bench -dconf/ -c$(MAKECONF) -V - -output : - $(PYTHON) $(BENCH)/bench -dconf/ -c$(MAKECONF) -fresult -V - -remote : - $(PYTHON) $(BENCH)/bench -dconf/ -c$(MAKECONF) -fresult -V -r$(RSSH) - -clean : - rm -f *.o bsl_unsafe_hash .bench* - diff --git a/bsl/proctest/bsl_thread_hash.cpp b/bsl/proctest/bsl_thread_hash.cpp deleted file mode 100644 index dce6fbd4000f51039c675981b9c765f882f2ecb9..0000000000000000000000000000000000000000 --- a/bsl/proctest/bsl_thread_hash.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_thread_hash.cpp,v 1.2 2008/11/12 04:13:35 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_thread_hash.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/26 11:45:39 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -template -struct type_t -{ - char data[size]; -}; - -struct point_t -{ - size_t hash_bucket; - size_t hash_datanum; - int thread_num; - int value_size; - long query_loop; - int insert_speed; - std::string hash_type; -public: - point_t() { - hash_bucket = 0; - hash_datanum = 0; - thread_num = 0; - value_size = 0; - query_loop = 0; - insert_speed = 0; - hash_type = ""; - } -}; - -int **g_randsize = 0; -int g_size = 0; -pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; -int g_pos = 0; -int g_num = 0; - -void randint(int num, int data) -{ - g_randsize = (int **) malloc (sizeof(int *) * num); - for (int i=0; i= g_num) g_pos = 0; - int *val = g_randsize[g_pos]; - ++ g_pos; - pthread_mutex_unlock(&g_lock); - return val; -} - -template -struct test_query_t -{ - hash_t & _1; - Slotime _2; - point_t & _3; -public: - test_query_t(hash_t & h, point_t &p) : - _1(h), _2(p.thread_num), _3(p) {} -}; - -template -void * test_insert_r(void *param) -{ - test_query_t *fd = (test_query_t *)param; - timeval s, e; - gettimeofday(&s, NULL); - for (int i=0; i_3.hash_datanum; ++i) { - fd->_1.set(rand(), value_type()); - if ((i%fd->_3.insert_speed) == fd->_3.insert_speed - 1) { - gettimeofday(&e, NULL); - long used = XTIMEDIFF(s, e); - if (used < 1000) { - timespec t = { - (1000-used) / 1000, - (1000-used) * 1000000 - }; - timespec e; - nanosleep(&t, &e); - } - gettimeofday(&s, NULL); - } - } - - return NULL; -} - - -template -void * test_query_r(void *arg) -{ - test_query_t *fd = (test_query_t *)arg; - type_t v; - int *val = getrand(); - long loop = fd->_3.query_loop / (long)fd->_3.thread_num; - fd->_2.start(); - for (long i=0; i_1.get(val[i%g_size], &v); - } - fd->_2.stop(); - return NULL; -} - -unsigned int ans_hash_fcnt(const long & v) { return v; } - -template -void test(hash_t &hash, point_t &p) -{ - for (int i=0; i<(int)((float)p.hash_datanum/(1.5f)); ++i) { - hash.set(rand(), stype_t()); - } - test_query_t qval(hash, p); - test_query_t uval(hash, p); - xthread_t ptr[] = { - {test_query_r, &qval, p.thread_num}, - {test_insert_r, &uval, 1}, - }; - run_thread(ptr, 2); - double speed = (double)(p.query_loop) / ((float)(qval._2.cost()) + 1e-10); - char flag[1024]; - snprintf(flag, sizeof(flag), "speed(%s)", p.hash_type.c_str()); - //std::cout< -void testcase(point_t &p) -{ - //ans::hashmap - { - std::cout<<"ans_hashmap "< > anshash1_t; - anshash1_t hash; - hash.create(p.hash_bucket, ans_hash_fcnt); - p.hash_type = "ans_hashmap"; - test >(hash, p); - std::cout< > bslhash1_t; - bslhash1_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_phashmap"; - test >(hash, p); - std::cout<("hash_bucket"); - p.hash_datanum = pb::getopt("hash_datanum"); - p.thread_num = pb::getopt("thread_num"); - p.value_size = pb::getopt("value_size"); - p.query_loop = pb::getopt("query_loop"); - p.query_loop *= 1000000; - p.insert_speed = pb::getopt("insert_speed"); - - if (p.value_size <= 4) { - testcase (p); - } else if (p.value_size <= 8) { - testcase (p); - } else if (p.value_size < 32) { - testcase (p); - } else { - testcase (p); - } - return 0; -} - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/bsl_unsafe_hash.cpp b/bsl/proctest/bsl_unsafe_hash.cpp deleted file mode 100644 index a8b83354a6fde344a1cf447d530fead2b9394744..0000000000000000000000000000000000000000 --- a/bsl/proctest/bsl_unsafe_hash.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_unsafe_hash.cpp,v 1.2 2008/11/12 04:00:31 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_unsf_hash.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/22 18:53:11 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "stl_hashmap.h" - -/* - * 单线程下的性能测试比较 - */ - -struct point_t -{ - size_t hash_bucket; - size_t hash_datanum; - int thread_num; - int value_size; - long query_loop; - std::string hash_type; -public: - point_t() { - hash_bucket = 0; - hash_datanum = 0; - thread_num = 0; - value_size = 0; - query_loop = 0; - hash_type = ""; - } -}; - -template -struct type_t -{ - char data[size]; -}; - -template -void test_insert(hash_t &hash, int datanum) -{ - Slotime st(1); - st.start(); - for (int i=0; i= g_num) g_pos = 0; - int *val = g_randsize[g_pos]; - ++ g_pos; - pthread_mutex_unlock(&g_lock); - return val; -} - -template -struct test_query_t -{ - hash_t & _1; - Slotime _2; - point_t & _3; -public: - test_query_t(hash_t & h, point_t &p) : - _1(h), _2(p.thread_num), _3(p) {} -}; -template -void * test_query_r(void *arg) -{ - test_query_t *fd = (test_query_t *)arg; - type_t v; - int *val = getrand(); - long loop = fd->_3.query_loop / (long)fd->_3.thread_num; - fd->_2.start(); - for (long i=0; i_1.get(val[i%g_size], &v); - } - fd->_2.stop(); - return NULL; -} -template -void test_query(hash_t &hash, point_t &p) -{ - test_query_t val(hash, p); - run_thread(test_query_r, &val, p.thread_num); - //std::cout<<" "< -void test(hash_t &hash, point_t &p) -{ - test_insert(hash, p.hash_datanum); - test_query(hash, p); -} - -template -void testcase(point_t &p) -{ - //stl::hashmap - { - g_pos = 0; - std::cout<<"stl_hashmap "< > xhash_t; - xhash_t hash; - p.hash_type = "stl_hashmap"; - test >(hash, p); - std::cout< > anshash1_t; - anshash1_t hash; - hash.create(p.hash_bucket, ans_hash_fcnt); - p.hash_type = "ans_hashmap"; - test >(hash, p); - std::cout< > rm_t; - rm_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_readmap"; - std::cout< > >vec; - for (int i=0; i<(int)p.hash_datanum; ++i) { - vec.push_back(std::make_pair(i, type_t())); - } - hash.assign(vec.begin(), vec.end()); - test_query >(hash, p); - hash.clear(); - } - //bsl::hashmap - { - g_pos = 0; - std::cout<<"bsl_hashmap sample_alloc "< > bslhash1_t; - bslhash1_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_hashmap/sample_alloc"; - test >(hash, p); - std::cout<, bsl::xhash, - bsl::equal, bsl::bsl_alloc > bslhash2_t; - bslhash2_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_hashmap/alloc"; - test >(hash, p); - std::cout<, bsl::xhash, - bsl::equal, bsl::bsl_cpsalloc > > bslhash3_t; - bslhash3_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_hashmap/cpsalloc"; - test >(hash, p); - std::cout< > bslphash1_t; - bslphash1_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_phashmap/sample_alloc"; - test >(hash, p); - std::cout<, bsl::xhash, - bsl::equal, bsl::bsl_alloc > bslphash2_t; - bslphash2_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_phashmap/alloc"; - test >(hash, p); - std::cout<, bsl::xhash, - bsl::equal, bsl::bsl_cpsalloc > > bslphash3_t; - bslphash3_t hash; - hash.create(p.hash_bucket); - p.hash_type = "bsl_phashmap/cpsalloc"; - test >(hash, p); - std::cout<("hash_bucket"); - p.hash_datanum = pb::getopt("hash_datanum"); - p.thread_num = pb::getopt("thread_num"); - p.value_size = pb::getopt("value_size"); - p.query_loop = pb::getopt("query_loop"); - p.query_loop *= 1000000; - -#if 0 - pb::put_result("hash_bucket", (int)p.hash_bucket); - pb::put_result("hash_datanum", (int)p.hash_datanum); - pb::put_result("thread_num", (int)p.thread_num); - pb::put_result("value_size", (int)p.value_size); - pb::put_result("query_loop", (int)p.query_loop); -#endif - //testcase(p); - if (p.value_size <= 4) { - testcase (p); - } else if (p.value_size <= 8) { - testcase (p); - } else if (p.value_size < 32) { - testcase (p); - } else { - testcase (p); - } - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/proctest/bslsort.cpp b/bsl/proctest/bslsort.cpp deleted file mode 100644 index 4bfa100e56e70bdfe7856d8d90ce830075a5c651..0000000000000000000000000000000000000000 --- a/bsl/proctest/bslsort.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bslsort.cpp,v 1.2 2008/11/12 04:13:35 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsltest.cpp - * @author yufan(com@baidu.com) - * @date 2008/07/31 18:53:53 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#include -#include -#include -#include -int main(int argc, char ** argv ) -{ - - pb::init_opt(argc, argv); - int len = pb::getopt("len"); - bsl::list s; - std::list t; - s.create(); - for(int i=0; i < len; i++) - { - int p = rand(); - t.push_front(p); - s.push_front(p); - } - pb::timer time; - s.sort(); - time.check(); -#if 0 - t.sort(); - bsl::list::iterator i1 = s.begin(); - for(std::list::iterator i2 = t.begin();i2 != t.end();i2++) - { - if(*i1 != *i2) - { - printf("%d,%d\n", *i1, *i2); - exit(1); - } - i1++; - } -#endif -} - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/bsltest.cpp b/bsl/proctest/bsltest.cpp deleted file mode 100644 index da1aa44786f3c08836f98e701aa03461d2e91191..0000000000000000000000000000000000000000 --- a/bsl/proctest/bsltest.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsltest.cpp,v 1.2 2008/11/12 04:13:35 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsltest.cpp - * @author yufan(com@baidu.com) - * @date 2008/07/31 18:53:53 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - - -#include -#include - -int main(int argc, char ** argv ) -{ - - pb::init_opt(argc, argv); - int c = pb::getopt("time"); - bsl::slist s; - pb::timer t; - for (int i=0; i< c; i++) - { - s.push_front(i); - } - t.check(); - -} - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/conf/make.conf b/bsl/proctest/conf/make.conf deleted file mode 100644 index 1e7065d81c7f12c036cdae2c8c51a190b764efec..0000000000000000000000000000000000000000 --- a/bsl/proctest/conf/make.conf +++ /dev/null @@ -1,62 +0,0 @@ -WORKROOT=../../../ - -LIBPATH=$(WORKROOT)lib2-64 - - -PUBLIC=$(WORKROOT)/public -ULLIB=$(LIBPATH)/ullib/ -NSHEAD=$(PUBLIC)/nshead/ -DICT=$(LIBPATH)/dict/ -BSL=$(WORKROOT)/libsrc/bsl/ - -INCLUDES= -I$(ULLIB)/include -I$(NSHEAD) -I$(DICT)/include/ -I$(BSL) -I$(PUBLIC) -I$(BSL)/yperfbench/include -CFLAGS = -Wall -W -pipe -Wno-unused-parameter -g -Wno-deprecated -D_XOPEN_SOURE=500 -D_GNU_SOURCE -LDFLAGS= -L$(BSL)/yperfbench/lib/ -lyperfbench -L$(ULLIB)/lib -L$(NSHEAD) -L$(DICT)/lib -luldict -lcrypto -lcrypt -lnshead -lullib -lpthread -lm - - -#测试查询性能 -unsafe_hash 2: bsl_unsafe_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - -#测试查询性能 -unsafe_hash_O3 2: bsl_unsafe_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) -O3 - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - -#测试多读一写下的性能 -thread_hash 2: bsl_thread_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - insert_speed = 1000000 - -#测试多读一写下的性能 -thread_hash_O3 2: bsl_thread_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) -O3 - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - insert_speed = 1000000 - -#测试链表性能 -listcase1 : bsltest.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - time = 10000000 20000000 40000000 - -listcase2 : stllist.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - time = 10000000 20000000 40000000 - -bslsort : bslsort.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - len = 1000000 2000000 4000000 - -stlsort : stlsort.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - len = 1000000 2000000 4000000 diff --git a/bsl/proctest/conf/make32.conf b/bsl/proctest/conf/make32.conf deleted file mode 100644 index 88734c5d8cdfbce59f41c7b2ff854a69080969d9..0000000000000000000000000000000000000000 --- a/bsl/proctest/conf/make32.conf +++ /dev/null @@ -1,62 +0,0 @@ -WORKROOT=../../../ - -LIBPATH=$(WORKROOT)lib2 - - -PUBLIC=$(WORKROOT)/public -ULLIB=$(LIBPATH)/ullib/ -NSHEAD=$(PUBLIC)/nshead/ -DICT=$(LIBPATH)/dict/ -BSL=$(WORKROOT)/libsrc/bsl/ - -INCLUDES= -I$(ULLIB)/include -I$(NSHEAD) -I$(DICT)/include/ -I$(BSL) -I$(PUBLIC) -I$(BSL)/yperfbench/include -CFLAGS = -Wall -W -pipe -Wno-unused-parameter -g -Wno-deprecated -D_XOPEN_SOURE=500 -D_GNU_SOURCE -LDFLAGS= -L$(BSL)/yperfbench/lib/ -lyperfbench -L$(ULLIB)/lib -L$(NSHEAD) -L$(DICT)/lib -luldict -lcrypto -lcrypt -lnshead -lullib -lpthread -lm - - -#测试查询性能 -unsafe_hash 2: bsl_unsafe_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - -#测试查询性能 -unsafe_hash_O3 2: bsl_unsafe_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) -O3 - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - -#测试多读一写下的性能 -thread_hash 2: bsl_thread_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - insert_speed = 1000000 - -#测试多读一写下的性能 -thread_hash_O3 2: bsl_thread_hash.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) -O3 - hash_bucket = 1000000 - hash_datanum = 1000000 700000 - thread_num = 1 4 8 16 32 48 64 - value_size = 8 16 32 - query_loop = 100 - insert_speed = 1000000 - -#测试链表性能 -listcase1 : bsltest.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - time = 10000000 20000000 40000000 - -listcase2 : stllist.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - time = 10000000 20000000 40000000 - -bslsort : bslsort.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - len = 1000000 2000000 4000000 - -stlsort : stlsort.cpp $(CFLAGS) $(LDFLAGS) $(INCLUDES) - len = 1000000 2000000 4000000 diff --git a/bsl/proctest/stl_hashmap.h b/bsl/proctest/stl_hashmap.h deleted file mode 100644 index 96672b32afcfb360388a2833c46b8b32615eb2ad..0000000000000000000000000000000000000000 --- a/bsl/proctest/stl_hashmap.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: stl_hashmap.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file stl_hashmap.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/26 15:12:10 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __STL_HASHMAP_H_ -#define __STL_HASHMAP_H_ - - -#include - -template -class xhashmap -{ -public: - hash_map _map; - int set(const key_t &key, const value_t &val) { - _map.insert(std::make_pair(key, val)); - return 0; - } - int get(const key_t &key, value_t *val) { - typename hash_map::iterator iter = _map.find(key); - if (iter == _map.end()) return -1; - if (val != 0) *val = iter->second; - return 0; - } - int erase(const key_t &key) { - _map.erase(key); - return 0; - } -}; - - -#endif //__STL_HASHMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/stllist.cpp b/bsl/proctest/stllist.cpp deleted file mode 100644 index 3f305846fea5948e727c9cb9dfbf71c7fec886a3..0000000000000000000000000000000000000000 --- a/bsl/proctest/stllist.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: stllist.cpp,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsltest.cpp - * @author yufan(com@baidu.com) - * @date 2008/07/31 18:53:53 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - - -#include -#include "yperfbench.h" - -int main(int argc, char ** argv ) -{ - - pb::init_opt(argc, argv); - int c = pb::getopt("time"); - std::list s; - pb::timer t; - for (int i=0; i< c; i++) - { - s.push_front(i); - } - t.check(); - -} - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/proctest/stlsort.cpp b/bsl/proctest/stlsort.cpp deleted file mode 100644 index bcb895c02dcf6acc58a024e7ff4c262402bcb1de..0000000000000000000000000000000000000000 --- a/bsl/proctest/stlsort.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: stlsort.cpp,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsltest.cpp - * @author yufan(com@baidu.com) - * @date 2008/07/31 18:53:53 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#include -#include -#include "yperfbench.h" - -int main(int argc, char ** argv ) -{ - - pb::init_opt(argc, argv); - int len = pb::getopt("len"); - std::list s; - for(int i=0; i < len; i++) - s.push_front(rand()); - pb::timer t; - s.sort(); - t.check(); -} - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/release.bcloud b/bsl/release.bcloud deleted file mode 100644 index ca86fa238fa0334f1c15e5c410230c8a31c963c4..0000000000000000000000000000000000000000 --- a/bsl/release.bcloud +++ /dev/null @@ -1,14 +0,0 @@ -mv BCLOUD.lib2-64 BCLOUD -find lib/ -name "libbsl_var*.a" -exec ar xo {} \; -ar cr lib/libbsl_var.a *.o -rm -f *.o -ar xo lib/libbsl_utils.a -ar xo lib/libbsl_archive.a -ar xo lib/libbsl_buffer.a -ar xo lib/libbsl_exception.a -ar xo lib/libbsl_check_cast.a -ar xo lib/libbsl_ResourcePool.a -ar xo lib/libbsl_pool.a -ar xo lib/libbsl_var.a -ar cr lib/libbsl.a *.o -rm -f *.o diff --git a/bsl/set.h b/bsl/set.h deleted file mode 100644 index 38730fedbb0369ff2cd247b7a63f15c200183b0f..0000000000000000000000000000000000000000 --- a/bsl/set.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: set.h,v 1.2 2009/03/09 04:56:41 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bslset.h - * @author xiaowei(com@baidu.com) - * @date 2009/01/13 11:35:10 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSLSET_H_ -#define __BSLSET_H_ - - -#include "containers/hash/bsl_hashset.h" -#include "containers/hash/bsl_phashset.h" -#include "containers/hash/bsl_readset.h" - -#endif //__BSLSET_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/string.h b/bsl/string.h deleted file mode 100644 index 927821fb5784eaa05878a7e2db33f83265c9130f..0000000000000000000000000000000000000000 --- a/bsl/string.h +++ /dev/null @@ -1,23 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: string.h,v 1.2 2009/06/26 05:23:25 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file string.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/06/25 12:20:00 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#ifndef _BSL_STRING_H_ -#define _BSL_STRING_H_ -#include "containers/string/bsl_string.h" -#endif //__STRING_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/test/COMAKE b/bsl/test/COMAKE deleted file mode 100644 index ba092b7a393f6e14bf08c6a47fb624c60f771086..0000000000000000000000000000000000000000 --- a/bsl/test/COMAKE +++ /dev/null @@ -1,62 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -#工作路径. -WORKROOT('../') - -#使用硬链接copy. -CopyUsingHardLink(True) - -#支持32位/64位平台编译 -#ENABLE_MULTI_LIBS(True) - -#C预处理器参数. -CPPFLAGS('-D_GNU_SOURCE -D__STDC_LIMIT_MACROS -DVERSION=\\\"1.9.8.7\\\"') -#为32位目标编译指定额外的预处理参数 -#CPPFLAGS_32('-D_XOPEN_SOURE=500') - -#C编译参数. -CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++编译参数. -CXXFLAGS('-g -pipe -W -Wall -fPIC') - -#IDL编译参数 -IDLFLAGS('--compack') - -#UBRPC编译参数 -UBRPCFLAGS('--compack') - -#头文件路径. -INCPATHS('. /home/luowei/workroot/libsrc/bsl/output/include') - -#使用库 -LIBS('/home/luowei/workroot/libsrc/bsl/output/lib/libbsl.a') - -#链接参数. -LDFLAGS('-lpthread -lrt') - -#依赖模块 -CONFIGS('lib2/ullib') - -#为32位/64位指定不同的依赖路径. -#CONFIGS_32('lib2/ullib') -#CONFIGS_64('lib2-64/ullib') -CONFIGS('com/btest/gtest') - -#user_headers = 'test_bsl_hashtable.cpp' - - -user_sources='test_bsl_hash_multimap.cpp' -user_headers='' - -#可执行文件 -Application('ex_test_bsl_hash_multimap',Sources(user_sources)) -#, Libraries'/home/luowei/workroot/libsrc/bsl/output/lib/libbsl.a') -#静态库 -#StaticLibrary('test',Sources(user_sources),HeaderFiles(user_headers)) -#共享库 -#SharedLibrary('test',Sources(user_sources),HeaderFiles(user_headers)) -#子目录 -#Directory('demo') - diff --git a/bsl/test/Makefile b/bsl/test/Makefile deleted file mode 100644 index 1cf7e688ec1f644ac882202e9e28a3f1b829c5cd..0000000000000000000000000000000000000000 --- a/bsl/test/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -#COMAKE2 edit-mode: -*- Makefile -*- -####################64Bit Mode#################### -ifeq ($(shell uname -m),x86_64) -CC=gcc -CXX=g++ -CXXFLAGS=-g \ - -pipe \ - -W \ - -Wall \ - -fPIC -CFLAGS=-g \ - -pipe \ - -W \ - -Wall \ - -fPIC -CPPFLAGS=-D_GNU_SOURCE \ - -D__STDC_LIMIT_MACROS \ - -DVERSION=\"1.9.8.7\" -INCPATH=-I. \ - -I/home/luowei/workroot/libsrc/bsl/output/include -DEP_INCPATH=-I../com/btest/gtest \ - -I../com/btest/gtest/include \ - -I../com/btest/gtest/output \ - -I../com/btest/gtest/output/include \ - -I../lib2-64/ullib \ - -I../lib2-64/ullib/include \ - -I../lib2-64/ullib/output \ - -I../lib2-64/ullib/output/include \ - -I../quality/autotest/reportlib/cpp \ - -I../quality/autotest/reportlib/cpp/include \ - -I../quality/autotest/reportlib/cpp/output \ - -I../quality/autotest/reportlib/cpp/output/include - -#============ CCP vars ============ -CCHECK=@ccheck.py -CCHECK_FLAGS= -PCLINT=@pclint -PCLINT_FLAGS= -CCP=@ccp.py -CCP_FLAGS= - - -#COMAKE UUID -COMAKE_MD5=22995f423ceeb5f605432ae4280e1ed3 COMAKE - - -.PHONY:all -all:comake2_makefile_check ex_test_bsl_hash_multimap - @echo "[COMAKE:BUILD][Target:'all']" - @echo "make all done" - -.PHONY:comake2_makefile_check -comake2_makefile_check: - @echo "[COMAKE:BUILD][Target:'comake2_makefile_check']" - #in case of error, update 'Makefile' by 'comake2' - @echo "$(COMAKE_MD5)">comake2.md5 - @md5sum -c --status comake2.md5 - @rm -f comake2.md5 - -.PHONY:ccpclean -ccpclean: - @echo "[COMAKE:BUILD][Target:'ccpclean']" - @echo "make ccpclean done" - -.PHONY:clean -clean:ccpclean - @echo "[COMAKE:BUILD][Target:'clean']" - rm -rf ex_test_bsl_hash_multimap - rm -rf ./output/bin/ex_test_bsl_hash_multimap - rm -rf ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o - -.PHONY:dist -dist: - @echo "[COMAKE:BUILD][Target:'dist']" - tar czvf output.tar.gz output - @echo "make dist done" - -.PHONY:distclean -distclean:clean - @echo "[COMAKE:BUILD][Target:'distclean']" - rm -f output.tar.gz - @echo "make distclean done" - -.PHONY:love -love: - @echo "[COMAKE:BUILD][Target:'love']" - @echo "make love done" - -ex_test_bsl_hash_multimap:ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o \ - /home/luowei/workroot/libsrc/bsl/output/lib/libbsl.a - @echo "[COMAKE:BUILD][Target:'ex_test_bsl_hash_multimap']" - $(CXX) ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o -Xlinker "-(" /home/luowei/workroot/libsrc/bsl/output/lib/libbsl.a ../com/btest/gtest/output/lib/libgtest.a \ - ../com/btest/gtest/output/lib/libgtest_main.a \ - ../lib2-64/ullib/lib/libullib.a \ - ../quality/autotest/reportlib/cpp/libautotest.a -lpthread \ - -lrt -Xlinker "-)" -o ex_test_bsl_hash_multimap - mkdir -p ./output/bin - cp -f --link ex_test_bsl_hash_multimap ./output/bin - -ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o:test_bsl_hash_multimap.cpp - @echo "[COMAKE:BUILD][Target:'ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o']" - $(CXX) -c $(INCPATH) $(DEP_INCPATH) $(CPPFLAGS) $(CXXFLAGS) -o ex_test_bsl_hash_multimap_test_bsl_hash_multimap.o test_bsl_hash_multimap.cpp - -endif #ifeq ($(shell uname -m),x86_64) - - diff --git a/bsl/test/test_bsl_hash_multimap.cpp b/bsl/test/test_bsl_hash_multimap.cpp deleted file mode 100644 index bf0b796fad31479832e6f1c4abf351c952d5231b..0000000000000000000000000000000000000000 --- a/bsl/test/test_bsl_hash_multimap.cpp +++ /dev/null @@ -1,1466 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef string _key; -typedef int _value; -typedef pair<_key, _value> _Pair; -typedef equal_to<_key> _Equl; -typedef bsl::bsl_sample_alloc, 256> _InnerAlloc; - -_Equl _equl; - -typedef bsl::hash_multimap<_key, _value> hash_type; - -typedef hash_type::iterator _iterator; -typedef hash_type::const_iterator _const_iterator; -typedef hash_type::iterator_pair _iterator_pair; -typedef hash_type::const_iterator_pair _const_iterator_pair; - -void print_hash(_const_iterator begin, _const_iterator end) -{ - printf("The hash_multimap can be seen as follow:\n"); - for(hash_type::const_iterator ite = begin ; ite != end; ++ite) - { - //printf("%s -> %d\n", ite->first, ite->second); - cout << ite->first << " -> " << ite->second << endl; - } -}; - -//杩斿洖绗竴涓敭鍊间负key鐨勮凯浠e櫒 -_const_iterator begin_key(const hash_type &ht, const _key &key) -{ - _const_iterator __first = ht.begin(); - while(__first != ht.end()) - { - //if((*__first).first == key) - if(_equl(__first->first, key)) - { - return __first; - } - ++__first; - } - return ht.end(); -}; - -_iterator begin_key(hash_type &ht, const _key &key) -{ - _iterator __first = ht.begin(); - while(__first != ht.end()) - { - //if((*__first).first == key) - if(_equl(__first->first, key)) - { - return __first; - } - ++__first; - }return ht.end(); -}; - -//杩斿洖鏈鍚庝竴涓釜閿间负key鐨勮凯浠e櫒鐨刵ext -_const_iterator end_key(const hash_type &ht, const _key &key) -{ - _const_iterator __end = ht.begin(); - while(__end != ht.end()) - { - //if((*__end).first == key) - if(_equl(__end->first, key)) - { - while(__end != ht.end() && _equl(__end->first, key)) - { - ++__end; - } - break; - } - ++__end; - } - return __end; -}; - -_iterator end_key(hash_type &ht, const _key &key) -{ - _iterator __end = ht.begin(); - while(__end != ht.end()) - { - //if((*__end).first == key) - if(_equl(__end->first, key)) - { - while(__end != ht.end() && _equl(__end->first, key)) - { - ++__end; - } - break; - } - ++__end; - } - return __end; -}; - - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -/** - * @brief -**/ -class test_hash_multimap_hash_multimap_suite : public ::testing::Test{ - protected: - test_hash_multimap_hash_multimap_suite(){}; - virtual ~test_hash_multimap_hash_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_hash_multimap_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_hash_multimap_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_hash_multimap_suite, case_default) -{ - //TODO - hash_type names; -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_hash_multimap_suite, case_copy) -{ - //TODO - hash_type names; - - if(0 != names.create(5)) - { - printf("create hash_multimap error with size %d\n", 5); - } - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - hash_type names_copy(names); - - printf("*********begin**************\n"); - hash_type hmp3(0); - printf("**********end*************\n"); - - try - { - hash_type hmp3(NULL); - int ret=hmp3.is_created(); - printf("***********************ret = %d\n", ret); - } - catch(bsl::Exception& e){printf("%s\n", e.all());} - - - //printf("****************\n"); - //printf("Source:\n"); - //print_hash(names.begin(), names.end()); - //printf("Copy:\n"); - //print_hash(names_copy.begin(), names_copy.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_hash_multimap_suite, case_normal) -{ - //TODO - hash_type names(5); - - names.set("Jones", 2, 1); - names.set("White", 3, 1); - names.set("White", 3, 1); - - //print_hash(names_copy.begin(), names_copy.end()); -} - -/** - * @brief -**/ -class test_hash_multimap_operator_equal_suite : public ::testing::Test{ - protected: - test_hash_multimap_operator_equal_suite(){}; - virtual ~test_hash_multimap_operator_equal_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_operator_equal_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_operator_equal_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_operator_equal_suite, case_self) -{ - //TODO - hash_type names(5); - names.set("Jones", 2, 1); - names.set("White", 3, 1); - names.set("Zhang", 1, 1); - - names = names; - //printf("******************\n"); - //print_hash(names.begin(), names.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_operator_equal_suite, case_other) -{ - hash_type names(5); - - names.set("Jones", 2, 1); - names.set("White", 3, 1); - names.set("Zhang", 1, 1); - names.set("Zhang", 1, 1); - - //printf("^^^^^^^^^^^^^^^^^^^^^^^^\n"); - hash_type names_des = names; - names_des = names; - //print_hash(names_des.begin(), names_des.end()); -} - -/** - * @brief -**/ -class test_hash_multimap_begin_suite : public ::testing::Test{ - protected: - test_hash_multimap_begin_suite(){}; - virtual ~test_hash_multimap_begin_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_begin_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_begin_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_begin_suite, case_normal) -{ - //TODO - hash_type names(100); - _iterator _iter_begin = names.begin(); - //EXPECT_EQ(0,_iter_begin._bucketpos); - //EXPECT_EQ(0,_iter_begin._node); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_begin_suite, case_const) -{ - //TODO -} - -/** - * @brief -**/ -class test_hash_multimap_end_suite : public ::testing::Test{ - protected: - test_hash_multimap_end_suite(){}; - virtual ~test_hash_multimap_end_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_end_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_end_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_end_suite, case_normal) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_end_suite, case_const) -{ - //TODO -} - -/** - * @brief -**/ -class test_hash_multimap_size_suite : public ::testing::Test{ - protected: - test_hash_multimap_size_suite(){}; - virtual ~test_hash_multimap_size_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_size_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_size_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_size_suite, case_size) -{ - //TODO - hash_type names_null; - ASSERT_EQ(0, names_null.size()); - - hash_type names(5); - ASSERT_EQ(0, names.size()); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - names.set("White", 1, 1); - ASSERT_EQ(14, names.size()); -} - -/** - * * @brief - * **/ -class test_hash_multimap_count_suite : public ::testing::Test{ - protected: - test_hash_multimap_count_suite(){}; - virtual ~test_hash_multimap_count_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_count_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_count_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_count_suite, case_count) -{ - //TODO - hash_type names_null; - ASSERT_EQ(0, names_null.count("Bob")); - - hash_type names(5); - ASSERT_EQ(0, names.count("Bob")); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - ASSERT_EQ(5, names.count("Bob")); - ASSERT_EQ(3, names.count("White")); - ASSERT_EQ(2, names.count("Li")); - ASSERT_EQ(0, names.count("Huang")); - ASSERT_EQ(1, names.count("Jack")); -} - -/** - * @brief -**/ -class test_hash_multimap_create_suite : public ::testing::Test{ - protected: - test_hash_multimap_create_suite(){}; - virtual ~test_hash_multimap_create_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_create_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_create_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_create_suite, case_create) -{ - //TODO - hash_type names; - - ASSERT_EQ(0, names.create(5)); -} - -/** - * @brief -**/ -class test_hash_multimap_is_created_suite : public ::testing::Test{ - protected: - test_hash_multimap_is_created_suite(){}; - virtual ~test_hash_multimap_is_created_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_is_created_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_is_created_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_is_created_suite, case_is_create) -{ - //TODO - hash_type names; - ASSERT_EQ(false, names.is_created()); - printf("**********%d\n", names.is_created()); - - names.create(5); - ASSERT_EQ(true, names.is_created()); - printf("**********%d\n", names.is_created()); - - names.destroy(); - ASSERT_EQ(false, names.is_created()); -} - -/** - * @brief -**/ -class test_hash_multimap_destroy_suite : public ::testing::Test{ - protected: - test_hash_multimap_destroy_suite(){}; - virtual ~test_hash_multimap_destroy_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_destroy_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_destroy_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_destroy_suite, case_destroy) -{ - //TODO - hash_type names; - ASSERT_EQ(0, names.destroy()); - - names.create(5); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - ASSERT_EQ(0, names.destroy()); - ASSERT_EQ(false, names.is_created()); - ASSERT_EQ(0, names.size()); -} - -/** - * @brief -**/ -class test_hash_multimap_get_suite : public ::testing::Test{ - protected: - test_hash_multimap_get_suite(){}; - virtual ~test_hash_multimap_get_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_get_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_get_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_normal_null) -{ - //TODO - hash_type names; - ASSERT_EQ(_iterator_pair(names.end(),names.end()), names.get("Li")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_const_null) -{ - hash_type names; - const hash_type names_const(names); - ASSERT_EQ(_const_iterator_pair(names_const.end(),names_const.end()), names_const.get("Li")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_normal_noexist) -{ - //TODO - hash_type names; - names.create(5); - ASSERT_EQ(_iterator_pair(names.end(),names.end()), names.get("Li")); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - - ASSERT_EQ(_iterator_pair(names.end(),names.end()), names.get("Li1")); - ASSERT_EQ(_iterator_pair(names.end(),names.end()), names.get("Tod")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_const_noexist) -{ - //TODO - hash_type names; - names.create(5); - const hash_type names_empty(names); - - ASSERT_EQ(_const_iterator_pair(names_empty.end(),names_empty.end()), names_empty.get("Li")); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - - const hash_type names_const(names); - - ASSERT_EQ(_const_iterator_pair(names_const.end(),names_const.end()), names_const.get("Li1")); - //_const_iterator_pair __const_iterator_pair = names_const.get("Li1"); - //print_hash(__const_iterator_pair.first, __const_iterator_pair.second); - ASSERT_EQ(_const_iterator_pair(names_const.end(),names_const.end()), names_const.get("Tod")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_normal_exist) -{ - //TODO - hash_type names(5); - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - - _iterator __begin; - _iterator __end; - _iterator_pair __ite_pair; - - //print_hash(names.begin(), names.end()); - - __begin = begin_key(names, "Bob"); - __end = end_key(names, "Bob"); - printf("equal:\n"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("Bob")); - //printf("%s = begin---end\n", "Bob"); - //print_hash(__begin, __end); - - __begin = begin_key(names, "White"); - __end = end_key(names, "White"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("White")); - //printf("%s = begin---end\n", "White"); - //print_hash(__begin, __end); - - __begin = begin_key(names, "Jack"); - __end = end_key(names, "Jack"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("Jack")); - //printf("%s = begin---end\n", "Jack"); - //print_hash(__begin, __end); - - __begin = begin_key(names, "Jones"); - __end = end_key(names, "Jones"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("Jones")); - //printf("%s = begin---end\n", "Jones"); - //print_hash(__begin, __end); - - __begin = begin_key(names, "Black"); - __end = end_key(names, "Black"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("Black")); - //printf("%s = begin---end\n", "Black"); - //print_hash(__begin, __end); - - __begin = begin_key(names, "Li"); - __end = end_key(names, "Li"); - EXPECT_EQ(_iterator_pair(__begin, __end), names.get("Li")); - //printf("%s = begin---end\n", "Li"); - //print_hash(__begin, __end); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_get_suite, case_const_exist) -{ - hash_type names(5); - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - - const hash_type names_const(names); - - _const_iterator __begin; - _const_iterator __end; - _const_iterator_pair __ite_pair; - //print_hash(names_const.begin(), names_const.end()); - - __begin = begin_key(names_const, "Bob"); - __end = end_key(names_const, "Bob"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Bob")); - //printf("%s = begin---end\n", "Bob"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "Jack"); - __end = end_key(names_const, "Jack"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Jack")); - //printf("%s = begin---end\n", "Jack"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "Jones"); - __end = end_key(names_const, "Jones"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Jones")); - //printf("%s = begin---end\n", "Jones"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "Black"); - __end = end_key(names_const, "Black"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Black")); - //printf("%s = begin---end\n", "Black"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "White"); - __end = end_key(names_const, "White"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("White")); - //printf("%s = begin---end\n", "White"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "Li"); - __end = end_key(names_const, "Li"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Li")); - //printf("%s = begin---end\n", "Li"); - //print_hash(__begin, __end); - - __begin = begin_key(names_const, "Zhang"); - __end = end_key(names_const, "Zhang"); - //printf("equal:\n"); - EXPECT_EQ(_const_iterator_pair(__begin, __end), names_const.get("Zhang")); - //printf("%s = begin---end\n", "Zhang"); - //print_hash(__begin, __end); -} - -/** - * @brief -**/ -class test_hash_multimap_find_suite : public ::testing::Test{ - protected: - test_hash_multimap_find_suite(){}; - virtual ~test_hash_multimap_find_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_find_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_find_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_find_suite, case_normal) -{ - //TODO - //int find(const key_type &k, value_type &val) - hash_type names; - ASSERT_EQ(-1, names.find("Bob", 1)); - - names.create(5); - ASSERT_EQ(bsl::HASH_NOEXIST, names.find("Bob", 1)); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - - ASSERT_EQ(bsl::HASH_EXIST, names.find("Bob", 1)); - ASSERT_EQ(bsl::HASH_NOEXIST, names.find("Bob", 5)); - ASSERT_EQ(bsl::HASH_NOEXIST, names.find("Tod", 1)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_find_suite, case_const) -{ - //TODO - hash_type names; - const hash_type names_const1(names); - ASSERT_EQ(bsl::HASH_NOEXIST, names_const1.find("Bob", 1)); - - names.create(5); - const hash_type names_const2 = names; - ASSERT_EQ(bsl::HASH_NOEXIST, names_const2.find("Bob", 1)); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("White", 1, 1); - const hash_type names_const3 = names; - ASSERT_EQ(bsl::HASH_EXIST, names.find("Bob", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names.find("White", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names.find("Bob", 3)); - ASSERT_EQ(bsl::HASH_NOEXIST, names.find("Bob", 5)); - ASSERT_EQ(bsl::HASH_NOEXIST, names.find("Tod", 1)); -} - -/** - * @brief -**/ -class test_hash_multimap_set_suite : public ::testing::Test{ - protected: - test_hash_multimap_set_suite(){}; - virtual ~test_hash_multimap_set_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_set_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_set_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_set_suite, case_null) -{ - //TODO - hash_type names; - ASSERT_EQ( -1, names.set("Jack", 1) ); - ASSERT_EQ( -1, names.set("Jack", 1, 1) ); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_set_suite, case_unequal) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 2) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 3) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Jack", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Jones", 2) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Black", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("White", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("White", 3) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Li", 4) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Zhang", 1) ); - ASSERT_EQ( bsl::HASH_EXIST, names.set("Bob", 1) ); - ASSERT_EQ( bsl::HASH_EXIST, names.set("Li", 4) ); - - //print_hash(names.begin(), names.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_set_suite, case_equal) -{ - //TODO - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 2, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Bob", 3, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Jack", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Jones", 2, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Black", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("White", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("White", 3, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Li", 4, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Li", 4, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set("Zhang", 1, 1) ); - - //print_hash(names.begin(), names.end()); -} - -/** - * @brief -**/ -class test_hash_multimap_erase_suite : public ::testing::Test{ - protected: - test_hash_multimap_erase_suite(){}; - virtual ~test_hash_multimap_erase_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_erase_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_erase_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_erase_suite, case_null) -{ - hash_type names; - ASSERT_EQ(-1, names.erase("Bob")); -} - -TEST_F(test_hash_multimap_erase_suite, case_no_exist) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - ASSERT_EQ(0, names.erase("Bob")); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - //printf("BEFORE erase:"); - //print_hash(names.begin(), names.end()); - - ASSERT_EQ(0, names.erase("Bob1")); - ASSERT_EQ(0, names.erase("White1")); - - //printf("After erase:"); - //print_hash(names.begin(), names.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_erase_suite, case_exist) -{ - //TODO - hash_type names; - - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - //printf("BEFORE erase:"); - //print_hash(names.begin(), names.end()); - - ASSERT_EQ(5, names.erase("Bob")); - //printf("AFTER erase %s:", "Bob"); - //print_hash(names.begin(), names.end()); - - ASSERT_EQ(1, names.erase("Jack")); - ASSERT_EQ(1, names.erase("Jones")); - ASSERT_EQ(2, names.erase("White")); - ASSERT_EQ(1, names.erase("Black")); - ASSERT_EQ(2, names.erase("Li")); - ASSERT_EQ(1, names.erase("Zhang")); - - //printf("AFTER erase:"); - //print_hash(names.begin(), names.end()); -} - -/** - * @brief -**/ -class test_hash_multimap_erase_pair_suite : public ::testing::Test{ - protected: - test_hash_multimap_erase_pair_suite(){}; - virtual ~test_hash_multimap_erase_pair_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_erase_pair_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_erase_pair_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_erase_pair_suite, case_null) -{ - //TODO - hash_type names; - ASSERT_EQ(-1, names.erase_pair("Bob", 1)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_erase_pair_suite, case_exist) -{ - //TODO - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - //printf("BEFORE erase:"); - //print_hash(names.begin(), names.end()); - - ASSERT_EQ(2, names.erase_pair("Bob", 3)); - - //print_hash(names.begin(), names.end()); - - ASSERT_EQ(2, names.erase_pair("Bob", 1)); - ASSERT_EQ(1, names.erase_pair("White", 3)); - ASSERT_EQ(1, names.erase_pair("Bob", 2)); - ASSERT_EQ(1, names.erase_pair("Jack", 2)); - ASSERT_EQ(1, names.erase_pair("Jones", 2)); - ASSERT_EQ(1, names.erase_pair("Black", 1)); - ASSERT_EQ(1, names.erase_pair("White", 1)); - ASSERT_EQ(2, names.erase_pair("Li", 4)); - ASSERT_EQ(1, names.erase_pair("Zhang", 1)); - //printf("AFTER erase ALL:"); - //print_hash(names.begin(), names.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_erase_pair_suite, case_no_exist) -{ - //TODO - hash_type names; - - if(names.create(5) != 0) - printf("create hash_multimap error with size %d\n", 5); - - ASSERT_EQ(0, names.erase_pair("Bob", 3)); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - ASSERT_EQ(0, names.erase_pair("Bob1", 3)); - ASSERT_EQ(0, names.erase_pair("White", 5)); -} - -/** - * @brief -**/ -class test_hash_multimap_assign_suite : public ::testing::Test{ - protected: - test_hash_multimap_assign_suite(){}; - virtual ~test_hash_multimap_assign_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_assign_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_assign_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_assign_suite, case_from_stlmap) -{ - //TODO - multimap<_key, _value> st; - st.insert(_Pair("Bob", 1)); - st.insert(_Pair("Bob", 2)); - st.insert(_Pair("Bob", 3)); - st.insert(_Pair("Bob", 3)); - st.insert(_Pair("Bob", 3)); - st.insert(_Pair("Jack", 1)); - st.insert(_Pair("Jones", 1)); - st.insert(_Pair("Black", 1)); - st.insert(_Pair("Li", 1)); - st.insert(_Pair("Zhang", 1)); - st.insert(_Pair("Zhang", 4)); - st.insert(_Pair("White", 1)); - - hash_type names_assign; - ASSERT_EQ(0, names_assign.assign(st.begin(), st.end())); - //print_hash(names_assign.begin(), names_assign.end()); - - ASSERT_EQ(0, names_assign.assign(st.begin(), st.end(), 1)); - //print_hash(names_assign.begin(), names_assign.end()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_assign_suite, case_from_bsl_multimap) -{ - //TODO - hash_type names; - names.create(5); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - hash_type names_assign; - - //printf("**************************************************"); - - ASSERT_EQ(0, names_assign.assign(names.begin(), names.end())); - //print_hash(names_assign.begin(), names_assign.end()); - names_assign.destroy(); - - ASSERT_EQ(0, names_assign.assign(names.begin(), names.end(), 1)); - //print_hash(names_assign.begin(), names_assign.end()); - names_assign.destroy(); - - names_assign.create(5); - ASSERT_EQ(0, names_assign.assign(names.begin(), names.end())); - //print_hash(names_assign.begin(), names_assign.end()); - names_assign.destroy(); - - names.create(5); - ASSERT_EQ(0, names_assign.assign(names.begin(), names.end(), 1)); - //print_hash(names_assign.begin(), names_assign.end()); - names_assign.destroy(); -} - -/** - * @brief -**/ -class test_hash_multimap_serialization_suite : public ::testing::Test{ - protected: - test_hash_multimap_serialization_suite(){}; - virtual ~test_hash_multimap_serialization_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_serialization_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_serialization_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_serialization_suite, case_null) -{ - //TODO - hash_type names; - bsl::filestream fs; - - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_serialization_suite, case_empty) -{ - //TODO - hash_type names(5); - bsl::filestream fs; - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_serialization_suite, case_no_empty) -{ - hash_type names(5); - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - bsl::filestream fs; - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); -} - -/** - * @brief -**/ -class test_hash_multimap_deserialization_suite : public ::testing::Test{ - protected: - test_hash_multimap_deserialization_suite(){}; - virtual ~test_hash_multimap_deserialization_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_deserialization_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_deserialization_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_deserialization_suite, case_null) -{ - //TODO - hash_type names; - hash_type names_out; - bsl::filestream fs; - - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); - - fs.open("archivefile","r"); - bsl::binarchive ar1(fs); - ASSERT_EQ(-1, deserialization(ar1,names_out)); - fs.close(); - - //鍙嶅簭鍒楀寲涓紝浣跨敤鐨勬槸create鑰岄潪recreate锛屾墍浠ュ垽鏂嚭_bitems==0鍚庯紝鐩存帴璺冲嚭杩斿洖-1 - ASSERT_EQ(0, names_out.size()); - ASSERT_EQ(false, names_out.is_created()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_deserialization_suite, case_empty) -{ - hash_type names(5); - hash_type names_out; - - bsl::filestream fs; - - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); - - fs.open("archivefile","r"); - bsl::binarchive ar1(fs); - ASSERT_EQ(0, deserialization(ar1,names_out)); - fs.close(); - - ASSERT_EQ(0, names_out.size()); - ASSERT_EQ(true, names_out.is_created()); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_deserialization_suite, case_no_empty) -{ - hash_type names(5); - hash_type names_out; - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - bsl::filestream fs; - - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names); - fs.close(); - fs.open("archivefile","r"); - bsl::binarchive ar1(fs); - ASSERT_EQ(0, deserialization(ar1,names_out)); - fs.close(); - - ASSERT_EQ(13, names_out.size()); - - //printf("The source hash_multimap is: \n"); - //print_hash(names.begin(), names.end()); - //printf("The deserialization result is: \n"); - //print_hash(names_out.begin(), names_out.end()); -} - -/** - * @brief -**/ -class test_hash_multimap_clear_suite : public ::testing::Test{ - protected: - test_hash_multimap_clear_suite(){}; - virtual ~test_hash_multimap_clear_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_hash_multimap_clear_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_hash_multimap_clear_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_clear_suite, case_null) -{ - //TODO - hash_type names; - names.clear(); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_hash_multimap_clear_suite, case_normal) -{ - hash_type names(5); - - names.clear(); - - names.set("Bob", 1, 1); - names.set("Bob", 1, 1); - names.set("Bob", 2, 1); - names.set("Bob", 3, 1); - names.set("Bob", 3, 1); - names.set("Jack", 2, 1); - names.set("Jones", 2, 1); - names.set("Black", 1, 1); - names.set("White", 1, 1); - names.set("White", 3, 1); - names.set("Li", 4, 1); - names.set("Li", 4, 1); - names.set("Zhang", 1, 1); - - names.clear(); - - ASSERT_EQ(0, names.size()); -} - diff --git a/bsl/test/test_bsl_hashtable.cpp b/bsl/test/test_bsl_hashtable.cpp deleted file mode 100644 index abc4d7753e24d6fe8691fc991e6ad4aaf570e9cb..0000000000000000000000000000000000000000 --- a/bsl/test/test_bsl_hashtable.cpp +++ /dev/null @@ -1,1576 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef string _key; -typedef int _value; -typedef pair<_key, _value> _Pair; -typedef equal_to<_key> _Equl; -typedef bsl::bsl_sample_alloc, 256> _InnerAlloc; - -template -struct pair_first -{ - typedef typename _Pair::first_type type; - const type & operator () (const _Pair & __p) const - { - return __p.first; - } -}; - -typedef pair_first<_Pair> _get_key; - -struct hash_func -{ - size_t operator () (const std::string &__key) const - { - size_t key = 0; - for (size_t i=0; i<__key.size(); ++i) - { - key = (key<<8)+__key[i]; - } - return key; - } -}; - -typedef bsl::bsl_hashtable<_key, _Pair, hash_func, _Equl, _get_key, _InnerAlloc> hash_type; - -typedef hash_type::iterator _iterator; -typedef hash_type::const_iterator _const_iterator; -typedef hash_type::iterator_pair _iterator_pair; -typedef hash_type::const_iterator_pair _const_iterator_pair; - -void print_hash(hash_type::const_iterator begin, hash_type::const_iterator end) -{ - printf("The hash_multimap can be seen as follow:\n"); - for(hash_type::const_iterator ite = begin ; ite != end; ++ite) - { - cout << ite->first << " -> " << ite->second << endl; - } -}; - -//杩斿洖绗竴涓敭鍊间负key鐨勮凯浠e櫒 -_iterator begin_key(hash_type &ht, const _key &key) -{ - _iterator __first = ht.begin(); - while(__first != ht.end()) - { - if((*__first).first == key) - { - return __first; - } - ++__first; - } - return ht.end(); -}; - -//杩斿洖鏈鍚庝竴涓釜閿间负key鐨勮凯浠e櫒鐨刵ext -_iterator end_key(hash_type &ht, const _key &key) -{ - _iterator __end = ht.begin(); - while(__end != ht.end()) - { - if((*__end).first == key) - { - while(__end != ht.end() && (*__end).first == key) - { - ++__end; - } - break; - } - ++__end; - } - return __end; -}; - - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -/** - * @brief -**/ -class test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite(){}; - virtual ~test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite, case_name2) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_bsl_hashtable_iterator_suite, case_name3) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_iterator_operator_multiplies_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_operator_multiplies_suite(){}; - virtual ~test_bsl_hashtable_iterator_operator_multiplies_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_operator_multiplies_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_operator_multiplies_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_multiplies_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_iterator_operator_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_operator_suite(){}; - virtual ~test_bsl_hashtable_iterator_operator_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_operator._suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_operator._suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_iterator_operator_equalto_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_operator_equalto_suite(){}; - virtual ~test_bsl_hashtable_iterator_operator_equalto_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_operator_equalto_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_operator_equalto_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_equalto_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_iterator_operator_notequal_to_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_operator_notequal_to_suite(){}; - virtual ~test_bsl_hashtable_iterator_operator_notequal_to_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_operator_notequal_to_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_operator_notequal_to_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_notequal_to_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_iterator_operator_plusplus_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_iterator_operator_plusplus_suite(){}; - virtual ~test_bsl_hashtable_iterator_operator_plusplus_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_iterator_operator_plusplus_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_iterator_operator_plusplus_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_plusplus_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_iterator_operator_plusplus_suite, case_name2) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, case_name2) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, case_name3) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_bsl_hashtable_const_iterator_suite, case_name4) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_operator_multiplies_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_operator_multiplies_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_operator_multiplies_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_operator_multiplies_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_operator_multiplies_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_multiplies_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_operator_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_operator_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_operator_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_operator._suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_operator._suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_operator_equalto_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_operator_equalto_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_operator_equalto_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_operator_equalto_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_operator_equalto_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_equalto_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_operator_notequal_to_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_operator_notequal_to_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_operator_notequal_to_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_operator_notequal_to_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_operator_notequal_to_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_notequal_to_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_const_iterator_operator_plusplus_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_const_iterator_operator_plusplus_suite(){}; - virtual ~test_bsl_hashtable_const_iterator_operator_plusplus_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_const_iterator_operator_plusplus_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_const_iterator_operator_plusplus_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_plusplus_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_const_iterator_operator_plusplus_suite, case_name2) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_bsl_hashtable_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_bsl_hashtable_suite(){}; - virtual ~test_bsl_hashtable_bsl_hashtable_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_bsl_hashtable_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_bsl_hashtable_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_bsl_hashtable_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_bsl_hashtable_suite, case_name2) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_bsl_hashtable_suite, case_name3) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_operator_equal_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_operator_equal_suite(){}; - virtual ~test_bsl_hashtable_operator_equal_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_operator_equal_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_operator_equal_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_operator_equal_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_create_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_create_suite(){}; - virtual ~test_bsl_hashtable_create_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_create_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_create_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_create_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_is_created_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_is_created_suite(){}; - virtual ~test_bsl_hashtable_is_created_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_is_created_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_is_created_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_is_created_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_destroy_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_destroy_suite(){}; - virtual ~test_bsl_hashtable_destroy_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_destroy_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_destroy_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_destroy_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_begin_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_begin_suite(){}; - virtual ~test_bsl_hashtable_begin_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_begin_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_begin_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_begin_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_begin_suite, case_name2) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_end_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_end_suite(){}; - virtual ~test_bsl_hashtable_end_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_end_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_end_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_end_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_end_suite, case_name2) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_size_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_size_suite(){}; - virtual ~test_bsl_hashtable_size_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_size_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_size_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_size_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_count_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_count_suite(){}; - virtual ~test_bsl_hashtable_count_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_count_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_count_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_count_suite, case_null) -{ - //TODO - hash_type names; - ASSERT_EQ(0, names.count(hash_func()("Bob"), "Bob")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_count_suite, test_count__EXIST) -{ - //TODO - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(4, names.count(hash_func()("Bob"), "Bob")); - ASSERT_EQ(1, names.count(hash_func()("Jack"), "Jack")); - ASSERT_EQ(1, names.count(hash_func()("Jones"), "Jones")); - ASSERT_EQ(1, names.count(hash_func()("Black"), "Black")); - ASSERT_EQ(1, names.count(hash_func()("White"), "White")); - ASSERT_EQ(2, names.count(hash_func()("Li"), "Li")); - ASSERT_EQ(1, names.count(hash_func()("Zhang"), "Zhang")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_count_suite, test_count__NOEXIST) -{ - //TODO - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - ASSERT_EQ(0, names.count(hash_func()("Jack"), "Jack")); - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(0, names.count(hash_func()("Jack1"), "Jack1")); - ASSERT_EQ(0, names.count(hash_func()("White1"), "White1")); -} - -/** - * @brief -**/ -class test_bsl_hashtable_assign_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_assign_suite(){}; - virtual ~test_bsl_hashtable_assign_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_assign_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_assign_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_assign_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_assign_multimap_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_assign_multimap_suite(){}; - virtual ~test_bsl_hashtable_assign_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_assign_multimap_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_assign_multimap_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_assign_multimap_suite, case_name_from_stlmap) -{ - //TODO - multimap<_key, _value> st; - st.insert(_Pair("Bob", 1)); - st.insert(_Pair("Bob", 2)); - st.insert(_Pair("Bob", 3)); - st.insert(_Pair("Jack", 1)); - st.insert(_Pair("Jones", 1)); - st.insert(_Pair("Black", 1)); - st.insert(_Pair("Li", 1)); - st.insert(_Pair("Zhang", 1)); - st.insert(_Pair("Zhang", 4)); - st.insert(_Pair("White", 1)); - - hash_type names_assign; - ASSERT_EQ(0, names_assign.assign_multimap(st.begin(), st.end())); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_assign_multimap_suite, case_name_unequal_from_bsl_multimap) -{ - hash_type names_equal; - names_equal.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_equal.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_equal.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_equal.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_equal.set_multimap(hash_func()("White"), "White", 1, 1); - names_equal.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_equal.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_equal.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - hash_type names_assign; - ASSERT_EQ(0, names_assign.assign_multimap(names_equal.begin(), names_equal.end())); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_assign_multimap_suite, case_name_equal_from_bsl_multimap) -{ - hash_type names_equal; - - names_equal.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_equal.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_equal.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_equal.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_equal.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_equal.set_multimap(hash_func()("White"), "White", 1, 1); - names_equal.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_equal.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_equal.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - hash_type names_assign; - ASSERT_EQ(0, names_assign.assign_multimap(names_equal.begin(), names_equal.end(), 1)); -} - -/** - * @brief -**/ -class test_bsl_hashtable_find_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_find_suite(){}; - virtual ~test_bsl_hashtable_find_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_find_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_find_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_suite, case_name1) -{ - //TODO -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_suite, case_name2) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_find_pair_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_find_pair_suite(){}; - virtual ~test_bsl_hashtable_find_pair_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_find_pair_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_find_pair_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_pair_suite, case_null) -{ - //TODO - hash_type names_find; - ASSERT_EQ(-1, names_find.find_pair(hash_func()("Li"), "Li", 2)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_pair_suite, case_exist) -{ - //TODO - hash_type names_find; - if(names_find.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names_find.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_find.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_find.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_find.set_multimap(hash_func()("White"), "White", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_find.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Bob"), "Bob", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Bob"), "Bob", 2)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Bob"), "Bob", 3)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Jack"), "Jack", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Jones"), "Jones", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Black"), "Black", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("White"), "White", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Li"), "Li", 1)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Li"), "Li", 2)); - ASSERT_EQ(bsl::HASH_EXIST, names_find.find_pair(hash_func()("Zhang"), "Zhang", 1)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_pair_suite, case_no_exist) -{ - hash_type names_find; - if(names_find.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ(bsl::HASH_NOEXIST, names_find.find_pair(hash_func()("Bob"), "Bob", 1)); - names_find.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_find.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_find.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_find.set_multimap(hash_func()("White"), "White", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_find.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - ASSERT_EQ(bsl::HASH_NOEXIST, names_find.find_pair(hash_func()("Bob"), "Bob", 4)); - ASSERT_EQ(bsl::HASH_NOEXIST, names_find.find_pair(hash_func()("Jack"), "Jack", 0)); - ASSERT_EQ(bsl::HASH_NOEXIST, names_find.find_pair(hash_func()("Li"), "Li", 5)); - ASSERT_EQ(bsl::HASH_NOEXIST, names_find.find_pair(hash_func()("Li1"), "Li1", 1)); -} - -/** - * @brief -**/ -class test_bsl_hashtable_find_multimap_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_find_multimap_suite(){}; - virtual ~test_bsl_hashtable_find_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_find_multimap_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_find_multimap_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_multimap_suite, case_null) -{ - //TODO - hash_type names_find; - - ASSERT_EQ(_iterator_pair(names_find.end(),names_find.end()), names_find.find_multimap(hash_func()("Li"), "Li")); - - if(names_find.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ(_iterator_pair(names_find.end(),names_find.end()), names_find.find_multimap(hash_func()("Li"), "Li")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_multimap_suite, case_noexist) -{ - //TODO - hash_type names_find; - if(names_find.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - ASSERT_EQ(_iterator_pair(names_find.end(),names_find.end()), names_find.find_multimap(hash_func()("Li"), "Li")); - - names_find.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_find.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_find.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_find.set_multimap(hash_func()("White"), "White", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_find.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(_iterator_pair(names_find.end(),names_find.end()), names_find.find_multimap(hash_func()("Li1"), "Li1")); - ASSERT_EQ(_iterator_pair(names_find.end(),names_find.end()), names_find.find_multimap(hash_func()("Boc"), "Boc")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_find_multimap_suite, case_exist) -{ - hash_type names_find; - if(names_find.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names_find.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_find.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_find.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_find.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_find.set_multimap(hash_func()("White"), "White", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_find.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_find.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - //鎵嬪伐鏌ユ壘range - _iterator __begin; - _iterator __end; - _iterator_pair __ite_pair; - - print_hash(names_find.begin(), names_find.end()); - - printf("begin:\n"); - __begin = begin_key(names_find, "Bob"); - printf("end:\n"); - __end = end_key(names_find, "Bob"); - printf("equal:\n"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Bob"), "Bob")); - - printf("begin:\n"); - __begin = begin_key(names_find, "Jack"); - printf("end:\n"); - __end = end_key(names_find, "Jack"); - printf("equal:\n"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Jack"), "Jack")); - - __begin = begin_key(names_find, "Jones"); - __end = end_key(names_find, "Jones"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Jones"), "Jones")); - - __begin = begin_key(names_find, "Black"); - __end = end_key(names_find, "Black"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Black"), "Black")); - - __begin = begin_key(names_find, "White"); - __end = end_key(names_find, "White"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("White"), "White")); - - __begin = begin_key(names_find, "Li"); - __end = end_key(names_find, "Li"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Li"), "Li")); - - __begin = begin_key(names_find, "Zhang"); - __end = end_key(names_find, "Zhang"); - EXPECT_EQ(_iterator_pair(__begin, __end), names_find.find_multimap(hash_func()("Zhang"), "Zhang")); -} - -/** - * @brief -**/ -class test_bsl_hashtable_set_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_set_suite(){}; - virtual ~test_bsl_hashtable_set_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_set_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_set_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_set_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_set_map_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_set_map_suite(){}; - virtual ~test_bsl_hashtable_set_map_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_set_map_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_set_map_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_set_map_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_set_multimap_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_set_multimap_suite(){}; - virtual ~test_bsl_hashtable_set_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_set_multimap_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_set_multimap_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_set_multimap_suite, case_null) -{ - //TODO - hash_type names; - ASSERT_EQ( -1, names.set_multimap(hash_func()("Jack"), "Jack", 1) ); - ASSERT_EQ( -1, names.set_multimap(hash_func()("Jack"), "Jack", 1, 1) ); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_set_multimap_suite, case_unequal) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Bob"), "Bob", 1) ); - ASSERT_EQ( bsl::HASH_EXIST, names.set_multimap(hash_func()("Bob"), "Bob", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Bob"), "Bob", 2) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Jack"), "Jack", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Jones"), "Jones", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Black"), "Black", 1) ); - ASSERT_EQ( bsl::HASH_EXIST, names.set_multimap(hash_func()("Black"), "Black", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("White"), "White", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("White"), "White", 2) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Li"), "Li", 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Zhang"), "Zhang", 1) ); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_set_multimap_suite, case_equal) -{ - hash_type names; - if(names.create(5) != 0) - { - - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Bob"), "Bob", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Bob"), "Bob", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Bob"), "Bob", 2, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Jack"), "Jack", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Jones"), "Jones", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Black"), "Black", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Black"), "Black", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("White"), "White", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("White"), "White", 2, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Li"), "Li", 1, 1) ); - ASSERT_EQ( bsl::HASH_INSERT_SEC, names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1) ); -} - -/** - * @brief -**/ -class test_bsl_hashtable_erase_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_erase_suite(){}; - virtual ~test_bsl_hashtable_erase_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_erase_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_erase_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_erase_multimap_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_erase_multimap_suite(){}; - virtual ~test_bsl_hashtable_erase_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_erase_multimap_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_erase_multimap_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_multimap_suite, case_null) -{ - //TODO - hash_type names; - ASSERT_EQ(-1, names.erase_multimap(hash_func()("Bob"), "Bob")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_multimap_suite, case_exist) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(4, names.erase_multimap(hash_func()("Bob"), "Bob")); - ASSERT_EQ(1, names.erase_multimap(hash_func()("Jack"), "Jack")); - ASSERT_EQ(1, names.erase_multimap(hash_func()("Jones"), "Jones")); - ASSERT_EQ(1, names.erase_multimap(hash_func()("Black"), "Black")); - ASSERT_EQ(1, names.erase_multimap(hash_func()("White"), "White")); - ASSERT_EQ(2, names.erase_multimap(hash_func()("Li"), "Li")); - ASSERT_EQ(1, names.erase_multimap(hash_func()("Zhang"), "Zhang")); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_multimap_suite, case_no_exist) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(0, names.erase_multimap(hash_func()("Bob1"), "Bob1")); - ASSERT_EQ(0, names.erase_multimap(hash_func()("Li1"), "Li1")); -} - -/** - * @brief -**/ -class test_bsl_hashtable_erase_pair_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_erase_pair_suite(){}; - virtual ~test_bsl_hashtable_erase_pair_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_erase_pair_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_erase_pair_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_pair_suite, case_null) -{ - hash_type names; - ASSERT_EQ(-1, names.erase_pair(hash_func()("Bob"), "Bob", 1)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_pair_suite, case_exist) -{ - //TODO - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(1 ,names.erase_pair(hash_func()("Bob"), "Bob", 2)); - ASSERT_EQ(1 ,names.erase_pair(hash_func()("Zhang"), "Zhang", 1)); - ASSERT_EQ(1 ,names.erase_pair(hash_func()("Black"), "Black", 1)); - ASSERT_EQ(2 ,names.erase_pair(hash_func()("Bob"), "Bob", 3)); - ASSERT_EQ(1 ,names.erase_pair(hash_func()("Li"), "Li", 2)); -} - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_erase_pair_suite, case_no_exist) -{ - hash_type names; - if(names.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - ASSERT_EQ(0 ,names.erase_pair(hash_func()("Bob"), "Bob", 1)); - - names.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names.set_multimap(hash_func()("Black"), "Black", 1, 1); - names.set_multimap(hash_func()("White"), "White", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 1, 1); - names.set_multimap(hash_func()("Li"), "Li", 2, 1); - names.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - ASSERT_EQ(0 ,names.erase_pair(hash_func()("Bob"), "Bob", 4)); - ASSERT_EQ(0 ,names.erase_pair(hash_func()("Bob1"), "Bob1", 2)); -} - -/** - * @brief -**/ -class test_bsl_hashtable_serialization_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_serialization_suite(){}; - virtual ~test_bsl_hashtable_serialization_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_serialization_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_serialization_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_serialization_suite, case_name1) -{ - //TODO -} - -/** - * @brief -**/ -class test_bsl_hashtable_deserialization_multimap_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_deserialization_multimap_suite(){}; - virtual ~test_bsl_hashtable_deserialization_multimap_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_deserialization_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_deserialization_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_deserialization_multimap_suite, case_null) -{ - //TODO - bsl::filestream fs; - - hash_type names_in; - hash_type names_out; - - fs.open("archivefile","w+"); - fs.close(); - - fs.open("archivefile","r"); - bsl::binarchive ar0(fs); - ASSERT_EQ(-1, names_out.deserialization_multimap(ar0)); - fs.close(); - - if(names_in.create(5) != 0) - { - printf("create hash_multimap error with size %d\n", 5); - } - names_in.set_multimap(hash_func()("Bob"), "Bob", 1, 1); - names_in.set_multimap(hash_func()("Bob"), "Bob", 2, 1); - names_in.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_in.set_multimap(hash_func()("Bob"), "Bob", 3, 1); - names_in.set_multimap(hash_func()("Jack"), "Jack", 1, 1); - names_in.set_multimap(hash_func()("Jones"), "Jones", 1, 1); - names_in.set_multimap(hash_func()("Black"), "Black", 1, 1); - names_in.set_multimap(hash_func()("White"), "White", 1, 1); - names_in.set_multimap(hash_func()("Li"), "Li", 1, 1); - names_in.set_multimap(hash_func()("Li"), "Li", 2, 1); - names_in.set_multimap(hash_func()("Zhang"), "Zhang", 1, 1); - - cout << "Input:\n"; - print_hash(names_in.begin(),names_in.end()); - - fs.open("archivefile","w+"); - bsl::binarchive ar(fs); - serialization(ar,names_in); - fs.close(); - - fs.open("archivefile","r"); - bsl::binarchive ar1(fs); - //deserialization(ar1,names_out); - ASSERT_EQ(0, names_out.deserialization_multimap(ar1)); - fs.close(); - - cout << "Output:\n"; - print_hash(names_out.begin(),names_out.end()); - -} - -/** - * @brief -**/ -class test_bsl_hashtable_clear_suite : public ::testing::Test{ - protected: - test_bsl_hashtable_clear_suite(){}; - virtual ~test_bsl_hashtable_clear_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bsl_hashtable_clear_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bsl_hashtable_clear_suite, *) - }; -}; - -/** - * @brief - * @begin_version 1.1.15.0 -**/ -TEST_F(test_bsl_hashtable_clear_suite, case_name1) -{ - //TODO -} - diff --git a/bsl/unittest/Makefile b/bsl/unittest/Makefile deleted file mode 100644 index dae970b78605c6cf6c3926605b03d64ace751be0..0000000000000000000000000000000000000000 --- a/bsl/unittest/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -WORKROOT=../../../ -CXX = $(WORKROOT)/libsrc/bsl/cxxtest - -MARCS= -ifeq ($(MAC),64) - LIBPATH=$(WORKROOT)lib2-64 -else - LIBPATH=$(WORKROOT)lib2 -endif - -PUBLIC=$(WORKROOT)/public -ULLIB=$(LIBPATH)/ullib/ -NSHEAD=$(PUBLIC)/nshead/ -DICT=$(LIBPATH)/dict/ -BSL=../output/ - -XDATA=*.data phash.dat.1 *.dat data 1 failtest -INCLUDE= -I./ -I$(CXX) -I$(ULLIB)/include -I$(NSHEAD) -I$(DICT)/include/ -I../../ -#XFLAG = -fsigned-char -Wall -W -pipe -Wno-unused-parameter -g -DBSL_DEBUG_MOD -#XXFLAG = -fsigned-char -Wall -W -pipe -Wno-unused-parameter -g -fprofile-arcs -ftest-coverage -XFLAG = -fsigned-char -Wall -W -g -D_XOPEN_SOURE=500 -D_GNU_SOURCE -ftemplate-depth-128 -g -fPIC -fsigned-char -Wall -Winline -pipe - #-Wreturn-type \ - #-Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -finline-functions \ - #-Wshadow -LIB= -L$(ULLIB)/lib -L$(NSHEAD) -L$(DICT)/lib -L$(BSL)/lib -lbsl -luldict -lcrypto -lcrypt -lullib -lpthread -lm - -CFLAG = $(XFLAG) -D_REENTRANT -D_FILTER -DNDEBUG $(INCLUDE) -CPPFLAG = $(XFLAG) -D_REENTRANT -D_FILTER $(INCLUDE) -rdynamic - -CXXTEST = $(CXX)/cxxtestgen.pl -OUTPUT = --error-printer --have-std --have-eh - -CC = gcc -CPP = g++ -PERL = perl -PY = python - -ALLTESTS=$(wildcard *.h) -CPPFILE=$(ALLTESTS:.h=.cpp) -EXE=$(basename $(ALLTESTS)) - -#$(CPPFILE) : $(ALLTESTS) -.h.cpp : - $(CXXTEST) $(OUTPUT) -o $*.cpp $*.h - - -all : $(EXE) - -$(EXE) : $(CPPFILE) - $(CPP) $(CPPFLAG) -o $@ $@.cpp $(LIB) - -#========================================================================= -.PHONY : clean all test - -clean : - rm -f $(CPPFILE) $(EXE) $(XDATA) -test : $(EXE) - @failed=0; - @for exe in $(EXE) ; do echo; echo -n doing $$exe ">>>>>>>>";echo;echo;\ - ./$$exe ; \ - echo done ; \ - echo ;\ - done; - -%.h: %.py - ./$^ > $@ - -bsl_test_string: bsl_test_string.h bsl_test_string.hpp $(BSL)/include/bsl/containers/string/bsl_string.h - -bsl_test_string_pool: bsl_test_string_pool.h $(BSL)/include/bsl/containers/string/bsl_string.h $(BSL)/include/bsl/pool/bsl_debugpool.h - -bsl_test_shared_buffer: bsl_test_shared_buffer.h $(BSL)/include/bsl/exception/bsl_shared_buffer.h - -bsl_test_auto_buffer: bsl_test_auto_buffer.h $(BSL)/include/bsl/AutoBuffer.h - -bsl_test_exception: bsl_test_exception.h $(BSL)/include/bsl/exception/bsl_exception.h - -bsl_test_bin_buffer: bsl_test_bin_buffer.h $(BSL)/include/bsl/BinBuffer.h - - diff --git a/bsl/unittest/bsl_test_alloc.h b/bsl/unittest/bsl_test_alloc.h deleted file mode 100644 index b1c4b18b08bf017d9cca08ce352339693f914100..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_alloc.h +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_alloc.h,v 1.2 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_alloc.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/22 17:38:52 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_ALLOC_H_ -#define __BSL_TEST_ALLOC_H_ -#include -#include -#include - - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - - - -template -bool test_normal() -{ - typedef typename _Alloc::value_type value_type; - typedef typename _Alloc::pointer pointer; - typedef std::vector vec_t; - typedef std::vector vecp_t; - - _Alloc alloc; - __XASSERT2(alloc.create() == 0); - vec_t vecs; - vecp_t vecp; - int loop = 100000; - for (int i=0; i intalloc_t; - void test_normal_int(void) { - TSM_ASSERT (0, test_normal()); - } - - typedef bsl::bsl_alloc dballoc_t; - void test_normal_double() { - TSM_ASSERT (0, test_normal()); - } - - typedef bsl::bsl_sample_alloc intsalloc_t; - void test_salloc_int(void) { - TSM_ASSERT (0, test_normal()); - } - - typedef bsl::bsl_sample_alloc dbsalloc_t; - void test_salloc_double() { - TSM_ASSERT (0, test_normal()); - } - - typedef bsl::bsl_cpsalloc intcpalloc_t; - void test_cpalloc_int() { - TSM_ASSERT (0, test_normal()); - } - - typedef bsl::bsl_cpsalloc dbcpalloc_t; - void test_cpalloc_double() { - TSM_ASSERT (0, test_normal()); - } -}; - - - - -#endif //__BSL_TEST_ALLOC_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_archive.h b/bsl/unittest/bsl_test_archive.h deleted file mode 100644 index e5cf6dca5411985296efac6e6cc03493205a510b..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_archive.h +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_archive.h,v 1.2 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_archive.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/12 16:37:59 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_ARCHIVE_H_ -#define __BSL_TEST_ARCHIVE_H_ - - -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - -bool test_archive(void) -{ - bsl::filestream fs; - fs.open ("test_archive.dat", "w"); - bsl::binarchive ar(fs); - fs.start_trans(); - const char *ptr = "hello world"; - ar.push(ptr, strlen(ptr)); - fs.drop_trans(true); - fs.close(); - return true; -} - -class bsl_test_archive : public CxxTest::TestSuite -{ -public: - void test_archive_ (void) { - TSM_ASSERT(0, test_archive()); - } -}; - - - - - - - - - - - - - - - - -#endif //__BSL_TEST_ARCHIVE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_auto_buffer.h b/bsl/unittest/bsl_test_auto_buffer.h deleted file mode 100644 index c5272b31cb2cbc1d73c9fd56c3a37478578f84ee..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_auto_buffer.h +++ /dev/null @@ -1,42833 +0,0 @@ - -#ifndef __BSL_TEST_AUTO_BUFFER_H_ -#define __BSL_TEST_AUTO_BUFFER_H_ -#include -#include -#include -#include -#include -#define see(x) do{ std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_b(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_c(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_d(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_e(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_f(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_g(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_h(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_i(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_j(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ba(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_be(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bf(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bi(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ca(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ce(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cf(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ch(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ci(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_da(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_db(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_de(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_df(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_di(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ea(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ec(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ed(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ee(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ef(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ei(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ej(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fa(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fe(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ff(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fi(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ga(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ge(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gf(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gi(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_gj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ha(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hb(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hc(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hd(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_he(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hf(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hg(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hh(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hi(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_hj(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ia(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ib(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ic(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_id(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ie(){ - bsl::AutoBuffer buf(0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_if(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ig(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ih(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ii(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ij(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ja(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_je(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ji(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_jj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_baa(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bab(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bac(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bad(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bae(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_baf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bag(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bah(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bai(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_baj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bba(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbe(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbi(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bbj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bca(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bce(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bch(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bci(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bcj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bda(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bde(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdi(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bdj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bea(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_beb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bec(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bed(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bee(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bef(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_beg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_beh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bei(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bej(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfa(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfe(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bff(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfi(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bfj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bga(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgb(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgc(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgd(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bge(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgf(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgg(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgh(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgi(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bgj(){ - bsl::AutoBuffer buf(1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bha(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhe(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhh(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhi(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bhj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bia(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bib(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bic(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bid(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bie(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bif(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_big(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bih(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bii(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bij(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bja(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bje(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjh(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bji(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_bjj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_caa(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cab(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cac(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cad(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cae(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_caf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cag(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cah(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cai(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_caj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cba(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbe(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbh(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbi(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cbj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cca(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cce(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cch(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cci(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ccj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cda(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cde(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdf(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdh(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdi(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cdj(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cea(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ceb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cec(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ced(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cee(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cef(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ceg(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ceh(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cei(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cej(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfa(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfb(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfc(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfd(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfe(){ - bsl::AutoBuffer buf(100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cff(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cfj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cga(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cge(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cgj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cha(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_che(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_chj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cia(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cib(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cic(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cid(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cie(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cif(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cig(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cih(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cii(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cij(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cja(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cje(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cji(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_cjj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_daa(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dab(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dac(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dad(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dae(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_daf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dag(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dah(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dai(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_daj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dba(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dbj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dca(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dce(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dch(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dci(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dcj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dda(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dde(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ddj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dea(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_deb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dec(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ded(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dee(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_def(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_deg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_deh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dei(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dej(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfa(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dff(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dfj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dga(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dge(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dgj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dha(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dhj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dia(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dib(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dic(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_did(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_die(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dif(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dig(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dih(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dii(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dij(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dja(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dje(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_dji(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_djj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eaa(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eab(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eac(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ead(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eae(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eaf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eag(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eah(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eai(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eaj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eba(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ebj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eca(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ece(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ech(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eci(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ecj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eda(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ede(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_edj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eea(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eeb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eec(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eed(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eee(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eef(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eeg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eeh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eei(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eej(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efa(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eff(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_efj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ega(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ege(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_egj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eha(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehe(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehi(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ehj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eia(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eib(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eic(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eid(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eie(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eif(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eig(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eih(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eii(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eij(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eja(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejb(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejc(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejd(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eje(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejg(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejh(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_eji(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_ejj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_faa(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fab(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fac(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fad(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fae(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_faf(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fag(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fah(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fai(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_faj(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } - - - void test_single_fba(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fbj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fca(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fce(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fch(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fci(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fcj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fda(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fde(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fdj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fea(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_feb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fec(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fed(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fee(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fef(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_feg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_feh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fei(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fej(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffa(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fff(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ffj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fga(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fge(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fgj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fha(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fhj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fia(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fib(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fic(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fid(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fie(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fif(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fig(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fih(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fii(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fij(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fja(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fje(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,0); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 0 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fji(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_fjj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gaa(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gab(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gac(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gad(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gae(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gaf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gag(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gah(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gai(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gaj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gba(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gbj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gca(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gce(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gch(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gci(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gcj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gda(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gde(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gdj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gea(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_geb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gec(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ged(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gee(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gef(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_geg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_geh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gei(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gej(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfa(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gff(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gfj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gga(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gge(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ggj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gha(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_ghj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,1); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 1 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gia(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value); - const char * result = "true"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gib(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gic(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf.push(value).push(value).push(value); - const char * result = "truetruetrue"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gid(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = true; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gie(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value); - const char * result = "false"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gif(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gig(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf.push(value).push(value).push(value); - const char * result = "falsefalsefalse"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gih(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bool value = false; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gii(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gij(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gja(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - char value = 'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gje(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gji(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf.push(value).push(value).push(value); - const char * result = "123123123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_gjj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = 123; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_haa(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value); - const char * result = "-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hab(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hac(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf.push(value).push(value).push(value); - const char * result = "-456-456-456"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_had(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - int value = -456; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hae(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value); - const char * result = "0"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_haf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hag(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf.push(value).push(value).push(value); - const char * result = "000"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hah(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = 0; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hai(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value); - const char * result = "-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_haj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hba(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf.push(value).push(value).push(value); - const char * result = "-1e+100-1e+100-1e+100"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - double value = -1e+100; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value); - const char * result = """"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf.push(value).push(value).push(value); - const char * result = """"""""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = ""; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value); - const char * result = "hello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf.push(value).push(value).push(value); - const char * result = "hello worldhello worldhello world"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hbj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "hello world"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hca(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value); - const char * result = "哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf.push(value).push(value).push(value); - const char * result = "哈哈哈哈哈哈"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const char * value = "哈哈"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hce(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value); - const char * result = "c"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf.push(value).push(value).push(value); - const char * result = "ccc"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hch(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - wchar_t value = L'c'; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hci(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value); - const char * result = "hello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hcj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hda(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf.push(value).push(value).push(value); - const char * result = "hellohellohello"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - const wchar_t * value = L"hello"; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value); - const char * result = "99"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hde(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf.push(value).push(value).push(value); - const char * result = "999999"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdf(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - unsigned char value = 99; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value); - const char * result = "127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf.push(value).push(value).push(value); - const char * result = "127127127"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hdj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = 127; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hea(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value); - const char * result = "-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_heb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hec(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf.push(value).push(value).push(value); - const char * result = "-128-128-128"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hed(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - signed char value = -128; - buf<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hee(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hef(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ).pushf( "abc[%d]\n%s", 123, "acumon" ); - const char * result = "abc[123]\nacumonabc[123]\nacumonabc[123]\nacumon"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_heg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 3, 'a'); - const char * result = "aaa"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_heh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 0, 'a'); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hei(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 4 ); - const char * result = "auto"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hej(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "auto_buffer", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfa(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "", 0 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( "abc", 2 ); - const char * result = "ab"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( (const char *)(NULL), 100 ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfe(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf << char(0); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hff(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfg(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 10, char(0) ); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfh(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push( 123 ); - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfi(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.clear(); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hfj(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hga(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hgb(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hgc(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf1.push(123); - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hgd(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - bsl::AutoBuffer buf1; - buf.transfer_from(buf1); - buf1.push(123); - buf.swap(buf1); - buf1.transfer_from(buf); - const char * result = ""; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - - void test_single_hge(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,100); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( 100 != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - - buf.push(123); - bsl::AutoBuffer buf1; - buf1.transfer_from(buf); - buf.push(123); - const char * result = "123"; - - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } - - -}; -#endif //__BSL_TEST_AUTO_BUFFER_H_ - diff --git a/bsl/unittest/bsl_test_auto_buffer.py b/bsl/unittest/bsl_test_auto_buffer.py deleted file mode 100755 index ab4d3f2fd01bda748dca5af0ba214e34c983eff4..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_auto_buffer.py +++ /dev/null @@ -1,427 +0,0 @@ -#!/usr/bin/env python -# vim: set fileencoding=utf-8 -# bsl_test_auto_buffer.h generator -HEADER = """ -#ifndef __BSL_TEST_AUTO_BUFFER_H_ -#define __BSL_TEST_AUTO_BUFFER_H_ -#include -#include -#include -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } -""" - -TEST_TEMPLATE2 = """ - void test_single_%(func_name)s(){ - // init pool - bsl::xcompool g_xcompool; - g_xcompool.create(); - bsl::AutoBuffer buf(g_xcompool,%(buf_size)d); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( %(buf_size)d != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - -%(operation)s - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - - } -""" - - -TEST_TEMPLATE3 = """ - void test_single_%(func_name)s(){ - // init pool - g_xmempool.create(g_membuf,sizeof(g_membuf)); - bsl::AutoBuffer buf(g_xmempool,%(buf_size)d); - TS_ASSERT( buf.empty() ); - TS_ASSERT( !buf.truncated() ); - - if ( %(buf_size)d != 0 ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - -%(operation)s - - - if ( 0 != strcmp( result, buf.c_str() ) ){ - see(buf.capacity()); - see(buf.size()); - see(strlen(result)); - see(buf.c_str()); - see(result); - } - TS_ASSERT( buf.size() == strlen(result) ); - TS_ASSERT( buf.capacity() >= buf.size() ); - TS_ASSERT( 0 == strcmp( buf.c_str(), result ) ); - TS_ASSERT( !buf.truncated() ); - - if ( buf.size() != 0 ){ - TS_ASSERT( !buf.empty() ); - }else{ - TS_ASSERT( buf.empty() ); - } - - if ( buf.size() != buf.capacity() ){ - TS_ASSERT( !buf.full() ); - }else{ - TS_ASSERT( buf.full() ); - } - - size_t old_capacity = buf.capacity(); - buf.clear(); - TS_ASSERT( buf.size() == 0 ); - TS_ASSERT( old_capacity == buf.capacity() ); - TS_ASSERT( buf.empty() ); - if ( old_capacity ){ - TS_ASSERT( !buf.full() ); - } - g_xmempool.clear(); - - } -""" - - -OPERATION_TEMPLATES = [ -""" - %(type)s value = %(literal)s; - buf.push(value); - const char * result = "%(string)s"; -""", - -""" - %(type)s value = %(literal)s; - buf< 2 and data[2] or data[1] - for operation_tmpl in OPERATION_TEMPLATES: - operation = operation_tmpl % vars() - func_name = id_iter.next() - print TEST_TEMPLATE % vars() - - for operation in SPECIAL_OPERATIONS: - func_name = id_iter.next() - print TEST_TEMPLATE % vars() - - for buf_size in [0, 1, 100]: - for data in TEST_DATA: - type, literal, string = data[0], data[1], len(data) > 2 and data[2] or data[1] - for operation_tmpl in OPERATION_TEMPLATES: - operation = operation_tmpl % vars() - func_name = id_iter.next() - print TEST_TEMPLATE2 % vars() - - for operation in SPECIAL_OPERATIONS: - func_name = id_iter.next() - print TEST_TEMPLATE2 % vars() - - - for buf_size in [0, 1, 100]: - for data in TEST_DATA: - type, literal, string = data[0], data[1], len(data) > 2 and data[2] or data[1] - for operation_tmpl in OPERATION_TEMPLATES: - operation = operation_tmpl % vars() - func_name = id_iter.next() - print TEST_TEMPLATE3 % vars() - - for operation in SPECIAL_OPERATIONS: - func_name = id_iter.next() - print TEST_TEMPLATE3 % vars() - - - print FOOTER diff --git a/bsl/unittest/bsl_test_bin_buffer.h b/bsl/unittest/bsl_test_bin_buffer.h deleted file mode 100644 index bc09f02cb5b119979564738a93c60b71f2eecfdc..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_bin_buffer.h +++ /dev/null @@ -1,689 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * $Id$ - * - **************************************************************************/ - - - -/** - * @file bsl_test_bin_buffer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/08/17 11:29:41 - * @version $Revision$ - * @brief - * - **/ - -#include -#include - -#include "cxxtest/TestSuite.h" - -#include -#include - -class test_BinBuffer_main: public CxxTest::TestSuite -{ - - template - Tp get_bin_value(const char * cstr, int len) { - Tp val; - char* ch = (char *)&val; - for (int i = 0; i < len; i ++) { - ch[i] = cstr[i]; - } - return val; - } - - template - Tp min(Tp a,Tp b) { - return a < b ? a : b; - } - - template - Tp max(Tp a,Tp b) { - return a > b ? a : b; - } - void get_str(char * str,const char* cstr,size_t len) { - size_t i; - for (i = 0; i < len; i ++) { - str[i] = cstr[i]; - } - str[i] = '\0'; - } - - -public: - test_BinBuffer_main() { - printf("begin\n"); - } - void test_special() - { - bsl::xcompool g_xcompool; - g_xcompool.create(); - // push char - { - char str[100]; - bsl::BinBuffer buf(g_xcompool,0); - buf.push('a'); - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"a") ); - buf.push('a'); - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"aa") ); - buf.push("aaa",3); - TS_ASSERT( 0 == strcmp(buf.data(),"aaaaa") ); - buf.push('\0'); - TS_ASSERT( buf.size() == 6 ); - buf.push('\0').push('\0'); - TS_ASSERT( buf.size() == 8 ); - } - // push signed char - { - bsl::BinBuffer buf(g_xcompool,10); - signed char sc = 12; - buf.push(sc); - signed char sc2 = get_bin_value(buf.data(),sizeof(signed char)); - TS_ASSERT( sc == sc2 ); - sc = 15; - buf.push(sc); - sc2 = get_bin_value(buf.data()+min(buf.get_pack(),sizeof(signed char)),sizeof(signed char)); - TS_ASSERT( sc == sc2 ); - //printf("=%hhd=\n",sc); - //printf("=%d=\n",buf.size()); - } - // push unsigned char - { - bsl::BinBuffer buf(g_xcompool,10); - unsigned char sc = 12; - buf.push(sc); - unsigned char sc2 = get_bin_value(buf.data(),sizeof(unsigned char)); - TS_ASSERT( sc == sc2 ); - sc = 15; - buf.push(sc); - sc2 = get_bin_value(buf.data()+min(buf.get_pack(),sizeof(unsigned char)),sizeof(unsigned char)); - TS_ASSERT( sc == sc2 ); - } - // push count char - { - bsl::BinBuffer buf(g_xcompool,0); - buf.push(5,'a'); - TS_ASSERT( 0 == strcmp(buf.data(),"aaaaa") ); - buf.push(5,'\0'); - TS_ASSERT( 0 == strcmp(buf.data(),"aaaaa") ); - buf.push(5,'b'); - //TS_ASSERT( 0 == strcmp(buf.data(),"aaaaabbbbb") ); - TS_ASSERT( 15 == buf.size() ); - } - // push wchar_t - { - bsl::BinBuffer buf(g_xcompool,0); - wchar_t wc = L'c'; - buf.push(wc); - TS_ASSERT( 0 == strcmp(buf.data(),"c") ); - buf.push(wc); - //printf("==%d==\n",sizeof(wchar_t)); - //printf("==%d==\n",buf.size()); - //printf("==%s==\n",buf.data()); - //TS_ASSERT( 0 == strcmp(buf.data(),"cc") ); - //buf.push("ccc"); - //TS_ASSERT( 0 == strcmp(buf.data(),"ccccc") ); - } - // push wchar_t* - { - /* - bsl::BinBuffer buf(g_xcompool,100); - buf.push("百度"); - TS_ASSERT(100 == buf.capacity()); - TS_ASSERT(4 == buf.size()); - buf.push0("百度"); - TS_ASSERT(9 == buf.size()); - printf("==%s==\n",buf.data()); - */ - } - // push int - { - bsl::BinBuffer buf(g_xcompool,20); - int val = 18977; - buf.push(val); - int val2 = get_bin_value(buf.data(),sizeof(int)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+min(buf.get_pack(),sizeof(int)),sizeof(int)); - TS_ASSERT( val == val2 ); - } - // push long int - { - bsl::BinBuffer buf(g_xcompool,20); - long int val = 18977; - buf.push(val); - long int val2 = get_bin_value(buf.data(),sizeof(long int)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(long int)),sizeof(long int)); - TS_ASSERT( val == val2 ); - } - // push unsigned int - { - bsl::BinBuffer buf(g_xcompool,20); - unsigned int val = 18977; - buf.push(val); - unsigned int val2 = get_bin_value(buf.data(),sizeof(unsigned int)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+min(buf.get_pack(),sizeof(unsigned int)),sizeof(unsigned int)); - TS_ASSERT( val == val2 ); - } - // push unsigned long int - { - bsl::BinBuffer buf(g_xcompool,20); - unsigned long int val = 18977; - buf.push(val); - unsigned long int val2 = get_bin_value(buf.data(),sizeof(unsigned long int)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(unsigned long int)),sizeof(unsigned long int)); - TS_ASSERT( val == val2 ); - } - // push char * - { - bsl::BinBuffer buf(g_xcompool,0); - buf.push("abcdef",6); - TS_ASSERT( 0 == strcmp(buf.data(),"abcdef") ); - buf.push("aa",2); - TS_ASSERT( buf.size() == 8 ); - buf.push("bb",2); - TS_ASSERT( buf.size() == 10 ); - } - // push char * - { - bsl::BinBuffer buf(g_xcompool,100); - buf.push("abcdef",6); - char str[100]; - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abcdef") ); - buf.push("aa",2); - TS_ASSERT( buf.size() == 8 ); - buf.push("bb",2); - TS_ASSERT( buf.size() == 10 ); - } - - // push char * , sub_str_len - { - bsl::BinBuffer buf(g_xcompool,0); - buf.push("abcdef",3); - char str[1000]; - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abc" ) ); - TS_ASSERT( !buf.truncated() ); - TS_ASSERT( !buf.ever_truncated() ); - buf.push("ABDEF",5); - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abcABDEF") ); - buf.push("e",1); - buf.push("f",100); - TS_ASSERT( 109 == buf.size() ); - buf.clear(); - buf.push("abcdefg",3); - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abc") ); - TS_ASSERT( 3 == buf.size() ); - buf.push("abc",4); - TS_ASSERT( 7 == buf.size() ); - } - - // push char * , sub_str_len - { - bsl::BinBuffer buf(g_xcompool,99); - buf.push("abcdef",3); - TS_ASSERT( 0 == strcmp(buf.data(),"abc" ) ); - TS_ASSERT( !buf.truncated() ); - TS_ASSERT( !buf.ever_truncated() ); - buf.push("ABDEF",5); - char str[100]; - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abcABDEF") ); - buf.push("e",1); - buf.push("f",100); - TS_ASSERT( 109 == buf.size() ); - buf.clear(); - buf.push("abcdefg",3); - get_str(str,buf.data(),buf.size()); - TS_ASSERT( 0 == strcmp(str,"abc") ); - TS_ASSERT( 3 == buf.size() ); - buf.push("abc",4); - TS_ASSERT( 7 == buf.size() ); - } - /* - // push capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,0); - buf.push(0,"a"); - TS_ASSERT( 0 == buf.size() ); - // cap < size - buf.push(1,"abcd"); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push(10,"efgh"); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push(4,"xyzz"); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,100); - buf.push(0,"a"); - TS_ASSERT( 0 == buf.size() ); - // cap < size - buf.push(1,"abcd"); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push(10,"efgh"); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push(4,"xyzz"); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - - // push0 capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,0); - buf.push0(0,"a"); - TS_ASSERT( 0 == buf.size() ); - - // cap < size - buf.push0(1,"abcd"); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( 0 == strcmp(buf.data(),"\0") ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push0(10,"efgh"); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push0(4,"xyzz"); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push0 capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,100); - buf.push0(0,"a"); - TS_ASSERT( 0 == buf.size() ); - - // cap < size - buf.push0(1,"abcd"); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( 0 == strcmp(buf.data(),"\0") ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push0(10,"efgh"); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push0(4,"xyzz"); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push capacity char * sub_str_len - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,0); - buf.push(0,"a"); - TS_ASSERT( 0 == buf.size() ); - // cap < size - buf.push(1,"abcd",10); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push(10,"efgh",1); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push(4,"xyzz",10); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,100); - buf.push(0,"a"); - TS_ASSERT( 0 == buf.size() ); - // cap < size - buf.push(1,"abcd",10); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push(10,"efgh",1); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push(4,"xyzz",10); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push0 capacity char * sub_str_len - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,0); - buf.push0(0,"a"); - TS_ASSERT( 0 == buf.size() ); - - // cap < size - buf.push0(1,"abcd",10); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( 0 == strcmp(buf.data(),"\0") ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push0(10,"efgh",1); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push0(4,"xyzz",10); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - } - // push0 capacity char * - { - // no 1 NULL; - bsl::BinBuffer buf(g_xcompool,100); - buf.push0(0,"a"); - TS_ASSERT( 0 == buf.size() ); - - // cap < size - buf.push0(1,"abcd",10); - TS_ASSERT( 1 == buf.size() ); - TS_ASSERT( 0 == strcmp(buf.data(),"\0") ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - // cap > size - buf.push0(10,"efgh",1); - TS_ASSERT( 11 == buf.size() ); - TS_ASSERT( !buf.truncated() ); - // cap == size - buf.push0(4,"xyzz",10); - TS_ASSERT( 15 == buf.size() ); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - }*/ - // push long long - { - bsl::BinBuffer buf(g_xcompool,20); - long long val = 333333318977LL; - buf.push(val); - long long val2 = get_bin_value(buf.data(),sizeof(long long)); - TS_ASSERT( val == val2 ); - val = 889922LL; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(long long)),sizeof(long long)); - TS_ASSERT( val == val2 ); - } - // push unsigned long long - { - bsl::BinBuffer buf(g_xcompool,20); - unsigned long long val = 333333318977ULL; - buf.push(val); - unsigned long long val2 = get_bin_value(buf.data(),sizeof(unsigned long long)); - TS_ASSERT( val == val2 ); - val = 889922ULL; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(unsigned long long)),sizeof(unsigned long long)); - TS_ASSERT( val == val2 ); - } - - // push double - { - bsl::BinBuffer buf(g_xcompool,20); - double val = 18977; - buf.push(val); - double val2 = get_bin_value(buf.data(),sizeof(double)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(double)),sizeof(double)); - TS_ASSERT( val == val2 ); - } - // push long double - { - bsl::BinBuffer buf(g_xcompool,20); - long double val = 18977; - buf.push(val); - long double val2 = get_bin_value(buf.data(),sizeof(long double)); - TS_ASSERT( val == val2 ); - val = 889922; - buf.push(val); - val2 = get_bin_value(buf.data()+max(buf.get_pack(),sizeof(long double)),sizeof(long double)); - TS_ASSERT( val == val2 ); - } - // push short - { - bsl::BinBuffer buf; - short val = 100; - buf.push(val); - short val2 = get_bin_value(buf.data(),sizeof(short)); - TS_ASSERT( val == val2 ); - } - // push unsigned short - { - bsl::BinBuffer buf; - unsigned short val = 200; - buf.push(val); - unsigned short val2 = get_bin_value(buf.data(),sizeof(unsigned short)); - TS_ASSERT( val == val2 ); - } - /* - // push format ... - { - bsl::BinBuffer buf(g_xcompool,0); - buf.pushf("%d%s",100,"hehe"); - TS_ASSERT( 7 == buf.size() ); - buf.push(100); - TS_ASSERT( 8 + sizeof(int) == buf.size() ); - } - // push format ... - { - bsl::BinBuffer buf(g_xcompool,0); - buf.pushf0("%d%s",100,"hehe"); - TS_ASSERT( 8 == buf.size() ); - } - // push capacity format ... - { - bsl::BinBuffer buf(g_xcompool,0); - buf.pushf(5,"%d%s",100,"hehe"); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - TS_ASSERT( 5 == buf.size() ); - } - // push capacity format ... - { - bsl::BinBuffer buf(g_xcompool,0); - buf.pushf0(5,"%d%s",100,"hehe"); - TS_ASSERT( buf.truncated() ); - TS_ASSERT( buf.ever_truncated() ); - TS_ASSERT( 5 == buf.size() ); - TS_ASSERT( 0 == strcmp(buf.data(),"100h") ); - } - */ - // transfer_from - { - bsl::BinBuffer buf(g_xcompool,100); - buf.push("a").push("b").push("asdfad;fkja;sdfja;sdfjdjf"); - size_t size = buf.size(); - bsl::BinBuffer buf2; - buf2.transfer_from(buf); - TS_ASSERT( size == buf2.size() ); - buf.swap(buf2); - TS_ASSERT( buf2.empty() ); - TS_ASSERT( size == buf.size() ); - buf.clear(); - buf.reserve(10); - buf.push("1234567890"); - TS_ASSERT( !buf.full() ); - TS_ASSERT( 100 == buf.capacity() ); - } - // push true false - { - bsl::BinBuffer buf; - buf.push(true); - bool tmp = get_bin_value(buf.data(),sizeof(bool)); - TS_ASSERT( tmp == true ); - TS_ASSERT( tmp != false ); - buf.clear(); - buf.push(false); - tmp = get_bin_value(buf.data(),sizeof(bool)); - TS_ASSERT( tmp == false ); - TS_ASSERT( tmp != true ); - } - // pack - { - bsl::BinBuffer buf; - size_t pack = sizeof(long); - size_t size = 0; - TS_ASSERT(true == buf.set_pack(pack)); - TS_ASSERT(size == buf.size()); - buf.push('a'); - size = 1; - TS_ASSERT(size == buf.size()); - buf.push(short(1)); - size = 4; - TS_ASSERT(size == buf.size()); - buf.push(0L); - size = ((size + pack - 1) & (~(pack - 1))) + sizeof(long); - TS_ASSERT(size == buf.size()); - buf.push(1.0); - size = ((size + pack - 1) & (~(pack - 1))) + sizeof(double); - TS_ASSERT(size == buf.size()); - } - /* - // pushf format ... - { - bsl::BinBuffer buf; - buf.pushf("%d",100).pushf("%d",100); - TS_ASSERT( 6 == buf.size() ); - buf.pushf0("%d",100).pushf0("%d",100); - TS_ASSERT( 14 == buf.size() ); - } - // push capacity format ... - { - bsl::BinBuffer buf; - buf.pushf(4,"%s","abcdef").pushf(3,"%s","12345"); - TS_ASSERT( 7 == buf.size() ); - //TS_ASSERT( 0 == strcmp(buf.data(),"abcd123") ); - } - // pushf0 - { - bsl::BinBuffer buf; - buf.pushf0(4,"%s","abcdef").pushf0(3,"%s","12345"); - TS_ASSERT( 7 == buf.size() ); - } - */ - // push - { - bsl::BinBuffer buf; - buf.push("123456789",3).push("abcdef",5); - TS_ASSERT( 8 == buf.size() ); - } - /* - // push - { - bsl::BinBuffer buf; - buf.push0(3,"123456789",3).push0(5,"abcdef",1).push0(1,"abcd",1); - }*/ - // construct - { - bsl::BinBuffer buf(size_t(-100)); - TS_ASSERT(buf.capacity() == 0); - bsl::BinBuffer buf2(1, size_t(-1)); - TS_ASSERT(buf2.get_pack() == bsl::BinBuffer::DEFAULT_PACK); - bsl::BinBuffer buf3(1,1000); - TS_ASSERT(buf3.get_pack() == bsl::BinBuffer::DEFAULT_PACK ); - } - { - bsl::BinBuffer buf; - const char *data = "hello world"; - buf< -#include - -class bsl_test_pool : public CxxTest::TestSuite -{ -public: - void test_normal(void) { - bsl::cached_mempool o; - o.free(0, 0); - } - void test_normal1(void) { - bsl::mempool *p = new bsl::cached_mempool(); - p->free(0, 0); - delete p; - } - void test_clear(){ - bsl::cached_mempool o; - o.malloc(2048); - o.malloc(2049); - o.clear(); - o.malloc(2049); - } -}; diff --git a/bsl/unittest/bsl_test_cpalloc_address.h b/bsl/unittest/bsl_test_cpalloc_address.h deleted file mode 100644 index 8f2b3950ec8c875ed63b8e6a160bebf28ff8f462..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_cpalloc_address.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_cpalloc_address.h,v 1.2 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_cpalloc_address.h - * @author xiaowei(com@baidu.com) - * @date 2008/10/28 11:25:32 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_CPALLOC_ADDRESS_H_ -#define __BSL_TEST_CPALLOC_ADDRESS_H_ - -#include -#include -#include -#include -#include -#include -#include "define.rc" - - -template -void test_address() -{ - typedef typename _Alloc::_Self _Self; // cpsalloc - typedef typename _Alloc::_Base _Base; // μ◇≤?alloc - - typedef typename _Self::pointer cpsalloc_pointer; - typedef typename _Base::pointer alloc_pointer; - typedef typename _Self::pointer cpsalloc_pointer; - typedef typename _Base::pointer alloc_pointer; - typedef typename _Base::reference reference; - - _Base alloc; - _Self cpsalloc; - - int ret; - ret = cpsalloc.create(); - TSM_ASSERT(ret, ret == 0); - - cpsalloc_pointer p1 = cpsalloc.allocate(1); - TSM_ASSERT(p1, p1 != 0); - - alloc_pointer p2 = alloc.allocate(1); - TSM_ASSERT(p2, p2 != NULL); - - // cpsalloc_pointer p3 = cpsalloc.address(*p2); - // TSM_ASSERT(p3, p3 != 0); - - - ret = cpsalloc.destroy(); - TSM_ASSERT(ret, ret == 0); -} - - - template -void test_address_const() -{ - /* - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::const_reference const_reference; - - _Alloc alloc; - pointer p = alloc.allocate(100); - TSM_ASSERT(p, p != NULL); - - const_pointer p2 = alloc.address((const_reference)*p); - TSM_ASSERT(p2, p2 == p); - - alloc.deallocate(p, 1); - */ -} - -class test_bsl_cpsalloc_address : public CxxTest::TestSuite -{ - public: - // 1) ∑μ??÷μ 《pointer??–?μ?addressΩ”?/ - void test_bsl_cpsalloc_address_1(void) - { - typedef bsl::bsl_alloc alloc_t_1; - typedef bsl::bsl_cpsalloc cpsalloc_t_1; - //typedef bsl::bsl_cpsalloc alloc_t_1; - // typedef bsl::bsl_cpsalloc alloc_t_2; - //typedef bsl::bsl_cpsalloc alloc_t_3; - //typedef bsl::bsl_cpsalloc alloc_t_4; - - test_address(); - //test_address(); - //test_address(); - //test_address(); - } - - // 2) ∑μ??÷μ 《const pointer??–?μ?addressΩ”?/ - void test_bsl_cpsalloc_address_2(void) - { - /* - typedef bsl::bsl_cpalloc alloc_t_1; - typedef bsl::bsl_cpalloc alloc_t_2; - //typedef bsl::bsl_cpalloc alloc_t_3; - typedef bsl::bsl_cpalloc alloc_t_4; - - test_address_const(); - test_address_const(); - //test_address_const(); - test_address_const(); - - std::cout << "test_bsl_alloc_address" << std::endl; - */ - } -}; - - - - - - - - - - - - - - - - - -#endif //__BSL_TEST_CPALLOC_ADDRESS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_deque.h b/bsl/unittest/bsl_test_deque.h deleted file mode 100644 index 3767945fba6a5a56150a48dc9ff713115addef66..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_deque.h +++ /dev/null @@ -1,802 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -std::string rand_string() -{ - std::string str; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - -class bsl_test_deque : public CxxTest::TestSuite -{ -public: - void test_operator() - { - { - bsl::deque t1; - for (int i = 0; i < 100; i ++) { - t1.push_back(i); - } - TS_ASSERT( 100 == t1.size() ); - bsl::deque t2; - t2 = t1; - TS_ASSERT( 100 == t2.size() ); - int i = 0; - for (bsl::deque::iterator Iter = t2.begin(); Iter != t2.end(); ++ Iter) { - TS_ASSERT( *Iter == i ++ ); - } - i = 0; - t1 = t1; - TS_ASSERT( 100 == t1.size() ); - for (bsl::deque::iterator Iter = t1.begin(); Iter != t1.end(); ++ Iter) { - TS_ASSERT( *Iter == i ++ ); - } - bsl::deque t3; - t3.push_back(1); - TS_ASSERT( 1 == *t3.begin() ); - bsl::deque t5; - bsl::deque t4; - t4 = t3; - t3.pop_back(); - t3 = t5; - TS_ASSERT( 0 == t3.size() ); - t1 = t3; - TS_ASSERT( 0 == t1.size() ); - TS_ASSERT( 0 == t3.size() ); - } - { - bsl::deque l1; - bsl::deque l2; - for (int i = 0; i < 1000; i ++) { - l1.push_front( "hello world" ); - } - TS_ASSERT( 1000 == l1.size() ); - for (int i = 0; i < 100; i ++) { - l2 = l1; - } - TS_ASSERT( 1000 == l2.size() ); - } - { - bsl::deque l1; - for (int i = 0; i < 100; i ++) { - l1.push_back(i); - } - TS_ASSERT( 100 == l1.size() ); - bsl::deque l2; - for (int i = 10; i > 0; i --) { - l2.push_back(i); - } - l2 = l1; - TS_ASSERT( 100 == l2.size() ); - TS_ASSERT( 100 == l1.size() ); - int i = 0; - for (bsl::deque::iterator iter = l2.begin(); iter != l2.end(); ++ iter, i ++) { - TS_ASSERT( *iter == i ); - } - } - } - void test_create() - { - bsl::deque l1; - int i; - for (i = 0; i < 10000; i ++) { - l1.create(); - } - for (i = 0; i < 10000; i ++) { - l1.create(); - } - bsl::deque l2; - for (i = 0; i < 10000; i ++) { - l2.create(); - } - for (i = 0; i < 10; i ++) { - l1.push_back(i); - } - TS_ASSERT( 10 == l1.size() ); - for (i = 0; i < 10; i ++) { - TS_ASSERT( i == l1[i] ); - } - } - - void test_nocreate_0() - { - bsl::deque t0; - int x; - TS_ASSERT_EQUALS(t0.resize(100), 0); - TS_ASSERT_EQUALS(t0.resize(100,300), 0); - TS_ASSERT_EQUALS(t0.assign(56,23), 0); - TS_ASSERT_EQUALS(t0.push_back(30), 0); - TS_ASSERT_EQUALS(t0.pop_back(), 0); - TS_ASSERT_EQUALS(t0.push_front(30), 0); - TS_ASSERT_EQUALS(t0.pop_front(), 0); - TS_ASSERT_EQUALS(t0.clear(), 0); - TS_ASSERT_EQUALS(t0.set(23, 34), -1); - TS_ASSERT_EQUALS(t0.get(21, &x), -1); - } - - void test_create_0() - { - bsl::deque t0; - TS_ASSERT(t0.destroy() == 0); - } - - void test_create_1() - { - bsl::deque t1; - t1.create(); - t1.create(); - t1.create(); - TS_ASSERT(t1.destroy() == 0); - } - - void test_create_2() - { - bsl::deque t0; - TS_ASSERT_EQUALS(t0.create(),0); - TS_ASSERT_EQUALS(t0.create(),0); - TS_ASSERT_EQUALS(t0.create(),0); - TS_ASSERT_EQUALS(t0.destroy(),0); - TS_ASSERT_EQUALS(t0.create(),0); - } - - void test_set_get_0() - { - bsl::deque t0; - TS_ASSERT_EQUALS(t0.create(), 0); - TS_ASSERT_EQUALS(t0.resize(300, 20),0); - int x; - TS_ASSERT_EQUALS(t0.get(5, &x), 0); - TS_ASSERT_EQUALS(x, 20); - TS_ASSERT_EQUALS(t0.set(5, 45), 0); - TS_ASSERT_EQUALS(t0.get(5, &x), 0); - TS_ASSERT_EQUALS(x, 45); - } - void test_resize_0() - { - bsl::deque t0; - TS_ASSERT_EQUALS(t0.create(), 0); - t0.resize(1000, 98); - TS_ASSERT_EQUALS(t0.size(), 1000); - for (int i = 0; i < (int)t0.size(); ++i) { - TS_ASSERT_EQUALS(t0[i], 98); - } - } - - void test_resize_1() - { - bsl::deque t0; - TS_ASSERT_EQUALS(t0.create(), 0); - t0.resize(1000); - TS_ASSERT_EQUALS(t0.size(), 1000); - } - - void test_push_front_0() - { - bsl::deque t0; - TS_ASSERT(t0.create() == 0); - int n = 5000; - for(int i=0; i < n; i++) { - int ret = t0.push_front(i); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t0.front() == i); - } - - int v = n - 1; - for (bsl::deque::iterator iter = t0.begin(); - iter != t0.end(); - ++iter) { - TS_ASSERT(*iter == v); - --v; - } - v = n - 1; - - for (bsl::deque::const_iterator iter = t0.begin(); - iter != t0.end(); - ++iter) { - TS_ASSERT(*iter == v); - --v; - } - v = 0; - - for (bsl::deque::reverse_iterator iter = t0.rbegin(); - iter != t0.rend(); - ++iter) { - TS_ASSERT(*iter == v); - ++v; - } - - - /* - v = n - 1; - - for (bsl::deque::const_reverse_iterator iter = t0.rbegin(); - iter != t0.rend(); - ++iter) { - TS_ASSERT(*iter == v); - v++; - } - */ - - - TS_ASSERT_EQUALS(t0.size() , n); - TS_ASSERT(t0.destroy() == 0); - } - - void test_push_front_1() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - std::string str(rand_string()); - int ret = t1.push_front(str); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t1.front() == str); - dt1.push_front(str); - } - - std::deque::iterator dt_iter = dt1.begin(); - for (bsl::deque::iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter) { - TS_ASSERT(*iter == *dt_iter); - } - - std::deque::const_iterator dt_iter1 = dt1.begin(); - for (bsl::deque::const_iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter1) { - TS_ASSERT(*iter == *dt_iter1); - } - - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - - void test_push_front_2() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - int ret = t1.push_front(tmp); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t1.front() == tmp); - dt1.push_front(tmp); - } - - std::deque::iterator dt_iter = dt1.begin(); - for (bsl::deque::iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter) { - TS_ASSERT(*iter == *dt_iter); - } - - std::deque::const_iterator dt_iter1 = dt1.begin(); - for (bsl::deque::const_iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter1) { - TS_ASSERT(*iter == *dt_iter1); - } - - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - - void test_push_back_0() - { - bsl::deque t0; - TS_ASSERT(t0.create() == 0); - int n = 5000; - for(int i=0; i < n; i++) { - int ret = t0.push_back(i); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t0.back() == i); - } - int v = 0; - for (bsl::deque::iterator iter = t0.begin(); - iter != t0.end(); - ++iter) { - TS_ASSERT(*iter == v); - ++v; - } - v = 0; - - for (bsl::deque::const_iterator iter = t0.begin(); - iter != t0.end(); - ++iter) { - TS_ASSERT(*iter == v); - ++v; - } - v = n - 1; - - for (bsl::deque::reverse_iterator iter = t0.rbegin(); - iter != t0.rend(); - ++iter) { - TS_ASSERT(*iter == v); - --v; - } - - TS_ASSERT_EQUALS(t0.size() , n); - TS_ASSERT(!t0.destroy()); - } - - void test_push_back_1() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - std::string str(rand_string()); - int ret = t1.push_back(str); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t1.back() == str); - dt1.push_back(str); - } - std::deque::iterator dt_iter = dt1.begin(); - for (bsl::deque::iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter) { - TS_ASSERT(*iter == *dt_iter); - } - - std::deque::const_iterator dt_iter1 = dt1.begin(); - for (bsl::deque::const_iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter1) { - TS_ASSERT(*iter == *dt_iter1); - } - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - void test_push_back_2() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - int ret = t1.push_front(tmp); - TS_ASSERT_EQUALS(ret, 0); - TS_ASSERT(t1.front() == tmp); - dt1.push_front(tmp); - } - - std::deque::iterator dt_iter = dt1.begin(); - for (bsl::deque::iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter) { - TS_ASSERT(*iter == *dt_iter); - } - - std::deque::const_iterator dt_iter1 = dt1.begin(); - for (bsl::deque::const_iterator iter = t1.begin(); - iter != t1.end(); - ++iter, ++dt_iter1) { - TS_ASSERT(*iter == *dt_iter1); - } - - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - - void test_push_pop_0() - { - bsl::deque t1; - std::deque dt1; - int n = 5000; - //int mpush = 0, mpop = 0; - TS_ASSERT(t1.create() == 0); - for (int i = 0; i < n; ++i) { - int x = rand(); - switch (rand()%4) { - case 0: TS_ASSERT(t1.push_back(x) == 0); - dt1.push_back(x); - break; - case 1: - if (t1.size() >0) { - TS_ASSERT(t1.pop_front() == 0); - dt1.pop_front(); - break; - } - case 2: TS_ASSERT(t1.push_front(x) == 0); - dt1.push_front(x); - break; - - case 3: - if (t1.size() > 0) { - TS_ASSERT(t1.pop_front() == 0); - dt1.pop_front(); - } - break; - default: - break; - } - - TS_ASSERT_EQUALS(t1.size(), dt1.size()); - if (t1.size() != 0) { - TS_ASSERT_EQUALS(t1.back(), dt1.back()); - TS_ASSERT_EQUALS(t1.front(), dt1.front()); - } - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_rand_0() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - int x = rand(); - t1.push_back(x); - dt1.push_back(x); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - TS_ASSERT_EQUALS(t1[x], dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_rand_1() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - std::string str(rand_string()); - t1.push_back(str); - dt1.push_back(str); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - TS_ASSERT_EQUALS(t1[x], dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - - void test_rand_2() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - MyClass s; - snprintf(s.name, sizeof(s.name), "%s", rand_string().c_str()); - snprintf(s.value, sizeof(s.value), "%s", rand_string().c_str()); - t1.push_back(s); - dt1.push_back(s); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - TS_ASSERT_EQUALS(t1[x], dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_clear_0() - { - bsl::deque t1; - std::deque dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - int x = rand(); - t1.push_back(x); - dt1.push_back(x); - } - t1.clear(); - t1.clear(); - t1.clear(); - dt1.clear(); - TS_ASSERT(t1.size() == dt1.size()); - - for (int i = 0; i < n; ++i) { - int x = rand()%n; - t1.push_back(x); - dt1.push_back(x); - } - TS_ASSERT(t1.size() == dt1.size()); - TS_ASSERT(t1.destroy() == 0); - } - - void test_ceate_0() - { - bsl::deque t1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - t1.push_back(i); - } - TS_ASSERT(t1.create() == 0); - TS_ASSERT(t1.size() == 0); - } - - void test_swap_0() - { - bsl::deque t1; - bsl::deque t2; - - TS_ASSERT(t1.create() == 0); - TS_ASSERT(t2.create() == 0); - for (int i = 0; i < 100; ++i) { - TS_ASSERT(t1.push_back(i) == 0); - TS_ASSERT(t2.push_front(i) == 0); - } - bsl::swap(t1, t2); - for (int i = 0; i < 100; ++i) { - TS_ASSERT(t2[i]==i); - TS_ASSERT(t1[i]==(100-i-1)); - } - - for (int i = 0; i < 100; ++i) { - TS_ASSERT(t1.push_back(i*2) == 0); - } - - for (int i = 0; i < 100; ++i) { - TS_ASSERT(t1[i+100] == i*2); - } - - for (int i = 0; i < 200; ++i) { - TS_ASSERT(t1.pop_back() == 0); - } - - } - - void test_assign_0() - { - bsl::deque t1; - MyClass tmp; - TS_ASSERT_EQUALS(t1.create(), 0); - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - TS_ASSERT_EQUALS(t1.assign(5000, tmp), 0); - TS_ASSERT_EQUALS(t1.size(),5000); - for(int i = 0; i < 5000; ++i) { - TS_ASSERT(t1[i] == tmp); - } - for (int i = 0; i < 5000; ++i) { - t1.pop_back(); - } - TS_ASSERT_EQUALS(t1.size(), 0); - } - - void test_assign_1() - { - bsl::deque t1; - std::vector t2; - for (int i = 0; i < 5000; ++i) { - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - t2.push_back(tmp); - } - t1.create(); - t1.assign(t2.begin(), t2.end()); - TS_ASSERT_EQUALS(t1.size(), t2.size()); - for (int i = 0; i < 5000; ++i) { - TS_ASSERT(t1[i] == t2[i]); - } - } - - void test_assign_2() - { - bsl::deque t1; - TS_ASSERT_EQUALS(t1.create(), 0); - TS_ASSERT_EQUALS(t1.assign(5000, 30), 0); - for (int i = 0; i < 5000; ++i) { - TS_ASSERT_EQUALS(t1[i], 30); - } - } - - void test_iter_0() - { - bsl::deque t1; - t1.create(); - for (int i = 0; i < 5000; ++i) { - t1.push_back(i); - } - bsl::deque::iterator iter; - iter = t1.begin(); - for (int i = 1; i < 5000; ++i) { - iter++; - TS_ASSERT(*iter == i); - } - for (int i = 4999; i > 0; --i) { - TS_ASSERT(*iter == i); - iter--; - } - for (int i = 1; i < 5000; ++i) { - ++iter; - TS_ASSERT(*iter == i); - } - for (int i = 4999; i > 0; --i) { - TS_ASSERT(*iter == i); - --iter; - } - - iter += 100; - TS_ASSERT(*iter == 100); - - TS_ASSERT(*(iter+100) == 200); - - TS_ASSERT(*(iter-20) == 80); - - iter -= 80; - TS_ASSERT(*iter == 20); - - TS_ASSERT(iter[100] == 120); - - - bsl::deque::iterator iter2; - bsl::deque t2; - t2.create(); - TS_ASSERT_EQUALS(t2.push_back(30), 0); - TS_ASSERT_EQUALS(t2.push_back(900), 0); - iter2 = t2.begin(); - - bsl::deque::iterator iter3; - iter3 = iter2+1; - TS_ASSERT(!(iter2 == iter3)); - TS_ASSERT(iter2 != iter3); - TS_ASSERT(iter2 < iter3); - TS_ASSERT(iter2 <= iter3); - TS_ASSERT(iter3 >= iter2); - TS_ASSERT(iter3 > iter2); - - - bsl::deque::const_iterator iter4; - iter4 = t2.begin(); - TS_ASSERT(iter4 < iter3); - TS_ASSERT(iter4 != iter3); - TS_ASSERT(iter4 == iter2); - TS_ASSERT(iter4 >= iter2); - TS_ASSERT(iter2 <= iter4); - TS_ASSERT(iter4 < iter3); - TS_ASSERT(iter3 > iter4); - - TS_ASSERT(iter3-iter4 == 1); - TS_ASSERT(iter4+1 == iter3); - - } - - void test_stl_alg_0() - { - //swap不支持 - bsl::deque t1; - t1.create(); - int n = 5000; - for (int i = 0; i < n; ++i) { - t1.push_front(i); - } - //sort - std::sort(t1.begin(), t1.end()); - for (int i = 0; i < n; ++i) { - TS_ASSERT(t1[i] == i); - } - - - std::vector m(n);; - //copy - std::copy(t1.begin(), t1.end(), m.begin()); - for (int i = 0; i < n; ++i) { - TS_ASSERT(t1[i] == i); - TS_ASSERT(t1[i] == m[i]); - } - - bsl::deque t2; - t2.create(); - t2.assign(t1.begin(), t1.end()); - - std::copy(t1.begin(), t1.end(), t2.begin()); - for (int i = 0; i < n; ++i) { - TS_ASSERT(t1[i] == i); - TS_ASSERT(t1[i] == t2[i]); - } - - //find - TS_ASSERT(*(std::find(t1.begin(), t1.end(), 30)) == 30); - - //count - TS_ASSERT(std::count(t1.begin(), t1.end(), 20) == 1); - } - - void test_serialization_0() - { - bsl::deque t1; - - TS_ASSERT(t1.create() == 0); - for (int i = 0; i< 5000; ++i) { - TS_ASSERT(t1.push_back(i) == 0); - } - bsl::filestream fd; - fd.open("data", "w"); - bsl::binarchive ar(fd); - TS_ASSERT(ar.write(t1) == 0); - fd.close(); - - t1.clear(); - TS_ASSERT(t1.size() == 0); - - fd.open("data", "r"); - TS_ASSERT(ar.read(& t1) == 0); - fd.close(); - TS_ASSERT(t1.size() == 5000); - for (int i = 0; i < 5000; ++i) { - TS_ASSERT(i == t1[i]); - } - } - - - -}; diff --git a/bsl/unittest/bsl_test_exception.h b/bsl/unittest/bsl_test_exception.h deleted file mode 100644 index a57fa15eed0bff56458c20ce77db06980fdd7f12..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_exception.h +++ /dev/null @@ -1,5324 +0,0 @@ - -#ifndef __BSL_TEST_EXCEPTION_H_ -#define __BSL_TEST_EXCEPTION_H_ -#include -#include "bsl/exception/bsl_exception.h" -#include "bsl_test_exception_prepare.h_" - -class test_exception : public CxxTest::TestSuite { -public: - - - void test_UnknownException_info_a(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "true"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_b(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(true); - }catch( bsl::Exception& ex ){ - const char * what = "true"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_c(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "true"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_d(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(true); - }catch( bsl::Exception& ex ){ - const char * what = "true"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_e(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(false); - }catch( bsl::UnknownException& ex ){ - const char * what = "false"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_f(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(false); - }catch( bsl::Exception& ex ){ - const char * what = "false"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_g(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(false); - }catch( bsl::UnknownException& ex ){ - const char * what = "false"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_h(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(false); - }catch( bsl::Exception& ex ){ - const char * what = "false"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_i(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(true).push(false).push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "truefalsetrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_j(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(true).push(false).push(true); - }catch( bsl::Exception& ex ){ - const char * what = "truefalsetrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ba(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(true).push(false).push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "truefalsetrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bb(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(true).push(false).push(true); - }catch( bsl::Exception& ex ){ - const char * what = "truefalsetrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bc(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123); - }catch( bsl::UnknownException& ex ){ - const char * what = "123"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bd(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123); - }catch( bsl::Exception& ex ){ - const char * what = "123"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_be(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123); - }catch( bsl::UnknownException& ex ){ - const char * what = "123"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bf(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123); - }catch( bsl::Exception& ex ){ - const char * what = "123"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bg(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123).push(-456).push(+789).push(0); - }catch( bsl::UnknownException& ex ){ - const char * what = "123-4567890"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bh(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123).push(-456).push(+789).push(0); - }catch( bsl::Exception& ex ){ - const char * what = "123-4567890"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bi(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123).push(-456).push(+789).push(0); - }catch( bsl::UnknownException& ex ){ - const char * what = "123-4567890"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_bj(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123).push(-456).push(+789).push(0); - }catch( bsl::Exception& ex ){ - const char * what = "123-4567890"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ca(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123.456).push(-1.2e+100).push(3.14e-50); - }catch( bsl::UnknownException& ex ){ - const char * what = "123.456-1.2e+1003.14e-50"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cb(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(123.456).push(-1.2e+100).push(3.14e-50); - }catch( bsl::Exception& ex ){ - const char * what = "123.456-1.2e+1003.14e-50"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cc(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123.456).push(-1.2e+100).push(3.14e-50); - }catch( bsl::UnknownException& ex ){ - const char * what = "123.456-1.2e+1003.14e-50"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cd(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(123.456).push(-1.2e+100).push(3.14e-50); - }catch( bsl::Exception& ex ){ - const char * what = "123.456-1.2e+1003.14e-50"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ce(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push('a').push(char(0)).push('b').push(4,'x'); - }catch( bsl::UnknownException& ex ){ - const char * what = "abxxxx"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cf(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push('a').push(char(0)).push('b').push(4,'x'); - }catch( bsl::Exception& ex ){ - const char * what = "abxxxx"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cg(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push('a').push(char(0)).push('b').push(4,'x'); - }catch( bsl::UnknownException& ex ){ - const char * what = "abxxxx"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ch(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push('a').push(char(0)).push('b').push(4,'x'); - }catch( bsl::Exception& ex ){ - const char * what = "abxxxx"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ci(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push("abc"); - }catch( bsl::UnknownException& ex ){ - const char * what = "abc"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_cj(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push("abc"); - }catch( bsl::Exception& ex ){ - const char * what = "abc"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_da(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push("abc"); - }catch( bsl::UnknownException& ex ){ - const char * what = "abc"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_db(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push("abc"); - }catch( bsl::Exception& ex ){ - const char * what = "abc"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_dc(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(""); - }catch( bsl::UnknownException& ex ){ - const char * what = ""; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_dd(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push(""); - }catch( bsl::Exception& ex ){ - const char * what = ""; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_de(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(""); - }catch( bsl::UnknownException& ex ){ - const char * what = ""; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_df(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push(""); - }catch( bsl::Exception& ex ){ - const char * what = ""; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_dg(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push("abc").push("").push("def"); - }catch( bsl::UnknownException& ex ){ - const char * what = "abcdef"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_dh(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).push("abc").push("").push("def"); - }catch( bsl::Exception& ex ){ - const char * what = "abcdef"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_di(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push("abc").push("").push("def"); - }catch( bsl::UnknownException& ex ){ - const char * what = "abcdef"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_dj(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).push("abc").push("").push("def"); - }catch( bsl::Exception& ex ){ - const char * what = "abcdef"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ea(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).pushf("%d%s",123,"abc").push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "123abctrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_eb(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_DEFAULT).pushf("%d%s",123,"abc").push(true); - }catch( bsl::Exception& ex ){ - const char * what = "123abctrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_DEFAULT; - const char * level_str = "EXCEPTION_LEVEL_DEBUG"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ec(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).pushf("%d%s",123,"abc").push(true); - }catch( bsl::UnknownException& ex ){ - const char * what = "123abctrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ed(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException().push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_SILENT).pushf("%d%s",123,"abc").push(true); - }catch( bsl::Exception& ex ){ - const char * what = "123abctrue"; - bsl::exception_level_t level = bsl::EXCEPTION_LEVEL_SILENT; - const char * level_str = "EXCEPTION_LEVEL_SILENT"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } - - - void test_UnknownException_info_ee(){ - int line; - try{ - line = __LINE__, throw bsl::UnknownException()<(1); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bgj(){ - try{ - throw_func_push(1); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bha(){ - try{ - throw_func_push(3); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhb(){ - try{ - throw_func_push(3); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhc(){ - try{ - throw_func_push(10000); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhd(){ - try{ - throw_func_push(10000); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhe(){ - try{ - throw_func_shift(1); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhf(){ - try{ - throw_func_shift(1); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhg(){ - try{ - throw_func_shift(3); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhh(){ - try{ - throw_func_shift(3); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhi(){ - try{ - throw_func_shift(10000); - }catch( bsl::UnknownException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_depth_bhj(){ - try{ - throw_func_shift(10000); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "UnknownException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::UnknownException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bia(){ - try{ - throw_func_push(1); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bib(){ - try{ - throw_func_push(1); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bic(){ - try{ - throw_func_push(3); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bid(){ - try{ - throw_func_push(3); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bie(){ - try{ - throw_func_push(10000); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bif(){ - try{ - throw_func_push(10000); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_push" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_big(){ - try{ - throw_func_shift(1); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bih(){ - try{ - throw_func_shift(1); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bii(){ - try{ - throw_func_shift(3); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bij(){ - try{ - throw_func_shift(3); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bja(){ - try{ - throw_func_shift(10000); - }catch( bsl::BadCastException& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_BadCastException_depth_bjb(){ - try{ - throw_func_shift(10000); - }catch( bsl::Exception& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "BadCastException" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::BadCastException" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "throw_func_shift" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } - - - void test_UnknownException_e2no_bjc(){ - { - int errno = 123; - BSL_E2NO( errno, call_nothrow() ); - assert( errno == 0 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - try{ - call_throw(); - }catch(bsl::Exception& e){ - see(e.what()); - } - - size_t old_level = bsl::Exception::set_stack_trace_level(1); - printf("bsl::Exception::set_stack_trace_level(1)\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( 1 == bsl::Exception::set_stack_trace_level(0) ); - printf("bsl::Exception::set_stack_trace_level(0)\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( bsl::Exception::set_stack_trace_level(old_level) == 0 ); - printf("bsl::Exception::set_stack_trace_level(%d)\n", int(old_level)); - { - int errno = 123; - BSL_E2NO( errno, throw std::out_of_range("this is message") ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw_int(456) ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, errno = 789 ); - assert( errno == 0 ); - } - } - - - void test_BadCastException_e2no_bjd(){ - { - int errno = 123; - BSL_E2NO( errno, call_nothrow() ); - assert( errno == 0 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - try{ - call_throw(); - }catch(bsl::Exception& e){ - see(e.what()); - } - - size_t old_level = bsl::Exception::set_stack_trace_level(1); - printf("bsl::Exception::set_stack_trace_level(1)\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( 1 == bsl::Exception::set_stack_trace_level(0) ); - printf("bsl::Exception::set_stack_trace_level(0)\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( bsl::Exception::set_stack_trace_level(old_level) == 0 ); - printf("bsl::Exception::set_stack_trace_level(%d)\n", int(old_level)); - { - int errno = 123; - BSL_E2NO( errno, throw std::out_of_range("this is message") ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw_int(456) ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, errno = 789 ); - assert( errno == 0 ); - } - } - - -}; -#endif //__BSL_TEST_EXCEPTION_H_ - diff --git a/bsl/unittest/bsl_test_exception.py b/bsl/unittest/bsl_test_exception.py deleted file mode 100755 index d8b6600d3c51abac96508dd9108f6900e6e77c75..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_exception.py +++ /dev/null @@ -1,252 +0,0 @@ -#!/usr/bin/env python -# bsl_test_shared_buffer.h generator -HEADER = """ -#ifndef __BSL_TEST_EXCEPTION_H_ -#define __BSL_TEST_EXCEPTION_H_ -#include -#include "bsl/exception/bsl_exception.h" -#include "bsl_test_exception_prepare.h_" - -class test_exception : public CxxTest::TestSuite { -public: -""" - -FOOTER = """ -}; -#endif //__BSL_TEST_EXCEPTION_H_ -""" - -EXCEPTIONS = [ - "UnknownException", - "BadCastException", -# "OutOfBoundException", -# "KeyNotFoundException", -# "KeyAlreadyExistException", -# "BadAllocException", -# "BadArgumentException", -# "NullPointerException", -# "BadFormatStringException", -# "UninitializedException", -# "NotImplementedException", -# "InvalidOperationException", -# "OverflowException", -# "UnderflowException", -# "ParseErrorException", -] - -INFO_TEST_TEMPLATE = """ - void test_%(exception)s_info_%(id)s(){ - int line; - try{ - line = __LINE__, throw bsl::%(exception)s()%(arg_cmd)s%(level_cmd)s%(msg_cmd)s; - }catch( bsl::%(catch_exception)s& ex ){ - const char * what = "%(what)s"; - bsl::exception_level_t level = bsl::%(level)s; - const char * level_str = "%(level_str)s"; - - TS_ASSERT( 0 == strcmp( ex.what(), what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "%(exception)s" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::%(exception)s" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), __func__ ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), __FILE__ ) ); - TS_ASSERT( 0 == strcmp( ex.function(), __PRETTY_FUNCTION__ ) ); - TS_ASSERT( ex.line() == line ); - - TS_ASSERT( ex.level() == level ); - TS_ASSERT( 0 == strcmp( ex.level_str(), level_str ) ); - - } - } -""" - -DEPTH_TEST_TEMPLATE = """ - void test_%(exception)s_depth_%(id)s(){ - try{ - %(func_name)s(%(depth)d); - }catch( bsl::%(catch_exception)s& ex ){ - - TS_ASSERT( strlen( ex.what() ) == 1000000 || 0 == strcmp( ex.what(), throw_func_what ) ); -#if __GNUC__ <= 2 - TS_ASSERT( 0 != strstr( ex.name(), "%(exception)s" ) ); -#else - TS_ASSERT( 0 == strcmp( ex.name(), "bsl::%(exception)s" ) ); -#endif - TS_ASSERT( 0 != strstr( ex.stack(), "%(func_name)s" ) ); - - TS_ASSERT( 0 == strcmp( ex.file(), "bsl_test_exception_prepare.h_" ) ); //test BSL_EARG - - TS_ASSERT( ex.level() == throw_func_level ); - - } - } -""" -E2NO_TEST_TEMPLATE = """ - void test_%(exception)s_e2no_%(id)s(){ - { - int errno = 123; - BSL_E2NO( errno, call_nothrow() ); - assert( errno == 0 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - try{ - call_throw(); - }catch(bsl::Exception& e){ - see(e.what()); - } - - size_t old_level = bsl::Exception::set_stack_trace_level(1); - printf("bsl::Exception::set_stack_trace_level(1)\\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( 1 == bsl::Exception::set_stack_trace_level(0) ); - printf("bsl::Exception::set_stack_trace_level(0)\\n"); - { - int errno = 123; - BSL_E2NO( errno, call_throw() ); - assert( errno == -1 ); - } - assert( bsl::Exception::set_stack_trace_level(old_level) == 0 ); - printf("bsl::Exception::set_stack_trace_level(%%d)\\n", int(old_level)); - { - int errno = 123; - BSL_E2NO( errno, throw std::out_of_range("this is message") ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, call_throw_int(456) ); - assert( errno == -1 ); - } - { - int errno = 123; - BSL_E2NO( errno, errno = 789 ); - assert( errno == 0 ); - } - } -""" - -TEST_DATA = [{ - 'msg_cmd':".push(true)", - 'what': "true" -},{ - 'msg_cmd':".push(false)", - 'what': "false" -},{ - 'msg_cmd':".push(true).push(false).push(true)", - 'what': "truefalsetrue" -},{ - 'msg_cmd':".push(123)", - 'what': "123" -},{ - 'msg_cmd':".push(123).push(-456).push(+789).push(0)", - 'what': "123-4567890" -},{ - 'msg_cmd':".push(123.456).push(-1.2e+100).push(3.14e-50)", - 'what': "123.456-1.2e+1003.14e-50" -},{ - 'msg_cmd':".push('a').push(char(0)).push('b').push(4,'x')", - 'what': "abxxxx" -},{ - 'msg_cmd':'.push("abc")', - 'what': "abc" -},{ - 'msg_cmd':'.push("")', - 'what': "" -},{ - 'msg_cmd':'.push("abc").push("").push("def")', - 'what': "abcdef" -},{ - 'msg_cmd':'.pushf("%d%s",123,"abc").push(true)', - 'what': "123abctrue" -},{ - 'msg_cmd':"< message:%s stack:%s", \ - (__bsl_bsl_exception_instance__).name(), \ - (__bsl_bsl_exception_instance__).file(), \ - (__bsl_bsl_exception_instance__).line(), \ - (__bsl_bsl_exception_instance__).function(), \ - (__bsl_bsl_exception_instance__).what(), \ - (__bsl_bsl_exception_instance__).stack() \ - ) \ -/** -* @brief 将异常转化成错误码并打印日志的宏函数 -* -* 该宏旨在帮助程序员把C程序库平滑地升级为C++程序库,C++程序之间避免使用该宏。 -* 若代码(code)不抛异常,errno会被置为0; -* 若代码(code)抛出异常,errno会被置为-1,并且打印详细的错误日志。 -* 强烈建议使用此宏后,检查errno -* 强烈建议代码(code)只是一句函数调用。 -*/ -#define BSL_E2NO(errno, code) \ - do{ \ - try{ \ - code; \ - (errno) = 0; \ - }catch(bsl::Exception& __bsl_bsl_exception_instance__){ /*long name to prevent naming confliction*/ \ - (errno) = -1; \ - BSL_LOG_EXCEPTION(__bsl_bsl_exception_instance__, #errno" is set to -1!"); \ - }catch(std::exception& __bsl_std_exception_instance__){ /*long name to prevent naming confliction*/ \ - (errno) = -1; \ - __BSL_LOG_FATAL__( "std::exception[%s] is caught! "#errno" is set to -1! Definitely a BUG!", \ - __bsl_std_exception_instance__.what() ); \ - }catch(...){ \ - (errno) = -1; \ - __BSL_LOG_FATAL__("unknown exception is caught! "#errno" is set to -1! Definitely a FATAL BUG!"); \ - } \ - }while(0) - -#define UB_LOG_WARNING( fmt, arg... ) \ - do{ \ - fprintf( stderr, "UB_LOG_WARNING:"fmt"\n", ##arg ); \ - }while(0) - -#define UB_LOG_FATAL( fmt, arg... ) \ - do{ \ - fprintf( stderr, "UB_LOG_FATAL:"fmt"\n", ##arg ); \ - }while(0) - -void call_nothrow(){ - //do nothing -} -template -void call_throw(){ - throw Exception()< -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< -void throw_func_push( int depth ){ - if ( depth <= 0 ){ - throw ExceptionT().push(1000000, 'c').push(BSL_EARG).push(bsl::EXCEPTION_LEVEL_FATAL); - } - throw_func_push( depth - 1 ); -} - -template -void throw_func_shift( int depth ){ - if ( depth <= 0 ){ - throw ExceptionT()<<"acumon"<<7336<<-123<<"abc"<( depth - 1 ); -} - -#endif //__BSL_TEST_EXCEPTION_PREPARE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_hash_qa.h b/bsl/unittest/bsl_test_hash_qa.h deleted file mode 100644 index 4979e1ecee6e0dc8bae08eed8fdaa4d366a0231e..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_hash_qa.h +++ /dev/null @@ -1,253 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_hash_qa.h,v 1.5 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_hash_qa.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/13 19:54:05 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_HASH_QA_H_ -#define __BSL_TEST_HASH_QA_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - - - - -bool test_hash_qa () -{ - { - bsl::hashmap h; - __XASSERT2(h.create((1UL<<10UL) - 1UL) == 0); - } - if (0) { - bsl::hashmap h; - if (sizeof(void *) == sizeof(char)*4) { - __XASSERT2(h.create(1<<30) != 0); - } else { - __XASSERT2(h.create(1<<30) == 0); - } - } - return true; -} - -bool test_hash_qa2 () -{ - bsl::phashmap v; - std::map h; - int num = 10; - for (int i=0; i::iterator iter=v.begin(); - iter != v.end(); ++iter) { - std::cout<first<<" "<second<, - bsl::bsl_cpsalloc > > vs; - __XASSERT2(vs.create(1000, 10, cmpstr) == 0); - vs.set("hello"); - vs.set("hell3"); - vs.set("hell2"); - vs.set("hello"); - __XASSERT2(vs.size() == 3); - vs.erase("hello"); - __XASSERT2(vs.size() == 2); - vs.clear(); - - return true; -} - -void * _fun_ (void *param) -{ - bsl::bsl_rwhashset *vs = (bsl::bsl_rwhashset *)param; - for (int i=0; i<100; ++i) vs->set(0); - return NULL; -} - -bool test_hash_qa4 () -{ - bsl::bsl_rwhashset vs; - __XASSERT2(vs.create(1000) == 0); - pthread_t pid[10]; - for (size_t i=0; i -struct type_t -{ - char data[size]; -}; - -// htt -template -void set_type(type_t & __key, int n) -{ - assert (size >= sizeof(int)); - int * dat = (int *)__key.data; - *dat = n; -} - -// htt -template -struct hash_key -{ - size_t operator () (const type_t &__key)const { - assert (size >= sizeof(int)); - return *((int *)__key.data); - } -}; - -template -struct hash_equal -{ - bool operator () (const type_t &__key1, const type_t &__key2)const { - for(int i = 0; i < (int)size; i++){ - if(__key1.data[i] != __key2.data[i]){ - return false; - } - } - return true; - } -}; - -template -bool test_hash_qa5() -{ - std::cout<<"bsl_readset"<, hash_key ,hash_equal > rm_t; - //./.bench --hash_bucket=2000000 --hash_datanum=1000000 --thread_num=1 --value_size=128 --query_loop=1 - int hash_bucket = 2000000; - int hash_datanum = 1000000; - - rm_t hash; - hash.create(hash_bucket); - std::cout< > vec; - type_t v; - for (int i=0; i<(int)hash_datanum; ++i) { - set_type(v, i); - vec.push_back(v); - } - std::cout<<"Time stamp(ass): "< >(hash, p); - for (int i=0; i()); - } -}; - - - - - - - - -#endif //__BSL_TEST_HASH_QA_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_hashmap.h b/bsl/unittest/bsl_test_hashmap.h deleted file mode 100644 index 2921e390c94fccdd58d6827c04a38f419875d0cf..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_hashmap.h +++ /dev/null @@ -1,586 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_hashmap.h,v 1.6 2009/06/26 05:23:25 xiaowei Exp $ - * - * hashmap phashmap的测试代码 - * test_hashmap 测试hashmap phashmap的基本功能 - * test_hashmap_iterator 测试hashmap的迭代器功能 - * test_hashmap_serialization 测试容器的序列化功能 - * test_hashmap_assign 测试assign功能 - * test_hashmap_clear clear功能的测试 - * - * 注意:phashmap的线程安全性问题,在另外的测试文件里面单独测试 - **************************************************************************/ - -/** - * @file hashtest.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 11:10:06 - * @version $Revision: 1.6 $ - * @brief - * - **/ - -#ifndef __BSL_TEST_HASHMAP_H -#define __BSL_TEST_HASHMAP_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng"}; -const size_t N = sizeof(s) / sizeof(s[0]); - -std::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i -bool test_hashmap() -{ - { - int loop = 1<<10; - for (int i=0; i vec; - for (int i=0; i -bool test_hashmap_iterator() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(1<<15) == 0); - - int insertsize = 1<<10; - for (int i=0; ifirst)->second == iter->second); - } - for (typename THMp::iterator iter = test.begin(); iter != test.end(); iter++) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - for (typename THMp::const_iterator iter = test.begin(); iter != test.end(); ++iter) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - for (typename THMp::const_iterator iter = test.begin(); iter != test.end(); iter++) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - - const THMp & testp = test; - for (typename THMp::const_iterator iter = testp.begin(); iter != testp.end(); ++iter) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - for (typename THMp::const_iterator iter = testp.begin(); iter != testp.end(); iter++) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - testp.get(randstr()); - - size_t vsize = vec.size(); - //根据序列化参数对value进行附值 - for (typename THMp::iterator iter = test.begin(); iter != test.end(); ++iter) { - iter->second = randstr(); - vec[iter->first] = iter->second; - } - - __XASSERT(vsize == vec.size(), "%lu != %lu", (unsigned long)vsize, (unsigned long)vec.size()); - - for (typename THMp::iterator iter = test.begin(); iter != test.end(); ++iter) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - - //不调用destroy,自己调用析构函数析构 - //需要valgrind检查是否内存泄露 - return true; -} - -template -bool test_hashmap_serialization() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(1<<15) == 0); - int loop = 1<<12; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - std::string val = ""; - int ret = test.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - test.clear(); - //读硬盘到新结构体 - { - THMp test_0; - __XASSERT2 (test_0.create(100) == 0); - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::map::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - std::string val = ""; - int ret = test_0.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - //读硬盘到新结构体, 新结构体不初始化 - { - THMp test_0; - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::map::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - std::string val = ""; - int ret = test_0.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - return true; -} - -//assign测试 -template -bool test_hashmap_assign() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(102400) == 0); - __BSL_DEBUG("create hashmap"); - int loop = 1<<15; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - std::string val = ""; - int ret = test.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT (val == iter->second, "%s == %s", val.c_str(), iter->second.c_str()); - } - - for (int i=0; i<16; ++i) { - __XASSERT2 (test.assign(vec.begin(), vec.end()) == 0); - } - return true; -} - -template -bool test_hashmap_clear() -{ - //没有create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - for (int i=0; i<10000; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - } - //create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.create(100000) == 0); - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - //有数据的情况下clear - { - THMp test0; - typedef std::map map_t; - map_t vmap; - for (int i=0; i<10000; ++i) { - vmap.insert(std::make_pair(randstr(), randstr())); - } - __XASSERT2(test0.create(vmap.size() * 2) == 0); - for (int i=0; i<10; ++i) { - __XASSERT2(test0.assign(vmap.begin(), vmap.end()) == 0); - } - - for (int i=0; i<10; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - - for (int i=0; i<100; ++i) { - __XASSERT2(test0.destroy() == 0); - } - } - return true; -} - -class bsl_test_hashmap : public CxxTest::TestSuite -{ -public: - typedef std::string key; - typedef std::string value; - typedef bsl::hashmap THMp1; - void test_operator() { - { - THMp1 ht; - std::map mp; - ht.assign(mp.begin(),mp.end()); - THMp1 ht2; - ht2 = ht; - THMp1 ht3(ht); - } - { - std::map mp; - for (size_t i = 0; i < N; i ++) { - mp[key(s[i])] = int(i); - } - THMp1 ht; - ht.assign(mp.begin(),mp.end()); - THMp1 ht2; - ht2 = ht; - THMp1 ht3(ht); - for (size_t i = 0; i < N; i ++) { - value val; - value val2; - value val3; - int ret = ht.get(key(s[i]),&val); - TS_ASSERT( ret == bsl::HASH_EXIST ); - ret = ht2.get(key(s[i]),&val2); - TS_ASSERT( ret == bsl::HASH_EXIST ); - ret = ht3.get(key(s[i]),&val3); - TS_ASSERT( ret == bsl::HASH_EXIST ); - TS_ASSERT( val2 == val3 ); - TS_ASSERT( val == val2 ); - } - } - } - void test_create() { - THMp1 ht; - for (int i = 10; i < 100; i ++) { - ht.create(i); - } - THMp1 ht2; - for (int i = 0; i < 100; i ++) { - ht2 = ht; - } - } - - /** - * @brief 测试hash表的正常功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_(void) { - __BSL_DEBUG("open debug mode"); - TSM_ASSERT ("test_hashmap error", test_hashmap()); - } - /** - * @brief 测试hash表迭代器功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_iterator_(void) { - TSM_ASSERT ("", test_hashmap_iterator()); - } - - /** - * @brief 测试hash表序列化功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_serialization_(void) { - TSM_ASSERT ("", test_hashmap_serialization()); - } - - /** - * @brief 测试hash表附值功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - - void test_hashmap_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_alloc分配器 - typedef bsl::hashmap, bsl::bsl_alloc > THMp2; - void test_hashmap2_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_hashmap2_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_hashmap2_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_hashmap2_assign_() { - TSM_ASSERT("", test_hashmap_assign()); - } - void test_hashmap2_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //默认的phashmap - typedef bsl::phashmap THMp3; - void test_phashmap_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmap_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_alloc的phashmap - typedef bsl::phashmap, bsl::bsl_alloc > THMp4; - void test_phashmap2_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmap2_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap2_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap2_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap2_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_cpsalloc分配器 - typedef bsl::phashmap, bsl::bsl_cpsalloc > > THMp5; - void test_phashmap3_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmp3_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap3_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap3_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap3_clear_() { - bsl::hashmap v1; - bsl::hashmap v2; - v1.create(100); - v2.create(1000); - v1.set(1, "hello"); - v1.get(1); - v2.set(2, "hello"); - v2.get(2); - TSM_ASSERT ("", test_hashmap_clear()); - } -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_hashmap_string.h b/bsl/unittest/bsl_test_hashmap_string.h deleted file mode 100644 index e2d5d0ef1cbd153e64c0db74e4584264d17f3e3c..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_hashmap_string.h +++ /dev/null @@ -1,515 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_hashmap_string.h,v 1.2 2008/12/15 09:57:00 xiaowei Exp $ - * - * hashmap phashmap的测试代码 - * test_hashmap 测试hashmap phashmap的基本功能 - * test_hashmap_iterator 测试hashmap的迭代器功能 - * test_hashmap_serialization 测试容器的序列化功能 - * test_hashmap_assign 测试assign功能 - * test_hashmap_clear clear功能的测试 - * - * 注意:phashmap的线程安全性问题,在另外的测试文件里面单独测试 - **************************************************************************/ - -/** - * @file hashtest.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 11:10:06 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#ifndef __BSL_TEST_HASHMAP_H -#define __BSL_TEST_HASHMAP_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - -bsl::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i -bool test_hashmap() -{ - { - int loop = 1<<10; - for (int i=0; i vec; - for (int i=0; i -bool test_hashmap_iterator() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(1<<15) == 0); - - int insertsize = 1<<10; - for (int i=0; ifirst)->second == iter->second); - } - - const THMp & testp = test; - for (typename THMp::const_iterator iter = testp.begin(); iter != testp.end(); ++iter) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - testp.get(randstr()); - - size_t vsize = vec.size(); - //根据序列化参数对value进行附值 - for (typename THMp::iterator iter = test.begin(); iter != test.end(); ++iter) { - iter->second = randstr(); - vec[iter->first] = iter->second; - } - - __XASSERT(vsize == vec.size(), "%lu != %lu", (unsigned long)vsize, (unsigned long)vec.size()); - - for (typename THMp::iterator iter = test.begin(); iter != test.end(); ++iter) { - __XASSERT2 (vec.find(iter->first)->second == iter->second); - } - - //不调用destroy,自己调用析构函数析构 - //需要valgrind检查是否内存泄露 - return true; -} - -template -bool test_hashmap_serialization() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(1<<15) == 0); - int loop = 1<<12; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - bsl::string val = ""; - int ret = test.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - test.clear(); - //读硬盘到新结构体 - { - THMp test_0; - __XASSERT2 (test_0.create(100) == 0); - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::map::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - bsl::string val = ""; - int ret = test_0.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - //读硬盘到新结构体, 新结构体不初始化 - { - THMp test_0; - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::map::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - bsl::string val = ""; - int ret = test_0.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT2 (val == iter->second); - } - } - return true; -} - -//assign测试 -template -bool test_hashmap_assign() -{ - THMp test; - std::map vec; - __XASSERT2 (test.create(102400) == 0); - __BSL_DEBUG("create hashmap"); - int loop = 1<<15; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - bsl::string val = ""; - int ret = test.get(iter->first, &val); - __XASSERT2 (ret == bsl::HASH_EXIST); - __XASSERT (val == iter->second, "%s == %s", val.c_str(), iter->second.c_str()); - } - - for (int i=0; i<16; ++i) { - __XASSERT2 (test.assign(vec.begin(), vec.end()) == 0); - } - return true; -} - -template -bool test_hashmap_clear() -{ - //没有create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - for (int i=0; i<10000; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - } - //create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.create(100000) == 0); - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - //有数据的情况下clear - { - THMp test0; - typedef std::map map_t; - map_t vmap; - for (int i=0; i<10000; ++i) { - vmap.insert(std::make_pair(randstr(), randstr())); - } - __XASSERT2(test0.create(vmap.size() * 2) == 0); - for (int i=0; i<10; ++i) { - __XASSERT2(test0.assign(vmap.begin(), vmap.end()) == 0); - } - - for (int i=0; i<10; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - - for (int i=0; i<100; ++i) { - __XASSERT2(test0.destroy() == 0); - } - } - return true; -} - -class bsl_test_hashmap : public CxxTest::TestSuite -{ -public: - typedef bsl::hashmap THMp1; - /** - * @brief 测试hash表的正常功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_(void) { - __BSL_DEBUG("open debug mode"); - TSM_ASSERT ("test_hashmap error", test_hashmap()); - } - /** - * @brief 测试hash表迭代器功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_iterator_(void) { - TSM_ASSERT ("", test_hashmap_iterator()); - } - - /** - * @brief 测试hash表序列化功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_serialization_(void) { - TSM_ASSERT ("", test_hashmap_serialization()); - } - - /** - * @brief 测试hash表附值功能 - * - * @return void - * @retval - * @author xiaowei - **/ - void test_hashmap_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - - void test_hashmap_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_alloc分配器 - typedef bsl::hashmap, bsl::bsl_alloc > THMp2; - void test_hashmap2_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_hashmap2_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_hashmap2_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_hashmap2_assign_() { - TSM_ASSERT("", test_hashmap_assign()); - } - void test_hashmap2_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //默认的phashmap - typedef bsl::phashmap THMp3; - void test_phashmap_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmap_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_alloc的phashmap - typedef bsl::phashmap, bsl::bsl_alloc > THMp4; - void test_phashmap2_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmap2_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap2_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap2_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap2_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } - - //bsl_cpsalloc分配器 - typedef bsl::phashmap, bsl::bsl_cpsalloc > > THMp5; - void test_phashmap3_() { - TSM_ASSERT ("", test_hashmap()); - } - void test_phashmp3_iterator_() { - TSM_ASSERT ("", test_hashmap_iterator()); - } - void test_phashmap3_serialization_() { - TSM_ASSERT ("", test_hashmap_serialization()); - } - void test_phashmap3_assign_() { - TSM_ASSERT ("", test_hashmap_assign()); - } - void test_phashmap3_clear_() { - TSM_ASSERT ("", test_hashmap_clear()); - } -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_hashset.h b/bsl/unittest/bsl_test_hashset.h deleted file mode 100644 index 2140b4d63ba0c2b79ff36200e8aeb807d29d69a1..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_hashset.h +++ /dev/null @@ -1,501 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_hashset.h,v 1.5 2008/12/15 09:57:00 xiaowei Exp $ - * - * hashset phashset的测试代码 - * test_hashset 测试hashset phashset的基本功能 - * test_hashset_iterator 测试hashset的迭代器功能 - * test_hashset_serialization 测试容器的序列化功能 - * - * 注意:phashset的线程安全性问题,在另外的测试文件里面单独测试 - **************************************************************************/ - - - -/** - * @file settest.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 11:10:06 - * @version $Revision: 1.5 $ - * @brief - * - **/ - -#ifndef __BSL_TEST_HASHSET_H -#define __BSL_TEST_HASHSET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng"}; -const size_t N = sizeof(s) / sizeof(s[0]); - -std::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i -bool test_hashset() -{ - int ret = 0; - { - int loop = 1<<10; - for (int i=0; i vec; - for (int i=0; i -bool test_hashset_iterator() -{ - int ret = 0; - THMp test; - std::set vec; - __XASSERT2 (test.create(1<<15) == 0); - - int insertsize = 1<<10; - for (int i=0; i -bool test_hashset_serialization() -{ - THMp test; - int ret = 0; - std::set vec; - __XASSERT2 (test.create(1<<15) == 0); - int loop = 1<<12; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - ret = test.get(*iter); - __XASSERT2 (ret == bsl::HASH_EXIST); - } - } - //test.clear(); - //读硬盘到新结构体 - { - THMp test_0; - __XASSERT2 (test_0.create(100) == 0); - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::set::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - ret = test_0.get(*iter); - __XASSERT2 (ret == bsl::HASH_EXIST); - } - } - //读硬盘到新结构体, 新结构体不初始化 - { - THMp test_0; - bsl::filestream fs; - __XASSERT2 (fs.open(htdat, "r") == 0); - bsl::binarchive ar(fs); - __XASSERT2 (ar.read(&test_0) == 0); - fs.close(); - - //check - __XASSERT (vec.size() == test_0.size(), "%lu != %lu", - (unsigned long)vec.size(), (unsigned long)test_0.size()); - for (std::set::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - std::string val = ""; - ret = test_0.get(*iter); - __XASSERT2 (ret == bsl::HASH_EXIST); - } - } - return true; -} - -//assign测试 -template -bool test_hashset_assign() -{ - THMp test; - std::set vec; - __XASSERT2(test.create(1<<15) == 0); - int loop = 1<<15; - for (int i=0; i::iterator iter = vec.begin(); - iter != vec.end(); ++iter) { - int ret = test.get(*iter); - __XASSERT2(ret == bsl::HASH_EXIST); - } - return true; -} - -template -bool test_hashset_clear() -{ - //没有create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - for (int i=0; i<10000; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - } - //create的情况下clear - { - THMp test0; - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.create(100000) == 0); - __XASSERT2(test0.size() == 0); - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - //有数据的情况下clear - { - THMp test0; - typedef std::set map_t; - map_t vmap; - for (int i=0; i<10000; ++i) { - vmap.insert(randstr()); - } - __XASSERT2(test0.create(vmap.size() * 2) == 0); - for (int i=0; i<10; ++i) { - __XASSERT2(test0.assign(vmap.begin(), vmap.end()) == 0); - } - - for (int i=0; i<10; ++i) { - __XASSERT2(test0.clear() == 0); - __XASSERT2(test0.size() == 0); - } - - for (int i=0; i<100; ++i) { - __XASSERT2(test0.destroy() == 0); - } - } - return true; -} - -class bsl_test_hashmap : public CxxTest::TestSuite -{ -public: - typedef std::string key; - typedef bsl::hashset THMp1; - - void test_operator() { - { - THMp1 ht; - std::set st; - ht.assign(st.begin(),st.end()); - THMp1 ht2; - ht2 = ht; - THMp1 ht3(ht); - } - { - std::set st; - for (size_t i = 0; i < N; i ++) { - st.insert( key(s[i] ) ); - } - THMp1 ht; - ht.assign(st.begin(),st.end()); - THMp1 ht2; - ht2 = ht; - THMp1 ht3(ht); - for (size_t i = 0; i < N; i ++) { - int ret = ht.get(key(s[i])); - TS_ASSERT( ret == bsl::HASH_EXIST ); - ret = ht2.get(key(s[i])); - TS_ASSERT( ret == bsl::HASH_EXIST ); - ret = ht3.get(key(s[i])); - TS_ASSERT( ret == bsl::HASH_EXIST ); - } - } - } - void test_create() { - THMp1 ht; - for (int i = 10; i < 100; i ++) { - ht.create(i); - } - THMp1 ht2; - for (int i = 0; i < 100; i ++) { - ht2 = ht; - } - } - void test_test_hashset_(void) { - __BSL_DEBUG("open debug mode"); - TSM_ASSERT ("", test_hashset()); - } - void test_hashset_iterator_() { - TSM_ASSERT ("", test_hashset_iterator()); - } - void test_hashset_serialization_() { - TSM_ASSERT ("", test_hashset_serialization()); - } - void test_hashset_assign_() { - TSM_ASSERT ("", test_hashset_assign()); - } - void test_hashset_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - - typedef bsl::hashset, - bsl::bsl_alloc > THMp2; - void test_hashset2_() { - TSM_ASSERT ("", test_hashset()); - } - void test_hashset2_iterator_() { - TSM_ASSERT ("", test_hashset_iterator()); - } - void test_hashset2_serialization_() { - TSM_ASSERT ("", test_hashset_serialization()); - } - void test_hashset2_assign_() { - TSM_ASSERT ("", test_hashset_assign()); - } - void test_hashset2_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - - typedef bsl::phashset THMp3; - void test_phashset_() { - TSM_ASSERT ("", test_hashset()); - } - void test_phashset_iterator_() { - TSM_ASSERT ("", test_hashset_iterator()); - } - void test_phashset_serialization_() { - TSM_ASSERT ("", test_hashset_serialization()); - } - void test_phashset_assign_() { - TSM_ASSERT ("", test_hashset_assign()); - } - void test_phashset_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - - typedef bsl::phashset, - bsl::bsl_alloc > THMp4; - void test_phashset2_() { - TSM_ASSERT ("", test_hashset()); - } - void test_phashset2_iterator_() { - TSM_ASSERT ("", test_hashset_iterator()); - } - void test_phashset2_serialization() { - TSM_ASSERT ("", test_hashset_serialization()); - } - void test_phashset2_assign_() { - TSM_ASSERT ("", test_hashset_assign()); - } - void test_phashset2_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - - typedef bsl::bsl_rwhashset, - bsl::bsl_alloc > THMp5; - void test_rwhashset_() { - TSM_ASSERT ("", test_hashset()); - } - void test_rwhashset_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - - typedef bsl::phashset, - bsl::bsl_cpsalloc > > THMp6; - void test_phashset3_() { - TSM_ASSERT ("", test_hashset()); - } - void test_phashset3_iterator_() { - TSM_ASSERT ("", test_hashset_iterator()); - } - void test_phashset3_serialization() { - TSM_ASSERT ("", test_hashset_serialization()); - } - void test_phashset3_assign_() { - TSM_ASSERT ("", test_hashset_assign()); - } - void test_phashset3_clear_() { - TSM_ASSERT ("", test_hashset_clear()); - } - -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_hashtable.h b/bsl/unittest/bsl_test_hashtable.h deleted file mode 100644 index 1aaf6fe9c61e859d6d73c9fe760aa87a254f487e..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_hashtable.h +++ /dev/null @@ -1,204 +0,0 @@ - -#ifndef __BSL_TEST_HASHTABLE_H -#define __BSL_TEST_HASHTABLE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng" -}; - -const size_t N = sizeof(s) / sizeof(s[0]); - - -std::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i, - bsl::param_select,bsl::bsl_sample_alloc, 256> > hash_type; - - void test_hashtable() { - - { - hash_type ht; - TS_ASSERT( 0 == ht.create(100)); - TS_ASSERT( true == ht.is_created() ); - - hash_type::const_iterator cit = ht.begin(); - ++cit; - cit++; - - hash_type::iterator it = ht.begin(); - ++it; - it++; - - const hash_type cht; - TS_ASSERT(false == cht.is_created()); - hash_type::const_iterator cht_cit= cht.begin(); - ++cht_cit; - cht_cit++; - } - { - try { - hash_type ht; - hash_type ht1; - ht = ht1; - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - } - } - { - try { - hash_type ht; - hash_type ht1(ht); - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - } - } - - //added 2011/11/15 - { - try{ - hash_type ht; - hash_type ht1(ht); - std::string key1("what"); - ht1.set(ht1._hashfun(key1),key1,key1); - } catch (bsl::Exception& e) { - printf("-------------------new\n\n==\n%s\n==\n",e.all()); - } - } - - //added 2011/11/15 - { - try{ - hash_type ht; - ht.create(10); - hash_type ht1(ht); - - std::string key1("what"); - ht1.set(ht1._hashfun(key1),key1,key1); - } catch (bsl::Exception& e) { - printf("-------------------new\n\n==\n%s\n==\n",e.all()); - } - } - - //added 2011/11/15 - { - try{ - hash_type ht; - ht.create(10); - hash_type ht1; - ht1.create(5); - ht1 = ht; - - std::string key1("what"); - ht1.set(ht1._hashfun(key1),key1,key1); - } catch (bsl::Exception& e) { - printf("-------------------new\n\n==\n%s\n==\n",e.all()); - } - } - - { - try { - printf("hello\n"); - hash_type ht(0); - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - printf("world\n"); - } - } - { - try { - hash_type ht(1000); - hash_type ht1(ht); - hash_type ht2 = ht; - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - } - } - { - hash_type ht(100); - std::set st; - ht.assign(st.begin(),st.end()); - } - { - std::set st; - for (size_t i = 0; i < N; i ++) { - st.insert(s[i]); - } - hash_type ht(100); - ht.assign(st.begin(),st.end()); - TS_ASSERT( ht.size() == N ); - - hash_type ht2 = ht; - TS_ASSERT( ht2.size() == N ); - hash_type ht3; - ht3 = ht; - TS_ASSERT( ht3.size() == N ); - - for (size_t i = 0; i < N; i ++) { - TS_ASSERT( ht.find( ht._hashfun( s[i] ), s[i] ) != NULL ); - TS_ASSERT( ht2.find( ht2._hashfun( s[i] ), s[i] ) != NULL ); - TS_ASSERT( ht3.find( ht3._hashfun( s[i] ), s[i] ) != NULL ); - } - } - - } - - void test_create() { - hash_type ht; - for (int i = 10; i < 100; i ++) { - ht.create(i); - } - hash_type ht2; - for (int i = 0; i < 100; i ++) { - ht2 = ht; - } - } -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_header.h b/bsl/unittest/bsl_test_header.h deleted file mode 100644 index c9c4f1c900c579e27d895938416261c5ff37bf74..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_header.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_header.h,v 1.2 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_header.h - * @author xiaowei(com@baidu.com) - * @date 2009/01/13 11:42:52 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_HEADER_H_ -#define __BSL_TEST_HEADER_H_ - - -#include "bsl/deque.h" -#include "bsl/list.h" -#include "bsl/map.h" -#include "bsl/pool.h" -#include "bsl/set.h" - -class bsl_test_header : public CxxTest::TestSuite -{ -public: - void test_header_t() { - } -}; - - - - - - - - - - - - - - - - -#endif //__BSL_TEST_HEADER_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_list.h b/bsl/unittest/bsl_test_list.h deleted file mode 100644 index e5143436c4510d2e1e95e16c447d827279223fa8..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_list.h +++ /dev/null @@ -1,903 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -class p -{ -public: - bool operator()(int q) - { - return q==50; - } -}; -class tt{ - public: - int i; - tt(int t):i(t){} -}; - -std::string rand_string() -{ - std::string str; - //srand(time(NULL)); - int n = rand()%10 + 1; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -class bsl_test_list : public CxxTest::TestSuite -{ -public: - void test_operator() - { - { - bsl::list l1; - bsl::list l2; - l1.create(); - l2.create(); - l1.insert( l1.begin(), l2.begin(), l2.begin() ); - - TS_ASSERT(0 == l1.size()); - TS_ASSERT(0 == l2.size()); - - TS_ASSERT( 0 != l1.erase( l1.begin() ) ); - TS_ASSERT( l1.begin() == l1.end() ); - TS_ASSERT( l2.begin() == l2.end() ); - - l1.insert( l1.begin(), l1.begin(), l1.end() ); - l1.insert( l1.begin(), 0, 1 ); - TS_ASSERT(0 == l1.size()); - } - { - bsl::list l1; - bsl::list l2; - l1.assign(l2.begin(),l2.end()); - } - { - bsl::list t1; - for (int i = 0; i < 100; i ++) { - t1.push_back(i); - } - TS_ASSERT( 100 == t1.size() ); - bsl::list t2; - t2 = t1; - TS_ASSERT( 100 == t1.size() ); - TS_ASSERT( 100 == t2.size() ); - int i = 0; - for (bsl::list::iterator Iter = t2.begin(); Iter != t2.end(); ++ Iter) { - TS_ASSERT( *Iter == i ++ ); - } - i = 0; - t1 = t1; - TS_ASSERT( 100 == t1.size() ); - for (bsl::list::iterator Iter = t1.begin(); Iter != t1.end(); ++ Iter) { - TS_ASSERT( *Iter == i ++ ); - } - - bsl::list t3; - t3.push_back(1); - TS_ASSERT( 1 == *t3.begin() ); - bsl::list t5; - - bsl::list t4; - t4 = t3; - TS_ASSERT( 1 == t4.size() ); - TS_ASSERT( 1 == t3.size() ); - - t3.pop_back(); - t3 = t5; - TS_ASSERT( 0 == t3.size() ); - - t1 = t3; - TS_ASSERT( 0 == t1.size() ); - TS_ASSERT( 0 == t3.size() ); - - //added 2011/11/17 - bsl::list t6; - bsl::list t7; - for(i=0;i<100;i++) - { - t7.push_back(i); - } - t6.push_back(1000); - t6 = t7; - bsl::list::iterator it = t6.begin(); - for(i=0;i<200;i++) - { - if(i == 100) - { - ++ it; - continue; - } - int j = i;; - if(i>100) - { - j = i-1; - } - TS_ASSERT( j%100 == *it ); - //printf(" %d %d ",j,*it); - ++ it; - } - //printf("\n"); - bsl::list::reverse_iterator it2 = t6.rbegin(); - for(i=0;i<200;i++) - { - if(i == 100) - { - ++ it2; - continue; - } - int j = i; - if(i>100) - { - j = i-1; - } - TS_ASSERT( 99-j%100 == *it2 ); - //printf(" %d %d ",j,*it2); - ++ it2; - } - //printf("\n"); - } - { - bsl::list l1; - bsl::list l2; - for (int i = 0; i < 10; i ++) { - l1.push_front( rand_string() ); - } - TS_ASSERT( 10 == l1.size() ); - for (int i = 0; i < 100; i ++) { - l2 = l1; - } - TS_ASSERT( 10 == l1.size() ); - TS_ASSERT( 10 == l2.size() ); - bsl::list::iterator iter = l1.begin(); - bsl::list::iterator iter2 = l2.begin(); - for( ; iter != l1.end(); ++ iter, ++ iter2) { - TS_ASSERT( (*iter) == (*iter2) ); - } - } - { - bsl::list l1; - for (int i = 0; i < 100; i ++) { - l1.push_back(i); - } - TS_ASSERT( 100 == l1.size() ); - bsl::list l2; - for (int i = 10; i > 0; i --) { - l2.push_back(i); - } - TS_ASSERT( 10 == l2.size() ); - l2 = l1; - TS_ASSERT( 100 == l1.size() ); - TS_ASSERT( 100 == l2.size() ); - int i = 0; - for (bsl::list::iterator iter = l2.begin(); iter != l2.end(); ++ iter, i ++) { - TS_ASSERT( *iter == i ); - } - } - } - void test_create() - { - bsl::list l1; - int i; - for (i = 0; i < 10000; i ++) { - l1.create(); - } - for (i = 0; i < 10000; i ++) { - l1.create(); - } - bsl::list l2; - TS_ASSERT(0 == l2.size()); - for (i = 0; i < 10000; i ++) { - l2.create(); - } - TS_ASSERT( 0 == l2.size()); - for (i = 0; i < 100; i ++) { - l2.push_back(i); - } - TS_ASSERT( 100 == l2.size() ); - } - void test_string() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t1.push_front(std::string("123"))); - TS_ASSERT(!t1.push_front(std::string("abc"))); - TS_ASSERT(!t1.push_front(std::string("ABC"))); - TS_ASSERT(3 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - void test_push_front() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT_EQUALS(t1.size() , 100); - bsl::list::iterator i = t1.begin(); - for(int v = 99; v >= 1; v--) - { - TS_ASSERT_EQUALS(*i , v); - i++; - } - TS_ASSERT(!t1.destroy()); - } - - void test_push_front1() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(tt(i))); - } - TS_ASSERT_EQUALS(t1.size() , 100); - bsl::list::iterator i = t1.begin(); - for(int v = 99; v >= 1; v--) - { - TS_ASSERT_EQUALS(i->i , v); - i++; - } - TS_ASSERT(!t1.destroy()); - } - - void test_push_back() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_back(i)); - } - TS_ASSERT_EQUALS(t1.size() , 100); - bsl::list::iterator i = t1.begin(); - for(int v=0; v<100; v++) - { - TS_ASSERT_EQUALS(*i , v); - i++; - } - TS_ASSERT(!t1.destroy()); - } - - void test_assign1() - { - bsl::list t1, t2; - TS_ASSERT(!t1.create()); - for (int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - TS_ASSERT(!t2.create()); - t2.assign(t1); - TS_ASSERT(100 == t2.size()); - bsl::list::iterator i = t2.begin(); - for(int v=99; v>=1; v--) - { - TS_ASSERT_EQUALS(*i , v); - i++; - } - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - void test_assign() - { - bsl::list t1, t2; - TS_ASSERT(!t1.create()); - for (int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(!t2.create()); - TS_ASSERT(0 == t2.size()); - t2.assign(t1.begin(), t1.end()); - TS_ASSERT(100 == t2.size()); - bsl::list::iterator i = t2.begin(); - for(int v=99; v>=1; v--) - { - TS_ASSERT_EQUALS(*i , v); - i++; - } - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - - void test_pop_front() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(0 == t1.size()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - TS_ASSERT(0 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - - - void test_pop_back() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(0 == t1.size()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - for(int i=0; i<100; i++) - { - // printf("%d\n", t1.back()); - TS_ASSERT_EQUALS(i , t1.back()); - t1.pop_back(); - } - TS_ASSERT(0 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - - void test_sort() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(rand())); - // TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - t1.sort(); - TS_ASSERT_EQUALS(t1.size() , 100); - //int tmp = 0x7fffffff; - for(bsl::list::iterator i1 = t1.begin(); i1!=t1.end(); ++i1) - { - // TS_ASSERT(tmp > *i1); - // printf("%d\n", *i1); - /* if( *i1 != v) - { - printf("%d, %d",*i1, v); - ERROR(); - } - v--;*/ - } - TS_ASSERT(100 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - - void test_remove() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.remove(50); - TS_ASSERT_EQUALS(t1.size(), 99); - TS_ASSERT(!t1.destroy()); - } - - void test_remove1() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(!t1.remove_if(p())); - TS_ASSERT_EQUALS(t1.size(), 99); - TS_ASSERT(!t1.destroy()); - } - - - void test_const() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - const bsl::list & t2 = t1; - int p = 1; - TS_ASSERT_EQUALS(t2.back() , 100); - TS_ASSERT_EQUALS(t2.front() , 1); - - p = 1; - for(bsl::list::const_iterator i1 = t2.begin(); i1!=t2.end(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - p = 1; - for(bsl::list::const_iterator i1 = t1.begin(); i1!=t1.end(); i1++) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - - TS_ASSERT(!t1.destroy()); - p = 100; - for(bsl::list::const_reverse_iterator i1 = t2.rbegin(); i1!=t2.rend(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - p = 100; - for(bsl::list::const_reverse_iterator i1 = t1.rbegin(); i1!=t1.rend(); i1++) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - - } - void test_const2() - { - bsl::list::const_iterator i = bsl::list::iterator(); - bsl::list::const_reverse_iterator p = bsl::list::reverse_iterator(); - } - - void test_forward_iterator() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(t1.begin() != t1.end()); - TS_ASSERT(t1.begin() == t1.begin()); - TS_ASSERT(t1.end() == t1.end()); - int p = 1; - for(bsl::list::iterator i1 = t1.begin(); i1!=t1.end(); i1++) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - p = 1; - for(bsl::list::iterator i1 = t1.begin(); i1!=t1.end(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - - p = 100; - bsl::list::iterator i1; - for(i1 = --(t1.end()); i1!=t1.begin(); i1--) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - p = 100; - for(i1 = --(t1.end()); i1!=t1.begin(); --i1) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - TS_ASSERT(!t1.destroy()); - - } - void test_reverse_iterator() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(t1.rbegin() != t1.rend()); - TS_ASSERT(t1.rbegin() == t1.rbegin()); - TS_ASSERT(t1.rend() == t1.rend()); - int p = 100; - for(bsl::list::reverse_iterator i1 = t1.rbegin(); i1!=t1.rend(); i1++) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - p = 100; - for(bsl::list::reverse_iterator i1 = t1.rbegin(); i1!=t1.rend(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - p = 1; - bsl::list::reverse_iterator i1; - for( i1 = --(t1.rend()); i1!=t1.rbegin(); i1--) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - p = 1; - for( i1 = --(t1.rend()); i1!=t1.rbegin(); --i1) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - - TS_ASSERT(!t1.destroy()); - - } - - void test_reverse() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.reverse(); - TS_ASSERT_EQUALS(t1.size() , 100); - int p = 100; - for(bsl::list::iterator i1 = t1.begin(); i1!=t1.end(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p--; - } - TS_ASSERT(100 == t1.size()); - TS_ASSERT(!t1.destroy()); - - } - - void test_swap() - { - //bsl::list > t1; - //bsl::list > t1; - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - t2.swap(t1); - TS_ASSERT_EQUALS(t2.size() , 100); - TS_ASSERT_EQUALS(t1.size() , 0); - t1.swap(t2); - TS_ASSERT_EQUALS(t2.size() , 0); - TS_ASSERT_EQUALS(t1.size() , 100); - for(int i=0; i<50; i++) - { - TS_ASSERT(!t2.push_front(3 * i)); - } - t2.swap(t1); - TS_ASSERT_EQUALS(t1.size() , 50); - TS_ASSERT_EQUALS(t2.size() , 100); - //bsl::list::iterator i = t1.begin(); - bsl::list::iterator i = t1.begin(); - //bsl::list::iterator p = t2.begin(); - bsl::list::iterator p = t2.begin(); - /*for(int v = 50; v >= 1; v--) - { - TS_ASSERT_EQUALS(*i , 3 * v); - i++; - TS_ASSERT_EQUALS(*p , v); - p++; - }*/ - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - void test_merge() - { - //bsl::list > t1; - //bsl::list > t1; - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - t2.merge(t1); - TS_ASSERT_EQUALS(t2.empty() , true); - for(int i=49; i>=0; i--) - { - TS_ASSERT(!t1.push_front(2*i)); - } - TS_ASSERT_EQUALS(t2.size() , 0); - t2.merge(t1); - TS_ASSERT_EQUALS(t2.size() , 50); - for(int i=49; i>=0; i--) - { - TS_ASSERT(!t1.push_front(2*i+1)); - } - t2.merge(t1); - TS_ASSERT_EQUALS(t1.empty() , true); - TS_ASSERT_EQUALS(t2.size() , 100); - TS_ASSERT(!t1.destroy()); - bsl::list::iterator p = t2.begin(); - for(int v = 0; v < 100; v++) - { - TS_ASSERT_EQUALS(*p , v); - p++; - } - TS_ASSERT(!t2.destroy()); - } - - void test_insert() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t1.insert(t1.begin(),1)); - TS_ASSERT(!t1.insert(t1.end(),2)); - TS_ASSERT_EQUALS(t1.size() , 2); - TS_ASSERT_EQUALS(t1.front() , 1); - TS_ASSERT_EQUALS(t1.back() , 2); - - bsl::list t2; - TS_ASSERT(!t2.insert(t1.begin(), 0)); - TS_ASSERT_EQUALS(t2.size() , 0); - TS_ASSERT_EQUALS(t1.size() , 3); - TS_ASSERT_EQUALS(t1.front() , 0); - TS_ASSERT_EQUALS(t1.back() , 2); - - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - - void test_insert2() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t1.insert(t1.begin(),2, 1)); - TS_ASSERT(!t1.insert(t1.end(),2, 2)); - //printf("%d\n", t1.size()); - TS_ASSERT_EQUALS(t1.size() , 4); - TS_ASSERT_EQUALS(t1.front() , 1); - TS_ASSERT_EQUALS(t1.back() , 2); - TS_ASSERT(!t1.destroy()); - } - - void test_insert3() - { - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - TS_ASSERT(!t2.push_front(2 * i)); - } - t1.insert(t1.end(),t2.begin(), t2.end()); - TS_ASSERT_EQUALS(t1.size() , 200); - - t2.insert(t1.end(),t2.begin(), t2.end()); - TS_ASSERT_EQUALS(t1.size() , 300); - - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - void test_size() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - const size_t N = 1000000; - for(size_t i=0; i t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - - } - TS_ASSERT(!t1.resize(200, 10)); - TS_ASSERT_EQUALS(t1.size() , 200); - TS_ASSERT_EQUALS(t1.back() , 10); - TS_ASSERT(!t1.resize(100)); - TS_ASSERT_EQUALS(t1.size() , 100); - TS_ASSERT_EQUALS(t1.back(), 0); - } - void test_splice() - { - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<30; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - for(int i=30; i<50; i++) - { - TS_ASSERT(!t2.push_front(i)); - } - t1.splice(t1.begin(), t2); - for(int i=50; i<100; i++) - { - TS_ASSERT(!t2.push_front(i)); - } - t2.splice(t1.begin(), t2); - - TS_ASSERT_EQUALS(t1.size(), 100); - TS_ASSERT_EQUALS(t2.size(), 0); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - TS_ASSERT(!t1.destroy()); - } -#if 0 - void 1test_splice1() - { - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<50; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - for(int i=50; i<100; i++) - { - TS_ASSERT(!t2.push_front(i)); - } - t1.splice(t1.begin(), t2, t2.begin()); - TS_ASSERT_EQUALS(t1.size(), 51); - TS_ASSERT_EQUALS(t2.size(), 49); - TS_ASSERT(!t1.destroy()); - - } - void 1test_splice2() - { - bsl::list t1; - bsl::list t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<50; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - for(int i=50; i<100; i++) - { - TS_ASSERT(!t2.push_front(i)); - } - t1.splice(t1.begin(), t2, t2.begin(), t2.end()); - TS_ASSERT_EQUALS(t1.size(), 100); - TS_ASSERT_EQUALS(t2.size(), 0); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - TS_ASSERT(!t1.destroy()); - - } -#endif - void test_erase() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.erase(t1.begin()); - TS_ASSERT_EQUALS(t1.size(), 99); - for(int i=98; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - TS_ASSERT(!t1.destroy()); - } - - void test_erase1() - { - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - bsl::list t2=t1; - TS_ASSERT(100 == t2.size()); - t1.erase(t2.begin(), t2.end()); - TS_ASSERT(100 == t1.size()); - TS_ASSERT(0 == t2.size()); - - t1.erase(t1.begin(), t1.end()); - TS_ASSERT_EQUALS(t1.size(), 0); - TS_ASSERT(!t1.destroy()); - } - void test_serialization() - { - - bsl::list t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - - bsl::filestream fd; - fd.open("data", "w"); - fd.setwbuffer(1<<20); - bsl::binarchive ar(fd); - TS_ASSERT (ar.write(t1) == 0); - fd.close(); - - t1.clear(); - TS_ASSERT_EQUALS(t1.size(), 0); - std::string str; - fd.open("data", "r"); - { - bsl::binarchive ar(fd); - TS_ASSERT (ar.read(&t1) == 0); - fd.close(); - } - TS_ASSERT_EQUALS(t1.size(), 100); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - } - void test_iterator(){ - { - //non-const - bsl::list li; - - bsl::list::iterator it1 = li.begin(); - bsl::list::iterator it2 = li.end(); - TS_ASSERT(it1 == it2); - - bsl::list::reverse_iterator rit1 = li.rbegin(); - bsl::list::reverse_iterator rit2 = li.rend(); - TS_ASSERT(rit1 == rit2); - - bsl::list::const_iterator cit1 = li.begin(); - bsl::list::const_iterator cit2 = li.end(); - TS_ASSERT(cit1 == cit2); - - bsl::list::const_reverse_iterator rcit1 = li.rbegin(); - bsl::list::const_reverse_iterator rcit2 = li.rend(); - TS_ASSERT(rcit1 == rcit2); - } - { - //const - const bsl::list li; - - bsl::list::const_iterator cit1 = li.begin(); - bsl::list::const_iterator cit2 = li.end(); - TS_ASSERT(cit1 == cit2); - - bsl::list::const_reverse_iterator rcit1 = li.rbegin(); - bsl::list::const_reverse_iterator rcit2 = li.rend(); - TS_ASSERT(rcit1 == rcit2); - } - } -}; diff --git a/bsl/unittest/bsl_test_memcpy.h b/bsl/unittest/bsl_test_memcpy.h deleted file mode 100644 index 96bd48ee775b0c1bfdf506f7ec29e68a039c7e3d..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_memcpy.h +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_memcpy.h,v 1.2 2009/04/07 06:35:53 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_memcpy.h - * @author xiaowei(com@baidu.com) - * @date 2009/01/06 19:01:23 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_MEMCPY_H_ -#define __BSL_TEST_MEMCPY_H_ - -#include -#include -#include "bsl/utils/bsl_memcpy.h" -#include -#include - -int test1() -{ - { - char buf[1024], ds[1024]; - for (int i=0; i<(int)sizeof(buf); ++i) { - buf[i] = 'a'; - ds[i] = 'z'-i%26; - } - for (int i=0; i<1024; ++i) { - bsl::xmemcpy(buf, ds, i); - for (int j=0; j -#include -#include -#include -#include - -#include -#include -#include - -#define ALLOC(type) bsl::pool_allocator -#define VECTOR(type) std::vector -#define MAP(key, value) \ - std::map, ALLOC(value) > - - -class bsl_test_mempool_stable : public CxxTest::TestSuite -{ -public: - void test_normal() - { - bsl::xcompool stlp; - stlp.create(1<<16); - - - bsl::xcompool pool; - pool.create(); - - - for (int idx=0; idx<3; ++idx) { - { - ALLOC(void *) ap(&stlp); - VECTOR(void *) vec (ap); - ALLOC(size_t) sp(&stlp); - std::less eq; - MAP(void *, size_t) vmp(eq, sp); - - long total = 0; - for (int i=0; i<1<<16; ++i) { - int lp = rand()%100; - for (int j=0; j 0) { - if (vec.size() == 0) break; - rel -= vmp[vec.back()]; - pool.free (vec.back(), vmp[vec.back()]); - vec.pop_back(); - } - } - } - - stlp.clear(); - pool.clear(); - - std::cout< eq; - MAP(void *, size_t) vmp(eq, sp); - - long total = 0; - for (int i=0; i<1<<16; ++i) { - int lp = rand()%100; - for (int j=0; j 0) { - if (vec.size() == 0) break; - rel -= vmp[vec.back()]; - pool.free (vec.back(), vmp[vec.back()]); - vec.pop_back(); - } - } - } - - std::cout< - -static const int DATANUM = 100000; - -///////////// -/** - * 测试多线程的读写安全情况 - * 这个case测试两个hash表, - * 一个是phash,一个是rwhash - */ -template -void * __test_phashmap_fun_query(void *param) -{ - auto_timer t("query time at one thread"); - HASH * test = (HASH *)param; - __XASSERT2(test!=NULL); - int qloop = DATANUM / 20; - for (int i=0; iget(str, &val); - if (ret == bsl::HASH_EXIST) { - __XASSERT2_R(str == val); - } - } - - return NULL; -} -template -void * __test_phashmap_fun_update(void *param) -{ - //auto_timer t("update time at one thread"); - HASH *test = (HASH *)param; - __XASSERT2(test!=NULL); - int uloop = DATANUM; - for (int i=0; iset(s1, s1) != -1); - test->erase(randstr()); - } - return NULL; -} - - -template -bool test_phashmap() -{ - return test_phashmap_temp(20, __test_phashmap_fun_query, - 1, __test_phashmap_fun_update); -} - -//测试在写情况下dump数据问题 -template -void * __test_cp_fun1(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2(test != NULL); - int result = 0; - int loop = 1000; - for (int i=0; imake_checkpoint(); - if(res==0){ - result++; - } - test->set(int2str(i),"100"); - //test->end_checkpoint(); - //test->get(int2str(i+1000)); - } - printf("\n\nstart_checkpoint result = %d\n",result); - return NULL; -} -template -void * __test_cp_fun2(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2(test != NULL); - int loop = 1000; - int result = 0; - for (int i=0; iend_checkpoint(); - if(res==0){ - result++; - } - test->get(int2str(i)); - //test->make_checkpoint(); - test->erase(int2str(i)); - } - printf("\n\nend_checkpoint result = %d\n",result); - return NULL; -} - -template -bool test_phashmap_cp1() -{ - return test_phashmap_temp(10, __test_cp_fun1, - 10, __test_cp_fun2); -} - - - -//测试在写情况下dump数据问题 -template -void * __test_cp_fun3(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - int num = DATANUM; - for (int i=0; iset(int2str(i), int2str(i)) == bsl::HASH_INSERT_SEC); - } - { - auto_timer t("make checkpoint"); - __XASSERT2_R(test->make_checkpoint() == 0); - } - for (int i=0; iset(int2str(i), int2str(num/2 - i), 1) == bsl::HASH_OVERWRITE); - } -#if 0 - //check - for (int i=0; iget(int2str(i), &val) == bsl::HASH_EXIST); - __XASSERT2_R(val == int2str(num/2 - i)); - } - __BSL_ERROR("start to erase"); -#endif - for (int i=0; ierase(int2str(i)) == bsl::HASH_EXIST, "erase %d %d", i, - test->dumpstatus()); - } - for (int i=0; iset(int2str(i), int2str(num - i)) == bsl::HASH_INSERT_SEC); - } - return NULL; -} -template -void * __test_cp_fun4(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - while (test->dumpstatus() == bsl::PHASH_NORMAL) { - struct timespec tv; - tv.tv_sec = 0; - tv.tv_nsec = 10 * 1000; - - nanosleep(&tv, NULL); - } - bsl::filestream fd; - __XASSERT2_R(fd.open("phash.dat.1", "w") == 0); - bsl::binarchive ar(fd); - __XASSERT2_R(ar.write(*test) == 0); - fd.close(); - - __XASSERT2_R(fd.open("phash.dat.1", "r") == 0); - bsl::binarchive ar2(fd); - HASH test2; - __XASSERT2_R(ar.read(&test2) == 0); - fd.close(); - - int num = DATANUM; - __BSL_DEBUG("---------start to check size %d", (int)test2.size()); - for (int i=0; i -void * __test_cp_fun5(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - int loop = DATANUM / 20; - for (int i=0; iget(int2str(i)); - } - return NULL; -} - -template -bool test_phashmap_cp2() -{ - return test_phashmap_temp(1, __test_cp_fun3, - 1, __test_cp_fun4, 20, __test_cp_fun5); -} - - -template -void inc_node(_T* v, void* /*args = NULL*/){ - *v += _I; -} - -template -class IncNode{ -public: - void operator()(_T* v, void* /*args = NULL*/){ - *v += _I; - } -}; - -template -void* update_func(void* args){ - HASH *ht = (HASH *)args; - for(int i = 0; i < 1000; ++i){ - for(int j = 0; j < 100; ++j){ - TS_ASSERT(ht->get(i, NULL, inc_node) == bsl::HASH_EXIST); - } - for(int j = 0; j < 100; ++j){ - TS_ASSERT(ht->get(i, NULL, IncNode()) == bsl::HASH_EXIST); - } - } - return NULL; -} - - - -class bsl_test_phashmap : public CxxTest::TestSuite -{ -public: - typedef bsl::phashmap type1_t; - void test_phashmap_(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - - typedef bsl::phashmap, - bsl::bsl_alloc > type2_t; - void test_phashmap_2(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_2() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_2() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - - /// - typedef bsl::phashmap, - bsl::bsl_cpsalloc > > type3_t; - void test_phashmap_3(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_3() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_3() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - - void test_get_callback(){ - typedef int _Key; - typedef int _Value; - typedef bsl::phashmap<_Key, _Value> hash_type; - - hash_type ht; - int hash_num = 1333; - int n = 1000; - const int INC = 1000; - - TS_ASSERT(ht.create(hash_num) == 0); - for(int i = 0; i < n; ++i){ - ht.set(i, 0); - } - TS_ASSERT((int)ht.size() == n); - - for(int i = 0; i < n; ++i){ - _Value old_val; - TS_ASSERT(ht.get(i, &old_val, inc_node) == bsl::HASH_EXIST); - TS_ASSERT(old_val == 0); - TS_ASSERT(ht.get(i, &old_val) == bsl::HASH_EXIST); - TS_ASSERT(old_val == INC); - TS_ASSERT((int)ht.size() == n); - } - - ht.clear(); - TS_ASSERT(ht.create(hash_num) == 0); - for(int i = 0; i < n; ++i){ - ht.set(i, 0); - } - TS_ASSERT((int)ht.size() == n); - - for(int i = 0; i < n; ++i){ - _Value old_val; - TS_ASSERT(ht.get(i, &old_val, IncNode()) == bsl::HASH_EXIST); - TS_ASSERT(old_val == 0); - TS_ASSERT(ht.get(i, &old_val) == bsl::HASH_EXIST); - TS_ASSERT(old_val == INC); - TS_ASSERT((int)ht.size() == n); - } - return; - } - - void test_get_callback_multithread(){ - typedef int _Key; - typedef int _Value; - typedef bsl::phashmap<_Key, _Value> hash_type; - - int rep = 20; - while(rep--){ - int hash_num = 1333; - hash_type ht; - TS_ASSERT(ht.create(hash_num) == 0); - int n = 1000; - for(int i = 0; i < n; ++i){ - ht.set(i, 0); - } - //check - TS_ASSERT((int)ht.size() == n); - for(int i = 0; i < n; ++i){ - hash_type::value_type val; - TS_ASSERT(ht.get(i, &val) == bsl::HASH_EXIST); - TS_ASSERT(val == 0); - } - int pn = 50; - std::vector pids(pn); - for(int i = 0; i < pn; ++i){ - TS_ASSERT(pthread_create(&pids[i], NULL, update_func, &ht) == 0); - } - for(int i = 0; i < pn; ++i){ - pthread_join(pids[i], NULL); - } - //check - TS_ASSERT((int)ht.size() == n); - for(int i = 0; i < n; ++i){ - hash_type::value_type val; - TS_ASSERT(ht.get(i, &val) == bsl::HASH_EXIST); - TS_ASSERT(val == pn * 100 * 2); - } - } - return; - } -}; - -#endif //__BSL_TEST_PHASHMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_phashmap_dump.h b/bsl/unittest/bsl_test_phashmap_dump.h deleted file mode 100644 index 48f36dba97a42c43f3dffd2bb2f40846f2aa22e7..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_phashmap_dump.h +++ /dev/null @@ -1,152 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_phashmap_dump.h,v 1.1 2008/11/17 05:39:51 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_phashmap_dump.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/17 11:19:15 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_PHASHMAP_DUMP_H_ -#define __BSL_TEST_PHASHMAP_DUMP_H_ - -#include - -const int DATANUM = 1<<20; -const char *g_dumpfile = "bsl_test_phashmap_dump.dat"; - -template -void * __query__(void *param) -{ - auto_timer t("query time at one thread"); - HASH *test = (HASH *)param; - - for (int i=0; iget(str, &val); - if (ret == bsl::HASH_EXIST) { - __XASSERT2_R(str == val); - } - } - - return NULL; -} - -std::set g_set; - -#include -pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t g_cond = PTHREAD_COND_INITIALIZER; - -static bool g_flagrun = true; - -template -void * __update__(void *param) -{ - auto_timer t("update time"); - HASH *test = (HASH *)param; - - for (int i=0; iset(str, str); - } - - fprintf(stderr, "start to checkpoint\n"); - pthread_mutex_lock (&g_lock); - if (test->make_checkpoint() != 0) { - g_flagrun = false; - } - fprintf(stderr, "singal post %d\n", (int)g_flagrun); - pthread_cond_signal(&g_cond); - pthread_mutex_unlock(&g_lock); - - __XASSERT2_R(g_flagrun); - - fprintf(stderr, "inserrt again\n"); - - for (int i=0; iset(str, str); - } - - fprintf(stderr, "byebye insert\n"); - - return NULL; -} - -template -void *__dump__(void *param) -{ - auto_timer t("dump"); - HASH *test = (HASH *)param; - - fprintf(stderr, "start dump\n"); - pthread_mutex_lock(&g_lock); - pthread_cond_wait(&g_cond, &g_lock); - pthread_mutex_unlock(&g_lock); - fprintf(stderr, "sart to dump to file\n"); - - __XASSERT2_R(g_flagrun); - - bsl::filestream fs; - __XASSERT2_R(fs.open(g_dumpfile, "w") == 0); - bsl::binarchive ar(fs); - __XASSERT2_R(test->serialization(ar) == 0); - fs.close(); - - HASH *q = new HASH; - __XASSERT2_R(q->create(1<<20) == 0); - __XASSERT2_R(fs.open(g_dumpfile, "r") == 0); - bsl::binarchive inar(fs); - __XASSERT2_R(q->deserialization(ar) == 0); - fs.close(); - - for (typename HASH::iterator iter = q->begin(); - iter != q->end(); ++iter) { - __XASSERT2_R(g_set.find(iter->first) != g_set.end()); - } - - return NULL; -} - -template -bool test_phashmap_dump() -{ - //保存文件明 bsl_test_phashmap_dump.dat - //10个线程查询,1个线程更新,1个线程等待dump - __XASSERT2( - test_phashmap_temp( - 10, __query__, - 1, __update__, - 1, __dump__) - ); - //检查load数据是否正确 - - return true; -} - -class bsl_test_phashmap_dump : public CxxTest::TestSuite -{ -public: - typedef bsl::phashmap type1_t; - void test_phashmap_dump_ () { - TSM_ASSERT("test_phashmap_dump", test_phashmap_dump()); - } -}; - - -#endif //__BSL_TEST_PHASHMAP_DUMP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_phashmap_str_dump.h b/bsl/unittest/bsl_test_phashmap_str_dump.h deleted file mode 100644 index da3fa467d79418e1f8963b057ddd69578dd8e474..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_phashmap_str_dump.h +++ /dev/null @@ -1,161 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_phashmap_str_dump.h,v 1.1 2008/11/26 09:37:19 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_phashmap_dump.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/17 11:19:15 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_PHASHMAP_DUMP_H_ -#define __BSL_TEST_PHASHMAP_DUMP_H_ - -#include - -const int DATANUM = 1<<20; -//const int DATANUM = 10; -const char *g_dumpfile = "bsl_test_phashmap_dump.dat"; - -template -void * __query__(void *param) -{ - auto_timer t("query time at one thread"); - HASH *test = (HASH *)param; - - for (int i=0; iget(str, &val); - if (ret == bsl::HASH_EXIST) { - __XASSERT2_R(str == val); - } - } - - fprintf(stderr, "byebye query\n"); - return NULL; -} - -std::set g_set; - -#include -pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t g_cond = PTHREAD_COND_INITIALIZER; - -static bool g_flagrun = true; -static bool g_cpend = false; - -template -void * __update__(void *param) -{ - auto_timer t("update time"); - HASH *test = (HASH *)param; - - for (int i=0; iset(str, str); - } - - fprintf(stderr, "start to checkpoint\n"); - pthread_mutex_lock (&g_lock); - if (test->make_checkpoint() != 0) { - g_flagrun = false; - } - g_cpend = true; - fprintf(stderr, "singal post %d\n", (int)g_flagrun); - pthread_cond_signal(&g_cond); - pthread_mutex_unlock(&g_lock); - - __XASSERT2_R(g_flagrun); - - fprintf(stderr, "inserrt again\n"); - - for (int i=0; iset(str, str); - } - - fprintf(stderr, "byebye insert\n"); - - return NULL; -} - -template -void *__dump__(void *param) -{ - auto_timer t("dump"); - HASH *test = (HASH *)param; - - fprintf(stderr, "start dump\n"); - pthread_mutex_lock(&g_lock); - if (g_cpend) { - pthread_mutex_unlock(&g_lock); - return NULL; - } - pthread_cond_wait(&g_cond, &g_lock); - pthread_mutex_unlock(&g_lock); - fprintf(stderr, "sart to dump to file\n"); - - __XASSERT2_R(g_flagrun); - - bsl::filestream fs; - __XASSERT2_R(fs.open(g_dumpfile, "w") == 0); - bsl::binarchive ar(fs); - __XASSERT2_R(test->serialization(ar) == 0); - fs.close(); - - HASH *q = new HASH; - __XASSERT2_R(q->create(1<<20) == 0); - __XASSERT2_R(fs.open(g_dumpfile, "r") == 0); - bsl::binarchive inar(fs); - __XASSERT2_R(q->deserialization(ar) == 0); - fs.close(); - - for (typename HASH::iterator iter = q->begin(); - iter != q->end(); ++iter) { - __XASSERT2_R(g_set.find(iter->first) != g_set.end()); - } - - fprintf(stderr, "byebye dump"); - return NULL; -} - -template -bool test_phashmap_dump() -{ - //保存文件明 bsl_test_phashmap_dump.dat - //10个线程查询,1个线程更新,1个线程等待dump - __XASSERT2( - test_phashmap_temp( - 10, __query__, - 1, __update__, - 1, __dump__) - ); - //检查load数据是否正确 - - return true; -} - -class bsl_test_phashmap_dump : public CxxTest::TestSuite -{ -public: - typedef bsl::phashmap type1_t; - void test_phashmap_dump_ () { - TSM_ASSERT("test_phashmap_dump", test_phashmap_dump()); - } -}; - - -#endif //__BSL_TEST_PHASHMAP_DUMP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_phashmap_string.h b/bsl/unittest/bsl_test_phashmap_string.h deleted file mode 100644 index 26083480f40be2926fd1e7ce3a08faeaabcb4f4a..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_phashmap_string.h +++ /dev/null @@ -1,245 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $测试phashmap在多线程环境下的安全性问题$ - * - **************************************************************************/ - - - -/** - * @file bsl_test_phashmap.h - * @author xiaowei(com@baidu.com) - * @date 2008/08/18 12:37:07 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_PHASHMAP_H_ -#define __BSL_TEST_PHASHMAP_H_ - -#include - -static const int DATANUM = 100000; - -///////////// -/** - * 测试多线程的读写安全情况 - * 这个case测试两个hash表, - * 一个是phash,一个是rwhash - */ -template -void * __test_phashmap_fun_query(void *param) -{ - auto_timer t("query time at one thread"); - HASH * test = (HASH *)param; - __XASSERT2(test!=NULL); - int qloop = DATANUM / 20; - for (int i=0; iget(str, &val); - if (ret == bsl::HASH_EXIST) { - __XASSERT2_R(str == val); - } - } - - return NULL; -} -template -void * __test_phashmap_fun_update(void *param) -{ - //auto_timer t("update time at one thread"); - HASH *test = (HASH *)param; - __XASSERT2(test!=NULL); - int uloop = DATANUM; - for (int i=0; iset(s1, s1) != -1); - test->erase(randstr()); - } - return NULL; -} - - -template -bool test_phashmap() -{ - return test_phashmap_temp(20, __test_phashmap_fun_query, - 1, __test_phashmap_fun_update); -} - -//测试在写情况下dump数据问题 -template -void * __test_cp_fun1(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2(test != NULL); - int loop = 1000; - for (int i=0; imake_checkpoint(); - } - return NULL; -} -template -void * __test_cp_fun2(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2(test != NULL); - int loop = 1000; - for (int i=0; iend_checkpoint(); - } - - return NULL; -} - -template -bool test_phashmap_cp1() -{ - return test_phashmap_temp(10, __test_cp_fun1, - 10, __test_cp_fun2); -} - - - -//测试在写情况下dump数据问题 -template -void * __test_cp_fun3(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - int num = DATANUM; - for (int i=0; iset(int2str(i), int2str(i)) == bsl::HASH_INSERT_SEC); - } - { - auto_timer t("make checkpoint"); - __XASSERT2_R(test->make_checkpoint() == 0); - } - for (int i=0; iset(int2str(i), int2str(num/2 - i), 1) == bsl::HASH_OVERWRITE); - } -#if 0 - //check - for (int i=0; iget(int2str(i), &val) == bsl::HASH_EXIST); - __XASSERT2_R(val == int2str(num/2 - i)); - } - __BSL_ERROR("start to erase"); -#endif - for (int i=0; ierase(int2str(i)) == bsl::HASH_EXIST, "erase %d %d", i, - test->dumpstatus()); - } - for (int i=0; iset(int2str(i), int2str(num - i)) == bsl::HASH_INSERT_SEC); - } - return NULL; -} -template -void * __test_cp_fun4(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - while (test->dumpstatus() == bsl::PHASH_NORMAL) { - struct timespec tv; - tv.tv_sec = 0; - tv.tv_nsec = 10 * 1000; - - nanosleep(&tv, NULL); - } - bsl::filestream fd; - __XASSERT2_R(fd.open("phash.dat.1", "w") == 0); - bsl::binarchive ar(fd); - __XASSERT2_R(ar.write(*test) == 0); - fd.close(); - - __XASSERT2_R(fd.open("phash.dat.1", "r") == 0); - bsl::binarchive ar2(fd); - HASH test2; - __XASSERT2_R(ar.read(&test2) == 0); - fd.close(); - - int num = DATANUM; - __BSL_DEBUG("---------start to check size %d", (int)test2.size()); - for (int i=0; i -void * __test_cp_fun5(void *param) -{ - HASH *test = (HASH *)param; - __XASSERT2_R(test != NULL); - int loop = DATANUM / 20; - for (int i=0; iget(int2str(i)); - } - return NULL; -} - -template -bool test_phashmap_cp2() -{ - return test_phashmap_temp(1, __test_cp_fun3, - 1, __test_cp_fun4, 20, __test_cp_fun5); -} - -class bsl_test_phashmap : public CxxTest::TestSuite -{ -public: - typedef bsl::phashmap type1_t; - void test_phashmap_(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - - typedef bsl::phashmap, - bsl::bsl_alloc > type2_t; - void test_phashmap_2(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_2() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_2() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - - /// - typedef bsl::phashmap, - bsl::bsl_cpsalloc > > type3_t; - void test_phashmap_3(void) { - TSM_ASSERT ("", test_phashmap()); - } - void test_phashmap_cp1_3() { - TSM_ASSERT ("", test_phashmap_cp1()); - } - void test_phashmap_cp2_3() { - TSM_ASSERT ("", test_phashmap_cp2()); - } - -}; - -#endif //__BSL_TEST_PHASHMAP_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_phashtable.h b/bsl/unittest/bsl_test_phashtable.h deleted file mode 100644 index f0c5c9f8f25d0ed373df1f3f5f43524b0665978f..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_phashtable.h +++ /dev/null @@ -1,231 +0,0 @@ - -#ifndef __BSL_TEST_HASHTABLE_H -#define __BSL_TEST_HASHTABLE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng" -}; - -const size_t N = sizeof(s) / sizeof(s[0]); - - -std::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i -void inc_node(_T* v, void* /*args = NULL*/){ - v->second += _I; -} - -template -class IncNode{ -public: - void operator()(_T* v, void* /*args = NULL*/){ - v->second += _I; - } -}; - -template -void* update_func(void* args){ - HASH *ht = (HASH *)args; - for(int i = 0; i < 1000; ++i){ - for(int j = 0; j < 100; ++j){ - TS_ASSERT(ht->get(i, NULL, inc_node) == bsl::HASH_EXIST); - } - for(int j = 0; j < 100; ++j){ - TS_ASSERT(ht->get(i, NULL, IncNode()) == bsl::HASH_EXIST); - } - } - return NULL; -} - -class bsl_test_phashtable : public CxxTest::TestSuite -{ -public: - - void test_hashtable() { - typedef std::string key; - typedef int value; - typedef bsl::bsl_phashtable, - bsl::param_select,bsl::bsl_sample_alloc, 256> > hash_type; - - { - hash_type ht; - TS_ASSERT( 0 == ht.create(100)); - } - { - bool ex_flag = false; - try { - hash_type ht(0); - } catch (bsl::Exception& e) { - ex_flag = true; - } - TS_ASSERT(ex_flag == true); - } - { - hash_type ht(100); - std::set st; - ht.assign(st.begin(),st.end()); - TS_ASSERT(ht.size() == 0); - } - { - std::set st; - for (size_t i = 0; i < N; i ++) { - st.insert(s[i]); - } - hash_type ht(100); - ht.assign(st.begin(),st.end()); - TS_ASSERT( ht.size() == N ); - } - } - - void test_multi_create() { - typedef std::string key; - typedef int value; - typedef bsl::bsl_phashtable, - bsl::param_select,bsl::bsl_sample_alloc, 256> > hash_type; - hash_type ht; - for (int i = 0; i < 100; i ++) { - ht.create(i); - } - } - - void test_get_callback(){ - typedef int _Key; - typedef std::pair<_Key, int> _Value; - typedef bsl::bsl_phashtable< - _Key, - _Value, - bsl::xhash<_Key>, - std::equal_to<_Key>, - bsl::pair_first<_Value>, - bsl::bsl_sample_alloc, 256> - > hash_type; - - hash_type ht; - int hash_num = 1333; - int n = 1000; - const int INC = 1000; - - TS_ASSERT(ht.create(hash_num) == 0); - for(int i = 0; i < n; ++i){ - ht.set(i, std::make_pair<_Key, int>(i, 0)); - } - TS_ASSERT((int)ht.size() == n); - - for(int i = 0; i < n; ++i){ - _Value old_val; - TS_ASSERT(ht.get(i, &old_val, inc_node) == bsl::HASH_EXIST); - TS_ASSERT(old_val.second == 0); - TS_ASSERT(ht.get(i, &old_val) == bsl::HASH_EXIST); - TS_ASSERT(old_val.second == INC); - TS_ASSERT((int)ht.size() == n); - } - - ht.clear(); - TS_ASSERT(ht.create(hash_num) == 0); - for(int i = 0; i < n; ++i){ - ht.set(i, std::make_pair<_Key, int>(i, 0)); - } - TS_ASSERT((int)ht.size() == n); - - for(int i = 0; i < n; ++i){ - _Value old_val; - TS_ASSERT(ht.get(i, &old_val, IncNode()) == bsl::HASH_EXIST); - TS_ASSERT(old_val.second == 0); - TS_ASSERT(ht.get(i, &old_val) == bsl::HASH_EXIST); - TS_ASSERT(old_val.second == INC); - TS_ASSERT((int)ht.size() == n); - } - return; - } - - void test_get_callback_multithread(){ - typedef int _Key; - typedef std::pair<_Key, int> _Value; - typedef bsl::bsl_phashtable< - _Key, - _Value, - bsl::xhash<_Key>, - std::equal_to<_Key>, - bsl::pair_first<_Value>, - bsl::bsl_sample_alloc, 256> - > hash_type; - - int rep = 20; - while(rep--){ - int hash_num = 1333; - hash_type ht; - TS_ASSERT(ht.create(hash_num) == 0); - int n = 1000; - for(int i = 0; i < n; ++i){ - ht.set(i, std::make_pair<_Key,int>(i, 0)); - } - //check - TS_ASSERT((int)ht.size() == n); - for(int i = 0; i < n; ++i){ - hash_type::value_type val; - TS_ASSERT(ht.get(i, &val) == bsl::HASH_EXIST); - TS_ASSERT(val.second == 0); - } - int pn = 50; - std::vector pids(pn); - for(int i = 0; i < pn; ++i){ - TS_ASSERT(pthread_create(&pids[i], NULL, update_func, &ht) == 0); - } - for(int i = 0; i < pn; ++i){ - pthread_join(pids[i], NULL); - } - //check - TS_ASSERT((int)ht.size() == n); - for(int i = 0; i < n; ++i){ - hash_type::value_type val; - TS_ASSERT(ht.get(i, &val) == bsl::HASH_EXIST); - TS_ASSERT(val.second == pn * 100 * 2); - } - } - return; - } -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_pool.h b/bsl/unittest/bsl_test_pool.h deleted file mode 100644 index 796bbb8176c05ec6e55626b1de3f5deff8738482..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_pool.h +++ /dev/null @@ -1,338 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_pool.h,v 1.14 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_pool.h - * @author xiaowei(com@baidu.com) - * @date 2008/12/08 19:52:09 - * @version $Revision: 1.14 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_POOL_H_ -#define __BSL_TEST_POOL_H_ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - - -typedef bool (*fun_t)(bsl::mempool *); - -bool test_normal_pool (bsl::mempool *pool) -{ - std::vector vec; - std::vector vec2; - //size_t sizv[] = {0, 4, 16, 1<<21, 1<<19}; - size_t vsize = 1000; - size_t cnt = 0; - for (size_t i=0; imalloc(size); - if (ptr) { - memset(ptr, 0, size); - cnt += size; - vec.push_back(ptr); - vec2.push_back(size); - void *ptr2 = vec.back(); - size_t ptr2siz = vec2.back(); - pool->free (ptr2, ptr2siz); - } - } - std::cout<<(cnt>>20)<malloc (size); - if (ptr) { - memset (ptr, 0, size); - cnt += size; - vec.push_back(ptr); - vec2.push_back(size); - } - } - for (size_t i=0; ifree (vec[i], vec2[i]); - } - return true; -} - -bool test_xmempool (fun_t op) -{ - bsl::xmempool *pool = new bsl::xmempool; - size_t size = 1<<24; - void *dat = malloc (size); - pool->create(dat, size, 2, 1<<16, 1.8); - __XASSERT2(op((bsl::mempool *)pool)); - - pool->clear(); - for (int i=0; i<1<<16; i = int(float(i)*1.5) + 1) - std::cout<goodsize(i) <<" "<goodsize(pool->goodsize(i))<<" " - <goodsize(pool->goodsize(i)+1)<destroy(); - delete pool; - free (dat); - { - bsl::xmempool pool2; - } - return true; -} - -bool test_xcompool (fun_t op) -{ - bsl::xcompool *pool = new bsl::xcompool; - pool->create(1<<20, 2, 1<<16, 2.0f); - __XASSERT2(op((bsl::mempool *)pool)); - pool->destroy(); - delete pool; - { - bsl::xcompool pool2; - } - return true; -}; - -bool test_debugpool (fun_t op) -{ - bsl::debugpool *pool = new bsl::debugpool; - __XASSERT2(op((bsl::mempool *)pool)); - pool->free(pool->malloc(10), 10); - delete pool; - return true; -} - -bool g_exp = true; -template -bool test_stl (bsl::mempool *pool) -{ -#ifndef __i386 - typedef bsl::pool_allocator alloc; - alloc a(pool); - typedef std::vector vector; - vector v(a); - typedef std::set, alloc> set; - set s(std::less(), a); - size_t num = 10000; - try { - for (size_t i=0; i()); - for (size_t i=0; i alloc_c; - typedef std::basic_string, alloc_c> string; - typedef bsl::pool_allocator alloc_s; - typedef std::vector vector; - typedef std::set, alloc_s> set; - - alloc_c ca(pool); - alloc_s cs(pool); - - string a(ca); - a = "helloa"; - string b(ca); - b = "hellob"; - string c(ca); - c = "helloc"; - - size_t slen = 1000; - vector v(cs); - for (size_t i=0; i()); - set s(std::less(), cs); - for (size_t i=0; imalloc(rand()%16+1) != NULL); - } - return true; -} - -class bsl_test_pool : public CxxTest::TestSuite -{ -public: - void test_normal_pool_ () { - TSM_ASSERT(0, test_xmempool(test_normal_pool)); - TSM_ASSERT(0, test_xcompool(test_normal_pool)); - TSM_ASSERT(0, test_xcompool(test_compool)); - } - void test_stl_pool_ () { - g_exp = true; - TSM_ASSERT(1, test_xmempool(test_stl)); - TSM_ASSERT(1, test_xmempool(test_stl)); - TSM_ASSERT(1, test_xmempool(test_stl)); - TSM_ASSERT(1, test_xmempool(test_stl)); - - g_exp = false; - TSM_ASSERT(1, test_xcompool(test_stl)); - TSM_ASSERT(1, test_xcompool(test_stl)); - TSM_ASSERT(1, test_xcompool(test_stl)); - TSM_ASSERT(1, test_xcompool(test_stl)); - - TSM_ASSERT(1, test_debugpool(test_stl)); - } - void test_stl_string_ () { - TSM_ASSERT(2, test_xmempool(test_comp)); - TSM_ASSERT(2, test_xcompool(test_comp)); - } - - void test_pool_allocator_() { - { - bsl::syspool pool; - bsl::pool_allocator alloc((bsl::mempool *)&pool); - try { - alloc.allocate(1<<30); - alloc.allocate(1<<30); - alloc.allocate(1<<30); - alloc.allocate(1<<30); - } catch (...) { - std::cout<<"Exception"< alloc((bsl::mempool *) &pool); - try { - alloc.allocate(1<<30); - alloc.allocate(1<<30); - alloc.allocate(1<<30); - alloc.allocate(1<<30); - } catch(bsl::BadAllocException &e){ - std::cout<<"Exception"<create(); - bsl::pool_allocator alloc(pool); - int size = 1<<30; - alloc.allocate(size); - delete pool; - } - catch(bsl::BadAllocException &e){ - std::cout << "bad alloc!\n" << std::endl; - } - } - { - bsl::xcompool pool; - } - { - typedef bsl::pool_allocator _Alloc; - typedef _Alloc::pointer pointer; - typedef _Alloc::const_reference const_reference; - int size = 1000; - int size2 = 1073741824; - char *buf = (char*)malloc(sizeof(char)*size); - bsl::xmempool *pool = new bsl::xmempool; - int ret = pool->create(buf, size); - if (ret != 0) return; - _Alloc alloc(pool); - pointer p; - try{ - p = alloc.allocate(size2); - TSM_ASSERT(p, p != NULL); - delete pool; - } - catch(bsl::BadAllocException &e){ - std::cout << "bad alloc!\n" << std::endl; - free(buf); - } - } - { - bsl::xcompool pool; - assert (pool.create() == 0); - assert (pool.create(0) != 0); - assert (pool.create(1<<10) == 0); - assert (pool.malloc(1<<11) != 0); - assert (pool.create(1<<16) == 0); - assert (pool.malloc(1<<17) != 0); - assert (pool.create(1<<17) == 0); - } - - { - bsl::xcompool pool; - assert (pool.create(1<<10) == 0); - for (int k=0; k<2; ++k) { - for (int i=0; i<(1<<22); ++i) { - void * ret = (void *)pool.malloc(i); - assert (ret != 0); - pool.free (ret, i); - if (i%(1<<20) == 0) { - std::cout< -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -std::string rand_string() -{ - std::string str; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - bool operator < (const MyClass & __x) const{ - return ((strcmp(name, __x.name) < 0) || - ((strcmp(name, __x.name) == 0) && - (strcmp(value, __x.value) < 0))); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - - -template -Tp rand_value(); - -template<> -int rand_value(){ - return rand(); -} - -template<> -std::string rand_value(){ - return rand_string(); -} - -template<> -MyClass rand_value(){ - MyClass ret; - std::string name = rand_string(); - std::string value = rand_string(); - memcpy(ret.name, name.c_str(), name.size()); - memcpy(ret.value, value.c_str(), value.size()); - return ret; -} - - -template -void test_queue(){ - typedef Tp val_type; - typedef std::queue Queue; - - const int N = 10; - const int M = 5; - std::vector vec(N); - for(int i = 0; i < N; ++i){ - vec[i] = rand_value(); - } - - //定义 - Queue q; - TS_ASSERT(q.size() == 0); - - //push - for(int i = 0; i < N; ++i){ - q.push(vec[i]); - TS_ASSERT(q.back() == vec[i]); - TS_ASSERT(q.front() == vec[0]); - } - TS_ASSERT((int)q.size() == N); - - //pop (N-M) items - for(int i = 0; i < N - M; ++i){ - TS_ASSERT(q.front() == vec[i]); - TS_ASSERT(q.back() == vec[N - 1]); - q.pop(); - } - TS_ASSERT((int)q.size() == M); - - //const queue reference - const Queue& cq = q; - TS_ASSERT(cq.empty() == false); - TS_ASSERT((int)cq.size() == M); - - //front item refenrnce - const val_type& v1 = cq.front(); - val_type& v2 = q.front(); - TS_ASSERT(v1 == v2); - - //back item refenrnce - const val_type& v3 = cq.back(); - val_type& v4 = q.back(); - TS_ASSERT(v3 == v4); - - //copy conqruct - Queue q2(q); - for(int i = 0; i < M; ++i){ - TS_ASSERT(q2.front() == vec[N - M + i]); - TS_ASSERT(q2.back() == vec[N - 1]); - q2.pop(); - } - TS_ASSERT((int)q2.size() == 0); - TS_ASSERT(q2.empty() == true); - - //q has not been changed. - TS_ASSERT((int)q.size() == M); - TS_ASSERT(q.empty() == false); - - //assignment - Queue q3; - q3 = q; - for(int i = 0; i < M; ++i){ - TS_ASSERT(q3.front() == vec[N - M + i]); - TS_ASSERT(q3.back() == vec[N - 1]); - q3.pop(); - } - TS_ASSERT((int)q3.size() == 0); - TS_ASSERT(q3.empty() == true); - - //q has not been changed. - TS_ASSERT((int)q.size() == M); - TS_ASSERT(q.empty() == false); - return; -} - -template -void test_priority_queue(){ - typedef Tp val_type; - typedef std::priority_queue Queue; - - const int N = 10; - const int M = 5; - std::vector vec(N); - for(int i = 0; i < N; ++i){ - vec[i] = rand_value(); - } - - //定义 - Queue q; - TS_ASSERT(q.size() == 0); - - //push - for(int i = 0; i < N; ++i){ - q.push(vec[i]); - std::sort(vec.begin(), vec.begin() + i + 1); - TS_ASSERT(q.top() == vec[i]); - } - TS_ASSERT((int)q.size() == N); - - std::sort(vec.begin(), vec.end()); - //pop (N-M) items - for(int i = 0; i < N - M; ++i){ - TS_ASSERT(q.top() == vec[N - 1 - i]); - q.pop(); - } - TS_ASSERT((int)q.size() == M); - - //const queue reference - const Queue& cq = q; - TS_ASSERT(cq.empty() == false); - TS_ASSERT((int)cq.size() == M); - - //top item refenrnce - const val_type& v1 = cq.top(); - const val_type& v2 = q.top(); - TS_ASSERT(v1 == v2); - - //copy conqruct - Queue q2(q); - for(int i = 0; i < M; ++i){ - q2.pop(); - } - TS_ASSERT((int)q2.size() == 0); - TS_ASSERT(q2.empty() == true); - - //q has not been changed. - TS_ASSERT((int)q.size() == M); - TS_ASSERT(q.empty() == false); - - //assignment - Queue q3; - q3 = q; - for(int i = 0; i < M; ++i){ - q3.pop(); - } - TS_ASSERT((int)q3.size() == 0); - TS_ASSERT(q3.empty() == true); - - //q has not been changed. - TS_ASSERT((int)q.size() == M); - TS_ASSERT(q.empty() == false); - return; -} - - - -class bsl_test_queue : public CxxTest::TestSuite -{ -public: - //queue - void test_queue_with_int_deque(){ - test_queue >(); - } - void test_queue_with_string_deque(){ - test_queue >(); - } - void test_queue_with_myclass_deque(){ - test_queue >(); - } - - //priority_queue - void test_priority_queue_with_int_deque(){ - test_priority_queue >(); - } - void test_priority_queue_with_string_deque(){ - test_priority_queue >(); - } - void test_priority_queue_with_myclass_deque(){ - test_priority_queue >(); - } - - void test_queue_with_int_list(){ - test_queue >(); - } - void test_queue_with_string_list(){ - test_queue >(); - } - void test_queue_with_myclass_list(){ - test_queue >(); - } -}; diff --git a/bsl/unittest/bsl_test_readmap.h b/bsl/unittest/bsl_test_readmap.h deleted file mode 100644 index 009a72ada6d7ef45ab5f88cfec983b183e79aa0b..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_readmap.h +++ /dev/null @@ -1,341 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_readmap.h,v 1.5 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_fun.cpp - * @author yingxiang(com@baidu.com) - * @date 2008/08/14 17:44:12 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - - #ifndef __BSL_TEST_FUN_ - #define __BSL_TEST_FUN_ - #include -#include -#include -#include -#include -#include -#include -#include "test_alloc.h.ini" -#include -#include -#include - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng" -}; -char t[][128]={"AAAA", "qsbbs", "yufa", "yingxian", "f*ck", "hello world!", "baidu"}; - -const int N = sizeof(s) / sizeof(s[0]); -const int M = sizeof(t) / sizeof(t[0]); - -class bsl_test_fun : public CxxTest::TestSuite -{ - public: - typedef std::string key; - typedef int value; - std::map mp; - public: - class hash_func{ - public: - static const int BASE = 33; - size_t operator()(const std::string& s) const { - size_t i, t = 0; - for(i = 0; i < s.size(); i++){ - t *= BASE; - t += s[i]; - } - return t; - } - }; - void test_operator() { - { - bsl::readmap rmp; - init(); - rmp.assign(mp.begin(),mp.end()); - bsl::readmap rmp2; - rmp2 = rmp; - TS_ASSERT(rmp2.size() == rmp.size()); - TS_ASSERT(rmp.size() == mp.size()); - } - { - std::map mp; - bsl::readmap rmp; - rmp.assign(mp.begin(),mp.end()); - } - { - bsl::readmap rmp; - init(); - rmp.assign(mp.begin(),mp.end()); - bsl::readmap rmp2(rmp); - TS_ASSERT(rmp2.size() == rmp.size()); - TS_ASSERT(rmp.size() == mp.size()); - } - { - bsl::readmap rmp; - init(); - rmp.assign(mp.begin(),mp.end()); - int i,v,v2; - bsl::readmap rmp2(rmp); - for (i = 0; i < N; i ++) { - rmp.get(key(s[i]),&v); - rmp2.get(key(s[i]),&v2); - TS_ASSERT(v == v2); - } - } - { - try { - bsl::readmap rmp(0); - bsl::readmap rmp2(rmp); - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - } - } - - } - void test_create() { - bsl::readmap rmp; - for (int i = 0; i < 100; i ++) { - rmp.create(); - } - bsl::readmap rmp2; - for (int i = 0; i < 10; i ++) { - rmp = rmp2; - } - } - - void test_normal_1(void) - { - int val = 0; - TSM_ASSERT(val, val == 0); - } - - void test_rm1(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret ==0); - } - - void test_rm2(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - } - - void test_rm3(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rmp.assign(mp.begin(), mp.end()); - TSM_ASSERT(ret, ret == 0); - TSM_ASSERT(ret, rmp.size() == mp.size()); - } - - void test_rm4(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rmp.assign(mp.begin(), mp.end()); - int i; - for(i = 0; i < 100; i++){ - key k = rnd_item(); - value v; - ret = rmp.get(k, &v); - - if(mp.find(k) != mp.end()){ - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - TSM_ASSERT(v, v == mp[k]); - } - else{ - TSM_ASSERT(ret, ret = bsl::HASH_NOEXIST); - } - } - } - - void test_rm5(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rmp.assign(mp.begin(), mp.end()); - int i, v; - for(i = 0; i < N; i++){ - ret = rmp.get(key(s[i]), &v); - TSM_ASSERT(v, v == i); - TSM_ASSERT(ret, ret = bsl::HASH_EXIST); - } - } - - void test_rm6(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rmp.assign(mp.begin(), mp.end()); - int i, v = -1; - for(i = 0; i < M; i++){ - ret = rmp.get(key(t[i]), &v); - TSM_ASSERT(v, v == -1); - TSM_ASSERT(ret, ret = bsl::HASH_NOEXIST); - } - } - - void test_rm7(void){ - bsl::readmap rmp; - int ret = rmp.create(12345); - TSM_ASSERT(ret, ret == 0); - std::pair p[N]; - int i; - key k; - for(i = 0; i < N; i++) { - p[i].first = key(s[i]); - p[i].second = p[i].first; - } - - ret = rmp.assign(p, p+N); - TSM_ASSERT(ret, ret == 0); - for(i = 0; i < N; i++){ - ret = rmp.get(key(s[i]), &k); - TSM_ASSERT(k, k == key(s[i])); - } -#if 1 - TS_ASSERT(rmp.size() == (size_t)N); - - bsl::readmap rmp2; - TS_ASSERT(rmp2.create() == 0); - TS_ASSERT(rmp2.assign(rmp.begin(), rmp.end()) == 0); - TS_ASSERT(rmp2.size() == (size_t)N); - rmp.clear(); - TS_ASSERT(rmp.size() == 0); - TS_ASSERT(rmp.bucket_size() == 12345); - rmp.destroy(); - TS_ASSERT(rmp.bucket_size() == 0); -#endif - //bsl::destruct(p, p+N); - - } -#if 1 - void test_rm8(void){ - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - std::pair p[N]; - int i; - key k; - for(i = 0; i < N; i++) { - p[i].first = key(s[i]); - p[i].second = p[i].first; - } - ret = rmp.assign(p, p+N); - TSM_ASSERT(ret, ret == 0); - for(i = 0; i < N; i++){ - ret = rmp.get(key(s[i]), &k); - TSM_ASSERT(k, k == key(s[i])); - } - - bsl::filestream fs; - ret = fs.open("hash.dat", "w"); - TSM_ASSERT(ret, ret == 0); - bsl::binarchive ar(fs); - ret = ar.write(rmp); - TSM_ASSERT(ret, ret == 0); - fs.close(); - } - - void test_rm9(){ - test_rm8(); - bsl::readmap rmp; - int ret = rmp.create(); - TSM_ASSERT(ret, ret == 0); - - bsl::filestream fs; - ret = fs.open("hash.dat", "r"); - TSM_ASSERT(ret, ret == 0); - - bsl::binarchive ar(fs); - ret = ar.read(&rmp); - TSM_ASSERT(ret, ret == 0); - fs.close() - ; - int i; - key k; - for(i = 0; i < N; i++){ - ret = rmp.get(key(s[i]), &k); - TSM_ASSERT(k, k == key(s[i])); - } - ret = get_const(&rmp); - TSM_ASSERT(ret, ret == 0); - } - - void test_rm10(){ - test_rm8(); - bsl::readmap rmp; - int ret = rmp.create(); - FILE * fp = fopen("failtest", "w"); - fclose(fp); - TSM_ASSERT(ret, ret == 0); - - bsl::filestream fs; - ret = fs.open("failtest", "r"); - TSM_ASSERT(ret, ret == 0); - - bsl::binarchive ar(fs); - ret = ar.read(&rmp); - TSM_ASSERT(ret, ret != 0); - fs.close(); - } - -#endif - private: - key rnd_item(){ - srand(time(NULL)); - return (key)(s[rand() % N]); - } - void init(){ - int i; - mp.clear(); - for(i = 0; i < N; i++){ - mp[(key)s[i]] = i; - } - } - int get_const(const bsl::readmap *bmp){ - for(int i = 0; i < N; i++){ - key k; - int ret = bmp->get(key(s[i]), &k); - if(k != key(s[i]) || ret != bsl::HASH_EXIST) return -1; - } - return 0; - } -}; - - -#endif - - - - - - - - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_readset.h b/bsl/unittest/bsl_test_readset.h deleted file mode 100644 index 8ea7f953bfb716affbbe0ce886165301b7415e23..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_readset.h +++ /dev/null @@ -1,322 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_readset.h,v 1.5 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_fun.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/08/14 17:44:12 - * @version $Revision: 1.5 $ - * @brief - * - **/ - - - #ifndef __BSL_TEST_FUN_ - #define __BSL_TEST_FUN_ - #include -#include -#include -#include -#include -#include -#include -#include -#include - -char s[][128]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng" -}; -char t[][128]={"AAAA", "qsbbs", "yufa", "yingxian", "f*ck", "hello world!", "baidu"}; - -const int N = sizeof(s) / sizeof(s[0]); -const int M = sizeof(t) / sizeof(t[0]); - -class bsl_test_fun : public CxxTest::TestSuite -{ - public: - typedef std::string key; - std::set st; - public: - class hash_func{ - public: - static const int BASE = 33; - size_t operator()(const std::string& s) const { - size_t i, t = 0; - for(i = 0; i < s.size(); i++){ - t *= BASE; - t += s[i]; - } - return t; - } - }; - void test_operator() { - { - bsl::readset rst; - init(); - rst.assign(st.begin(),st.end()); - bsl::readset rst2; - rst2 = rst; - TS_ASSERT(rst2.size() == rst.size()); - TS_ASSERT(rst.size() == st.size()); - } - { - std::set st; - bsl::readset rst; - rst.assign(st.begin(),st.end()); - } - { - bsl::readset rst; - init(); - rst.assign(st.begin(),st.end()); - bsl::readset rst2(rst); - TS_ASSERT(rst2.size() == rst.size()); - TS_ASSERT(rst.size() == st.size()); - } - { - bsl::readset rst; - init(); - rst.assign(st.begin(),st.end()); - int i; - bsl::readset rst2(rst); - for (i = 0; i < N; i ++) { - int ret = rst.get(key(s[i])); - TS_ASSERT( ret == bsl::HASH_EXIST ); - ret = rst2.get(key(s[i])); - TS_ASSERT(ret == bsl::HASH_EXIST); - } - } - { - try { - bsl::readset rst(0); - bsl::readset rst2(rst); - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - } - } - } - void test_create() { - bsl::readset rst; - for (int i = 0; i < 100; i ++) { - rst.create(); - } - bsl::readset rst2; - for (int i = 0; i < 10; i ++) { - rst = rst2; - } - } - void test_norsal_1(void) - { - int val = 0; - TSM_ASSERT(val, val == 0); - } - - void test_rs1(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - } - - void test_rs2(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - } - - void test_rs3(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rst.assign(st.begin(), st.end()); - TSM_ASSERT(ret, ret == 0); - TSM_ASSERT(ret, rst.size() == st.size()); - } - - void test_rs4(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rst.assign(st.begin(), st.end()); - int i; - for(i = 0; i < 100; i++){ - key k = rnd_item(); - ret = rst.get(k); - - if(st.find(k) != st.end()){ - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - } - else{ - TSM_ASSERT(ret, ret = bsl::HASH_NOEXIST); - } - } - } - - void test_rs5(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rst.assign(st.begin(), st.end()); - int i; - for(i = 0; i < N; i++){ - ret = rst.get(key(s[i])); - TSM_ASSERT(ret, ret = bsl::HASH_EXIST); - } - } - - void test_rs6(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - init(); - ret = rst.assign(st.begin(), st.end()); - int i; - for(i = 0; i < M; i++){ - ret = rst.get(key(t[i])); - TSM_ASSERT(ret, ret = bsl::HASH_NOEXIST); - } - } - - void test_rs7(void){ - bsl::readset rst; - int ret = rst.create(12345); - TSM_ASSERT(ret, ret == 0); - key p[N]; - int i; - key k; - for(i = 0; i < N; i++) { - p[i] = s[i]; - } - ret = rst.assign(p, p+N); - TSM_ASSERT(ret, ret == 0); - for(i = 0; i < N; i++){ - ret = rst.get(key(s[i])); - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - } - TS_ASSERT(rst.size() == (size_t)N); - bsl::readset rst2; - TS_ASSERT(rst2.create() == 0); - TS_ASSERT(rst2.assign(rst.begin(), rst.end()) == 0); - TS_ASSERT(rst2.size() == (size_t)N); - rst.clear(); - TS_ASSERT(rst.size() == 0); - TS_ASSERT(rst.bucket_size() == 12345); - rst.destroy(); - TS_ASSERT(rst.bucket_size() == 0); - } - - void test_rs8(void){ - bsl::readset rst; - int ret = rst.create(); - TSM_ASSERT(ret, ret == 0); - key p[N]; - int i; - key k; - for(i = 0; i < N; i++) { - p[i] = key(s[i]); - } - ret = rst.assign(p, p+N); - TSM_ASSERT(ret, ret == 0); - for(i = 0; i < N; i++){ - ret = rst.get(key(s[i])); - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - } - bsl::filestream fs; - ret = fs.open("hashset.dat", "w"); - TSM_ASSERT(ret, ret == 0); - bsl::binarchive ar(fs); - ret = ar.write(rst); - TSM_ASSERT(ret, ret == 0); - fs.close(); - } - - void test_rs9(){ - test_rs8(); - bsl::readset rst; - int ret = rst.create(); - TS_ASSERT(ret == 0); - - bsl::filestream fs; - ret = fs.open("hashset.dat", "r"); - TSM_ASSERT(ret, ret == 0); - - bsl::binarchive ar(fs); - ret = ar.read(&rst); - TSM_ASSERT(ret, ret == 0); - fs.close(); - - int i; - for(i = 0; i < N; i++){ - ret = rst.get(key(s[i])); - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - } - ret = get_const(&rst); - TSM_ASSERT(ret, 0 == ret); - } - - void test_rs10(){ - test_rs8(); - bsl::readset rst; - int ret = rst.create(); - FILE * fp = fopen("failtest", "w"); - fclose(fp); - TS_ASSERT(ret == 0); - - bsl::filestream fs; - ret = fs.open("failtest", "r"); - TSM_ASSERT(ret, ret == 0); - - bsl::binarchive ar(fs); - ret = ar.read(&rst); - TSM_ASSERT(ret, ret != 0); - fs.close(); - } - private: - key rnd_item(){ - srand(time(NULL)); - return (key)(s[rand() % N]); - } - void init(){ - int i; - for(i = 0; i < N; i++){ - st.insert((key)s[i]); - } - } - - int get_const(const bsl::readset * rst){ - for(int i = 0; i < N; i++){ - int ret = rst->get(key(s[i])); - TSM_ASSERT(ret, ret == bsl::HASH_EXIST); - } - return 0; - } - - -}; - - -#endif - - - - - - - - - - - - - - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_rwhashset.h b/bsl/unittest/bsl_test_rwhashset.h deleted file mode 100644 index 3599e34dca9397e5812f9ce109cce7add89bc52c..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_rwhashset.h +++ /dev/null @@ -1,94 +0,0 @@ - -#ifndef __BSL_TEST_HASHTABLE_H -#define __BSL_TEST_HASHTABLE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -char s[][32]={"yingxiang", "yufan", "wangjiping", "xiaowei", "yujianjia", "maran", "baonenghui", - "gonglei", "wangyue", "changxinglong", "chenxiaoming", "guoxingrong", "kuangyuheng" -}; - -const size_t N = sizeof(s) / sizeof(s[0]); - - -std::string randstr() -{ - char buf[130] = {0}; - int len = rand()%64 + 1; - for (int i=0; i hash_type; - void test_rwhashset() { - { - hash_type ht; - TS_ASSERT( 0 == ht.create(100)); - } - { - try { - printf("hello\n"); - hash_type ht(0); - } catch (bsl::Exception& e) { - printf("\n==\n%s\n==\n",e.all()); - printf("world\n"); - } - } - { - hash_type ht(100); - std::set st; - ht.assign(st.begin(),st.end()); - } - } - void test_create() { - hash_type ht; - for (int i = 10; i < 100; i ++) { - ht.create(i); - } - hash_type ht2; - for (int i = 0; i < 100; i ++) { - ht2.create(i); - } - } -}; - -#endif -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/bsl_test_rwseque.h b/bsl/unittest/bsl_test_rwseque.h deleted file mode 100644 index fc4f52d06ea52724a6625e50f911bb56998faa3a..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_rwseque.h +++ /dev/null @@ -1,410 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -std::string rand_string() -{ - std::string str; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char u[256]; - MyClass() { - memset(u, 0, 256); - } - ~MyClass() { - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - } -}; - -class bsl_test_rwseque : public CxxTest::TestSuite -{ -public: - void test_operator() - { - { - bsl::rwseque l1; - TS_ASSERT(0 == l1.create()); - for (int i = 0; i < 1000; i ++) { - l1.push_back( "hello world" ); - } - TS_ASSERT( 1000 == l1.size() ); - } - { - bsl::rwseque l1; - TS_ASSERT(0 == l1.create()); - for (int i = 0; i < 100; i ++) { - l1.push_back(i); - } - TS_ASSERT( 100 == l1.size() ); - int i = 0; - for (bsl::rwseque::iterator iter = l1.begin(); iter != l1.end(); ++ iter, i ++) { - TS_ASSERT( *iter == i ); - } - } - } - void test_create() - { - bsl::rwseque l1; - int i; - for (i = 0; i < 10000; i ++) { - l1.create(); - } - for (i = 0; i < 10000; i ++) { - l1.create(); - } - bsl::rwseque l2; - for (i = 0; i < 10000; i ++) { - l2.create(); - } - for (i = 0; i < 10; i ++) { - l1.push_back(i); - } - TS_ASSERT( 10 == l1.size() ); - } - void test_create_0() - { - bsl::rwseque t0; - TS_ASSERT(t0.destroy() == 0); - } - - void test_create_1() - { - bsl::rwseque t1; - t1.create(); - t1.create(); - t1.create(); - TS_ASSERT(t1.destroy() == 0); - } - - void test_push_back_0() - { - bsl::rwseque t0; - TS_ASSERT(t0.create() == 0); - int n = 5000; - for(int i=0; i < n; ++i) { - int ret = t0.push_back(i); - TS_ASSERT_EQUALS(ret, 0); - } - for (int i=0; i < n; ++i) { - int s; - TS_ASSERT(t0.get(i, &s) == 0); - TS_ASSERT(s==i); - } - - TS_ASSERT_EQUALS(t0.size() , n); - TS_ASSERT(!t0.destroy()); - } - - void test_push_back_1() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - std::string str(rand_string()); - int ret = t1.push_back(str); - TS_ASSERT_EQUALS(ret, 0); - dt1.push_back(str); - } - for (int i = 0; i < n; ++i) { - std::string str; - TS_ASSERT(t1.get(i, &str)==0); - TS_ASSERT(str == dt1[i]); - } - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - void test_push_back_2() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - int ret = t1.push_back(tmp); - TS_ASSERT_EQUALS(ret, 0); - dt1.push_back(tmp); - } - for (int i = 0; i < n; ++i) { - MyClass tmp; - TS_ASSERT(t1.get(i, &tmp)==0); - TS_ASSERT(tmp == dt1[i]); - } - - - TS_ASSERT_EQUALS(t1.size() , n); - TS_ASSERT(t1.destroy() == 0); - } - - - void test_push_pop_back_0() - { - bsl::rwseque t1; - std::vector dt1; - int n = 1000; - //int mpush = 0, mpop_back = 0; - TS_ASSERT(t1.create() == 0); - for (int i = 0; i < n; ++i) { - int x = rand(); - switch (rand()%2) { - case 0: TS_ASSERT(t1.push_back(x) == 0); - dt1.push_back(x); - break; - - case 1: - if (t1.size() > 0) { - TS_ASSERT(t1.pop_back() == 0); - dt1.pop_back(); - } - break; - default: - break; - } - - TS_ASSERT_EQUALS(t1.size(), dt1.size()); - if (t1.size() != 0) { - for (int j = 0; j < (int)t1.size(); ++j) { - int s; - TS_ASSERT(t1.get((unsigned int)j, &s) == 0); - TS_ASSERT(s == dt1[j]); - } - } - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_get_0() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - int x = rand(); - t1.push_back(x); - dt1.push_back(x); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - int s; - TS_ASSERT(t1.get(x, &s) == 0); - TS_ASSERT_EQUALS(s, dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_get_1() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - std::string str(rand_string()); - t1.push_back(str); - dt1.push_back(str); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - std::string str; - TS_ASSERT(t1.get(x, &str)==0); - TS_ASSERT(str == dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - - void test_rand_2() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - MyClass s; - snprintf(s.name, sizeof(s.name), "%s", rand_string().c_str()); - snprintf(s.value, sizeof(s.value), "%s", rand_string().c_str()); - t1.push_back(s); - dt1.push_back(s); - } - for (int i = 0; i < n; ++i) { - int x = rand()%n; - MyClass tmp; - TS_ASSERT_EQUALS(t1.get(x, &tmp), 0); - TS_ASSERT_EQUALS(tmp, dt1[x]); - } - TS_ASSERT(t1.destroy() == 0); - } - - void test_clear_0() - { - bsl::rwseque t1; - std::vector dt1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - int x = rand(); - t1.push_back(x); - dt1.push_back(x); - } - t1.clear(); - t1.clear(); - t1.clear(); - dt1.clear(); - TS_ASSERT_EQUALS(t1.size(), dt1.size()); - - for (int i = 0; i < n; ++i) { - int x = rand()%n; - t1.push_back(x); - dt1.push_back(x); - } - TS_ASSERT_EQUALS(t1.size(), dt1.size()); - TS_ASSERT_EQUALS(t1.destroy(), 0); - } - - void test_ceate_0() - { - bsl::rwseque t1; - TS_ASSERT(t1.create() == 0); - int n = 5000; - for (int i = 0; i < n; ++i) { - t1.push_back(i); - } - TS_ASSERT(t1.create() == 0); - TS_ASSERT(t1.size() == 0); - } - - void test_assign_0() - { - bsl::rwseque t1; - t1.create(); - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - t1.assign(5000, tmp); - TS_ASSERT_EQUALS(t1.size(), 5000); - for(int i = 0; i < 5000; ++i) { - MyClass stmp; - TS_ASSERT_EQUALS(t1.get(i, &stmp), 0); - TS_ASSERT_EQUALS(tmp , stmp); - } - for (int i = 0; i < 5000; ++i) { - t1.pop_back(); - } - TS_ASSERT(t1.size() == 0); - } - - void test_assign_1() - { - bsl::rwseque t1; - t1.create(); - std::vector t2; - for (int i = 0; i < 5000; ++i) { - MyClass tmp; - snprintf(tmp.name, sizeof(tmp.name), "%s", rand_string().c_str()); - snprintf(tmp.value, sizeof(tmp.value), "%s", rand_string().c_str()); - t2.push_back(tmp); - } - t1.assign(t2.begin(), t2.end()); - TS_ASSERT(t1.size() == t2.size()); - for (int i = 0; i < 50; ++i) { - MyClass tmp; - TS_ASSERT(t1.get(i, &tmp) == 0); - TS_ASSERT(tmp == t2[i]); - } - } - - void test_iter_0() - { - bsl::rwseque t1; - t1.create(); - for (int i = 0; i < 5000; ++i) { - t1.push_back(i); - } - bsl::rwseque::iterator iter; - iter = t1.begin(); - for (int i = 1; i < 5000; ++i) { - iter++; - TS_ASSERT(*iter == i); - } - for (int i = 4999; i > 0; --i) { - TS_ASSERT(*iter == i); - iter--; - } - for (int i = 1; i < 5000; ++i) { - ++iter; - TS_ASSERT(*iter == i); - } - for (int i = 4999; i > 0; --i) { - TS_ASSERT(*iter == i); - --iter; - } - - iter += 100; - TS_ASSERT(*iter == 100); - - TS_ASSERT(*(iter+100) == 200); - - TS_ASSERT(*(iter-20) == 80); - - iter -= 80; - TS_ASSERT(*iter == 20); - - TS_ASSERT(iter[100] == 120); - - - bsl::rwseque::iterator iter2; - bsl::rwseque t2; - t2.create(); - TS_ASSERT_EQUALS(t2.push_back(30), 0); - TS_ASSERT_EQUALS(t2.push_back(900), 0); - iter2 = t2.begin(); - - bsl::rwseque::iterator iter3; - iter3 = iter2+1; - TS_ASSERT(!(iter2 == iter3)); - TS_ASSERT(iter2 != iter3); - } -}; diff --git a/bsl/unittest/bsl_test_rwseque_pthread.h b/bsl/unittest/bsl_test_rwseque_pthread.h deleted file mode 100644 index 075faf5457dc4a4f3ca8a7a57b58693559ab33bf..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_rwseque_pthread.h +++ /dev/null @@ -1,322 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -std::string rand_string() -{ - std::string str; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - -std::vector g_tid; - -template -class MyParam{ - public: - bsl::rwseque r; - std::vector data; - T default_value; -}; - -const int MAX_SIZE = 1000; - -template -void* bsl_rwseque_push(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < 1000; ++i) { - for (int i = 0; i < MAX_SIZE; ++i) { - s->r.push_back(s->data[i]); - } - for (int i = 0;i < MAX_SIZE; ++i) { - s->r.pop_back(); - } - } - return NULL; - -} - -template -void* bsl_rwseque_set(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < 1000; ++i) { - for (int i = 0; i < MAX_SIZE; ++i) { - int x = rand()%MAX_SIZE; - s->r.set(x, s->data[x]); - } - } - return NULL; - -} - -template -void* bsl_rwseque_clear(void *arg) -{ - MyParam *s = static_cast*>(arg); - int a = 0, b = 0; - for (int i = 0; i < 1000; ++i) { -// size_t size = s->r.size(); - TS_ASSERT(s->r.clear() == 0); - if (s->r.size()) { - a++; - } else { - b++; - } - } - return NULL; - -} - - - -template -void* bsl_rwseque_get(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < MAX_SIZE; ++i) { - T tmp; - int p = s->r.size()%MAX_SIZE; - int ret = s->r.get(p, &tmp); - if (ret == 0) { - - if (tmp == s->default_value) { - continue; - } - if (s->data[p] != tmp) { - TS_ASSERT(s->data[p] == tmp); - for (int z = 0; z < (int)g_tid.size(); ++z) { - if (g_tid[z] != pthread_self()) { - pthread_cancel(g_tid[z]); - } - } - return NULL; - } - - } - } - return 0; -} - -#define CREATE_PTHREAD(g_tid,func,num,var) \ - do { for (int i = 0; i < num; ++i) { \ - pthread_t tid; \ - pthread_create(&tid, NULL, func, &var);\ - g_tid.push_back(tid);} \ - }while(0); - -#define PTHREAD_JOIN(g_tid) \ - do { \ - for (int i = 0; i < (int)g_tid.size(); ++i) {\ - pthread_join(g_tid[i], NULL); \ - }\ - g_tid.clear(); \ - }while(0); - - -class bsl_test_rwseque : public CxxTest::TestSuite -{ -public: - - /** - * 一个线程push, 另外的线程随机get - * 20个线程 - **/ - void test_push_pop_0() - { - - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - * 一个线程push, 另外的线程随机get - * 20个线程 - **/ - void test_push_pop_1() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - * 20个线程 - **/ - void test_push_pop_2() - { - - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(3000); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - * 20个线程 - **/ - void test_push_pop_3() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back("kdksoafuido"); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - - /** - * 一个线程set,《喔鱿叱蘥et - **/ - void test_set_get_0() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 1, s); - - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - * 一个线程set,《喔鱿叱蘥et - **/ - void test_set_get_1() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - s.r.assign(MAX_SIZE, ""); - s.default_value = ""; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - **/ - void test_set_get_2() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 10, s); - - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - **/ - void test_set_get_3() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - s.r.assign(MAX_SIZE, ""); - s.default_value = ""; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - void test_get_clear_0() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(60000); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 5, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_clear, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - PTHREAD_JOIN(g_tid); - } - - - void test_create_1() - { - bsl::rwseque t1; - t1.create(); - t1.create(); - t1.create(); - TS_ASSERT(t1.destroy() == 0); - } - - - -}; diff --git a/bsl/unittest/bsl_test_rwseque_pthread_string.h b/bsl/unittest/bsl_test_rwseque_pthread_string.h deleted file mode 100644 index bb897f90796dd6e74f99f655b868249a90fbd03f..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_rwseque_pthread_string.h +++ /dev/null @@ -1,323 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -bsl::string rand_string() -{ - char buf[256] = {0}; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - buf[i] = 'a' + rand()%26; - } - return buf; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - -std::vector g_tid; - -template -class MyParam{ - public: - bsl::rwseque r; - std::vector data; - T default_value; -}; - -const int MAX_SIZE = 1000; - -template -void* bsl_rwseque_push(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < 1000; ++i) { - for (int i = 0; i < MAX_SIZE; ++i) { - s->r.push_back(s->data[i]); - } - for (int i = 0;i < MAX_SIZE; ++i) { - s->r.pop_back(); - } - } - return NULL; - -} - -template -void* bsl_rwseque_set(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < 1000; ++i) { - for (int i = 0; i < MAX_SIZE; ++i) { - int x = rand()%MAX_SIZE; - s->r.set(x, s->data[x]); - } - } - return NULL; - -} - -template -void* bsl_rwseque_clear(void *arg) -{ - MyParam *s = static_cast*>(arg); - int a = 0, b = 0; - for (int i = 0; i < 1000; ++i) { -// size_t size = s->r.size(); - TS_ASSERT(s->r.clear() == 0); - if (s->r.size()) { - a++; - } else { - b++; - } - } - return NULL; - -} - - - -template -void* bsl_rwseque_get(void *arg) -{ - MyParam *s = static_cast*>(arg); - for (int i = 0; i < MAX_SIZE; ++i) { - T tmp; - int p = s->r.size()%MAX_SIZE; - int ret = s->r.get(p, &tmp); - if (ret == 0) { - - if (tmp == s->default_value) { - continue; - } - if (s->data[p] != tmp) { - TS_ASSERT(s->data[p] == tmp); - for (int z = 0; z < (int)g_tid.size(); ++z) { - if (g_tid[z] != pthread_self()) { - pthread_cancel(g_tid[z]); - } - } - return NULL; - } - - } - } - return 0; -} - -#define CREATE_PTHREAD(g_tid,func,num,var) \ - do { for (int i = 0; i < num; ++i) { \ - pthread_t tid; \ - pthread_create(&tid, NULL, func, &var);\ - g_tid.push_back(tid);} \ - }while(0); - -#define PTHREAD_JOIN(g_tid) \ - do { \ - for (int i = 0; i < (int)g_tid.size(); ++i) {\ - pthread_join(g_tid[i], NULL); \ - }\ - g_tid.clear(); \ - }while(0); - - -class bsl_test_rwseque : public CxxTest::TestSuite -{ -public: - - /** - * 一个线程push, 另外的线程随机get - * 20个线程 - **/ - void test_push_pop_0() - { - - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - * 一个线程push, 另外的线程随机get - * 20个线程 - **/ - void test_push_pop_1() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - * 20个线程 - **/ - void test_push_pop_2() - { - - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(3000); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - * 20个线程 - **/ - void test_push_pop_3() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back("kdksoafuido"); - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - - /** - * 一个线程set,《喔鱿叱蘥et - **/ - void test_set_get_0() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 1, s); - - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - * 一个线程set,《喔鱿叱蘥et - **/ - void test_set_get_1() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - s.r.assign(MAX_SIZE, ""); - s.default_value = ""; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - /** - **/ - void test_set_get_2() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(i); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 10, s); - - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - - /** - **/ - void test_set_get_3() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(rand_string()); - s.r.assign(MAX_SIZE, ""); - s.default_value = ""; - CREATE_PTHREAD(g_tid, bsl_rwseque_set, 10, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - - PTHREAD_JOIN(g_tid); - } - - void test_get_clear_0() - { - MyParam s; - s.r.create(); - for (int i = 0; i < MAX_SIZE; ++i) s.data.push_back(60000); - s.r.assign(MAX_SIZE, -1); - s.default_value = -1; - - CREATE_PTHREAD(g_tid, bsl_rwseque_push, 5, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_clear, 1, s); - CREATE_PTHREAD(g_tid, bsl_rwseque_get, 20, s); - PTHREAD_JOIN(g_tid); - } - - - void test_create_1() - { - bsl::rwseque t1; - t1.create(); - t1.create(); - t1.create(); - TS_ASSERT(t1.destroy() == 0); - } - - - -}; diff --git a/bsl/unittest/bsl_test_sample_alloc_allocate_deallocate.h b/bsl/unittest/bsl_test_sample_alloc_allocate_deallocate.h deleted file mode 100644 index 514f592a6d6aee6227f060bd228c62cad568e7b3..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_sample_alloc_allocate_deallocate.h +++ /dev/null @@ -1,161 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_sample_alloc_allocate_deallocate.h,v 1.2 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_sample_alloc_allocate_deallocate.h - * @author xiaowei(com@baidu.com) - * @date 2008/10/28 11:44:27 - * @version $Revision: 1.2 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_SAMPLE_ALLOC_ALLOCATE_DEALLOCATE_H_ -#define __BSL_TEST_SAMPLE_ALLOC_ALLOCATE_DEALLOCATE_H_ - - -#include -#include -#include -#include -#include -#include -#include "define.rc" - -template -void test_allocate_deallocate_1() -{ - typedef typename _Alloc::self _Self; // bsl_sample_alloc - typedef typename _Self::pointer pointer; - - _Self alloc; - pointer p; - int ret; - - ret = alloc.create(); - TSM_ASSERT(ret, ret == 0); - - for(int i = 0; i < 100000; i++){ - p = alloc.allocate(1); - if (p == NULL) { - fprintf(stderr, "\n%d %m\n", i); - } - TSM_ASSERT(p, p != NULL); - alloc.deallocate(p, 1); - } - - ret = alloc.destroy(); - TSM_ASSERT(ret, ret == 0); -} - -template -void test_allocate_deallocate_2() -{ - typedef typename _Alloc::self _Self; // bsl_sample_alloc - typedef typename _Self::pointer pointer; - - _Self alloc; - int ret; - - ret = alloc.create(); - TSM_ASSERT(ret, ret == 0); - - alloc.deallocate(NULL, 1); - - ret = alloc.destroy(); - TSM_ASSERT(ret, ret == 0); -} - -class test_bsl_sample_alloc_allocate_deallocate : public CxxTest::TestSuite -{ -public: - // 1) ÷?∏¥??¥OEallocate∫? deallocate - void test_bsl_sample_alloc_allocate_deallocate_1(void) - { - typedef bsl::bsl_alloc alloc_t_1; - typedef bsl::bsl_sample_alloc cpsalloc_t_1; - typedef bsl::bsl_alloc alloc_t_2; - typedef bsl::bsl_sample_alloc cpsalloc_t_2; - - typedef bsl::bsl_alloc > alloc_t_3; - typedef bsl::bsl_sample_alloc cpsalloc_t_3; - - typedef bsl::bsl_alloc alloc_t_4; - typedef bsl::bsl_sample_alloc cpsalloc_t_4; - - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - } - - // 2) ≤OE ?_ItemsΩoe¥? ±£¨μ~”√allocate - void test_bsl_sample_alloc_allocate_deallocate_2(void) - { - typedef bsl::bsl_alloc alloc_t_1; - typedef bsl::bsl_sample_alloc cpsalloc_t_1; - - typedef bsl::bsl_alloc alloc_t_2; - typedef bsl::bsl_sample_alloc cpsalloc_t_2; - - typedef bsl::bsl_alloc > alloc_t_3; - typedef bsl::bsl_sample_alloc cpsalloc_t_3; - - // _Items∫〈¥? - typedef bsl::bsl_alloc alloc_t_4; - typedef bsl::bsl_sample_alloc cpsalloc_t_4; - - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - test_allocate_deallocate_1(); - } - - // 3) ≤OE ?pointer ptrOE(TM)NULL ±£¨μ~”√deallocate - void test_bsl_sample_alloc_allocate_deallocate_3(void) - { -/* - typedef bsl::bsl_alloc alloc_t_1; - typedef bsl::bsl_sample_alloc cpsalloc_t_1; - typedef bsl::bsl_alloc alloc_t_2; - typedef bsl::bsl_sample_alloc cpsalloc_t_2; - typedef bsl::bsl_alloc > alloc_t_3; - typedef bsl::bsl_sample_alloc cpsalloc_t_3; - - typedef bsl::bsl_alloc alloc_t_4; - typedef bsl::bsl_sample_alloc cpsalloc_t_4; - - test_allocate_deallocate_2(); - test_allocate_deallocate_2(); - test_allocate_deallocate_2(); - test_allocate_deallocate_2(); -*/ - std::cout << "test_bsl_sample_alloc_allocate_deallocate" << std::endl; - } -}; - - - - - - - - - - - - - - - - -#endif //__BSL_TEST_SAMPLE_ALLOC_ALLOCATE_DEALLOCATE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_shallow_copy_string.hpp b/bsl/unittest/bsl_test_shallow_copy_string.hpp deleted file mode 100644 index 094b15dc2a52ce65393754bd0fcfbb494aec2275..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_shallow_copy_string.hpp +++ /dev/null @@ -1,186 +0,0 @@ - - - -/** - * @file bsl_test_string.hpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/12 17:29:08 - * @version $Revision: 1.10 $ - * @brief - * - **/ -#ifndef __BSL_TEST_SHALLOW_COPY_STRING_HPP_ -#define __BSL_TEST_SHALLOW_COPY_STRING_HPP_ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< - * example: CXM_ASSERT( 3 + 3 != 6, <<"test: "< -class bsl_test_shallow_copy_string{ -private: - typedef bsl::basic_string<_CharT,_Alloc> string_t; - _CharT *_cs_0; - const size_t _cs_0_len; - const size_t _cs_0_size; - _CharT* _cs_1; - _CharT* _cs_2; - _CharT* _cs_3; - _CharT* _cs_4; - _CharT* _cs_5; - _CharT* _empty_cs; - _CharT* _cs_0_add_1; - - static _CharT * malloc_clone( const char * str ){ - size_t len = strlen(str); - _CharT * p = static_cast<_CharT*>(malloc( (len+1)*sizeof(_CharT) )); - for( size_t i = 0; i<=len; ++i){ - p[i] = str[i]; - } - - return p; - } - -public: - bsl_test_shallow_copy_string() - : _cs_0(malloc_clone("bsl_string")), - _cs_0_len(strlen("bsl_string")), - _cs_0_size(_cs_0_len * sizeof(_CharT)), - _cs_1(malloc_clone("acumon")), - _cs_2(malloc_clone("ACUMON")), - _cs_3(malloc_clone("acumo")), - _cs_4(malloc_clone("acumon")), // == _cs_1 - _cs_5(malloc_clone("pudding")), - _empty_cs(malloc_clone("")), - _cs_0_add_1(malloc_clone("bsl_stringacumon")) - { - } - - ~bsl_test_shallow_copy_string(){ - free( _cs_0 ); - free( _cs_1 ); - free( _cs_0_add_1 ); - free( _cs_2 ); - free( _cs_3 ); - free( _cs_4 ); - free( _cs_5 ); - free( _empty_cs ); - } - - - void test_shallow_copy() - { - - const size_t char_size = sizeof(_CharT); - _Alloc all; - { - string_t s(_cs_0, 3,all,true); - TS_ASSERT( s.size() == 3 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, 3*char_size ) ); - // TS_ASSERT( s.c_str()[3] == '\0' ); - } - - { - string_t s(_cs_0, 3,all,false); - TS_ASSERT( s.size() == 3 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, 3*char_size ) ); - TS_ASSERT( s.c_str()[3] == '\0' ); - } - - /* { - string_t a(_cs_0); - string_t s(a,all,false); - TS_ASSERT( s.size() == a.size() ); - TS_ASSERT( 0 == memcmp( s.c_str(), a.c_str(), a.size() )); - TS_ASSERT( s.c_str()[s.size()]== '\0' ); - } - - - { - string_t a(_cs_0); - string_t s(a,all,true); - TS_ASSERT( s.size() == a.size() ); - TS_ASSERT( 0 == memcmp( s.c_str(), a.c_str(), a.size() )); - //TS_ASSERT( s.c_str()[s.size()]== '\0' ); - } - */ - { - string_t a(_cs_0); - string_t s(a); - TS_ASSERT( s.size() == a.size() ); - TS_ASSERT( 0 == memcmp( s.c_str(),a.c_str(), s.size() ) ); - TS_ASSERT( s.c_str() != a.c_str() ); - } - - { - string_t a(_cs_0, 3,all,true); - string_t s(a); - TS_ASSERT( s.size() == a.size() ); - TS_ASSERT( 0 == memcmp( s.c_str(),a.c_str(), s.size() ) ); - TS_ASSERT( s.c_str() == a.c_str() ); - } - - - } - -}; - -#endif //__BSL_TEST_STRING_HPP_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_shallow_copy_string.py b/bsl/unittest/bsl_test_shallow_copy_string.py deleted file mode 100755 index 67f8623bab2d345feb3e5c9bf4c58e4104b08e8c..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_shallow_copy_string.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -TEST_CLASS_NAME = 'bsl_test_shallow_copy_string' - -TEST_TYPES = [ 'normal' ] - -CHAR_TYPES = [ 'char', 'wchar_t', 'unsigned short', 'unsigned int' ] - -ALLOC_TYPES = [ 'bsl::bsl_alloc', 'std::allocator' ] - -TEST_METHODS= [ - 'test_shallow_copy' -] - -HEADER = """ -#ifndef __BSL_TEST_SHALLOW_COPY_STRING_H_ -#define __BSL_TEST_SHALLOW_COPY_STRING_H_ -#include -#include "bsl_test_shallow_copy_string.hpp" -class bsl_test_string_main : public CxxTest::TestSuite{ -public: -""" - -FOOTER = """ -}; -#endif //__BSL_TEST_SHALLOW_COPY_STRING_H_ -""" - -FUNCTION_TEMPLATE = """ - void test_%(test_type)s_%(escape_char_type)s_%(escape_alloc_type)s_%(escape_test_method)s(){ - return %(TEST_CLASS_NAME)s<%(char_type)s, %(alloc_type)s<%(char_type)s> >().%(escape_test_method)s(); - } -""" - -def escape(s): - return s.replace(' ','_').replace('::','_') - -if __name__ == '__main__': - print HEADER, - for test_type in TEST_TYPES: - for char_type in CHAR_TYPES: - escape_char_type = escape(char_type) - for alloc_type in ALLOC_TYPES: - escape_alloc_type = escape(alloc_type) - for test_method in TEST_METHODS: - escape_test_method = escape(test_method) - print FUNCTION_TEMPLATE % locals() - print FOOTER, - diff --git a/bsl/unittest/bsl_test_slist.h b/bsl/unittest/bsl_test_slist.h deleted file mode 100644 index f22966790f5d730bfb4bd076655a4cc69a420132..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_slist.h +++ /dev/null @@ -1,625 +0,0 @@ -// bsl_slist.cpp : 定义控制台应用程序的入口点。 -// - - -#include -#include -#include - -#include -#include -#include -#include -#include - -#define ERROR() printf("error%d\n", __LINE__) -#include -#if 0 -template -int test_iterate(bsl::slist list) -{ - int v=0; - for(list.iterator i=list.begin(); i!=list.end(); ++i) - { - if( *i != v) - ERROR(); - v++; - } -} -#endif -//template - -#include -class p -{ -public: - bool operator()(int q) - { - return q==50; - } -}; -class bsl_test_slist : public CxxTest::TestSuite -{ - public: - - void test_operator() - { - typedef bsl::slist::iterator Iter; - { - { - bsl::slist l1; - bsl::slist l2; - l1.create(); - l2.create(); - TS_ASSERT(0 == l1.size()); - TS_ASSERT(0 == l2.size()); - TS_ASSERT( 0 != l1.erase_after( l1.begin() ) ); - TS_ASSERT( l1.begin() == l1.end() ); - TS_ASSERT( l2.begin() == l2.end() ); - } - { - bsl::slist l1; - bsl::slist l2; - for (int i = 0; i < 5; i ++) { - l1.push_front(i); - } - TS_ASSERT( 5 == l1.size() ); - - for (int i = 0; i < 60; i ++) { - l2.push_front(i); - } - TS_ASSERT( 60 == l2.size() ); - - Iter f1,f2; - f1 = l1.begin(); - f2 = l2.begin(); - - for (size_t i = 1; i < l1.size(); i ++) { - f1 ++; - f2 ++; - } - Iter tmp = f1; - f2 ++; - while (f2 != l2.end()) { - l1.insert_after( f1, *f2 ); - f1 ++; - f2 ++; - } - TS_ASSERT(60 == l1.size()); - TS_ASSERT(60 == l2.size()); - - l1.erase_after( tmp, l1.end() ); - TS_ASSERT(5 == l1.size()); - int i = 4; - for (Iter iter = l1.begin(); iter != l1.end(); ++ iter) { - TS_ASSERT( i == *iter ); - i --; - } - } - { - bsl::slist l1; - bsl::slist l2; - for (int i = 0; i < 5; i ++) { - l1.push_front(i); - } - - for (int i = 0; i < 60; i ++) { - l2.push_front(i); - } - TS_ASSERT( 60 == l2.size() ); - l2 = l1; - TS_ASSERT( 5 == l2.size() ); - - TS_ASSERT( l2.size() == l1.size() ); - Iter iter1,iter2; - for (iter1 = l1.begin(), iter2 = l2.begin(); iter1 != l1.end() && iter2 != l2.end(); ++ iter1, ++ iter2) { - TS_ASSERT( *iter1 == *iter2); - } - } - { - bsl::slist l1; - bsl::slist l2; - for (int i = 0; i < 5; i ++) { - l1.push_front(i); - } - - for (int i = 0; i < 60; i ++) { - l2.push_front(i); - } - l1 = l2; - TS_ASSERT( l2.size() == l1.size() ); - Iter iter1,iter2; - for (iter1 = l1.begin(), iter2 = l2.begin(); iter1 != l1.end() && iter2 != l2.end(); ++ iter1, ++ iter2) { - TS_ASSERT( *iter1 == *iter2); - } - } - { - bsl::slist l1; - for (int i = 0; i < 5; i ++) { - l1.push_front(i); - } - TS_ASSERT( 5 == l1.size() ); - bsl::slist l2(l1); - TS_ASSERT( l1.size() == l2.size() ); - Iter iter1,iter2; - for (iter1 = l1.begin(), iter2 = l2.begin(); iter1 != l1.end() && iter2 != l2.end(); ++ iter1, ++ iter2) { - TS_ASSERT( *iter1 == *iter2 ); - } - } - { - bsl::slist t1; - for (int i = 0; i < 100; i ++) { - t1.push_front(i); - } - TS_ASSERT(100 == t1.size()); - bsl::slist t2; - t2 = t1; - TS_ASSERT( 100 == t2.size() ); - int i = 99; - for (bsl::slist::iterator Iter = t2.begin(); Iter != t2.end(); ++ Iter) { - TS_ASSERT( *Iter == i -- ); - } - i = 99; - t1 = t1; - TS_ASSERT( 100 == t1.size() ); - for (bsl::slist::iterator Iter = t1.begin(); Iter != t1.end(); ++ Iter) { - TS_ASSERT( *Iter == i -- ); - } - bsl::slist t3; - t3.push_front(1); - TS_ASSERT( 1 == *t3.begin() ); - TS_ASSERT(1 == t3.size()); - bsl::slist t5; - bsl::slist t4; - t4 = t3; - TS_ASSERT(0 == t5.size()); - TS_ASSERT(1 == t4.size()); - t3.pop_front(); - t3 = t5; - TS_ASSERT( 0 == t3.size() ); - t1 = t3; - TS_ASSERT( 0 == t1.size() ); - TS_ASSERT( 0 == t3.size() ); - } - } - { - bsl::slist l1; - bsl::slist l2; - for (int i = 0; i < 1000; i ++) { - l1.push_front( "hello world" ); - } - TS_ASSERT(1000 == l1.size()); - for (int i = 0; i < 100; i ++) { - l2 = l1; - } - TS_ASSERT(1000 == l1.size()); - TS_ASSERT(1000 == l2.size()); - } - } - void test_create() - { - bsl::slist l1; - int i; - for (i = 0; i < 10000; i ++) { - l1.create(); - } - for (i = 0; i < 10000; i ++) { - l1.create(); - } - bsl::slist l2; - for (i = 0; i < 10000; i ++) { - l2.create(); - } - TS_ASSERT(0 == l1.size()); - TS_ASSERT(0 == l2.size()); - for (i = 0; i < 100; i ++) { - l2.push_front(i); - } - TS_ASSERT( 100 == l2.size() ); - } - void test_string() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t1.push_front(std::string("123"))); - TS_ASSERT(!t1.push_front(std::string("abc"))); - TS_ASSERT(!t1.push_front(std::string("ABC"))); - TS_ASSERT(3 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - void test_push_front() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(0 == t1.size()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - int v = 99; - for(bsl::slist::iterator i = t1.begin(); i != t1.end(); i++) - { - TS_ASSERT_EQUALS(*i, v); - v--; - } - TS_ASSERT(!t1.destroy()); - } - void test_assign() - { - bsl::slist t1, t2; - TS_ASSERT(!t1.create()); - for (int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - TS_ASSERT(!t2.create()); - t2.assign(t1.begin(), t1.end()); - TS_ASSERT(100 == t2.size()); - int v = 99; - for(bsl::slist::iterator i1 = t2.begin(); i1!=t2.end(); ++i1) - { - TS_ASSERT_EQUALS( *i1, v); - v--; - } - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - - void test_const() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - const bsl::slist & t2 = t1; - int p = 1; - for(bsl::slist::const_iterator i1 = t2.begin(); i1!=t2.end(); ++i1) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - TS_ASSERT(!t1.destroy()); - } - void test_const1() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - const bsl::slist & t2 = t1; - int p = 1; - for(bsl::slist::const_iterator i1 = t2.begin(); i1!=t2.end(); i1++) - { - TS_ASSERT_EQUALS(p , *i1); - p++; - } - TS_ASSERT(!t1.destroy()); - } - void test_const2() - { - bsl::slist::const_iterator i = bsl::slist::iterator(); - } - - void test_pop_front() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i, t1.front()); - t1.pop_front(); - } - TS_ASSERT(0 == t1.size()); - TS_ASSERT(!t1.destroy()); - } - void test_sort() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(rand())); - //TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - t1.sort(); - TS_ASSERT_EQUALS(t1.size() , 100); - for(bsl::slist::iterator i1 = t1.begin(); i1!=t1.end(); ++i1) - { - //TS_ASSERT(tmp > *i1); - // printf("%d\n", *i1); - /* if( *i1 != v) - { - printf("%d, %d",*i1, v); - ERROR(); - } - v--;*/ - } - TS_ASSERT(!t1.destroy()); - } - void test_sort1() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - //TS_ASSERT(!t1.push_front(rand())); - TS_ASSERT(!t1.push_front(i)); - } - t1.sort(std::less()); - TS_ASSERT_EQUALS(t1.size() , 100); - for(bsl::slist::iterator i1 = t1.begin(); i1!=t1.end(); ++i1) - { - // printf("%d\n", *i1); - /* if( *i1 != v) - { - printf("%d, %d",*i1, v); - ERROR(); - } - v--;*/ - } - TS_ASSERT(!t1.destroy()); - } - void test_remove() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.remove(50); - TS_ASSERT_EQUALS(t1.size(), 99); - TS_ASSERT(!t1.destroy()); - } - - void test_remove1() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(!t1.remove_if(p())); - TS_ASSERT_EQUALS(t1.size(), 99); - TS_ASSERT(!t1.destroy()); - } - - void test_erase_after() - { - bsl::slist t1; - bsl::slist t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.erase_after(t1.begin()); - t2.erase_after(t1.begin()); - TS_ASSERT_EQUALS(t1.size(), 98); - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - void test_erase_after1() - { - bsl::slist t1; - bsl::slist t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.erase_after(t1.begin(), t1.end()); - TS_ASSERT_EQUALS(t1.size(), 1); - TS_ASSERT_EQUALS(t2.size(), 0); - - for(int i=100; i>0; i--) - { - TS_ASSERT(!t1.push_front(i)); - } - t2.erase_after(t1.begin(), t1.end()); - TS_ASSERT_EQUALS(t1.size(), 1); - TS_ASSERT_EQUALS(t2.size(), 0); - - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - void test_reverse() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - t1.reverse(); - TS_ASSERT_EQUALS(t1.size(), 100); - for(int i=0; i<100; i++) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - TS_ASSERT(!t1.destroy()); - } - void test_swap() - { - bsl::slist t1; - bsl::slist t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - for(int i=0; i<50; i++) - { - TS_ASSERT(!t2.push_front(3 * i)); - } - t2.swap(t1); - TS_ASSERT_EQUALS(t1.size() , 50); - TS_ASSERT_EQUALS(t2.size() , 100); - TS_ASSERT(!t1.destroy()); - TS_ASSERT(!t2.destroy()); - } - - - void test_serialization() - { - - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - - bsl::filestream fd; - fd.open("data", "w"); - fd.setwbuffer(1<<20); - bsl::binarchive ar(fd); - TS_ASSERT (ar.write(t1) == 0); - fd.close(); - - t1.clear(); - TS_ASSERT_EQUALS(t1.size(), 0); - std::string str; - fd.open("data", "r"); - { - bsl::binarchive ar(fd); - TS_ASSERT (ar.read(&t1) == 0); - fd.close(); - } - TS_ASSERT_EQUALS(t1.size(), 100); - for(int i=99; i>=0; i--) - { - TS_ASSERT_EQUALS(i ,t1.front()); - t1.pop_front(); - } - } - void test_previous() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - - bsl::slist::iterator i1 = t1.begin(); - for(int i =0; i<50; ++i) - { - i1++; - } - TS_ASSERT_EQUALS(*i1, 49); - TS_ASSERT_EQUALS(*t1.previous(i1), 50); - } - void test_merge() - { - //bsl::slist > t1; - //bsl::slist > t1; - bsl::slist t1; - bsl::slist t2; - TS_ASSERT(!t1.create()); - TS_ASSERT(!t2.create()); - t2.merge(t1); - TS_ASSERT_EQUALS(t2.empty() , true); - for(int i=49; i>=0; i--) - { - TS_ASSERT(!t1.push_front(2*i)); - } - TS_ASSERT_EQUALS(t2.size() , 0); - t2.merge(t1); - TS_ASSERT_EQUALS(t2.size() , 50); - for(int i=49; i>=0; i--) - { - TS_ASSERT(!t1.push_front(2*i+1)); - } - t2.merge(t1); - TS_ASSERT_EQUALS(t1.empty() , true); - TS_ASSERT_EQUALS(t2.size() , 100); - TS_ASSERT(!t1.destroy()); - bsl::slist::iterator p = t2.begin(); - for(int v = 0; v < 100; v++) - { - TS_ASSERT_EQUALS(*p , v); - p++; - } - TS_ASSERT(!t2.destroy()); - } - void test_size() - { - bsl::slist t1; - TS_ASSERT(!t1.create()); - const size_t N = 1000000; - for(size_t i=0; i li; - - bsl::slist::iterator it1 = li.begin(); - bsl::slist::iterator it2 = li.end(); - TS_ASSERT(it1 == it2); - - bsl::slist::const_iterator cit1 = li.begin(); - bsl::slist::const_iterator cit2 = li.end(); - - } - { - //const - const bsl::slist li; - - bsl::slist::const_iterator cit1 = li.begin(); - bsl::slist::const_iterator cit2 = li.end(); - TS_ASSERT(cit1 == cit2); - } - } - - void test_iterator_2(){ - bsl::slist t1; - TS_ASSERT(!t1.create()); - TS_ASSERT(0 == t1.size()); - for(int i=0; i<100; i++) - { - TS_ASSERT(!t1.push_front(i)); - } - TS_ASSERT(100 == t1.size()); - int v = 99; - for(bsl::slist::iterator i = t1.begin(); i != t1.end(); i++) - { - TS_ASSERT_EQUALS(*i, v); - v--; - } - v = 99; - for(bsl::slist::iterator i = t1.begin(); i != t1.end(); ++i) - { - TS_ASSERT_EQUALS(*i, v); - v--; - } - TS_ASSERT(!t1.destroy()); - } - -}; diff --git a/bsl/unittest/bsl_test_stack.h b/bsl/unittest/bsl_test_stack.h deleted file mode 100644 index 91ab3ea955ebc37b6cf8f7ed72189339d733b354..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_stack.h +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include - -std::string rand_string() -{ - std::string str; - srand(time(NULL)); - int n = rand()%100; - for (int i = 0; i < n; ++i) { - str += 'a' + rand()%26; - } - return str; -} - -struct MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - - -template -Tp rand_value(); - -template<> -int rand_value(){ - return rand(); -} - -template<> -std::string rand_value(){ - return rand_string(); -} - -template<> -MyClass rand_value(){ - MyClass ret; - std::string name = rand_string(); - std::string value = rand_string(); - memcpy(ret.name, name.c_str(), name.size()); - memcpy(ret.value, value.c_str(), value.size()); - return ret; -} - - -template -void test_stack(){ - typedef Tp val_type; - typedef std::stack Stack; - - const int N = 10; - const int M = 5; - std::vector vec(N); - for(int i = 0; i < N; ++i){ - vec[i] = rand_value(); - } - //定义 - Stack st; - TS_ASSERT(st.size() == 0); - //push - for(int i = 0; i < N; ++i){ - st.push(vec[i]); - } - TS_ASSERT((int)st.size() == N); - //pop - for(int i = N - 1; i >= M; --i){ - TS_ASSERT(st.top() == vec[i]); - st.pop(); - } - TS_ASSERT((int)st.size() == M); - TS_ASSERT(st.top() == vec[M - 1]); - - //const reference - const Stack& cst = st; - TS_ASSERT(cst.empty() == false); - TS_ASSERT((int)cst.size() == M); - - //top refenrnce - const val_type& v1 = cst.top(); - val_type& v2 = st.top(); - TS_ASSERT(v1 == v2); - - //copy construct - Stack st2(st); - for(int i = M - 1; i >= 0; --i){ - TS_ASSERT(st2.top() == vec[i]); - st2.pop(); - } - TS_ASSERT((int)st2.size() == 0); - TS_ASSERT(st2.empty() == true); - TS_ASSERT((int)st.size() == M); - TS_ASSERT(st.empty() == false); - //assignment - Stack st3; - st3 = st; - for(int i = M - 1; i >= 0; --i){ - TS_ASSERT(st3.top() == vec[i]); - st3.pop(); - } - TS_ASSERT((int)st3.size() == 0); - TS_ASSERT(st3.empty() == true); - TS_ASSERT((int)st.size() == M); - TS_ASSERT(st.empty() == false); - return; -} - -class bsl_test_stack : public CxxTest::TestSuite -{ -public: - void test_stack_with_int_deque(){ - test_stack >(); - } - void test_stack_with_string_deque(){ - test_stack >(); - } - void test_stack_with_myclass_deque(){ - test_stack >(); - } - void test_stack_with_int_list(){ - test_stack >(); - } - void test_stack_with_string_list(){ - test_stack >(); - } - void test_stack_with_myclass_list(){ - test_stack >(); - } -}; diff --git a/bsl/unittest/bsl_test_string.h b/bsl/unittest/bsl_test_string.h deleted file mode 100644 index 44ce4dcb05ce584a1863e80aaff635ef24e8f877..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_string.h +++ /dev/null @@ -1,1250 +0,0 @@ - -#ifndef __BSL_TEST_STRING_H_ -#define __BSL_TEST_STRING_H_ -#include -#include "bsl_test_string.hpp" -class bsl_test_string_main : public CxxTest::TestSuite{ -public: - - void test_normal_char_bsl_bsl_alloc_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_char_bsl_bsl_alloc_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_char_bsl_bsl_alloc_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_char_bsl_bsl_alloc_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_char_bsl_bsl_alloc_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_char_bsl_bsl_alloc_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_char_bsl_bsl_alloc_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_char_bsl_bsl_alloc_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_char_bsl_bsl_alloc_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_char_bsl_bsl_alloc_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_char_bsl_bsl_alloc_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_char_bsl_bsl_alloc_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_char_bsl_bsl_alloc_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_char_bsl_bsl_alloc_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_char_bsl_bsl_alloc_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_char_bsl_bsl_alloc_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_char_std_allocator_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_char_std_allocator_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_char_std_allocator_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_char_std_allocator_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_char_std_allocator_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_char_std_allocator_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_char_std_allocator_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_char_std_allocator_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_char_std_allocator_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_char_std_allocator_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_char_std_allocator_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_char_std_allocator_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_char_std_allocator_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_char_std_allocator_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_char_std_allocator_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_char_std_allocator_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_char_std_allocator_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_char_std_allocator_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_char_std_allocator_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_char_std_allocator_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_char_std_allocator_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_char_std_allocator_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_char_std_allocator_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_char_std_allocator_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_char_std_allocator_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_char_std_allocator_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_char_std_allocator_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_char_std_allocator_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_char_std_allocator_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_char_std_allocator_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_char_std_allocator_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_wchar_t_bsl_bsl_alloc_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_wchar_t_std_allocator_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_wchar_t_std_allocator_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_wchar_t_std_allocator_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_wchar_t_std_allocator_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_wchar_t_std_allocator_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_wchar_t_std_allocator_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_wchar_t_std_allocator_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_wchar_t_std_allocator_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_wchar_t_std_allocator_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_wchar_t_std_allocator_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_wchar_t_std_allocator_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_wchar_t_std_allocator_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_wchar_t_std_allocator_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_wchar_t_std_allocator_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_wchar_t_std_allocator_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_wchar_t_std_allocator_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_wchar_t_std_allocator_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_wchar_t_std_allocator_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_wchar_t_std_allocator_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_wchar_t_std_allocator_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_wchar_t_std_allocator_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_unsigned_short_bsl_bsl_alloc_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_unsigned_short_std_allocator_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_unsigned_short_std_allocator_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_unsigned_short_std_allocator_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_unsigned_short_std_allocator_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_unsigned_short_std_allocator_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_unsigned_short_std_allocator_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_unsigned_short_std_allocator_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_unsigned_short_std_allocator_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_unsigned_short_std_allocator_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_unsigned_short_std_allocator_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_unsigned_short_std_allocator_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_unsigned_short_std_allocator_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_unsigned_short_std_allocator_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_unsigned_short_std_allocator_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_unsigned_short_std_allocator_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_unsigned_short_std_allocator_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_unsigned_int_bsl_bsl_alloc_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - - void test_normal_unsigned_int_std_allocator_test_ctors(){ - return bsl_test_string >().test_ctors(); - } - - - void test_normal_unsigned_int_std_allocator_test_c_str(){ - return bsl_test_string >().test_c_str(); - } - - - void test_normal_unsigned_int_std_allocator_test_empty(){ - return bsl_test_string >().test_empty(); - } - - - void test_normal_unsigned_int_std_allocator_test_size(){ - return bsl_test_string >().test_size(); - } - - - void test_normal_unsigned_int_std_allocator_test_length(){ - return bsl_test_string >().test_length(); - } - - - void test_normal_unsigned_int_std_allocator_test_capacity(){ - return bsl_test_string >().test_capacity(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_square(){ - return bsl_test_string >().test_operator_square(); - } - - - void test_normal_unsigned_int_std_allocator_test_clear(){ - return bsl_test_string >().test_clear(); - } - - - void test_normal_unsigned_int_std_allocator_test_reserve(){ - return bsl_test_string >().test_reserve(); - } - - - void test_normal_unsigned_int_std_allocator_test_swap(){ - return bsl_test_string >().test_swap(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_assign_to_null(){ - return bsl_test_string >().test_operator_assign_to_null(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_assign_to_cstring(){ - return bsl_test_string >().test_operator_assign_to_cstring(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_assign_to_string(){ - return bsl_test_string >().test_operator_assign_to_string(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_eq_eq(){ - return bsl_test_string >().test_operator_eq_eq(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_not_eq(){ - return bsl_test_string >().test_operator_not_eq(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_lt(){ - return bsl_test_string >().test_operator_lt(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_gt(){ - return bsl_test_string >().test_operator_gt(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_lt_eq(){ - return bsl_test_string >().test_operator_lt_eq(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_gt_eq(){ - return bsl_test_string >().test_operator_gt_eq(); - } - - - void test_normal_unsigned_int_std_allocator_test_operator_shift(){ - return bsl_test_string >().test_operator_shift(); - } - - - void test_normal_unsigned_int_std_allocator_test_serialization(){ - return bsl_test_string >().test_serialization(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_str(){ - return bsl_test_string >().test_append_str(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_sub_str(){ - return bsl_test_string >().test_append_sub_str(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_cstr(){ - return bsl_test_string >().test_append_cstr(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_sub_cstr(){ - return bsl_test_string >().test_append_sub_cstr(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_n_char(){ - return bsl_test_string >().test_append_n_char(); - } - - - void test_normal_unsigned_int_std_allocator_test_append_range(){ - return bsl_test_string >().test_append_range(); - } - - - void test_normal_unsigned_int_std_allocator_test_push_back(){ - return bsl_test_string >().test_push_back(); - } - - - void test_normal_unsigned_int_std_allocator_test_appendf(){ - return bsl_test_string >().test_appendf(); - } - - - void test_normal_unsigned_int_std_allocator_test_find(){ - return bsl_test_string >().test_find(); - } - - - void test_normal_unsigned_int_std_allocator_test_rfind(){ - return bsl_test_string >().test_rfind(); - } - - -}; -#endif //__BSL_TEST_STRING_H_ diff --git a/bsl/unittest/bsl_test_string.hpp b/bsl/unittest/bsl_test_string.hpp deleted file mode 100644 index e0682d72ddaba0e372caa8d742b32ff38997fd84..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_string.hpp +++ /dev/null @@ -1,1245 +0,0 @@ - - -/** - * @file bsl_test_string.hpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/12 17:29:08 - * @version $Revision: 1.10 $ - * @brief - * - **/ -#ifndef __BSL_TEST_STRING_HPP_ -#define __BSL_TEST_STRING_HPP_ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< - * example: CXM_ASSERT( 3 + 3 != 6, <<"test: "< -class bsl_test_string{ -private: - typedef bsl::basic_string<_CharT,_Alloc> string_t; - _CharT *_cs_0; - const size_t _cs_0_len; - const size_t _cs_0_size; - _CharT* _cs_1; - _CharT* _cs_2; - _CharT* _cs_3; - _CharT* _cs_4; - _CharT* _cs_5; - _CharT* _empty_cs; - _CharT* _cs_0_add_1; - - static _CharT * malloc_clone( const char * str ){ - size_t len = strlen(str); - _CharT * p = static_cast<_CharT*>(malloc( (len+1)*sizeof(_CharT) )); - for( size_t i = 0; i<=len; ++i){ - p[i] = str[i]; - } - - return p; - } - -public: - bsl_test_string() - : _cs_0(malloc_clone("bsl_string")), - _cs_0_len(strlen("bsl_string")), - _cs_0_size(_cs_0_len * sizeof(_CharT)), - _cs_1(malloc_clone("acumon")), - _cs_2(malloc_clone("ACUMON")), - _cs_3(malloc_clone("acumo")), - _cs_4(malloc_clone("acumon")), // == _cs_1 - _cs_5(malloc_clone("pudding")), - _empty_cs(malloc_clone("")), - _cs_0_add_1(malloc_clone("bsl_stringacumon")) - { - } - - ~bsl_test_string(){ - free( _cs_0 ); - free( _cs_1 ); - free( _cs_0_add_1 ); - free( _cs_2 ); - free( _cs_3 ); - free( _cs_4 ); - free( _cs_5 ); - free( _empty_cs ); - } - - - void test_ctors(){ - - const size_t char_size = sizeof(_CharT); - // default ctor - { - string_t s; - TS_ASSERT( s.size() == 0); - TS_ASSERT( s.c_str() != NULL ); - TS_ASSERT( s.c_str()[0] == '\0' ); - } - - // bsl_string( const _CharT * ) - { - string_t s(_cs_0); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, _cs_0_size )); - TS_ASSERT( s.c_str()[s.size()]== '\0' ); - } - - - // bsl_basic_string( const_pointer str, size_type len ) throw(/*BadAllocException*/) - { - string_t s(_cs_0, 3); - TS_ASSERT( s.size() == 3 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, 3*char_size ) ); - TS_ASSERT( s.c_str()[3] == '\0' ); - } - - // bsl_basic_string( const bsl_basic_string& other, size_type begin_pos ) throw(/*BadAllocException*/) - { - string_t _s=_cs_0; //patch for g++2.96 - string_t s(_s, 2); //s = "l_string" - TS_ASSERT( s.size() == _cs_0_len -2 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0+2, (_cs_0_len-2)*char_size ) ); - TS_ASSERT( s.c_str()[_cs_0_len-2] == '\0' ); - } - - - // bsl_basic_string( const bsl_basic_string& other, size_type begin_pos, size_type sub_str_len ) throw(/*BadAllocException*/) - { - string_t _s=_cs_0; //patch for g++2.96 - string_t s(_s, 1, 4); //s = "sl_s" - TS_ASSERT( s.size() == 4 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0+1, 4*char_size ) ); - TS_ASSERT( s.c_str()[4] == '\0' ); - } - - // bsl_basic_string( const_pointer cstr, size_type cstr_len, const allocator_type& = allocator_type() ) throw(/*BadAllocException*/) - { - string_t s(_cs_0, 2); //s = "ac" - TS_ASSERT( s.size() == 2 ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, 2*char_size ) ); - TS_ASSERT( s.c_str()[2] == '\0' ); - } - - // bsl_basic_string( const_pointer cstr, const allocator_type& = allocator_type() ) throw(/*BadAllocException*/) - { - string_t s(_cs_0); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, _cs_0_size ) ); - TS_ASSERT( s.c_str()[s.size()] == '\0' ); - } - - // bsl_basic_string( size_type n, value_type chr, const allocator_type& = allocator_type() ) - { - _CharT cs2[] = { 'a','a','a','a' }; - size_t cs2_len = sizeof(cs2)/sizeof(*cs2); - string_t s(cs2_len, 'a'); - TS_ASSERT( s.size() == cs2_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), cs2, sizeof(cs2 )) ); - TS_ASSERT( s.c_str()[s.size()] == '\0' ); - } - - // template bsl_basic_string( InputIterator __begin, InputIterator __end, const allocator_type& = allocator_type() ) - { - string_t s(_cs_0,_cs_0+_cs_0_len); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, _cs_0_size )); - TS_ASSERT( s.c_str()[s.size()]== '\0' ); - } - } - // getters - void test_c_str(){ - //empty c_str() - { - string_t s; - TS_ASSERT( s.c_str() != NULL ); - TS_ASSERT( s.c_str()[0] == '\0' ); - } - - - //string from const _CharT * - { - string_t s(_cs_0); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, _cs_0_size )); - TS_ASSERT( s.c_str() != _cs_0 ); - TS_ASSERT( s.c_str()[s.size()]== '\0' ); - } - - //string from another string - { - string_t _s(_cs_0), s(_s); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( 0 == memcmp( s.c_str(), _cs_0, _cs_0_size )); - TS_ASSERT( s.c_str() != _s.c_str() ); - TS_ASSERT( s.c_str()[s.size()]== '\0' ); - - } - - - } - - void test_empty() { - //string from default ctor - { - string_t s; - TS_ASSERT( s.empty() ); - } - - //string after clear() - { - string_t s(_cs_0); - s.clear(); - TS_ASSERT( s.empty() ); - } - - //string after ="" - { - string_t s(_cs_0); - s = _empty_cs; - TS_ASSERT( s.empty() ); - } - - } - - void test_size() { - //empty string size - { - string_t s; - TS_ASSERT( s.size() == 0 ); - } - - //string from cstring - { - string_t s(_cs_0); - TS_ASSERT( s.size() == _cs_0_len ); - } - - //string after = - { - _CharT cs2[] = { 'h', 'i', '\0' }; - string_t s(_cs_0); - s = cs2; - TS_ASSERT( s.size() == sizeof(cs2)/sizeof(*cs2) -1); - - s = _empty_cs; - TS_ASSERT( s.size() == 0 ); - } - - } - - void test_length() { - //empty string length - { - string_t s; - TS_ASSERT( s.length() == 0 ); - } - - //string from cstring - { - string_t s(_cs_0); - TS_ASSERT( s.length() == _cs_0_len ); - } - - //string after = - { - _CharT cs2[] = { 'h', 'i', '\0' }; - string_t s(_cs_0); - s = cs2; - TS_ASSERT( s.length() == sizeof(cs2)/sizeof(*cs2) -1); - - s = _empty_cs; - TS_ASSERT( s.length() == 0 ); - } - - } - - /** - * @brief - * - * @return size_type - * @retval - * @see - * @author chenxm - * @date 2008/09/10 21:38:24 - **/ - void test_capacity(){ - //empty string - { - TS_ASSERT( string_t().capacity() == 0 ); - } - - //normal string - { - TS_ASSERT( string_t(_cs_0).capacity() >= string_t(_cs_0).length() ); - } - - } - - void test_operator_square(){ - - //normal string - { - string_t s = _cs_0; - for( size_t i = 0; i < _cs_0_len; ++ i ){ - TS_ASSERT( s[i] == _cs_0[i] ); - } - } - - //const string - { - const string_t s = _cs_0; - for( size_t i = 0; i < _cs_0_len; ++ i ){ - TS_ASSERT( s[i] == _cs_0[i] ); - } - } - - //test writing - { - const _CharT cs2[] = { 'l','i','v','e','\0' }; - string_t s(cs2); - s[0] = cs2[3]; s[1] = cs2[2]; s[2] = cs2[1]; s[3] = cs2[0]; - const _CharT expected[] = { 'e', 'v', 'i', 'l', '\0' }; - TS_ASSERT( 0 == memcmp( s.c_str(), expected, sizeof(expected) )); - } - - } - - // setters - void test_clear(){ - //empty string - { - string_t s; - s.clear(); - TS_ASSERT( s.c_str()[0] == 0 ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s == string_t() ); - - } - - //normal string - { - string_t s(_cs_0); - s.clear(); - TS_ASSERT( s.c_str()[0] == 0 ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.capacity() == string_t(_cs_0).capacity() ); - - } - - } - - void test_reserve(){ - //empty string - { - string_t s; - TS_ASSERT( s.capacity() == 0 ); - s.reserve(1); - TS_ASSERT( s.capacity() == 1 ); - s.reserve(123); - TS_ASSERT( s.capacity() == 123 ); - s.reserve(100); - TS_ASSERT( s.capacity() == 123 ); //ignore request for smaller capacity - } - - //normal string - { - string_t s(_cs_0); - s.reserve(1); //ignored - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.capacity() == _cs_0_len ); - s.reserve(100); - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.capacity() == std::max(size_t(100),_cs_0_len) ); - - } - - } - - void test_swap(){ - //swap method - { - string_t s1(_cs_1), s2(_cs_2); - const _CharT *p1=s1.c_str(), *p2=s2.c_str(); - size_t len1=s1.size(), len2=s2.size(),cap1=s1.capacity(),cap2=s2.capacity(); - s1.swap(s2); - TS_ASSERT( s1.c_str() == p2 ); - TS_ASSERT( s1.size() == len2 ); - TS_ASSERT( s1.capacity() == cap2 ); - TS_ASSERT( s2.c_str() == p1 ); - TS_ASSERT( s2.size() == len1 ); - TS_ASSERT( s2.capacity() == cap1 ); - - } - - //std::swap() - //不推荐使用!这个复杂度高达O(s1.size()+s2.size())! - { - string_t s1(_cs_1), s2(_cs_2); - const _CharT *p1=s1.c_str(), *p2=s2.c_str(); - size_t len1=s1.size(), len2=s2.size(); - std::swap(s1,s2); - TS_ASSERT( s1.c_str() != p2 ); //因为发生了深复制 - TS_ASSERT( s1 == string_t(_cs_2) ); //但是字面值是相等的 - TS_ASSERT( s1.size() == len2 ); - TS_ASSERT( s1.capacity() == len2 ); //因为字符串是重新构造的,因此会"trim to size" - TS_ASSERT( s2.c_str() != p1 ); //因为发生了深复制 - TS_ASSERT( s2 == string_t(_cs_1) ); - TS_ASSERT( s2.size() == len1 ); - TS_ASSERT( s2.capacity() == len1 ); - - } - } - - /** - * @brief deprecated bsl::string don't accept NULL any more, and will throw NullPointerException in the future - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2008/11/09 01:00:48 - **/ - void test_operator_assign_to_null(){ - - /* - //empty string to null - { - string_t s; - s = NULL; - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == 0 ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - //normal string to null - { - string_t s(_cs_0); - s = NULL; - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == _cs_0_len ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - */ - } - - void test_operator_assign_to_cstring(){ - //empty string to empty string - { - string_t s; - s = _empty_cs; - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == 0 ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - //empty string to normal string - { - string_t s; - s = _cs_0; - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( s.capacity() == _cs_0_len ); - } - //normal string to empty string - { - string_t s(_cs_0); - s = _empty_cs; - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == _cs_0_len ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - //normal string to normal string - { - char _cs2[] = "hello world!"; - char _cs3[] = "no ResourcePool, no rp!"; - char _cs4[] = "no money no talk"; - _CharT * cs2 = malloc_clone(_cs2); - _CharT * cs3 = malloc_clone(_cs3); - _CharT * cs4 = malloc_clone(_cs4); - size_t cs2_len = sizeof(_cs2)/sizeof(*_cs2)-1; - size_t cs3_len = sizeof(_cs3)/sizeof(*_cs3)-1; - size_t cs4_len = sizeof(_cs4)/sizeof(*_cs4)-1; - - string_t s(_cs_0); - s = cs2; - TS_ASSERT( s == string_t(cs2) ); - TS_ASSERT( s.size() == cs2_len ); - TS_ASSERT( s.capacity() == cs2_len ); - TS_ASSERT( s.c_str()[cs2_len] == 0 ); - - s = cs3; - TS_ASSERT( s == string_t(cs3) ); - TS_ASSERT( s.size() == cs3_len ); - TS_ASSERT( s.capacity() == cs3_len ); - TS_ASSERT( s.c_str()[cs3_len] == 0 ); - - s = cs4; - TS_ASSERT( s == string_t(cs4) ); - TS_ASSERT( s.size() == cs4_len ); - TS_ASSERT( s.capacity() == cs4_len ); - TS_ASSERT( s.c_str()[cs4_len] == 0 ); - - free( cs2 ); - free( cs3 ); - free( cs4 ); - } - - - //empty string to self - { - string_t s(_empty_cs); - s = s.c_str(); - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == 0 ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - //normal string to self - { - string_t s(_cs_0); - s = s.c_str(); - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( s.capacity() == _cs_0_len ); - TS_ASSERT( s.c_str()[_cs_0_len] == 0 ); - } - } - - void test_operator_assign_to_string(){ - //empty string to empty string - { - string_t s; - s = string_t(); - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == 0 ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - //empty string to normal string - { - string_t s; - s = string_t(_cs_0); - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( s.capacity() == _cs_0_len ); - } - - //normal string to empty string - { - string_t s(_cs_0); - s = string_t(); - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == _cs_0_len ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - //normal string to normal string - { - char _cs2[] = "hello world!"; - char _cs3[] = "no ResourcePool, no rp!"; - char _cs4[] = "no money no talk"; - _CharT * cs2 = malloc_clone(_cs2); - _CharT * cs3 = malloc_clone(_cs3); - _CharT * cs4 = malloc_clone(_cs4); - size_t cs2_len = sizeof(_cs2)/sizeof(*_cs2)-1; - size_t cs3_len = sizeof(_cs3)/sizeof(*_cs3)-1; - size_t cs4_len = sizeof(_cs4)/sizeof(*_cs4)-1; - string_t s2 = cs2; - string_t s3 = cs3; - string_t s4 = cs4; - - string_t s(_cs_0); - s = s2; - TS_ASSERT( s == string_t(cs2) ); - TS_ASSERT( s.size() == cs2_len ); - TS_ASSERT( s.capacity() == cs2_len );//cs2_len > _cs_0_len - TS_ASSERT( s.c_str()[cs2_len] == 0 ); - - s = s3; - TS_ASSERT( s == string_t(cs3) ); - TS_ASSERT( s.size() == cs3_len ); - TS_ASSERT( s.capacity() == cs3_len );//cs3_len > cs2_len - TS_ASSERT( s.c_str()[cs3_len] == 0 ); - - s = s4; - TS_ASSERT( s == string_t(cs4) ); - TS_ASSERT( s.size() == cs4_len ); - TS_ASSERT( s.capacity() == cs3_len );//cs4_len < cs3_len - TS_ASSERT( s.c_str()[cs4_len] == 0 ); - - free( cs2 ); - free( cs3 ); - free( cs4 ); - } - - //empty string to self - { - string_t s(_empty_cs); - s = s; - TS_ASSERT( s == string_t() ); - TS_ASSERT( s.size() == 0 ); - TS_ASSERT( s.capacity() == 0 ); - TS_ASSERT( s.c_str()[0] == 0 ); - } - - //normal string to self - { - string_t s(_cs_0); - s = s; - TS_ASSERT( s == string_t(_cs_0) ); - TS_ASSERT( s.size() == _cs_0_len ); - TS_ASSERT( s.capacity() == _cs_0_len ); - TS_ASSERT( s.c_str()[_cs_0_len] == 0 ); - } - } - - - void test_operator_eq_eq(){ - _CharT cs2[] = {'b','s','l','_','s','t','r','i','n','g','\0'}; - _CharT cs3[] = {'n','o','t',' ','e','q','\0'}; - //string and string - { - TS_ASSERT( string_t() == string_t() ); - TS_ASSERT( string_t(_cs_0) == string_t(_cs_0) ); - TS_ASSERT( string_t(_cs_0) == string_t(cs2) ); - TS_ASSERT( !(string_t(_cs_0) == string_t(cs3)) ); - } - - //string and cstring - { - TS_ASSERT( string_t() == _empty_cs ); - TS_ASSERT( string_t(_cs_0) == string_t(_cs_0) ); - TS_ASSERT( string_t(_cs_0) == string_t(cs2) ); - TS_ASSERT( !( string_t(_cs_0) == string_t(cs3)) ); - } - - //cstring and string - { - TS_ASSERT( _empty_cs == string_t() ); - TS_ASSERT( string_t(_cs_0) == string_t(_cs_0) ); - TS_ASSERT( string_t(cs2) == string_t(_cs_0) ); - TS_ASSERT( !( string_t(cs3) == string_t(_cs_0)) ); - } - } - - void test_operator_not_eq(){ - _CharT cs2[] = {'b','s','l','_','s','t','r','i','n','g','\0'}; - _CharT cs3[] = {'n','o','t',' ','e','q','\0'}; - //string and string - { - TS_ASSERT( !(string_t() != string_t()) ); - TS_ASSERT( !(string_t(_cs_0) != string_t(_cs_0)) ); - TS_ASSERT( !(string_t(_cs_0) != string_t(cs2)) ); - TS_ASSERT( string_t(_cs_0) != string_t(cs3) ); - } - - //string and cstring - { - TS_ASSERT( !(string_t() != _empty_cs) ); - TS_ASSERT( !(string_t(_cs_0) != string_t(_cs_0)) ); - TS_ASSERT( !(string_t(_cs_0) != string_t(cs2)) ); - TS_ASSERT( string_t(_cs_0) != string_t(cs3) ); - } - - //cstring and string - { - TS_ASSERT( !(_empty_cs != string_t()) ); - TS_ASSERT( !(string_t(_cs_0) != string_t(_cs_0)) ); - TS_ASSERT( !(string_t(cs2) != string_t(_cs_0)) ); - TS_ASSERT( string_t(cs3) != string_t(_cs_0) ); - } - } - - void test_operator_lt(){ - //empty string - { - TS_ASSERT( !(string_t() < string_t()) ); - TS_ASSERT( string_t() < string_t(_cs_1) ); - TS_ASSERT( string_t() < string_t(_cs_2) ); - } - - //normal string - { - TS_ASSERT( string_t(_cs_2) < string_t(_cs_1) ); - TS_ASSERT( !(string_t(_cs_1) < string_t(_cs_2)) ); - - TS_ASSERT( string_t(_cs_3) < string_t(_cs_1) ); - TS_ASSERT( !(string_t(_cs_1) < string_t(_cs_3)) ); - - TS_ASSERT( !(string_t(_cs_4) < string_t(_cs_1)) ); - TS_ASSERT( !(string_t(_cs_1) < string_t(_cs_4)) ); - - TS_ASSERT( string_t(_cs_1) < string_t(_cs_5) ); - TS_ASSERT( !(string_t(_cs_5) < string_t(_cs_1)) ); - } - - } - - void test_operator_gt(){ - //empty string - { - string_t empty_str1, empty_str2; //modified because of a bug of g++2.96 - TS_ASSERT( !(empty_str1 > empty_str1) ); - TS_ASSERT( !(empty_str1 > empty_str2) ); - TS_ASSERT( !(empty_str1 > string_t(_cs_1)) ); - TS_ASSERT( !(empty_str1 > string_t(_cs_2)) ); - TS_ASSERT( !(empty_str2 > string_t(_cs_3)) ); - TS_ASSERT( !(empty_str2 > string_t(_cs_4)) ); - } - - //normal string - { - TS_ASSERT( !(string_t(_cs_2) > string_t(_cs_1)) ); - TS_ASSERT( string_t(_cs_1) > string_t(_cs_2)); - - TS_ASSERT( !(string_t(_cs_3) > string_t(_cs_1)) ); - TS_ASSERT( string_t(_cs_1) > string_t(_cs_3)); - - TS_ASSERT( !(string_t(_cs_4) > string_t(_cs_1)) ); - TS_ASSERT( !(string_t(_cs_1) > string_t(_cs_4)) ); - - TS_ASSERT( !(string_t(_cs_1) > string_t(_cs_5)) ); - TS_ASSERT( string_t(_cs_5) > string_t(_cs_1)); - } - - } - - void test_operator_lt_eq(){ - //empty string - { - TS_ASSERT( string_t() <= string_t() ); - TS_ASSERT( string_t() <= string_t(_cs_1) ); - TS_ASSERT( string_t() <= string_t(_cs_2) ); - } - - //normal string - { - TS_ASSERT( string_t(_cs_2) <= string_t(_cs_1) ); - TS_ASSERT( !(string_t(_cs_1) <= string_t(_cs_2)) ); - - TS_ASSERT( string_t(_cs_3) <= string_t(_cs_1) ); - TS_ASSERT( !(string_t(_cs_1) <= string_t(_cs_3)) ); - - TS_ASSERT( string_t(_cs_4) <= string_t(_cs_1) ); - TS_ASSERT( string_t(_cs_1) <= string_t(_cs_4) ); - - TS_ASSERT( string_t(_cs_1) <= string_t(_cs_5) ); - TS_ASSERT( !(string_t(_cs_5) <= string_t(_cs_1)) ); - } - - } - - void test_operator_gt_eq(){ - //empty string - { - TS_ASSERT( string_t() >= string_t() ); - TS_ASSERT( !(string_t() >= string_t(_cs_1)) ); - TS_ASSERT( !(string_t() >= string_t(_cs_2)) ); - } - - //normal string - { - TS_ASSERT( !(string_t(_cs_2) >= string_t(_cs_1)) ); - TS_ASSERT( string_t(_cs_1) >= string_t(_cs_2)); - - TS_ASSERT( !(string_t(_cs_3) >= string_t(_cs_1)) ); - TS_ASSERT( string_t(_cs_1) >= string_t(_cs_3)); - - TS_ASSERT( string_t(_cs_4) >= string_t(_cs_1) ); - TS_ASSERT( string_t(_cs_1) >= string_t(_cs_4) ); - - TS_ASSERT( !(string_t(_cs_1) >= string_t(_cs_5)) ); - TS_ASSERT( string_t(_cs_5) >= string_t(_cs_1)); - } - - } - - void test_operator_shift(){ -#if __GNUC__ >= 3 - //empty string - { - std::basic_stringstream<_CharT> ss; - ss<() ); - } - - //normal string - { - std::basic_stringstream<_CharT> ss; - ss< ss; - ss< ss; - ss< ss; - ss< ss; - ss< li(char_str, char_str + sizeof(char_str) -1); - std::string ss(char_str); - bsl::string bs(char_str); - string_t string_t_bs(li.begin(), li.end()); - - //"" + "" == "" - { - assert( string_t().append(_cs_0, _cs_0) == string_t() ); - std::string empty_s; - assert( string_t(_empty_cs).append(empty_s.begin(), empty_s.end()) == string_t() ); - assert( string_t().append(li.begin(), li.begin()) == string_t() ); - assert( string_t(_empty_cs).append(ss.end(), ss.end()) == string_t(_empty_cs) ); - - } - - // "..." + "" == "..." - { - assert( string_t(_cs_0).append(char_str, char_str) == string_t(_cs_0) ); - assert( string_t().append(li.begin(), li.end()) == string_t_bs ); - assert( string_t().append(ss.begin(), ss.end()) == string_t_bs ); - - } - - // "xxx" + "..." == "xxx..." - { - std::basic_string<_CharT> ss1(_cs_1); - string_t bs1(_cs_1); - assert( string_t(_cs_0).append(_cs_1, _cs_1 + 6) == string_t( _cs_0_add_1 ) ); - assert( string_t(_cs_0).append(ss1.begin(), ss1.end()) == string_t( _cs_0_add_1 ) ); - - } - - } - void test_push_back(){ - { - string_t s; - _CharT c('a'); - s.push_back(c); - assert( s == string_t(&c,1) ); - } - - { - string_t s(_cs_3); - s.push_back('n'); - assert( s == string_t(_cs_1) ); - } - - } - - void test_appendf(){ - { - //no look up - const char * fmt = "abc"; - string_t s; - s.reserve(10); - s.appendf( fmt ); - assert( s == string_t(fmt,fmt+3) ); - } - { - string_t s; - const char *fmt = "char:%c int:%d char_str:%s wchar_str:%ls\n" ; - _CharT * ans = malloc_clone( "char:c int:123 char_str:bsl::string! wchar_str:Acumon!\n" ); - s.appendf(fmt, 'c', 123, "bsl::string!", L"Acumon!" ); - assert( s == ans ); - free( ans ); - } - } - - void test_find(){ - assert( string_t(_cs_0).find( _cs_0 ) == 0 ); - assert( string_t(_cs_1).find( _cs_3 ) == 0 ); - assert( string_t(_cs_0).find( _cs_1 ) == string_t::npos ); - - const char* cs1 = "bslacumo"; - const char* cs2 = "acumon"; - string_t s1(cs1, cs1+strlen(cs1)); - string_t s2(cs2, cs2+strlen(cs2)); - assert( s1.find(s2) == string_t::npos ); - assert( s1.find(s2.c_str(), 0, s2.size() - 1) == 3 ); - assert( s1.find(s2.c_str(), 3, s2.size() - 1) == 3 ); - assert( s1.find(s2.c_str(), 4, s2.size() - 1) == string_t::npos ); - - assert( s1.find(s1[5]) == 5 ); - assert( s1.find(s1[5],5) == 5 ); - assert( s1.find(s1[5],6) == string_t::npos); - } - - void test_rfind(){ - assert( string_t(_cs_0).rfind( _cs_0 ) == 0 ); - assert( string_t(_cs_1).rfind( _cs_3 ) == 0 ); - assert( string_t(_cs_0).rfind( _cs_1 ) == string_t::npos ); - - const char* cs1 = "bslacumo"; - const char* cs2 = "acumon"; - string_t s1(cs1, cs1+strlen(cs1)); - string_t s2(cs2, cs2+strlen(cs2)); - assert( s1.rfind(s2) == string_t::npos ); - assert( s1.rfind(s2.c_str(), 0, s2.size() - 1) == string_t::npos ); - assert( s1.rfind(s2.c_str(), 3, s2.size() - 1) == 3 ); - assert( s1.rfind(s2.c_str(), 4, s2.size() - 1) == 3 ); - - assert( s1.rfind(s1[5]) == 5 ); - assert( s1.rfind(s1[5],5) == 5 ); - assert( s1.rfind(s1[5],6) == 5 ); - assert( s1.rfind(s1[5],4) == string_t::npos); - - const char* cs3 = "123b4567"; - const char* cs4 = "3b4"; - string_t str(cs3, cs3+strlen(cs3)); - string_t tmp(cs4, cs4+strlen(cs4)); - - assert( str.rfind(tmp) == 2 ); - assert( str.rfind(tmp, 3) == 2 ); - - } - -}; - -#endif //__BSL_TEST_STRING_HPP_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_string.py b/bsl/unittest/bsl_test_string.py deleted file mode 100755 index 2461bbab82fa966265dbab8136f8f0a39c722790..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_string.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python -TEST_CLASS_NAME = 'bsl_test_string' - -TEST_TYPES = [ 'normal' ] - -CHAR_TYPES = [ 'char', 'wchar_t', 'unsigned short', 'unsigned int' ] - -ALLOC_TYPES = [ 'bsl::bsl_alloc', 'std::allocator' ] - -TEST_METHODS= [ - 'test_ctors', - 'test_c_str', - 'test_empty', - 'test_size', - 'test_length', - 'test_capacity', - 'test_operator_square', - 'test_clear', - 'test_reserve', - 'test_swap', - 'test_operator_assign_to_null', - 'test_operator_assign_to_cstring', - 'test_operator_assign_to_string', - 'test_operator_eq_eq', - 'test_operator_not_eq', - 'test_operator_lt', - 'test_operator_gt', - 'test_operator_lt_eq', - 'test_operator_gt_eq', - 'test_operator_shift', - 'test_serialization', - 'test_append_str', - 'test_append_sub_str', - 'test_append_cstr', - 'test_append_sub_cstr', - 'test_append_n_char', - 'test_append_range', - 'test_push_back', - 'test_appendf', - 'test_find', - 'test_rfind' -] - -HEADER = """ -#ifndef __BSL_TEST_STRING_H_ -#define __BSL_TEST_STRING_H_ -#include -#include "bsl_test_string.hpp" -class bsl_test_string_main : public CxxTest::TestSuite{ -public: -""" - -FOOTER = """ -}; -#endif //__BSL_TEST_STRING_H_ -""" - -FUNCTION_TEMPLATE = """ - void test_%(test_type)s_%(escape_char_type)s_%(escape_alloc_type)s_%(escape_test_method)s(){ - return %(TEST_CLASS_NAME)s<%(char_type)s, %(alloc_type)s<%(char_type)s> >().%(escape_test_method)s(); - } -""" - -def escape(s): - return s.replace(' ','_').replace('::','_') - -if __name__ == '__main__': - print HEADER, - for test_type in TEST_TYPES: - for char_type in CHAR_TYPES: - escape_char_type = escape(char_type) - for alloc_type in ALLOC_TYPES: - escape_alloc_type = escape(alloc_type) - for test_method in TEST_METHODS: - escape_test_method = escape(test_method) - print FUNCTION_TEMPLATE % locals() - print FOOTER, - diff --git a/bsl/unittest/bsl_test_string32.h b/bsl/unittest/bsl_test_string32.h deleted file mode 100644 index acb0ea8afddb443c38802ec787601aae88631f4a..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_string32.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_string32.h,v 1.3 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_string32.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/19 18:29:35 - * @version $Revision: 1.3 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_STRING32_H_ -#define __BSL_TEST_STRING32_H_ - -#include -#include -#include -#include -#include -#include - -class bsl_test_string32 : public CxxTest::TestSuite -{ -public: - void test_string32 () { - bsl::string str = "adsf2"; - std::vector vec; - vec.push_back(str); - bsl::deque > deq; - deq.push_back(vec); - } -}; - - - - - - - - - - - - -#endif //__BSL_TEST_STRING32_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/bsl_test_utils.h b/bsl/unittest/bsl_test_utils.h deleted file mode 100644 index 769f3c5ee2eb6469284d9cbeb0086aff15d437bb..0000000000000000000000000000000000000000 --- a/bsl/unittest/bsl_test_utils.h +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_test_utils.h,v 1.3 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_test_utils.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/09 12:19:44 - * @version $Revision: 1.3 $ - * @brief - * - **/ - - -#ifndef __BSL_TEST_UTILS_H_ -#define __BSL_TEST_UTILS_H_ - -#include -#include -#include -#include - -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - -bool test_max () { - int a = 10, b = 5, c = 10; - int min = bsl::min(a, b); - int max = bsl::max(a, b); - if (min > max) { - max = min; - } - bsl::equal()(a, c); - bsl::more()(a, b); - bsl::less()(b, a); - - printf("\nhello world\n"); - //std::cout<::value<::value<::value); - __XASSERT2(bsl::high_bitpos<0x1234>::value == 13); - printf("-------0x%lx\n", bsl::moreq2<0x1234>::value); - __XASSERT2(bsl::moreq2<0x1234>::value == 0x2000UL); - printf("-------0x%lx\n", bsl::moreq2<0x5678>::value); - __XASSERT2(bsl::moreq2<0x5678>::value == 0x8000UL); - printf("-------%ld\n", bsl::moreq2<0x5678>::value); - __XASSERT2(bsl::moreq2<0x5678>::value == 32768UL); - - return true; -} - -class bsl_test_utils : public CxxTest::TestSuite -{ -public: - void test_max_() { - TSM_ASSERT("", test_max()); - } -}; - - - - - - - - - - - - - - - - - -#endif //__BSL_TEST_UTILS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/unittest/define.rc b/bsl/unittest/define.rc deleted file mode 100644 index bf19c8d421e81e7dbe24188d84f5afe1e811de07..0000000000000000000000000000000000000000 --- a/bsl/unittest/define.rc +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: define.rc,v 1.1 2008/11/14 03:39:13 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file define.h - * @author xiaowei(com@baidu.com) - * @date 2008/10/28 11:42:03 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __DEFINE_H_ -#define __DEFINE_H_ - -#include -class MyClass { - public: - char name[800]; - char value[800]; - bool operator == (const MyClass & __x) const { - return ((strcmp(name, __x.name) == 0)&& - (strcmp(value, __x.value) == 0)); - } - const MyClass & operator = (const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - memcpy(u, __x.u, 256); - return *this; - } - char *u; - MyClass() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyClass() { - free(u); - } - MyClass(const MyClass &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - -class MyStruct { - public: - char name[800]; - char value[800]; - char *u; - MyStruct() { - u = (char*)malloc(256); - memset(u, 0, 128); - } - ~MyStruct() { - free(u); - } - MyStruct(const MyStruct &__x) { - memcpy(name, __x.name, sizeof(name)); - memcpy(value, __x.value, sizeof(value)); - u = (char*)malloc(256); - memcpy(u, __x.u, 256); - } -}; - - - - - - - - - - - - - - - - - -#endif //__DEFINE_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/unittest/header.hpp b/bsl/unittest/header.hpp deleted file mode 100644 index 49b9cc5bf63c58df5e40496f5c69297997e9d0ec..0000000000000000000000000000000000000000 --- a/bsl/unittest/header.hpp +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef _HEADER_HPP -#define _HEADER_HPP - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//////utils -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - - -static std::vector g_pid; -static bool g_pthread_flag = true; -#define __XASSERT_R(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - g_pthread_flag = false; \ - for (int i=0; i<(int)g_pid.size(); ++i) { \ - if (g_pid[i] != pthread_self()) { \ - int ret = pthread_cancel(g_pid[i]); \ - fprintf(stdout, "\n[error]kill pthread_t[%ld][%d]ret[%d][%m]\n", (long)g_pid[i], i, ret); \ - } \ - } \ - return NULL; \ - }\ -} - -#define __XASSERT2_R(flag) __XASSERT_R(flag, "") - -class auto_timer -{ - char buf[64]; - timeval s, e; - public: - auto_timer(const char *str = NULL) { - buf[0] = 0; - if (str) snprintf(buf, sizeof(buf), "%s", str); - gettimeofday(&s, NULL); - } - auto_timer(const char *str, int val) { - snprintf(buf, sizeof(buf), "%s %d ", str, val); - gettimeofday(&s, NULL); - } - ~auto_timer() { - gettimeofday(&e, NULL); - long t = (long)((e.tv_sec - s.tv_sec) * 1000000 + (e.tv_usec - s.tv_usec)); - if (t/1000 > 0) { - __BSL_DEBUG("%s %ld", buf, t); - } - } -}; - -class dis_timer -{ - timeval s, e; -public: - void start() { - gettimeofday(&s, NULL); - } - void end() { - gettimeofday(&e, NULL); - } - int costms () { - return (int)((e.tv_sec-s.tv_sec)*1000 + (e.tv_usec-s.tv_usec)/1000); - } -}; - - - -std::string randstr(int wan=32) -{ - char buf[130] = {0}; - int len = rand()%wan + 1; - for (int i=0; i -bool test_phashmap_temp(int pnum, void *(*pfun)(void *), int upnum, void *(*upfun)(void *), - int lnum = 0, void *(*lfun)(void *) = 0) -{ - HASH * test = new (std::nothrow) HASH; - g_pthread_flag = true; - __XASSERT2(test != NULL); - __XASSERT2(test->create(1<<20) == 0); - g_pid.clear(); - pthread_t pid; - - { - //auto_timer t("phashmap costime"); - - for (int i=0; i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//////utils -#define __XASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - return false; \ - }\ -} - -#define __XASSERT2(flag) __XASSERT(flag, "") - - -static std::vector g_pid; -static bool g_pthread_flag = true; -#define __XASSERT_R(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ - g_pthread_flag = false; \ - for (int i=0; i<(int)g_pid.size(); ++i) { \ - if (g_pid[i] != pthread_self()) { \ - int ret = pthread_cancel(g_pid[i]); \ - fprintf(stdout, "\n[error]kill pthread_t[%ld][%d]ret[%d][%m]\n", (long)g_pid[i], i, ret); \ - } \ - } \ - return NULL; \ - }\ -} - -#define __XASSERT2_R(flag) __XASSERT_R(flag, "") - -class auto_timer -{ - char buf[64]; - timeval s, e; - public: - auto_timer(const char *str = NULL) { - buf[0] = 0; - if (str) snprintf(buf, sizeof(buf), "%s", str); - gettimeofday(&s, NULL); - } - auto_timer(const char *str, int val) { - snprintf(buf, sizeof(buf), "%s %d ", str, val); - gettimeofday(&s, NULL); - } - ~auto_timer() { - gettimeofday(&e, NULL); - long t = (long)((e.tv_sec - s.tv_sec) * 1000000 + (e.tv_usec - s.tv_usec)); - if (t/1000 > 0) { - __BSL_DEBUG("%s %ld", buf, t); - } - } -}; - -class dis_timer -{ - timeval s, e; -public: - void start() { - gettimeofday(&s, NULL); - } - void end() { - gettimeofday(&e, NULL); - } - int costms () { - return (int)((e.tv_sec-s.tv_sec)*1000 + (e.tv_usec-s.tv_usec)/1000); - } -}; - - - -bsl::string randstr(int wan=32) -{ - char buf[130] = {0}; - int len = rand()%wan + 1; - for (int i=0; i -bool test_phashmap_temp(int pnum, void *(*pfun)(void *), int upnum, void *(*upfun)(void *), - int lnum = 0, void *(*lfun)(void *) = 0) -{ - HASH * test = new (std::nothrow) HASH; - g_pthread_flag = true; - __XASSERT2(test != NULL); - __XASSERT2(test->create(1<<20) == 0); - g_pid.clear(); - pthread_t pid; - - { - //auto_timer t("phashmap costime"); - - for (int i=0; i -#include -#include -#include - -namespace test -{ - using namespace bsl; -/** -* @brief An allocator that uses malloc. -* -* This is precisely the allocator defined in the C++ Standard. -* - all allocation calls malloc -* - all deallocation calls free -*/ - -template < typename _Tp > -class bsl_alloc -{ -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp *pointer; - typedef const _Tp *const_pointer; - typedef _Tp & reference; - typedef const _Tp & const_reference; - typedef _Tp value_type; - typedef bsl_alloc<_Tp> pool_type; - - template < typename _Tp1 > - struct rebind { - typedef bsl_alloc < _Tp1 > other; - }; - - static const bool recycle_space = false; //在alloc析构的时候,是否释放空间 - static const bool thread_safe = true; //空间分配器是否线程安全 - - bsl_alloc() {} - - bsl_alloc(const bsl_alloc &) {} - - template < typename _Tp1 > - bsl_alloc(const bsl_alloc < _Tp1 > &) {} - - ~bsl_alloc() {} - - pointer address(reference __x) const { - return &__x; - } - - const_pointer address(const_reference __x) const { - return &__x; - } - - //NB:__n is permitted to be 0. The C++ standard says nothing - // about what the return value is when __n == 0. - pointer allocate(size_type __n, const void * = 0) { - if(rand() % 5 == 0) return NULL; - pointer __ret = static_cast < _Tp * >(malloc(__n * sizeof(_Tp))); - return __ret; - } - - pointer reallocate(size_type __n, void * ptr = 0) { - if (ptr == NULL) { - return allocate(__n, ptr); - } - return static_cast < _Tp * >(realloc(ptr, __n * sizeof(_Tp))); - } - - //__p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type) { - free(static_cast < void *>(__p)); - } - - size_type max_size() const { - return size_t(-1) / sizeof(_Tp); - } - - //_GLIBCXX_RESOLVE_LIB_DEFECTS - //402. wrong new expression in[some_] allocator: : construct - void construct(pointer __p, const _Tp & __val) { - ::new(__p) value_type(__val); - } - - void destroy(pointer __p) { - __p->~ _Tp(); - } - - int create() {return 0;} - int destroy() {return 0;} - - void swap (bsl_alloc<_Tp> &_) { - } - - int merge(bsl_alloc<_Tp> &_){ - return 0; - } -}; - -template < typename _Tp > -inline bool operator == (const bsl_alloc < _Tp > &, const bsl_alloc < _Tp > &) { - return true; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator == (const bsl_alloc <_Tp > &, const _Alloc2 &) { - return false; -} - -template < typename _Tp > -inline bool operator != (const bsl_alloc < _Tp > &, const bsl_alloc < _Tp > &) { - return false; -} - -template < typename _Tp, class _Alloc2 > -inline bool operator != (const bsl_alloc <_Tp > &, const _Alloc2 &) { - return true; -} - -} - -#endif // xalloc_h__ diff --git a/bsl/unittest/war.sh b/bsl/unittest/war.sh deleted file mode 100644 index 654d79261326cc29be77c401237d902c04eac5a9..0000000000000000000000000000000000000000 --- a/bsl/unittest/war.sh +++ /dev/null @@ -1,3 +0,0 @@ -make -j 16 > res 2>&1 -cat res | grep "warning" | grep "^bsl_test" -v | sort | uniq > 1 -cat 1 diff --git a/bsl/utils/BCLOUD b/bsl/utils/BCLOUD deleted file mode 100644 index 75ba46f73d93d5fdf8ce213f4abb4248c36f1418..0000000000000000000000000000000000000000 --- a/bsl/utils/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -#CPPFLAGS(r'-D_GNU_SOURCE -D__STDC_LIMIT_MACROS') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS('-W -Wall -fsigned-char -fPIC -O2 -ftemplate-depth-128') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libutils.a') -#LIBS('$OUT/so/libutils.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl/utils') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('utils', Sources(user_sources)) - -#UT -#UTApplication('utils', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_utils', Sources(user_sources)) -#StaticLibrary('utils', PreBuilt(True)) - -#.so -#SharedLibrary('utils', Sources(user_sources)) -#SharedLibrary('utils', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/utils/CMakeLists.txt b/bsl/utils/CMakeLists.txt deleted file mode 100644 index 4ca89aa48e9c3043877abeeff92160e0df4499b3..0000000000000000000000000000000000000000 --- a/bsl/utils/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_library(utils ${CMAKE_CURRENT_LIST_DIR}/bsl_memcpy.cpp) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/utils/Makefile b/bsl/utils/Makefile deleted file mode 100644 index 91c200f1e1d978c6306904648affc5c5a6f99b56..0000000000000000000000000000000000000000 --- a/bsl/utils/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -CC=g++ -BSL=../ -INCLUDES=-ftemplate-depth-128 -CFLAGS = -fsigned-char -fPIC -O2 -LDFLAGS= -OBJS=bsl_memcpy.o -TARGET= -LIB=libbsl_utils.a - -OUTINC=$(BSL)/output/include/bsl/utils -OUTLIB=$(BSL)/output/lib - -all : $(TARGET) $(LIB) output - -%.o : %.cpp - $(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES) - -$(TARGET) : $(OBJS) - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(INCLUDES) - -$(LIB) : $(OBJS) - rm -f $@ - ar cr $@ $(OBJS) - -output : $(LIB) - rm -rf $(OUTINC) - mkdir -p $(OUTINC) - mkdir -p $(OUTLIB) - cp *.h $(OUTINC) - cp $(LIB) $(OUTLIB) - -tags : - ctags -R * - -clean: - rm -f $(OBJS) $(TARGET) $(LIB) - rm -f -r $(OUTINC); - rm -f $(OUTLIB)/$(LIB) - - diff --git a/bsl/utils/bsl_construct.h b/bsl/utils/bsl_construct.h deleted file mode 100644 index 4e7ebf7371db9c0fcc568aa8e46f0e4cc1e01993..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_construct.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef _BSL_CONSTRUCT_H -#define _BSL_CONSTRUCT_H - -#include -#include - -#if __GNUC__ >= 4 -#include -#endif - -namespace bsl -{ - /** - * @if maint - * Constructs an object in existing memory by invoking an allocated - * object's constructor with an initializer. - * @endif - */ - template - inline void - bsl_construct(_T1* __p, const _T2& __value) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 402. wrong new expression in [some_]allocator::construct - ::new(static_cast(__p)) _T1(__value); - } - - /** - * @if maint - * Constructs an object in existing memory by invoking an allocated - * object's default constructor (no initializers). - * @endif - */ - template - inline void - bsl_construct(_T1* __p) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 402. wrong new expression in [some_]allocator::construct - ::new(static_cast(__p)) _T1(); - } - - /** - * @if maint - * Destroy the object pointed to by a pointer type. - * @endif - */ - template - inline void - bsl_destruct(_Tp* __pointer) - { __pointer->~_Tp(); } - - /** - * @if maint - * Destroy a range of objects with nontrivial destructors. - * - * This is a helper function used only by destruct(). - * @endif - */ - template - inline void - __bsl_destroy_aux(_ForwardIterator __first, _ForwardIterator __last, - __false_type) - { for ( ; __first != __last; ++__first) bsl::bsl_destruct(&*__first); } - - /** - * @if maint - * Destroy a range of objects with trivial destructors. Since the destructors - * are trivial, there's nothing to do and hopefully this function will be - * entirely optimized away. - * - * This is a helper function used only by destruct(). - * @endif - */ - template - inline void - __bsl_destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) - { } - - /** - * @if maint - * Destroy a range of objects. If the value_type of the object has - * a trivial destructor, the compiler should optimize all of this - * away, otherwise the objects' destructors must be invoked. - * @endif - */ - template - inline void - bsl_destruct(_ForwardIterator __first, _ForwardIterator __last) - { - typedef typename std::iterator_traits<_ForwardIterator>::value_type _Value_type; - typedef typename __type_traits < _Value_type >::has_trivial_destructor - _Has_trivial_destructor; - bsl::__bsl_destroy_aux(__first, __last, _Has_trivial_destructor()); - } -} // namespace bsl - -#endif /* _BSL_CONSTRUCT_H */ - diff --git a/bsl/utils/bsl_debug.h b/bsl/utils/bsl_debug.h deleted file mode 100644 index 4e67b000a6c60249501d0d8c91e42f25ff2df7f5..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_debug.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_debug.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_debug.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/25 20:49:30 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __BSL_DEBUG_H_ -#define __BSL_DEBUG_H_ - -#include -#include -#include - -namespace bsl -{ - -#ifdef BSL_DEBUG_MOD - -#define __BSL_DEBUG(fmt, arg...) \ -{ \ - fprintf(stdout, "[----------debug--------][%s:%d]" fmt "\n", __FILE__, __LINE__, ##arg); \ -} -#define __BSL_ASSERT(flag, fmt, arg...) \ -{\ - bool ___bsl_flag = flag; \ - if (!(___bsl_flag)) { \ - fprintf(stdout, "[error][%s:%d][%s]" fmt "\n", __FILE__, __LINE__, #flag, ##arg); \ - }\ - assert (___bsl_flag); \ -} - - -class auto_xtimer -{ - char buf[64]; - timeval s, e; - public: - auto_xtimer(const char *str = NULL) { - buf[0] = 0; - if (str) snprintf(buf, sizeof(buf), "%s", str); - gettimeofday(&s, NULL); - } - ~auto_xtimer() { - gettimeofday(&e, NULL); - long t = (long)((e.tv_sec - s.tv_sec) * 1000000 + (e.tv_usec - s.tv_usec)); - __BSL_DEBUG("%s %ld", buf, t); - } -}; - -#define AUTO_TIMER(str) bsl::auto_xtimer t(str) -#else -#define __BSL_DEBUG(fmt, arg...) -#define __BSL_ASSERT(...) -#define AUTO_TIMER(str) -#endif - -#define __BSL_ERROR(fmt, arg...) \ -{ \ - fprintf(stdout, "[error][%s:%d]" fmt "\n", __FILE__, __LINE__, ##arg); \ -} - - - -}; - - - - - - - - - - - - - - - - -#endif //__BSL_DEBUG_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/utils/bsl_memcpy.cpp b/bsl/utils/bsl_memcpy.cpp deleted file mode 100644 index 1facfa32957d22d9d0523f60aafbd93694edb98b..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_memcpy.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_memcpy.cpp,v 1.3 2009/10/14 08:24:59 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file xmemcpy.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/11/07 17:20:48 - * @version $Revision: 1.3 $ - * @brief - * - **/ - -#include "bsl_memcpy.h" - -namespace bsl -{ - -class xmembase -{ -public: - virtual void * copy (void *dest, const void *src) = 0; - virtual ~xmembase(){} -}; - -static const size_t XMEM_MAXSIZE = 120; - -template -struct xmemcpy_t -{ - int data[size]; -}; - -template <> -struct xmemcpy_t<0> -{ -}; - -template -class xmemcopy : public xmembase -{ -public: - void * copy (void *dest, const void *src) - { - typedef xmemcpy_t type_t; - //if (size/sizeof(int) > 0) { - *((type_t *)dest) = *((type_t *)src); - //} - //编译的时候是常数,if不存在判断性能损失 - if ((size%sizeof(int)) > 0) { - ((char *)dest)[size-1] = ((char *)src)[size-1]; - } - if ((size%sizeof(int)) > 1) { - ((char *)dest)[size-2] = ((char *)src)[size-2]; - } - if ((size%sizeof(int)) > 2) { - ((char *)dest)[size-3] = ((char *)src)[size-3]; - } - return dest; - } -}; - -template <> -class xmemcopy<0> : public xmembase -{ -public: - void * copy (void *dest, const void *src) { - return dest; - (void)src; - } -}; - - -static xmembase *g_base[XMEM_MAXSIZE] = {NULL}; - -template -void init() { - if (g_base[len] == NULL) { - g_base[len] = new xmemcopy; - } - init(); -} - -template <> -void init<0> () { - if (g_base[0] == NULL) { - g_base[0] = new xmemcopy<0>; - } -} - - -class xmem_monitor -{ -public: - xmem_monitor() { - init(); - } - ~xmem_monitor() { - for (size_t i = 0; i < XMEM_MAXSIZE; ++i) { - if (g_base[i]) { - delete g_base[i]; - g_base[i] = NULL; - } - } - } -}; - -static xmem_monitor g_monitor; - - - -void *xmemcpy (void *dest, const void *src, size_t len) -{ - //防止重叠 - long dst = ((long)dest - (long)src); - if ( (dst < (long)len && dst > 0 - (long)len) || - len >= XMEM_MAXSIZE) { - return ::memcpy(dest, src, len); - } - - if (g_base[len] == NULL) { - return ::memcpy(dest, src, len); - } - - return g_base[len]->copy(dest, src); -} - -} - - - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/utils/bsl_memcpy.h b/bsl/utils/bsl_memcpy.h deleted file mode 100644 index 97b69b1333ed836b2eb3f750509ba725584cde05..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_memcpy.h +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_memcpy.h,v 1.6 2009/10/14 08:24:59 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file xmemcpy.h - * @author xiaowei(com@baidu.com) - * @date 2008/11/07 17:17:22 - * @version $Revision: 1.6 $ - * @brief - * - **/ - - -#ifndef __XMEMCPY_H_ -#define __XMEMCPY_H_ - - -#include -namespace bsl -{ -void *xmemcpy (void *dest, const void *src, size_t len); -}; - - - -#endif //__XMEMCPY_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/utils/bsl_type_traits.h b/bsl/utils/bsl_type_traits.h deleted file mode 100644 index 83d915870826bb35df8a5b7c8d52b348aee85d6c..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_type_traits.h +++ /dev/null @@ -1,413 +0,0 @@ -// Type traits implementation -*- C++ -*- - -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, 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 General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/* - * - * Copyright (c) 1997 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - */ - -/** @file type_traits.h - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ - -#ifndef _BSL_TYPE_TRAITS_H -#define _BSL_TYPE_TRAITS_H - -//#pragma GCC system_header - -//#include - -/* -This header file provides a framework for allowing compile time dispatch -based on type attributes. This is useful when writing template code. -For example, when making a copy of an array of an unknown type, it helps -to know if the type has a trivial copy constructor or not, to help decide -if a memcpy can be used. - -The class template __type_traits provides a series of typedefs each of -which is either __true_type or __false_type. The argument to -__type_traits can be any type. The typedefs within this template will -attain their correct values by one of these means: - 1. The general instantiation contain conservative values which work - for all types. - 2. Specializations may be declared to make distinctions between types. - 3. Some compilers (such as the Silicon Graphics N32 and N64 compilers) - will automatically provide the appropriate specializations for all - types. - -EXAMPLE: - -//Copy an array of elements which have non-trivial copy constructors -template void - copy(_Tp* __source,_Tp* __destination,int __n,__false_type); -//Copy an array of elements which have trivial copy constructors. Use memcpy. -template void - copy(_Tp* __source,_Tp* __destination,int __n,__true_type); - -//Copy an array of any type by using the most efficient copy mechanism -template inline void copy(_Tp* __source,_Tp* __destination,int __n) { - copy(__source,__destination,__n, - typename __type_traits<_Tp>::has_trivial_copy_constructor()); -} -*/ - -/** - * @brief 来自gcc3.4.5,bits/type_traits.h - */ -namespace bsl { - -struct __true_type {}; -struct __false_type {}; - -template - struct __type_traits - { - typedef __true_type this_dummy_member_must_be_first; - /* Do not remove this member. It informs a compiler which - automatically specializes __type_traits that this - __type_traits template is special. It just makes sure that - things work if an implementation is using a template - called __type_traits for something unrelated. */ - - /* The following restrictions should be observed for the sake of - compilers which automatically produce type specific specializations - of this class: - - You may reorder the members below if you wish - - You may remove any of the members below if you wish - - You must not rename members without making the corresponding - name change in the compiler - - Members you add will be treated like regular members unless - you add the appropriate support in the compiler. */ - - - typedef __false_type has_trivial_default_constructor; - typedef __false_type has_trivial_copy_constructor; - typedef __false_type has_trivial_assignment_operator; - typedef __false_type has_trivial_destructor; - typedef __false_type is_POD_type; - }; - - -// Provide some specializations. - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template<> - struct __type_traits - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -template - struct __type_traits<_Tp*> - { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; - -// The following could be written in terms of numeric_limits. -// We're doing it separately to reduce the number of dependencies. - -template - struct _Is_integer - { - typedef __false_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template<> - struct _Is_integer - { - typedef __true_type _Integral; - }; - -template - struct _Is_normal_iterator - { - typedef __false_type _Normal; - }; - -// Forward declaration hack, should really include this from somewhere. -namespace __gnu_cxx -{ - template - class __normal_iterator; -} - -template - struct _Is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator, - _Container> > - { - typedef __true_type _Normal; - }; -} - -#endif /* _BSL_TYPE_TRAITS_H */ - -// Local Variables: -// mode:C++ -// End: - -/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */ diff --git a/bsl/utils/bsl_utils.h b/bsl/utils/bsl_utils.h deleted file mode 100644 index 6ff9768ccc150b735cc7642394290b06118ecfbe..0000000000000000000000000000000000000000 --- a/bsl/utils/bsl_utils.h +++ /dev/null @@ -1,179 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: bsl_utils.h,v 1.6 2008/12/15 09:57:00 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file bsl_utils.h - * @author xiaowei(com@baidu.com) - * @date 2008/07/12 14:35:13 - * @version $Revision: 1.6 $ - * @brief - * - **/ - - -#ifndef __BSL_UTILS_H_ -#define __BSL_UTILS_H_ - -#include -#include -#include -#include -#include -#include - -namespace bsl -{ - -//有些模版参数需要预处理 -#define __MAC_BSL_MIN(_1, _2) (((_1)<(_2)) ? (_1) : (_2)) -template -inline const _Tp & min (const _Tp &_1, const _Tp &_2) -{ - return __MAC_BSL_MIN(_1, _2); -} -#define __MAC_BSL_MAX(_1, _2) (((_1)<(_2)) ? (_2) : (_1)) -template -inline const _Tp & max (const _Tp &_1, const _Tp &_2) -{ - return __MAC_BSL_MAX(_1, _2); -} - -template -struct equal -{ - inline bool operator () (const _Tp &_1, const _Tp &_2) const { - return _1 == _2; - } -}; - -template -struct more -{ - inline bool operator () (const _Tp &_1, const _Tp &_2) const { - return _1 > _2; - } -}; - -template -struct less -{ - inline bool operator () (const _Tp &_1, const _Tp &_2) const { - return _1 < _2; - } -}; - -#if 0 -template -struct pair -{ - typedef _T first_type; - typedef _T second_type; - - _T first; - _Q second; -public: - pair(const pair & p) : first(p.first), second(p.second) {} - pair(const _T &t, const _Q &q) : first(t), second(q) {} - pair() {} - - template - int serialization(_Archive &ar) { - if (bsl::serialization(ar, first)) return -1; - if (bsl::serialization(ar, second)) return -1; - return 0; - } - - template - int deserialization(_Archive &ar) { - if (bsl::deserialization(ar, first)) return -1; - if (bsl::deserialization(ar, second)) return -1; - return 0; - } -}; -#endif - -template -struct pair_first -{ - typedef typename _Pair::first_type type; - const type & operator () (const _Pair & __p) const { - return __p.first; - } -}; - -template -struct pair_second -{ - typedef typename _Pair::second_type type; - const type & operator () (const _Pair & __p) const { - return __p.second; - } -}; - -template -struct param_select -{ - const _Tp & operator () (const _Tp & __p) const { - return __p; - } -}; - -template -struct select2st -{ - typedef _1 type; -}; -template -struct select2st -{ - typedef _2 type; -}; - -//锁保护 -class mutexlock_monitor -{ - pthread_mutex_t *_lock; -public: - mutexlock_monitor(pthread_mutex_t *lock) : _lock(lock) { - pthread_mutex_lock(_lock); - } - ~mutexlock_monitor() { - pthread_mutex_unlock(_lock); - } -}; - -//获取一个无符号常整形的最高位所在位置 -template -struct high_bitpos -{ - static const int value = ((val < (1UL<::value) : (bits+1)); -}; - -template -struct high_bitpos -{ - static const int value = 0; -}; - -template -struct moreq2 -{ - static const unsigned long value = ((val > (1UL<::value) : (1UL< -struct moreq2 -{ - static const unsigned long value = 0; -}; - -}//namespace bsl -#endif //__BSL_UTILS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/Makefile b/bsl/var/Makefile deleted file mode 100644 index c5b9b3f6d2094dc81765ae2e30778874c4709939..0000000000000000000000000000000000000000 --- a/bsl/var/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -LIB = bsl_var -SUBLIB_DIRS = interface utils implement -SUBLIBS = bsl_var_utils bsl_var_implement - - -VAR_ROOT= . -include Makefile.env - -all: lib clean - -lib: sublibs - @echo "[make] building lib $(LIB) ..."; - @for SUBLIB in $(SUBLIBS); do\ - ar xo $(OUTPUT_LIB_PATH)/lib$$SUBLIB.a; \ - done - @mkdir -p $(OUTPUT_LIB_PATH) - @ar cr $(OUTPUT_LIB_PATH)/lib$(LIB).a *.o - -sublibs: - @for SUBLIB in $(SUBLIB_DIRS); do\ - echo "[make] building lib $$SUBLIB ...";\ - make -C $$SUBLIB;\ - done - -clean: - @echo "[make] cleaning ..." - @rm -f *.o - @for SUBLIB in $(SUBLIB_DIRS); do\ - echo "[make] cleaning lib $$SUBLIB ...";\ - make clean -C $$SUBLIB;\ - done diff --git a/bsl/var/Makefile.env b/bsl/var/Makefile.env deleted file mode 100644 index 6025705f61fbe3b4ce22d385ab028fc7eaa00dc1..0000000000000000000000000000000000000000 --- a/bsl/var/Makefile.env +++ /dev/null @@ -1,59 +0,0 @@ -# Public Makefile settings for VAR -# It requires VAR_ROOT to be set before include this file - -# About the project ######################### -BSL_PROJECT_NAME= bsl -BSL_VERSION = "$(BSL_PROJECT_NAME) 1.1.0.0" -BSL_CVSTAG = "$(BSL_PROJECT_NAME)_1-1-0-0_PD_BL" - -# Machine ################################### -ifeq ($(MAC),64) -ARCH = 64 -ARCH_SUFFIX = -64 -else -ARCH = 32 -ARCH_SUFFIX = -endif - -# Paths ##################################### -BSL_ROOT = $(VAR_ROOT)/.. -WORK_ROOT = $(VAR_ROOT)/../../.. -OUTPUT_ENTRANCE_PATH= $(BSL_ROOT)/output/include/bsl -OUTPUT_HEAD_PATH = $(BSL_ROOT)/output/include/bsl/var -OUTPUT_LIB_PATH = $(BSL_ROOT)/output/lib -OUTPUT_BIN_PATH = $(BSL_ROOT)/output/bin - -# Compile Tools ############################# -CXX = g++ -CC = g++ -SHELL = /bin/bash - -# Public flags - -DEBUG_CXXFLAG = -DVAR_DEBUG_FLAG -PROJECT_CXXFLAGS = \ - -DBSL_VERSION="\$(BSL_VERSION)\" \ - -DBSL_CVSTAG="\$(BSL_CVSTAG)\" \ - -DBSL_PROJECT_NAME="\"$(BSL_PROJECT_NAME)\"" - -DEPEND_CXXFLAGS = -I$(BSL_ROOT)/output/include \ - -DEPEND_LDFLAGS = -L$(BSL_ROOT)/output/lib -lbsl - -ifeq ($(MAC),ARM32) -GCC_VER = $(shell gcc --version | head -n1 | cut -d' ' -f4) -else -GCC_VER = $(shell gcc --version | head -n1 | cut -d' ' -f3) -endif - -SUPPORT_OX = $(shell if [[ $(GCC_VER) > '4.2.9' ]]; then echo "--std=c++0x"; fi;) - -CXXFLAGS = \ - -g -rdynamic -pipe -fPIC -finline-functions \ - -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \ - -Wconversion -Winline -Woverloaded-virtual -Wsign-promo \ - $(SUPPORT_OX) \ - $(DEBUG_CXXFLAG) $(PROJECT_CXXFLAGS) $(DEPEND_CXXFLAGS) - -LDFLAGS = -rdynamic $(DEPEND_LDFLAGS) - diff --git a/bsl/var/Makefile.rules b/bsl/var/Makefile.rules deleted file mode 100644 index 2fe827204071f74e227961f01425e5fcd62c3b33..0000000000000000000000000000000000000000 --- a/bsl/var/Makefile.rules +++ /dev/null @@ -1,98 +0,0 @@ -#comment the following line for debugging -.SILENT: all test output clean tag doc debug build_lib output output_entrances output_heads output_objects output_lib output_bins - -.PHONY: all test output clean tag doc debug build_lib output output_entrances output_heads output_objects output_lib output_bins - -#comment the following line to use default known suffixes (DANGEROUS!!!) -.SUFFIXES: - -all: output clean - -%.o: %.cpp $(DEPEND_HEADS) - @echo "[make] building $@ ..." - $(CC) -o $@ -c $< $(CXXFLAGS) - -%: %.o $(DEPEND_LIBS) $(PROVIDE_OBJECTS) - @echo "[make] building $@ ..." - $(CC) -o $@ $^ $(LDFLAGS) - -build_lib: $(PROVIDE_OBJECTS) - if [ "$(strip $(PROVIDE_LIB))" ]; then \ - echo "[make] builiding lib$(strip $(PROVIDE_LIB)).a ..."; \ - ar cr lib$(strip $(PROVIDE_LIB)).a $(PROVIDE_OBJECTS); \ - fi - -output: output_entrances output_heads output_lib output_bins - -output_entrances: $(PROVIDE_ENTRANCES) - if [[ "$(strip $(PROVIDE_ENTRANCES))" && "$(strip $(OUTPUT_ENTRANCE_PATH))" ]]; then \ - echo "[make] copying $(PROVIDE_ENTRANCES) to $(OUTPUT_ENTRANCE_PATH) ..."; \ - mkdir -p $(OUTPUT_ENTRANCE_PATH); \ - cp -u $^ $(OUTPUT_ENTRANCE_PATH); \ - fi - -output_heads: $(strip $(filter-out $(PROVIDE_ENTRANCES), $(PROVIDE_HEADS))) - if [[ "$^" && "$(strip $(OUTPUT_HEAD_PATH))" ]]; then \ - echo "[make] copying $^ to $(OUTPUT_HEAD_PATH) ..."; \ - mkdir -p $(OUTPUT_HEAD_PATH); \ - cp -u $^ $(OUTPUT_HEAD_PATH); \ - fi - -output_objects: $(PROVIDE_OBJECTS) - if [[ "$(strip $(PROVIDE_OBJECTS))" && "$(strip $(OUTPUT_OBJECT_PATH))" ]]; then \ - echo "[make] copying $^ to $(OUTPUT_OBJECT_PATH) ..."; \ - mkdir -p $(OUTPUT_OBJECT_PATH); \ - cp -u $^ $(OUTPUT_OBJECT_PATH); \ - fi - -output_lib: build_lib - if [[ "$(strip $(PROVIDE_LIB))" && "$(strip $(OUTPUT_LIB_PATH))" ]]; then \ - echo "[make] copying lib$(strip $(PROVIDE_LIB)).a to $(OUTPUT_LIB_PATH) ..."; \ - mkdir -p $(OUTPUT_LIB_PATH); \ - cp -u lib$(strip $(PROVIDE_LIB)).a $(OUTPUT_LIB_PATH); \ - fi - -output_bins: $(PROVIDE_BINS) - if [[ "$(strip $(PROVIDE_BINS))" && "$(strip $(OUTPUT_BIN_PATH))" ]]; then \ - echo "[make] copying $^ to $(OUTPUT_BIN_PATH) ..."; \ - mkdir -p $(OUTPUT_BIN_PATH); \ - cp $^ $(OUTPUT_BIN_PATH); \ - fi - -clean: - @echo "[make] cleaning ..." - rm *.o *.a $(PROVIDE_BINS) $(GENERATED_FILES) $(TEST_TARGETS) -f - -doc: - @echo "[make] generating documents ..." - doxygen - -tag: - @echo "[make] generating tags ..." - ctags --c++-kinds=+p --fields=+iaS --extra=+q -R $(TAG_ROOT); - -debug: - @echo "[make] printing variables ..." - @echo 'basic configuration' - @echo '' - @echo 'path configuration' - @echo '$$(WORK_ROOT) = $(WORK_ROOT)' - @echo '$$(VAR_ROOT) = $(VAR_ROOT)' - @echo '$$(OUTPUT_HEAD_PATH) = $(OUTPUT_HEAD_PATH)' - @echo '$$(OUTPUT_OBJECT_PATH) = $(OUTPUT_OBJECT_PATH)' - @echo '$$(OUTPUT_LIB_PATH) = $(OUTPUT_LIB_PATH)' - @echo '$$(OUTPUT_BIN_PATH) = $(OUTPUT_LIB_PATH)' - @echo '' - @echo 'build & test configuration' - @echo '$$(PROVIDE_HEADS) = $(PROVIDE_HEADS)' - @echo '$$(PROVIDE_OBJECTS) = $(PROVIDE_OBJECTS)' - @echo '$$(PROVIDE_LIB) = $(PROVIDE_LIB)' - @echo '$$(PROVIDE_BINS) = $(PROVIDE_BINS)' - @echo '$$(DEPEND_HEADS) = $(DEPEND_HEADS)' - @echo '$$(DEPEND_OBJECTS) = $(DEPEND_OBJECTS)' - @echo '$$(DEPEND_LIB) = $(DEPEND_LIB)' - @echo '$$(CXXFLAGS) = $(CXXFLAGS)' - @echo '$$(LDFLAGS) = $(LDFLAGS)' - @echo '' - @echo 'other' - @echo '$$(TAG_ROOT) = $(TAG_ROOT)' diff --git a/bsl/var/implement/Array.h b/bsl/var/implement/Array.h deleted file mode 100644 index 8aa77bc3a16672a2e73029f85c60666ef98fcc9d..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Array.h +++ /dev/null @@ -1,1082 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Array.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Array.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:36:18 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_ARRAY_H__ -#define __BSL_VAR_ARRAY_H__ - -#include -#include "bsl/pool/bsl_pool.h" -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/var/Null.h" -#include "bsl/var/utils.h" - -namespace bsl{ -namespace var{ - //typedefs - //templateclass allocator_t> - template - class BasicArray; - - /** - * @brief 封装了std::deque >的数组类型 - * - **/ - typedef BasicArray > > Array; - - /** - * @brief var::Array数组类型,与var::Dict保持类似的接口 - * implement_t为BasicArray的内部实现 - * - * - */ - template - class BasicArray: public IVar{ - public: - /** - * @brief Var::Array的string类型 - * - */ - typedef IVar::string_type string_type; - /** - * @brief Var::Array的字段类型 - */ - typedef IVar::field_type field_type; - /** - * @brief Var::Array的allocator - */ - typedef typename implement_t::allocator_type allocator_type; - /** - * @brief Var::Array的迭代器 - */ - typedef ArrayIterator array_iterator; - /** - * @brief Var::Array的const迭代器 - */ - typedef ArrayConstIterator array_const_iterator; - /** - * @brief Var::Array的reference_type - */ - typedef Ref reference_type; - - /** - * @brief var::Array内部的数组实现别名 - * - **/ - typedef implement_t array_type; - - public: - BasicArray() - :_array() { } - - /** - * @brief BasicArray的构造函数 - * - * @param [in] allocator : allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/10 11:27:05 - **/ - explicit BasicArray( const allocator_type& _alloc ) :_array(_alloc){} - - /** - * @brief BasicArray的复制构造函数 - * - * @param [in] other : const BasicArray& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/10 11:27:58 - **/ - BasicArray( const BasicArray& other ) :IVar(other), _array(other._array){} - - /** - * @brief BasicArray的复制赋值运算符 - * - * @param [in] other : const BasicArray& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/10 11:28:47 - **/ - BasicArray& operator = ( const BasicArray& other ){ - try{ - _array = other._array; - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<(var)); - }else if ( var.is_array() ){ - size_t var_size = var.size(); - try{ - _array.resize( var_size ); - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<= _array.size() ){ - return bsl::var::Null::null; - } - return _array[idx]; - } - - /** - * @brief 获取下标idx处的IVar对象的引用对象 - * 如果下标越界,返回一个默认值 - * - * @param [in] idx : size_t - * @param [in] default_value : IVar& - * @return IVar& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/10 11:39:57 - **/ - virtual IVar& get( size_t idx, IVar& default_value ) { - if ( idx >= _array.size() ){ - return default_value; - } - return _array[idx]; - } - - /** - * @brief 获取下标idx处的IVar对象的引用对象 - * 如果下标越界,返回var::Null - * - * @param [in] idx : size_t - * @param [in] default_value : IVar& - * @return IVar& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/11 15:54:07 - **/ - virtual const IVar& get( size_t idx ) const { - if ( idx >= _array.size() ){ - return bsl::var::Null::null; - } - return _array[idx]; - } - - /** - * @brief 获取下标idx处的IVar对象的引用对象 - * 如果下标越界,返回一个默认值,const版本 - * - * @param [in] idx : size_t - * @param [in] default_value : const IVar& - * @return const IVar& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 15:54:57 - **/ - virtual const IVar& get( size_t idx, const IVar& default_value ) const { - if ( idx >= _array.size() ){ - return default_value; - } - return _array[idx]; - } - - /** - * @brief 设置下标idx上的绑定 - * - * @param [in] idx : size_t - * @param [in] value : IVar& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 15:56:03 - **/ - virtual void set( size_t idx, IVar& value ){ - if ( idx >= _array.size() ){ - try{ - _array.resize(idx + 1); - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<= _array.size() || _array[idx].is_null() ){ - return false; - }else{ - _array[idx] = Null::null; - return true; - } - } - - /** - * @brief 返回只读起始数组迭代器 - * is_array()返回true的IVar实现类都必须支持该方法 - * - * @param - * @return array_const_iterator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 15:59:58 - **/ - virtual array_const_iterator array_begin() const { - return array_const_iterator( - _s_create_const_iterator( &_array, 0 ), - _s_clone_const_iterator, - _s_destroy_const_iterator - ); - } - - /** - * @brief 返回起始数组迭代器 - * - * @param - * @return array_iterator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:01:21 - **/ - virtual array_iterator array_begin() { - return array_iterator( - _s_create_iterator( &_array, 0 ), - _s_clone_iterator, - _s_destroy_iterator - ); - } - - /** - * @brief 返回只读末尾数组迭代器 - * - * @param - * @return array_const_iterator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:01:53 - **/ - virtual array_const_iterator array_end() const { - return array_const_iterator( - _s_create_const_iterator( &_array, _array.size() ), - _s_clone_const_iterator, - _s_destroy_const_iterator - ); - } - - /** - * @brief 返回数组末尾迭代器 - * - * @param - * @return array_iterator - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:02:29 - **/ - virtual array_iterator array_end() { - return array_iterator( - _s_create_iterator( &_array, _array.size() ), - _s_clone_iterator, - _s_destroy_iterator - ); - } - - /** - * @brief 返回/设置下标绑定 - * - * @param [in] idx : int - * @return const IVar& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:03:09 - **/ - virtual const IVar& operator []( int idx ) const { - return this->get( idx >= 0 ? size_t(idx) : size_t(_array.size() + idx) ); - } - - /** - * @brief 返回/设置下标绑定 - * - * @param [in] idx : int - * @return IVar& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:05:00 - **/ - virtual IVar& operator []( int idx ){ - if ( idx >= int(_array.size()) ){ - try{ - _array.resize( idx + 1 ); //自动扩展数组大小 - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<get( idx >= 0 ? size_t(idx) : size_t(_array.size() + idx) ); - } - - //methods for dict -#if __GNUC__ > 2 - using IVar::operator []; - using IVar::get; - using IVar::set; - using IVar::del; -#else - //avoid using bug of g++ 2.96 - - /** - * @brief 返回字段名绑定 - * 所有is_dict()返回true的IVar实现类都必须支持该方法 - * - * @param - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:06:54 - **/ - virtual IVar& get( const field_type& name ) { - throw bsl::InvalidOperationException()<(&other); - if ( !p ){ - throw bsl::BadCastException() - <_p_array; - _offset = p->_offset; - } - - /** - * @brief 判断是否等于其它数组类型迭代器 - * - * @param [in] other : const IArrayIteratorImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:18:51 - **/ - virtual bool equal_to( const IArrayIteratorImpl& other ) const; - /** - * @brief 判断是否等于其它只读数组类型迭代器 - * - * @param [in] other : const IArrayConstIteratorImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:19:54 - **/ - virtual bool equal_to( const IArrayConstIteratorImpl& other ) const; - - private: - /** - * @brief 数组指针 - * - **/ - array_type *_p_array; - /** - * @brief 数组指针的偏移位置 - * - **/ - size_t _offset; - }; - - /** - * @brief 只读数组类型代器实现 - * - **/ - class ArrayConstIteratorImpl: public IArrayConstIteratorImpl{ - friend class ArrayIteratorImpl; - public: - /** - * @brief 只读数组类型迭代器的构造函数 - * - * @param [in] p_array : const array_type* - * @param [in] offset : size_t - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:32:33 - **/ - ArrayConstIteratorImpl( const array_type* p_array, size_t offset ) - :_p_array(p_array), _offset(offset){} - - virtual ~ArrayConstIteratorImpl() { - //pass - } - - /** - * @brief 得到偏移位置 - * - **/ - virtual size_t key() const { - return _offset; - } - - /** - * @brief 得到偏移位置上的绑定值 - * - * - **/ - virtual const IVar& value() const { - return (*_p_array)[_offset]; - } - /** - * @brief 偏移位置后移 - * - **/ - virtual void iterate(){ - ++ _offset; - } - /** - * @brief 将其它数组类型迭代器对其赋值 - * - * @param [in] other : const IArrayIteratorImpl& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:23:51 - **/ - virtual void assign( const IArrayIteratorImpl& other ) { - const ArrayIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException() - <_p_array; - _offset = p->_offset; - } - /** - * @brief 将其它只读数组类型迭代器对其赋值 - * - * @param [in] other : const IArrayConstIteratorImpl& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:24:55 - **/ - virtual void assign( const IArrayConstIteratorImpl& other ) { - const ArrayConstIteratorImpl *p = - dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException() - <_p_array; - _offset = p->_offset; - } - - /** - * @brief 判断是否等于其它只读数组类型迭代器 - * - * @param [in] other : const IArrayConstIteratorImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:26:22 - **/ - virtual bool equal_to( const IArrayConstIteratorImpl& other ) const; - - /** - * @brief 判断是否等于其它数组类型迭代器 - * - * @param [in] other : const IArrayIteratorImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 17:27:09 - **/ - virtual bool equal_to( const IArrayIteratorImpl& other ) const; - - private: - /** - * @brief 数组指针 - * - **/ - const array_type * _p_array; - /** - * @brief 数组指针的偏移位置 - * - **/ - size_t _offset; - }; - - /** - * @brief 创建一个数组的迭代器 - * - * @param [in] p_array : array_type* - * @param [in] offset : size_t - * @return IArrayIteratorImpl * - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:14:45 - **/ - static IArrayIteratorImpl * _s_create_iterator( array_type* p_array, size_t offset){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - IArrayIteratorImpl *p = impl_alloc_t().allocate(1); //throw - new(p) ArrayIteratorImpl(p_array, offset ); //nothrow - return p; - } - - /** - * @brief 创建一个只读数组的迭代器 - * @param [in] p_array : const array_type* - * @param [in] offset : size_t - * @return IArrayConstIteratorImpl * - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:16:18 - **/ - static IArrayConstIteratorImpl * _s_create_const_iterator( - const array_type* p_array, - size_t offset - ){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - IArrayConstIteratorImpl *p = impl_alloc_t().allocate(1); //throw - new(p) ArrayConstIteratorImpl(p_array, offset ); //nothrow - return p; - } - - /** - * @brief 克隆数组的迭代器 - * - * @param [in] p_other : const IArrayIteratorImpl* - * @return IArrayIteratorImpl* - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:17:48 - **/ - static IArrayIteratorImpl * _s_clone_iterator( const IArrayIteratorImpl *p_other ){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - const ArrayIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException() - <::other impl_alloc_t; - const ArrayConstIteratorImpl *psrc = - dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException() - <::other impl_alloc_t; - ArrayIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~ArrayIteratorImpl(); - impl_alloc_t().deallocate( _p, 1 ); - } - } - - /** - * @brief 销毁只读数组的迭代器 - * @param [in] p : IArrayIteratorImpl - * @return void - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:20:38 - **/ - static void _s_destroy_const_iterator( IArrayConstIteratorImpl * p){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - ArrayConstIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~ArrayConstIteratorImpl(); - impl_alloc_t().deallocate( _p, 1 ); - } - } - - /** - * @brief 内部封装的数组 - * - **/ - array_type _array; - }; - - /** - * @brief 判断数组两个迭代器是否相同 - * - * @param [in] other : const IArrayIteratroImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:26:48 - **/ - template - inline bool BasicArray:: - ArrayIteratorImpl::equal_to( const IArrayIteratorImpl& other ) const { - const ArrayIteratorImpl *p = - dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - /** - * @brief 判断数组的迭代器与只读数组的迭代器是否相同 - * - * @param [in] other : const IArrayConstIteratroImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:27:47 - **/ - template - inline bool BasicArray:: - ArrayIteratorImpl::equal_to( const IArrayConstIteratorImpl& other ) const { - const ArrayConstIteratorImpl *p = - dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - /** - * @brief 判断只读数组的迭代器与数组的迭代器是否相同 - * - * @param [in] other : const IArrayIteratroImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:28:37 - **/ - template - inline bool BasicArray:: - ArrayConstIteratorImpl::equal_to( const IArrayIteratorImpl& other ) const { - const ArrayIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - /** - * @brief 判断两个只读数组的迭代器是否相同 - * - * @param [in] other : const IArrayConstIteratroImpl& - * @return bool - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 16:29:20 - **/ - template - inline bool BasicArray:: - ArrayConstIteratorImpl:: - equal_to( const IArrayConstIteratorImpl& other ) const { - const ArrayConstIteratorImpl *p = - dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - -}} //namespace bsl::var - -#endif //__BSL_VAR_ARRAY_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/BCLOUD b/bsl/var/implement/BCLOUD deleted file mode 100644 index eacc890409558f30e56627fa6ac12fe042cdc01b..0000000000000000000000000000000000000000 --- a/bsl/var/implement/BCLOUD +++ /dev/null @@ -1,68 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DVAR_DEBUG_FLAG -DBSL_VERSION=\"bsl1.1.0.0\" -DBSL_CVSTAG=\"bsl_1-1-0-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libimplement.a') -#LIBS('$OUT/so/libimplement.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl/var') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('implement', Sources(user_sources)) - -#UT -#UTApplication('implement', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_var_implement', Sources(user_sources)) -#StaticLibrary('implement', PreBuilt(True)) - -#.so -#SharedLibrary('implement', Sources(user_sources)) -#SharedLibrary('implement', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/var/implement/BigInt.h b/bsl/var/implement/BigInt.h deleted file mode 100644 index 23436cc7ee8c7174a2ad3b7a2e61d167afdec986..0000000000000000000000000000000000000000 --- a/bsl/var/implement/BigInt.h +++ /dev/null @@ -1,832 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2013 Baidu.com, Inc. All Rights Reserved - * $Id: BigInt.h,v 1.1.24 2013/07/19 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file BigInt.h - * @brief BigInt in var - * @author linjieqiong - * @version 1.1.24 - * @date 2013-07-14 - */ -#ifndef __BSL_VAR_BIGINT_H__ -#define __BSL_VAR_BIGINT_H__ - -#include -#include -#include -#include -#include -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" - -namespace bsl{ -namespace var{ - -namespace { - -#define HEX_CHARSET "1234567890abcdefABCDEF" - -enum hex_machine_state{ - MSTART, - MPREFIX, - MDIGIT, - MEND, - MERROR, -}; - -enum base_type{ - BHEX, - BDECIMAL, - BBINARY, - BUNREC, -}; - -} - -templateclass BigInt; -typedef BigInt<1024, true> BigIntk; - -template -class BigInt : public IVar{ -public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef unsigned char byte; - typedef BigInt Self; - typedef std::deque implement_t; - typedef implement_t::const_iterator const_imitr; - template - struct rebind {typedef BigInt Other;}; - -public: - BigInt(){ - clear(); - } - BigInt(bool __value){ - clear(); - operator=(__value); - } - BigInt(int __value){ - clear(); - operator=(__value); - } - BigInt(long long __value){ - clear(); - operator=(__value); - } - BigInt(const char * __value){ - clear(); - operator=(__value); - } - BigInt(string_type __value){ - clear(); - operator=(__value); - } - BigInt(const BigInt & other) - : IVar(other) - , _value(other._value){ - } - - /** - * @brief copy constructor - * - * @param other - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/27 21:51:26 - */ - BigInt & operator=(const BigInt & other){ - _value = other._value; - return *this; - } - - /** - * @brief 杞崲鍏朵粬BigInt绫诲瀷锛屾湰鍑芥暟涓篶heck_cast - * - * @tparam bits2 - * @tparam sign2 - * @param other - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/27 21:50:49 - */ - template - BigInt(const BigInt & other) - : IVar(other){ - operator=(other.to_string()); - if(sign == true && sign2 == false && (_value[0] & 0x80)){ - _value.push_front(0); - } - else if(sign == false && sign2 == true && (_value[0] & 0x80)){ - throw bsl::UnderflowException()<", bits, sign?"signed":"unsigned"); - return type; - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:32:01 - */ - virtual IVar::mask_type get_mask() const { - if(sign == true){ - return IVar::IS_NUMBER | IVar::IS_BIG_INT | IVar::IS_SIGNED; - } - return IVar::IS_NUMBER | IVar::IS_BIG_INT; - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:34:36 - */ - virtual bool to_bool() const { - size_t sz = _value.size(); - if(sz == 0){ - return false; - } - size_t idx = 0; - if(sign == true){ - if((_value[0] & 0x7f) != 0){ - return true; - } - idx ++; - } - for(; idx(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:35:53 - */ - virtual unsigned char to_uint8() const { - return check_cast_unsigned(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:36:01 - */ - virtual signed short to_int16() const { - return check_cast_signed(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:36:01 - */ - virtual unsigned short to_uint16() const { - return check_cast_unsigned(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:36:57 - */ - virtual signed int to_int32() const { - return check_cast_signed(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:37:08 - */ - virtual unsigned int to_uint32() const { - return check_cast_unsigned(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:37:21 - */ - virtual signed long long to_int64() const { - return check_cast_signed(); - } - - /** - * @brief - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 16:37:41 - */ - virtual unsigned long long to_uint64() const { - return check_cast_unsigned(); - } - - ///** - // * @brief - // * - // * @return - // * - // * @version 1.1.24 - // * @author linjieqiong - // * @date 2013/07/19 16:37:50 - // */ - //virtual float to_float() const { - // return static_cast(_value); - //} - - ///** - // * @brief - // * - // * @return - // * - // * @version 1.1.24 - // * @author linjieqiong - // * @date 2013/07/19 16:38:04 - // */ - //virtual double to_double() const { - // return check_cast(_value); - //} - - virtual BigInt& operator = ( bool b ){ - clear(); - (b == true) ? _value.push_back(1) : _value.push_back(0); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:01:08 - */ - virtual BigInt& operator = ( signed char i ){ - assign_signed(i); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:01:26 - */ - virtual BigInt& operator = ( unsigned char i ){ - assign_unsigned(i); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:01:37 - */ - virtual BigInt& operator = ( signed short i ){ - assign_signed(i); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:01:48 - */ - virtual BigInt& operator = ( unsigned short i ){ - assign_unsigned(i); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:02:00 - */ - virtual BigInt& operator = ( signed int i ){ - assign_signed(i); - return *this; - } - - /** - * @brief - * - * @param i - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:02:09 - */ - virtual BigInt& operator = ( unsigned int i ){ - assign_unsigned(i); - return *this; - } - - virtual BigInt& operator = ( long long ll ){ - assign_signed(ll); - return *this; - } - - /** - * @brief - * - * @param d - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:02:23 - */ - virtual BigInt& operator = ( unsigned long long d ){ - assign_unsigned(d); - return *this; - } - - ///** - // * @brief - // * - // * @param f - // * - // * @return - // * - // * @version 1.1.24 - // * @author linjieqiong - // * @date 2013/07/19 17:02:33 - // */ - //virtual BigInt& operator = ( float f ){ - // _value = check_cast(f); - // return *this; - //} - - ///** - // * @brief - // * - // * @param d - // * - // * @return - // * - // * @version 1.1.24 - // * @author linjieqiong - // * @date 2013/07/19 17:02:47 - // */ - //virtual BigInt& operator = ( double d ){ - // _value = check_cast(d); - // return *this; - //} - - /** - * @brief 灏嗘暟瀛楀瓧绗︿覆杞垚BigInt - * @note 鐩墠鍙湁鍗佸叚杩涘埗褰㈠紡鐨勫瓧绗︿覆鑳借璇嗗埆 - * e.g.: "0x01234fad", "0XFFFFF12" - * - * @param cstr - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/19 17:03:14 - */ - virtual BigInt& operator = ( const char * cstr ){ - if(cstr == NULL){ - throw bsl::NullPointerException()< bits; - } - -protected: - template - T check_cast_signed()const{ - const size_t byte_limit = sizeof(T); - const size_t value_size = _value.size(); - if(value_size == 0){ - throw bsl::BadCastException()<(_value[0] & 0x80); - if( value_size > byte_limit || - (value_size == byte_limit && sign == false && nsign == true)){ - throw bsl::OverflowException()< - T check_cast_unsigned()const{ - const size_t byte_limit = sizeof(T); - const size_t value_size = _value.size(); - if(value_size == 0){ - throw bsl::BadCastException()<(_value[0] & 0x80); - if(sign == true && nsign == true){ - throw bsl::UnderflowException()< byte_limit){ - throw bsl::OverflowException()< - void assign_signed(T num){ - clear(); - size_t byte_size = sizeof(num); - for(size_t i=0; i>= 8; - } - bool nsign = static_cast(num & 0x80); - if(sign == false && nsign == true){ - clear(); - throw bsl::UnderflowException()< - void assign_unsigned(T num){ - clear(); - size_t byte_size = sizeof(num); - for(size_t i=0; i>= 8; - } - _value.push_front(num & 0xff); - bool highest_bit = static_cast(num & 0x80); - if(highest_bit == true && sign == true){ - _value.push_front(0); - } - } - - /** - * @brief get the base of a digit string, - * only hex string will be recognized currently - * - * @param str the input string - * @param base the base of the digit string - * - * @return if recognized, the prefix of the @str will be trimed - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/24 10:38:05 - */ - const char * GetBase(const char *str, int &base){ - const char * dpos = str; - int state = MSTART; - while(*dpos != 0){ - switch(state){ - case MSTART: - state = MPREFIX; - break; - case MPREFIX: - if(*dpos == '0'){ - if(tolower(*(dpos+1)) == 'x'){ - dpos += 2; - state = MEND; - } - else{ - state = MERROR; - } - } - else{ - state = MERROR; - } - break; - case MEND: - base = BHEX; - return dpos; - case MERROR: - default: - base = BUNREC; - return NULL; - } - } - base = BUNREC; - return NULL; - } - - /** - * @brief convert a hex string to values and push into container - * - * @param digits - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/24 10:37:05 - */ - void check_hex_convert(const char * digits){ - int idx = strlen(digits) - 1; - while(idx >= 0){ - int hhalf=0, lhalf=0; - lhalf = check_hex_value(digits, idx); - -- idx; - if(idx >= 0){ - hhalf = check_hex_value(digits, idx); - -- idx; - } - _value.push_front(hhalf<<4 | lhalf); - } - } - - /** - * @brief - * - * @param digits a hex string, eg: 0abc13df - * @param idx the index of a hex char in @digits - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/24 10:35:10 - */ - int check_hex_value(const char * digits, const int idx){ - char digit = digits[idx]; - char *pos = strchr(HEX_CHARSET, digit); - if(pos != NULL){ - return (pos < HEX_CHARSET + 10) ? - digit - '0' : tolower(digit) - 'a' + 10; - } - else{ - throw bsl::BadFormatStringException() - < - Bool& operator = ( BigInt val){ - _value = val.to_bool(); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Bool& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Bool& operator = ( float f ){ - _value = f; - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Bool& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Bool& operator = ( double val ){ - _value = val; - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Bool& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Bool& operator = ( const char * val ){ - _value = (NULL != val && '\0' != val[0]); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Bool& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Bool& operator = ( const string_type& val ){ - _value = (val.c_str()[0] != '\0') ; - return *this; - } - - /** - * @brief 转化为布尔类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual bool to_bool() const { - return _value; - } - - /** - * @brief 转化为8位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed char to_int8() const { - return static_cast(_value); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return static_cast(_value); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return static_cast(_value); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return static_cast(_value); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return static_cast(_value); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return static_cast(_value); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return static_cast(_value); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return static_cast(_value); - } - - /** - * @brief conversion to bigint, not a virtual function derived - * - * @tparam bits - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 15:51:13 - */ - template - BigInt to_bigint() { - BigInt tmp = _value; - return tmp; - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return static_cast(_value); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return static_cast(_value); - } - - //using default version for raw - using IVar::operator =; - private: - bool _value; - }; - -}} //namespace bsl::var -#endif //__BSL_VAR_BOOL_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/CMakeLists.txt b/bsl/var/implement/CMakeLists.txt deleted file mode 100644 index 266fefce9f483844ecfabce46e9b2f3b52e4e56b..0000000000000000000000000000000000000000 --- a/bsl/var/implement/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -FILE(GLOB implement_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(implement ${implement_srcs}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/var/implement/Dict.h b/bsl/var/implement/Dict.h deleted file mode 100644 index 55dbe21c2ec3892ca0742fba57a8a4b202b8ef40..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Dict.h +++ /dev/null @@ -1,1078 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Dict.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Dict.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:36:18 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_DICT_H__ -#define __BSL_VAR_DICT_H__ - -#include -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 -#include -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 -#include -#elif __GNUC__ >= 3 -#include -#else -#include -#endif -#include "bsl/pool/bsl_pool.h" -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/var/Null.h" -#include "bsl/var/utils.h" - -#if __GNUC__ < 3 -namespace __gnu_cxx{ - /** - * @brief 使g++2.96也统一为__gnu_cxx命名空间 - * - * - */ - using std::hash_map; - using std::hash; -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - using std::tr1; -#endif -} -#endif - -namespace bsl{ -namespace var{ - //forward declarations & typedefs - template - class BasicDict; - - templateclass Alloc> - class __StdMapAdapter; - - templateclass Alloc> - class __GnuHashMapAdapter; - - /** - * @brief 封装了std::map,并使用bsl::pool_allocator的字典 - * - */ - typedef BasicDict<__StdMapAdapter > StdMapDict; - - /** - * @brief 封装了__gnu_cxx::hash_map,并使用bsl::pool_allocator的字典 - * - * - */ - typedef BasicDict<__GnuHashMapAdapter >GnuHashDict; - - /** - * @brief 最推荐使用的字典 - * - * 目前最推荐使用的是封装了std::map,并使用bsl::pool_allocator的StdMapDict - */ - typedef StdMapDict Dict; - - - /** - * @brief 字典类型 - * - **/ - - template - class BasicDict: public IVar{ - public: - /** - * @brief 字符串类型 - */ - typedef IVar::string_type string_type; - /** - * @brief 字段类型 - */ - typedef IVar::field_type field_type; - /** - * @brief allocator类型 - */ - typedef typename implement_t::allocator_type allocator_type; - /** - * @brief 字典迭代器 - */ - typedef DictIterator dict_iterator; - /** - * @brief 只读字典迭代器 - */ - typedef DictConstIterator dict_const_iterator; - /** - * @brief 类型的引用 - */ - typedef Ref reference_type; - - public: - BasicDict() - :_dict(), _alloc() {} - - /** - * @brief 构造函数 - * - * @param [in] init_capacity : size_t - * @param [in] alloc_ : allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 19:50:51 - **/ - BasicDict( - size_t init_capacity, - const allocator_type& alloc_ = allocator_type() - ) - :_dict(init_capacity, alloc_), _alloc(alloc_) {} - - /** - * @brief 构造函数 - * - * @param [in] alloc_ : const allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 19:52:00 - **/ - explicit BasicDict( const allocator_type& alloc_ ) - :_dict(alloc_), _alloc(alloc_) {} - - /** - * @brief 复制构造函数 - * - * @param [in] other : const BasicDict& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 19:52:33 - **/ - BasicDict( const BasicDict& other ) - :IVar(other), _dict(other._dict), _alloc(other._alloc) {} - - /** - * @brief 复制赋值运算符 - * - * @param [in] other : const BasicDict& - * @return BasicDict& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 19:53:29 - **/ - BasicDict& operator = ( const BasicDict& other ){ - try{ - _dict = other._dict; - _alloc = other._alloc; - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<key(), (iter->value()).clone(rp, is_deep_copy)); - } - } - return res; - } - - /** - * @brief 递归打印自身及下级结点信息 - * - * @param [in] verbose_level : size_t - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2009/05/14 17:34:58 - **/ - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t verbose_level = 0) const { - string_type res; - if ( verbose_level == 0 ){ - res.appendf("[bsl::var::BasicDict] this[%p] size[%zd]", this, _dict.size() ); - }else{ - dump_to_string(*this, res, verbose_level, "", 0 ); - } - return res; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return dump(0); - } - - /** - * @brief 将IVar类型转化为Dict类型 - * - * @param [in] var : IVar& - * @return BasicDict& - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/12 19:54:43 - **/ - virtual BasicDict& operator = ( IVar& var ) { - if ( typeid(var) == typeid(*this) ){ - _dict = dynamic_cast(var)._dict; - }else if ( var.is_dict() ){ - _dict.clear(); - IVar::dict_iterator iter_ = var.dict_begin(); - IVar::dict_iterator end = var.dict_end(); - for( ; iter_ != end ; ++iter_ ){ - _dict[iter_->key()] = iter_->value(); - } - }else{ - throw bsl::InvalidOperationException()<second; - } - /** - * @brief 返回字段名绑定,若字段名不存在,返回默认值 - * - **/ - virtual IVar& get( const field_type& name, IVar& default_value ) { - iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return default_value; - } - return iter_->second; - } - /** - * @brief 返回字段名绑定 - * - **/ - virtual const IVar& get( const field_type& name ) const { - const_iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return bsl::var::Null::null; - } - return iter_->second; - } - - /** - * @brief 返回字段名绑定,若字段名不存在,返回默认值 - * - **/ - virtual const IVar& get( const field_type& name, const IVar& default_value ) const { - const_iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return default_value; - } - return iter_->second; - } - /** - * @brief 设置字段名绑定 - * - **/ - virtual void set( const field_type& name, IVar& value ){ - _dict[name] = value; - } - - /** - * @brief 删除字段名绑定 - * - **/ - virtual bool del( const field_type& name ) { - iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return false; - } - _dict.erase( iter_ ); - return true; - } - - /** - * @brief 返回只读起始字典迭代器 - * - **/ - virtual dict_const_iterator dict_begin() const { - return dict_const_iterator( - _s_create_const_iterator( _dict.begin(), &_alloc ), - _s_clone_const_iterator, - _s_destroy_const_iterator, - &_alloc - ); - } - /** - * @brief 返回起始字典迭代器 - * - **/ - virtual dict_iterator dict_begin() { - return dict_iterator( - _s_create_iterator( _dict.begin(), &_alloc ), - _s_clone_iterator, - _s_destroy_iterator, - &_alloc - ); - } - /** - * @brief 返回只读末尾字典迭代器 - * - **/ - virtual dict_const_iterator dict_end() const { - return dict_const_iterator( - _s_create_const_iterator( _dict.end(), &_alloc ), - _s_clone_const_iterator, - _s_destroy_const_iterator, - &_alloc - ); - } - /** - * @brief 返回末尾字典迭代器 - * - **/ - virtual dict_iterator dict_end() { - return dict_iterator( - _s_create_iterator( _dict.end(), &_alloc ), - _s_clone_iterator, - _s_destroy_iterator, - &_alloc - ); - } - /** - * @brief 返回/设置下标绑定 - * - */ - virtual const IVar& operator []( const field_type& name ) const { - const_iter_impl_t iter_ = _dict.find(name); - if ( iter_ == _dict.end() ){ - throw bsl::KeyNotFoundException()<second; - } - - /** - * @brief 返回/设置下标绑定 - * - **/ - virtual IVar& operator []( const field_type& name ){ - return _dict[name]; - } - - //methods for array -#if __GNUC__ > 2 - using IVar::operator []; - using IVar::get; - using IVar::set; - using IVar::del; -#else - //avoid using bug of g++ 2.96 - - /** - * @brief 获取下标idx处的IVar对象的引用对象,数组接口 - * - */ - virtual IVar& get( size_t idx ) { - throw bsl::InvalidOperationException()<first; - } - /** - * @brief 得到偏移位置上的绑定值 - */ - virtual IVar& value() const { - return _iter->second; - } - /** - * @brief 偏移位置后移 - */ - virtual void iterate(){ - ++ _iter; - } - /** - * @brief 将其它字典类型迭代器对其赋值 - */ - virtual void assign( const IDictIteratorImpl& other ) { - const DictIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException() - <_iter; - } - /** - * @brief 判断是否等于其它只读字典类型迭代器 - */ - virtual bool equal_to( const IDictIteratorImpl& other ) const; - /** - * @brief 判断是否等于其它字典类型迭代器 - */ - virtual bool equal_to( const IDictConstIteratorImpl& other ) const; - - private: - /** - * @brief 字典迭代器 - */ - iter_impl_t _iter; - }; - /** - * @brief 只读字典迭代器的实现 - */ - class DictConstIteratorImpl: public IDictConstIteratorImpl{ - friend class DictIteratorImpl; - public: - - /** - * @brief 复制构造函数 - */ - DictConstIteratorImpl( const const_iter_impl_t& iter_ ) - :_iter(iter_){} - - virtual ~DictConstIteratorImpl() { - //pass - } - /** - * @brief 得到偏移位置 - */ - virtual const string_type& key() const { - return _iter->first; - } - /** - * @brief 得到偏移位置上的绑定值 - */ - virtual const IVar& value() const { - return _iter->second; - } - /** - * @brief 偏移位置后移 - */ - virtual void iterate(){ - ++ _iter; - } - /** - * @brief 将其它字典类型迭代器对其赋值 - */ - virtual void assign( const IDictIteratorImpl& other ) { - const DictIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException() - <_iter; - } - /** - * @brief 将其它只读字典类型迭代器对其赋值 - */ - virtual void assign( const IDictConstIteratorImpl& other ) { - const DictConstIteratorImpl *p = - dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException() - <_iter; - } - /** - * @brief 判断是否等于其它只读字典类型迭代器 - */ - virtual bool equal_to( const IDictConstIteratorImpl& other ) const; - /** - * @brief 判断是否等于其它字典类型迭代器 - */ - virtual bool equal_to( const IDictIteratorImpl& other ) const; - - private: - /** - * @brief 只读字典迭代器 - */ - const_iter_impl_t _iter; - }; - - /** - * @brief 创建一个字典的迭代器 - */ - static IDictIteratorImpl * _s_create_iterator( - const iter_impl_t& iter_, - const void *p_alloc - ){ - typedef - typename allocator_type::template rebind::other impl_alloc_t; - IDictIteratorImpl *p = impl_alloc_t(*static_cast(p_alloc)).allocate(1); //throw - new(p) DictIteratorImpl( iter_ ); //nothrow - return p; - } - /** - * @brief 创建一个只读字典的迭代器 - */ - static IDictConstIteratorImpl * _s_create_const_iterator( - const const_iter_impl_t& iter_, - const void *p_alloc - ){ - typedef - typename allocator_type:: - template rebind::other impl_alloc_t; - IDictConstIteratorImpl *p = impl_alloc_t(*static_cast(p_alloc)).allocate(1); //throw - new(p) DictConstIteratorImpl( iter_ ); //nothrow - return p; - } - /** - * @brief 克隆字典的迭代器 - */ - static IDictIteratorImpl * _s_clone_iterator( - const IDictIteratorImpl *p_other, - const void *p_alloc - ){ - typedef - typename allocator_type::template rebind::other impl_alloc_t; - const DictIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException() - <(p_alloc)).allocate(1); //throw - new(p) DictIteratorImpl(*psrc); - return p; - } - /** - * @brief 克隆只读字典的迭代器 - */ - static IDictConstIteratorImpl * _s_clone_const_iterator( - const IDictConstIteratorImpl *p_other, - const void *p_alloc - ){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - const DictConstIteratorImpl *psrc = - dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException() - <(p_alloc)).allocate(1); //throw - new(p) DictConstIteratorImpl(*psrc); - return p; - } - /** - * @brief 销毁字典的迭代器 - */ - static void _s_destroy_iterator( IDictIteratorImpl * p, const void *p_alloc){ - typedef - typename allocator_type::template rebind::other impl_alloc_t; - DictIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~DictIteratorImpl(); - impl_alloc_t(*static_cast(p_alloc)).deallocate( _p, 1 ); - } - } - /** - * @brief 销毁只读字典的迭代器 - */ - static void _s_destroy_const_iterator( - IDictConstIteratorImpl * p, - const void *p_alloc - ){ - typedef typename allocator_type:: - template rebind::other impl_alloc_t; - DictConstIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~DictConstIteratorImpl(); - impl_alloc_t(*static_cast(p_alloc)).deallocate( _p, 1 ); - } - } - /** - * @brief 内部字典 - */ - implement_t _dict; - /** - * @brief 内部的allocator - */ - allocator_type _alloc; //TODO:为了简单直观,没有做EBO优化,以后可以加上 - }; - - template - inline bool BasicDict::DictIteratorImpl::equal_to( - const IDictIteratorImpl& other - ) const { - const DictIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - template - inline bool BasicDict::DictIteratorImpl::equal_to( - const IDictConstIteratorImpl& other - ) const { - const DictConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && p->_iter == _iter; - } - - template - inline bool BasicDict::DictConstIteratorImpl::equal_to( - const IDictIteratorImpl& other - ) const { - const DictIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - template - inline bool BasicDict::DictConstIteratorImpl::equal_to( - const IDictConstIteratorImpl& other - ) const { - const DictConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - /** - * @brief 修整一下std::map的接口,提供一个接受allocator的构造函数 - * - * 典型的adapter模式 - * 该adapter还能使其运行时名字没有这么吓人:-P - * - */ - templateclass Alloc> - class __StdMapAdapter: public std::map< - IVar::string_type, - bsl::var::Ref, - std::less, - Alloc > - >{ - public: - /** - * @brief 重命名std::map的接口 - * - */ - typedef std::map< - IVar::string_type, - bsl::var::Ref, - std::less, - Alloc > - > base_type; - /** - * @brief allocator的类型 - * - */ - typedef typename base_type::allocator_type allocator_type; - /** - * @brief 迭代器 - * - */ - typedef typename base_type::iterator iterator; - /** - * @brief 只读迭代器 - * - */ - typedef typename base_type::const_iterator const_iterator; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2009/04/08 11:22:53 - **/ - __StdMapAdapter() - :base_type(){} - - /** - * @brief 使用allocator初始化的构造函数 - * - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:23:05 - **/ - explicit __StdMapAdapter( const allocator_type& alloc_ ) - :base_type(std::less(), alloc_ ){} - - /** - * @brief 使用init_capacity与allocator初始化的构造函数 - * - * 对于std::map,init_capacity没有意义,直接忽略 - * @param [in] init_capacity : size_t - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 12:02:53 - **/ - explicit __StdMapAdapter( size_t /*init_capacity*/, const allocator_type& alloc_ ) - :base_type(std::less(), alloc_ ){} - - //inherit everything else - }; - - /** - * @brief 修整一下__gnu_cxx::hash_map的接口,提供一个接受allocator的构造函数 - * - * 典型的adapter模式 - * 该adapter还能使其运行时名字没有这么吓人:-P - * - */ - templateclass Alloc> -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - class __GnuHashMapAdapter: public std::tr1::unordered_map< - IVar::string_type, - bsl::var::Ref, - ::__gnu_cxx::hash, - std::equal_to, - Alloc - > { -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 - - class __GnuHashMapAdapter: public std::unordered_map< - IVar::string_type, - bsl::var::Ref, - __gnu_cxx::hash, - std::equal_to, - Alloc - > { -#else - class __GnuHashMapAdapter: public __gnu_cxx::hash_map< - IVar::string_type, - bsl::var::Ref, - __gnu_cxx::hash, - std::equal_to, - Alloc - > { -#endif - public: - /** - * @brief 重命名__gnu_cxx::hash_map接口 - * - */ -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - typedef std::tr1::unordered_map< - IVar::string_type, - bsl::var::Ref, - ::__gnu_cxx::hash, - std::equal_to, - Alloc - > base_type; -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 - typedef std::unordered_map< - IVar::string_type, - bsl::var::Ref, - __gnu_cxx::hash, - std::equal_to, - Alloc - > base_type; -#else - typedef __gnu_cxx::hash_map< - IVar::string_type, - bsl::var::Ref, - __gnu_cxx::hash, - std::equal_to, - Alloc - > base_type; -#endif - /** - * @brief allocator的类型 - * - */ - typedef typename base_type::allocator_type allocator_type; - /** - * @brief 迭代器 - * - */ - typedef typename base_type::iterator iterator; - /** - * @brief 只读迭代器 - * - */ - typedef typename base_type::const_iterator const_iterator; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2009/04/08 11:22:15 - **/ - __GnuHashMapAdapter() - :base_type(){} - - /** - * @brief 使用allocator初始化的构造函数 - * - * 100是__gnu_cxx::hash_map使用的默认容量值 - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:22:27 - **/ - explicit __GnuHashMapAdapter( const allocator_type& alloc_ ) - :base_type( - 100, - typename base_type::hasher(), - typename base_type::key_equal(), - alloc_ - ){} - - /** - * @brief 使用init_capacity与allocator初始化的构造函数 - * - * @param [in] init_capacity : size_t - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:58:52 - **/ - explicit __GnuHashMapAdapter( size_t init_capacity, const allocator_type& alloc_ ) - :base_type( - init_capacity, - typename base_type::hasher(), - typename base_type::key_equal(), - alloc_ - ){} - - //inherit everything else - }; -}} //namespace bsl::var - -#endif //__BSL_VAR_DICT_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Double.h b/bsl/var/implement/Double.h deleted file mode 100644 index b53dea5fa852d0c846e303d8fb48b2c6d8d50d41..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Double.h +++ /dev/null @@ -1,394 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Double.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Double.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:32:42 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_DOUBLE_H__ -#define __BSL_VAR_DOUBLE_H__ - -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" - -namespace bsl{ -namespace var{ - class Double: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - public: - //special methods - Double( double __value = 0 ) :_value(__value){} - - Double( const Double& other ) - :IVar(other), _value( other._value ) {} - - Double& operator = ( const Double& other ){ - _value = other._value; - return *this; - } - - //methods for all - virtual Double& operator = ( IVar& var ) { - try{ - _value = var.to_double(); //throw - }catch(bsl::Exception& e){ - e<<"{bsl::var::Int32::operator =("<(_value); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return check_cast(_value); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value); - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return float(_value); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return _value; - } - - virtual Double& operator = ( bool b ){ - _value = b; - return *this; - } - - virtual Double& operator = ( int i ){ - _value = check_cast(i); - return *this; - } - - virtual Double& operator = ( long long ll ){ - _value = check_cast(ll); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Double& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Double& operator = ( float f ){ - _value = f; - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Double& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Double& operator = ( double d ){ - _value = d; - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Double& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Double& operator = ( const char * cstr ){ - _value = check_cast(cstr); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Double& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Double& operator = ( const string_type& str ){ - _value = check_cast(str.c_str()); - return *this; - } - - //use default version for bool、raw - using IVar::operator =; - - //testers - virtual bool is_number() const { - return true; - } - - virtual bool is_double() const { - return true; - } - - private: - double _value; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_DOUBLE_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Function.h b/bsl/var/implement/Function.h deleted file mode 100644 index 015d3fae88881b89a685717e953d23e329589b11..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Function.h +++ /dev/null @@ -1,185 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Function.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Function.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:53:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_FUNCTION_H__ -#define __BSL_VAR_FUNCTION_H__ -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" - -namespace bsl{ -namespace var{ - class Function: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef IVar& (* function_type )(IVar&, bsl::ResourcePool& ); - typedef IVar::array_iterator array_iterator; - typedef IVar::array_const_iterator array_const_iterator; - - //special methods - Function( function_type func, const string_type& name ) - :IVar(), _func(func), _name(name){ } - - Function( const Function& other ) - :IVar(other), _func(other._func), _name(other._name){ } - - virtual ~Function(){ } - - Function& operator = ( const Function& other ){ - _func = other._func; - _name = other._name; - return *this; - } - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - // pass - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return Function& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual Function& clone( bsl::ResourcePool& rp ) const { - return rp.clone(*this); - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return Function& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual Function& clone( bsl::ResourcePool& rp, bool /*is_deep_copy*/ ) const { - return rp.clone(*this); - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t /*verbose_level*/ = 0) const { - return string_type("[bsl::var::Function]").append(_name); - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return _name; - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - return "bsl::var::Function"; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return IVar::IS_CALLABLE; - } - - virtual Function& operator = ( IVar& var ){ - Function * vfp = dynamic_cast(&var); - if ( vfp == NULL ){ - throw bsl::InvalidOperationException()<_name; - _func = vfp->_func; - return *this; - } - - } - - virtual bool is_callable() const { - return true; - } - - //converters - using IVar::operator =; - - virtual IVar& operator()(IVar& args, bsl::ResourcePool& _rp ){ - return (*_func)(args, _rp); - } - - virtual IVar& operator()(IVar& /*self*/, IVar& args, bsl::ResourcePool& _rp ){ - return (*_func)(args, _rp); - } - - private: - function_type _func; - string_type _name; - }; - -}} //namespace bsl::var -#endif //__BSL_VAR_FUNCTION_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Int32.h b/bsl/var/implement/Int32.h deleted file mode 100644 index a589dfe367e5af18ac17c5c6ea72e96be2a478b0..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Int32.h +++ /dev/null @@ -1,534 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Int32.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Int32.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:32:42 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_INT32_H__ -#define __BSL_VAR_INT32_H__ - -#include -#include -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" -#include "BigInt.h" - -namespace bsl{ -namespace var{ - - class Int32: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - public: - //special methods - Int32( int __value = 0 ) - :_value(__value){} - - Int32( const Int32& other ) - :IVar(other), _value( other._value ) {} - - Int32& operator = ( const Int32& other ){ - _value = other._value; - return *this; - } - - //methods for all - virtual Int32& operator = ( IVar& var ) { - try{ - _value = var.to_int32(); //throw - }catch(bsl::Exception& e){ - e<<"{bsl::var::Int32::operator =("<(_value); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return _value; - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value); - } - - /** - * @brief - * - * @return long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual long long to_int64() const { - return _value; - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value); - } - - /** - * @brief conversion to bigint, not a virtual function derived - * - * @tparam bits - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 15:51:13 - */ - template - BigInt to_bigint() { - BigInt tmp = _value; - return tmp; - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return static_cast(_value); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return static_cast(_value); - } - - virtual Int32& operator = ( bool b ){ - _value = b; - return *this; - } - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( signed char i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( unsigned char i ){ - _value = i; - return *this; - } - - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( signed short i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( unsigned short i ){ - _value = i; - return *this; - } - - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( signed int i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( unsigned int ll ){ - _value = check_cast(ll); - return *this; - } - - virtual Int32& operator = ( long long ll ){ - _value = check_cast(ll); - return *this; - } - - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( unsigned long long ll ){ - _value = check_cast(ll); - return *this; - } - - /** - * @brief - * - * @tparam bits - * @param val - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 16:26:45 - */ - template - Int32& operator = ( BigInt val){ - _value = val.to_int32(); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( float f ){ - _value = check_cast(f); - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( double d ){ - _value = check_cast(d); - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( const char *cstr ){ - _value = check_cast(cstr); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Int32& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int32& operator = ( const string_type& str ){ - _value = check_cast(str.c_str()); - return *this; - } - - //use default version for raw - using IVar::operator =; - - //testers - virtual bool is_number() const { - return true; - } - - virtual bool is_int32() const { - return true; - } - - private: - int _value; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_INT32_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Int64.h b/bsl/var/implement/Int64.h deleted file mode 100644 index 35efaaeb51d849221c2a227bca2a72a11749596d..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Int64.h +++ /dev/null @@ -1,533 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Int64.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Int64.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:32:42 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_INT64_H__ -#define __BSL_VAR_INT64_H__ - -#include -#include -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" -#include "BigInt.h" - -namespace bsl{ -namespace var{ - class Int64: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - public: - //special methods - Int64( long long __value = 0 ) :_value(__value){} - - Int64( const Int64& other ) - :IVar(other), _value( other._value ) {} - - Int64& operator = ( const Int64& other ){ - _value = other._value; - return *this; - } - - //methods for all - virtual Int64& operator = ( IVar& var ) { - try{ - _value = var.to_int64(); //throw - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<(_value); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return _value; - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value); - } - - /** - * @brief conversion to bigint, not a virtual function derived - * - * @tparam bits - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 15:51:13 - */ - template - BigInt to_bigint() { - BigInt tmp = _value; - return tmp; - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return static_cast(_value); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return check_cast(_value); - } - - virtual Int64& operator = ( bool b ){ - _value = b; - return *this; - } - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( signed char i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( unsigned char i ){ - _value = i; - return *this; - } - - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( signed short i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( unsigned short i ){ - _value = i; - return *this; - } - - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( signed int i ){ - _value = i; - return *this; - } - - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( unsigned int i ){ - _value = i; - return *this; - } - - virtual Int64& operator = ( long long ll ){ - _value = ll; - return *this; - } - - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( unsigned long long d ){ - _value = check_cast(d); - return *this; - } - - /** - * @brief - * - * @tparam bits - * @param val - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 16:26:45 - */ - template - Int64& operator = ( BigInt val){ - _value = val.to_int64(); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( float f ){ - _value = check_cast(f); - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( double d ){ - _value = check_cast(d); - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( const char * cstr ){ - _value = check_cast(cstr); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Int64& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Int64& operator = ( const string_type& str ){ - _value = check_cast(str.c_str()); - return *this; - } - - //use default version for bool、raw - using IVar::operator =; - - //testers - virtual bool is_number() const { - return true; - } - - virtual bool is_int64() const { - return true; - } - - private: - long long _value; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_INT64_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/MagicArray.h b/bsl/var/implement/MagicArray.h deleted file mode 100644 index c418c6c51cbc6fc9de0efb4415b94b3a761954c3..0000000000000000000000000000000000000000 --- a/bsl/var/implement/MagicArray.h +++ /dev/null @@ -1,548 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: MagicArray.h,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file MagicBasicArray.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:36:18 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#ifndef __BSL_VAR_MAGIC_ARRAY_H__ -#define __BSL_VAR_MAGIC_ARRAY_H__ - -#include -#include "bsl/pool/bsl_pool.h" -#include "bsl/var/IVar.h" -#include "bsl/var/MagicRef.h" -#include "bsl/var/Null.h" -#include "bsl/var/utils.h" - -namespace bsl{ -namespace var{ - //typedefs - template - class MagicBasicArray; - - typedef MagicBasicArray > MagicArray; - - template - class MagicBasicArray: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef allocator_t allocator_type; - typedef ArrayIterator array_iterator; - typedef ArrayConstIterator array_const_iterator; - typedef MagicRef reference_type; - - public: - MagicBasicArray(bsl::ResourcePool& rp) - :_array(), _rp(rp) {} - - MagicBasicArray( const MagicBasicArray& other ) - :IVar(other), _array(other._array), _rp(other._rp){} - - MagicBasicArray& operator = ( const MagicBasicArray& other ){ - try{ - _array = other._array; - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<(var)); - }else if ( var.is_array() ){ - size_t var_size = var.size(); - try{ - _array.resize( var_size, reference_type(_rp) ); - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<= _array.size() ){ - return bsl::var::Null::null; - } - return _array[idx]; - } - - virtual IVar& get( size_t idx, IVar& default_value ) { - if ( idx >= _array.size() ){ - return default_value; - } - return _array[idx]; - } - - virtual const IVar& get( size_t idx ) const { - if ( idx >= _array.size() ){ - return bsl::var::Null::null; - } - return _array[idx]; - } - - virtual const IVar& get( size_t idx, const IVar& default_value ) const { - if ( idx >= _array.size() ){ - return default_value; - } - return _array[idx]; - } - - virtual void set( size_t idx, IVar& value ){ - if ( idx >= _array.size() ){ - try{ - _array.resize(idx + 1, reference_type(_rp) ); - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<= _array.size() || _array[idx].is_null() ){ - return false; - }else{ - _array[idx] = Null::null; - return true; - } - } - - virtual array_const_iterator array_begin() const { - return array_const_iterator( _s_create_const_iterator( &_array, 0 ), _s_clone_const_iterator, _s_destroy_const_iterator ); - } - - virtual array_iterator array_begin() { - return array_iterator( _s_create_iterator( &_array, 0 ), _s_clone_iterator, _s_destroy_iterator ); - } - - virtual array_const_iterator array_end() const { - return array_const_iterator( _s_create_const_iterator( &_array, _array.size() ), _s_clone_const_iterator, _s_destroy_const_iterator ); - } - - virtual array_iterator array_end() { - return array_iterator( _s_create_iterator( &_array, _array.size() ), _s_clone_iterator, _s_destroy_iterator ); - } - - virtual const IVar& operator []( int idx ) const { - return this->get( idx >= 0 ? size_t(idx) : size_t(_array.size() + idx) ); - } - - virtual IVar& operator []( int idx ){ - if ( idx >= int(_array.size()) ){ - try{ - _array.resize( idx + 1, reference_type(_rp) ); - }catch(bsl::Exception& e){ - throw; - }catch(std::exception& e){ - throw StdException(e)<get( idx >= 0 ? size_t(idx) : size_t(_array.size() + idx) ); - } - - //methods for dict -#if __GNUC__ > 2 - using IVar::operator []; - using IVar::get; - using IVar::set; - using IVar::del; -#else - //avoid using bug of g++ 2.96 - virtual IVar& get( const field_type& name ) { - throw bsl::InvalidOperationException()< array_type; - class ArrayIteratorImpl; - class ArrayConstIteratorImpl; - - class ArrayIteratorImpl: public IArrayIteratorImpl{ - friend class ArrayConstIteratorImpl; - public: - - ArrayIteratorImpl( array_type* p_array, size_t offset ) - :_p_array(p_array), _offset(offset){} - - virtual ~ArrayIteratorImpl() { - //pass - } - - virtual size_t key() const { - return _offset; - } - - virtual IVar& value() const { - return (*_p_array)[_offset]; - } - - virtual void iterate(){ - ++ _offset; - } - - virtual void assign( const IArrayIteratorImpl& other ) { - const ArrayIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_p_array; - _offset = p->_offset; - } - - virtual bool equal_to( const IArrayIteratorImpl& other ) const; - - virtual bool equal_to( const IArrayConstIteratorImpl& other ) const; - - private: - array_type *_p_array; - size_t _offset; - }; - - - class ArrayConstIteratorImpl: public IArrayConstIteratorImpl{ - friend class ArrayIteratorImpl; - public: - - ArrayConstIteratorImpl( const array_type* p_array, size_t offset ) - :_p_array(p_array), _offset(offset){} - - virtual ~ArrayConstIteratorImpl() { - //pass - } - - virtual size_t key() const { - return _offset; - } - - virtual const IVar& value() const { - return (*_p_array)[_offset]; - } - - virtual void iterate(){ - ++ _offset; - } - - virtual void assign( const IArrayIteratorImpl& other ) { - const ArrayIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_p_array; - _offset = p->_offset; - } - - virtual void assign( const IArrayConstIteratorImpl& other ) { - const ArrayConstIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_p_array; - _offset = p->_offset; - } - - virtual bool equal_to( const IArrayConstIteratorImpl& other ) const; - - virtual bool equal_to( const IArrayIteratorImpl& other ) const; - - private: - const array_type * _p_array; - size_t _offset; - }; - - static IArrayIteratorImpl * _s_create_iterator( array_type* p_array, size_t offset){ - typedef typename allocator_t::template rebind::other impl_alloc_t; - IArrayIteratorImpl *p = impl_alloc_t().allocate(1); //throw - new(p) ArrayIteratorImpl(p_array, offset ); //nothrow - return p; - } - - static IArrayConstIteratorImpl * _s_create_const_iterator( const array_type* p_array, size_t offset){ - typedef typename allocator_t::template rebind::other impl_alloc_t; - IArrayConstIteratorImpl *p = impl_alloc_t().allocate(1); //throw - new(p) ArrayConstIteratorImpl(p_array, offset ); //nothrow - return p; - } - - static IArrayIteratorImpl * _s_clone_iterator( const IArrayIteratorImpl *p_other ){ - typedef typename allocator_t::template rebind::other impl_alloc_t; - const ArrayIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException()<::other impl_alloc_t; - const ArrayConstIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException()<::other impl_alloc_t; - ArrayIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~ArrayIteratorImpl(); - impl_alloc_t().deallocate( _p, 1 ); - } - } - - static void _s_destroy_const_iterator( IArrayConstIteratorImpl * p){ - typedef typename allocator_t::template rebind::other impl_alloc_t; - ArrayConstIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~ArrayConstIteratorImpl(); - impl_alloc_t().deallocate( _p, 1 ); - } - } - - array_type _array; - bsl::ResourcePool& _rp; - }; - - template - inline bool MagicBasicArray::ArrayIteratorImpl::equal_to( const IArrayIteratorImpl& other ) const { - const ArrayIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - template - inline bool MagicBasicArray::ArrayIteratorImpl::equal_to( const IArrayConstIteratorImpl& other ) const { - const ArrayConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - template - inline bool MagicBasicArray::ArrayConstIteratorImpl::equal_to( const IArrayIteratorImpl& other ) const { - const ArrayIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - - template - inline bool MagicBasicArray::ArrayConstIteratorImpl::equal_to( const IArrayConstIteratorImpl& other ) const { - const ArrayConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _p_array == p->_p_array && _offset == p->_offset; - } - -}} //namespace bsl::var - -#endif //__BSL_VAR_MAGIC_ARRAY_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/MagicDict.h b/bsl/var/implement/MagicDict.h deleted file mode 100644 index 6a4edfddb054f9e3ef533e0c783fc76529edc0c5..0000000000000000000000000000000000000000 --- a/bsl/var/implement/MagicDict.h +++ /dev/null @@ -1,750 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: MagicDict.h,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file MagicDict.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:36:18 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#ifndef __BSL_VAR_MAGIC_DICT_H__ -#define __BSL_VAR_MAGIC_DICT_H__ - -#include -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 -#include -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 -#include -#elif __GNUC__ >= 3 -#include -#else -#include -#endif -#include "bsl/pool/bsl_pool.h" -#include "bsl/var/IVar.h" -#include "bsl/var/MagicRef.h" -#include "bsl/var/Null.h" -#include "bsl/var/utils.h" - -#if __GNUC__ < 3 -namespace __gnu_cxx{ - /** - * @brief 使g++2.96也统一为__gnu_cxx命名空间 - * - * - */ - using std::hash_map; - using std::hash; -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - using std::tr1; -#endif -} -#endif - -namespace bsl{ -namespace var{ - //forward declarations & typedefs - template - class MagicBasicDict; - - templateclass Alloc> - class __MagicStdMapAdapter; - - templateclass Alloc> - class __MagicGnuHashMapAdapter; - - /** - * @brief 封装了std::map,并使用bsl::pool_allocator的字典 - * - */ - typedef MagicBasicDict<__MagicStdMapAdapter > MagicStdMapDict; - - /** - * @brief 封装了__gnu_cxx::hash_map,并使用bsl::pool_allocator的字典 - * - * - */ - typedef MagicBasicDict<__MagicGnuHashMapAdapter >MagicGnuHashDict; - - /** - * @brief 最推荐使用的字典 - * - * 目前最推荐使用的是封装了std::map,并使用bsl::pool_allocator的StdMapDict - */ - typedef MagicStdMapDict MagicDict; - - - template - class MagicBasicDict: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef typename implement_t::allocator_type allocator_type; - typedef DictIterator dict_iterator; - typedef DictConstIterator dict_const_iterator; - typedef MagicRef reference_type; - - public: - MagicBasicDict(bsl::ResourcePool& rp) - :_dict(), _alloc(), _rp(rp) {} - - explicit MagicBasicDict( bsl::ResourcePool& rp, size_t init_capacity, const allocator_type& alloc_ = allocator_type() ) - :_dict(init_capacity, alloc_), _alloc(alloc_), _rp(rp) {} - - explicit MagicBasicDict( bsl::ResourcePool& rp, const allocator_type& alloc_ ) - :_dict(alloc_), _alloc(alloc_), _rp(rp) {} - - MagicBasicDict( const MagicBasicDict& other ) - :IVar(other), _dict(other._dict), _alloc(other._alloc), _rp(other._rp) {} - - MagicBasicDict& operator = ( const MagicBasicDict& other ){ - try{ - _dict = other._dict; - _alloc= other._alloc; - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<key(), (iter->value()).clone(rp, is_deep_copy)); - } - } - return res; - } - - /** - * @brief 递归打印自身及下级结点信息 - * - * @param [in] verbose_level : size_t - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2009/05/14 17:34:58 - **/ - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t verbose_level = 0) const { - string_type res; - if ( verbose_level == 0 ){ - res.appendf("[bsl::var::MagicBasicDict] this[%p] size[%zd]", this, _dict.size() ); - }else{ - dump_to_string(*this, res, verbose_level, "", 0 ); - } - return res; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return dump(0); - } - - virtual MagicBasicDict& operator = ( IVar& var ) { - if ( typeid(var) == typeid(*this) ){ - _dict = dynamic_cast(var)._dict; - }else if ( var.is_dict() ){ - _dict.clear(); - IVar::dict_iterator iter_ = var.dict_begin(); - IVar::dict_iterator end = var.dict_end(); - for( ; iter_ != end ; ++ iter_ ){ - bsl::var::MagicRef mr(_rp); - mr = iter_->value(); - _dict.insert(std::make_pair(iter_->key(), mr)); - } - }else{ - throw bsl::InvalidOperationException()<second; - } - - virtual IVar& get( const field_type& name, IVar& default_value ) { - iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return default_value; - } - return iter_->second; - } - - virtual const IVar& get( const field_type& name ) const { - const_iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return bsl::var::Null::null; - } - return iter_->second; - } - - virtual const IVar& get( const field_type& name, const IVar& default_value ) const { - const_iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return default_value; - } - return iter_->second; - } - - virtual void set( const field_type& name, IVar& value ){ - bsl::var::MagicRef mr(_rp); - mr = value; - typedef std::pair pair_t; - pair_t res = _dict.insert( std::pair( name, mr ) ); - if ( !res.second ){ - //already exist - res.first->second = mr; - } - } - - virtual bool del( const field_type& name ) { - iter_impl_t iter_ = _dict.find( name ); - if ( iter_ == _dict.end() ){ - return false; - } - _dict.erase( iter_ ); - return true; - } - - virtual dict_const_iterator dict_begin() const { - return dict_const_iterator( _s_create_const_iterator( _dict.begin(), &_alloc ), _s_clone_const_iterator, _s_destroy_const_iterator, &_alloc ); - } - - virtual dict_iterator dict_begin() { - return dict_iterator( _s_create_iterator( _dict.begin(), &_alloc ), _s_clone_iterator, _s_destroy_iterator, &_alloc ); - } - - virtual dict_const_iterator dict_end() const { - return dict_const_iterator( _s_create_const_iterator( _dict.end(), &_alloc ), _s_clone_const_iterator, _s_destroy_const_iterator, &_alloc ); - } - - virtual dict_iterator dict_end() { - return dict_iterator( _s_create_iterator( _dict.end(), &_alloc ), _s_clone_iterator, _s_destroy_iterator, &_alloc ); - } - - virtual const IVar& operator []( const field_type& name ) const { - const_iter_impl_t iter_ = _dict.find(name); - if ( iter_ == _dict.end() ){ - throw bsl::KeyNotFoundException()<second; - } - - virtual IVar& operator []( const field_type& name ){ - iter_impl_t iter_ = _dict.find(name); - if ( iter_ == _dict.end() ){ - iter_ = _dict.insert(std::make_pair(name, bsl::var::MagicRef(_rp))).first; - } - return iter_->second; - } - - //methods for array -#if __GNUC__ > 2 - using IVar::operator []; - using IVar::get; - using IVar::set; - using IVar::del; -#else - //avoid using bug of g++ 2.96 - virtual IVar& get( size_t idx ) { - throw bsl::InvalidOperationException()<first; - } - - virtual IVar& value() const { - return _iter->second; - } - - virtual void iterate(){ - ++ _iter; - } - - virtual void assign( const IDictIteratorImpl& other ) { - const DictIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_iter; - } - - virtual bool equal_to( const IDictIteratorImpl& other ) const; - - virtual bool equal_to( const IDictConstIteratorImpl& other ) const; - - private: - iter_impl_t _iter; - }; - - - class DictConstIteratorImpl: public IDictConstIteratorImpl{ - friend class DictIteratorImpl; - public: - - DictConstIteratorImpl( const const_iter_impl_t& iter_ ) - :_iter(iter_){} - - virtual ~DictConstIteratorImpl() { - //pass - } - - virtual const string_type& key() const { - return _iter->first; - } - - virtual const IVar& value() const { - return _iter->second; - } - - virtual void iterate(){ - ++ _iter; - } - - virtual void assign( const IDictIteratorImpl& other ) { - const DictIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_iter; - } - - virtual void assign( const IDictConstIteratorImpl& other ) { - const DictConstIteratorImpl *p = dynamic_cast(&other); - if ( !p ){ - throw bsl::BadCastException()<_iter; - } - - virtual bool equal_to( const IDictConstIteratorImpl& other ) const; - - virtual bool equal_to( const IDictIteratorImpl& other ) const; - - private: - const_iter_impl_t _iter; - }; - - static IDictIteratorImpl * _s_create_iterator( const iter_impl_t& iter_, const void *p_alloc ){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - IDictIteratorImpl *p = impl_alloc_t(*static_cast(p_alloc)).allocate(1); //throw - new(p) DictIteratorImpl( iter_ ); //nothrow - return p; - } - - static IDictConstIteratorImpl * _s_create_const_iterator( const const_iter_impl_t& iter_, const void *p_alloc ){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - IDictConstIteratorImpl *p = impl_alloc_t(*static_cast(p_alloc)).allocate(1); //throw - new(p) DictConstIteratorImpl( iter_ ); //nothrow - return p; - } - - static IDictIteratorImpl * _s_clone_iterator( const IDictIteratorImpl *p_other, const void *p_alloc ){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - const DictIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException()<(p_alloc)).allocate(1); //throw - new(p) DictIteratorImpl(*psrc); - return p; - } - - static IDictConstIteratorImpl * _s_clone_const_iterator( const IDictConstIteratorImpl *p_other, const void *p_alloc ){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - const DictConstIteratorImpl *psrc = dynamic_cast(p_other); - if ( !psrc ){ - throw bsl::BadCastException()<(p_alloc)).allocate(1); //throw - new(p) DictConstIteratorImpl(*psrc); - return p; - } - - static void _s_destroy_iterator( IDictIteratorImpl * p, const void *p_alloc){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - DictIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~DictIteratorImpl(); - impl_alloc_t(*static_cast(p_alloc)).deallocate( _p, 1 ); - } - } - - static void _s_destroy_const_iterator( IDictConstIteratorImpl * p, const void *p_alloc ){ - typedef typename allocator_type::template rebind::other impl_alloc_t; - DictConstIteratorImpl *_p = dynamic_cast(p); - if ( _p ){ - _p->~DictConstIteratorImpl(); - impl_alloc_t(*static_cast(p_alloc)).deallocate( _p, 1 ); - } - } - - implement_t _dict; - allocator_type _alloc; //TODO:为了简单直观,没有做EBO优化,以后可以加上 - bsl::ResourcePool& _rp; - }; - - template - inline bool MagicBasicDict::DictIteratorImpl::equal_to( const IDictIteratorImpl& other ) const { - const DictIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - template - inline bool MagicBasicDict::DictIteratorImpl::equal_to( const IDictConstIteratorImpl& other ) const { - const DictConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && p->_iter == _iter; - } - - template - inline bool MagicBasicDict::DictConstIteratorImpl::equal_to( const IDictIteratorImpl& other ) const { - const DictIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - template - inline bool MagicBasicDict::DictConstIteratorImpl::equal_to( const IDictConstIteratorImpl& other ) const { - const DictConstIteratorImpl *p = dynamic_cast(&other); - return p != NULL && _iter == p->_iter; - } - - /** - * @brief 修整一下std::map的接口,提供一个接受allocator的构造函数 - * - * 典型的adapter模式 - * 该adapter还能使其运行时名字没有这么吓人:-P - * - */ - templateclass Alloc> - class __MagicStdMapAdapter: public std::map, Alloc > >{ - public: - typedef std::map, Alloc > > base_type; - typedef typename base_type::allocator_type allocator_type; - typedef typename base_type::iterator iterator; - typedef typename base_type::const_iterator const_iterator; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2009/04/08 11:22:53 - **/ - __MagicStdMapAdapter() - :base_type(){} - - /** - * @brief 使用allocator初始化的构造函数 - * - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:23:05 - **/ - explicit __MagicStdMapAdapter( const allocator_type& alloc_ ) - :base_type(std::less(), alloc_ ){} - - /** - * @brief 使用init_capacity与allocator初始化的构造函数 - * - * 对于std::map,init_capacity没有意义,直接忽略 - * @param [in] init_capacity : size_t - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 12:02:53 - **/ - explicit __MagicStdMapAdapter( size_t /*init_capacity*/, const allocator_type& alloc_ ) - :base_type(std::less(), alloc_ ){} - - //inherit everything else - }; - - /** - * @brief 修整一下__gnu_cxx::hash_map的接口,提供一个接受allocator的构造函数 - * - * 典型的adapter模式 - * 该adapter还能使其运行时名字没有这么吓人:-P - * - */ - templateclass Alloc> -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - class __MagicGnuHashMapAdapter: public std::tr1::unordered_map< - IVar::string_type, - bsl::var::MagicRef, - ::__gnu_cxx::hash, - std::equal_to, - Alloc > { -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 - class __MagicGnuHashMapAdapter: public std::unordered_map< - IVar::string_type, - bsl::var::MagicRef, - __gnu_cxx::hash, - std::equal_to, - Alloc > { -#else - class __MagicGnuHashMapAdapter: public __gnu_cxx::hash_map< - IVar::string_type, - bsl::var::MagicRef, - ::__gnu_cxx::hash, - std::equal_to, - Alloc > { -#endif - public: -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 - typedef std::tr1::unordered_map< - IVar::string_type, - bsl::var::MagicRef, - ::__gnu_cxx::hash, - std::equal_to, - Alloc > base_type; -#elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 - typedef std::unordered_map< - IVar::string_type, - bsl::var::MagicRef, - __gnu_cxx::hash, - std::equal_to, - Alloc > base_type; -#else - typedef __gnu_cxx::hash_map< - IVar::string_type, - bsl::var::MagicRef, - ::__gnu_cxx::hash, - std::equal_to, - Alloc > base_type; -#endif - typedef typename base_type::allocator_type allocator_type; - typedef typename base_type::iterator iterator; - typedef typename base_type::const_iterator const_iterator; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2009/04/08 11:22:15 - **/ - __MagicGnuHashMapAdapter() - :base_type(){} - - /** - * @brief 使用allocator初始化的构造函数 - * - * 100是__gnu_cxx::hash_map使用的默认容量值 - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:22:27 - **/ - explicit __MagicGnuHashMapAdapter( const allocator_type& alloc_ ) - :base_type(100, typename base_type::hasher(), typename base_type::key_equal(), alloc_ ){} - - /** - * @brief 使用init_capacity与allocator初始化的构造函数 - * - * @param [in] init_capacity : size_t - * @param [in] alloc_ : const allocator_type& - * @return explicit - * @retval - * @see - * @author chenxm - * @date 2009/04/08 11:58:52 - **/ - explicit __MagicGnuHashMapAdapter( size_t init_capacity, const allocator_type& alloc_ ) - :base_type(init_capacity, typename base_type::hasher(), typename base_type::key_equal(), alloc_ ){} - - //inherit everything else - }; -}} //namespace bsl::var - -#endif //__BSL_VAR_DICT_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/MagicRef.cpp b/bsl/var/implement/MagicRef.cpp deleted file mode 100644 index 673879b53fc17ca820e702628b6bff9286c1e7aa..0000000000000000000000000000000000000000 --- a/bsl/var/implement/MagicRef.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: MagicRef.cpp,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file MagicRef.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/12/15 00:19:01 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#include "MagicRef.h" -#include "implement.h" -#include - -namespace bsl{ namespace var { - MagicRef::string_type MagicRef::to_string() const { - if ( _p ){ - return _p->to_string(); - }else{ - return bsl::var::Null::null.to_string(); - } - } - - IVar& MagicRef::ref() const { - if ( _p ){ - return *_p; - }else{ - return bsl::var::Null::null; - } - } - - MagicRef& MagicRef::operator = ( bool val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( signed char val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( unsigned char val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( signed short val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( unsigned short val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( signed int val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( unsigned int val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( signed long long val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( unsigned long long val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( float val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( double val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create >(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( const char *val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( const string_type& val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create(val); - } - return *this; - } - - MagicRef& MagicRef::operator = ( const raw_type& val ){ - if ( _p ){ - _p->operator = ( val ); - }else{ - _p = &_rp.create(val); - } - return *this; - } - void MagicRef::set( size_t index, IVar& value ){ - if ( !_p ){ - _p = &_rp.createn(const_cast(_rp)); - } - return _p->set( index, value ); - } - - bool MagicRef::del( size_t index ){ - if ( !_p ){ - _p = &_rp.createn(_rp); - } - return _p->del(index); - } - - IVar& MagicRef::operator []( int index ){ - if ( !_p ){ - _p = &_rp.createn(_rp); - } - return _p->operator [](index); - } - - void MagicRef::set( const field_type& name, IVar& value ){ - if ( !_p ){ - _p = &_rp.createn(_rp); - } - return _p->set(name, value); - } - - bool MagicRef::del( const field_type& name ){ - if ( !_p ){ - _p = &_rp.createn(_rp); - } - return _p->del(name); - } - - IVar& MagicRef::operator []( const field_type& name ){ - if ( !_p ){ - _p = &_rp.createn(_rp); - } - return _p->operator []( name ); - } -}}//end of namespace - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/MagicRef.h b/bsl/var/implement/MagicRef.h deleted file mode 100644 index b558509dad68547c3113dcc43e4a9cb02851231e..0000000000000000000000000000000000000000 --- a/bsl/var/implement/MagicRef.h +++ /dev/null @@ -1,909 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: MagicRef.h,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file MagicRef.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/12/14 18:04:30 - * @version $Revision: 1.2 $ - * @brief - * MagicRef,在第一次赋值时才智能确定类型的Ref - * MagicRef一经确定类型,即不可再次改变。进行错误类型的操作会导致抛异常。但这个行为以后可能改变,请不要依赖(抛异常)这个特性 - **/ -#ifndef __BSL_VAR__AUTOREF_H_ -#define __BSL_VAR__AUTOREF_H_ - -#include -#include - -namespace bsl{ namespace var { - - /** - * @brief 魔法引用 - * - * 根据第一次使用来变成相应的类型 - */ - class MagicRef: public bsl::var::IRef{ - public: - MagicRef(ResourcePool& rp) - :IRef(), _p(NULL), _rp(rp){} - - MagicRef( const MagicRef& other) - :IRef(other), _p(other._p), _rp(other._rp){} - - MagicRef& operator = ( const MagicRef& other ){ - _p = other._p; - return *this; - } - - virtual ~MagicRef(){} - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual IVar& clone( bsl::ResourcePool& rp ) const { - if ( !_p ){ - return rp.clone(*this); - }else{ - return _p->clone(rp); - } - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual IVar& clone( bsl::ResourcePool& rp, bool is_deep_copy ) const { - if ( !_p ){ - return rp.clone(*this); - }else{ - return _p->clone(rp, is_deep_copy); - } - } - - //methods for ref - virtual IVar& ref() const ; - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - if ( _p ){ - _p->clear(); - } - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t verbose_level = 0) const { - string_type res; - res.appendf("@%p: ", _p); - if ( _p ){ - res.append(_p->dump(verbose_level)); - }else{ - res.append(""); - } - return res; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const ; - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - string_type res("bsl::var::MagicRef("); - if ( _p ){ - res.append(_p->get_type()); - } - res.append(")"); - return res; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return IVar::mask_type( IVar::IS_REF | ( _p ? _p->get_mask() : 0 ) ); - } - - virtual MagicRef& operator = ( IVar& var ){ - if ( var.is_ref() ){ - IRef * __p = dynamic_cast(&var); - if ( NULL != __p ){ - //make a shortcut - _p = &__p->ref(); - }else{ - //unknown ref type - _p = &var; - } - }else{ - //non-ref value; - _p = &var; - } - return *this; - } - - - //methods for all, test methods - virtual bool is_null() const { - if ( _p ){ - return _p->is_null(); - }else{ - return true; - } - } - - virtual bool is_ref() const { - return true; - } - - virtual bool is_bool() const { - if ( _p ){ - return _p->is_bool(); - }else{ - return false; - } - } - - virtual bool is_number() const { - if ( _p ){ - return _p->is_number(); - }else{ - return false; - } - } - - virtual bool is_int8() const { - if ( _p ){ - return _p->is_int8(); - }else{ - return false; - } - } - - virtual bool is_uint8() const { - if ( _p ){ - return _p->is_uint8(); - }else{ - return false; - } - } - - virtual bool is_int16() const { - if ( _p ){ - return _p->is_int16(); - }else{ - return false; - } - } - - virtual bool is_uint16() const { - if ( _p ){ - return _p->is_uint16(); - }else{ - return false; - } - } - - virtual bool is_int32() const { - if ( _p ){ - return _p->is_int32(); - }else{ - return false; - } - } - - virtual bool is_uint32() const { - if ( _p ){ - return _p->is_uint32(); - }else{ - return false; - } - } - - virtual bool is_int64() const { - if ( _p ){ - return _p->is_int64(); - }else{ - return false; - } - } - - virtual bool is_uint64() const { - if ( _p ){ - return _p->is_uint64(); - }else{ - return false; - } - } - - virtual bool is_float() const { - if ( _p ){ - return _p->is_float(); - }else{ - return false; - } - } - - virtual bool is_double() const { - if ( _p ){ - return _p->is_double(); - }else{ - return false; - } - } - - /** - * @brief 判断是否是字符串类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:05:44 - **/ - virtual bool is_string() const { - if ( _p ){ - return _p->is_string(); - }else{ - return false; - } - } - - virtual bool is_array() const { - if ( _p ){ - return _p->is_array(); - }else{ - return false; - } - } - - virtual bool is_dict() const { - if ( _p ){ - return _p->is_dict(); - }else{ - return false; - }; - } - - virtual bool is_callable() const { - if ( _p ){ - return _p->is_callable(); - }else{ - return false; - } - } - - virtual bool is_raw() const { - if ( _p ){ - return _p->is_raw(); - }else{ - return false; - } - } - - //methods for value - /** - * @brief 转化为布尔类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual bool to_bool() const { - if ( _p ){ - return _p->to_bool(); - }else{ - return IRef::to_bool(); - } - } - - /** - * @brief 转化为8位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed char to_int8() const { - if ( _p ){ - return _p->to_int8(); - }else{ - return IRef::to_int8(); - } - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - if ( _p ){ - return _p->to_uint8(); - }else{ - return IRef::to_uint8(); - } - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - if ( _p ){ - return _p->to_int16(); - }else{ - return IRef::to_int16(); - } - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - if ( _p ){ - return _p->to_uint16(); - }else{ - return IRef::to_uint16(); - } - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - if ( _p ){ - return _p->to_int32(); - }else{ - return IRef::to_int32(); - } - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - if ( _p ){ - return _p->to_uint32(); - }else{ - return IRef::to_uint32(); - } - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - if ( _p ){ - return _p->to_int64(); - }else{ - return IRef::to_int64(); - } - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - if ( _p ){ - return _p->to_uint64(); - }else{ - return IRef::to_uint64(); - } - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - if ( _p ){ - return _p->to_float(); - }else{ - return IRef::to_float(); - } - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - if ( _p ){ - return _p->to_double(); - }else{ - return IRef::to_double(); - } - } - - virtual raw_type to_raw() const { - if ( _p ){ - return _p->to_raw(); - }else{ - return IRef::to_raw(); - } - } - - virtual MagicRef& operator = ( bool val ); - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( signed char val ); - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( unsigned char val ); - - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( signed short val ); - - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( unsigned short val ); - - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( signed int val ); - - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( unsigned int val ); - - /** - * @brief 使用signed long long类型赋值 - * - * @param [in] val : signed long long - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( signed long long val ); - - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( unsigned long long val ); - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( float val ); - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( double val ); - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( const char *val ); - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return MagicRef& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual MagicRef& operator = ( const string_type& val ); - - virtual MagicRef& operator = ( const raw_type& val ); - - //methods for string - virtual const char *c_str() const { - if ( _p ){ - return _p->c_str(); - }else{ - return IRef::c_str(); - } - } - - virtual size_t c_str_len() const { - if ( _p ){ - return _p->c_str_len(); - }else{ - return IRef::c_str_len(); - } - } - - //methods for array or dict - /** - * @brief 返回子元素个数(数组或字典)类型支持 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:35:15 - **/ - virtual size_t size() const { - if ( _p ){ - return _p->size(); - }else{ - return IRef::size(); - } - } - - //methods for array - virtual IVar& get( size_t index ) { - if ( _p ){ - return _p->get(index); - }else{ - return IRef::get(index); - } - } - - virtual IVar& get( size_t index, IVar& default_value ) { - if ( _p ){ - return _p->get(index, default_value); - }else{ - return IRef::get(index, default_value); - } - - } - - virtual const IVar& get( size_t index ) const { - if ( _p ){ - return _p->get(index); - }else{ - return IRef::get(index); - } - } - - virtual const IVar& get( size_t index, const IVar& default_value ) const { - if ( _p ){ - return _p->get(index,default_value); - }else{ - return IRef::get(index, default_value); - } - } - - virtual void set( size_t index, IVar& value ); - - virtual bool del( size_t index ); - - virtual array_const_iterator array_begin() const { - if ( _p ){ - return const_cast(_p)->array_begin(); - }else{ - return IRef::array_begin(); - } - } - - virtual array_iterator array_begin() { - if ( _p ){ - return _p->array_begin(); - }else{ - return IRef::array_begin(); - } - } - - virtual array_const_iterator array_end() const { - if ( _p ){ - return const_cast(_p)->array_end(); - }else{ - return IRef::array_end(); - } - } - - virtual array_iterator array_end() { - if ( _p ){ - return _p->array_end(); - }else{ - return IRef::array_end(); - } - } - - virtual const IVar& operator []( int index ) const { - if ( _p ){ - return _p->operator [](index); - }else{ - return IRef::operator[](index); - } - } - - virtual IVar& operator []( int index ); - - //methods for dict - virtual IVar& get( const field_type& name ) { - if ( _p ){ - return _p->get(name); - }else{ - return IRef::get(name); - } - } - - virtual IVar& get( const field_type& name, IVar& default_value ) { - if ( _p ){ - return _p->get(name, default_value); - }else{ - return IRef::get(name, default_value); - } - } - - virtual const IVar& get( const field_type& name ) const { - if ( _p ){ - return _p->get(name); - }else{ - return IRef::get(name); - } - } - - virtual const IVar& get( const field_type& name, const IVar& default_value ) const { - if ( _p ){ - return _p->get(name, default_value); - }else{ - return IRef::get(name, default_value); - } - } - - virtual void set( const field_type& name, IVar& value ); - - virtual bool del( const field_type& name ); - - virtual const IVar& operator []( const field_type& name ) const { - if ( _p ){ - return _p->operator [](name); - }else{ - return IRef::operator [](name); - } - } - - virtual IVar& operator []( const field_type& name ); - - virtual dict_const_iterator dict_begin() const { - if ( _p ){ - return const_cast(_p)->dict_begin(); - }else{ - return IRef::dict_begin(); - } - } - - virtual dict_iterator dict_begin() { - if ( _p ){ - return _p->dict_begin(); - }else{ - return IRef::dict_begin(); - } - } - - virtual dict_const_iterator dict_end() const { - if ( _p ){ - return const_cast(_p)->dict_end(); - }else{ - return IRef::dict_end(); - } - } - - virtual dict_iterator dict_end() { - if ( _p ){ - return _p->dict_end(); - }else{ - return IRef::dict_end(); - } - } - - virtual IVar& operator()(IVar& param, bsl::ResourcePool& rp ){ - if ( _p ){ - return (*_p)(param, rp); - }else{ - return IRef::operator()(param, rp); - } - } - - virtual IVar& operator()(IVar& self, IVar& param, bsl::ResourcePool& rp ){ - if ( _p ){ - return (*_p)(self, param, rp); - }else{ - return IRef::operator()(self, param, rp); - } - } - private: - bsl::var::IVar* _p; - bsl::ResourcePool& _rp; - - }; //end of class -}}//end of namespace -#endif //__BSL_VAR__AUTOREF_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Makefile b/bsl/var/implement/Makefile deleted file mode 100644 index 56f511fb679f352c621b978b958cc13ae4870b2b..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = .. -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_HEADS = $(wildcard *.h) - -PROVIDE_OBJECTS = Null.o MagicRef.o - -PROVIDE_LIB = bsl_var_implement - -DEPEND_HEADS = $(PROVIDE_HEADS) $(wildcard $(OUTPUT_HEAD_PATH)/*.h ) - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### -check_cast_generated.h: check_cast.py - ./$^ > $@ - - diff --git a/bsl/var/implement/Method.h b/bsl/var/implement/Method.h deleted file mode 100644 index 6af544704f72b595980ca8bbaf38107d96f89a7f..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Method.h +++ /dev/null @@ -1,145 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Method.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Method.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:53:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_METHOD_H__ -#define __BSL_VAR_METHOD_H__ -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/var/Null.h" - -namespace bsl{ -namespace var{ - class Method: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef IVar& (* method_type )( IVar&, IVar&, bsl::ResourcePool& ); - typedef IVar::array_iterator array_iterator; - typedef IVar::array_const_iterator array_const_iterator; - - //special methods - Method( method_type method, const string_type& name ) - :IVar(), _method(method), _name(name){ } - - Method( const Method& other ) - :IVar(other), _method(other._method), _name(other._name){ } - - virtual ~Method(){ } - - Method& operator = ( const Method& other ){ - _method = other._method; - _name = other._name; - return *this; - } - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - // pass - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return Method& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual Method& clone( bsl::ResourcePool& rp ) const { - return rp.clone(*this); - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return Method& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual Method& clone( bsl::ResourcePool& rp, bool /*is_deep_copy*/ ) const { - return rp.clone(*this); - } - - virtual string_type dump(size_t /*verbose_level*/ = 0) const { - return string_type("[bsl::var::Method]").append(_name); - } - - virtual string_type to_string() const { - return _name; - } - - virtual string_type get_type() const { - return "bsl::var::Method"; - } - - virtual IVar::mask_type get_mask() const { - return IVar::IS_CALLABLE; - } - - virtual Method& operator = ( IVar& var ){ - Method * vfp = dynamic_cast(&var); - if ( vfp == NULL ){ - throw bsl::InvalidOperationException()<_name; - _method = vfp->_method; - return *this; - } - - } - - virtual bool is_callable() const { - return true; - } - - using IVar::operator =; - - virtual IVar& operator()(IVar& args, bsl::ResourcePool& _rp ){ - return (*_method)(Null::null, args, _rp); - } - - virtual IVar& operator()(IVar& self, IVar& args, bsl::ResourcePool& _rp ){ - return (*_method)(self, args, _rp); - } - - private: - method_type _method; - string_type _name; - }; - -}} //namespace bsl::var -#endif //__BSL_VAR_METHOD_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Null.cpp b/bsl/var/implement/Null.cpp deleted file mode 100644 index abacb77a03c0f4886457b7e34bb92b87b6209751..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Null.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Null.cpp,v 1.2 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file Null.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/28 18:19:18 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include "bsl/var/Null.h" - -bsl::var::Null bsl::var::Null::null; - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Null.h b/bsl/var/implement/Null.h deleted file mode 100644 index 5ffc6c44ab0cb6cb2b31ed20809a8d921874e954..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Null.h +++ /dev/null @@ -1,162 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Null.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Null.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:53:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_NULL_H__ -#define __BSL_VAR_NULL_H__ -#include "bsl/var/IVar.h" - -namespace bsl{ -namespace var{ - class Null: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - //special methods - Null(){ } - - Null( const Null& other ):IVar(other){ } - - virtual ~Null(){ } - - Null& operator = ( const Null& ){ - return *this; - } - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - // pass - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return Null& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual Null& clone( bsl::ResourcePool& rp ) const { - return rp.clone(*this); - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - **@param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return Null& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual Null& clone( bsl::ResourcePool& rp, bool /*is_deep_copy*/ ) const { - return rp.clone(*this); - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t /*verbose_level*/ = 0) const { - return "[bsl::var::Null]null"; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return "null"; - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - return "bsl::var::Null"; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return 0; - } - - virtual Null& operator = ( IVar& var ){ - if ( !var.is_null() ){ - throw bsl::InvalidOperationException()< -#include -#include "bsl/var/IVar.h" -#include "bsl/check_cast.h" -#include "bsl/var/var_traits.h" - -namespace bsl{ -namespace var{ - template - class Number: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - public: - //special methods - Number( T __value = 0 ) :_value(__value){} - - Number( const Number& other ) - :IVar(other), _value( other._value ) {} - - Number& operator = ( const Number& other ){ - _value = other._value; - return *this; - } - - //methods for all - virtual Number& operator = ( IVar& var ) { - try{ - if ( var.is_double() ){ - _value = check_cast( var.to_double() ); - }else if ( var.is_uint64() ){ - _value = check_cast( var.to_uint64() ); - }else{ - _value = check_cast( var.to_int64() ); - } - - }catch(bsl::Exception& e){ - e<<"{"<<__PRETTY_FUNCTION__<<"("<]").append(check_cast(_value)); - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return check_cast(_value); - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - return "bsl::var::Number"; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return var_traits::MASK; - } - - /** - * @brief 转化为布尔类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual bool to_bool() const { - return _value != 0; - } - - /** - * @brief 转化为8位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed char to_int8() const { - return check_cast(_value); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return check_cast(_value); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return check_cast(_value); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value); - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - #ifdef __arm__ - if (typeid(T) == typeid(float) || typeid(T) == typeid(const float)) { - volatile uint32_t tmp = *(volatile uint32_t *)&_value; - return check_cast(*(float *)&tmp); - } else if (typeid(T) == typeid(double) || typeid(T) == typeid(const double)) { - volatile uint64_t tmp = *(volatile uint64_t *)&_value; - return check_cast(*(double *)&tmp); - } else { - return check_cast(_value); - } - #else - return check_cast(_value); - #endif - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - #ifdef __arm__ - if (typeid(T) == typeid(float) || typeid(T) == typeid(const float)) { - volatile uint32_t tmp = *(volatile uint32_t *)&_value; - return check_cast(*(float *)&tmp); - } else if (typeid(T) == typeid(double) || typeid(T) == typeid(const double)) { - volatile uint64_t tmp = *(volatile uint64_t *)&_value; - return check_cast(*(double *)&tmp); - } else { - return check_cast(_value); - } - #else - return check_cast(_value); - #endif - } - - virtual Number& operator = ( bool b ){ - _value = check_cast(b); - return *this; - } - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( signed char i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( unsigned char i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( signed short i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( unsigned short i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( signed int i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( unsigned int i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用signed long long类型赋值 - * - * @param [in] val : signed long long - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( signed long long i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( unsigned long long i ){ - _value = check_cast(i); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( float f ){ - _value = check_cast(f); - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( double d ){ - _value = check_cast(d); - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( const char * cstr ){ - _value = check_cast(cstr); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Number& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Number& operator = ( const string_type& str ){ - _value = check_cast(str.c_str()); - return *this; - } - - //use default version for raw - using IVar::operator =; - - //testers - virtual bool is_number() const { - return true; - } - - virtual bool is_int8() const { - return typeid(T) == typeid(signed char); - } - - virtual bool is_uint8() const { - return typeid(T) == typeid(unsigned char); - } - - virtual bool is_int16() const { - return typeid(T) == typeid(signed short); - } - - virtual bool is_uint16() const { - return typeid(T) == typeid(unsigned short); - } - - virtual bool is_int32() const { - return typeid(T) == typeid(signed int); - } - - virtual bool is_uint32() const { - return typeid(T) == typeid(unsigned int); - } - - virtual bool is_int64() const { - return typeid(T) == typeid(signed long long); - } - - virtual bool is_uint64() const { - return typeid(T) == typeid(unsigned long long); - } - - virtual bool is_float() const { - return typeid(T) == typeid(float); - } - - virtual bool is_double() const { - return typeid(T) == typeid(double); - } - - private: - T _value; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_NUMBER_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/Ref.h b/bsl/var/implement/Ref.h deleted file mode 100644 index 35f982691cd2d90c9ad6f7dec8e9730755c12374..0000000000000000000000000000000000000000 --- a/bsl/var/implement/Ref.h +++ /dev/null @@ -1,755 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: Ref.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file Ref.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:30:35 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_REF_H__ -#define __BSL_VAR_REF_H__ - -#include "bsl/var/IRef.h" -#include "bsl/var/Null.h" - -namespace bsl{ -namespace var{ - class Ref: public IRef{ - public: - typedef IRef::string_type string_type; - typedef IRef::field_type field_type; - - //special methods - Ref( ) - :IRef(), _p(&Null::null) {} - - Ref( const Ref& other ) - :IRef(other), _p(other._p) { } - - Ref( IVar& var ) - :IRef(), _p(&var){ - if ( var.is_ref() ){ - IRef * __p = dynamic_cast(&var); - if ( NULL != __p ){ - //make a shortcut - _p = &__p->ref(); - } - } - } - - /** - * @brief Ref is a kind of "weak ref" which do nothing on destructor - * - * @see - * @author chenxm - * @date 2008/09/25 12:08:53 - **/ - ~Ref(){ - //pass - } - - Ref& operator = ( const Ref& other ){ - _p = other._p; - return *this; - } - - virtual IVar& ref() const { - return *_p; - } - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear() { - return _p->clear(); - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual IVar& clone( bsl::ResourcePool& rp ) const { - return _p->clone(rp); - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - **@param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual IVar& clone( bsl::ResourcePool& rp, bool is_deep_copy ) const { - return _p->clone(rp, is_deep_copy); - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t verbose_level = 0) const { - string_type res; - res.appendf("@%p: ", _p); - res.append(_p->dump(verbose_level)); - return res; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return _p->to_string(); - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - string_type res("bsl::var::Ref("); - res.append(_p->get_type()); - res.append(")"); - return res; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return IVar::IS_REF | _p->get_mask(); - } - - virtual Ref& operator = ( IVar& var ){ - if ( var.is_ref() ){ - IRef * __p = dynamic_cast(&var); - if ( NULL != __p ){ - //make a shortcut - _p = &__p->ref(); - }else{ - //unknown ref type - _p = &var; - } - }else{ - //non-ref value; - _p = &var; - } - return *this; - } - - - //methods for all, test methods - virtual bool is_null() const { - return _p->is_null(); - } - - virtual bool is_ref() const { - return true; - } - - virtual bool is_bool() const { - return _p->is_bool(); - } - - virtual bool is_number() const { - return _p->is_number(); - } - - virtual bool is_int8() const { - return _p->is_int8(); - } - - virtual bool is_uint8() const { - return _p->is_uint8(); - } - - virtual bool is_int16() const { - return _p->is_int16(); - } - - virtual bool is_uint16() const { - return _p->is_uint16(); - } - - virtual bool is_int32() const { - return _p->is_int32(); - } - - virtual bool is_uint32() const { - return _p->is_uint32(); - } - - virtual bool is_int64() const { - return _p->is_int64(); - } - - virtual bool is_uint64() const { - return _p->is_uint64(); - } - - virtual bool is_float() const { - return _p->is_float(); - } - - virtual bool is_double() const { - return _p->is_double(); - } - - /** - * @brief 判断是否是字符串类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:05:44 - **/ - virtual bool is_string() const { - return _p->is_string(); - } - - virtual bool is_array() const { - return _p->is_array(); - } - - virtual bool is_dict() const { - return _p->is_dict(); - } - - virtual bool is_callable() const { - return _p->is_callable(); - } - - virtual bool is_raw() const { - return _p->is_raw(); - } - - //methods for value - /** - * @brief 转化为布尔类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual bool to_bool() const { - return _p->to_bool(); - } - - /** - * @brief 转化为8位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed char to_int8() const { - return _p->to_int8(); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return _p->to_uint8(); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return _p->to_int16(); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return _p->to_uint16(); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return _p->to_int32(); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return _p->to_uint32(); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return _p->to_int64(); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return _p->to_uint64(); - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return _p->to_float(); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return _p->to_double(); - } - - virtual raw_type to_raw() const { - return _p->to_raw(); - } - - virtual Ref& operator = ( bool val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( signed char val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( unsigned char val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( signed short val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( unsigned short val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( signed int val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( unsigned int val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用signed long long类型赋值 - * - * @param [in] val : signed long long - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( signed long long val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( unsigned long long val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( float val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( double val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( const char *val ){ - _p->operator = ( val ); - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return Ref& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual Ref& operator = ( const string_type& val ){ - _p->operator = ( val ); - return *this; - } - - virtual Ref& operator = ( const raw_type& val ){ - _p->operator = ( val ); - return *this; - } - - //methods for string - virtual const char *c_str() const { - return _p->c_str(); - } - - virtual size_t c_str_len() const { - return _p->c_str_len(); - } - - //methods for array or dict - /** - * @brief 返回子元素个数(数组或字典)类型支持 - * - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:35:15 - **/ - virtual size_t size() const { - return _p->size(); - } - - //methods for array - virtual IVar& get( size_t index ) { - return _p->get(index); - } - - virtual IVar& get( size_t index, IVar& default_value ) { - return _p->get(index, default_value); - } - - virtual const IVar& get( size_t index ) const { - return _p->get(index); - } - - virtual const IVar& get( size_t index, const IVar& default_value ) const { - return _p->get(index,default_value); - } - - virtual void set( size_t index, IVar& value ){ - return _p->set( index, value ); - } - - virtual bool del( size_t index ){ - return _p->del(index); - } - - virtual array_const_iterator array_begin() const { - return const_cast(_p)->array_begin(); - } - - virtual array_iterator array_begin() { - return _p->array_begin(); - } - - virtual array_const_iterator array_end() const { - return const_cast(_p)->array_end(); - } - - virtual array_iterator array_end() { - return _p->array_end(); - } - - virtual const IVar& operator []( int index ) const { - return _p->operator [](index); - } - - virtual IVar& operator []( int index ){ - return _p->operator [](index); - } - - //methods for dict - virtual IVar& get( const field_type& name ) { - return _p->get(name); - } - - virtual IVar& get( const field_type& name, IVar& default_value ) { - return _p->get(name, default_value); - } - - virtual const IVar& get( const field_type& name ) const { - return _p->get(name); - } - - virtual const IVar& get( const field_type& name, const IVar& default_value ) const { - return _p->get(name, default_value); - } - - virtual void set( const field_type& name, IVar& value ){ - return _p->set(name, value); - } - - virtual bool del( const field_type& name ){ - return _p->del(name); - } - - virtual const IVar& operator []( const field_type& name ) const { - return _p->operator [](name); - } - - virtual IVar& operator []( const field_type& name ){ - return _p->operator []( name ); - } - - virtual dict_const_iterator dict_begin() const { - return const_cast(_p)->dict_begin(); - } - - virtual dict_iterator dict_begin() { - return _p->dict_begin(); - } - - virtual dict_const_iterator dict_end() const { - return const_cast(_p)->dict_end(); - } - - virtual dict_iterator dict_end() { - return _p->dict_end(); - } - - virtual IVar& operator()(IVar& param, bsl::ResourcePool& rp ){ - return (*_p)(param, rp); - } - - virtual IVar& operator()(IVar& self, IVar& param, bsl::ResourcePool& rp ){ - return (*_p)(self, param, rp); - } - private: - IVar * _p; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_REF_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/ShallowRaw.h b/bsl/var/implement/ShallowRaw.h deleted file mode 100644 index 1850643da566e696c072d999bda4fd15dc2cf4f2..0000000000000000000000000000000000000000 --- a/bsl/var/implement/ShallowRaw.h +++ /dev/null @@ -1,201 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ShallowRaw.h,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file ShallowRaw.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:53:41 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_SHALLOW_RAW_H__ -#define __BSL_VAR_SHALLOW_RAW_H__ -#include "bsl/var/IVar.h" - -namespace bsl{ -namespace var{ - /** - * @brief ShallowRaw是一种raw类型,但它只维护指针和长度,不维护数据本身,固名 - * - * - */ - class ShallowRaw: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - typedef IVar::raw_type raw_type; - - //special methods - ShallowRaw() - :_value(){} - - ShallowRaw( const ShallowRaw& other ) - :IVar(other), _value(other._value){ } - - explicit ShallowRaw( const raw_type& value_ ) - :IVar(), _value(value_){} - - ShallowRaw( const void *data_, size_t size_ ) - :IVar(), _value(data_, size_) {} - - virtual ~ShallowRaw(){ } - - ShallowRaw& operator = ( const ShallowRaw& other ){ - if ( this != &other ){ - _value = other._value; - } - return *this; - } - - //methods for all - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - _value.data = NULL; - _value.length = 0; - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return ShallowRaw& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual ShallowRaw& clone( bsl::ResourcePool& rp ) const { - return rp.clone(*this); - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - **@param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return ShallowRaw& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual ShallowRaw& clone( bsl::ResourcePool& rp, bool /*is_deep_copy*/ ) const { - return rp.clone(*this); - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type dump(size_t verbose_level = 0) const { - string_type res; - res.appendf("[bsl::var::ShallowRaw] data[%p] length[%zd]", _value.data, _value.length); - if ( _value.data != NULL && verbose_level > 0 ){ - res.append(" value["); - const char * bytes = static_cast(_value.data); - for( size_t i = 0; i < _value.length; ++ i){ - res.appendf("\\x%02hhx", bytes[i]); - } - res.append("]"); - } - return res; - } - - /** - * @brief 转化为字符串 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type to_string() const { - return dump(0); - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual string_type get_type() const { - return "bsl::var::ShallowRaw"; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { - return IVar::IS_RAW; - } - - virtual ShallowRaw& operator = ( IVar& other ){ - if ( this != &other ){ - _value = other.to_raw(); - } - return *this; - } - - virtual bool is_raw() const { - return true; - } - - //all other is_xxx() return false; - - //methods for raw - virtual ShallowRaw& operator = ( const raw_type& val ){ - _value = val; - return *this; - } - - virtual raw_type to_raw() const { - return _value; - } - - using IVar::operator =; - private: - raw_type _value; - }; - -}} //namespace bsl::var -#endif //__BSL_VAR_SHALLOW_RAW_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/ShallowString.h b/bsl/var/implement/ShallowString.h deleted file mode 100644 index 783ad094de992631ee095bd3e6d0144a925afd43..0000000000000000000000000000000000000000 --- a/bsl/var/implement/ShallowString.h +++ /dev/null @@ -1,406 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ShallowString.h,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file ShallowString.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:34:12 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_SHALLOW_STRING_H__ -#define __BSL_VAR_SHALLOW_STRING_H__ -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" -#include "bsl/ShallowCopyString.h" - -namespace bsl{ -namespace var{ - class ShallowString: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - - public: - //special methods - ShallowString( ) - : _value() {} - - ShallowString( const ShallowString& other ) - : IVar(other), _value(other._value) { } - - ShallowString( const char * cstr ) - : IVar(), _value(cstr) { } - - ShallowString( const char * cstr, size_t len ) - : IVar(), _value(cstr, len) { } - - ShallowString( const bsl::ShallowCopyString& value_) - : IVar(), _value( value_.c_str(), value_.size() ) { } - - - ShallowString( const string_type& value_ ) - : IVar(), _value(value_.c_str(), value_.size()){} - - ShallowString& operator = ( const ShallowString& other ){ - _value = other._value; - return *this; - } - - virtual ~ShallowString(){ - //pass - } - - //methods for all - virtual ShallowString& operator = ( IVar& var ){ - if ( var.is_string() ){ - _value = var.c_str(); - return *this; - }else{ - throw bsl::InvalidOperationException()<(_value.c_str()); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return ShallowString& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual ShallowString& operator = ( const char * cstr ){ - _value = cstr; - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const string_type& - * @return ShallowString& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual ShallowString& operator = ( const string_type& str ){ - _value = str; - return *this; - } - - //use default version for bool、raw、number - using IVar::operator =; - - /** - * @brief 返回C风格字符串表示 - * - * 所有is_string()返回true的IVar实现类都必须支持该方法。 - * 若实现类不支持该操作,抛出bsl::InvalidOperationException异常 - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/04/22 18:41:19 - **/ - virtual const char * c_str() const { - return _value.c_str(); - } - - /** - * @brief 返回C风格字符串表示的长度,不包括末尾的'\0' - * - * 所有is_string()返回true的IVar实现类都必须支持该方法。 - * 若实现类不支持该操作,抛出bsl::InvalidOperationException异常 - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/04/22 18:41:54 - **/ - virtual size_t c_str_len() const { - return _value.size(); - } - - private: - bsl::ShallowCopyString _value; - }; - -}}//namespace bsl::var - -#endif //__BSL_VAR_SHALLOW_STRING_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/String.h b/bsl/var/implement/String.h deleted file mode 100644 index ce24e3f65ecce3f3d42b9cadc63b64d9686464d3..0000000000000000000000000000000000000000 --- a/bsl/var/implement/String.h +++ /dev/null @@ -1,698 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: String.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file String.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:34:12 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_STRING_H__ -#define __BSL_VAR_STRING_H__ -#include "bsl/var/IVar.h" -#include "bsl/var/Ref.h" -#include "bsl/check_cast.h" -#include "bsl/pool/bsl_pool.h" -#include "bsl/pool/bsl_poolalloc.h" -#include "BigInt.h" - -namespace bsl{ -namespace var{ - - // forward declarations & typedefs - template - class BasicString; - - - /** - * @brief 封装了IVar::string_type(bsl::string) - * - **/ - typedef BasicString String; - - /** - * @brief var::String字符串类,与var::Dict保持类似的接口 - * implement_t为BasicString内部实现 - * - **/ - template - class BasicString: public IVar{ - public: - - /** - * @brief Var::String的string类型 - * - **/ - typedef IVar::string_type string_type; - /** - * @brief var::String的字段类型 - * - **/ - typedef IVar::field_type field_type; - /** - * @brief 得到实现类的allocator - * - **/ - typedef typename implement_t::allocator_type allocator_type; - - public: - //special methods - BasicString( ): _value() {} - - /** - * @brief 复制构造函数 - * - * @param [in] other : BasicString& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 18:33:34 - **/ - BasicString( const BasicString& other ) - :IVar(other), _value(other._value) { } - - /** - * @brief 带allocator的构造函数 - * - * @param [in] alloc_ : const allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 18:21:44 - **/ - explicit BasicString( const allocator_type& alloc_ ): _value( alloc_ ) {} - - /** - * @brief 传入字符串和allocator的构造函数 - * - * @param [in] cstr : const char* - * @param [in] alloc_ : const allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 19:41:24 - **/ - BasicString( const char * cstr, const allocator_type& alloc_ = allocator_type() ) - : _value(cstr,alloc_) { } - - /** - * @brief 传入字符串和长度和allocator的构造函数 - * - * @param [in] cstr : const char* - * @param [in] len : size_t - * @param [in] alloc_ : const allocator_type& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 19:42:19 - **/ - BasicString( - const char *cstr, size_t len, - const allocator_type& alloc_ = allocator_type() - ) - : _value(cstr, len, alloc_) {} - - /** - * @brief 与复制构造函数不同,value_是implement_t类型 - * - * @param [in] value_ : implement_t& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 18:35:10 - **/ - BasicString( const implement_t& value_ ): _value(value_){} - - /** - * @brief 重载operator=运算符 - * - * @parami [in] other : const BasicString& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 19:43:45 - **/ - BasicString& operator = ( const BasicString& other ){ - _value = other._value; - return *this; - } - - virtual ~BasicString(){ - //pass - } - - /** - * @brief IVar所有派生类都必须实现的接口 - * - * @param [in] var : IVar& - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 19:49:54 - **/ - //methods for all - virtual BasicString& operator = ( IVar& var ){ - _value = var.to_string(); - return *this; - } - - /** - * @brief 输出调试信息(仅用于调试)可通过verbose_level控制递归层数 - * - * @return implement_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual implement_t dump(size_t /*verbose_level*/=0) const { - return implement_t("[bsl::var::String]").append(_value); - } - - /** - * @brief 转化为字符串 - * - * @return implement_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual implement_t to_string() const { - return _value; - } - - /** - * @brief 获取类型字符串(所有var类型都支持,仅用于调试使用,勿用于类型判断) - * - * @return implement_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual implement_t get_type() const { - return "bsl::var::String"; - } - - /** - * @brief 获取类型掩码(所有var类型都支持) - * - * @return IVar::mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:44:20 - **/ - virtual IVar::mask_type get_mask() const { -#ifdef PHP_COMLOG - return IVar::_IS_STRING; -#else - return IVar::IS_STRING; -#endif - } - - /** - * @brief 清理函数 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:48:46 - **/ - virtual void clear(){ - _value.clear(); - } - - /** - * @brief 克隆函数 - * - * 该函数只克隆本身结点,不克隆子结点,对引用类型,克隆指向的结点 - * - * @param [in] rp : bsl::ResourcePool& - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 - **/ - virtual BasicString& clone( bsl::ResourcePool& rp ) const { - return rp.clone(*this); - } - - /** - * @brief 克隆函数 - * - * 由is_deep_copy参数控制是否深复制 - * 若为false, 只克隆本身结点,不克隆子结点 - * 若为true, 克隆本身结点,并且递归克隆子结点 - * 对引用类型,克隆指向的结点 - * - **@param [in] rp : bsl::ResourcePool& - * @param [in] is_deep_copy : bool - * @return BasicString& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:58:07 / modified by zhujianwei at 2011/03/22 - **/ - virtual BasicString& clone( bsl::ResourcePool& rp, bool /*is_deep_copy*/ ) const { - return rp.clone(*this); - } - - //testers - /** - * @brief 判断是否是字符串类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:05:44 - **/ - virtual bool is_string() const { - return true; - } - - //methods for value - /** - * @brief 转化为布尔类型 - * - * @return bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual bool to_bool() const { - return _value.c_str()[0] != '\0'; - } - - /** - * @brief 转化为8位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed char to_int8() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为8位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned char - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned char to_uint8() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为16位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed short to_int16() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为16位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned short - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned short to_uint16() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为32位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed int to_int32() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为32位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned int - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned int to_uint32() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为64位有符号整数类型(所有is_number()返回真的类型都支持) - * - * @return signed long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual signed long long to_int64() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为64位无符号整数类型(所有is_number()返回真的类型都支持) - * - * @return unsigned long long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual unsigned long long to_uint64() const { - return check_cast(_value.c_str()); - } - - /** - * @brief conversion to bigint, not a virtual function derived - * - * @tparam bits - * - * @return - * - * @version 1.1.24 - * @author linjieqiong - * @date 2013/07/25 15:51:13 - */ - template - BigInt to_bigint() { - BigInt tmp = _value; - return tmp; - } - - /** - * @brief 转化为单精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual float to_float() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为双精度浮点数类型(所有is_number()返回真的类型都支持) - * - * @return double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 18:09:14 - **/ - virtual double to_double() const { - return check_cast(_value.c_str()); - } - - /** - * @brief 转化为布尔类型 - * - * @param - * @return - * @retval - * @see - * @author liaoshangbin - * @data 2010/08/09 19:52:26 - **/ - virtual BasicString& operator = ( bool b ){ - if ( b ){ - _value = "true"; - }else{ - _value = "false"; - } - return *this; - } - - /** - * @brief 使用signed char类型赋值 - * - * @param [in] val : signed char - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( signed char val ){ - _value.setf( "%hhd", val ); - return *this; - } - - /** - * @brief 使用unsigned char类型赋值 - * - * @param [in] val : unsigned char - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( unsigned char val ){ - _value.setf( "%hhu", val ); - return *this; - } - /** - * @brief 使用signed short类型赋值 - * - * @param [in] val : signed short - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( signed short val ){ - _value.setf( "%hd", val ); - return *this; - } - /** - * @brief 使用unsigned short类型赋值 - * - * @param [in] val : unsigned short - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( unsigned short val ){ - _value.setf( "%hu", val ); - return *this; - } - /** - * @brief 使用signed int类型赋值 - * - * @param [in] val : signed int - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( signed int val ){ - _value.setf( "%d", val ); - return *this; - } - /** - * @brief 使用unsigned int类型赋值 - * - * @param [in] val : unsigned int - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( unsigned int val ){ - _value.setf( "%u", val ); - return *this; - } - /** - * @brief 使用signed long long类型赋值 - * - * @param [in] val : signed long long - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( signed long long val ){ - _value.setf( "%lld", val ); - return *this; - } - /** - * @brief 使用unsigned long long类型赋值 - * - * @param [in] val : unsigned long long - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( unsigned long long val ){ - _value.setf( "%llu", val ); - return *this; - } - - template - BasicString& operator = ( BigInt val){ - _value = val.to_string(); - return *this; - } - - /** - * @brief 使用float类型赋值 - * - * @param [in] val : float - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( float f ){ - _value.setf( "%f", f ); - return *this; - } - - /** - * @brief 使用double类型赋值 - * - * @param [in] val : double - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( double d ){ - _value.setf( "%lf", d ); - return *this; - } - - /** - * @brief 使用const char *类型赋值 - * - * @param [in] val : const char * - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( const char * cstr ){ - _value = cstr; - return *this; - } - - /** - * @brief 使用字符串类型赋值 - * - * @param [in] val : const implement_t& - * @return String& - * @retval - * @see - * @author chenxm - * @date 2010/03/17 19:23:16 - **/ - virtual BasicString& operator = ( const implement_t& str ){ - _value = str; - return *this; - } - - //use default version for bool、raw - using IVar::operator =; - - /** - * @brief 返回C风格字符串表示 - * - * 所有is_string()返回true的IVar实现类都必须支持该方法。 - * 若实现类不支持该操作,抛出bsl::InvalidOperationException异常 - * @return const char* - * @retval - * @see - * @author chenxm - * @date 2009/04/22 18:41:19 - **/ - virtual const char * c_str() const { - return _value.c_str(); - } - - /** - * @brief 返回C风格字符串表示的长度,不包括末尾的'\0' - * - * 所有is_string()返回true的IVar实现类都必须支持该方法。 - * 若实现类不支持该操作,抛出bsl::InvalidOperationException异常 - * @return size_t - * @retval - * @see - * @author chenxm - * @date 2009/04/22 18:41:54 - **/ - virtual size_t c_str_len() const { - return _value.size(); - } - - private: - /** - * BaseString内部封装的string类型 - * - **/ - implement_t _value; - }; - -}}//namespace bsl::var - -#endif //__BSL_VAR_STRING_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/implement/implement.h b/bsl/var/implement/implement.h deleted file mode 100644 index a40094103677d4642e1077f66ca2ad3bdccbe507..0000000000000000000000000000000000000000 --- a/bsl/var/implement/implement.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: implement.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file implement.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/01/09 18:19:10 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_IMPLEMENT_H__ -#define __BSL_VAR_IMPLEMENT_H__ -#include "bsl/var/Null.h" -#include "bsl/var/Ref.h" -#include "bsl/var/Bool.h" -#include "bsl/var/Int32.h" -#include "bsl/var/Int64.h" -#include "bsl/var/BigInt.h" -#include "bsl/var/Double.h" -#include "bsl/var/Number.h" -#include "bsl/var/String.h" -#include "bsl/var/ShallowString.h" -#include "bsl/var/ShallowRaw.h" -#include "bsl/var/Array.h" -#include "bsl/var/Dict.h" -#include "bsl/var/Function.h" -#include "bsl/var/Method.h" -#include "bsl/var/MagicArray.h" -#include "bsl/var/MagicDict.h" -#include "bsl/var/MagicRef.h" - -#endif //__BSL_VAR_IMPLEMENT_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/ArrayIterator.h b/bsl/var/interface/ArrayIterator.h deleted file mode 100644 index c030937b4522846d4863200f24674276b3e215b2..0000000000000000000000000000000000000000 --- a/bsl/var/interface/ArrayIterator.h +++ /dev/null @@ -1,192 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ArrayIterator.h,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file ArrayIterator.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 11:00:45 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_ARRAY_ITERATOR_H__ -#define __BSL_VAR_ARRAY_ITERATOR_H__ -namespace bsl{ -namespace var{ - //forward declaration - class IVar; - class IArrayConstIteratorImpl; - class IArrayIteratorImpl; - class ArrayConstIterator; - class ArrayIterator; - - //interface definition - class IArrayIteratorImpl{ - public: - typedef IArrayIteratorImpl implement_type; - typedef IArrayConstIteratorImpl const_implement_type; - - IArrayIteratorImpl(){} - IArrayIteratorImpl( const IArrayIteratorImpl& ) {} - - virtual ~IArrayIteratorImpl() {} - virtual size_t key() const = 0; - virtual IVar& value() const = 0; - - virtual void assign( const implement_type& ) = 0; - virtual bool equal_to( const implement_type& ) const = 0; - virtual bool equal_to( const const_implement_type& ) const = 0; - virtual void iterate() = 0; - }; - - class IArrayConstIteratorImpl{ - public: - typedef IArrayIteratorImpl implement_type; - typedef IArrayConstIteratorImpl const_implement_type; - - IArrayConstIteratorImpl(){} - IArrayConstIteratorImpl( const IArrayConstIteratorImpl& ){} - - virtual ~IArrayConstIteratorImpl() {} - virtual size_t key() const = 0; - virtual const IVar& value() const = 0; - - virtual void assign( const implement_type& ) = 0; - virtual void assign( const const_implement_type& ) = 0; - virtual bool equal_to( const implement_type& ) const = 0; - virtual bool equal_to( const const_implement_type& ) const = 0; - virtual void iterate() = 0; - }; - - //iterator defintion - class ArrayIterator{ - public: - typedef ArrayIterator iterator_type; - typedef ArrayConstIterator const_iterator_type; - typedef IArrayIteratorImpl implement_type; - typedef IArrayConstIteratorImpl const_implement_type; - typedef implement_type *(* cloner_type )( const implement_type * ); - typedef void (* destroyer_type )( implement_type * ); - - ArrayIterator( implement_type * p_impl, cloner_type cloner, destroyer_type destroyer ) - :_p_impl(p_impl), _cloner(cloner), _destroyer(destroyer) {} - - ArrayIterator( const ArrayIterator& other ) - :_p_impl( other._cloner(other._p_impl) ), _cloner(other._cloner), _destroyer(other._destroyer) { } - - ~ArrayIterator(){ - _destroyer( _p_impl ); - } - - ArrayIterator& operator = ( const ArrayIterator& other ){ - _p_impl->assign( *other._p_impl ); - return *this; - } - - const implement_type* operator ->() const { - return _p_impl; - } - - const implement_type& operator *() const { - return *_p_impl; - } - - ArrayIterator& operator ++(){ - _p_impl->iterate(); - return *this; - } - - private: - implement_type *_p_impl; - cloner_type _cloner; - destroyer_type _destroyer; - }; - - class ArrayConstIterator{ - public: - typedef ArrayIterator iterator_type; - typedef ArrayConstIterator const_iterator_type; - typedef IArrayIteratorImpl implement_type; - typedef IArrayConstIteratorImpl const_implement_type; - typedef const_implement_type *(* cloner_type )( const const_implement_type * ); - typedef void (* destroyer_type )( const_implement_type * ); - - ArrayConstIterator( const_implement_type * p_impl, cloner_type cloner, destroyer_type destroyer ) - :_p_impl(p_impl), _cloner(cloner), _destroyer(destroyer) {} - - ArrayConstIterator( const ArrayConstIterator& other ) - :_p_impl( other._cloner(other._p_impl) ), _cloner(other._cloner), _destroyer(other._destroyer) { } - - ~ArrayConstIterator(){ - _destroyer( _p_impl ); - } - - ArrayConstIterator& operator = ( const ArrayConstIterator& other ){ - _p_impl->assign( *other._p_impl ); - return *this; - } - - const const_implement_type* operator ->() const { - return _p_impl; - } - - const const_implement_type& operator *() const { - return *_p_impl; - } - - ArrayConstIterator& operator ++(){ - _p_impl->iterate(); - return *this; - } - - private: - const_implement_type *_p_impl; - cloner_type _cloner; - destroyer_type _destroyer; - }; - - inline bool operator == ( const ArrayConstIterator& i, const ArrayConstIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const ArrayConstIterator& i, const ArrayIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const ArrayIterator& i, const ArrayConstIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const ArrayIterator& i, const ArrayIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator != ( const ArrayConstIterator& i, const ArrayConstIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const ArrayConstIterator& i, const ArrayIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const ArrayIterator& i, const ArrayConstIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const ArrayIterator& i, const ArrayIterator & j ) { - return !i->equal_to(*j); - } - - -}} //namespace var - - -#endif //__BSL_VAR_ARRAY_ITERATOR_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/BCLOUD b/bsl/var/interface/BCLOUD deleted file mode 100644 index 484f6d1c778d7e378a58967c537c403bf6847376..0000000000000000000000000000000000000000 --- a/bsl/var/interface/BCLOUD +++ /dev/null @@ -1,55 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../../') - -#Preprocessor flags. -#CPPFLAGS(r'-D_GNU_SOURCE -D__STDC_LIMIT_MACROS') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -#CXXFLAGS(' -g -pipe -W -Wall -fPIC') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -#INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libinterface.a') -#LIBS('$OUT/so/libinterface.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -#user_sources=GLOB("*.c *.cpp *.cc *.idl") - -#release headers -HEADERS('ArrayIterator.h DictIterator.h IBinaryDeserializer.h IBinarySerializer.h IRef.h ITextDeserializer.h ITextSerializer.h IVar.h', '$INC/bsl/var') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') -#.a -#StaticLibrary('interface', Sources(user_sources)) -#StaticLibrary('interface', PreBuilt(True)) - -#.so -#SharedLibrary('interface', Sources(user_sources)) -#SharedLibrary('interface', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/var/interface/CMakeLists.txt b/bsl/var/interface/CMakeLists.txt deleted file mode 100644 index 18f1dd6d2877fda91b41b9532a44301078cd4f0d..0000000000000000000000000000000000000000 --- a/bsl/var/interface/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_custom_target(interface) diff --git a/bsl/var/interface/DictIterator.h b/bsl/var/interface/DictIterator.h deleted file mode 100644 index 6dfda11d1b5abedb5469b789b2c4e79fd9439395..0000000000000000000000000000000000000000 --- a/bsl/var/interface/DictIterator.h +++ /dev/null @@ -1,317 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: DictIterator.h,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file DictIterator.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 11:01:13 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_DICT_ITERATOR_H__ -#define __BSL_VAR_DICT_ITERATOR_H__ - -#include "bsl/containers/string/bsl_string.h" -namespace bsl{ -namespace var{ - //forward declaration - class IVar; - class IDictConstIteratorImpl; - class IDictIteratorImpl; - class DictConstIterator; - class DictIterator; - - //interface definition - class IDictIteratorImpl{ - public: - typedef bsl::string string_type; - typedef IDictIteratorImpl implement_type; - typedef IDictConstIteratorImpl const_implement_type; - - virtual ~IDictIteratorImpl() {} - virtual const string_type& key() const = 0; - virtual IVar& value() const = 0; - - virtual void assign( const implement_type& ) = 0; - virtual bool equal_to( const implement_type& ) const = 0; - virtual bool equal_to( const const_implement_type& ) const = 0; - virtual void iterate() = 0; - }; - - class IDictConstIteratorImpl{ - public: - typedef bsl::string string_type; - typedef IDictIteratorImpl implement_type; - typedef IDictConstIteratorImpl const_implement_type; - - virtual ~IDictConstIteratorImpl() {} - virtual const string_type& key() const = 0; - virtual const IVar& value() const = 0; - - virtual void assign( const implement_type& ) = 0; - virtual void assign( const const_implement_type& ) = 0; - virtual bool equal_to( const implement_type& ) const = 0; - virtual bool equal_to( const const_implement_type& ) const = 0; - virtual void iterate() = 0; - }; - - //iterator defintion - class DictIterator{ - public: - typedef DictIterator iterator_type; - typedef DictConstIterator const_iterator_type; - typedef IDictIteratorImpl implement_type; - typedef IDictConstIteratorImpl const_implement_type; - typedef implement_type *(* cloner_type )( const implement_type *, const void * ); - typedef void (* destroyer_type )( implement_type *, const void * ); - - /** - * @brief 构造函数 - * - * @param [in] p_impl : implement_type* 实现类型 - * @param [in] cloner : cloner_type 复制函数指针 - * @param [in] destroyer : destroyer_type 销毁函数指针 - * @param [in] p_alloc : void* 内存分配器指针 - * @see - * @author chenxm - * @date 2009/04/07 21:15:55 - **/ - DictIterator( implement_type * p_impl, cloner_type cloner, destroyer_type destroyer, const void *p_alloc ) - :_p_impl(p_impl), _cloner(cloner), _destroyer(destroyer), _p_alloc(p_alloc) {} - - /** - * @brief 复制构造函数 - * - * @param [in] other : const DictIterator& - * @see - * @author chenxm - * @date 2009/04/07 21:17:16 - **/ - DictIterator( const DictIterator& other ) - :_p_impl(other._cloner(other._p_impl, other._p_alloc) ), _cloner(other._cloner), _destroyer(other._destroyer), _p_alloc(other._p_alloc) {} - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/04/07 21:17:23 - **/ - ~DictIterator(){ - _destroyer( _p_impl, _p_alloc ); - } - - /** - * @brief 赋值运算符 - * - * @param [in] other : const DictIterator& - * @return DictIterator& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:18:14 - **/ - DictIterator& operator = ( const DictIterator& other ){ - _p_impl->assign( *other._p_impl ); - return *this; - } - - /** - * @brief ->运算符重载 - * - * @return const implement_type* - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:18:23 - **/ - const implement_type* operator ->() const { - return _p_impl; - } - - /** - * @brief *运算符重载 - * - * @return const implement_type* - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:18:23 - **/ - const implement_type& operator *() const { - return *_p_impl; - } - - /** - * @brief 前缀++运算符重载 - * - * @return DictIterator& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:19:28 - **/ - DictIterator& operator ++(){ - _p_impl->iterate(); - return *this; - } - - private: - implement_type *_p_impl; - cloner_type _cloner; - destroyer_type _destroyer; - const void *_p_alloc; - }; - - class DictConstIterator{ - public: - typedef DictIterator iterator_type; - typedef DictConstIterator const_iterator_type; - typedef IDictIteratorImpl implement_type; - typedef IDictConstIteratorImpl const_implement_type; - typedef const_implement_type *(* cloner_type )( const const_implement_type *, const void * ); - typedef void (* destroyer_type )( const_implement_type *, const void * ); - - /** - * @brief 构造函数 - * - * @param [in] p_impl : const_implement_type* - * @param [in] cloner : cloner_type - * @param [in] destroyer : destroyer_type - * @param [in] p_alloc : void* - * @see - * @author chenxm - * @date 2009/04/07 21:20:51 - **/ - DictConstIterator( const_implement_type * p_impl, cloner_type cloner, destroyer_type destroyer, const void *p_alloc ) - :_p_impl(p_impl), _cloner(cloner), _destroyer(destroyer), _p_alloc(p_alloc) {} - - /** - * @brief 复制构造函数 - * - * @param [in] other : const DictConstIterator& - * @see - * @author chenxm - * @date 2009/04/07 21:20:58 - **/ - DictConstIterator( const DictConstIterator& other ) - :_p_impl(other._cloner(other._p_impl, other._p_alloc) ), _cloner(other._cloner), _destroyer(other._destroyer), _p_alloc(other._p_alloc) {} - - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/04/07 21:21:12 - **/ - ~DictConstIterator(){ - _destroyer( _p_impl, _p_alloc ); - } - - /** - * @brief 赋值运算符 - * - * @param [in] other : const DictConstIterator& - * @return DictConstIterator& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:21:25 - **/ - DictConstIterator& operator = ( const DictConstIterator& other ){ - _p_impl->assign( *other._p_impl ); - return *this; - } - - /** - * @brief ->运算符重载 - * - * @return const const_implement_type* - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:21:36 - **/ - const const_implement_type* operator ->() const { - return _p_impl; - } - - /** - * @brief *运算符重载 - * - * @return const const_implement_type& - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:21:36 - **/ - const const_implement_type& operator *() const { - return *_p_impl; - } - - /** - * @brief 前缀++运算符重载 - * - * @return DictConstIterator& operator - * @retval - * @see - * @author chenxm - * @date 2009/04/07 21:22:46 - **/ - DictConstIterator& operator ++(){ - _p_impl->iterate(); - return *this; - } - - private: - const_implement_type *_p_impl; - cloner_type _cloner; - destroyer_type _destroyer; - const void *_p_alloc; - }; - - inline bool operator == ( const DictConstIterator& i, const DictConstIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const DictConstIterator& i, const DictIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const DictIterator& i, const DictConstIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator == ( const DictIterator& i, const DictIterator & j ) { - return i->equal_to(*j); - } - - inline bool operator != ( const DictConstIterator& i, const DictConstIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const DictConstIterator& i, const DictIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const DictIterator& i, const DictConstIterator & j ) { - return !i->equal_to(*j); - } - - inline bool operator != ( const DictIterator& i, const DictIterator & j ) { - return !i->equal_to(*j); - } - - -}} //namespace bsl::var - -#endif //__BSL_VAR_DICT_ITERATOR_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/IBinaryDeserializer.h b/bsl/var/interface/IBinaryDeserializer.h deleted file mode 100644 index 51a4d72f94e61a9790ffb3e49887463b98975ee4..0000000000000000000000000000000000000000 --- a/bsl/var/interface/IBinaryDeserializer.h +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: IBinaryDeserializer.h,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file IBinaryDeserializer.h - * @author duchuanying(duchuanying@baidu.com) - * @date 2008/11/01 21:37:08 - * @version $Revision: 1.3 $ - * @brief mcpack -> IVar - * - **/ - - -#ifndef __BSL_VAR_IBINARY_DESERIALIZER_H__ -#define __BSL_VAR_IBINARY_DESERIALIZER_H__ - -#include -#include -#include - -namespace bsl{ -namespace var{ - -class IBinaryDeserializer{ -public: - virtual ~IBinaryDeserializer(){} - - /** - * @brief 反序列化buffer为Var对象 - * - * 默认实现,如无特殊需要,子类不必重写该函数。 - * - * @param [in] buf : const void* - * @param [in] max_size : size_t - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/12/02 16:58:09 - **/ - virtual IVar& deserialize(const void* buf, size_t max_size){ - size_t res = try_deserialize( buf, max_size ); - if ( res > max_size ){ - throw bsl::OutOfBoundException()<="< -namespace bsl{ namespace var { - class IRef: public IVar{ - public: - typedef IVar::string_type string_type; - typedef IVar::field_type field_type; - virtual IVar& ref() const = 0; - using IVar::operator=; - }; //end of class -}}//end of namespace - - -#endif //__BSL_VAR__IREF_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/ITextDeserializer.h b/bsl/var/interface/ITextDeserializer.h deleted file mode 100644 index d6a803df2f002a7ac98abda2e8217f449bda5d06..0000000000000000000000000000000000000000 --- a/bsl/var/interface/ITextDeserializer.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ITextDeserializer.h,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file ITextDeserializer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/10/07 21:16:20 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_ITEXT_DESERIALIZER_H__ -#define __BSL_VAR_ITEXT_DESERIALIZER_H__ - -#include -#include -#include -namespace bsl{ -namespace var{ - - class ITextDeserializer{ - public: - virtual ~ITextDeserializer(){} - virtual IVar& deserialize(const char* text) = 0; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_ITEXT_DESERIALIZER_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/ITextSerializer.h b/bsl/var/interface/ITextSerializer.h deleted file mode 100644 index e74331981a9170f3ecc464c42964a1e4f902d2b1..0000000000000000000000000000000000000000 --- a/bsl/var/interface/ITextSerializer.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ITextSerializer.h,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file ITextSerializer.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/10/07 21:16:20 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __BSL_VAR_ITEXT_SERIALIZER_H__ -#define __BSL_VAR_ITEXT_SERIALIZER_H__ - -#include -#include - -namespace bsl{ -namespace var{ - - class ITextSerializer{ - public: - virtual ~ITextSerializer(){} - virtual void serialize(const IVar& var, bsl::AutoBuffer& buf) = 0; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_ITEXT_SERIALIZER_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/IVar.h b/bsl/var/interface/IVar.h deleted file mode 100644 index 224000f59e9473e2be09c4a7475dffed242ef428..0000000000000000000000000000000000000000 --- a/bsl/var/interface/IVar.h +++ /dev/null @@ -1,1813 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: IVar.h,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file IVar.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:29:15 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#ifndef __BSL_VAR_IVAR_H__ -#define __BSL_VAR_IVAR_H__ - -#include "bsl/containers/string/bsl_string.h" -#include "bsl/exception/bsl_exception.h" -#include "bsl/ResourcePool.h" -#include "bsl/var/ArrayIterator.h" -#include "bsl/var/DictIterator.h" - -namespace bsl{ -namespace var{ - - /** - * @brief 为IVar支持无类型二进制数据而定义的结构体 - * - * 相当于头指针与长度的简单集合,析构时不会回收data所指内存。 - */ - struct raw_t{ - /** - * @brief 二进制数据头指针 - * - * - */ - const void *data; - /** - * @brief 二进制数据长度  - * - * - */ - size_t length; - - /** - * @brief 默认构造函数 - * - * @see - * @author chenxm - * @date 2010/03/17 16:46:28 - **/ - raw_t() - :data(NULL), length(0) {} - /** - * @brief 常用的构造函数 - * - * @param [in] data_ : const void* - * @param [in] len : size_t - * @see - * @author chenxm - * @date 2010/03/17 16:46:41 - **/ - raw_t( const void *data_, size_t len) - :data(data_), length(len) {} - }; - - //forward declaration - class IVar{ - public: - /** - * @brief 字符串类型 - * - * - */ - typedef bsl::string string_type; - - /** - * @brief 字段名类型 - * - * - */ - typedef bsl::string field_type; - - /** - * @brief 无类型二进制数据类型 - * - * - */ - typedef raw_t raw_type; - - /** - * @brief 数组迭代器类型 - * - * - */ - typedef ArrayIterator array_iterator; - - /** - * @brief 只读数组迭代器类型 - * - * - */ - typedef ArrayConstIterator array_const_iterator; - - /** - * @brief 字典迭代器类型 - * - * - */ - typedef DictIterator dict_iterator; - - /** - * @brief 只读字典迭代器类型 - * - * - */ - typedef DictConstIterator dict_const_iterator; - - /** - * @brief 掩码类型 - * - * - */ - typedef unsigned int mask_type; - - // constant definition -#ifdef PHP_COMLOG - static const mask_type _IS_BOOL = 1 << 0; /**< 是否布尔类型 */ - static const mask_type IS_NUMBER = 1 << 1; /**< 是否数值类型 */ - static const mask_type _IS_STRING = 1 << 2; /**< 是否字符串类型 */ - static const mask_type IS_RAW = 1 << 3; /**< 是否二进制类型 */ - static const mask_type _IS_ARRAY = 1 << 4; /**< 是否数组类型 */ - static const mask_type IS_DICT = 1 << 5; /**< 是否字典类型 */ - static const mask_type IS_CALLABLE = 1 << 6; /**< 是否可调用类型 */ - static const mask_type IS_OTHER = 1 << 7; /**< 是否其它类型 */ - static const mask_type IS_REF = 1 << 8; /**< 是否引用类型 */ - static const mask_type IS_MUTABLE = 1 << 9; /**< 是否可变类型 */ - static const mask_type IS_FLOATING = 1 << 10; /**< 是否浮点类型 */ - static const mask_type IS_SIGNED = 1 << 11; /**< 是否有符号类型 */ - static const mask_type IS_ONE_BYTE = 1 << 12; /**< 是否单字节类型 */ - static const mask_type IS_TWO_BYTE = 1 << 13; /**< 是否双字节类型 */ - static const mask_type IS_FOUR_BYTE = 1 << 14; /**< 是否四字节类型 */ - static const mask_type IS_EIGHT_BYTE = 1 << 15; /**< 是否八字节类型 */ - static const mask_type IS_BIG_INT = 1 << 16; /**< 是否大整数类型 */ - static const mask_type NONE_MASK = 0; /**< 空掩码 */ - static const mask_type ALL_MASK = ~0; /**< 满掩码 */ -#else - static const mask_type IS_BOOL = 1 << 0; /**< 是否布尔类型 */ - static const mask_type IS_NUMBER = 1 << 1; /**< 是否数值类型 */ - static const mask_type IS_STRING = 1 << 2; /**< 是否字符串类型 */ - static const mask_type IS_RAW = 1 << 3; /**< 是否二进制类型 */ - static const mask_type IS_ARRAY = 1 << 4; /**< 是否数组类型 */ - static const mask_type IS_DICT = 1 << 5; /**< 是否字典类型 */ - static const mask_type IS_CALLABLE = 1 << 6; /**< 是否可调用类型 */ - static const mask_type IS_OTHER = 1 << 7; /**< 是否其它类型 */ - static const mask_type IS_REF = 1 << 8; /**< 是否引用类型 */ - static const mask_type IS_MUTABLE = 1 << 9; /**< 是否可变类型 */ - static const mask_type IS_FLOATING = 1 << 10; /**< 是否浮点类型 */ - static const mask_type IS_SIGNED = 1 << 11; /**< 是否有符号类型 */ - static const mask_type IS_ONE_BYTE = 1 << 12; /**< 是否单字节类型 */ - static const mask_type IS_TWO_BYTE = 1 << 13; /**< 是否双字节类型 */ - static const mask_type IS_FOUR_BYTE = 1 << 14; /**< 是否四字节类型 */ - static const mask_type IS_EIGHT_BYTE = 1 << 15; /**< 是否八字节类型 */ - static const mask_type IS_BIG_INT = 1 << 16; /**< 是否大整数类型 */ - static const mask_type NONE_MASK = 0; /**< 空掩码 */ - static const mask_type ALL_MASK = ~0; /**< 满掩码 */ -#endif - - //methods for all - /** - * @brief 析构函数 - * - * @see - * @author chenxm - * @date 2009/02/04 18:49:09 - **/ - virtual ~IVar(){ } - - /** - * @brief 赋值运算符 - * - * 所有IVar实现类都必须支持该方法。 - * - * @return IVar& operator - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:49:21 - **/ - virtual IVar& operator = ( IVar& ) = 0; - - /** - * @brief 打印重要的内部状态,及其子IVar对象的状态 - * - * 所有IVar实现类都必须支持该方法。 - * 该方法仅用于调试与跟踪,其内容应该容易被肉眼识别。其格式可能经常变化,不应对其内容进行监控。 - * - * 可选的verbose_level参数表示递归深度。0表示不递归子IVar对象,实现类应保证该函数算法复杂度为O(1);1表示递归所有直接子IVar对象,实现类应保证该函数算法复杂度为O(size()),余类推。 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:51:26 - **/ - virtual string_type dump(size_t verbose_level=0) const = 0; - - /** - * @brief 清空函数 - * - * 所有IVar实现类都必须支持该方法。 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:51:06 - **/ - virtual void clear() = 0; - - /** - * @brief 转化为字符串。 - * - * 所有IVar实现类都必须支持该方法。 - * 自BSL 1.0.5后,该函数只用于转化为字符串,调试/跟踪应使用dump() - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:51:26 - **/ - virtual string_type to_string() const = 0; - - /** - * @brief 返回实现类型的字符串表示 - * - * 所有IVar实现类都必须支持该方法。 - * - * @return string_type - * @retval - * @see - * @author chenxm - * @date 2009/02/04 18:54:18 - **/ - virtual string_type get_type() const = 0; - - /** - * @brief 返回实现类型的类型掩码 - * - * 所有IVar实现类都必须支持该方法。 - * 目前返回值类型目前是unsigned short,以后可能会改变,但会保持与unsigned short兼容 - * - * @return mask_type - * @retval - * @see - * @author chenxm - * @date 2010/03/11 18:54:18 - **/ - virtual mask_type get_mask() const = 0; - - /** - * @brief 复制一个var结点 - * - * @return IVar& - * @retval - * @see - * @author chenxm - * @date 2010/01/29 16:20:41 - **/ - virtual IVar& clone(bsl::ResourcePool& /*rp*/) const = 0; - - /** - * @brief 复制一个var结点, 由is_deep_copy参数控制是否深复制 - * - * @return IVar& - * @retval - * @see - * @author zhujianwei - * @date 2011/03/22 - **/ - virtual IVar& clone(bsl::ResourcePool& /*rp*/, bool /*is_deep_copy*/) const{ - throw bsl::NotImplementedException()< T - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:12:36 - **/ - template - T to() const; - - /** - * @brief 用无类型二进制数据类型赋值 - * - * 所有is_raw()返回true的实现类都必须实现该方法 - * 若实现类不支持该操作,抛出bsl::InvalidOperationException异常 - * - * @return IVar& operator - * @retval - * @see - * @author chenxm - * @date 2009/05/03 14:32:19 - **/ - virtual IVar& operator = ( const raw_type& value_ ){ - throw bsl::InvalidOperationException()<= size(),返回bsl::var::Null::null; - * 一般用于试探性获取 - * - * @return const IVar& - * @retval - * @see - * @author chenxm - * @date 2009/02/04 19:12:42 - **/ - virtual const IVar& get( size_t idx ) const { - throw bsl::InvalidOperationException()<= size(),则数组会自动增长到size() + 1 - * - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/02/04 19:07:04 - **/ - virtual void set( size_t idx, IVar& value_ ){ - throw bsl::InvalidOperationException()<= size(),抛出bsl::OutOfBoundException异常 - * 一般用于"确定性获取"(获取不到直接抛异常) - * 试验性支持:若index < 0,等价于size() + index - * - * @param [in] index : int - * @return const IVar& [] - * @retval - * @see - * @author chenxm - * @date 2009/02/04 19:16:21 - **/ - virtual const IVar& operator []( int idx ) const { - throw bsl::InvalidOperationException()<= size(),数组会自动增长到index + 1 - * 一般用于设置下标绑定或者确定性获取(获取不到会导致数组自动增长) - * 试验性支持:若index < 0,等价于size() + index - * - * @param [in] index : int - * @return IVar& [] - * @retval - * @see - * @author chenxm - * @date 2009/02/04 19:23:03 - **/ - virtual IVar& operator []( int idx ){ - throw bsl::InvalidOperationException()<的特化实现(该方法不能被改写) - * - * @return template<> inline bool - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:16:00 - **/ - template<> - inline bool IVar::to() const{ - return this->to_bool(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline signed char IVar::to - inline signed char IVar::to() const{ - return this->to_int8(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline unsigned char IVar::to - inline unsigned char IVar::to() const{ - return this->to_uint8(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline signed short IVar::to - inline signed short IVar::to() const{ - return this->to_int16(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline unsigned short IVar::to - inline unsigned short IVar::to() const{ - return this->to_uint16(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline signed int IVar::to - inline signed int IVar::to() const{ - return this->to_int32(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline unsigned int IVar::to - inline unsigned int IVar::to() const{ - return this->to_uint32(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline signed long long IVar::to - inline signed long long IVar::to() const{ - return this->to_int64(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline unsigned long long IVar::to - inline unsigned long long IVar::to() const{ - return this->to_uint64(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline float - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:15 - **/ - template<> - inline float IVar::to() const{ - return this->to_float(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline double - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:17 - **/ - template<> - inline double IVar::to() const{ - return this->to_double(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline bsl::string - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:19 - **/ - template<> - inline bsl::string IVar::to() const{ - return this->to_string(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline raw_t - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:21 - **/ - template<> - inline raw_t IVar::to() const{ - return this->to_raw(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return template<> inline const char* IVar::to - inline const char * IVar::to() const{ - return this->c_str(); - } - -#if __WORDSIZE == 64 - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return signed long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:23 - **/ - template<> - inline signed long IVar::to() const{ - return this->to_int64(); - } - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return unsigned long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:23 - **/ - template<> - inline unsigned long IVar::to() const{ - return this->to_uint64(); - } -#else - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return signed long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:23 - **/ - template<> - inline signed long IVar::to() const{ - return this->to_int32(); - } - - /** - * @brief IVar::to的特化实现(该方法不能被改写) - * - * @return unsigned long - * @retval - * @see - * @author chenxm - * @date 2010/03/17 17:17:23 - **/ - template<> - inline unsigned long IVar::to() const{ - return this->to_uint32(); - } -#endif - -}} // namespace bsl::var - -#endif //__BSL_VAR_IVAR_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/interface/Makefile b/bsl/var/interface/Makefile deleted file mode 100644 index a2e373026f9da293f2895f7d06f20d51708d5e77..0000000000000000000000000000000000000000 --- a/bsl/var/interface/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = .. -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_HEADS = $(wildcard *.h) - -PROVIDE_OBJECTS = - -DEPEND_HEADS = $(PROVIDE_HEADS) $(wildcard $(OUTPUT_HEAD_PATH)/*.h ) - -DEPEND_OBJECTS = - -DEPEND_LIBS = - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### -check_cast_generated.h: check_cast.py - ./$^ > $@ - - diff --git a/bsl/var/unittest/ITestVar.h b/bsl/var/unittest/ITestVar.h deleted file mode 100644 index 8c6868e1c0bdcff07122acbffa7bbdf070768122..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/ITestVar.h +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: ITestVar.h,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file ITestVar.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/28 16:55:49 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __ITESTVAR_H_ -#define __ITESTVAR_H_ - -#ifndef LLONG_MAX -#define LLONG_MAX 9223372036854775807LL -#endif - -#ifndef LLONG_MIN -#define LLONG_MIN (-LLONG_MAX-1LL) -#endif - -#ifndef ULLONG_MAX -#define ULLONG_MAX 18446744073709551615ULL -#endif - -#define ECHO_DO( __STATEMENT__ ) \ - do{ \ - std::cout<<"\n/""/"<< /*__FILE__ <<":"<< __LINE__<<":\t"<<*/ (#__STATEMENT__)<<";"< - -class ITestVar{ -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - //special methods - virtual void test_special() = 0; - - //methods for all - virtual void test_clear() = 0; - virtual void test_dump() = 0; - virtual void test_to_string() = 0; - virtual void test_get_type() = 0; - virtual void test_operator_assign() = 0; - virtual void test_clone() = 0; - virtual void test_mask() = 0; - - //method for value - virtual void test_bool() = 0; - virtual void test_raw() = 0; - virtual void test_number() = 0; - virtual void test_string() = 0; - - //methods for array and dict - virtual void test_array() = 0; - - //methods for dict - virtual void test_dict() = 0; - - //methods for callable - virtual void test_callable() = 0; - - virtual void test_all( ){ - //special methods - ECHO_DO( test_special() ); - - //methods for all - ECHO_DO( test_clear() ); - ECHO_DO( test_dump() ); - ECHO_DO( test_to_string() ); - ECHO_DO( test_get_type() ); - ECHO_DO( test_operator_assign() ); - ECHO_DO( test_clone() ); - // ECHO_DO( test_mask() ); - - //methods for different categories - ECHO_DO( test_bool() ); - ECHO_DO( test_raw() ); - ECHO_DO( test_number() ); - ECHO_DO( test_string() ); - ECHO_DO( test_array() ); - ECHO_DO( test_dict() ); - ECHO_DO( test_callable() ); - printf("test:%s Accepted!\n",typeid(*this).name()); - - } -}; - - -#endif //__ITESTVAR_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/Makefile b/bsl/var/unittest/Makefile deleted file mode 100644 index 27926c913f3a6054d1f5631431f35a84c055ad4a..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = .. -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_HEADS = $(wildcard *.h) - -DEPEND_HEADS = $(PROVIDE_HEADS) $(wildcard ../../output/include/bsl/*.h) $(wildcard ../../output/include/bsl/var/*.h) - -PROVIDE_OBJECTS = - -DEPEND_OBJECTS = - -PROVIDE_LIBS = - -DEPEND_LIBS = - -PROVIDE_BINS = test_bsl_wrappers test_check_cast_gen test_check_cast test_ResourcePool test_ShallowCopystring test_var_utils test_var_Bool test_var_Null test_var_Ref test_var_Int32 test_var_Int64 test_var_Double test_var_ShallowString test_var_String test_var_String2 test_var_ShallowRaw test_var_Array test_var_Array2 test_var_Dict test_var_Function test_var_Method test_var_MagicRef test_var_Number - -##### OVERWRITE ##### - -OUTPUT_HEAD_PATH = -OUTPUT_OBJECT_PATH = -OUTPUT_LIB_PATH = -OUTPUT_BIN_PATH = - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -TEST_TARGETS = $(PROVIDE_BINS) - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### - -test_check_cast_gen.cpp: test_check_cast_gen.py - ./$^ > $@ - -test: output - @for TEST_TARGET in $(TEST_TARGETS); do\ - echo "[make] testing $$TEST_TARGET ...";\ - ./$$TEST_TARGET;\ - done - -valgrind_test: output - @for TEST_TARGET in $(TEST_TARGETS); do\ - echo "[make] testing $$TEST_TARGET ...";\ - valgrind --leak-check=full --show-reachable=yes ./$$TEST_TARGET;\ - done - - - diff --git a/bsl/var/unittest/test.h b/bsl/var/unittest/test.h deleted file mode 100644 index e92c4c1ea9a2ec69b379ce754a45d42eb06ec2ab..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __TEST_H___ -#define __TEST_H___ - -#include -#include -#include -#include"bsl/containers/string/bsl_string.h" -#include"bsl/var/implement.h" -#include"ITestVar.h" - - -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< -#include -#include -#include -#include "bsl/ResourcePool.h" -#include "bsl/pool/bsl_debugpool.h" -#include "bsl/pool/bsl_xcompool.h" -#include "bsl/var/implement.h" - -using namespace std; - -#include -#include -using namespace std; -#define see(x) do{ \ - cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<(p); - - assert( C::s_default_constructor_count == 1); - assert( C::alive_count() == 1 ); - bsl::destroy(p); - assert( C::s_destructor_count == 1 ); - assert( C::alive_count() == 0 ); - - //test copy constructor - char buf2[sizeof(C)]; - void *q = buf2; - bsl::construct(q,p); - int aa = 4; - bsl::construct(q,&aa); //call C::C(int) - assert( C::s_copy_constructor_count == 1 ); - assert( C::s_int_constructor_count == 1 ); - assert( C::alive_count() == 2 ); - - bsl::destroy(q); - assert( C::s_destructor_count == 2 ); - assert( C::alive_count() == 1 ); -} - -void test_attach(){ - C::clear_count(); - - cout< ); - - C *pc_arr = new C[2]; - rp.attach( pc_arr, bsl::bsl_delete_array ); - - }// rp destroyed here, “没有rp,就什么都没有了” - - assert( C::s_default_constructor_count == 3 ); - assert( C::s_destructor_count == 3 ); - assert( C::alive_count() == 0 ); -} - -void test_create(){ - cout<(); - //test create(arg) - rp.create(c); - //test create(arg) with int - rp.create(123); - C* pc = rp.createp(456); - assert(NULL != pc); - }// rp destroyed here, “没有rp,就什么都没有了” - assert( C::s_default_constructor_count == 1 ); - assert( C::s_copy_constructor_count == 1 ); - assert( C::s_int_constructor_count == 2 ); - assert( C::s_destructor_count == 4 ); - assert( C::alive_count() == 0 ); - - //POD - { - bsl::ResourcePool rp; - void * p = rp.create(); - void * p1 = rp.create(p); - assert( p1 == p ); - void * p2 = rp.create(p); - assert( p2 == p ); - const char * str = "str"; - const void * p3 = rp.create(str); - assert( p3 == str ); - //注意: void * p4 = rp.create(str); 是不可以的 - //因为const char *& 不能转化成void * - - }// rp destroyed here - -} - -void test_create_array(){ - cout<(2);// default = 1 copy = 2 int = 0 destruct = 1 - - //test create(arg) - C* c_arr2 = rp.create_array(3, c_arr[0]); // default = 1 copy = 5 int = 0 destruct = 1 - - //test create(arg) with arg is int - C* c_arr3 = rp.create_array(4, 7336 );// default = 1 copy = 5 int = 4 destruct = 1 - - // you can dump them casually - c_arr = NULL; - c_arr2 = NULL; - c_arr3 = NULL; - - }// rp destroyed here, “没有rp,就什么都没有了” - -#ifdef NGUI_CONFIG_DO_NOT_COPY_FOR_DEFAULT_CONSTRUCTION - //这个没什么好说的,正常版本 - assert( C::s_default_constructor_count == 2 ); - assert( C::s_copy_constructor_count == 3 ); - assert( C::s_int_constructor_count == 4 ); - assert( C::alive_count() == 0 ); -#else - //这个看请面的注释 - assert( C::s_default_constructor_count == 1 ); - assert( C::s_copy_constructor_count == 5 ); - assert( C::s_int_constructor_count == 4 ); - assert( C::alive_count() == 0 ); -#endif - - //pod; - { - bsl::ResourcePool rp; - void ** p_arr = rp.create_array(1); - void ** p1_arr = rp.create_array(3,p_arr[0]); - char str[] = "str"; - const void ** p2_arr = rp.create_array(3,str); - for( int i = 0; i< 3; ++ i ){ - assert(p2_arr[i] == str ); - } - void ** p3_arr = rp.create_array(7,(void*)str); - for( int i = 0; i< 7; ++ i ){ - assert(p3_arr[i] == str ); - } - - } - -} - -void test_clone(){ - cout<(src[1]); - rp.clone(src[1]); - //test clone_array() - C* pc3 = rp.clone_array(src, 3); - assert(NULL != pc3); - //test create_raw() - void * p1 = rp.create_raw( 123 ); - assert(NULL != p1); - void * p2 = rp.clone_raw( p1, 123 ); - assert(NULL != p2); - //test create_cstring() - char * str = rp.clone_cstring( "没有rp,就什么都没有了" ); - assert( 0 == strcmp( str, "没有rp,就什么都没有了" ) ); - }// rp destroyed here, “没有rp,就什么都没有了” - assert( C::s_default_constructor_count == 0 ); - assert( C::s_copy_constructor_count == 5 ); - assert( C::s_int_constructor_count == 0 ); - assert( C::s_destructor_count == 5 ); - assert( C::alive_count() == 0 ); - -} -#include -#include -#include -#include -#include - -/* -void test_allocator(){ - cout< > v; - map >m; - set > s; - list > l; - deque > di; - deque >, bsl::NgAlloc > > > dv; - - // todo: 功能测试 -} -*/ - -void test_with_mempool(){ - { - bsl::debugpool pool; - bsl::ResourcePool rp(pool); - rp.create(); - rp.create_array(123); - } - - { - bsl::debugpool pool; - bsl::ResourcePool rp(pool); - bsl::pool_allocator alloc = rp.get_allocator(); - char *p = alloc.allocate(2); - alloc.deallocate(p, 2); - bsl::pool_allocator alloc2 = rp.get_allocator(); - C* pc = alloc2.allocate(1); - alloc2.deallocate(pc, 1); - } - - { - bsl::debugpool pool; - bsl::ResourcePool rp(pool); - char * p = static_cast(rp.create_raw(1000)); - p[999] = 'A'; - } - - { - bsl::debugpool pool; - bsl::ResourcePool rp(pool); - const char * cs = "iwegoewgewobjojqwnn q qoeqbn w%$%#^@$#@^@$%@!@$&&*%$*%$"; - assert( 0 == strcmp( cs, rp.clone_cstring(cs) ) ); - assert( 0 == strcmp( "", rp.clone_cstring("") ) ); - assert( 0 == strncmp( cs, rp.clone_cstring(cs, strlen(cs)), strlen(cs) ) ); - assert( 0 == strncmp( cs, rp.clone_cstring(cs, 5), 5 ) ); - assert( '\0' == * rp.clone_cstring(cs, 0) ) ; - } - - { - bsl::xcompool pool; - pool.create(); - bsl::ResourcePool rp(pool); - bsl::var::String str = - rp.create(bsl::var::String::allocator_type( &rp.get_mempool() )); - str = "hello word"; - printf("%s\n",str.c_str()); - } -} - -class EException: public bsl::BasicException{}; - -class E{ -public: - E(){ - throw EException()<(buf)), _count(0), _size(size) {} - - virtual void * malloc(size_t size){ - if ( _count + size > _size ){ - throw bsl::BadAllocException()<::iterator iter = _map.find(static_cast(p)); - if ( iter == _map.end() || p != iter->first || len != iter->second ){ - throw bsl::BadArgumentException()< _map; - char * _buf; - size_t _count; - size_t _size; -}; - -void test_except(){ - { - bsl::ResourcePool rp; - ASSERT_THROW( rp.create(), EException ); - assert( NULL == rp.createp() ); - } - { - - bsl::ResourcePool rp; - const E& ee = rp.create(std::nothrow); - ASSERT_THROW( rp.create(ee), EException ); - assert( NULL == rp.createp(ee) ); - } - - { - BufPool throw_pool(NULL, 0); - bsl::ResourcePool rp(throw_pool); - - ASSERT_THROW( rp.create(), bsl::BadAllocException ); - ASSERT_THROW( rp.create(123), bsl::BadAllocException ); - assert( NULL == rp.createp() ); - assert( NULL == rp.createp(123) ); - - C *pc = new C(); - ASSERT_THROW( rp.attach( pc, bsl::bsl_delete ), bsl::BadAllocException ); - } -} - -void test_valist(const char * format, ...) { - va_list ap; - va_start(ap,format); - bsl::ResourcePool rp; - const char * str = rp.vcrcprintf( format, ap ); - printf("%s\n",str); - const char * str2 = rp.vcrcprintf_hint( 5, format, ap ); - printf("%s\n",str2); - va_end(ap); - assert( 0 == strcmp( str, rp.clone_cstring(str2) ) ); - return ; -} - -void test_print() { - test_valist("%d,%d,%s,%lf",200,3,"wahaha",1.0); - bsl::ResourcePool rp; - const char * str2 = rp.crcprintf("%d,%d,%s,%lf",200,3,"wahaha",1.0); - const char * str3 = rp.crcprintf_hint(5,"%d,%d,%s,%lf",200,3,"wahaha",1.0); - assert( 0 == strcmp(str2,rp.clone_cstring(str3)) ); -} - -int main(){ - try{ - test_construct_and_destroy(); - test_attach(); - test_create(); - test_create_array(); - test_clone(); - test_with_mempool(); - test_except(); - test_print(); - }catch(bsl::Exception& e){ - fprintf( stderr, "Exception: %s", e.what() ); - } - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_ShallowCopystring.cpp b/bsl/var/unittest/test_ShallowCopystring.cpp deleted file mode 100644 index 5fe43e17d2fd5982b57481cb4d3659436cf1a183..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_ShallowCopystring.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_ShallowCopystring.cpp,v 1.3 2009/06/15 06:29:05 chenxm Exp $ - * - **************************************************************************/ - - - -/** - * @file test_ShallowCopyString.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/08 10:31:44 - * @version $Revision: 1.3 $ - * @brief - * - **/ - -#include -#include -#include "bsl/ShallowCopyString.h" - -int main(){ - //todo: more tests, even more tests! - const char *str = "hello world"; - size_t len = strlen(str); - bsl::ShallowCopyString ss = str; - assert( 0 == strcmp(ss.c_str(), str) ); - assert( ss.length() == len ); - assert( ss.size() == len ); - assert( ss.capacity() == len ); - assert( ss == str ); - assert( str == ss ); - assert( ss == bsl::ShallowCopyString(str) ); - assert( ss == bsl::ShallowCopyString(ss) ); - - std::cout<comake2.md5 - @md5sum -c --status comake2.md5 - @rm -f comake2.md5 - -.PHONY:ccpclean -ccpclean: - @echo "[COMAKE:BUILD][Target:'ccpclean']" - @echo "make ccpclean done" - -.PHONY:clean -clean:ccpclean - @echo "[COMAKE:BUILD][Target:'clean']" - rm -rf test_BigInt - rm -rf ./output/bin/test_BigInt - rm -rf test_BigInt_test_BigInt.o - -.PHONY:dist -dist: - @echo "[COMAKE:BUILD][Target:'dist']" - tar czvf output.tar.gz output - @echo "make dist done" - -.PHONY:distclean -distclean:clean - @echo "[COMAKE:BUILD][Target:'distclean']" - rm -f output.tar.gz - @echo "make distclean done" - -.PHONY:love -love: - @echo "[COMAKE:BUILD][Target:'love']" - @echo "make love done" - -test_BigInt:test_BigInt_test_BigInt.o \ - ../../../output/lib/libbsl.a - @echo "[COMAKE:BUILD][Target:'test_BigInt']" - $(CXX) test_BigInt_test_BigInt.o -Xlinker "-(" ../../../output/lib/libbsl.a ../../../../../com/btest/gtest/output/lib/libgtest.a \ - ../../../../../com/btest/gtest/output/lib/libgtest_main.a \ - ../../../../../quality/autotest/reportlib/cpp/libautotest.a -lpthread \ - -lcrypto \ - -lrt -Xlinker "-)" -o test_BigInt - mkdir -p ./output/bin - cp -f --link test_BigInt ./output/bin - -test_BigInt_test_BigInt.o:test_BigInt.cpp - @echo "[COMAKE:BUILD][Target:'test_BigInt_test_BigInt.o']" - $(CXX) -c $(INCPATH) $(DEP_INCPATH) $(CPPFLAGS) $(CXXFLAGS) -o test_BigInt_test_BigInt.o test_BigInt.cpp - -endif #ifeq ($(shell uname -m),x86_64) - - diff --git a/bsl/var/unittest/test_bigint/test_BigInt.cpp b/bsl/var/unittest/test_bigint/test_BigInt.cpp deleted file mode 100644 index 47a1c58423b974d20eec7f49570ea23faaca392f..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_bigint/test_BigInt.cpp +++ /dev/null @@ -1,332 +0,0 @@ -#include -#include -#include "Bool.h" -#include "Int32.h" -#include "Int64.h" -#include "String.h" -#include "BigInt.h" -#include - -#define SIGNED true -#define UNSIGNED false - -using namespace bsl::var; - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -/** - * @brief -**/ -class test_bigint_suite : public ::testing::Test{ - protected: - test_bigint_suite(){}; - virtual ~test_bigint_suite(){}; - virtual void SetUp() { - //Called befor every TEST_F(test_bigint_suite, *) - }; - virtual void TearDown() { - //Called after every TEST_F(test_bigint_suite, *) - }; -}; - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_ivar_is_bigint) -{ - //TODO - BigIntk b; - IVar & i = b; - EXPECT_EQ(i.is_bigint(), true); -} - - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_ivar_string) -{ - //TODO - bsl::string original = "0xf234567890abcdef"; - { - int exception_flag = 0; - try{ - BigInt<128, UNSIGNED> a = (const char *)NULL; - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } - { - // copy contructor and assignment operator - BigInt<128, SIGNED> a = original; - bsl::string conv = a.to_string(); - EXPECT_EQ(strcmp(conv.c_str(), original.c_str()), 0); - } - { - BigInt<128, UNSIGNED> a = original; - bsl::string conv = a.to_string(); - EXPECT_EQ(strcmp(conv.c_str(), original.c_str()), 0); - } - { - String orig = original; - BigInt<128, SIGNED> a = orig.to_bigint<128, SIGNED>(); - String conv; - conv = a; - EXPECT_EQ(strcmp(conv.c_str(), original.c_str()), 0); - } - { - String orig = original; - int exception_flag = 0; - try{ - BigInt<128, UNSIGNED> a = orig.to_bigint<128, SIGNED>(); - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } -} - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_ivar_bool) -{ - //TODO - BigInt<1, SIGNED> a = true; // copy contructor - EXPECT_EQ(a.is_overflow(), true); - - Bool b = a.to_bool(); - EXPECT_EQ(b.to_bool(), true); - - a = false; // assignment operator - EXPECT_EQ(a.to_bool(), false); - - Bool c; - c = a; - EXPECT_EQ(c.to_bool(), false); - - a = c.to_bigint<1, SIGNED>(); - EXPECT_EQ(a.to_bool(), false); - - { - BigIntk b = 0x00000001; - EXPECT_EQ(b.to_bool(), true); - b = 0x00000000; - EXPECT_EQ(b.to_bool(), false); - b = "0x00000000"; - EXPECT_EQ(b.to_bool(), false); - } -} - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_int32) -{ - //TODO - { - int a = 0xffa; - BigIntk b = a; - EXPECT_EQ(b.to_int32(), a); - EXPECT_EQ(b.to_bool(), true); - } - { - int a = -123; - BigIntk b = a; - EXPECT_EQ(b.to_int32(), -123); - } - { - Int32 c = 0xffffffff; - BigIntk b = c.to_bigint<1024, SIGNED>(); - EXPECT_EQ(b.is_overflow(), false); - EXPECT_EQ(strcmp(b.to_string().c_str(), "0xffffffff"), 0); - c = b; - EXPECT_EQ(c.to_int32(), (signed int)0xffffffff); - } - { - int a = -123; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a; - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } - { - Int32 a = 0x7fffffff; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a.to_bigint<1024, UNSIGNED>(); - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 0); - - a = (signed int)0xffffffff; - exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a.to_bigint<1024, UNSIGNED>(); - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } -} - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_int64) -{ - //TODO - { - long long a = -123; - BigIntk b = a; - EXPECT_EQ(b.to_int64(), -123); - } - { - Int64 c = 0xffffffffffffffff; - BigIntk b = c.to_bigint<1024, SIGNED>(); - EXPECT_EQ(b.is_overflow(), false); - EXPECT_EQ(strcmp(b.to_string().c_str(), "0xffffffffffffffff"), 0); - c = b; - EXPECT_EQ(c.to_int64(), (signed long long)0xffffffffffffffff); - } - { - BigInt<1024, UNSIGNED> b = "0xffffffffffffffff"; - EXPECT_EQ(b.is_overflow(), false); - EXPECT_EQ(b.to_uint64(), (unsigned long long)0xffffffffffffffff); - } - { - long long a = -123; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a; - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } - { - Int64 a = 0x7fffffffffffffff; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a.to_bigint<1024, UNSIGNED>(); - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 0); - - a = (signed long long)0xffffffffffffffff; - exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a.to_bigint<1024, UNSIGNED>(); - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } -} - -/** - * @brief float and double conversion, not supported - * @begin_version -**/ -TEST_F(test_bigint_suite, case_float_double) -{ - //TODO - { - float a = 3.14; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a; - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } - { - double a = 3.14; - int exception_flag = 0; - try{ - BigInt<1024, UNSIGNED> b; - b = a; - } - catch(...){ - exception_flag = 1; - } - EXPECT_EQ(exception_flag, 1); - } -} - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_overflow) -{ - //TODO - { - BigInt<32, UNSIGNED> b; - b = "0xffffffff"; - EXPECT_EQ(b.is_overflow(), false); - - bsl::var::BigInt<32, SIGNED> c; - c = "0xffffffff"; - EXPECT_EQ(c.is_overflow(), false); - } - { - BigInt<32, UNSIGNED> b; - b = "0xfffffffff"; - EXPECT_EQ(b.is_overflow(), true); - - bsl::var::BigInt<32, SIGNED> c; - c = "0xfffffffff"; - EXPECT_EQ(c.is_overflow(), true); - } -} - -/** - * @brief - * @begin_version -**/ -TEST_F(test_bigint_suite, case_resourcepool) -{ - //TODO - { - BigInt<128, UNSIGNED> b; - b = "0xffffffff"; - - bsl::ResourcePool rp; - BigInt<128, UNSIGNED> & c = b.clone(rp); - EXPECT_EQ(strcmp(b.to_string().c_str(), c.to_string().c_str()), 0); - } - -} - diff --git a/bsl/var/unittest/test_bsl_wrappers.cpp b/bsl/var/unittest/test_bsl_wrappers.cpp deleted file mode 100644 index 3661cad1df8ff0d04d25eb9f63c9cb65e264b9b9..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_bsl_wrappers.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_bsl_wrappers.cpp,v 1.2 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file test_bsl_wrappers.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/08/14 10:44:47 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include"bsl/ResourcePool.h" -#include -#include -#include -using namespace std; -using namespace bsl; -#define see(x) do{ \ - cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< - - -// #define NG_TEST_DEBUG -/* - * __construct_aux [bsl] - __construct_aux [bsl] - bsl::construct [bsl] - bsl::construct [bsl] - bsl::destroy [bsl] - __construct_array_aux [bsl] - __construct_array_aux [bsl] - bsl::construct_array [bsl] - bsl::construct_array [bsl] - default_destroy_array [bsl] - bsl::destroy_array [bsl] - deallocate [bsl] - bsl::destroy_and_deallocate [bsl] - bsl::destroy_and_deallocate_array [bsl] - bsl_delete [bsl] - bsl_delete_array [bsl] - bsl_free [bsl] - bsl_fclose [bsl] -*/ - -/** -* @brief 好用的测试类 -* -* -*/ -class C{ -public: - static int s_default_constructor_count; - static int s_copy_constructor_count; - static int s_int_constructor_count; - static int s_destructor_count; - static int alive_count(){ - return s_default_constructor_count - + s_copy_constructor_count - + s_int_constructor_count - - s_destructor_count; - } - static void print_count(){ - see( s_default_constructor_count ); - see( s_copy_constructor_count ); - see( s_int_constructor_count ); - see( s_destructor_count ); - see( alive_count() ); - } - - static void clear_count(){ - s_default_constructor_count = 0; - s_copy_constructor_count = 0; - s_int_constructor_count = 0; - s_destructor_count = 0; - } - - C(){ -#ifdef NG_TEST_DEBUG - cerr<<"C() this ="<(buf); - bsl::construct(buf, &iarg); - bsl::construct(buf, &carg); - - assert( C::s_default_constructor_count == 1 ); - assert( C::s_copy_constructor_count == 1 ); - assert( C::s_int_constructor_count == 1 ); - assert( C::s_destructor_count == 0 ); - assert( C::alive_count() == 3 ); - - //for non-pod array - C::clear_count(); - - char arr_buf[sizeof(C)*100]; - - bsl::construct_array(arr_buf,arr_buf+0); - bsl::construct_array(arr_buf,arr_buf+3); - - bsl::construct_array(arr_buf, arr_buf+5, &iarg); - bsl::construct_array(arr_buf, arr_buf+7, &carg); - -#ifdef NGUI_CONFIG_DO_NOT_COPY_FOR_DEFAULT_CONSTRUCTION - assert( C::s_default_constructor_count == 3 ); - assert( C::s_copy_constructor_count == 7 ); - assert( C::s_int_constructor_count == 5 ); - assert( C::s_destructor_count == 0 ); - assert( C::alive_count() == 15 ); -#else - assert( C::s_default_constructor_count == 2 ); - assert( C::s_copy_constructor_count == 10 ); - assert( C::s_int_constructor_count == 5 ); - assert( C::s_destructor_count == 2 ); - assert( C::alive_count() == 15 ); -#endif - - //for pod - float farg = 4670.9394; - float fbuf[1]; - void * vfbuf = fbuf; - bsl::construct(fbuf); -#ifndef NGUI_CONFIG_SKIP_POD_INITIALIAZION - assert(*fbuf == 0.0 ); -#endif - bsl::construct(vfbuf, &farg);//用fbuf代替vfbuf当然也是没问题的 - assert(*fbuf == farg ); - - bsl::construct(vfbuf, &iarg); - assert( *fbuf == float(iarg) ); - - //for pod array - float farr[100]; - - bsl::construct_array(farr, farr+3); -#ifndef NGUI_CONFIG_SKIP_POD_INITIALIAZION - for( int i = 0; i < 3; ++ i){ - assert(farr[i] == 0.0); - } -#endif - bsl::construct_array(farr, farr+5, &farg);//用farr代替vfarr当然也是没问题的 - for( int i = 0; i < 5; ++ i){ - assert(farr[i] == farg ); - } - - bsl::construct_array(farr, farr+7, &iarg); - for( int i = 0; i < 7; ++ i){ - assert(farr[i] == float(iarg)); - } - - -} -void test_destroy(){ - cout<<"enter "<<__func__<<"()"<(buf); - bsl::destroy(buf); - - char arr[sizeof(C)*100]; - bsl::construct_array(arr,arr+sizeof(C)*3, &iarg ); - bsl::destroy_array(arr,arr+sizeof(C)*3); - - bsl::construct_array(arr,arr+sizeof(C)*11, &iarg ); - default_destroy_array((C*)arr, ((C*)arr)+11); - - assert( C::s_destructor_count == 15 ); - assert( C::alive_count() == 0 ); - - //for POD, just test compilation - bsl::destroy(arr); - bsl::destroy(arr); - bsl::destroy(arr); - - bsl::destroy_array(arr,arr+3); - bsl::destroy_array(arr,arr+5); - bsl::destroy_array(arr,arr+7); - - default_destroy_array(arr,arr+11); - -} -/* -void test_deallocate(){ - cout<<"enter "<<__func__<<"()"<().allocate(46709394); - deallocate >( buf, buf + 46709394 ); - } - - for( int i = 0; i< times; ++ i){ - C * buf = NgAlloc().allocate(46709394); - deallocate >( buf, buf + 46709394 ); - } - - //POD - for( int i = 0; i< times; ++ i){ - char * buf = std::allocator().allocate(46709394); - deallocate >( buf, buf + 46709394 ); - } - - for( int i = 0; i< times; ++ i){ - char * buf = NgAlloc().allocate(46709394); - deallocate >( buf, buf+46709394 ); - } -} - -void test_destroy_and_deallocate(){ - cout<<"enter "<<__func__<<"()"<().allocate(1); - bsl::destroy_and_deallocate >(dbl); - - C::clear_count(); - C* pc = bsl::NgAlloc().allocate(10); - bsl::NgAlloc().construct(pc,carg); - bsl::destroy_and_deallocate >(pc); - - assert( C::s_default_constructor_count == 0 ); - assert( C::s_copy_constructor_count == 1 ); - assert( C::s_int_constructor_count == 0 ); - assert( C::s_destructor_count == 1 ); - assert( C::alive_count() == 0 ); - - - //destroy_and_deallocate_array - //POD - for( int i = 0; i< times; ++ i){ - float * buf = std::allocator().allocate(7336); - for( int j = 0; j < 7336; ++ j){ - std::allocator().construct(&buf[j], farg ); - } - bsl::destroy_and_deallocate_array >( buf, buf+7336 ); - } - - for( int i = 0; i< times; ++ i){ - float * buf = bsl::NgAlloc().allocate(7336); - for( int j = 0; j < 7336; ++ j){ - bsl::NgAlloc().construct(&buf[j], farg ); - } - bsl::destroy_and_deallocate_array >( buf, buf+7336 ); - } - - //non-POD - C::clear_count(); - for( int i = 0; i< times; ++ i){ - C * buf = std::allocator().allocate(7336); - for( int j = 0; j < 7336; ++ j){ - std::allocator().construct(&buf[j], carg ); - } - bsl::destroy_and_deallocate_array >( buf, buf+7336 ); - } - - for( int i = 0; i< times; ++ i){ - C * buf = bsl::NgAlloc().allocate(7336); - for( int j = 0; j < 7336; ++ j){ - bsl::NgAlloc().construct(&buf[j], carg ); - } - bsl::destroy_and_deallocate_array >( buf, buf+7336 ); - } - - assert( C::s_default_constructor_count == 0 ); - assert( C::s_copy_constructor_count == 7336+7336 ); - assert( C::s_int_constructor_count == 0 ); - assert( C::s_destructor_count == 7336+7336 ); - assert( C::alive_count() == 0 ); - - -} -*/ -void test_bsl_delete(){ - cout<<"enter "<<__func__<<"()"<(pc); - - C* arr_c = new C[123]; - bsl_delete_array(arr_c); - assert( C::s_default_constructor_count == 1+123 ); - assert( C::s_copy_constructor_count == 0 ); - assert( C::s_int_constructor_count == 0 ); - assert( C::s_destructor_count == 1+123 ); - assert( C::alive_count() == 0 ); -} -void test_bsl_fclose(){ - cout<<"enter "<<__func__<<"()"< -#include -#include "bsl/check_cast.h" - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<(val); - printf("%hd\n",a); - } catch (bsl::Exception& e) { - printf("%s\n",e.all()); - } -} - -void test_to_char(){ - { - //char - assert( 'a' == bsl::check_cast('a') ); - - //int - assert( '\0'== bsl::check_cast(0) ); - assert( char(127) == bsl::check_cast(127) ); - assert( char(-128)== bsl::check_cast(-128) ); - ASSERT_THROW( bsl::check_cast(-129), bsl::UnderflowException ); - ASSERT_THROW( bsl::check_cast(128), bsl::OverflowException ); - - //unsigned char - assert( 'c' == bsl::check_cast((unsigned char)('c'))); - assert( char(127) == bsl::check_cast((unsigned char)(127))); - ASSERT_THROW( bsl::check_cast(((unsigned char)128)), bsl::OverflowException ); - - //double - assert( char(127) == bsl::check_cast(127.0) ); - assert( char(-128)== bsl::check_cast(-128.0) ); - ASSERT_THROW( bsl::check_cast(-129.0), bsl::UnderflowException ); - ASSERT_THROW( bsl::check_cast(128.0), bsl::OverflowException ); - - //cstring - assert( char(0) == bsl::check_cast("") ); - assert( char('c') == bsl::check_cast("cat") ); - - } -} - -void test_to_short(){ -} - -void test_to_int(){ - //char - assert( 0 == bsl::check_cast('\0') ); - assert( -1 == bsl::check_cast(char(-1))); - - //unsigned char - assert( 0 == bsl::check_cast((unsigned char)0)); - assert( 255 == bsl::check_cast((unsigned char)255)); - - //int - assert( INT_MIN == bsl::check_cast(INT_MIN) ); - assert( INT_MAX == bsl::check_cast(INT_MAX) ); - - //long - if ( sizeof(long) > 4 ){ - assert( INT_MIN == bsl::check_cast(long(INT_MIN)) ); - assert( INT_MAX == bsl::check_cast(long(INT_MAX)) ); - ASSERT_THROW( bsl::check_cast(long(INT_MIN)-1), bsl::UnderflowException ); - ASSERT_THROW( bsl::check_cast(long(INT_MAX)+1), bsl::OverflowException ); - }else{ - assert( INT_MIN == bsl::check_cast(long(INT_MIN)) ); - assert( INT_MAX == bsl::check_cast(long(INT_MAX)) ); - } - - //long long - assert( INT_MIN == bsl::check_cast((long long)(INT_MIN)) ); - assert( INT_MAX == bsl::check_cast((long long)(INT_MAX)) ); - ASSERT_THROW( bsl::check_cast((long long)(INT_MIN)-1), bsl::UnderflowException ); - ASSERT_THROW( bsl::check_cast((long long)(INT_MAX)+1), bsl::OverflowException ); - - //double - assert( INT_MIN == bsl::check_cast(double(INT_MIN)) ); - assert( INT_MAX == bsl::check_cast(double(INT_MAX)) ); - ASSERT_THROW( bsl::check_cast(double(INT_MIN)-1), bsl::UnderflowException ); - ASSERT_THROW( bsl::check_cast(double(INT_MAX)+1), bsl::OverflowException ); - - //cstring - -} - -void test_to_size_t(){ - assert( ULONG_MAX == bsl::check_cast((long long)ULONG_MAX) ); - assert( INT_MAX == bsl::check_cast(int(INT_MAX)) ); - -} -void test_to_long(){ -} - -void test_to_long_long(){ -} - -void test_to_float(){ -} - -void test_to_double(){ -} - -void test_to_long_double(){ -} -void test_interpret(){ - while(true){ - char buf[1024]; - while(fgets(buf, 1024, stdin)){ - try{ - printf("result: %lld\n", bsl::check_cast(buf) ); - //bsl::check_cast(int(1)); - }catch(bsl::Exception& e){ - printf("error: %s\n",e.what()); - } - } - } -} - -int main(){ - test_short_to_const_char(); - test_to_char(); - test_to_short(); - test_to_int(); - test_to_long(); - test_to_long_long(); - test_to_float(); - test_to_double(); - test_to_long_double(); - printf("ok...\n"); - //test_interpret(); - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_check_cast_gen.cpp b/bsl/var/unittest/test_check_cast_gen.cpp deleted file mode 100644 index eae721e296778e664020790b4352d620182600ff..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_check_cast_gen.cpp +++ /dev/null @@ -1,8758 +0,0 @@ - -#include -#include "bsl/check_cast.h" - -#include -#include -#define see(x) do{ std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - //unsigned char -> int - //unsigned long long -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //char -> int - //unsigned long -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //size_t -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //unsigned int -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //short -> int - //long -> int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - //unsigned short -> int - //long long -> int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 1) ), bsl::UnderflowException ); - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //signed char -> int - //int -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - //unsigned long long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //size_t -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned int -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //short -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned short -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //long long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //size_t -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned int -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //short -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //signed char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned char -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned long long -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //char -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //unsigned long -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //size_t -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned int -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //short -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned short -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long long -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //signed char -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //int -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //size_t -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //unsigned int -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //short -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //size_t -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //unsigned int -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //short -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //signed char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //size_t -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //unsigned int -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //short -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned char -> short - //unsigned long long -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //char -> short - //unsigned long -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //size_t -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned int -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //short -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - //long -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned short -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //long long -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //signed char -> short - //int -> long - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - //unsigned char -> long - //unsigned long long -> long - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //char -> long - //unsigned long -> long - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //size_t -> long - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //unsigned int -> long - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //short -> long - //long -> long - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - //unsigned short -> long - //long long -> long - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 1) ), bsl::UnderflowException ); - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //signed char -> long - //int -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //size_t -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned int -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //short -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned short -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - //long long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> long long - //unsigned char -> long long - //unsigned long long -> long long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //char -> long long - //unsigned long -> long long - //size_t -> long long - //unsigned int -> long long - //short -> long long - //long -> long long - //unsigned short -> long long - //long long -> long long - - assert( -9223372036854775808.0L == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - assert( -9223372036854775808.0L + 1 == bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ) ) ; - - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - //signed char -> long long - //int -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned char -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned long long -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //char -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //unsigned long -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //size_t -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned int -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //short -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned short -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long long -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //signed char -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //float -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //double -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //long double -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //float -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //double -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //long double -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //float -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //double -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //long double -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //float -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //double -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //long double -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //float -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //double -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //long double -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //float -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //double -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //long double -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //float -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //double -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //long double -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //float -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //double -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //long double -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //float -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //double -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //long double -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - long value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //float -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //double -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //long double -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //float -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //double -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //long double -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //float -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //double -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //long double -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 255LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 255LL ) ); - float value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 255LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 255LL ) ); - double value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 255LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 255LL ) ); - long double value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL ) ); - float value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL ) ); - double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL ) ); - long double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -32768LL ) ); - float value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -32768LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 32767LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 32767LL ) ); - float value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -32768LL ) ); - double value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -32768LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 32767LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 32767LL ) ); - double value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -32768LL ) ); - long double value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -32768LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 32767LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 32767LL ) ); - long double value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 65535LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 65535LL ) ); - float value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 65535LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 65535LL ) ); - double value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 65535LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 65535LL ) ); - long double value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL ) ); - float value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL ) ); - double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL ) ); - long double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 255LL == bsl::check_cast( const_cast("255LL") ) ) ; - assert( 255LL == bsl::check_cast( const_cast("255LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 255LL == bsl::check_cast( const_cast("255") ) ) ; - assert( 255LL == bsl::check_cast( const_cast("255") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 254LL == bsl::check_cast( const_cast("254LL") ) ) ; - assert( 254LL == bsl::check_cast( const_cast("254LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 254LL == bsl::check_cast( const_cast("254") ) ) ; - assert( 254LL == bsl::check_cast( const_cast("254") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("256LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("256LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("256") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("256") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - - - assert( -32768LL == bsl::check_cast( const_cast("-32768LL") ) ) ; - assert( -32768LL == bsl::check_cast( const_cast("-32768LL") ) ) ; - - - assert( 32767LL == bsl::check_cast( const_cast("32767LL") ) ) ; - assert( 32767LL == bsl::check_cast( const_cast("32767LL") ) ) ; - - - assert( -32768LL == bsl::check_cast( const_cast("-32768") ) ) ; - assert( -32768LL == bsl::check_cast( const_cast("-32768") ) ) ; - - - assert( 32767LL == bsl::check_cast( const_cast("32767") ) ) ; - assert( 32767LL == bsl::check_cast( const_cast("32767") ) ) ; - - - assert( -32767LL == bsl::check_cast( const_cast("-32767LL") ) ) ; - assert( -32767LL == bsl::check_cast( const_cast("-32767LL") ) ) ; - - - assert( 32766LL == bsl::check_cast( const_cast("32766LL") ) ) ; - assert( 32766LL == bsl::check_cast( const_cast("32766LL") ) ) ; - - - assert( -32767LL == bsl::check_cast( const_cast("-32767") ) ) ; - assert( -32767LL == bsl::check_cast( const_cast("-32767") ) ) ; - - - assert( 32766LL == bsl::check_cast( const_cast("32766") ) ) ; - assert( 32766LL == bsl::check_cast( const_cast("32766") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-32769LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-32769LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("32768LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("32768LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-32769") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-32769") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("32768") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("32768") ), bsl::OverflowException ); - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 65535LL == bsl::check_cast( const_cast("65535LL") ) ) ; - assert( 65535LL == bsl::check_cast( const_cast("65535LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 65535LL == bsl::check_cast( const_cast("65535") ) ) ; - assert( 65535LL == bsl::check_cast( const_cast("65535") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 65534LL == bsl::check_cast( const_cast("65534LL") ) ) ; - assert( 65534LL == bsl::check_cast( const_cast("65534LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 65534LL == bsl::check_cast( const_cast("65534") ) ) ; - assert( 65534LL == bsl::check_cast( const_cast("65534") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("65536LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("65536LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("65536") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("65536") ), bsl::OverflowException ); - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - - - assert( -128LL == bsl::check_cast( const_cast("-128LL") ) ) ; - assert( -128LL == bsl::check_cast( const_cast("-128LL") ) ) ; - - - assert( 127LL == bsl::check_cast( const_cast("127LL") ) ) ; - assert( 127LL == bsl::check_cast( const_cast("127LL") ) ) ; - - - assert( -128LL == bsl::check_cast( const_cast("-128") ) ) ; - assert( -128LL == bsl::check_cast( const_cast("-128") ) ) ; - - - assert( 127LL == bsl::check_cast( const_cast("127") ) ) ; - assert( 127LL == bsl::check_cast( const_cast("127") ) ) ; - - - assert( -127LL == bsl::check_cast( const_cast("-127LL") ) ) ; - assert( -127LL == bsl::check_cast( const_cast("-127LL") ) ) ; - - - assert( 126LL == bsl::check_cast( const_cast("126LL") ) ) ; - assert( 126LL == bsl::check_cast( const_cast("126LL") ) ) ; - - - assert( -127LL == bsl::check_cast( const_cast("-127") ) ) ; - assert( -127LL == bsl::check_cast( const_cast("-127") ) ) ; - - - assert( 126LL == bsl::check_cast( const_cast("126") ) ) ; - assert( 126LL == bsl::check_cast( const_cast("126") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-129LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-129LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("128LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("128LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-129") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-129") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("128") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("128") ), bsl::OverflowException ); - - - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - - - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - - - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - - - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - - - { - //avoid floating-point number errors - float value1 = -2147483648LL; - float value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - float value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = 2147483647LL; - float value2 = bsl::check_cast( const_cast("2147483647LL") ); - float value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = -2147483648LL; - float value2 = bsl::check_cast( const_cast("-2147483648") ) ; - float value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = 2147483647LL; - float value2 = bsl::check_cast( const_cast("2147483647") ); - float value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = -2147483648LL; - double value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - double value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = 2147483647LL; - double value2 = bsl::check_cast( const_cast("2147483647LL") ); - double value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = -2147483648LL; - double value2 = bsl::check_cast( const_cast("-2147483648") ) ; - double value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = 2147483647LL; - double value2 = bsl::check_cast( const_cast("2147483647") ); - double value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = -2147483648LL; - long double value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - long double value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = 2147483647LL; - long double value2 = bsl::check_cast( const_cast("2147483647LL") ); - long double value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = -2147483648LL; - long double value2 = bsl::check_cast( const_cast("-2147483648") ) ; - long double value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = 2147483647LL; - long double value2 = bsl::check_cast( const_cast("2147483647") ); - long double value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - assert( "-2147483648" == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - - - assert( "-2147483647" == bsl::check_cast( static_cast(-2147483647LL) ) ) ; - - - assert( "2147483647" == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - assert( "2147483646" == bsl::check_cast( static_cast(2147483646LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "255" == bsl::check_cast( static_cast(255LL) ) ) ; - - - assert( "254" == bsl::check_cast( static_cast(254LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "18446744073709551615" == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - - assert( "18446744073709551614" == bsl::check_cast( static_cast(18446744073709551614ULL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "4294967295" == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - assert( "4294967294" == bsl::check_cast( static_cast(4294967294LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "4294967295" == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - assert( "4294967294" == bsl::check_cast( static_cast(4294967294LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "4294967295" == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - assert( "4294967294" == bsl::check_cast( static_cast(4294967294LL) ) ) ; - - - assert( "-32768" == bsl::check_cast( static_cast(-32768LL) ) ) ; - - - assert( "-32767" == bsl::check_cast( static_cast(-32767LL) ) ) ; - - - assert( "32767" == bsl::check_cast( static_cast(32767LL) ) ) ; - - - assert( "32766" == bsl::check_cast( static_cast(32766LL) ) ) ; - - - assert( "-2147483648" == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - - - assert( "-2147483647" == bsl::check_cast( static_cast(-2147483647LL) ) ) ; - - - assert( "2147483647" == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - assert( "2147483646" == bsl::check_cast( static_cast(2147483646LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "65535" == bsl::check_cast( static_cast(65535LL) ) ) ; - - - assert( "65534" == bsl::check_cast( static_cast(65534LL) ) ) ; - - - assert( "-9223372036854775808" == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - - - assert( "-9223372036854775807" == bsl::check_cast( static_cast(-9223372036854775807LL) ) ) ; - - - assert( "9223372036854775807" == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - assert( "9223372036854775806" == bsl::check_cast( static_cast(9223372036854775806LL) ) ) ; - - - assert( "-128" == bsl::check_cast( static_cast(-128LL) ) ) ; - - - assert( "-127" == bsl::check_cast( static_cast(-127LL) ) ) ; - - - assert( "127" == bsl::check_cast( static_cast(127LL) ) ) ; - - - assert( "126" == bsl::check_cast( static_cast(126LL) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "A" == bsl::check_cast( static_cast('A') ) ) ; - -#else - //int -> int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - //unsigned char -> int - //unsigned long long -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //char -> int - //unsigned long -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //size_t -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //unsigned int -> int - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //short -> int - //long -> int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 1) ), bsl::UnderflowException ); - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //unsigned short -> int - //long long -> int - - assert( -2147483648LL == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - assert( -2147483648LL + 1 == bsl::check_cast( static_cast(-2147483648LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 1) ), bsl::UnderflowException ); - - - assert( 2147483647LL - 1== bsl::check_cast( static_cast(2147483647LL - 1) ) ) ; - assert( 2147483647LL == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 1) ), bsl::OverflowException ); - - //signed char -> int - //int -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - //unsigned long long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //size_t -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned int -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //short -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //unsigned short -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //long long -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 255LL - 1== bsl::check_cast( static_cast(255LL - 1) ) ) ; - assert( 255LL == bsl::check_cast( static_cast(255LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned char - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //size_t -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //unsigned int -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //short -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //signed char -> unsigned long long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned char -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned long long -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //char -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //unsigned long -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //size_t -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned int -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //short -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned short -> char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long long -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //signed char -> char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //int -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //size_t -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //unsigned int -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //short -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //signed char -> unsigned long - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //size_t -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 18446744073709551615ULL - 1== bsl::check_cast( static_cast(18446744073709551615ULL - 1) ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - //unsigned int -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //short -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned short -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //signed char -> size_t - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //size_t -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //unsigned int -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - //short -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //unsigned short -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //long long -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 4294967295LL - 1== bsl::check_cast( static_cast(4294967295LL - 1) ) ) ; - assert( 4294967295LL == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned int - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned char -> short - //unsigned long long -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //char -> short - //unsigned long -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //size_t -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned int -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //short -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - //long -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //unsigned short -> short - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //long long -> short - - assert( -32768LL == bsl::check_cast( static_cast(-32768LL) ) ) ; - assert( -32768LL + 1 == bsl::check_cast( static_cast(-32768LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 1) ), bsl::UnderflowException ); - - - assert( 32767LL - 1== bsl::check_cast( static_cast(32767LL - 1) ) ) ; - assert( 32767LL == bsl::check_cast( static_cast(32767LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 1) ), bsl::OverflowException ); - - //signed char -> short - //int -> long - //unsigned char -> long - //unsigned long long -> long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //char -> long - //unsigned long -> long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //size_t -> long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //unsigned int -> long - //short -> long - //long -> long - - assert( -9223372036854775808.0L == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - assert( -9223372036854775808.0L + 1 == bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ) ) ; - - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - //unsigned short -> long - //long long -> long - - assert( -9223372036854775808.0L == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - assert( -9223372036854775808.0L + 1 == bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ) ) ; - - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - //signed char -> long - //int -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - //unsigned long long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //unsigned long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //size_t -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned int -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //short -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //unsigned short -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - //long long -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - - assert( 65535LL - 1== bsl::check_cast( static_cast(65535LL - 1) ) ) ; - assert( 65535LL == bsl::check_cast( static_cast(65535LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 1) ), bsl::OverflowException ); - - //signed char -> unsigned short - - assert( 0LL == bsl::check_cast( static_cast(0LL) ) ) ; - assert( 0LL + 1 == bsl::check_cast( static_cast(0LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1) ), bsl::UnderflowException ); - - //int -> long long - //unsigned char -> long long - //unsigned long long -> long long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //char -> long long - //unsigned long -> long long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //size_t -> long long - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 1) ), bsl::OverflowException ); - - //unsigned int -> long long - //short -> long long - //long -> long long - - assert( -9223372036854775808.0L == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - assert( -9223372036854775808.0L + 1 == bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ) ) ; - - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - //unsigned short -> long long - //long long -> long long - - assert( -9223372036854775808.0L == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - assert( -9223372036854775808.0L + 1 == bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ) ) ; - - - assert( 9223372036854775807ULL - 1== bsl::check_cast( static_cast(9223372036854775807ULL - 1) ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - //signed char -> long long - //int -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned char -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned long long -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //char -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //unsigned long -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //size_t -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned int -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //short -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //unsigned short -> signed char - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //long long -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 1) ), bsl::UnderflowException ); - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 1) ), bsl::OverflowException ); - - //signed char -> signed char - - assert( -128LL == bsl::check_cast( static_cast(-128LL) ) ) ; - assert( -128LL + 1 == bsl::check_cast( static_cast(-128LL + 1) ) ) ; - - - assert( 127LL - 1== bsl::check_cast( static_cast(127LL - 1) ) ) ; - assert( 127LL == bsl::check_cast( static_cast(127LL) ) ) ; - - //float -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //double -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //long double -> int - - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - int value1 = static_cast( static_cast( -2147483648LL + 2147483.647 ) ); - int value2 = bsl::check_cast( static_cast(-2147483648LL + 2147483.647) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-2147483648LL - 2147483.647) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(2147483647LL + 2147483.647) ), bsl::OverflowException ); - - //float -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //double -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //long double -> unsigned char - - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned char value1 = static_cast( static_cast( 0LL + 0.255 ) ); - unsigned char value2 = bsl::check_cast( static_cast(0LL + 0.255) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 0.255) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(255LL + 0.255) ), bsl::OverflowException ); - - //float -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //double -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //long double -> unsigned long long - - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //float -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //double -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //long double -> char - - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL ) ); - char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //float -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //double -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //long double -> unsigned long - - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned long value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - unsigned long value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //float -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //double -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //long double -> size_t - - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL ) ); - size_t value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - size_t value1 = static_cast( static_cast( 0LL + 1.84467440737e+16 ) ); - size_t value2 = bsl::check_cast( static_cast(0LL + 1.84467440737e+16) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 1.84467440737e+16) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(18446744073709551615ULL + 1.84467440737e+16) ), bsl::OverflowException ); - - //float -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //double -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //long double -> unsigned int - - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned int value1 = static_cast( static_cast( 0LL + 4294967.295 ) ); - unsigned int value2 = bsl::check_cast( static_cast(0LL + 4294967.295) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 4294967.295) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(4294967295LL + 4294967.295) ), bsl::OverflowException ); - - //float -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //double -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //long double -> short - - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL ) ); - short value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - short value1 = static_cast( static_cast( -32768LL + 32.767 ) ); - short value2 = bsl::check_cast( static_cast(-32768LL + 32.767) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-32768LL - 32.767) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(32767LL + 32.767) ), bsl::OverflowException ); - - //float -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //double -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //long double -> long - - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //float -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //double -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //long double -> unsigned short - - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - unsigned short value1 = static_cast( static_cast( 0LL + 65.535 ) ); - unsigned short value2 = bsl::check_cast( static_cast(0LL + 65.535) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(0LL - 65.535) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(65535LL + 65.535) ), bsl::OverflowException ); - - //float -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //double -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //long double -> long long - - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long long value1 = static_cast( static_cast( -9223372036854775808.0L + 9.22337203685e+15 ) ); - long long value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 9.22337203685e+15) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-9223372036854775808.0L - 9.22337203685e+15) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(9223372036854775807ULL + 9.22337203685e+15) ), bsl::OverflowException ); - - //float -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //double -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - //long double -> signed char - - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - signed char value1 = static_cast( static_cast( -128LL + 0.127 ) ); - signed char value2 = bsl::check_cast( static_cast(-128LL + 0.127) ); - assert( value1 == value2 ); - } - - - ASSERT_THROW( bsl::check_cast( static_cast(-128LL - 0.127) ), bsl::UnderflowException ); - - - ASSERT_THROW( bsl::check_cast( static_cast(127LL + 0.127) ), bsl::OverflowException ); - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 2147483647LL ) ); - float value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 2147483647LL ) ); - double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -2147483648LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-2147483648LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 2147483647LL ) ); - long double value2 = bsl::check_cast( static_cast(2147483647LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 255LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 255LL ) ); - float value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 255LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 255LL ) ); - double value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 255LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(255LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 255LL ) ); - long double value2 = bsl::check_cast( static_cast(255LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL ) ); - float value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL ) ); - double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL ) ); - long double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - float value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 18446744073709551615ULL ) ); - long double value2 = bsl::check_cast( static_cast(18446744073709551615ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 4294967295LL ) ); - float value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 4294967295LL ) ); - double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 4294967295LL ) ); - long double value2 = bsl::check_cast( static_cast(4294967295LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -32768LL ) ); - float value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -32768LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 32767LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 32767LL ) ); - float value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -32768LL ) ); - double value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -32768LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 32767LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 32767LL ) ); - double value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -32768LL ) ); - long double value2 = bsl::check_cast( static_cast(-32768LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -32768LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-32768LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 32767LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(32767LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 32767LL ) ); - long double value2 = bsl::check_cast( static_cast(32767LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL ) ); - float value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 0LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 65535LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 65535LL ) ); - float value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL ) ); - double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 0LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 65535LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 65535LL ) ); - double value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL ) ); - long double value2 = bsl::check_cast( static_cast(0LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 0LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(0LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 65535LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(65535LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 65535LL ) ); - long double value2 = bsl::check_cast( static_cast(65535LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL ) ); - float value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -128LL + 1 ) ); - float value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL - 1 ) ); - float value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 127LL ) ); - float value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL ) ); - double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -128LL + 1 ) ); - double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL - 1 ) ); - double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 127LL ) ); - double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL ) ); - long double value2 = bsl::check_cast( static_cast(-128LL ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -128LL + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-128LL + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(127LL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 127LL ) ); - long double value2 = bsl::check_cast( static_cast(127LL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - float value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - float value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - float value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( -9223372036854775808.0L + 1 ) ); - long double value2 = bsl::check_cast( static_cast(-9223372036854775808.0L + 1) ); - assert( value1 == value2 ); - } - - - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL - 1 ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL - 1) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - long double value1 = static_cast( static_cast( 9223372036854775807ULL ) ); - long double value2 = bsl::check_cast( static_cast(9223372036854775807ULL ) ); - assert( value1 == value2 ); - } - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648LL") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647LL") ) ) ; - - - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - assert( -2147483648LL == bsl::check_cast( const_cast("-2147483648") ) ) ; - - - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - assert( 2147483647LL == bsl::check_cast( const_cast("2147483647") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647LL") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646LL") ) ) ; - - - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - assert( -2147483647LL == bsl::check_cast( const_cast("-2147483647") ) ) ; - - - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - assert( 2147483646LL == bsl::check_cast( const_cast("2147483646") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-2147483649") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("2147483648") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 255LL == bsl::check_cast( const_cast("255LL") ) ) ; - assert( 255LL == bsl::check_cast( const_cast("255LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 255LL == bsl::check_cast( const_cast("255") ) ) ; - assert( 255LL == bsl::check_cast( const_cast("255") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 254LL == bsl::check_cast( const_cast("254LL") ) ) ; - assert( 254LL == bsl::check_cast( const_cast("254LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 254LL == bsl::check_cast( const_cast("254") ) ) ; - assert( 254LL == bsl::check_cast( const_cast("254") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("256LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("256LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("256") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("256") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615ULL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - assert( 18446744073709551615ULL == bsl::check_cast( const_cast("18446744073709551615") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614ULL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - assert( 18446744073709551614ULL == bsl::check_cast( const_cast("18446744073709551614") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("18446744073709551616") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - assert( 4294967295LL == bsl::check_cast( const_cast("4294967295") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - assert( 4294967294LL == bsl::check_cast( const_cast("4294967294") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("4294967296") ), bsl::OverflowException ); - - - assert( -32768LL == bsl::check_cast( const_cast("-32768LL") ) ) ; - assert( -32768LL == bsl::check_cast( const_cast("-32768LL") ) ) ; - - - assert( 32767LL == bsl::check_cast( const_cast("32767LL") ) ) ; - assert( 32767LL == bsl::check_cast( const_cast("32767LL") ) ) ; - - - assert( -32768LL == bsl::check_cast( const_cast("-32768") ) ) ; - assert( -32768LL == bsl::check_cast( const_cast("-32768") ) ) ; - - - assert( 32767LL == bsl::check_cast( const_cast("32767") ) ) ; - assert( 32767LL == bsl::check_cast( const_cast("32767") ) ) ; - - - assert( -32767LL == bsl::check_cast( const_cast("-32767LL") ) ) ; - assert( -32767LL == bsl::check_cast( const_cast("-32767LL") ) ) ; - - - assert( 32766LL == bsl::check_cast( const_cast("32766LL") ) ) ; - assert( 32766LL == bsl::check_cast( const_cast("32766LL") ) ) ; - - - assert( -32767LL == bsl::check_cast( const_cast("-32767") ) ) ; - assert( -32767LL == bsl::check_cast( const_cast("-32767") ) ) ; - - - assert( 32766LL == bsl::check_cast( const_cast("32766") ) ) ; - assert( 32766LL == bsl::check_cast( const_cast("32766") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-32769LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-32769LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("32768LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("32768LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-32769") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-32769") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("32768") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("32768") ), bsl::OverflowException ); - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - - - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0LL") ) ) ; - - - assert( 65535LL == bsl::check_cast( const_cast("65535LL") ) ) ; - assert( 65535LL == bsl::check_cast( const_cast("65535LL") ) ) ; - - - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - assert( 0LL == bsl::check_cast( const_cast("0") ) ) ; - - - assert( 65535LL == bsl::check_cast( const_cast("65535") ) ) ; - assert( 65535LL == bsl::check_cast( const_cast("65535") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1LL") ) ) ; - - - assert( 65534LL == bsl::check_cast( const_cast("65534LL") ) ) ; - assert( 65534LL == bsl::check_cast( const_cast("65534LL") ) ) ; - - - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - assert( 1LL == bsl::check_cast( const_cast("1") ) ) ; - - - assert( 65534LL == bsl::check_cast( const_cast("65534") ) ) ; - assert( 65534LL == bsl::check_cast( const_cast("65534") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("65536LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("65536LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-1") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("65536") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("65536") ), bsl::OverflowException ); - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808.0L") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807ULL") ) ) ; - - - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - assert( -9223372036854775808.0L == bsl::check_cast( const_cast("-9223372036854775808") ) ) ; - - - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - assert( 9223372036854775807ULL == bsl::check_cast( const_cast("9223372036854775807") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807LL") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806LL") ) ) ; - - - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - assert( -9223372036854775807LL == bsl::check_cast( const_cast("-9223372036854775807") ) ) ; - - - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - assert( 9223372036854775806LL == bsl::check_cast( const_cast("9223372036854775806") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809.0L") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808ULL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-9223372036854775809") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("9223372036854775808") ), bsl::OverflowException ); - - - assert( -128LL == bsl::check_cast( const_cast("-128LL") ) ) ; - assert( -128LL == bsl::check_cast( const_cast("-128LL") ) ) ; - - - assert( 127LL == bsl::check_cast( const_cast("127LL") ) ) ; - assert( 127LL == bsl::check_cast( const_cast("127LL") ) ) ; - - - assert( -128LL == bsl::check_cast( const_cast("-128") ) ) ; - assert( -128LL == bsl::check_cast( const_cast("-128") ) ) ; - - - assert( 127LL == bsl::check_cast( const_cast("127") ) ) ; - assert( 127LL == bsl::check_cast( const_cast("127") ) ) ; - - - assert( -127LL == bsl::check_cast( const_cast("-127LL") ) ) ; - assert( -127LL == bsl::check_cast( const_cast("-127LL") ) ) ; - - - assert( 126LL == bsl::check_cast( const_cast("126LL") ) ) ; - assert( 126LL == bsl::check_cast( const_cast("126LL") ) ) ; - - - assert( -127LL == bsl::check_cast( const_cast("-127") ) ) ; - assert( -127LL == bsl::check_cast( const_cast("-127") ) ) ; - - - assert( 126LL == bsl::check_cast( const_cast("126") ) ) ; - assert( 126LL == bsl::check_cast( const_cast("126") ) ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("-129LL") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-129LL") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("128LL") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("128LL") ), bsl::OverflowException ); - - - ASSERT_THROW( bsl::check_cast( const_cast("-129") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast( const_cast("-129") ), bsl::UnderflowException ) ; - - - ASSERT_THROW( bsl::check_cast( const_cast("128") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast( const_cast("128") ), bsl::OverflowException ); - - - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - - - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - assert( '0' == bsl::check_cast( const_cast("0") ) ) ; - - - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - - - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - assert( '\0' == bsl::check_cast( const_cast("\0") ) ) ; - - - { - //avoid floating-point number errors - float value1 = -2147483648LL; - float value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - float value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = 2147483647LL; - float value2 = bsl::check_cast( const_cast("2147483647LL") ); - float value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = -2147483648LL; - float value2 = bsl::check_cast( const_cast("-2147483648") ) ; - float value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - float value1 = 2147483647LL; - float value2 = bsl::check_cast( const_cast("2147483647") ); - float value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = -2147483648LL; - double value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - double value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = 2147483647LL; - double value2 = bsl::check_cast( const_cast("2147483647LL") ); - double value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = -2147483648LL; - double value2 = bsl::check_cast( const_cast("-2147483648") ) ; - double value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - double value1 = 2147483647LL; - double value2 = bsl::check_cast( const_cast("2147483647") ); - double value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = -2147483648LL; - long double value2 = bsl::check_cast( const_cast("-2147483648LL") ) ; - long double value3 = bsl::check_cast( const_cast("-2147483648LL") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = 2147483647LL; - long double value2 = bsl::check_cast( const_cast("2147483647LL") ); - long double value3 = bsl::check_cast( const_cast("2147483647LL") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = -2147483648LL; - long double value2 = bsl::check_cast( const_cast("-2147483648") ) ; - long double value3 = bsl::check_cast( const_cast("-2147483648") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - { - //avoid floating-point number errors - long double value1 = 2147483647LL; - long double value2 = bsl::check_cast( const_cast("2147483647") ); - long double value3 = bsl::check_cast( const_cast("2147483647") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } - - - assert( "-2147483648" == bsl::check_cast( static_cast(-2147483648LL) ) ) ; - - - assert( "-2147483647" == bsl::check_cast( static_cast(-2147483647LL) ) ) ; - - - assert( "2147483647" == bsl::check_cast( static_cast(2147483647LL) ) ) ; - - - assert( "2147483646" == bsl::check_cast( static_cast(2147483646LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "255" == bsl::check_cast( static_cast(255LL) ) ) ; - - - assert( "254" == bsl::check_cast( static_cast(254LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "18446744073709551615" == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - - assert( "18446744073709551614" == bsl::check_cast( static_cast(18446744073709551614ULL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "18446744073709551615" == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - - assert( "18446744073709551614" == bsl::check_cast( static_cast(18446744073709551614ULL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "18446744073709551615" == bsl::check_cast( static_cast(18446744073709551615ULL) ) ) ; - - - assert( "18446744073709551614" == bsl::check_cast( static_cast(18446744073709551614ULL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "4294967295" == bsl::check_cast( static_cast(4294967295LL) ) ) ; - - - assert( "4294967294" == bsl::check_cast( static_cast(4294967294LL) ) ) ; - - - assert( "-32768" == bsl::check_cast( static_cast(-32768LL) ) ) ; - - - assert( "-32767" == bsl::check_cast( static_cast(-32767LL) ) ) ; - - - assert( "32767" == bsl::check_cast( static_cast(32767LL) ) ) ; - - - assert( "32766" == bsl::check_cast( static_cast(32766LL) ) ) ; - - - assert( "-9223372036854775808" == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - - - assert( "-9223372036854775807" == bsl::check_cast( static_cast(-9223372036854775807LL) ) ) ; - - - assert( "9223372036854775807" == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - assert( "9223372036854775806" == bsl::check_cast( static_cast(9223372036854775806LL) ) ) ; - - - assert( "0" == bsl::check_cast( static_cast(0LL) ) ) ; - - - assert( "1" == bsl::check_cast( static_cast(1LL) ) ) ; - - - assert( "65535" == bsl::check_cast( static_cast(65535LL) ) ) ; - - - assert( "65534" == bsl::check_cast( static_cast(65534LL) ) ) ; - - - assert( "-9223372036854775808" == bsl::check_cast( static_cast(-9223372036854775808.0L) ) ) ; - - - assert( "-9223372036854775807" == bsl::check_cast( static_cast(-9223372036854775807LL) ) ) ; - - - assert( "9223372036854775807" == bsl::check_cast( static_cast(9223372036854775807ULL) ) ) ; - - - assert( "9223372036854775806" == bsl::check_cast( static_cast(9223372036854775806LL) ) ) ; - - - assert( "-128" == bsl::check_cast( static_cast(-128LL) ) ) ; - - - assert( "-127" == bsl::check_cast( static_cast(-127LL) ) ) ; - - - assert( "127" == bsl::check_cast( static_cast(127LL) ) ) ; - - - assert( "126" == bsl::check_cast( static_cast(126LL) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "-1234.5" == bsl::check_cast( static_cast(-1234.5) ) ) ; - - - assert( "1.234e+12" == bsl::check_cast( static_cast(1.234e+12) ) ) ; - - - assert( "A" == bsl::check_cast( static_cast('A') ) ) ; - -#endif - - return 0; -} - diff --git a/bsl/var/unittest/test_check_cast_gen.py b/bsl/var/unittest/test_check_cast_gen.py deleted file mode 100755 index af875231ca22db9c9cdc54e05211d6d778de2d79..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_check_cast_gen.py +++ /dev/null @@ -1,343 +0,0 @@ -#!/usr/bin/env python -INF = float('inf') - -SUFFIX = { - 'long': 'L', - 'long long': 'LL', - 'unsigned int': 'U', - 'unsigned long': 'UL', - 'unsigned long long': 'ULL', - 'float': '.0', - 'double': '.0', - 'long double': '.0L', - 'size_t': 'UL', - #'ptrdiff_t': 'L' -} - -MIN_32 = { - 'char': -2**7, 'signed char': -2**7, 'short': -2**15, 'int': -2**31, 'long': -2**31, 'long long': -2**63, - 'unsigned char': 0, 'unsigned short': 0, 'unsigned int': 0, 'unsigned long': 0, 'unsigned long long': 0, - 'size_t': 0, #'ptrdiff_t': -2**31 -# 'float': -INF, 'double': -INF, 'long double': -INF -} - -MAX_32 = { - 'char': 2**7-1, 'signed char' : 2**7-1, 'short': 2**15-1, 'int': 2**31-1, 'long': 2**31-1, 'long long': 2**63-1, - 'unsigned char': 2**8-1, 'unsigned short': 2**16-1, 'unsigned int': 2**32-1, 'unsigned long': 2**32-1, 'unsigned long long': 2**64-1, - 'size_t': 2**32-1, #'ptrdiff_t': 2**31-1 -# 'float': INF, 'double': INF, 'long double': INF -} - -MIN_64 = dict(MIN_32) -MIN_64['ptrdiff_t'] = MIN_64['long'] = MIN_64['long long'] - -MAX_64 = dict(MAX_32) -MAX_64['ptrdiff_t'] = MAX_64['long'] = MAX_64['long long'] -MAX_64['size_t'] = MAX_64['unsigned long'] = MAX_64['unsigned long long'] - -INT_TYPES = MIN_32.keys() - -FLOAT_TYPES = [ 'float', 'double', 'long double' ] - -HEADER = """ -#include -#include "bsl/check_cast.h" - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<( static_cast<%(src_type)s>(%(min)s) ) ) ; - assert( %(min)s + %(offset)s == bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(min)s + %(offset)s) ) ) ; -""" - -MIN_FLOAT_TEMPLATE = """ - { - //avoid floating-point number errors - %(dest_type)s value1 = static_cast<%(dest_type)s>( static_cast<%(src_type)s>( %(min)s ) ); - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(min)s ) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - %(dest_type)s value1 = static_cast<%(dest_type)s>( static_cast<%(src_type)s>( %(min)s + %(offset)s ) ); - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(min)s + %(offset)s) ); - assert( value1 == value2 ); - } -""" - -UNDERFLOW_TEMPLATE = """ - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(min)s - %(offset)s) ), bsl::UnderflowException ); -""" - -MAX_TEMPLATE = """ - assert( %(max)s - %(offset)s== bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(max)s - %(offset)s) ) ) ; - assert( %(max)s == bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(max)s) ) ) ; -""" - -MAX_FLOAT_TEMPLATE = """ - { - //avoid floating-point number errors - %(dest_type)s value1 = static_cast<%(dest_type)s>( static_cast<%(src_type)s>( %(max)s - %(offset)s ) ); - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(max)s - %(offset)s) ); - assert( value1 == value2 ); - } - { - //avoid floating-point number errors - %(dest_type)s value1 = static_cast<%(dest_type)s>( static_cast<%(src_type)s>( %(max)s ) ); - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(max)s ) ); - assert( value1 == value2 ); - } -""" - -OVERFLOW_TEMPLATE = """ - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( static_cast<%(src_type)s>(%(max)s + %(offset)s) ), bsl::OverflowException ); -""" - -MIN_CSTR_TEMPLATE = """ - assert( %(min)s == bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ) ) ; - assert( %(min)s == bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ) ) ; -""" - -MIN_CSTR_FLOAT_TEMPLATE = """ - { - //avoid floating-point number errors - %(dest_type)s value1 = %(min)s; - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ) ; - %(dest_type)s value3 = bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ) ; - assert( value1 == value2 ); - assert( value1 == value3 ); - } -""" - -UNDERFLOW_CSTR_TEMPLATE = """ - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ), bsl::UnderflowException ) ; - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( const_cast("%(min_str)s") ), bsl::UnderflowException ) ; -""" - -MAX_CSTR_TEMPLATE = """ - assert( %(max)s == bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ) ) ; - assert( %(max)s == bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ) ) ; -""" - -MAX_CSTR_FLOAT_TEMPLATE = """ - { - //avoid floating-point number errors - %(dest_type)s value1 = %(max)s; - %(dest_type)s value2 = bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ); - %(dest_type)s value3 = bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ); - assert( value1 == value2 ); - assert( value1 == value3 ); - } -""" - -OVERFLOW_CSTR_TEMPLATE = """ - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ), bsl::OverflowException ); - ASSERT_THROW( bsl::check_cast<%(dest_type)s>( const_cast("%(max_str)s") ), bsl::OverflowException ); -""" - - -TO_BSL_STR_TEMPLATE = """ - assert( "%(res)s" == bsl::check_cast( static_cast<%(src_type)s>(%(value)s) ) ) ; -""" - -def literal(num): - return str(num) + ( 'ULL' if num >= MAX_32['long long'] else '.0L' if num <= MIN_32['long long'] else 'LL' ) ; - -if __name__ == "__main__": - print HEADER - print '#if __WORDSIZE == 32' - for (MIN, MAX) in [ (MIN_32, MAX_32), (MIN_64, MAX_64) ]: - if MIN == MIN_64: - print '#else' - # INT_TYPES -> INT_TYPES - for dest_type in INT_TYPES: - for src_type in INT_TYPES: - min = literal(MIN[dest_type]) - max = literal(MAX[dest_type]) - offset = '1' - print ''.join(['\t\t//', src_type, ' -> ', dest_type]) - if MIN[src_type] <= MIN[dest_type] and MIN[dest_type] != -INF: - print MIN_TEMPLATE % locals() - if MIN[src_type] < MIN[dest_type]: - print UNDERFLOW_TEMPLATE% locals() - if MAX[src_type] >= MAX[dest_type] and MAX[dest_type] != INF: - print MAX_TEMPLATE % locals() - if MAX[src_type] > MAX[dest_type]: - print OVERFLOW_TEMPLATE % locals() - - # FLOAT_TYPES -> INT_TYPES - for dest_type in INT_TYPES: - for src_type in FLOAT_TYPES: - min = literal(MIN[dest_type]) - max = literal(MAX[dest_type]) - offset = str(MAX[dest_type]*0.001) - print ''.join(['\t\t//', src_type, ' -> ', dest_type]) - print MIN_FLOAT_TEMPLATE % locals() - print UNDERFLOW_TEMPLATE% locals() - #some has Overflow problem caused by floating-point errors - #print MAX_FLOAT_TEMPLATE % locals() - print OVERFLOW_TEMPLATE % locals() - - #special for Overflow problems - max = literal(MAX[dest_type]) - offset = '1' - dest_type = 'float' - for src_type in [ 'char', 'unsigned char', 'short', 'unsigned short' ]: - print MAX_FLOAT_TEMPLATE % locals() - - dest_type = 'double' - for src_type in INT_TYPES: - if src_type not in [ 'long long', 'unsigned long long' ]: - print MAX_FLOAT_TEMPLATE % locals() - - dest_type = 'long double' - for src_type in INT_TYPES: - if src_type not in [ 'unsigned long long' ]: - print MAX_FLOAT_TEMPLATE % locals() - - - # INT_TYPES -> FLOAT_TYPES - # always pass - for src_type in INT_TYPES: - for dest_type in FLOAT_TYPES: - min = literal(MIN[src_type]) - max = literal(MAX[src_type]) - offset = 1 - print MIN_FLOAT_TEMPLATE % locals() - print MAX_FLOAT_TEMPLATE % locals() - - # FLOAT_TYPES -> FLOAT_TYPES - for src_type in FLOAT_TYPES: - for dest_type in FLOAT_TYPES: - min = literal(MIN['long long']) - max = literal(MAX['long long']) - offset = 1 - print MIN_FLOAT_TEMPLATE % locals() - print MAX_FLOAT_TEMPLATE % locals() - - # C string -> INT_TYPES except CHAR_TYPES - for dest_type in INT_TYPES: - if dest_type not in ['char']: - min = literal(MIN[dest_type]) - max = literal(MAX[dest_type]) - min_str = min - max_str = max - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - min_str = str(MIN[dest_type]) #no suffix - max_str = str(MAX[dest_type]) #no suffix - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - - min = literal(MIN[dest_type] + 1) - max = literal(MAX[dest_type] - 1) - min_str = min - max_str = max - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - min_str = str(MIN[dest_type] + 1) #no suffix - max_str = str(MAX[dest_type] - 1) #no suffix - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - - min = literal(MIN[dest_type] - 1) - max = literal(MAX[dest_type] + 1) - min_str = min - max_str = max - print UNDERFLOW_CSTR_TEMPLATE % locals() - print OVERFLOW_CSTR_TEMPLATE % locals() - min_str = str(MIN[dest_type] - 1) #no suffix - max_str = str(MAX[dest_type] + 1) #no suffix - print UNDERFLOW_CSTR_TEMPLATE % locals() - print OVERFLOW_CSTR_TEMPLATE % locals() - - # C string -> CHAR_TYPES - for dest_type in ['char']: - min = "'0'" - max = "'0'" - min_str = "0" - max_str = "0" - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - - min = "'\\0'" - max = "'\\0'" - min_str = "\\0" - max_str = "\\0" - print MIN_CSTR_TEMPLATE % locals() - print MAX_CSTR_TEMPLATE % locals() - - # C string -> FLOAT_TYPES - for dest_type in FLOAT_TYPES: - min = str(MIN['int'])+'LL' - max = str(MAX['int'])+'LL' - min_str = min - max_str = max - print MIN_CSTR_FLOAT_TEMPLATE % locals() - print MAX_CSTR_FLOAT_TEMPLATE % locals() - min_str = str(MIN['int']) - max_str = str(MAX['int']) - print MIN_CSTR_FLOAT_TEMPLATE % locals() - print MAX_CSTR_FLOAT_TEMPLATE % locals() - - # INT_TYPES -> bsl::string - for src_type in INT_TYPES: - if src_type not in [ 'char' ]: - value = literal(MIN[src_type]) - res = str(MIN[src_type]) - print TO_BSL_STR_TEMPLATE % locals() - value = literal(MIN[src_type] + 1) - res = str(MIN[src_type] + 1) - print TO_BSL_STR_TEMPLATE % locals() - value = literal(MAX[src_type]) - res = str(MAX[src_type]) - print TO_BSL_STR_TEMPLATE % locals() - value = literal(MAX[src_type] - 1) - res = str(MAX[src_type] - 1) - print TO_BSL_STR_TEMPLATE % locals() - - # FLOAT_TYPES -> bsl::string - for src_type in FLOAT_TYPES: - value = res = "-1234.5" - print TO_BSL_STR_TEMPLATE % locals() - value = res = "1.234e+12" - print TO_BSL_STR_TEMPLATE % locals() - - # CHAR_TYPES -> bsl::string - src_type = 'char' - value = "'A'" - res = "A" - print TO_BSL_STR_TEMPLATE % locals() - - print '#endif' - print FOOTER - - - - - - diff --git a/bsl/var/unittest/test_data.json b/bsl/var/unittest/test_data.json deleted file mode 100644 index a85f0bdf2ce6a1aba86e042a3ab4f211f7d70993..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_data.json +++ /dev/null @@ -1,82 +0,0 @@ -# normal tests -# basic text -null -true -false -[] -{} -"" -'' -0 --1 - -# more complicated -#arrays -[[]] -[[],[]] -[[[]],[[[]]]] -[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] - -#numbers -1 -1000000000 -1.2 --3.40 -+0.0012300 --000.444 -1e+06 --1.2e-08 - -#normal strings -"abc" -'abc' -" abc " -' abc ' -# "\tabc\t" -" abc " -' abc ' -#" \t\t\tabc\t " -" abc " -' abc ' -#"\ta\tb\tc\t" -" a b c " -' a b c ' - -#escaped strings -"\"" -'\"' -"\'" -'\'' -"\\" -'\\' -"\/" -'\/' -"\b" -'\b' -"\f" -'\f' -"\n" -'\n' -"\r" -'\r' -"\t" -'\t' -#"一二" -"\u4e00\u4e8c" -'\u4e00\u4e8c' -"一二" -'一二' -#mixed -"\t一二ab\u4e00cd\u4e8c\n" -'\t一二ab\u4e00cd\u4e8c\n' - -#objects -{"":""} -{ '': "" } -{"":{}} - {"" : { } } -{"":{"":{"":{}}}} -{'': { '' : { '' :{ }}}} -{"":{},"null":null,"true":true,"false":false,"1":1,"[]":[],"[[[[]]]]":[[[[]]]]} -{'':{},'null':null,'true':true,'false':false,'1':1,'[]':[],'[[[[]]]]':[[[[]]]]} - diff --git a/bsl/var/unittest/test_data.std b/bsl/var/unittest/test_data.std deleted file mode 100644 index 342a7d361710a1dfa3492286861f64eeef1038a4..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_data.std +++ /dev/null @@ -1,89 +0,0 @@ -# normal tests - -# basic text - -null -1 -0 -[] -{} -"" -"" -0 --1 -# more complicated - -#arrays - -[[]] -[[],[]] -[[[]],[[[]]]] -[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] -#numbers - -1 -1e+09 -1.2 --3.4 -0.00123 --0.444 -1e+06 --1.2e-08 -#normal strings - -"abc" -"abc" -" abc " -" abc " -# "\tabc\t" - -" abc " -" abc " -#" \t\t\tabc\t " - -" abc " -" abc " -#"\ta\tb\tc\t" - -" a b c " -" a b c " -#escaped strings - -"\"" -"\"" -"\"" -"\"" -"\\" -"\\" -"\/" -"\/" -"\b" -"\b" -"\f" -"\f" -"\n" -"\n" -"\r" -"\r" -"\t" -"\t" -#"一二" - -"\u4e00\u4e8c" -"\u4e00\u4e8c" -"\u4e00\u4e8c" -"\u4e00\u4e8c" -#mixed - -"\t\u4e00\u4e8cab\u4e00cd\u4e8c\n" -"\t\u4e00\u4e8cab\u4e00cd\u4e8c\n" -#objects - -{"":""} -{"":""} -{"":{}} -{"":{}} -{"":{"":{"":{}}}} -{"":{"":{"":{}}}} -{"":{},"1":1,"[[[[]]]]":[[[[]]]],"[]":[],"false":0,"null":null,"true":1} -{"":{},"1":1,"[[[[]]]]":[[[[]]]],"[]":[],"false":0,"null":null,"true":1} diff --git a/bsl/var/unittest/test_mcpack.json b/bsl/var/unittest/test_mcpack.json deleted file mode 100644 index a6afc46f7aeb5735d85942cb4fd584f75942a09c..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_mcpack.json +++ /dev/null @@ -1,13 +0,0 @@ -{"k":1} -{"k":"v"} -{"k":0} -{"k":1} -{"k":9} -{"k": {"kk": 99}} -{"k": [77,88,99] } -{"k": 8,"k1":"v"} -{"k": {"kk": 77},"j":[77,88,99],"m": 123} -{"k": {"kk":77,"jj":88},"j":[33,33,55],"m":9,"n":"v"} -{"k": {"kk":{"kkk":"vvv","mmm":[9111,9222,9333]},"nn":93},"m":[81,82,83],"n":0,"w":"v"} -{"k": [{"kk":43,"mm":34},{"aa":[56,23]},{"9k":34}]} - diff --git a/bsl/var/unittest/test_mcpack.std b/bsl/var/unittest/test_mcpack.std deleted file mode 100644 index f9fd4bb6f4194104389db222575f0a8ff48ab362..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_mcpack.std +++ /dev/null @@ -1,60 +0,0 @@ ------ -{"k":1} - -k:1 -{"k":1} ------ -{"k":"v"} - -k:v -{"k":"v"} ------ -{"k":0} - -k:0 -{"k":0} ------ -{"k":1} - -k:1 -{"k":1} ------ -{"k":9} - -k:9 -{"k":9} ------ -{"k": {"kk": 99}} - -k,kk:99 -{"k":{"kk":99}} ------ -{"k": [77,88,99] } - -k:0:77 k:1:88 k:2:99 -{"k":[77,88,99]} ------ -{"k": 8,"k1":"v"} - -k:8 k1:v -{"k":8,"k1":"v"} ------ -{"k": {"kk": 77},"j":[77,88,99],"m": 123} - -j:0:77 j:1:88 j:2:99 k,kk:77 m:123 -{"j":[77,88,99],"k":{"kk":77},"m":123} ------ -{"k": {"kk":77,"jj":88},"j":[33,33,55],"m":9,"n":"v"} - -j:0:33 j:1:33 j:2:55 k,jj:88 k,kk:77 m:9 n:v -{"j":[33,33,55],"k":{"jj":88,"kk":77},"m":9,"n":"v"} ------ -{"k": {"kk":{"kkk":"vvv","mmm":[9111,9222,9333]},"nn":93},"m":[81,82,83],"n":0,"w":"v"} - -k,kk,kkk:vvv k,kk,mmm:0:9111 k,kk,mmm:1:9222 k,kk,mmm:2:9333 k,nn:93 m:0:81 m:1:82 m:2:83 n:0 w:v -{"k":{"kk":{"kkk":"vvv","mmm":[9111,9222,9333]},"nn":93},"m":[81,82,83],"n":0,"w":"v"} ------ -{"k": [{"kk":43,"mm":34},{"aa":[56,23]},{"9k":34}]} - -k:0,kk:43 k:0,mm:34 k:1,aa:0:56 k:1,aa:1:23 k:2,9k:34 -{"k":[{"kk":43,"mm":34},{"aa":[56,23]},{"9k":34}]} diff --git a/bsl/var/unittest/test_perform_array.cpp b/bsl/var/unittest/test_perform_array.cpp deleted file mode 100644 index 2463a15d91e64e73e3e8d8d30b3cb1d6318bddb6..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_perform_array.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_perform_array.cpp,v 1.2 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file test_perform_array.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/10/22 17:27:00 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include -#include -#include -#include "bsl/var/implement.h" - -void test_array_1(){ - int group_size = 1000000; - int array_len = 10; - - bsl::var::Array va; - std::vector ve; - std::deque de; - void * ar[array_len]; - - int va_time = 0; - int va_get_time = 0; - int ve_time = 0; - int de_time = 0; - int ar_time = 0; - - ve.assign( array_len, &ve ); - de.assign( array_len, &de ); - for( int i = 0; i < array_len; ++ i ){ - va[array_len] = va; - ar[array_len] = ar; - } - - int pos = rand() % array_len; - struct timeval b, e; - void * res; - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = &va[pos]; - } - gettimeofday(&e, NULL); - va_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = &va.get(pos); - } - gettimeofday(&e, NULL); - va_get_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = ve[pos]; - } - gettimeofday(&e, NULL); - ve_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = de[pos]; - } - gettimeofday(&e, NULL); - de_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = ar[pos]; - } - gettimeofday(&e, NULL); - ar_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - - printf("group_size:%d array_len:%d\n", group_size, array_len ); - printf("%20s: %dus, %gtimes/s\n", "bsl::var::Array", va_time, 1e6 * group_size / va_time ); - printf("%20s: %dus, %gtimes/s\n", "bsl::var::Array.get()", va_get_time, 1e6 * group_size / va_get_time ); - printf("%20s: %dus, %gtimes/s\n", "std::vector", ve_time, 1e6 * group_size / ve_time ); - printf("%20s: %dus, %gtimes/s\n", "std::deque", de_time, 1e6 * group_size / de_time ); - printf("%20s: %dus, %gtimes/s\n", "void *[]", ar_time, 1e6 * group_size / ar_time ); - -} - -void test_array_2(){ - int group_size = 1000; - int array_len = 10000; - - bsl::var::Array va; - bsl::var::Array va2; - std::vector ve; - std::vector ve2; - std::deque de; - std::deque de2; - void * ar[array_len]; - - int va_time = 0; - int va_get_time = 0; - int va2_time = 0; - int ve_time = 0; - int ve2_time = 0; - int de_time = 0; - int de2_time = 0; - int ar_time = 0; - - ve.reserve( array_len ); - de.resize( array_len ); - va[array_len -1]; //自动增长 - - struct timeval b, e; - - for( int i = 0; i < group_size; ++ i ){ - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - va[j] = va[j-1]; - } - gettimeofday(&e, NULL); - va_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - va.set(j, va.get(j-1)); - } - gettimeofday(&e, NULL); - va_get_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - va2[j] = va2[j-1]; - } - gettimeofday(&e, NULL); - va2_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - ve[j] = ve[j-1]; - } - gettimeofday(&e, NULL); - ve_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - ve2.reserve(j+1); - ve2[j] = ve2[j-1]; - } - gettimeofday(&e, NULL); - ve2_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - de[j] = de[j-1]; - } - gettimeofday(&e, NULL); - de_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - if ( size_t(j) > de2.size() ){ - de2.resize(j+1); - } - de2[j] = de2[j-1]; - } - gettimeofday(&e, NULL); - de2_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - - gettimeofday(&b, NULL); - for( int j = 1; j < array_len; ++ j ){ - ar[j] = ar[j-1]; - } - gettimeofday(&e, NULL); - ar_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - } - - printf("group_size:%d array_len:%d\n", group_size, array_len ); - printf("%20s: %dus, %gtimes/s\n", "bsl::var::Array", va_time, 1e6 * group_size / va_time ); - printf("%20s: %dus, %gtimes/s\n", "bsl::var::Array 2", va2_time, 1e6 * group_size / va2_time ); - printf("%20s: %dus, %gtimes/s\n", "bsl::var::Array.get()", va_get_time, 1e6 * group_size / va_get_time ); - printf("%20s: %dus, %gtimes/s\n", "std::vector", ve_time, 1e6 * group_size / ve_time ); - printf("%20s: %dus, %gtimes/s\n", "std::vector 2", ve2_time, 1e6 * group_size / ve2_time ); - printf("%20s: %dus, %gtimes/s\n", "std::deque", de_time, 1e6 * group_size / de_time ); - printf("%20s: %dus, %gtimes/s\n", "std::deque 2", de2_time, 1e6 * group_size / de2_time ); - printf("%20s: %dus, %gtimes/s\n", "void *[]", ar_time, 1e6 * group_size / ar_time ); - -} - -int main(){ - return 0; - //test_array_1(); - test_array_2(); - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_perform_dict.cpp b/bsl/var/unittest/test_perform_dict.cpp deleted file mode 100644 index 05a0eb07b456afd2f4757861c7085a550cf73cf9..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_perform_dict.cpp +++ /dev/null @@ -1,603 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_perform_dict.cpp,v 1.2 2009/03/09 04:56:42 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file test_perform_dict.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/10/22 17:27:00 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include -#include -#include -#include -#include -#include "bsl/var/implement.h" -const int MAX_STR_LEN = 1000; -const int MAX_DICT_SIZE = 100000; -char cs[MAX_DICT_SIZE+1][MAX_STR_LEN]; -std::string ss[MAX_DICT_SIZE+1]; -bsl::string bs[MAX_DICT_SIZE+1]; - -struct bsl_str_hash_func{ - size_t operator ()( const bsl::string& str ) const { - return __gnu_cxx::__stl_hash_string( str.c_str() ); - } -}; - -struct std_str_hash_func{ - size_t operator ()( const std::string& str ) const { - return __gnu_cxx::__stl_hash_string( str.c_str() ); - } -}; - -char * gen_random_str(char * str, int len ){ - const char BEGIN = 'a'; - const char END = 'z'; - for( int i = 0; i < len; ++ i ){ - str[i] = BEGIN + rand() % (END + 1 - BEGIN ); - } - str[len] = 0; - return str; -} - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("< sssm; //std_str_std_map; - std::map bssm; //bsl_str_std_map; - bsl::hashmap ssbm; - bsl::hashmap bsbm; - __gnu_cxx::hash_map ssgm; //std_str_gnu_map; - __gnu_cxx::hash_map bsgm; //bsl_str_gnu_map; - - ssbm.create(dict_size); //比较豪华的size - bsbm.create(dict_size); //比较豪华的size - - int vd_time = 0; - int vd_get_time = 0; - int sssm_time = 0; - int bssm_time = 0; - int ssbm_time = 0; - int bsbm_time = 0; - int ssgm_time = 0; - int bsgm_time = 0; - - int csbs_time = 0;// time used in char * => bsl::string - int csss_time = 0;// time used in char * => std::string - int loop_time = 0; - - //灌数据 - for( int i = 0; i < dict_size; ++ i ){ - gen_random_str( cs[i], str_len ); - ss[i] = cs[i]; //make std str array - bs[i] = cs[i]; //make bsl str array - vd[bs[i]] = vd; - sssm[ss[i]] = cs[i]; //make dictionarys - ssbm.set(ss[i], cs[i]); - ssgm[ss[i]] = cs[i]; - - bssm[bs[i]] = cs[i]; - bsbm.set(bs[i], cs[i]); - bsgm[bs[i]] = cs[i]; - - } - see( vd.size() ); - see( sssm.size() ); - see( ssbm.size() ); - see( ssgm.size() ); - see( bssm.size() ); - see( bsbm.size() ); - see( bsgm.size() ); - - - for( int i = 0; i < groups; ++ i ){ - int pos = rand() % dict_size; - struct timeval b, e; - void * res; - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = &vd[bs[pos]]; - } - gettimeofday(&e, NULL); - vd_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = &vd.get(bs[pos]); - } - gettimeofday(&e, NULL); - vd_get_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = sssm[ss[pos]]; - } - gettimeofday(&e, NULL); - sssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - ssbm.get(ss[pos],&res); - } - gettimeofday(&e, NULL); - ssbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = ssgm[ss[pos]]; - } - gettimeofday(&e, NULL); - ssgm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = bssm[bs[pos]]; - } - gettimeofday(&e, NULL); - bssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - bsbm.get(bs[i], &res); - } - gettimeofday(&e, NULL); - bsbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - res = bsgm[bs[i]]; - } - gettimeofday(&e, NULL); - bsgm_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - bsl::basic_string > __bs(cs[pos]); - } - gettimeofday(&e, NULL); - csbs_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - std::string __ss(cs[pos]); - } - gettimeofday(&e, NULL); - csss_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - ; - } - gettimeofday(&e, NULL); - loop_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - } - - printf("groups:%d group_size:%d dict_size:%d str_len:%d\n", groups, group_size, dict_size, str_len ); - const char * fmt ="map: %-20s str: %-20s method: %-20s total time: %dus \n" ; - printf(fmt, "bsl::var::Dict", "bsl::string", "operator []", vd_time ); - printf(fmt, "bsl::var::Dict", "bsl::string", "get()", vd_get_time ); - printf(fmt, "std::map", "bsl::string", "operator []", bssm_time ); - printf(fmt, "std::map", "std::string", "operator []", sssm_time ); - printf(fmt, "__gnu_cxx::hash_map", "bsl::string", "operator []", bsgm_time ); - printf(fmt, "__gnu_cxx::hash_map", "std::string", "operator []", ssgm_time ); - printf(fmt, "bsl::hashmap", "bsl::string", "get(k&, v*)", bsbm_time ); - printf(fmt, "bsl::hashmap", "std::string", "get(k&, v*)", ssbm_time ); - printf("char * => bsl::string time:%dus\n", csbs_time ); - printf("char * => std::string time:%dus\n", csss_time ); - printf("empty loop time:%dus\n", loop_time ); - - ssbm.destroy(); - bsbm.destroy(); -} - -void test_dict_iterator( int groups, int group_size, int dict_size, int str_len ){ - - bsl::var::Dict vd; //var_dict; - std::map sssm; //std_str_std_map; - std::map bssm; //bsl_str_std_map; - bsl::hashmap ssbm; - bsl::hashmap bsbm; - __gnu_cxx::hash_map ssgm; //std_str_gnu_map; - __gnu_cxx::hash_map bsgm; //bsl_str_gnu_map; - - ssbm.create(dict_size); //比较豪华的size - bsbm.create(dict_size); //比较豪华的size - - int vd_time = 0; - int sssm_time = 0; - int bssm_time = 0; - int ssbm_time = 0; - int bsbm_time = 0; - int ssgm_time = 0; - int bsgm_time = 0; - - int csbs_time = 0;// time used in char * => bsl::string - int csss_time = 0;// time used in char * => std::string - int loop_time = 0; - - //灌数据 - for( int i = 0; i < dict_size; ++ i ){ - gen_random_str( cs[i], str_len ); - ss[i] = cs[i]; //make std str array - bs[i] = cs[i]; //make bsl str array - vd[bs[i]] = vd; - sssm[ss[i]] = cs[i]; //make dictionarys - ssbm.set(ss[i], cs[i]); - ssgm[ss[i]] = cs[i]; - - bssm[bs[i]] = cs[i]; - bsbm.set(bs[i], cs[i]); - bsgm[bs[i]] = cs[i]; - - } - see( vd.size() ); - see( sssm.size() ); - see( ssbm.size() ); - see( ssgm.size() ); - see( bssm.size() ); - see( bsbm.size() ); - see( bsgm.size() ); - - - for( int i = 0; i < groups; ++ i ){ - int pos = rand() % dict_size; - struct timeval b, e; - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( bsl::var::IVar::dict_iterator iter = vd.dict_begin(); iter != vd.dict_end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - vd_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( std::map::iterator iter = sssm.begin(); iter != sssm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - sssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( bsl::hashmap::iterator iter = ssbm.begin(); iter != ssbm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - ssbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( __gnu_cxx::hash_map::iterator iter = ssgm.begin(); iter != ssgm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - ssgm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( std::map::iterator iter = bssm.begin(); iter != bssm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - bssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( bsl::hashmap::iterator iter = bsbm.begin(); iter != bsbm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - bsbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( __gnu_cxx::hash_map::iterator iter = bsgm.begin(); iter != bsgm.end(); ++ iter ) - ; - } - gettimeofday(&e, NULL); - bsgm_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - bsl::basic_string > __bs(cs[pos]); - } - gettimeofday(&e, NULL); - csbs_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - std::string __ss(cs[pos]); - } - gettimeofday(&e, NULL); - csss_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - ; - } - gettimeofday(&e, NULL); - loop_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - } - - printf("groups:%d group_size:%d dict_size:%d str_len:%d\n", groups, group_size, dict_size, str_len ); - const char * fmt ="map: %-20s str: %-20s total time: %dus \n" ; - printf(fmt, "bsl::var::Dict", "bsl::string", vd_time ); - printf(fmt, "std::map", "bsl::string", bssm_time ); - printf(fmt, "std::map", "std::string", sssm_time ); - printf(fmt, "__gnu_cxx::hash_map", "bsl::string", bsgm_time ); - printf(fmt, "__gnu_cxx::hash_map", "std::string", ssgm_time ); - printf(fmt, "bsl::hashmap", "bsl::string", bsbm_time ); - printf(fmt, "bsl::hashmap", "std::string", ssbm_time ); - - ssbm.destroy(); - bsbm.destroy(); -} - - -void test_dict_insert( int groups, int group_size, int dict_size, int str_len ){ - - bsl::var::Dict vd; //var_dict; - std::map sssm; //std_str_std_map; - std::map bssm; //bsl_str_std_map; - bsl::hashmap ssbm; - bsl::hashmap bsbm; - __gnu_cxx::hash_map ssgm; //std_str_gnu_map; - __gnu_cxx::hash_map bsgm; //bsl_str_gnu_map; - - ssbm.create(dict_size); //比较豪华的size - bsbm.create(dict_size); //比较豪华的size - - int vd_time = 0; - int sssm_time = 0; - int bssm_time = 0; - int ssbm_time = 0; - int bsbm_time = 0; - int ssgm_time = 0; - int bsgm_time = 0; - - int csbs_time = 0;// time used in char * => bsl::string - int csss_time = 0;// time used in char * => std::string - int loop_time = 0; - - //灌数据 - for( int i = 0; i < dict_size; ++ i ){ - gen_random_str( cs[i], str_len ); - ss[i] = cs[i]; //make std str array - bs[i] = cs[i]; //make bsl str array - /* - vd[bs[i]] = vd; - sssm[ss[i]] = cs[i]; //make dictionarys - ssbm.set(ss[i], cs[i]); - ssgm[ss[i]] = cs[i]; - - bssm[bs[i]] = cs[i]; - bsbm.set(bs[i], cs[i]); - bsgm[bs[i]] = cs[i]; - */ - - } - - for( int i = 0; i < groups; ++ i ){ - int pos = rand() % dict_size; - struct timeval b, e; - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - vd[bs[k]] = vd; - } - vd.clear(); - } - gettimeofday(&e, NULL); - vd_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k< dict_size; ++ k ){ - sssm[ss[i]] = cs[i]; - } - sssm.clear(); - } - gettimeofday(&e, NULL); - sssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - ssbm.set(ss[i], cs[i]); - } - ssbm.clear(); - } - gettimeofday(&e, NULL); - ssbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - ssgm[ss[i]] = cs[i]; - } - ssgm.clear(); - } - gettimeofday(&e, NULL); - ssgm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - bssm[bs[i]] = cs[i]; - } - bssm.clear(); - } - gettimeofday(&e, NULL); - bssm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - bsbm.set(bs[i], cs[i]); - } - bsbm.clear(); - } - gettimeofday(&e, NULL); - bsbm_time += (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - for( int k = 0; k < dict_size; ++ k ){ - bsgm[bs[i]] = cs[i]; - } - bsgm.clear(); - } - gettimeofday(&e, NULL); - bsgm_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - bsl::basic_string > __bs(cs[pos]); - } - gettimeofday(&e, NULL); - csbs_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - std::string __ss(cs[pos]); - } - gettimeofday(&e, NULL); - csss_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - gettimeofday(&b, NULL); - for( int j = 0; j < group_size; ++ j ){ - ; - } - gettimeofday(&e, NULL); - loop_time+= (e.tv_sec - b.tv_sec) * 1000000 + (e.tv_usec - b.tv_usec ); - - } - - printf("groups:%d group_size:%d dict_size:%d str_len:%d\n", groups, group_size, dict_size, str_len ); - const char * fmt ="map: %-20s str: %-20s total time: %dus \n" ; - printf(fmt, "bsl::var::Dict", "bsl::string", vd_time ); - printf(fmt, "std::map", "bsl::string", bssm_time ); - printf(fmt, "std::map", "std::string", sssm_time ); - printf(fmt, "__gnu_cxx::hash_map", "bsl::string", bsgm_time ); - printf(fmt, "__gnu_cxx::hash_map", "std::string", ssgm_time ); - printf(fmt, "bsl::hashmap", "bsl::string", bsbm_time ); - printf(fmt, "bsl::hashmap", "std::string", ssbm_time ); - - ssbm.destroy(); - bsbm.destroy(); -} -int usage(){ - fprintf( stderr, "usage:\n./test_perform_dict [random|iterator|insert] [groups] [group_size] [dict_size(<=%d)] [str_len(<%d)]\n", - MAX_DICT_SIZE, MAX_STR_LEN); - return 0; -} - -int timval_diff( const timeval& begin, const timeval& end ){ - return ( end.tv_sec - begin.tv_sec ) * 100 * 10000 + ( end.tv_usec - begin.tv_usec ); -} - -int string_compare( ){ - struct timeval b,e; - char s[100001]; - memset(s,'a',sizeof(s)); - s[100000] = 0; - - gettimeofday(&b,NULL); - std::string ss1(s), ss2(s); - gettimeofday(&e,NULL); - printf("std::string::string(): %dus\n", timval_diff( b, e ) ); - - gettimeofday(&b,NULL); - bsl::string bs1(s), bs2(s); - gettimeofday(&e,NULL); - - printf("bsl::string::string(): %dus\n", timval_diff( b, e ) ); - - gettimeofday(&b,NULL); - ss1 == ss2; - gettimeofday(&e,NULL); - - printf("std::string::operator ==: %dus\n", timval_diff( b, e ) ); - - gettimeofday(&b,NULL); - bs1 == bs2; - gettimeofday(&e,NULL); - - printf("bsl::string::operator ==: %dus\n", timval_diff( b, e ) ); - - gettimeofday(&b,NULL); - assert(!memcmp( bs1.c_str(), bs2.c_str(), bs1.length() )); - gettimeofday(&e,NULL); - - printf("memcmp: %dus\n", timval_diff( b, e ) ); - - return 0; -} - -int main(int argc, char *argv[]){ - - if ( argc < 2 ){ - return usage(); - } - int groups, group_size, dict_size, str_len; - if ( 0 == strcmp(argv[1], "random") ){ - if ( argc < 6 ){ - return usage(); - } - sscanf( argv[2], "%d", &groups ); - sscanf( argv[3], "%d", &group_size ); - sscanf( argv[4], "%d", &dict_size ); - sscanf( argv[5], "%d", &str_len ); - test_dict_random( groups, group_size, dict_size, str_len ); - return 0; - }else if ( 0 == strcmp( argv[1], "iterator" ) ){ - if ( argc < 6 ){ - return usage(); - } - sscanf( argv[2], "%d", &groups ); - sscanf( argv[3], "%d", &group_size ); - sscanf( argv[4], "%d", &dict_size ); - sscanf( argv[5], "%d", &str_len ); - test_dict_iterator( groups, group_size, dict_size, str_len ); - return 0; - - }else if ( 0 == strcmp( argv[1], "insert" ) ){ - if ( argc < 6 ){ - return usage(); - } - sscanf( argv[2], "%d", &groups ); - sscanf( argv[3], "%d", &group_size ); - sscanf( argv[4], "%d", &dict_size ); - sscanf( argv[5], "%d", &str_len ); - test_dict_insert( groups, group_size, dict_size, str_len ); - return 0; - - }else{ - return usage(); - } - -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Array.cpp b/bsl/var/unittest/test_var_Array.cpp deleted file mode 100644 index 06f7a5b0633d8bcead93aa2beff3296910d1abbe..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Array.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Array.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarArray.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 13:35:54 - * @version $Revision: 1.4 $ - * @brief - * - **/ - -#include "test_var_invalid.h" - -class TestVarArray: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarArray(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::Array arr1; - bsl::var::Int32 i32(123); - arr1[100] = i32; - bsl::var::Array arr2(arr1); - assert( arr2.size() == arr1.size() ); - assert( arr2[100].to_int32() == 123 ); - } - - //assign - { - bsl::var::Array arr1; - bsl::var::Int32 i32(123); - arr1[100] = i32; - bsl::var::Array arr2; - arr2 = arr1; - assert( arr2.size() == arr1.size() ); - assert( arr2[100].to_int32() == 123 ); - } - - } - virtual void test_mask(){ - test_mask_consistency( bsl::var::Array() ); - } - //methods for all - virtual void test_size() { - { - assert( bsl::var::Array().size() == 0 ); - } - { - bsl::var::Array arr; - arr[100] = bsl::var::Null::null; - assert( arr.size() == 101 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Array arr; - arr.clear(); //assert no-throw - assert(arr.size() == 0); - } - } - - virtual void test_dump() { - stub(); - } - - virtual void test_to_string() { - stub(); - } - - virtual void test_get_type() { - assert( bsl::var::Array().get_type() == string_type("bsl::var::BasicArray") ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Int32 i0(0),i1(1),i2(2); - bsl::var::Array arr; - arr[0] = i0; - arr[1] = i1; - arr[2] = i2; - - //shallow clone - { - bsl::var::Array& rep = arr.clone(rp); - assert( rep.size() == arr.size() ); - assert( rep[0].to_int32() == i0.to_int32() ); - assert( rep[1].to_int32() == i1.to_int32() ); - assert( rep[2].to_int32() == i2.to_int32() ); - assert( &bsl::var::Ref(rep[0]).ref() == &i0 ); - assert( &bsl::var::Ref(rep[1]).ref() == &i1 ); - assert( &bsl::var::Ref(rep[2]).ref() == &i2 ); - } - //deep clone - { - bsl::var::Array& rep = arr.clone(rp, true); - assert( rep.size() == arr.size() ); - assert( rep[0].to_int32() == i0.to_int32() ); - assert( rep[1].to_int32() == i1.to_int32() ); - assert( rep[2].to_int32() == i2.to_int32() ); - assert( &bsl::var::Ref(rep[0]).ref() != &i0 ); - assert( &bsl::var::Ref(rep[1]).ref() != &i1 ); - assert( &bsl::var::Ref(rep[2]).ref() != &i2 ); - } - } - - virtual void test_bool(){ - test_invalid_bool(_arr); - } - - virtual void test_raw(){ - test_invalid_raw(_arr); - } - - virtual void test_number(){ - test_invalid_number(_arr); - } - - virtual void test_string(){ - test_invalid_string(_arr); - } - - virtual void test_array(){ - test_array_get(); - test_array_set(); - test_array_del(); - test_array_iterator(); - test_array_const_iterator(); - test_array_operator_square(); - } - - virtual void test_dict(){ - test_invalid_dict(_arr); - } - - virtual void test_callable(){ - test_invalid_callable(_arr); - } - - //methods for array - virtual void test_array_get(){ - //normal get - { - assert( bsl::var::Array().get(0).is_null() ); - } - { - bsl::var::Array arr; - arr[0] = null; - assert( arr.get(0).is_null() ); - } - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 1949; - arr[123] = i32; - assert( arr.get(123).to_int32() == 1949 ); - assert( arr.get(122).is_null() ); - assert( arr.get(456).is_null() ); - } - //geek get - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 1234; - arr[0] = i32; - arr.get(0) = 4321; - assert( arr[0].to_int32() == 4321 ); - } - //get with default - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 9394; - bsl::var::Ref ref; - bsl::var::Ref ref_i32 = i32; - - arr[9] = i32; - arr[0] = null; - - assert( arr.get(9, ref).to_int32() == i32.to_int32() ); - assert( &bsl::var::Ref(arr.get(9, ref)).ref() == &i32 ); - assert( arr.get(0, ref).is_null() ); - assert( arr.get(9999, ref_i32).to_int32() == i32.to_int32() ); - assert( arr.get(99999, null).is_null() ); - } - } - - virtual void test_array_set(){ - { - bsl::var::Array arr; - arr.set(127, null ); - assert( arr.size() == 128 ); - assert( arr[127].is_null() ); - } - } - - virtual void test_array_del(){ - { - assert( bsl::var::Array().del(0) == false ); - } - } - - virtual void test_array_iterator(){ - { - bsl::var::Array arr; - //empty array: - assert( arr.array_begin() == arr.array_end() ); - } - { - //iterators from different array are not equal - assert( bsl::var::Array().array_begin() != bsl::var::Array().array_begin() ); - assert( bsl::var::Array().array_end() != bsl::var::Array().array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr; - arr[0] = rp.create(123); - arr[2] = rp.create(456); - bsl::var::Array::array_iterator iter = arr.array_begin(); - - //iter => arr[0] - assert( iter == arr.array_begin() ); - assert( iter != arr.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => arr[1] - assert( iter != arr.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - iter->value() = rp.create(789); - assert( arr[1].is_int32() ); - assert( arr[1].to_int32() == 789 ); - assert( (++ iter)->key() == 2 ); - - //iter => arr[2] - assert( iter != arr.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == arr.array_end() ); - - //iter == arr.array_end() - assert( iter == arr.array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr; - bsl::var::Array::array_iterator iter = arr.array_begin(); - iter = arr.array_end(); - bsl::var::Array::array_iterator iter2(iter); - assert( iter2 == arr.array_end() ); - } - } - - virtual void test_array_const_iterator(){ - { - const bsl::var::Array arr; - //empty array: - assert( arr.array_begin() == arr.array_end() ); - } - { - //iterators from different array are not equal - assert( bsl::var::Array().array_begin() != bsl::var::Array().array_begin() ); - assert( bsl::var::Array().array_end() != bsl::var::Array().array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr1; - arr1[0] = rp.create(123); - arr1[2] = rp.create(456); - const bsl::var::Array& arr = arr1; - bsl::var::Array::array_const_iterator iter = arr.array_begin(); - - //iter => arr[0] - assert( iter == arr.array_begin() ); - assert( iter != arr.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => arr[1] - assert( iter != arr.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - assert( (++ iter)->key() == 2 ); - - //iter => arr[2] - assert( iter != arr.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == arr.array_end() ); - - //iter == arr.array_end() - assert( iter == arr.array_end() ); - } - - } - - virtual void test_array_operator_square(){ - bsl::ResourcePool rp; - - //non-const - { - bsl::var::Array arr; - arr[100] = rp.create(123); - assert( arr.size() == 101 ); - assert( arr[100].is_int32() ); - assert( arr[100].to_int32() == 123); - } - { - bsl::var::Array arr; - assert( arr[456].is_ref() ); - assert( arr[789].is_null() ); - } - - //const - { - bsl::var::Array arr1; - arr1[100] = rp.create(123); - const bsl::var::Array& arr = arr1; - assert( arr.size() == 101 ); - assert( arr[100].is_int32() ); - assert( arr[100].to_int32() == 123); - - assert( arr[0].is_null() ); - } - - } - - virtual void test_operator_assign(){ - //valid assignments - { - //prepare - bsl::var::Array arr1; - bsl::var::Array arr2; - bsl::var::Int32 i32 = 123; - arr1[0] = i32; - - //test - arr2 = arr1; - assert( arr2.size() == 1 ); - assert( arr2[0].to_int32() == 123 ); - - arr2 = arr2; //self assignment! - assert( arr2.size() == 1 ); - assert( arr2[0].to_int32() == 123 ); - - } - //invalid assignments - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 123; - ASSERT_THROW( arr = 123, bsl::InvalidOperationException ); - ASSERT_THROW( arr = 123LL, bsl::InvalidOperationException ); - ASSERT_THROW( arr = 123.456, bsl::InvalidOperationException ); - ASSERT_THROW( arr = "123", bsl::InvalidOperationException ); - ASSERT_THROW( arr = i32, bsl::InvalidOperationException ); - } - } - - virtual void test_operator_paren(){ - { - bsl::var::Array args; - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Array()(args, rp), bsl::InvalidOperationException ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Array()(self, args, rp), bsl::InvalidOperationException ); - } - } -private: - bsl::var::Null null; - bsl::var::Array _arr; -}; - - -int main(){ - TestVarArray().test_all(); - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Array2.cpp b/bsl/var/unittest/test_var_Array2.cpp deleted file mode 100644 index 3e69a635d569f186055a696974b19c1d379ddaa0..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Array2.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Array.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarArray.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 13:35:54 - * @version $Revision: 1.4 $ - * @brief - * - **/ - -#include "test_var_invalid.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if !(defined(__cplusplus) && (!defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100)) - #include -#endif - -bsl::xcompool g_xcompool; - -class TestVarArray: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - typedef bsl::var::Array::allocator_type allocator_type; - - TestVarArray() { - g_xcompool.create(); - allocator_type __alloc(&g_xcompool); - _alloc = __alloc; - bsl::var::Array __array(_alloc); - _arr = __array; - } - - virtual ~TestVarArray(){} - - //special methods - virtual void test_special(){ - //mempool - { - char buff[10000]; - bsl::xmempool pool; - pool.create(buff, sizeof(buff)); - bsl::var::Array::allocator_type pool_alloc( &pool ); - bsl::var::Array arr1( pool_alloc ); - bsl::var::Array arr2; - bsl::var::Int32 i32(123); - arr2[100] = i32; - arr1 = arr2; - assert( arr2.size() == arr2.size() ); - assert( arr2[100].to_int32() == 123 ); - - bsl::var::Array arr3(arr1); - assert( arr3.size() == arr1.size() ); - assert( arr3[100].to_int32() == 123 ); - - bsl::var::Array arr4; - arr4 = arr1; - assert( arr4.size() == arr1.size() ); - assert( arr4[100].to_int32() == 123 ); - pool.clear(); - } - - //copy ctor - { - bsl::var::Array arr1( _alloc ); - bsl::var::Int32 i32(123); - arr1[100] = i32; - bsl::var::Array arr2(arr1); - assert( arr2.size() == arr1.size() ); - assert( arr2[100].to_int32() == 123 ); - } - - //assign - { - bsl::var::Array arr1( _alloc ); - bsl::var::Int32 i32(123); - arr1[100] = i32; - bsl::var::Array arr2( _alloc ); - arr2 = arr1; - assert( arr2.size() == arr1.size() ); - assert( arr2[100].to_int32() == 123 ); - } - - } - virtual void test_mask(){ - test_mask_consistency( bsl::var::Array() ); - } - //methods for all - virtual void test_size() { - { - assert( bsl::var::Array().size() == 0 ); - } - { - bsl::var::Array arr( _alloc ); - arr[100] = bsl::var::Null::null; - assert( arr.size() == 101 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Array arr( _alloc ); - arr.clear(); //assert no-throw - assert(arr.size() == 0); - } - } - - virtual void test_dump() { - stub(); - } - - virtual void test_to_string() { - stub(); - } - - virtual void test_get_type() { - assert( bsl::var::Array().get_type() == string_type("bsl::var::BasicArray") ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Int32 i0(0),i1(1),i2(2); - bsl::var::Array arr( allocator_type( &rp.get_mempool() ) ); - arr[0] = i0; - arr[1] = i1; - arr[2] = i2; - bsl::var::Array& rep = arr.clone(rp); - assert( rep.size() == arr.size() ); - assert( rep[0].to_int32() == i0.to_int32() ); - assert( rep[1].to_int32() == i1.to_int32() ); - assert( rep[2].to_int32() == i2.to_int32() ); - } - - virtual void test_bool(){ - test_invalid_bool(_arr); - } - - virtual void test_raw(){ - test_invalid_raw(_arr); - } - - virtual void test_number(){ - test_invalid_number(_arr); - } - - virtual void test_string(){ - test_invalid_string(_arr); - } - - virtual void test_array(){ - test_array_get(); - test_array_set(); - test_array_del(); - test_array_iterator(); - test_array_const_iterator(); - test_array_operator_square(); - } - - virtual void test_dict(){ - test_invalid_dict(_arr); - } - - virtual void test_callable(){ - test_invalid_callable(_arr); - } - - //methods for array - virtual void test_array_get(){ - //normal get - { - assert( bsl::var::Array().get(0).is_null() ); - } - { - bsl::var::Array arr( _alloc ); - arr[0] = null; - assert( arr.get(0).is_null() ); - } - { - bsl::var::Array arr( _alloc ); - bsl::var::Int32 i32 = 1949; - arr[123] = i32; - assert( arr.get(123).to_int32() == 1949 ); - assert( arr.get(122).is_null() ); - assert( arr.get(456).is_null() ); - } - //geek get - { - bsl::var::Array arr( _alloc ); - bsl::var::Int32 i32 = 1234; - arr[0] = i32; - arr.get(0) = 4321; - assert( arr[0].to_int32() == 4321 ); - } - //get with default - { - bsl::var::Array arr( _alloc ); - bsl::var::Int32 i32 = 9394; - bsl::var::Ref ref; - bsl::var::Ref ref_i32 = i32; - - arr[9] = i32; - arr[0] = null; - - assert( arr.get(9, ref).to_int32() == i32.to_int32() ); - assert( &bsl::var::Ref(arr.get(9, ref)).ref() == &i32 ); - assert( arr.get(0, ref).is_null() ); - assert( arr.get(9999, ref_i32).to_int32() == i32.to_int32() ); - assert( arr.get(99999, null).is_null() ); - } - } - - virtual void test_array_set(){ - { - bsl::var::Array arr( _alloc ); - arr.set(127, null ); - assert( arr.size() == 128 ); - assert( arr[127].is_null() ); - } - } - - virtual void test_array_del(){ - { - assert( bsl::var::Array().del(0) == false ); - } - } - - virtual void test_array_iterator(){ - { - bsl::var::Array arr( _alloc ); - //empty array: - assert( arr.array_begin() == arr.array_end() ); - } - { - //iterators from different array are not equal - assert( bsl::var::Array().array_begin() != bsl::var::Array().array_begin() ); - assert( bsl::var::Array().array_end() != bsl::var::Array().array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr( _alloc ); - arr[0] = rp.create(123); - arr[2] = rp.create(456); - bsl::var::Array::array_iterator iter = arr.array_begin(); - - //iter => arr[0] - assert( iter == arr.array_begin() ); - assert( iter != arr.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => arr[1] - assert( iter != arr.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - iter->value() = rp.create(789); - assert( arr[1].is_int32() ); - assert( arr[1].to_int32() == 789 ); - assert( (++ iter)->key() == 2 ); - - //iter => arr[2] - assert( iter != arr.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == arr.array_end() ); - - //iter == arr.array_end() - assert( iter == arr.array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr( _alloc ); - bsl::var::Array::array_iterator iter = arr.array_begin(); - iter = arr.array_end(); - bsl::var::Array::array_iterator iter2(iter); - assert( iter2 == arr.array_end() ); - } - } - - virtual void test_array_const_iterator(){ - { - const bsl::var::Array arr( _alloc ); - //empty array: - assert( arr.array_begin() == arr.array_end() ); - } - { - //iterators from different array are not equal - assert( bsl::var::Array().array_begin() != bsl::var::Array().array_begin() ); - assert( bsl::var::Array().array_end() != bsl::var::Array().array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array arr1( _alloc ); - arr1[0] = rp.create(123); - arr1[2] = rp.create(456); - const bsl::var::Array& arr = arr1; - bsl::var::Array::array_const_iterator iter = arr.array_begin(); - - //iter => arr[0] - assert( iter == arr.array_begin() ); - assert( iter != arr.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => arr[1] - assert( iter != arr.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - assert( (++ iter)->key() == 2 ); - - //iter => arr[2] - assert( iter != arr.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == arr.array_end() ); - - //iter == arr.array_end() - assert( iter == arr.array_end() ); - } - - } - - virtual void test_array_operator_square(){ - bsl::ResourcePool rp; - - //non-const - { - bsl::var::Array arr( _alloc ); - arr[100] = rp.create(123); - assert( arr.size() == 101 ); - assert( arr[100].is_int32() ); - assert( arr[100].to_int32() == 123); - } - { - bsl::var::Array arr( _alloc ); - assert( arr[456].is_ref() ); - assert( arr[789].is_null() ); - } - - //const - { - bsl::var::Array arr1( _alloc ); - arr1[100] = rp.create(123); - const bsl::var::Array& arr = arr1; - assert( arr.size() == 101 ); - assert( arr[100].is_int32() ); - assert( arr[100].to_int32() == 123); - - assert( arr[0].is_null() ); - } - - } - - virtual void test_operator_assign(){ - //valid assignments - { - //prepare - bsl::var::Array arr1( _alloc ); - bsl::var::Array arr2( _alloc ); - bsl::var::Int32 i32 = 123; - arr1[0] = i32; - - //test - arr2 = arr1; - assert( arr2.size() == 1 ); - assert( arr2[0].to_int32() == 123 ); - - arr2 = arr2; //self assignment! - assert( arr2.size() == 1 ); - assert( arr2[0].to_int32() == 123 ); - - } - //invalid assignments - { - bsl::var::Array arr( _alloc ); - bsl::var::Int32 i32 = 123; - ASSERT_THROW( arr = 123, bsl::InvalidOperationException ); - ASSERT_THROW( arr = 123LL, bsl::InvalidOperationException ); - ASSERT_THROW( arr = 123.456, bsl::InvalidOperationException ); - ASSERT_THROW( arr = "123", bsl::InvalidOperationException ); - ASSERT_THROW( arr = i32, bsl::InvalidOperationException ); - } - } - - virtual void test_operator_paren(){ - { - bsl::var::Array args( _alloc ); - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Array()(args, rp), bsl::InvalidOperationException ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Array()(self, args, rp), bsl::InvalidOperationException ); - } - } -private: - bsl::var::Null null; - bsl::var::Array _arr; - allocator_type _alloc; -}; - - -int main(){ - TestVarArray().test_all(); - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Bool.cpp b/bsl/var/unittest/test_var_Bool.cpp deleted file mode 100644 index 5a118db1adff2711686489e4c4a11eb2538733db..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Bool.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Bool.cpp,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_var_Bool.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/05/09 20:27:23 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#include "test_var_invalid.h" - -class TestVarBool: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarBool(){} - - //speical methods - virtual void test_special(){ - //ctor - { - bsl::var::Bool b; - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - assert( b.to_bool() == true ); - } - { - bsl::var::Bool b(false); - assert( b.to_bool() == false ); - } - // copy ctor - { - bsl::var::Bool b1(true); - bsl::var::Bool b2(b1); - assert( b2.to_bool() == true ); - - } - // copy assign - { - bsl::var::Bool b1(true), b2(false); - b1 = b2; - assert( b1.to_bool() == false ); - } - } - virtual void test_mask(){ - test_mask_consistency( bsl::var::Bool() ); - } - //methods for all - virtual void test_clear() { - { - bsl::var::Bool b; - b.clear(); //assert no-throw - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - b.clear(); - assert( b.to_bool() == false ); - } - } - - virtual void test_dump() { - { - bsl::var::Bool b; - assert( b.dump() == "[bsl::var::Bool]false" ); - assert( b.dump(999) == "[bsl::var::Bool]false" ); - } - { - bsl::var::Bool b(true); - assert( b.dump() == "[bsl::var::Bool]true" ); - assert( b.dump(999) == "[bsl::var::Bool]true" ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Bool b; - assert( b.to_string() == "false" ); - } - { - bsl::var::Bool b(true); - assert( b.to_string() == "true" ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Bool().get_type() == string_type("bsl::var::Bool") ); - } - - //method for value - virtual void test_bool(){ - { - bsl::var::Bool b; - b = true; - assert( b.to_bool() == true ); - } - { - const bsl::var::Bool b(true); - assert( b.to_bool() == true ); - } - } - virtual void test_raw(){ - bsl::var::Bool b; - test_invalid_raw(b); - } - - virtual void test_number(){ - test_with_int32(); - test_with_int64(); - test_with_double(); - - test_valid_number( bsl::var::Bool(true), true ); - test_valid_number( bsl::var::Bool(false), false ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Bool b; - assert(b.clone(rp).to_string() == b.to_string() ); - assert(b.clone(rp).get_type() == b.get_type() ); - test_valid_number( bsl::var::Bool(true).clone(rp), true ); - test_valid_number( bsl::var::Bool(false).clone(rp), false ); - } - - virtual void test_string(){ - bsl::var::Bool b; - test_valid_string(); - test_invalid_string(b); - } - - //methods for array and dict - virtual void test_array(){ - bsl::var::Bool b; - test_invalid_array(b); - } - - //methods for dict - virtual void test_dict(){ - bsl::var::Bool b; - test_invalid_dict(b); - } - - //methods for callable - virtual void test_callable(){ - bsl::var::Bool b; - test_invalid_callable(b); - } - - virtual void test_operator_assign(){ - //valid assign - { - bsl::var::Bool b1, b2(true); - b1 = (bsl::var::IVar&)(b2); - assert( b1.to_bool() == true ); - } - { - bsl::var::Bool b1, b2(true); - bsl::var::Ref ref = b2; - b1 = ref; - assert( b1.to_bool() == true ); - } - - } - - virtual void test_valid_string(){ - //= const char * - { - bsl::var::Bool b(true); - b = static_cast(NULL); - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - b = ""; - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - b = "abc"; - assert( b.to_bool() == true ); - } - - //= string_type - { - bsl::var::Bool b(true); - b = string_type(""); - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - b = string_type("false"); //wierd but correct - assert( b.to_bool() == true ); - } - - } - virtual void test_with_int32(){ - //operator = - { - bsl::var::Bool b; - b = 123; - assert( b.to_bool() == true ); - b = 0; - assert( b.to_bool() == false ); - } - //to_int32() - { - assert( bsl::var::Bool().to_int32() == 0 ); - assert( bsl::var::Bool(true).to_int32() == 1 ); - } - //from Int32 - { - bsl::var::Int32 i32(9394); - bsl::var::Bool b; - b = i32; - assert( b.to_bool() == true ); - } - { - bsl::var::Int32 i32; - bsl::var::Bool b; - b = i32; - assert( b.to_bool() == false ); - } - //to Int32 - { - bsl::var::Bool b(true); - bsl::var::Int32 i32; - i32 = b; - assert( i32.to_int32() == 1 ); - } - { - bsl::var::Bool b; - bsl::var::Int32 i32; - i32 = b; - assert( i32.to_int32() == 0 ); - } - } - - virtual void test_with_int64(){ - //operator = - { - bsl::var::Bool b; - b = 123LL; - assert( b.to_bool() == true ); - b = 0LL; - assert( b.to_bool() == false ); - } - //to_int64() - { - assert( bsl::var::Bool().to_int64() == 0 ); - assert( bsl::var::Bool(true).to_int64() == 1 ); - } - //from Int64 - { - bsl::var::Int64 i64(9394); - bsl::var::Bool b; - b = i64; - assert( b.to_bool() == true ); - } - { - bsl::var::Int64 i64; - bsl::var::Bool b; - b = i64; - assert( b.to_bool() == false ); - } - //to Int64 - { - bsl::var::Bool b(true); - bsl::var::Int64 i64; - i64 = b; - assert( i64.to_int64() == 1 ); - } - { - bsl::var::Bool b; - bsl::var::Int64 i64; - i64 = b; - assert( i64.to_int64() == 0 ); - } - } - - virtual void test_with_double(){ - //operator = - { - bsl::var::Bool b; - b = 123.456; - assert( b.to_bool() == true ); - b = 0.0; - assert( b.to_bool() == false ); - } - //to_double() - { - assert( bsl::var::Bool().to_double() == 0 ); - assert( bsl::var::Bool(true).to_double() == 1 ); - } - //from Double - { - bsl::var::Double dbl(4670.9394); - bsl::var::Bool b; - b = dbl; - assert( b.to_bool() == true ); - } - { - bsl::var::Double dbl; - bsl::var::Bool b; - b = dbl; - assert( b.to_bool() == false ); - } - //to Double - { - bsl::var::Bool b(true); - bsl::var::Double dbl; - dbl = b; - assert( dbl.to_double() == 1 ); - } - { - bsl::var::Bool b; - bsl::var::Double dbl; - dbl = b; - assert( dbl.to_double() == 0 ); - } - } - -private: -}; - -int main(){ - TestVarBool test; - test.test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Dict.cpp b/bsl/var/unittest/test_var_Dict.cpp deleted file mode 100644 index e8274500bd92f24d578754f2d77314f148ae38f2..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Dict.cpp +++ /dev/null @@ -1,644 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Dict.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarDict.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 13:35:54 - * @version $Revision: 1.4 $ - * @brief - * - **/ - -#include -#include -#include -#include "test_var_invalid.h" -#include "bsl/pool.h" -#include "bsl/pool/bsl_pool.h" -#include "bsl/var/Dict.h" -#include "bsl/var/assign.h" -#include "bsl/ResourcePool.h" -#include "bsl/pool/bsl_xmempool.h" - -#if !(defined(__cplusplus) && (!defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100)) -#include -#endif - -bsl::xmempool g_mempool; -bsl::mempool& g_pool = g_mempool; - -templateclass creater_t> -class TestVarDict: public ITestVar{ -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::DictIterator dict_iterator; - typedef bsl::var::DictConstIterator dict_const_iterator; - typedef bsl::var::Dict::allocator_type allocator_type; - - virtual ~TestVarDict(){} - - //special methods - virtual void test_special(){ - //pool - { - char buff[10000]; - bsl::xmempool pool; - pool.create(buff, sizeof(buff)); - - allocator_type pool_alloc( &pool ); - bsl::var::Dict dict1( pool_alloc ); - bsl::var::Int32 i32 = 123; - dict1["null"] = null; - dict1["i32"] = i32; - - bsl::var::Dict dict2 = dict1; - assert( dict2.get("null").is_null() ); - assert( dict2.get("i32").to_int32() == 123 ); - - pool.clear(); - } - - //copy ctor - { - //prepare - dict_t& dict1 = _creater.create(); - bsl::var::Int32 i32 = 123; - dict1["null"] = null; - dict1["i32"] = i32; - - //test - dict_t dict2 = dict1; - assert( dict2.get("null").is_null() ); - assert( dict2.get("i32").to_int32() == 123 ); - } - //copy assign - { - //prepare - dict_t& dict1 = _creater.create(); - bsl::var::Int32 i32 = 123; - dict1["null"] = null; - dict1["i32"] = i32; - - //test - dict_t& dict2 = _creater.create(); - dict2 = dict1; - assert( dict2.get("null").is_null() ); - assert( dict2.get("i32").to_int32() == 123 ); - - //不同实现类型之间的赋值 - bsl::var::StdMapDict smd; - smd = dict1; - assert( smd["null"].is_null() ); - assert( smd["i32"].to_int32() == 123 ); - - bsl::var::GnuHashDict ghd; - ghd = dict1; - assert( ghd["null"].is_null() ); - assert( ghd["i32"].to_int32() == 123 ); - } - } - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Dict() ); - } - - virtual void test_size() { - { - assert( _creater.create().size() == 0 ); - } - { - dict_t& dict = _creater.create(); - dict["abc"] = bsl::var::Null::null; - assert( dict.size() == 1 ); - } - - } - - virtual void test_clear() { - { - dict_t& dict = _creater.create(); - dict.clear(); //assert no-throw - assert(dict.size() == 0); - } - } - - virtual void test_dump() { - { - stub(); - } - } - - virtual void test_to_string() { - { - stub(); - } - } - - virtual void test_get_type() { - assert( _creater.create().get_type() == string_type("bsl::var::BasicDict") ); - } - - virtual void test_bool(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_bool(dict); - } - - virtual void test_raw(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_raw(dict); - } - - virtual void test_number(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_number(dict); - } - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Dict dict; - bsl::var::Int32 i32(123); - bsl::var::Int64 i64(456); - bsl::var::assign( dict, "hello", i32, "world", i64 ); // dict = {"hello":i32, "world":i64} - { - //Shallow copy - bsl::var::Dict& cl = dict.clone(rp); - assert( cl.get_type() == dict.get_type() ); - assert( cl.size() == dict.size() ); - assert( cl["hello"].to_int32() == 123 ); - assert( cl["world"].to_int64() == 456 ); - assert( &bsl::var::Ref(cl["hello"]).ref() == &i32 ); - assert( &bsl::var::Ref(cl["world"]).ref() == &i64 ); - } - { - //deep copy - bsl::var::Dict& cl = dict.clone(rp, true); - assert( cl.get_type() == dict.get_type() ); - assert( cl.size() == dict.size() ); - assert( cl["hello"].to_int32() == 123 ); - assert( cl["world"].to_int64() == 456 ); - assert( &bsl::var::Ref(cl["hello"]).ref() != &i32 ); - assert( &bsl::var::Ref(cl["world"]).ref() != &i64 ); - } - } - virtual void test_string(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_string(dict); - } - - virtual void test_array(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_array(dict); - } - - virtual void test_dict(){ - test_dict_get(); - test_dict_set(); - test_dict_del(); - test_dict_iterator(); - test_dict_const_iterator(); - test_dict_operator_square(); - } - - virtual void test_callable(){ - bsl::var::IVar& dict = _creater.create(); - test_invalid_callable(dict); - } - - virtual void test_dict_iterator(){ - { - dict_t dict = _creater.create(); - //empty dict: - assert( dict.dict_begin() == dict.dict_end() ); - } - { - //iterators from different dict are not equal - //true to std::map - //not true to __gnu_cxx::hash_map, since end() yields iterators that considered equal - //disable such test case - /* - dict_t dict1 = _creater.create(); - dict_t dict2 = _creater.create(); - dict1["null"]= bsl::var::Null::null; - dict2["null"]= bsl::var::Null::null; - assert( dict1.dict_begin() != dict2.dict_begin() ); - assert( dict1.dict_end() != dict2.dict_end() ); - */ - } - - { - bsl::ResourcePool rp; - dict_t& dict = _creater.create(); - dict["0"] = rp.template create(123); - dict["2"] = rp.template create(456); - dict["null"] = rp.template create(); - bsl::var::Dict::dict_iterator iter = dict.dict_begin(); - - - assert( iter == dict.dict_begin() ); - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - bsl::var::IVar& value2 = iter->value(); - - iter == dict.dict_end(); - //assert( (++ iter)->key() != key2 ); - - assert( ++ iter == dict.dict_end() ); - - //无序的东西真难测 - assert( (key0 == "0" && value0.to_int32() == 123 && (value0 = 1230, true)) // dict["0"] will be Int(1230) - || (key1 == "0" && value1.to_int32() == 123 && (value1 = 1230, true)) - || (key2 == "0" && value2.to_int32() == 123 && (value2 = 1230, true)) - ); - - - assert( (key0 == "2" && value0.to_int32() == 456 && (value0 = 4560, true)) // dict["0"] will be Int(4560) - || (key1 == "2" && value1.to_int32() == 456 && (value1 = 4560, true)) - || (key2 == "2" && value2.to_int32() == 456 && (value2 = 4560, true)) - ); - assert( (key0 == "null" && value0.is_null() && (value0 = rp.template create(-1), true)) - || (key1 == "null" && value1.is_null() && (value1 = rp.template create(-1), true)) - || (key2 == "null" && value2.is_null() && (value2 = rp.template create(-1), true)) - ); - - assert( dict["0"].to_int32() == 1230 ); - assert( dict["2"].to_int32() == 4560 ); - assert( dict["null"].to_int32() == -1); - - } - - } - - virtual void test_dict_const_iterator(){ - { - const dict_t& dict = _creater.create(); - //empty dict: - assert( dict.dict_begin() == dict.dict_end() ); - } - - { - bsl::ResourcePool rp; - dict_t& _dict = _creater.create(); - _dict["0"] = rp.template create(123); - _dict["2"] = rp.template create(456); - _dict["null"] = rp.template create(); - const dict_t& dict = _dict; - bsl::var::Dict::dict_const_iterator iter = dict.dict_begin(); - - assert( iter == dict.dict_begin() ); - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - const bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - const bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != dict.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - const bsl::var::IVar& value2 = iter->value(); - //assert( (++ iter)->key() != key2 ); - - //iter == dict.dict_end() - assert( (++iter) == dict.dict_end() ); - - //无序的东西真难测 - assert( (key0 == "0" && value0.to_int32() == 123) - || (key1 == "0" && value1.to_int32() == 123) - || (key2 == "0" && value2.to_int32() == 123) - ); - - assert( (key0 == "2" && value0.to_int32() == 456) - || (key1 == "2" && value1.to_int32() == 456) - || (key2 == "2" && value2.to_int32() == 456) - ); - - assert( (key0 == "null" && value0.is_null()) - || (key1 == "null" && value1.is_null()) - || (key2 == "null" && value2.is_null()) - ); - - assert( dict["0"].to_int32() == 123 ); - assert( dict["2"].to_int32() == 456 ); - assert( dict["null"].is_null()); - - } - - } - - virtual void test_dict_get(){ - //normal get - { - assert( _creater.create().get("").is_null() ); - } - { - assert( _creater.create().get("a key").is_null() ); - } - { - assert( _creater.create().get(string_type("another key")).is_null() ); - } - { - dict_t _dict = _creater.create(); - const dict_t& dict = _dict; - bsl::var::Int32 i32 = 4670; - - _dict["an int"] = i32; - _dict["null"] = null; - - assert( dict.get("an int").to_int32() == i32.to_int32() ); - assert( dict.get(string_type("an int")).to_int32() == i32.to_int32() ); - assert( dict.get("null").is_null() ); - - assert( dict.get("unexist").is_null() ); - } - //geek get - { - dict_t& dict = _creater.create(); - bsl::var::Int32 i32 = 7776; - dict["an int"] = i32; - dict.get("an int") = 0; - assert( dict["an int"].to_int32() == 0 ); - } - //get with default - { - dict_t& dict = _creater.create(); - bsl::var::Int32 i32 = 9394; - bsl::var::Ref ref; - bsl::var::Ref ref_i32 = i32; - - dict["an int"] = i32; - dict["null"] = null; - - assert( dict.get("an int", ref).to_int32() == i32.to_int32() ); - assert( dict.get(string_type("an int"), ref).to_int32() == i32.to_int32() ); - assert( dict.get("null", ref).is_null() ); - assert( dict.get("unexist", ref_i32).to_int32() == i32.to_int32() ); - } - } - - virtual void test_dict_set(){ - { - dict_t& dict = _creater.create(); - bsl::var::Int32 i32 = 4670; - dict.set("i32", i32); - assert( dict["i32"].to_int32() == 4670 ); - } - } - - virtual void test_dict_del(){ - { - dict_t& dict = _creater.create(); - bsl::var::Int32 i32 = 874; - dict["del"] = i32; - assert( dict.size() == 1 ); - assert( dict["del"].to_int32() == 874 ); - dict.del("del"); - assert( dict.size() == 0 ); - assert( dict.get("del").is_null() ); - } - } - - virtual void test_dict_operator_square(){ - - //non-const - { - bsl::ResourcePool rp; - dict_t& dict = _creater.create(); - dict["acumon"] = rp.template create(123); - assert( dict.size() == 1 ); - assert( dict["acumon"].is_int32() ); - assert( dict[string_type("acumon")].to_int32() == 123); - - dict["abc"] = dict["acumon"]; - assert( dict["abc"].to_int32() == 123 ); - } - { - dict_t& dict = _creater.create(); - assert( dict[""].is_ref() ); - assert( dict[""].is_null() ); - } - - //const - { - bsl::ResourcePool rp; - dict_t& _dict = _creater.create(); - _dict["acumon"] = rp.template create(123); - const dict_t& dict = _dict; - assert( dict.size() == 1 ); - assert( dict[string_type("acumon")].is_int32() ); - assert( dict["acumon"].to_int32() == 123); - - ASSERT_THROW( dict["unexist"], bsl::KeyNotFoundException ); - } - - } - - virtual void test_operator_assign(){ - //valid assignments - { - //prepare - dict_t& dict1 = _creater.create(); - dict_t& dict2 = _creater.create(); - bsl::var::Int32 i32 = 123; - dict1["hi"] = i32; - - //test - dict2 = dict1; - assert( dict2.size() == 1 ); - assert( dict2["hi"].to_int32() == 123 ); - - dict2 = dict2; //self assignment! - assert( dict2.size() == 1 ); - assert( dict2["hi"].to_int32() == 123 ); - - } - - } - -private: - bsl::var::Null null; - creater_t _creater; -}; - - -template -class DefaultCreater{ -public: - dict_t& create(){ - return _rp.template create(); - } -private: - bsl::ResourcePool _rp; -}; - -template -class CapacityCreater{ -public: - static size_t capacity; - dict_t& create(){ - return _rp.template create(capacity); - } -private: - bsl::ResourcePool _rp; -}; - -template -class AllocatorCreater{ -public: - static typename dict_t::allocator_type alloc; - dict_t& create(){ - return _rp.template create(alloc); - } -private: - bsl::ResourcePool _rp; -}; - -template -class PoolAllocatorCreater{ -public: - typedef typename dict_t::allocator_type allocator_type; - dict_t& create(){ - return _rp.template create(allocator_type(&g_pool)); - } -private: - bsl::ResourcePool _rp; -}; - -template -class CapacityAllocatorCreater{ -public: - static size_t capacity; - static typename dict_t::allocator_type alloc; - dict_t& create(){ - return _rp.template create(capacity, alloc); - } -private: - bsl::ResourcePool _rp; -}; - -template -class CapacityPoolAllocatorCreater{ -public: - static size_t capacity; - typedef typename dict_t::allocator_type allocator_type; - dict_t& create(){ - return _rp.template create(capacity, allocator_type(&g_pool)); - } -private: - bsl::ResourcePool _rp; -}; - - -//configuration -template<> -size_t CapacityCreater::capacity = 1000; -template<> -size_t CapacityAllocatorCreater::capacity = 1000; -template<> -size_t CapacityPoolAllocatorCreater::capacity = 1000; -template<> -size_t CapacityCreater::capacity = 1000; -template<> -size_t CapacityAllocatorCreater::capacity = 1000; -template<> -size_t CapacityPoolAllocatorCreater::capacity = 1000; - - -template<> -bsl::var::StdMapDict::allocator_type -AllocatorCreater::alloc = bsl::var::StdMapDict::allocator_type(); - -template<> -bsl::var::StdMapDict::allocator_type -CapacityAllocatorCreater::alloc = bsl::var::StdMapDict::allocator_type(); - -template<> -bsl::var::GnuHashDict::allocator_type -AllocatorCreater::alloc = bsl::var::GnuHashDict::allocator_type(); - -template<> -bsl::var::GnuHashDict::allocator_type -CapacityAllocatorCreater::alloc = bsl::var::GnuHashDict::allocator_type(); - - - -/** - * @brief 测试函数 - * - * 测试组合共有12个,分别是 - * - * std::map std::allocator DefaultCreater - * std::map std::allocator CapacityCreater - * std::map std::allocator AllocatorCreater - * std::map std::allocator CapacityAllocatorCreater - * - * __gnu_cxx::hash_map std::allocator DefaultCreater - * __gnu_cxx::hash_map std::allocator CapacityCreater - * __gnu_cxx::hash_map std::allocator AllocatorCreater - * __gnu_cxx::hash_map std::allocator CapacityAllocatorCreater - * - * std::map bsl::pool_allocator AllocatorCreater - * std::map bsl::pool_allocator CapacityAllocatorCreater - * __gnu_cxx::hash_map bsl::pool_allocator AllocatorCreater - * __gnu_cxx::hash_map bsl::pool_allocator CapacityAllocatorCreater - * - * @return int - * @retval - * @see - * @author chenxm - * @date 2009/04/08 14:33:54 -**/ -char g_membuf[104857600]; -int main(){ - - //init - g_mempool.create(g_membuf, sizeof(g_membuf)); - - //test - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - TestVarDict().test_all(); - g_mempool.clear(); - - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Double.cpp b/bsl/var/unittest/test_var_Double.cpp deleted file mode 100644 index ebc3d6656947f0f4200a84f1f90256fa9dffb456..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Double.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Double.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarDouble.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/29 17:33:45 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "bsl/var/Double.h" -#include "test_var_invalid.h" - -class TestVarDouble: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarDouble() - :_dbl(2008.0512){} - - virtual ~TestVarDouble(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::Double var = 123456789.1234567; - bsl::var::Double j = var; - assert( j.is_double() ); - assert( j.to_double() == 123456789.1234567 ); - var = 987654321.098765; - assert( j.to_double() == 123456789.1234567 ); - } - //copy assign - { - bsl::var::Double var = 123456789.1234567; - bsl::var::Double j; - j = var; - assert( j.is_double() ); - assert( j.to_double() == 123456789.1234567 ); - var = 987654321.098765; - assert( j.to_double() == 123456789.1234567 ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Double() ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::Double var; - var = 123; - assert( var.to_int32() == 123 ); - assert( var.to_int64() == 123 ); - } - // = long long - { - bsl::var::Double var; - var = 1234567891234567LL; - assert( var.to_double() == double(1234567891234567LL) ); - assert( var.to_int64() == 1234567891234567LL ); - } - // = double - { - bsl::var::Double var; - var = 12345678904670.9394; - assert( var.to_double() ==12345678904670.9394 ); - } - // = const char * - { - bsl::var::Double var; - var = "1234567.46709394"; - assert( var.to_double() == 1234567.46709394 ); - } - - // = string_type - { - bsl::var::Double var; - var = bsl::var::IVar::string_type("1234567.46709394"); - assert( var.to_double() == 1234567.46709394 ); - } - - // = Int32 - { - bsl::var::Int32 j; - bsl::var::Double var; - j = 123; - var = j; - assert( var.to_int32() == 123 ); - assert( var.to_int64() == 123 ); - } - - // = Double - { - bsl::var::Double var, j; - j = 123456789.1234567; - var = j; - assert( var.to_double() == 123456789.1234567 ); - } - - // = *this - { - bsl::var::Double var; - var = 123; - var = var; - assert( var.to_double() == 123 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Double var(123456.7891234); - var.clear(); //assert no-throw - assert(var.to_int64() == 0); - } - } - - virtual void test_dump() { - { - bsl::var::Double var; - assert( var.dump() == string_type("[bsl::var::Double]0") ); - assert( var.dump(999) == string_type("[bsl::var::Double]0") ); - } - - { - bsl::var::Double var(123.45); - assert( var.dump() == string_type("[bsl::var::Double]123.45") ); - assert( var.dump(999) == string_type("[bsl::var::Double]123.45") ); - } - - { - bsl::var::Double var(-1e-100); - assert( var.dump() == string_type("[bsl::var::Double]-1e-100") ); - assert( var.dump(999) == string_type("[bsl::var::Double]-1e-100") ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Double var; - assert( var.to_string() == string_type("0") ); - } - - { - bsl::var::Double var(123.45); - assert( var.to_string() == string_type("123.45") ); - } - - { - bsl::var::Double var(-1e-100); - assert( var.to_string() == string_type("-1e-100") ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Double().get_type() == string_type("bsl::var::Double") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::Double dbl(123); - dbl = true; - assert( dbl.to_double() == 1 ); - } - { - bsl::var::Double dbl(123); - dbl = false; - assert( dbl.to_double() == 0 ); - } - // to bool - { - assert( bsl::var::Double().to_bool() == false ); - assert( bsl::var::Double(-1).to_bool() == true ); - } - } - - virtual void test_raw(){ - test_invalid_raw(_dbl); - } - - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - - test_valid_number( bsl::var::Double(-1), double(-1.0) ); - test_valid_number( bsl::var::Double(0), double(0.0) ); - test_valid_number( bsl::var::Double(double(LLONG_MAX)*double(LLONG_MAX)), double(LLONG_MAX)*double(LLONG_MAX) ); - test_valid_number( bsl::var::Double(-double(LLONG_MAX)*double(LLONG_MAX)), -double(LLONG_MAX)*double(LLONG_MAX) ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Double v(123); - assert(v.clone(rp).to_string() == v.to_string() ); - assert(v.clone(rp).get_type() == v.get_type() ); - - test_valid_number( bsl::var::Double(-1).clone(rp), double(-1.0) ); - test_valid_number( bsl::var::Double(0).clone(rp), double(0.0) ); - test_valid_number( bsl::var::Double(double(LLONG_MAX)*double(LLONG_MAX)).clone(rp), double(LLONG_MAX)*double(LLONG_MAX) ); - test_valid_number( bsl::var::Double(-double(LLONG_MAX)*double(LLONG_MAX)).clone(rp), -double(LLONG_MAX)*double(LLONG_MAX) ); - } - - virtual void test_string(){ - test_invalid_string(_dbl); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_dbl); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_dbl); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_dbl); - } - - virtual void test_to_int32(){ - { - assert( bsl::var::Double().to_int32() == 0 ); - assert( bsl::var::Double(-1).to_int32() == -1 ); - assert( bsl::var::Double(1234567).to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - assert( bsl::var::Double().to_int64() == 0 ); - assert( bsl::var::Double(-1).to_int64() == -1 ); - assert( bsl::var::Double(1234567).to_int64() == 1234567 ); - } - } - - virtual void test_to_double(){ - { - assert( bsl::var::Double().to_double() == 0 ); - assert( bsl::var::Double(-1.2345).to_double() == -1.2345 ); - assert( bsl::var::Double(1234567.3435).to_double() == 1234567.3435 ); - } - } - -private: - bsl::var::Double _dbl; -}; - -int main(){ - TestVarDouble().test_all(); - return 0; -} - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Function.cpp b/bsl/var/unittest/test_var_Function.cpp deleted file mode 100644 index a8fef77cd2b48ebb193b5d1572e365741aa205a1..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Function.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Function.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_var_Function.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:57:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "test_var_invalid.h" - -bsl::var::IVar& echo( bsl::var::IVar& args, bsl::ResourcePool& ){ - return args; -} - -bsl::var::IVar& join( bsl::var::IVar& args, bsl::ResourcePool& rp ){ - bsl::var::IVar::string_type res; - for( size_t i = 0; i < args.size(); ++ i ){ - res.append(args[int(i)].to_string()); - } - return rp.create(res); -} - -class TestVarFunction: public ITestVar{ -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarFunction() - :_func(echo, "echo"){} - - virtual ~TestVarFunction(){} - - //speical methods - virtual void test_special(){ - // ctors - { - bsl::var::Function func1(&echo, "echo"); - assert( func1.to_string() == "echo" ); - bsl::var::Function func2(func1); - assert( func2.to_string() == "echo" ); - } - // copy assign - { - bsl::var::Function func1(&echo, "echo"); - bsl::var::Function func2(&join, "join"); - func1 = func2; - assert( func1.to_string() == "join" ); - } - } - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Function(&echo, "echo") ); - } - - - virtual void test_clear() { - { - bsl::var::Function func1(&echo, "echo"); - func1.clear(); //no effect - assert( func1.to_string() == "echo" ); - } - } - - virtual void test_dump() { - { - bsl::var::Function func(echo, "echo"); - assert( func.dump() == "[bsl::var::Function]echo" ); - assert( func.dump(999) == "[bsl::var::Function]echo" ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Function func(echo, "echo"); - assert( func.to_string() == "echo" ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Function(&echo, "echo").get_type() == string_type("bsl::var::Function") ); - } - - //method for value - virtual void test_bool(){ - test_invalid_bool(_func); - } - virtual void test_raw(){ - test_invalid_raw(_func); - } - virtual void test_number(){ - test_invalid_number(_func); - } - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Function f(&echo, "echo"); - bsl::var::Function& cl = f.clone(rp); - bsl::var::MagicRef args(rp); - args[0] = 123; - args[1] = "hello"; - assert( cl.get_type() == string_type("bsl::var::Function") ); - assert( cl.to_string() == string_type("echo") ); - bsl::var::IVar& res = cl(args, rp); - assert( res[0].to_int32() == 123 ); - assert( res[1].c_str() == args[1].c_str() ); - } - - virtual void test_string(){ - test_invalid_string(_func); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_func); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_func); - } - - //methods for callable - virtual void test_callable(){ - test_operator_paren(); - } - - virtual void test_operator_assign(){ - //valid assign - { - bsl::var::Function func1(&echo, "echo"), func2(&join, "join"); - bsl::var::IVar& ivar = func1; - func2 = ivar; - assert( func2.to_string() == func1.to_string() ); - - } - //invalid assign - { - bsl::var::Function func(&echo, "echo"); - bsl::var::Int32 i32; - ASSERT_THROW( func = 123, bsl::InvalidOperationException ); - ASSERT_THROW( func = 123LL, bsl::InvalidOperationException ); - ASSERT_THROW( func = 123.456, bsl::InvalidOperationException ); - ASSERT_THROW( func = "123", bsl::InvalidOperationException ); - ASSERT_THROW( func = i32, bsl::InvalidOperationException ); - } - } - - virtual void test_operator_paren(){ - { - bsl::var::Array args; - bsl::ResourcePool rp; - bsl::var::IVar& res = bsl::var::Function(&echo, "echo")(args, rp); - assert( &res == &args ); - } - { - bsl::ResourcePool rp; - bsl::var::Array args; - bsl::var::Int32 i32(123); - bsl::var::String str("hao"); - args[0] = str; - args[1] = i32; - bsl::var::IVar& res = bsl::var::Function(&join, "join")(args, rp); - assert( res.to_string() == "hao123" ); - } - { - bsl::ResourcePool rp; - bsl::var::Dict self; - bsl::var::Array args; - bsl::var::Int32 i32(123); - bsl::var::String str("hao"); - args[0] = str; - args[1] = i32; - bsl::var::IVar& res = bsl::var::Function(&join, "join")(self, args, rp); - assert( res.to_string() == "hao123" ); - } - } -private: - bsl::var::Function _func; -}; - -int main(){ - TestVarFunction test; - test.test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Int32.cpp b/bsl/var/unittest/test_var_Int32.cpp deleted file mode 100644 index 487d2d63a5664add8e643a959f720c09d25e4726..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Int32.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include "bsl/var/implement.h" -#include "test_var_invalid.h" - -class TestVarInt32: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarInt32() - :_i32(123){} - - virtual ~TestVarInt32(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::Int32 i = 123; - bsl::var::Int32 j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = 456; - assert( j.to_int32() == 123 ); - } - //copy assign - { - bsl::var::Int32 i = 123; - bsl::var::Int32 j; - j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = 456; - assert( j.to_int32() == 123 ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Int32() ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::Int32 i; - i = 123; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - // = long long - { - - bsl::var::Int32 i; - ASSERT_THROW( i = 1234567891234567LL, bsl::OverflowException ); - } - - // = double - { - bsl::var::Int32 i; - i = 4670.9394; - assert( i.to_int32() == 4670 ); - assert( i.to_int64() == 4670 ); - assert( i.to_double() == 4670 ); - } - - // = const char * - { - bsl::var::Int32 i; - i = "46709394"; - assert( i.to_int32() == 46709394 ); - } - - // = string_type - { - bsl::var::Int32 i; - i = bsl::var::IVar::string_type("46709394"); - assert( i.to_int32() == 46709394 ); - } - - // = Int32 - { - bsl::var::Int32 i, j; - j = 123; - i = j; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - // = *this - { - bsl::var::Int32 i; - i = 123; - i = i; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Int32 i(123); - i.clear(); //assert no-throw - assert(i.to_int32() == 0); - } - } - - virtual void test_dump() { - { - bsl::var::Int32 i; - assert( i.dump() == string_type("[bsl::var::Int32]0") ); - assert( i.dump(999) == string_type("[bsl::var::Int32]0") ); - } - - { - bsl::var::Int32 i(1234567); - assert( i.dump() == string_type("[bsl::var::Int32]1234567") ); - assert( i.dump(999) == string_type("[bsl::var::Int32]1234567") ); - } - } - - virtual void test_to_string() { - { - bsl::var::Int32 i; - assert( i.to_string() == string_type("0") ); - } - - { - bsl::var::Int32 i(1234567); - assert( i.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::Int32().get_type() == string_type("bsl::var::Int32") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::Int32 i32(123); - i32 = true; - assert( i32.to_int32() == 1 ); - } - { - bsl::var::Int32 i32(123); - i32 = false; - assert( i32.to_int32() == 0 ); - } - // to bool - { - assert( bsl::var::Int32().to_bool() == false ); - assert( bsl::var::Int32(-1).to_bool() == true ); - } - } - virtual void test_raw(){ - test_invalid_raw(_i32); - } - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - - test_valid_number( bsl::var::Int32(INT_MIN), static_cast(INT_MIN) ); - test_valid_number( bsl::var::Int32(INT_MAX), static_cast(INT_MAX) ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Int32 i32; - assert( i32.clone(rp).get_type() == i32.get_type() ); - assert( i32.clone(rp).to_int32() == i32.to_int32() ); - - test_valid_number( bsl::var::Int32(INT_MIN).clone(rp), static_cast(INT_MIN) ); - test_valid_number( bsl::var::Int32(INT_MAX).clone(rp), static_cast(INT_MAX) ); - } - virtual void test_string(){ - test_invalid_string(_i32); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_i32); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_i32); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_i32); - } - - virtual void test_to_int32(){ - { - assert( bsl::var::Int32().to_int32() == 0 ); - assert( bsl::var::Int32(-1).to_int32() == -1 ); - assert( bsl::var::Int32(1234567).to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - assert( bsl::var::Int32().to_int64() == 0 ); - assert( bsl::var::Int32(-1).to_int64() == -1 ); - assert( bsl::var::Int32(1234567).to_int64() == 1234567 ); - } - } - - virtual void test_to_double(){ - { - assert( bsl::var::Int32().to_double() == 0 ); - assert( bsl::var::Int32(-1).to_double() == -1 ); - assert( bsl::var::Int32(1234567).to_double() == 1234567 ); - } - } - -private: - bsl::var::Int32 _i32; -}; - -int main(){ - TestVarInt32().test_all(); - return 0; -} - - diff --git a/bsl/var/unittest/test_var_Int64.cpp b/bsl/var/unittest/test_var_Int64.cpp deleted file mode 100644 index 938109fdc5bec8c5a68ea97fd3679516d0a1ee83..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Int64.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#include "bsl/var/Int64.h" -#include "test_var_invalid.h" - -class TestVarInt64: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - TestVarInt64() - :_i64(1234567891234567LL){} - - virtual ~TestVarInt64(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::Int64 i = 1234567891234567LL; - bsl::var::Int64 j = i; - assert( j.is_int64() ); - assert( j.to_int64() == 1234567891234567LL ); - i = 987654321098765LL; - assert( j.to_int64() == 1234567891234567LL ); - } - //copy assign - { - bsl::var::Int64 i = 1234567891234567LL; - bsl::var::Int64 j; - j = i; - assert( j.is_int64() ); - assert( j.to_int64() == 1234567891234567LL ); - i = 987654321098765LL; - assert( j.to_int64() == 1234567891234567LL ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Int64() ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::Int64 i; - i = 123; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - // = long long - { - bsl::var::Int64 i; - i = 1234567891234567LL; - ASSERT_THROW( i.to_int32(), bsl::OverflowException ); - assert( i.to_int64() == 1234567891234567LL ); - assert( i.to_double() == double(1234567891234567LL) ); - } - // = double - { - bsl::var::Int64 i; - i = 12345678904670.9394; - ASSERT_THROW( i.to_int32(), bsl::OverflowException ); - assert( i.to_int64() == (long long)(12345678904670.9394) ); - assert( i.to_double() ==(long long)(12345678904670.9394) ); - } - - // = const char * - { - bsl::var::Int64 i; - i = "123456746709394"; - assert( i.to_int64() == 123456746709394LL ); - } - - // = string_type - { - bsl::var::Int64 i; - i = bsl::var::IVar::string_type("123456746709394"); - assert( i.to_int64() == 123456746709394LL ); - } - - // = Int32 - { - bsl::var::Int32 j; - bsl::var::Int64 i; - j = 123; - i = j; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - // = Int64 - { - bsl::var::Int64 i, j; - j = 1234567891234567LL; - i = j; - ASSERT_THROW( i.to_int32(), bsl::OverflowException ); - assert( i.to_int64() == 1234567891234567LL ); - } - - // = *this - { - bsl::var::Int64 i; - i = 123; - i = i; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Int64 i(1234567891234LL); - i.clear(); //assert no-throw - assert(i.to_int64() == 0); - } - } - - virtual void test_dump() { - { - bsl::var::Int64 i; - assert( i.dump() == string_type("[bsl::var::Int64]0") ); - assert( i.dump(999) == string_type("[bsl::var::Int64]0") ); - } - - { - bsl::var::Int64 i(1234567891234567LL); - assert( i.dump() == string_type("[bsl::var::Int64]1234567891234567") ); - assert( i.dump(999) == string_type("[bsl::var::Int64]1234567891234567") ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Int64 i; - assert( i.to_string() == string_type("0") ); - } - - { - bsl::var::Int64 i(1234567891234567LL); - assert( i.to_string() == string_type("1234567891234567") ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Int64().get_type() == string_type("bsl::var::Int64") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::Int64 i64(123); - i64 = true; - assert( i64.to_int64() == 1 ); - } - { - bsl::var::Int64 i64(123); - i64 = false; - assert( i64.to_int64() == 0 ); - } - // to bool - { - assert( bsl::var::Int64().to_bool() == false ); - assert( bsl::var::Int64(-1).to_bool() == true ); - } - } - - virtual void test_raw(){ - test_invalid_raw(_i64); - } - - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - - test_valid_number( bsl::var::Int64(-1), -1LL ); - test_valid_number( bsl::var::Int64(0), 0LL ); - test_valid_number( bsl::var::Int64(LLONG_MIN), LLONG_MIN ); - test_valid_number( bsl::var::Int64(LLONG_MAX), LLONG_MAX ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Int64 v(123); - assert(v.clone(rp).to_string() == v.to_string() ); - assert(v.clone(rp).get_type() == v.get_type() ); - - test_valid_number( bsl::var::Int64(-1).clone(rp), -1LL ); - test_valid_number( bsl::var::Int64(0).clone(rp), 0LL ); - test_valid_number( bsl::var::Int64(LLONG_MIN).clone(rp), LLONG_MIN ); - test_valid_number( bsl::var::Int64(LLONG_MAX).clone(rp), LLONG_MAX ); - } - - virtual void test_string(){ - test_invalid_string(_i64); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_i64); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_i64); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_i64); - } - - - virtual void test_to_int32(){ - { - assert( bsl::var::Int64().to_int32() == 0 ); - assert( bsl::var::Int64(-1).to_int32() == -1 ); - assert( bsl::var::Int64(1234567).to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - assert( bsl::var::Int64().to_int64() == 0 ); - assert( bsl::var::Int64(-1).to_int64() == -1 ); - assert( bsl::var::Int64(1234567).to_int64() == 1234567 ); - } - } - - virtual void test_to_double(){ - { - assert( bsl::var::Int64().to_double() == 0 ); - assert( bsl::var::Int64(-1).to_double() == -1 ); - assert( bsl::var::Int64(1234567).to_double() == 1234567 ); - } - } - -private: - bsl::var::Int64 _i64; -}; - -int main(){ - TestVarInt64().test_all(); - return 0; -} - - diff --git a/bsl/var/unittest/test_var_MagicRef.cpp b/bsl/var/unittest/test_var_MagicRef.cpp deleted file mode 100644 index efc156030419ba6cc5760b9e96e4a7dc1118ad79..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_MagicRef.cpp +++ /dev/null @@ -1,1099 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_MagicRef.cpp,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarMagicRef.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 12:32:18 - * @version $Revision: 1.2 $ - * @brief - * - **/ - -#include "test_var_invalid.h" -#include "bsl/var/implement.h" - -class TestVarMagicRef: public ITestVar{ - -public: - TestVarMagicRef(){} - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarMagicRef(){} - - //special methods - virtual void test_special(){ - bsl::ResourcePool rp; - //ref - { - bsl::var::MagicRef ref(rp); - assert( ref.ref().is_null() ); - } - { - bsl::var::Int32 i32 = 123; - bsl::var::MagicRef ref(rp); - ref = i32; - assert( &ref.ref() == &i32 ); - } - //copy ctor - { - bsl::var::Int32 i32 = 123; - bsl::var::Int64 i64 = 456; - bsl::var::MagicRef i(rp); - i = i32; - bsl::var::MagicRef j(i); - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = i64; - assert( j.to_int32() == 123 ); - } - //copy assign - { - bsl::var::MagicRef i(rp); - i = 123; - bsl::var::MagicRef j(i); - j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = 456; - assert( j.to_int32() == 456 ); - } - } - - //methods for all - virtual void test_mask(){ - bsl::ResourcePool rp; - test_mask_consistency( bsl::var::MagicRef(rp) ); - bsl::var::MagicRef mr(rp); - mr["abc"] = 123; - mr["arr"][0] = "hello"; - test_mask_consistency( mr ); - test_mask_consistency( mr["abc"] ); - test_mask_consistency( mr["arr"] ); - test_mask_consistency( mr["arr"][0] ); - } - - virtual void test_operator_assign(){ - bsl::ResourcePool rp; - // = int - { - bsl::var::MagicRef ref(rp); - ref = 123; - assert( ref.to_int32() == 123 ); - assert( ref.to_int64() == 123 ); - - ref = 456; - assert( ref.to_int32() == 456 ); - assert( ref.to_int64() == 456 ); - - } - - // = long long - { - - bsl::var::MagicRef ref(rp); - ref = 9876543219876543LL; - ASSERT_THROW( ref.to_int32(), bsl::OverflowException ); - assert( ref.to_int64() == 9876543219876543LL ); - ref = 1234567891234567LL; - assert( ref.to_int64() == 1234567891234567LL ); - ASSERT_THROW( ref.to_int32(), bsl::OverflowException ); - - assert( ref.to_int64() == 1234567891234567LL ); - } - - // = double - { - - bsl::var::MagicRef ref(rp); - ref = 987654321.9876543; - assert( ref.to_double()== double(987654321.9876543) ); - ref = 123456789.1234567; - assert( ref.to_double() == 123456789.1234567 ); - assert( ref.to_int32() == int(123456789.1234567) ); - assert( ref.to_double() == 123456789.1234567 ); - } - - // = string_type - { - - bsl::var::MagicRef ref(rp); - ref = "987654321.9876543"; - assert( ref.to_double()== double(987654321.9876543) ); - - ref = "123456789.1234567"; - assert( ref.to_double() == 123456789.1234567 ); - assert( ref.to_int32() == 123456789 ); - assert( ref.to_int64() == 123456789 ); - assert( ref.to_double() == double(123456789.1234567) ); - - ref = "hello world!"; - assert( ref.to_string() == "hello world!" ); - - } - - // = MagicRef - { - bsl::var::MagicRef ref1(rp), ref2(rp); - ref1 = 123; - - ref2 = ref1; - assert( ref2.to_int32() == 123 ); - assert( ref2.to_int64() == 123 ); - - ref1 = 456; - assert( ref2.to_int32() == 456 ); - assert( ref2.to_int64() == 456 ); - - } - - // = *this - { - bsl::var::MagicRef ref(rp); - ref = 123; - ref = ref; - assert( ref.to_int32() == 123 ); - assert( ref.to_int64() == 123 ); - } - - } - - virtual void test_size() { - bsl::ResourcePool rp; - { - bsl::var::MagicRef ref(rp); - ref[100] = bsl::var::Null::null; - assert( ref.size() == 101 ); - } - - { - bsl::var::MagicRef ref(rp); - test_invalid_array(ref); - } - } - - virtual void test_clear() { - bsl::ResourcePool rp; - { - bsl::var::Int32 i32(123); - bsl::var::MagicRef ref(rp); - ref = i32; - ref.clear(); //assert no-throw - assert(ref.to_int32() == 0); - assert(&ref.ref() == &i32 ); - } - } - - virtual void test_dump() { - bsl::ResourcePool rp; - { - bsl::var::MagicRef ref(rp); - see( ref.dump().c_str() ); - assert( NULL != strstr( ref.dump().c_str(), "null" )); - } - { - bsl::var::Int32 i32; - bsl::var::MagicRef ref(rp); - ref = i32; - see( ref.dump().c_str() ); - assert( NULL != strstr( ref.dump().c_str(), "0" ) ); - assert( NULL != strstr( ref.dump(999).c_str(), "0" ) ); - } - - { - bsl::var::String str = "1234567"; - bsl::var::MagicRef ref(rp); - ref = str; - see( ref.dump().c_str() ); - assert( NULL != strstr( ref.dump().c_str(), "1234567" ) ); - assert( NULL != strstr( ref.dump(999).c_str(), "1234567" ) ); - } - } - - virtual void test_to_string() { - bsl::ResourcePool rp; - { - bsl::var::Int32 i32; - bsl::var::MagicRef ref(rp); - ref = i32; - assert( ref.to_string() == string_type("0") ); - } - - { - bsl::var::String str = "1234567"; - bsl::var::MagicRef ref(rp); - ref = str; - assert( ref.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - bsl::ResourcePool rp; - assert( bsl::var::MagicRef(rp).get_type() == string_type("bsl::var::MagicRef()") ); - bsl::var::MagicRef mr(rp); - bsl::var::Int32 i32; - mr = i32; - assert( mr.get_type() == string_type("bsl::var::MagicRef(bsl::var::Int32)") ); - } - - //method for value - virtual void test_bool(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref["ab"] = "dict"; - test_invalid_bool(ref); - test_with_bool(); - } - virtual void test_raw(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref = 123; - test_invalid_raw(ref); - test_with_raw(); - } - virtual void test_number(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref["abc"][0] = 456; - test_invalid_number(ref); - test_to_int32(); - test_to_int64(); - test_to_double(); - - /* -signed char int8 SCHAR_MIN -signed char int8 SCHAR_MAX -unsigned char uint8 0 -unsigned char uint8 UCHAR_MAX -signed short int16 SHRT_MIN -signed short int16 SHRT_MAX -unsigned short uint16 0 -unsigned short uint16 USHRT_MAX -signed int int32 INT_MIN -signed int int32 INT_MAX -unsigned int uint32 0 -unsigned int uint32 UINT_MAX -signed long long int64 LLONG_MIN -signed long long int64 LLONG_MAX -unsigned long long uint64 0 -unsigned long long uint64 ULLONG_MAX - */ - { - bsl::var::MagicRef mr(rp); - mr = static_cast(SCHAR_MIN); - test_valid_number( mr, static_cast(SCHAR_MIN) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(SCHAR_MAX); - test_valid_number( mr, static_cast(SCHAR_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(0); - test_valid_number( mr, static_cast(0) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(UCHAR_MAX); - test_valid_number( mr, static_cast(UCHAR_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(SHRT_MIN); - test_valid_number( mr, static_cast(SHRT_MIN) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(SHRT_MAX); - test_valid_number( mr, static_cast(SHRT_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(0); - test_valid_number( mr, static_cast(0) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(USHRT_MAX); - test_valid_number( mr, static_cast(USHRT_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(INT_MIN); - test_valid_number( mr, static_cast(INT_MIN) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(INT_MAX); - test_valid_number( mr, static_cast(INT_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(0); - test_valid_number( mr, static_cast(0) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(UINT_MAX); - test_valid_number( mr, static_cast(UINT_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(LLONG_MIN); - test_valid_number( mr, static_cast(LLONG_MIN) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(LLONG_MAX); - test_valid_number( mr, static_cast(LLONG_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(0); - test_valid_number( mr, static_cast(0) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(ULLONG_MAX); - test_valid_number( mr, static_cast(ULLONG_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = double(LLONG_MAX)*double(LLONG_MAX); - test_valid_number( mr, double(LLONG_MAX)*double(LLONG_MAX) ); - mr = -double(LLONG_MAX)*double(LLONG_MAX); - test_valid_number( mr, -double(LLONG_MAX)*double(LLONG_MAX) ); - } - - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef mr1(rp); - mr1[0] = 123; - mr1[1]["abc"] = ULLONG_MAX; - bsl::var::IVar& mr2 = mr1.clone(rp); - assert(mr2[0].to_int32() == 123); - assert(mr2[1]["abc"].to_uint64() == ULLONG_MAX); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(0); - test_valid_number( mr.clone(rp), static_cast(0) ); - } - { - bsl::var::MagicRef mr(rp); - mr = static_cast(ULLONG_MAX); - test_valid_number( mr.clone(rp), static_cast(ULLONG_MAX) ); - } - { - bsl::var::MagicRef mr(rp); - mr = double(LLONG_MAX)*double(LLONG_MAX); - test_valid_number( mr.clone(rp), double(LLONG_MAX)*double(LLONG_MAX) ); - } - - } - - virtual void test_string(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref[0] = 123; - test_invalid_string(ref); - test_c_str(); - } - - //methods for array - virtual void test_array(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref = "123"; - test_invalid_array(ref); - test_array_get(); - test_array_set(); - test_array_del(); - test_array_iterator(); - test_array_const_iterator(); - test_array_operator_square(); - } - - //methods for dict - virtual void test_dict(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref = 123; - test_invalid_dict(ref); - test_dict_get(); - test_dict_set(); - test_dict_del(); - test_dict_iterator(); - test_dict_const_iterator(); - test_dict_operator_square(); - } - - //methods for callable - virtual void test_callable(){ - bsl::ResourcePool rp; - bsl::var::MagicRef ref(rp); - ref = 123; - test_invalid_callable(ref); - test_operator_paren(); - } - - virtual void test_with_bool(){ - bsl::ResourcePool rp; - { - bsl::var::Bool b; - b = true; - bsl::var::MagicRef ref(rp); - ref = b; - assert( ref.to_bool() == true ); - ref = false; - assert( b.to_bool() == false ); - } - } - - virtual void test_with_raw(){ - bsl::var::raw_t raw_1("Acumon", 3); - bsl::var::raw_t raw_2; - bsl::ResourcePool rp; - - { - bsl::var::ShallowRaw raw1(raw_1); - bsl::var::MagicRef ref(rp); - ref = raw1; - assert( ref.to_raw().data == raw_1.data ); - assert( ref.to_raw().length == raw_1.length ); - ref = raw_2; - assert( raw1.to_raw().data == raw_2.data ); - assert( raw1.to_raw().length == raw_2.length ); - } - - } - - virtual void test_to_int32(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).to_int32(), bsl::InvalidOperationException ); - } - { - bsl::var::Int32 i32 = -1; - bsl::var::MagicRef mr(rp); - mr = i32; - assert( mr.to_int32() == -1 ); - } - } - - virtual void test_to_int64(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).to_int64(), bsl::InvalidOperationException ); - } - { - bsl::var::Int64 i64 = 1234567891234567LL; - bsl::var::MagicRef mr(rp); - mr = i64; - assert( mr.to_int64() == 1234567891234567LL ); - } - } - - virtual void test_to_double(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).to_double(), bsl::InvalidOperationException ); - } - { - bsl::var::Double var = 123456789.1234567; - bsl::var::MagicRef mr(rp); - mr = var; - assert( mr.to_double() == 123456789.1234567 ); - } - } - - virtual void test_c_str(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).c_str(), bsl::InvalidOperationException ); - } - { - bsl::var::String var = "123456789.1234567"; - bsl::var::MagicRef mr(rp); - mr = var; - assert( mr.c_str() == var.c_str()); - assert( mr.c_str_len() == var.c_str_len()); - } - { - bsl::var::String var = string_type("123456789.1234567"); - bsl::var::MagicRef mr(rp); - mr = var; - assert( mr.c_str() == var.c_str()); - assert( mr.c_str_len() == var.c_str_len()); - } - } - - //methods for array - virtual void test_array_get(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).get(0), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 123; - arr[100] = i32; - bsl::var::MagicRef ref(rp); - ref = arr; - assert( ref.get(100).to_int32() == 123 ); - } - - } - - virtual void test_array_set(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef var(rp); - var = 123; - ASSERT_THROW( var.set(0, var), bsl::InvalidOperationException ); - - } - { - bsl::var::Array arr; - bsl::var::MagicRef ref(rp); - ref = arr; - ref.set(100, arr); - bsl::var::MagicRef r(rp); - r = arr[100]; - assert( &r.ref() == &arr ); - } - } - - virtual void test_array_del(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef var(rp); - var = 123; - ASSERT_THROW( var.del(0), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 123; - arr[100] = i32; - bsl::var::MagicRef ref(rp); - ref = arr; - assert( ref.del(99) == false ); - assert( ref.del(100) == true ); - assert( ref.del(101) == false ); - assert( arr[100].is_null() ); - } - - } - - virtual void test_array_iterator(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef var(rp); - var = 123; - ASSERT_THROW( var.array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( var.array_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::MagicRef ref(rp); - ref = arr; - //empty array: - assert( ref.array_begin() == ref.array_end() ); - } - { - bsl::var::Array arr; - bsl::var::MagicRef ref(rp); - ref = arr; - ref[0] = rp.create(123); - ref[2] = rp.create(456); - bsl::var::Array::array_iterator iter = ref.array_begin(); - - //iter => ref[0] - assert( iter == ref.array_begin() ); - assert( iter != ref.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => ref[1] - assert( iter != ref.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - iter->value() = rp.create(789); - assert( ref[1].is_int32() ); - assert( ref[1].to_int32() == 789 ); - assert( (++ iter)->key() == 2 ); - - //iter => ref[2] - assert( iter != ref.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == ref.array_end() ); - - //iter == ref.array_end() - assert( iter == ref.array_end() ); - } - - } - - virtual void test_array_const_iterator(){ - /* - bsl::ResourcePool rp; - { - const bsl::var::MagicRef ref(rp); - ASSERT_THROW( ref.array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.array_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - const bsl::var::MagicRef ref(rp); - ref = arr; - //empty array: - assert( ref.array_begin() == ref.array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array _arr; - _arr[0] = rp.create(123); - _arr[2] = rp.create(456); - const bsl::var::MagicRef ref(rp); - ref = _arr; - bsl::var::IVar::array_const_iterator iter = ref.array_begin(); - - //iter => ref[0] - assert( iter == ref.array_begin() ); - assert( iter != ref.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => ref[1] - assert( iter != ref.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - assert( (++ iter)->key() == 2 ); - - //iter => ref[2] - assert( iter != ref.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == ref.array_end() ); - - //iter == ref.array_end() - assert( iter == ref.array_end() ); - } - */ - } - - virtual void test_array_operator_square(){ - bsl::ResourcePool rp; - - //non-const - { - bsl::var::Array arr; - bsl::var::MagicRef ref(rp); - ref = arr; - ref[100] = rp.create(123); - assert( ref.size() == 101 ); - assert( ref[100].is_int32() ); - assert( ref[100].to_int32() == 123); - } - { - bsl::var::Array arr; - bsl::var::MagicRef ref(rp); - ref = arr; - assert( ref[456].is_ref() ); - assert( ref[789].is_null() ); - } - - //const - { - bsl::var::Array _arr; - bsl::var::MagicRef ref(rp); - ref = _arr; - _arr[100] = rp.create(123); - assert( ref.size() == 101 ); - assert( ref[100].is_int32() ); - assert( ref[100].to_int32() == 123); - - assert( ref[0].is_null() ); - } - - } - - //methods for dict - virtual void test_dict_iterator(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef ref(rp); - ASSERT_THROW( ref.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.dict_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - //empty ref: - assert( ref.dict_begin() == ref.dict_end() ); - } - - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - ref["0"] = rp.create(123); - ref["2"] = rp.create(456); - ref["null"] = rp.create(); - bsl::var::IVar::dict_iterator iter = ref.dict_begin(); - - - assert( iter == ref.dict_begin() ); - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - bsl::var::IVar& value2 = iter->value(); - ++iter; - - //iter == ref.dict_end() - assert( iter == ref.dict_end() ); - - assert( (key0 == "0" && value0.to_int32() == 123 && (value0 = 1230, true)) /* ref["0"] will be Int(1230) */ - || (key1 == "0" && value1.to_int32() == 123 && (value1 = 1230, true)) - || (key2 == "0" && value2.to_int32() == 123 && (value2 = 1230, true)) - ); - - assert( (key0 == "2" && value0.to_int32() == 456 && (value0 = 4560, true)) /* ref["0"] will be Int(4560) */ - || (key1 == "2" && value1.to_int32() == 456 && (value1 = 4560, true)) - || (key2 == "2" && value2.to_int32() == 456 && (value2 = 4560, true)) - ); - - assert( (key0 == "null" && value0.is_null() && (value0 = rp.create(-1), true)) - || (key1 == "null" && value1.is_null() && (value1 = rp.create(-1), true)) - || (key2 == "null" && value2.is_null() && (value2 = rp.create(-1), true)) - ); - - assert( ref["0"].to_int32() == 1230 ); - assert( ref["2"].to_int32() == 4560 ); - assert( ref["null"].to_int32() == -1); - - } - - } - - virtual void test_dict_const_iterator(){ - /* - bsl::ResourcePool rp; - { - const bsl::var::MagicRef ref(rp); - ASSERT_THROW( ref.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.dict_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - const bsl::var::MagicRef ref(rp); - ref = dict; - //empty ref: - assert( ref.dict_begin() == ref.dict_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Dict _dict; - _dict["0"] = rp.create(123); - _dict["2"] = rp.create(456); - _dict["null"] = rp.create(); - const bsl::var::MagicRef ref = _dict; - bsl::var::IVar::dict_const_iterator iter = ref.dict_begin(); - - assert( iter == ref.dict_begin() ); - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - const bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - const bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - const bsl::var::IVar& value2 = iter->value(); - ++ iter; - - //iter == ref.dict_end() - assert( iter == ref.dict_end() ); - - assert( key0 == "0" && value0.to_int32() == 123 - || key1 == "0" && value1.to_int32() == 123 - || key2 == "0" && value2.to_int32() == 123 - ); - - assert( key0 == "2" && value0.to_int32() == 456 - || key1 == "2" && value1.to_int32() == 456 - || key2 == "2" && value2.to_int32() == 456 - ); - - assert( key0 == "null" && value0.is_null() - || key1 == "null" && value1.is_null() - || key2 == "null" && value2.is_null() - ); - - assert( ref["0"].to_int32() == 123 ); - assert( ref["2"].to_int32() == 456 ); - assert( ref["null"].is_null()); - - } - */ - } - - virtual void test_dict_get(){ - bsl::ResourcePool rp; - { - ASSERT_THROW( bsl::var::MagicRef(rp).get(""), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::MagicRef(rp).get("a key"), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::MagicRef(rp).get(string_type("another key")), bsl::InvalidOperationException ); - } - //normal get - { - bsl::var::Dict dict; - bsl::var::MagicRef mr(rp); - mr = dict; - assert( mr.get("").is_null() ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef mr(rp); - mr = dict; - assert( mr.get("a key").is_null() ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef mr(rp); - mr = dict; - assert( mr.get(string_type("another key")).is_null() ); - } - { - bsl::var::Dict _dict; - bsl::var::MagicRef ref(rp); - ref = _dict; - bsl::var::Int32 i32 = 4670; - - _dict["an int"] = i32; - _dict["null"] = bsl::var::Null::null; - - assert( ref.get("an int").to_int32() == i32.to_int32() ); - assert( ref.get("null").is_null() ); - - assert( ref.get("unexist").is_null() ); - } - //geek get - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - bsl::var::Int32 i32 = 7776; - ref["an int"] = i32; - ref.get("an int") = 0; - assert( ref["an int"].to_int32() == 0 ); - } - //get with default - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - bsl::var::Int32 i32 = 9394; - bsl::var::MagicRef ref_null(rp); - bsl::var::MagicRef ref_i32(rp); - ref_i32 = i32; - - ref["an int"] = i32; - ref["null"] = bsl::var::Null::null; - - assert( ref.get("an int", ref_null).to_int32() == i32.to_int32() ); - assert( ref.get("null", ref_null).is_null() ); - assert( ref.get("unexist", ref_i32).to_int32() == i32.to_int32() ); - } - } - - virtual void test_dict_set(){ - bsl::ResourcePool rp; - bsl::var::Int32 i32 = 123; - bsl::var::MagicRef ref(rp); - ref = i32; - { - ASSERT_THROW( ref.set(string_type(""),ref), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( ref.set("some key",ref), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( ref.set(string_type("another key"),ref), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef ref1(rp); - ref1 = dict; - bsl::var::Int32 i321 = 4670; - ref1.set("i32", i321); - assert( ref1["i32"].to_int32() == 4670 ); - } - } - - virtual void test_dict_del(){ - bsl::ResourcePool rp; - { - bsl::var::MagicRef ref(rp); - ref = 123; - ASSERT_THROW( ref.del(""), bsl::InvalidOperationException ); - } - { - bsl::var::MagicRef ref(rp); - ref = 123; - ASSERT_THROW( ref.del("a key"), bsl::InvalidOperationException ); - } - { - bsl::var::MagicRef ref(rp); - ref = 123; - ASSERT_THROW( ref.del(string_type("another key")), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - bsl::var::Int32 i32 = 874; - ref["del"] = i32; - assert( ref.size() == 1 ); - assert( ref["del"].to_int32() == 874 ); - ref.del("del"); - assert( ref.size() == 0 ); - assert( ref.get("del").is_null() ); - } - } - - virtual void test_dict_operator_square(){ - bsl::ResourcePool rp; - //non const - { - bsl::var::MagicRef ref(rp); - ref = 123; - ASSERT_THROW( ref[""], bsl::InvalidOperationException ); - ASSERT_THROW( ref["awesome key"], bsl::InvalidOperationException ); - } - //const - { - const bsl::var::MagicRef ref(rp); - ASSERT_THROW( ref[""], bsl::InvalidOperationException ); - ASSERT_THROW( ref["aweful key"], bsl::InvalidOperationException ); - } - - //non-const - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - ref["acumon"] = rp.create(123); - assert( ref.size() == 1 ); - assert( ref["acumon"].is_int32() ); - assert( ref[string_type("acumon")].to_int32() == 123); - - ref["abc"] = ref["acumon"]; - assert( ref["abc"].to_int32() == 123 ); - } - { - bsl::var::Dict dict; - bsl::var::MagicRef ref(rp); - ref = dict; - assert( ref[""].is_ref() ); - assert( ref[""].is_null() ); - } - - //const - { - bsl::var::Dict _dict; - _dict["acumon"] = rp.create(123); - const bsl::var::Dict& ref = _dict; - assert( ref.size() == 1 ); - assert( ref[string_type("acumon")].is_int32() ); - assert( ref["acumon"].to_int32() == 123); - - ASSERT_THROW( ref["unexist"], bsl::KeyNotFoundException ); - } - - } - - - virtual void test_operator_paren(){ - bsl::ResourcePool rp; - { - bsl::var::Array args; - bsl::var::Function func(&echo_f, "echo"); - bsl::var::MagicRef ref(rp); - ref = func; - bsl::var::IVar& res = ref(args, rp); - assert( &res == &args ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::var::Method method(&echo_m, "echo"); - bsl::var::MagicRef ref(rp); - ref = method; - bsl::var::IVar& res = ref(self, args, rp); - assert( &bsl::var::Ref(res["self"]).ref() == &self ); - assert( &bsl::var::Ref(res["args"]).ref() == &args ); - } - { - bsl::var::Array args; - bsl::var::MagicRef mr(rp); - ASSERT_THROW( mr(args, rp), bsl::InvalidOperationException ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::var::MagicRef mr(rp); - ASSERT_THROW( mr(self, args, rp), bsl::InvalidOperationException ); - } - } - - -private: -}; - -int main(){ - TestVarMagicRef().test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Method.cpp b/bsl/var/unittest/test_var_Method.cpp deleted file mode 100644 index 72909b576852a1e1f155842bfd1f90c49261b153..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Method.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Method.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_var_Method.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:57:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "test_var_invalid.h" - -bsl::var::IVar& echo( bsl::var::IVar& self, bsl::var::IVar& args, bsl::ResourcePool& rp){ - bsl::var::IVar& res = rp.create(); - res["self"] = self; - res["args"] = args; - return res; -} - -bsl::var::IVar& size( bsl::var::IVar& self, bsl::var::IVar& , bsl::ResourcePool& rp ){ - return rp.create(int(self.size())); -} - -class TestVarMethod: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarMethod() - :_method(echo, "method"){} - - virtual ~TestVarMethod(){} - - //speical methods - virtual void test_special(){ - // ctors - { - bsl::var::Method func1(&echo, "echo"); - assert( func1.to_string() == "echo" ); - bsl::var::Method func2(func1); - assert( func2.to_string() == "echo" ); - } - // copy assign - { - bsl::var::Method func1(&echo, "echo"); - bsl::var::Method func2(&size, "size"); - func1 = func2; - assert( func1.to_string() == "size" ); - } - } - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Method(&echo, "echo") ); - } - - virtual void test_clear() { - { - bsl::var::Method func1(&echo, "echo"); - func1.clear(); //no effect - assert( func1.to_string() == "echo" ); - } - } - - virtual void test_dump() { - { - bsl::var::Method func(echo, "echo"); - assert( func.dump() == "[bsl::var::Method]echo" ); - assert( func.dump(999) == "[bsl::var::Method]echo" ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Method func(echo, "echo"); - assert( func.to_string() == "echo" ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Method(&echo, "echo").get_type() == string_type("bsl::var::Method") ); - } - - //method for value - virtual void test_bool(){ - test_invalid_bool(_method); - } - virtual void test_raw(){ - test_invalid_raw(_method); - } - virtual void test_number(){ - test_invalid_number(_method); - } - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Method f(&echo, "echo"); - bsl::var::Method& cl = f.clone(rp); - bsl::var::MagicRef args(rp); - bsl::var::Dict self; - args[0] = 123; - args[1] = "hello"; - assert( cl.get_type() == string_type("bsl::var::Method") ); - assert( cl.to_string() == string_type("echo") ); - bsl::var::IVar& res = cl(self, args, rp); - assert( res["args"][0].to_int32() == 123 ); - assert( res["args"][1].c_str() == args[1].c_str() ); - assert( res["self"].is_dict() ); - } - virtual void test_string(){ - test_invalid_string(_method); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_method); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_method); - } - - //methods for callable - virtual void test_callable(){ - test_operator_paren(); - } - - virtual void test_operator_assign(){ - //valid assign - { - bsl::var::Method func1(&echo, "echo"), func2(&size, "size"); - bsl::var::IVar& ivar = func1; - func2 = ivar; - assert( func2.to_string() == func1.to_string() ); - - } - //invalid assign - { - bsl::var::Method func(&echo, "echo"); - bsl::var::Int32 i32; - ASSERT_THROW( func = 123, bsl::InvalidOperationException ); - ASSERT_THROW( func = 123LL, bsl::InvalidOperationException ); - ASSERT_THROW( func = 123.456, bsl::InvalidOperationException ); - ASSERT_THROW( func = "123", bsl::InvalidOperationException ); - ASSERT_THROW( func = i32, bsl::InvalidOperationException ); - } - } - - virtual void test_operator_paren(){ - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::ResourcePool rp; - bsl::var::IVar& res = bsl::var::Method(&echo, "echo")(self, args, rp); - assert( &bsl::var::Ref(res["self"]).ref() == &self ); - assert( &bsl::var::Ref(res["args"]).ref() == &args ); - } - { - bsl::var::Array args; - bsl::ResourcePool rp; - bsl::var::IVar& res = bsl::var::Method(&echo, "echo")(args, rp); - assert( res["self"].is_null() ); - assert( &bsl::var::Ref(res["args"]).ref() == &args ); - } - { - bsl::ResourcePool rp; - bsl::var::Dict self; - bsl::var::Array args; - bsl::var::Int32 i32(123); - bsl::var::String str("hao"); - self["str"] = str; - self["i32"] = i32; - bsl::var::IVar& res = bsl::var::Method(&size, "size")(self, args, rp); - assert( res.to_int32() == 2 ); - } - } -private: - bsl::var::Method _method; -}; - -int main(){ - TestVarMethod test; - test.test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Null.cpp b/bsl/var/unittest/test_var_Null.cpp deleted file mode 100644 index 595eaf5521cf8c0d068e796b60385ef19c4cbf04..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Null.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Null.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarNull.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 20:57:41 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "test_var_invalid.h" - -class TestVarNull: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarNull(){} - - //speical methods - virtual void test_special(){ - // copy ctor - { - bsl::var::Null null1; - bsl::var::Null null2(null1); - assert( null2.is_null() ); - } - // copy assign - { - bsl::var::Null null1, null2; - null2 = null1; - assert( null2.is_null() ); - } - } - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Null() ); - } - - virtual void test_clear() { - { - bsl::var::Null null; - null.clear(); //assert no-throw - } - } - - virtual void test_dump() { - { - bsl::var::Null null; - assert( null.dump() == string_type("[bsl::var::Null]null") ); - assert( null.dump(999) == string_type("[bsl::var::Null]null") ); - } - - } - - virtual void test_to_string() { - { - bsl::var::Null null; - assert( null.to_string() == string_type("null") ); - } - - } - - virtual void test_get_type() { - assert( bsl::var::Null().get_type() == string_type("bsl::var::Null") ); - } - - //method for value - virtual void test_bool(){ - test_invalid_bool(bsl::var::Null::null); - } - virtual void test_raw(){ - test_invalid_raw(bsl::var::Null::null); - } - virtual void test_number(){ - test_invalid_number(bsl::var::Null::null); - } - virtual void test_clone(){ - bsl::ResourcePool rp; - assert( bsl::var::Null::null.clone(rp).is_null() ); - } - - virtual void test_string(){ - test_invalid_string(bsl::var::Null::null); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(bsl::var::Null::null); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(bsl::var::Null::null); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(bsl::var::Null::null); - } - - virtual void test_operator_assign(){ - //valid assign - { - bsl::var::Null null1, null2; - bsl::var::Ref ref_to_null; - null1 = null1; - assert( null1.is_null() ); - - null1 = null2; - assert( null1.is_null() ); - - null1 = (bsl::var::IVar&)(null2); - assert( null1.is_null() ); - - null1 = ref_to_null; - assert( null1.is_null() ); - - } - //invalid assign - { - bsl::var::Null null; - bsl::var::Int32 i32; - ASSERT_THROW( null = 123, bsl::InvalidOperationException ); - ASSERT_THROW( null = 123LL, bsl::InvalidOperationException ); - ASSERT_THROW( null = 123.456, bsl::InvalidOperationException ); - ASSERT_THROW( null = "123", bsl::InvalidOperationException ); - ASSERT_THROW( null = i32, bsl::InvalidOperationException ); - } - } - -private: -}; - -int main(){ - TestVarNull test; - test.test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_Number.cpp b/bsl/var/unittest/test_var_Number.cpp deleted file mode 100644 index 3b9fbdc52e29dcf85182ea9753a3e54d25128f00..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Number.cpp +++ /dev/null @@ -1,308 +0,0 @@ -#include "bsl/var/implement.h" -#include "test_var_invalid.h" -#include - -class TestVarNumber: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarNumber() - :_i32(123){} - - virtual ~TestVarNumber(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::Number i = 123; - bsl::var::Number j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = 456; - assert( j.to_int32() == 123 ); - } - //copy assign - { - bsl::var::Number i = 123; - bsl::var::Number j; - j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = 456; - assert( j.to_int32() == 123 ); - } - } - - //methods for all - virtual void test_mask(){ -/* -signed char int8 -unsigned char uint8 -signed short int16 -unsigned short uint16 -signed int int32 -unsigned int uint32 -signed long long int64 -unsigned long long uint64 -*/ - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - test_mask_consistency( bsl::var::Number() ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::Number i; - i = 123; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - // = long long - { - - bsl::var::Number i; - ASSERT_THROW( i = 1234567891234567LL, bsl::OverflowException ); - } - - // = double - { - bsl::var::Number i; - i = 4670.9394; - assert( i.to_int32() == 4670 ); - assert( i.to_int64() == 4670 ); - assert( i.to_double() == 4670 ); - } - - // = const char * - { - bsl::var::Number i; - i = "46709394"; - assert( i.to_int32() == 46709394 ); - } - - // = string_type - { - bsl::var::Number i; - i = bsl::var::IVar::string_type("46709394"); - assert( i.to_int32() == 46709394 ); - } - - // = Number - { - bsl::var::Number i, j; - j = 123; - i = j; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - // = *this - { - bsl::var::Number i; - i = 123; - i = i; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - } - - } - - virtual void test_clear() { - { - bsl::var::Number i(123); - i.clear(); //assert no-throw - assert(i.to_int32() == 0); - } - } - - virtual void test_dump() { - { - bsl::var::Number i; - assert( i.dump() == string_type("[bsl::var::Number]0") ); - assert( i.dump(999) == string_type("[bsl::var::Number]0") ); - } - - { - bsl::var::Number i(1234567); - assert( i.dump() == string_type("[bsl::var::Number]1234567") ); - assert( i.dump(999) == string_type("[bsl::var::Number]1234567") ); - } - } - - virtual void test_to_string() { - { - bsl::var::Number i; - assert( i.to_string() == string_type("0") ); - } - - { - bsl::var::Number i(1234567); - assert( i.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::Number().get_type() == string_type("bsl::var::Number") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::Number i32(123); - i32 = true; - assert( i32.to_int32() == 1 ); - } - { - bsl::var::Number i32(123); - i32 = false; - assert( i32.to_int32() == 0 ); - } - // to bool - { - assert( bsl::var::Number().to_bool() == false ); - assert( bsl::var::Number(-1).to_bool() == true ); - } - } - virtual void test_raw(){ - test_invalid_raw(_i32); - } - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - -/* -signed char int8 SCHAR_MIN -signed char int8 SCHAR_MAX -unsigned char uint8 0 -unsigned char uint8 UCHAR_MAX -signed short int16 SHRT_MIN -signed short int16 SHRT_MAX -unsigned short uint16 0 -unsigned short uint16 USHRT_MAX -signed int int32 INT_MIN -signed int int32 INT_MAX -unsigned int uint32 0 -unsigned int uint32 UINT_MAX -signed long long int64 LLONG_MIN -signed long long int64 LLONG_MAX -unsigned long long uint64 0 -unsigned long long uint64 ULLONG_MAX - - test_valid_number( bsl::var::Number<\1>(\3), static_cast<\1>(\3) ); - -*/ - - test_valid_number( bsl::var::Number(SCHAR_MIN), static_cast(SCHAR_MIN) ); - test_valid_number( bsl::var::Number(SCHAR_MAX), static_cast(SCHAR_MAX) ); - test_valid_number( bsl::var::Number(0), static_cast(0) ); - test_valid_number( bsl::var::Number(UCHAR_MAX), static_cast(UCHAR_MAX) ); - test_valid_number( bsl::var::Number(SHRT_MIN), static_cast(SHRT_MIN) ); - test_valid_number( bsl::var::Number(SHRT_MAX), static_cast(SHRT_MAX) ); - test_valid_number( bsl::var::Number(0), static_cast(0) ); - test_valid_number( bsl::var::Number(USHRT_MAX), static_cast(USHRT_MAX) ); - test_valid_number( bsl::var::Number(INT_MIN), static_cast(INT_MIN) ); - test_valid_number( bsl::var::Number(INT_MAX), static_cast(INT_MAX) ); - test_valid_number( bsl::var::Number(0), static_cast(0) ); - test_valid_number( bsl::var::Number(UINT_MAX), static_cast(UINT_MAX) ); - test_valid_number( bsl::var::Number(LLONG_MIN), static_cast(LLONG_MIN) ); - test_valid_number( bsl::var::Number(LLONG_MAX), static_cast(LLONG_MAX) ); - test_valid_number( bsl::var::Number(0), static_cast(0) ); - test_valid_number( bsl::var::Number(ULLONG_MAX), static_cast(ULLONG_MAX) ); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Number v(123); - assert(v.clone(rp).to_string() == v.to_string() ); - assert(v.clone(rp).get_type() == v.get_type() ); - - test_valid_number( bsl::var::Number(-1).clone(rp), -1 ); - test_valid_number( bsl::var::Number(0).clone(rp), 0 ); - - test_valid_number( bsl::var::Number(SCHAR_MIN).clone(rp), static_cast(SCHAR_MIN) ); - test_valid_number( bsl::var::Number(SCHAR_MAX).clone(rp), static_cast(SCHAR_MAX) ); - test_valid_number( bsl::var::Number(0).clone(rp), static_cast(0) ); - test_valid_number( bsl::var::Number(UCHAR_MAX).clone(rp), static_cast(UCHAR_MAX) ); - test_valid_number( bsl::var::Number(SHRT_MIN).clone(rp), static_cast(SHRT_MIN) ); - test_valid_number( bsl::var::Number(SHRT_MAX).clone(rp), static_cast(SHRT_MAX) ); - test_valid_number( bsl::var::Number(0).clone(rp), static_cast(0) ); - test_valid_number( bsl::var::Number(USHRT_MAX).clone(rp), static_cast(USHRT_MAX) ); - test_valid_number( bsl::var::Number(INT_MIN).clone(rp), static_cast(INT_MIN) ); - test_valid_number( bsl::var::Number(INT_MAX).clone(rp), static_cast(INT_MAX) ); - test_valid_number( bsl::var::Number(0).clone(rp), static_cast(0) ); - test_valid_number( bsl::var::Number(UINT_MAX).clone(rp), static_cast(UINT_MAX) ); - test_valid_number( bsl::var::Number(LLONG_MIN).clone(rp), static_cast(LLONG_MIN) ); - test_valid_number( bsl::var::Number(LLONG_MAX).clone(rp), static_cast(LLONG_MAX) ); - test_valid_number( bsl::var::Number(0).clone(rp), static_cast(0) ); - test_valid_number( bsl::var::Number(ULLONG_MAX).clone(rp), static_cast(ULLONG_MAX) ); - } - - virtual void test_string(){ - test_invalid_string(_i32); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_i32); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_i32); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_i32); - } - - virtual void test_to_int32(){ - { - assert( bsl::var::Number().to_int32() == 0 ); - assert( bsl::var::Number(-1).to_int32() == -1 ); - assert( bsl::var::Number(1234567).to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - assert( bsl::var::Number().to_int64() == 0 ); - assert( bsl::var::Number(-1).to_int64() == -1 ); - assert( bsl::var::Number(1234567).to_int64() == 1234567 ); - } - } - - virtual void test_to_double(){ - { - assert( bsl::var::Number().to_double() == 0 ); - assert( bsl::var::Number(-1).to_double() == -1 ); - assert( bsl::var::Number(1234567).to_double() == 1234567 ); - } - } - -private: - bsl::var::Number _i32; -}; - -int main(){ - TestVarNumber().test_all(); - return 0; -} - - diff --git a/bsl/var/unittest/test_var_Ref.cpp b/bsl/var/unittest/test_var_Ref.cpp deleted file mode 100644 index a5bc6b3592083998a8d999ef562d67f580fdc09d..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_Ref.cpp +++ /dev/null @@ -1,884 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_Ref.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarRef.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/25 12:32:18 - * @version $Revision: 1.4 $ - * @brief - * - **/ - -#include "test_var_invalid.h" -#include "bsl/var/implement.h" - -class TestVarRef: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarRef(){} - - //special methods - virtual void test_special(){ - //ref - { - bsl::var::Ref ref; - assert( ref.ref().is_null() ); - } - { - bsl::var::Int32 i32 = 123; - bsl::var::Ref ref(i32); - assert( &ref.ref() == &i32 ); - } - //copy ctor - { - bsl::var::Int32 i32 = 123; - bsl::var::Int64 i64 = 456; - bsl::var::Ref i = i32; - bsl::var::Ref j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = i64; - assert( j.to_int32() == 123 ); - } - //copy assign - { - bsl::var::Int32 i32 = 123; - bsl::var::Int64 i64 = 456; - bsl::var::Ref i = i32; - bsl::var::Ref j; - j = i; - assert( j.is_int32() ); - assert( j.to_int32() == 123 ); - i = i64; - assert( j.to_int32() == 123 ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::Ref() ); - bsl::var::Int32 i32; - bsl::var::String str; - bsl::var::Array arr; - bsl::var::Ref r; - r = i32; - test_mask_consistency( r ); - r = str; - test_mask_consistency( r ); - r = arr; - test_mask_consistency( r ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::Ref ref; - bsl::var::Int32 i32; - ref = i32; - i32 = 123; - assert( ref.to_int32() == 123 ); - assert( ref.to_int64() == 123 ); - - ref = 456; - assert( i32.to_int32() == 456 ); - assert( ref.to_int32() == 456 ); - assert( ref.to_int64() == 456 ); - - } - - // = long long - { - - bsl::var::Ref ref; - bsl::var::Int64 i64; - ref = i64; - i64 = 9876543219876543LL; - ASSERT_THROW( ref.to_int32(), bsl::OverflowException ); - assert( ref.to_int64() == 9876543219876543LL ); - ref = 1234567891234567LL; - assert( i64.to_int64() == 1234567891234567LL ); - ASSERT_THROW( i64.to_int32(), bsl::OverflowException ); - - assert( ref.to_int64() == 1234567891234567LL ); - } - - // = double - { - - bsl::var::Ref ref; - bsl::var::Double var; - ref = var; - var = 987654321.9876543; - assert( ref.to_double()== double(987654321.9876543) ); - ref = 123456789.1234567; - assert( var.to_double() == 123456789.1234567 ); - assert( ref.to_int32() == int(123456789.1234567) ); - assert( ref.to_double() == 123456789.1234567 ); - } - - // = string_type - { - - bsl::var::Ref ref; - bsl::var::String var; - ref = var; - var = "987654321.9876543"; - assert( ref.to_double()== double(987654321.9876543) ); - - ref = "123456789.1234567"; - assert( var.to_double() == 123456789.1234567 ); - assert( ref.to_int32() == 123456789 ); - assert( ref.to_int64() == 123456789 ); - assert( ref.to_double() == double(123456789.1234567) ); - - ref = "hello world!"; - assert( var.to_string() == "hello world!" ); - - } - - // = Ref - { - bsl::var::Ref ref1, ref2; - bsl::var::Int32 i=123, j=456; - ref1 = i; - - ref2 = ref1; - assert( ref2.to_int32() == 123 ); - assert( ref2.to_int64() == 123 ); - - ref1 = j; - assert( ref2.to_int32() == 123 ); - assert( ref2.to_int64() == 123 ); - - } - - // = *this - { - bsl::var::Ref ref; - bsl::var::Int32 i = 123; - ref = i; - ref = ref; - assert( ref.to_int32() == 123 ); - assert( ref.to_int64() == 123 ); - } - - } - - virtual void test_size() { - { - bsl::var::Array arr; - arr[100] = bsl::var::Null::null; - assert( bsl::var::Ref(arr).size() == 101 ); - } - - { - bsl::var::Ref ref; - test_invalid_array(ref); - } - } - - virtual void test_clear() { - { - bsl::var::Int32 i32(123); - bsl::var::Ref ref(i32); - ref.clear(); //assert no-throw - assert(ref.to_int32() == 0); - assert(&ref.ref() == &i32 ); - } - } - - virtual void test_dump() { - { - bsl::var::Int32 i32; - bsl::var::Ref ref(i32); - assert( NULL != strstr( ref.dump().c_str(), "0" ) ); - assert( NULL != strstr( ref.dump(999).c_str(), "0" ) ); - } - - { - bsl::var::String str = "1234567"; - bsl::var::Ref ref(str); - assert( NULL != strstr( ref.dump().c_str(), "1234567" ) ); - assert( NULL != strstr( ref.dump(999).c_str(), "1234567" ) ); - } - } - - virtual void test_to_string() { - { - bsl::var::Int32 i32; - bsl::var::Ref ref(i32); - assert( ref.to_string() == string_type("0") ); - } - - { - bsl::var::String str = "1234567"; - bsl::var::Ref ref(str); - assert( ref.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::Ref().get_type() == string_type("bsl::var::Ref(bsl::var::Null)") ); - } - - //method for value - virtual void test_bool(){ - test_invalid_bool(_ref); - test_with_bool(); - } - virtual void test_raw(){ - test_invalid_raw(_ref); - test_with_raw(); - } - virtual void test_number(){ - test_invalid_number(_ref); - test_to_int32(); - test_to_int64(); - test_to_double(); - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::Int32 i32; - bsl::var::Ref r1 = i32; - bsl::var::IVar& r2 = r1.clone(rp); - assert( &r1 != &r2 ); - assert( r1.to_int32() == r2.to_int32() ); - } - - virtual void test_string(){ - test_invalid_string(_ref); - test_c_str(); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_ref); - test_array_get(); - test_array_set(); - test_array_del(); - test_array_iterator(); - test_array_const_iterator(); - test_array_operator_square(); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_ref); - test_dict_get(); - test_dict_set(); - test_dict_del(); - test_dict_iterator(); - test_dict_const_iterator(); - test_dict_operator_square(); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_ref); - test_operator_paren(); - } - - virtual void test_with_bool(){ - { - bsl::var::Bool b; - b = true; - bsl::var::Ref ref(b); - assert( ref.to_bool() == true ); - ref = false; - assert( b.to_bool() == false ); - } - { - bsl::var::Bool b(true); - const bsl::var::Ref ref(b); - assert( ref.to_bool() == true ); - } - } - - virtual void test_with_raw(){ - bsl::var::raw_t raw_1("Acumon", 3); - bsl::var::raw_t raw_2; - - { - bsl::var::ShallowRaw raw1(raw_1); - bsl::var::Ref ref = raw1; - assert( ref.to_raw().data == raw_1.data ); - assert( ref.to_raw().length == raw_1.length ); - ref = raw_2; - assert( raw1.to_raw().data == raw_2.data ); - assert( raw1.to_raw().length == raw_2.length ); - } - - { - bsl::var::ShallowRaw raw1(raw_1); - const bsl::var::Ref ref = raw1; - assert( ref.to_raw().data == raw_1.data ); - assert( ref.to_raw().length == raw_1.length ); - } - } - - virtual void test_to_int32(){ - { - ASSERT_THROW( bsl::var::Ref().to_int32(), bsl::InvalidOperationException ); - } - { - bsl::var::Int32 i32 = -1; - assert( bsl::var::Ref(i32).to_int32() == -1 ); - } - } - - virtual void test_to_int64(){ - { - ASSERT_THROW( bsl::var::Ref().to_int64(), bsl::InvalidOperationException ); - } - { - bsl::var::Int64 i64 = 1234567891234567LL; - assert( bsl::var::Ref(i64).to_int64() == 1234567891234567LL ); - } - } - - virtual void test_to_double(){ - { - ASSERT_THROW( bsl::var::Ref().to_double(), bsl::InvalidOperationException ); - } - { - bsl::var::Double var = 123456789.1234567; - assert( bsl::var::Ref(var).to_double() == 123456789.1234567 ); - } - } - - virtual void test_c_str(){ - { - ASSERT_THROW( bsl::var::Ref().c_str(), bsl::InvalidOperationException ); - } - { - bsl::var::String var = "123456789.1234567"; - assert( bsl::var::Ref(var).c_str() == var.c_str()); - assert( bsl::var::Ref(var).c_str_len() == var.c_str_len()); - } - { - bsl::var::String var = string_type("123456789.1234567"); - assert( bsl::var::Ref(var).c_str() == var.c_str()); - assert( bsl::var::Ref(var).c_str_len() == var.c_str_len()); - } - } - - //methods for array - virtual void test_array_get(){ - { - ASSERT_THROW( bsl::var::Ref().get(0), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 123; - arr[100] = i32; - bsl::var::Ref ref(arr); - assert( ref.get(100).to_int32() == 123 ); - } - - } - - virtual void test_array_set(){ - { - bsl::var::Ref var; - ASSERT_THROW( bsl::var::Ref().set(0, var), bsl::InvalidOperationException ); - - } - { - bsl::var::Array arr; - bsl::var::Ref ref(arr); - ref.set(100, arr); - bsl::var::Ref r = arr[100]; - assert( &r.ref() == &arr ); - } - } - - virtual void test_array_del(){ - { - ASSERT_THROW( bsl::var::Ref().del(0), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::Int32 i32 = 123; - arr[100] = i32; - bsl::var::Ref ref(arr); - assert( ref.del(99) == false ); - assert( ref.del(100) == true ); - assert( ref.del(101) == false ); - assert( arr[100].is_null() ); - } - - } - - virtual void test_array_iterator(){ - { - ASSERT_THROW( bsl::var::Ref().array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( bsl::var::Ref().array_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - bsl::var::Ref ref = arr; - //empty array: - assert( ref.array_begin() == ref.array_end() ); - } - { - bsl::ResourcePool rp; - bsl::var::Array arr; - bsl::var::Ref ref = arr; - ref[0] = rp.create(123); - ref[2] = rp.create(456); - bsl::var::Array::array_iterator iter = ref.array_begin(); - - //iter => ref[0] - assert( iter == ref.array_begin() ); - assert( iter != ref.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => ref[1] - assert( iter != ref.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - iter->value() = rp.create(789); - assert( ref[1].is_int32() ); - assert( ref[1].to_int32() == 789 ); - assert( (++ iter)->key() == 2 ); - - //iter => ref[2] - assert( iter != ref.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == ref.array_end() ); - - //iter == ref.array_end() - assert( iter == ref.array_end() ); - } - - } - - virtual void test_array_const_iterator(){ - { - const bsl::var::Ref ref; - ASSERT_THROW( ref.array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.array_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Array arr; - const bsl::var::Ref ref(arr); - //empty array: - assert( ref.array_begin() == ref.array_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Array _arr; - _arr[0] = rp.create(123); - _arr[2] = rp.create(456); - const bsl::var::Ref ref = _arr; - bsl::var::IVar::array_const_iterator iter = ref.array_begin(); - - //iter => ref[0] - assert( iter == ref.array_begin() ); - assert( iter != ref.array_end() ); - assert( iter->key() == 0 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 123 ); - assert( (++ iter)->key() == 1 ); - - //iter => ref[1] - assert( iter != ref.array_end() ); - assert( iter->key() == 1 ); - assert( iter->value().is_null() ); - assert( (++ iter)->key() == 2 ); - - //iter => ref[2] - assert( iter != ref.array_end() ); - assert( iter->key() == 2 ); - assert( iter->value().is_int32() ); - assert( iter->value().to_int32() == 456 ); - assert( (++ iter) == ref.array_end() ); - - //iter == ref.array_end() - assert( iter == ref.array_end() ); - } - - } - - virtual void test_array_operator_square(){ - bsl::ResourcePool rp; - - //non-const - { - bsl::var::Array arr; - bsl::var::Ref ref = arr; - ref[100] = rp.create(123); - assert( ref.size() == 101 ); - assert( ref[100].is_int32() ); - assert( ref[100].to_int32() == 123); - } - { - bsl::var::Array arr; - bsl::var::Ref ref = arr; - assert( ref[456].is_ref() ); - assert( ref[789].is_null() ); - } - - //const - { - bsl::var::Array _arr; - bsl::var::Ref ref = _arr; - _arr[100] = rp.create(123); - assert( ref.size() == 101 ); - assert( ref[100].is_int32() ); - assert( ref[100].to_int32() == 123); - - assert( ref[0].is_null() ); - } - - } - - //methods for dict - virtual void test_dict_iterator(){ - { - bsl::var::Ref ref; - ASSERT_THROW( ref.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.dict_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - //empty ref: - assert( ref.dict_begin() == ref.dict_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - ref["0"] = rp.create(123); - ref["2"] = rp.create(456); - ref["null"] = rp.create(); - bsl::var::IVar::dict_iterator iter = ref.dict_begin(); - - - assert( iter == ref.dict_begin() ); - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - bsl::var::IVar& value2 = iter->value(); - ++iter; - - //iter == ref.dict_end() - assert( iter == ref.dict_end() ); - - assert( (key0 == "0" && value0.to_int32() == 123 && (value0 = 1230, true)) /* ref["0"] will be Int(1230) */ - || (key1 == "0" && value1.to_int32() == 123 && (value1 = 1230, true)) - || (key2 == "0" && value2.to_int32() == 123 && (value2 = 1230, true)) - ); - - assert( (key0 == "2" && value0.to_int32() == 456 && (value0 = 4560, true)) /* ref["0"] will be Int(4560) */ - || (key1 == "2" && value1.to_int32() == 456 && (value1 = 4560, true)) - || (key2 == "2" && value2.to_int32() == 456 && (value2 = 4560, true)) - ); - - assert( (key0 == "null" && value0.is_null() && (value0 = rp.create(-1), true)) - || (key1 == "null" && value1.is_null() && (value1 = rp.create(-1), true)) - || (key2 == "null" && value2.is_null() && (value2 = rp.create(-1), true)) - ); - - assert( ref["0"].to_int32() == 1230 ); - assert( ref["2"].to_int32() == 4560 ); - assert( ref["null"].to_int32() == -1); - - } - - } - - virtual void test_dict_const_iterator(){ - { - const bsl::var::Ref ref; - ASSERT_THROW( ref.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( ref.dict_end(), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - const bsl::var::Ref ref = dict; - //empty ref: - assert( ref.dict_begin() == ref.dict_end() ); - } - - { - bsl::ResourcePool rp; - bsl::var::Dict _dict; - _dict["0"] = rp.create(123); - _dict["2"] = rp.create(456); - _dict["null"] = rp.create(); - const bsl::var::Ref ref = _dict; - bsl::var::IVar::dict_const_iterator iter = ref.dict_begin(); - - assert( iter == ref.dict_begin() ); - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key0 = iter->key(); - const bsl::var::IVar& value0 = iter->value(); - assert( (++ iter)->key() != key0 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key1 = iter->key(); - const bsl::var::IVar& value1 = iter->value(); - assert( (++ iter)->key() != key1 ); - - assert( iter != ref.dict_end() ); - const bsl::var::IVar::string_type& key2 = iter->key(); - const bsl::var::IVar& value2 = iter->value(); - ++ iter; - - //iter == ref.dict_end() - assert( iter == ref.dict_end() ); - - assert( (key0 == "0" && value0.to_int32() == 123) - || (key1 == "0" && value1.to_int32() == 123) - || (key2 == "0" && value2.to_int32() == 123) - ); - - assert( (key0 == "2" && value0.to_int32() == 456) - || (key1 == "2" && value1.to_int32() == 456) - || (key2 == "2" && value2.to_int32() == 456) - ); - - assert( (key0 == "null" && value0.is_null()) - || (key1 == "null" && value1.is_null()) - || (key2 == "null" && value2.is_null()) - ); - - assert( ref["0"].to_int32() == 123 ); - assert( ref["2"].to_int32() == 456 ); - assert( ref["null"].is_null()); - - } - - } - - virtual void test_dict_get(){ - { - ASSERT_THROW( bsl::var::Ref().get(""), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().get("a key"), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().get(string_type("another key")), bsl::InvalidOperationException ); - } - //normal get - { - bsl::var::Dict dict; - assert( bsl::var::Ref(dict).get("").is_null() ); - } - { - bsl::var::Dict dict; - assert( bsl::var::Ref(dict).get("a key").is_null() ); - } - { - bsl::var::Dict dict; - assert( bsl::var::Ref(dict).get(string_type("another key")).is_null() ); - } - { - bsl::var::Dict _dict; - const bsl::var::Ref ref = _dict; - bsl::var::Int32 i32 = 4670; - - _dict["an int"] = i32; - _dict["null"] = bsl::var::Null::null; - - assert( ref.get("an int").to_int32() == i32.to_int32() ); - assert( ref.get("null").is_null() ); - - assert( ref.get("unexist").is_null() ); - } - //geek get - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - bsl::var::Int32 i32 = 7776; - ref["an int"] = i32; - ref.get("an int") = 0; - assert( ref["an int"].to_int32() == 0 ); - } - //get with default - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - bsl::var::Int32 i32 = 9394; - bsl::var::Ref ref_null; - bsl::var::Ref ref_i32 = i32; - - ref["an int"] = i32; - ref["null"] = bsl::var::Null::null; - - assert( ref.get("an int", ref_null).to_int32() == i32.to_int32() ); - assert( ref.get("null", ref_null).is_null() ); - assert( ref.get("unexist", ref_i32).to_int32() == i32.to_int32() ); - } - } - - virtual void test_dict_set(){ - bsl::var::Int32 i32 = 123; - bsl::var::Ref ref = i32; - { - ASSERT_THROW( bsl::var::Ref().set(string_type(""),ref), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().set("some key",ref), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().set(string_type("another key"),ref), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::Ref ref1 = dict; - bsl::var::Int32 i321 = 4670; - ref1.set("i32", i321); - assert( ref1["i32"].to_int32() == 4670 ); - } - } - - virtual void test_dict_del(){ - { - ASSERT_THROW( bsl::var::Ref().del(""), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().del("a key"), bsl::InvalidOperationException ); - } - { - ASSERT_THROW( bsl::var::Ref().del(string_type("another key")), bsl::InvalidOperationException ); - } - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - bsl::var::Int32 i32 = 874; - ref["del"] = i32; - assert( ref.size() == 1 ); - assert( ref["del"].to_int32() == 874 ); - ref.del("del"); - assert( ref.size() == 0 ); - assert( ref.get("del").is_null() ); - } - } - - virtual void test_dict_operator_square(){ - bsl::ResourcePool rp; - //non const - { - bsl::var::Ref ref; - ASSERT_THROW( ref[""], bsl::InvalidOperationException ); - ASSERT_THROW( ref["awesome key"], bsl::InvalidOperationException ); - } - //const - { - const bsl::var::Ref ref; - ASSERT_THROW( ref[""], bsl::InvalidOperationException ); - ASSERT_THROW( ref["aweful key"], bsl::InvalidOperationException ); - } - - //non-const - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - ref["acumon"] = rp.create(123); - assert( ref.size() == 1 ); - assert( ref["acumon"].is_int32() ); - assert( ref[string_type("acumon")].to_int32() == 123); - - ref["abc"] = ref["acumon"]; - assert( ref["abc"].to_int32() == 123 ); - } - { - bsl::var::Dict dict; - bsl::var::Ref ref = dict; - assert( ref[""].is_ref() ); - assert( ref[""].is_null() ); - } - - //const - { - bsl::var::Dict _dict; - _dict["acumon"] = rp.create(123); - const bsl::var::Dict& ref = _dict; - assert( ref.size() == 1 ); - assert( ref[string_type("acumon")].is_int32() ); - assert( ref["acumon"].to_int32() == 123); - - ASSERT_THROW( ref["unexist"], bsl::KeyNotFoundException ); - } - - } - - - virtual void test_operator_paren(){ - { - bsl::var::Array args; - bsl::ResourcePool rp; - bsl::var::Function func(&echo_f, "echo"); - bsl::var::Ref ref; - ref = func; - bsl::var::IVar& res = ref(args, rp); - assert( &res == &args ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::ResourcePool rp; - bsl::var::Method method(&echo_m, "echo"); - bsl::var::Ref ref; - ref = method; - bsl::var::IVar& res = ref(self, args, rp); - assert( &bsl::var::Ref(res["self"]).ref() == &self ); - assert( &bsl::var::Ref(res["args"]).ref() == &args ); - } - { - bsl::var::Array args; - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Ref()(args, rp), bsl::InvalidOperationException ); - } - { - bsl::var::Dict self; - bsl::var::Array args; - bsl::ResourcePool rp; - ASSERT_THROW( bsl::var::Ref()(self, args, rp), bsl::InvalidOperationException ); - } - } - - -private: - bsl::var::Ref _ref; -}; - -int main(){ - TestVarRef().test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_ShallowRaw.cpp b/bsl/var/unittest/test_var_ShallowRaw.cpp deleted file mode 100644 index 6867b2057394a78d17a34417c0cc1368e41eae90..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_ShallowRaw.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_ShallowRaw.cpp,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_var_ShallowRaw.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/05/09 20:27:23 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#include "test_var_invalid.h" - -class TestVarShallowRaw: public ITestVar{ - -public: - typedef bsl::var::IVar::string_type string_type; - typedef bsl::var::IVar::field_type field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - virtual ~TestVarShallowRaw(){} - - //speical methods - virtual void test_special(){ - //ctor - { - bsl::var::ShallowRaw raw; - assert( raw.to_raw().data == NULL ); - assert( raw.to_raw().length == 0 ); - } - { - bsl::var::raw_t raw_(static_cast("hello"), strlen("hello")+1); - bsl::var::ShallowRaw raw(raw_); - assert( raw.to_raw().data == raw_.data ); - assert( raw.to_raw().length == raw_.length ); - } - { - bsl::var::raw_t raw_("hello", strlen("hello")+1); - bsl::var::ShallowRaw raw( raw_.data, raw_.length ); - assert( raw.to_raw().data == raw_.data ); - assert( raw.to_raw().length == raw_.length ); - } - // copy ctor - { - bsl::var::raw_t raw_("hello", strlen("hello")+1); - bsl::var::ShallowRaw raw1(raw_); - bsl::var::ShallowRaw raw2(raw1); - assert( raw2.to_raw().data == raw_.data ); - assert( raw2.to_raw().length == raw_.length ); - - } - // copy assign - { - bsl::var::raw_t raw_("hello", strlen("hello")+1); - bsl::var::ShallowRaw raw1(raw_); - bsl::var::ShallowRaw raw2; - raw2 = raw1; - assert( raw2.to_raw().data == raw_.data ); - assert( raw2.to_raw().length == raw_.length ); - raw2 = raw2; - assert( raw2.to_raw().data == raw_.data ); - assert( raw2.to_raw().length == raw_.length ); - } - } - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::ShallowRaw("hello",1) ); - } - - virtual void test_clear() { - { - bsl::var::ShallowRaw raw; - raw.clear(); - assert( raw.to_raw().data == NULL ); - assert( raw.to_raw().length == 0 ); - } - { - bsl::var::ShallowRaw raw("hi", 1); - raw.clear(); - assert( raw.to_raw().data == NULL ); - assert( raw.to_raw().length == 0 ); - } - } - - virtual void test_dump(){ - stub(); - } - - virtual void test_to_string() { - stub(); - } - - virtual void test_get_type() { - assert( bsl::var::ShallowRaw().get_type() == string_type("bsl::var::ShallowRaw") ); - } - - //method for value - virtual void test_bool(){ - bsl::var::ShallowRaw raw; - test_invalid_bool(raw); - } - virtual void test_raw(){ - bsl::var::raw_t raw_("Acumon", 3); - bsl::var::ShallowRaw raw; - raw = raw_; - assert( raw.to_raw().data == raw_.data ); - assert( raw.to_raw().length == raw_.length ); - - const bsl::var::ShallowRaw const_raw(raw_); - assert( const_raw.to_raw().data == raw_.data ); - assert( const_raw.to_raw().length == raw_.length ); - - } - virtual void test_number(){ - bsl::var::ShallowRaw raw; - test_invalid_number(raw); - } - virtual void test_clone(){ - bsl::var::raw_t raw_("hello", 5); - bsl::var::ShallowRaw raw(raw_); - bsl::ResourcePool rp; - assert( raw.clone(rp).get_type() == raw.get_type() ); - assert( raw.clone(rp).to_raw().data == raw_.data ); - assert( raw.clone(rp).to_raw().length == raw_.length ); - } - - virtual void test_string(){ - bsl::var::ShallowRaw raw; - test_invalid_string(raw); - } - - //methods for array and dict - virtual void test_array(){ - bsl::var::ShallowRaw raw; - test_invalid_array(raw); - } - - //methods for dict - virtual void test_dict(){ - bsl::var::ShallowRaw raw; - test_invalid_dict(raw); - } - - //methods for callable - virtual void test_callable(){ - bsl::var::ShallowRaw raw; - test_invalid_callable(raw); - } - - virtual void test_operator_assign(){ - //valid assign - { - bsl::var::raw_t raw_("", 1); - bsl::var::ShallowRaw raw1, raw2(raw_); - raw1 = (bsl::var::IVar&)(raw2); - assert( raw1.to_raw().data == raw_.data ); - assert( raw1.to_raw().length == raw_.length ); - } - { - bsl::var::raw_t raw_("", 1); - bsl::var::ShallowRaw raw1, raw2(raw_); - bsl::var::Ref ref = raw2; - raw1 = raw2; - assert( raw1.to_raw().data == raw_.data ); - assert( raw1.to_raw().length == raw_.length ); - } - - } - -private: -}; - -int main(){ - TestVarShallowRaw test; - test.test_all(); - return 0; -} - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_ShallowString.cpp b/bsl/var/unittest/test_var_ShallowString.cpp deleted file mode 100644 index 222a31d3b2ae4e3f4fd7735059c7d91c772c1e8b..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_ShallowString.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_ShallowString.cpp,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarShallowString.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/29 15:04:28 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#include "bsl/var/implement.h" -#include "test_var_invalid.h" - -class TestVarShallowString: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarShallowString() - :_str("沃草微舞"){} - - virtual ~TestVarShallowString(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - const char * cs = "hello"; - bsl::var::ShallowString i = cs; - bsl::var::ShallowString j = i; - assert( j.is_string() ); - assert( j.c_str() == cs ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - //copy assign - { - const char * cs = "hello"; - bsl::var::ShallowString i = cs; - bsl::var::ShallowString j; - j = i; - assert( j.is_string() ); - assert( j.c_str() == cs ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::ShallowString("str") ); - } - - virtual void test_operator_assign(){ - // = const char* - { - bsl::var::ShallowString i; - const char *cs1 = "46709394"; - i = cs1; - assert( i.to_int32() == 46709394 ); - - const char *cs2 = "abcdef"; - i = cs2; - assert( i.c_str() == cs2 ); - - } - - // = string_type - { - bsl::var::ShallowString i; - string_type str1("46709394"); - i = str1; - assert( i.c_str() == str1.c_str() ); - assert( i.to_int32() == 46709394 ); - - string_type str2("abcdef"); - i = str2; - assert( i.to_string() == "abcdef" ); - - } - - // = ShallowString - { - bsl::var::ShallowString i, j; - j = "a secret"; - i = j; - assert( i.to_string() == "a secret" ); - } - - // = *this - { - bsl::var::ShallowString i; - i = "self"; - i = i; - assert( i.to_string() == "self" ); - } - - } - - virtual void test_clear() { - { - bsl::var::ShallowString i("will be cleared"); - i.clear(); //assert no-throw - assert(i.to_string() == ""); - } - } - - virtual void test_to_string() { - { - bsl::var::ShallowString i; - assert( i.to_string() == string_type("") ); - } - - { - bsl::var::ShallowString i("1234567"); - assert( i.to_string() == string_type("1234567") ); - } - } - - virtual void test_dump(){ - { - bsl::var::ShallowString i; - assert( i.dump() == string_type("[bsl::var::ShallowString]") ); - assert( i.dump(999) == string_type("[bsl::var::ShallowString]") ); - } - { - bsl::var::ShallowString i("1234567"); - assert( i.dump() == string_type("[bsl::var::ShallowString]1234567") ); - assert( i.dump(999) == string_type("[bsl::var::ShallowString]1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::ShallowString().get_type() == string_type("bsl::var::ShallowString") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::ShallowString str("Acumon"); - ASSERT_THROW( str = true, bsl::InvalidOperationException ); - } - { - bsl::var::ShallowString str("Acumon"); - ASSERT_THROW( str = false, bsl::InvalidOperationException ); - } - // to bool - { - assert( bsl::var::ShallowString().to_bool() == false ); - assert( bsl::var::ShallowString("false").to_bool() == true ); - } - } - - virtual void test_raw(){ - test_invalid_raw(_str); - } - - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - } - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::ShallowString ss = "abc"; - assert( ss.clone(rp).get_type() == ss.get_type() ); - assert( ss.clone(rp).c_str() == ss.c_str() ); - } - virtual void test_string(){ - test_c_str(); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_str); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_str); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_str); - } - - virtual void test_to_int32(){ - { - ASSERT_THROW( bsl::var::ShallowString().to_int32(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::ShallowString("not a number!").to_int32(), bsl::BadCastException ); - - assert( bsl::var::ShallowString("0").to_int32() == 0 ); - assert( bsl::var::ShallowString("-1").to_int32() == -1 ); - assert( bsl::var::ShallowString("1234567").to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - ASSERT_THROW( bsl::var::ShallowString().to_int64(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::ShallowString("not a number!").to_int64(), bsl::BadCastException ); - - assert( bsl::var::ShallowString("+0").to_int64() == 0 ); - assert( bsl::var::ShallowString("-123456789123").to_int64() == -123456789123LL ); - assert( bsl::var::ShallowString("+123456746709394").to_int64() == 123456746709394LL ); - } - } - - virtual void test_to_double(){ - { - ASSERT_THROW( bsl::var::ShallowString().to_double(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::ShallowString("not a number!").to_double(), bsl::BadCastException ); - - assert( bsl::var::ShallowString("-4670.9394").to_double() == -4670.9394 ); - assert( bsl::var::ShallowString("+0.00000000").to_double() == 0 ); - assert( bsl::var::ShallowString("123.456").to_double() == 123.456 ); - } - } - - virtual void test_c_str(){ - { - bsl::var::ShallowString i; - assert( i.c_str() == string_type("") ); - assert( i.c_str_len() == 0 ); - } - - { - const char * cs = "1234567"; - bsl::var::ShallowString i(cs); - assert( i.c_str() == cs ); - assert( i.c_str_len() == strlen(cs) ); - } - } - -private: - bsl::var::ShallowString _str; -}; - -int main(){ - TestVarShallowString().test_all(); - return 0; -} - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_String.cpp b/bsl/var/unittest/test_var_String.cpp deleted file mode 100644 index a2f71832042fa5db0da3a694ed04a04f067a16b0..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_String.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_String.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarString.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/29 15:04:28 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "bsl/var/implement.h" -#include "test_var_invalid.h" - -class TestVarString: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - TestVarString() - :_str("沃草微舞"){} - - virtual ~TestVarString(){} - - //special methods - virtual void test_special(){ - //copy ctor - { - bsl::var::String i = "hello"; - bsl::var::String j = i; - assert( j.is_string() ); - assert( j.to_string() == "hello" ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - //copy assign - { - bsl::var::String i = "hello"; - bsl::var::String j; - j = i; - assert( j.is_string() ); - assert( j.to_string() == "hello" ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::String("hello") ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::String i; - i = 123; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - assert( i.to_string() == "123" ); - assert( i.is_string() ); - } - - // = long long - { - - bsl::var::String i; - i = 1234567891234567LL; - assert( i.to_int64() == 1234567891234567LL ); - assert( i.to_double() == double(1234567891234567LL) ); - assert( i.is_string() ); - assert( i.to_string() == "1234567891234567" ); - } - - // = double - { - bsl::var::String i; - i = 4670.9394; - assert( i.to_int32() == 4670 ); - assert( i.to_int64() == 4670 ); - assert( i.to_double() == 4670.9394 ); - assert( i.is_string() ); - assert( i.to_string() == "4670.939400" ); - } - - // = const char* - { - bsl::var::String i; - i = "46709394"; - assert( i.to_int32() == 46709394 ); - - i = "abcdef"; - assert( i.to_string() == "abcdef" ); - - i = ""; - assert( i.to_string() == "" ); - - } - - // = string_type - { - bsl::var::String i; - i = string_type("46709394"); - assert( i.to_int32() == 46709394 ); - - i = string_type("abcdef"); - assert( i.to_string() == "abcdef" ); - - i = string_type(); - assert( i.to_string() == "" ); - - } - - // = String - { - bsl::var::String i, j; - j = "a secret"; - i = j; - assert( i.to_string() == "a secret" ); - } - - // = *this - { - bsl::var::String i; - i = "self"; - i = i; - assert( i.to_string() == "self" ); - } - - } - - virtual void test_clear() { - { - bsl::var::String i("will be cleared"); - i.clear(); //assert no-throw - assert(i.to_string() == ""); - } - } - - virtual void test_dump() { - { - bsl::var::String i; - assert( i.dump() == string_type("[bsl::var::String]") ); - assert( i.dump(999) == string_type("[bsl::var::String]") ); - } - - { - bsl::var::String i("1234567"); - assert( i.dump() == string_type("[bsl::var::String]1234567") ); - assert( i.dump(999) == string_type("[bsl::var::String]1234567") ); - } - } - - virtual void test_to_string() { - { - bsl::var::String i; - assert( i.to_string() == string_type("") ); - } - - { - bsl::var::String i("1234567"); - assert( i.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::String().get_type() == string_type("bsl::var::String") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::String str("Acumon"); - str = true; - assert( str.to_string() == "true" ); - } - { - bsl::var::String str("Acumon"); - str = false; - assert( str.to_string() == "false" ); - } - // to bool - { - assert( bsl::var::String().to_bool() == false ); - assert( bsl::var::String("false").to_bool() == true ); - } - } - - virtual void test_raw(){ - test_invalid_raw(_str); - } - - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::String s("hello"); - assert( s.clone(rp).get_type() == s.get_type() ); - assert( s.clone(rp).to_string() == s.to_string() ); - assert( s.clone(rp).c_str() != s.c_str() ); - } - - virtual void test_string(){ - test_c_str(); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_str); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_str); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_str); - } - - virtual void test_to_int32(){ - { - ASSERT_THROW( bsl::var::String().to_int32(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_int32(), bsl::BadCastException ); - - assert( bsl::var::String("0").to_int32() == 0 ); - assert( bsl::var::String("-1").to_int32() == -1 ); - assert( bsl::var::String("1234567").to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - ASSERT_THROW( bsl::var::String().to_int64(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_int64(), bsl::BadCastException ); - - assert( bsl::var::String("+0").to_int64() == 0 ); - assert( bsl::var::String("-123456789123").to_int64() == -123456789123LL ); - assert( bsl::var::String("+123456746709394").to_int64() == 123456746709394LL ); - } - } - - virtual void test_to_double(){ - { - ASSERT_THROW( bsl::var::String().to_double(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_double(), bsl::BadCastException ); - - assert( bsl::var::String("-4670.9394").to_double() == -4670.9394 ); - assert( bsl::var::String("+0.00000000").to_double() == 0 ); - assert( bsl::var::String("123.456").to_double() == 123.456 ); - } - } - - virtual void test_c_str(){ - { - bsl::var::String i; - assert( i.c_str() == string_type("") ); - assert( i.c_str_len() == 0 ); - } - - { - bsl::var::String i("1234567"); - assert( i.c_str() == string_type("1234567") ); - assert( i.c_str_len() == string_type("1234567").size() ); - } - } - -private: - bsl::var::String _str; -}; - -int main(){ - TestVarString().test_all(); - return 0; -} - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_String2.cpp b/bsl/var/unittest/test_var_String2.cpp deleted file mode 100644 index daf8c0f3fdd9fd4bf23e52eb8143b96f4ab3afb8..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_String2.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_String.cpp,v 1.4 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_VarString.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/29 15:04:28 - * @version $Revision: 1.4 $ - * @brief - * - **/ -#include "bsl/var/implement.h" -#include "test_var_invalid.h" -#include "bsl/pool/bsl_pool.h" -#include "bsl/pool/bsl_xcompool.h" - - -bsl::xcompool g_xcompool; - -class TestVarString: public ITestVar{ - -public: - typedef bsl::string string_type; - typedef bsl::string field_type; - typedef bsl::var::ArrayIterator array_iterator; - typedef bsl::var::ArrayConstIterator array_const_iterator; - - typedef bsl::var::String::allocator_type allocator_type; - - TestVarString() - { - g_xcompool.create(); - allocator_type __alloc(&g_xcompool); - _alloc = __alloc; - bsl::var::String __str("沃草微舞",_alloc); - _str = __str; - } - - virtual ~TestVarString(){} - - //special methods - virtual void test_special(){ - //pool - { - bsl::syspool pool; - allocator_type alloc(&pool); - bsl::var::String str1(alloc); - str1 = "hello"; - bsl::var::String str2 = str1; - assert( str2.is_string() ); - assert( str2.to_string() == "hello" ); - str1 = "world"; - assert( str2.to_string() == "hello" ); - } - //xmempool - { - bsl::xmempool pool; - char buffer[1000]; - pool.create(buffer,sizeof(buffer)); - allocator_type alloc(&pool); - bsl::var::String str1(alloc); - bsl::var::String str2; - str2 = "hello world"; - str1 = str2; - assert( str1.to_string() == "hello world" ); - pool.clear(); - - bsl::var::String str3("hehe",alloc); - str2 = "hehe"; - assert(str3.to_string() == str2.to_string()); - str2 = str3; - assert(str3.to_string() == str2.to_string()); - pool.clear(); - - bsl::var::String str4("hoho",3,alloc); - assert(str4.to_string() == "hoh"); - pool.clear(); - - } - //copy ctor - { - bsl::var::String i = "hello"; - bsl::var::String j = i; - assert( j.is_string() ); - assert( j.to_string() == "hello" ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - //copy assign - { - bsl::var::String i = "hello"; - bsl::var::String j; - j = i; - assert( j.is_string() ); - assert( j.to_string() == "hello" ); - i = "acumon"; - assert( j.to_string() == "hello" ); - } - } - - //methods for all - virtual void test_mask(){ - test_mask_consistency( bsl::var::String("hello") ); - } - - virtual void test_operator_assign(){ - // = int - { - bsl::var::String i(_alloc); - i = 123; - assert( i.to_int32() == 123 ); - assert( i.to_int64() == 123 ); - assert( i.to_string() == "123" ); - assert( i.is_string() ); - } - - // = long long - { - - bsl::var::String i(_alloc); - i = 1234567891234567LL; - assert( i.to_int64() == 1234567891234567LL ); - assert( i.to_double() == double(1234567891234567LL) ); - assert( i.is_string() ); - assert( i.to_string() == "1234567891234567" ); - } - - // = double - { - bsl::var::String i(_alloc); - i = 4670.9394; - assert( i.to_int32() == 4670 ); - assert( i.to_int64() == 4670 ); - assert( i.to_double() == 4670.9394 ); - assert( i.is_string() ); - assert( i.to_string() == "4670.939400" ); - } - - // = const char* - { - bsl::var::String i(_alloc); - i = "46709394"; - assert( i.to_int32() == 46709394 ); - - i = "abcdef"; - assert( i.to_string() == "abcdef" ); - - i = ""; - assert( i.to_string() == "" ); - - } - - // = string_type - { - bsl::var::String i(_alloc); - i = string_type("46709394"); - assert( i.to_int32() == 46709394 ); - - i = string_type("abcdef"); - assert( i.to_string() == "abcdef" ); - - i = string_type(); - assert( i.to_string() == "" ); - - } - - // = String - { - bsl::var::String i(_alloc), j(_alloc); - j = "a secret"; - i = j; - assert( i.to_string() == "a secret" ); - } - - // = *this - { - bsl::var::String i(_alloc); - i = "self"; - i = i; - assert( i.to_string() == "self" ); - } - - } - - virtual void test_clear() { - { - bsl::var::String i("will be cleared",_alloc); - i.clear(); //assert no-throw - assert(i.to_string() == ""); - } - } - - virtual void test_dump() { - { - bsl::var::String i(_alloc); - assert( i.dump() == string_type("[bsl::var::String]") ); - assert( i.dump(999) == string_type("[bsl::var::String]") ); - } - - { - bsl::var::String i("1234567",_alloc); - assert( i.dump() == string_type("[bsl::var::String]1234567") ); - assert( i.dump(999) == string_type("[bsl::var::String]1234567") ); - } - } - - virtual void test_to_string() { - { - bsl::var::String i(_alloc); - assert( i.to_string() == string_type("") ); - } - - { - bsl::var::String i("1234567",_alloc); - assert( i.to_string() == string_type("1234567") ); - } - } - - virtual void test_get_type() { - assert( bsl::var::String().get_type() == string_type("bsl::var::String") ); - } - - //method for value - virtual void test_bool(){ - //= bool - { - bsl::var::String str("Acumon",_alloc); - str = true; - assert( str.to_string() == "true" ); - } - { - bsl::var::String str("Acumon",_alloc); - str = false; - assert( str.to_string() == "false" ); - } - // to bool - { - assert( bsl::var::String().to_bool() == false ); - assert( bsl::var::String("false").to_bool() == true ); - } - } - - virtual void test_raw(){ - test_invalid_raw(_str); - } - - virtual void test_number(){ - test_to_int32(); - test_to_int64(); - test_to_double(); - - } - - virtual void test_clone(){ - bsl::ResourcePool rp; - bsl::var::String s("hello",_alloc); - assert( s.clone(rp).get_type() == s.get_type() ); - assert( s.clone(rp).to_string() == s.to_string() ); - assert( s.clone(rp).c_str() != s.c_str() ); - } - - virtual void test_string(){ - test_c_str(); - } - - //methods for array - virtual void test_array(){ - test_invalid_array(_str); - } - - //methods for dict - virtual void test_dict(){ - test_invalid_dict(_str); - } - - //methods for callable - virtual void test_callable(){ - test_invalid_callable(_str); - } - - virtual void test_to_int32(){ - { - ASSERT_THROW( bsl::var::String().to_int32(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_int32(), bsl::BadCastException ); - - assert( bsl::var::String("0").to_int32() == 0 ); - assert( bsl::var::String("-1").to_int32() == -1 ); - assert( bsl::var::String("1234567").to_int32() == 1234567 ); - } - } - - virtual void test_to_int64(){ - { - ASSERT_THROW( bsl::var::String().to_int64(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_int64(), bsl::BadCastException ); - - assert( bsl::var::String("+0").to_int64() == 0 ); - assert( bsl::var::String("-123456789123").to_int64() == -123456789123LL ); - assert( bsl::var::String("+123456746709394").to_int64() == 123456746709394LL ); - } - } - - virtual void test_to_double(){ - { - ASSERT_THROW( bsl::var::String().to_double(), bsl::BadCastException ); - ASSERT_THROW( bsl::var::String("not a number!").to_double(), bsl::BadCastException ); - - assert( bsl::var::String("-4670.9394").to_double() == -4670.9394 ); - assert( bsl::var::String("+0.00000000").to_double() == 0 ); - assert( bsl::var::String("123.456").to_double() == 123.456 ); - } - } - - virtual void test_c_str(){ - { - bsl::var::String i(_alloc); - assert( i.c_str() == string_type("") ); - assert( i.c_str_len() == 0 ); - } - - { - bsl::var::String i("1234567",_alloc); - assert( i.c_str() == string_type("1234567") ); - assert( i.c_str_len() == string_type("1234567").size() ); - } - } - -private: - bsl::var::String _str; - allocator_type _alloc; -}; - -int main(){ - TestVarString().test_all(); - return 0; -} - - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_invalid.h b/bsl/var/unittest/test_var_invalid.h deleted file mode 100644 index 2bb6490417d426332a62f9bc9fdfffd5aa8fc697..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_invalid.h +++ /dev/null @@ -1,486 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_invalid.h,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file test_var_invalid.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/05/09 16:11:45 - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __TEST_VAR_INVALID_H_ -#define __TEST_VAR_INVALID_H_ - -#include "bsl/var/implement.h" -#include "test.h" - -inline void test_mask_consistency(const bsl::var::IVar& var){ - using namespace bsl::var; - if ( var.is_number() ){ - assert( var.get_mask() & IVar::IS_NUMBER ); - } - // assert( var.\1() == bool(\2) ); - assert( var.is_number() == bool(var.get_mask() & IVar::IS_NUMBER ) ); - assert( var.is_null() == bool((var.get_mask() & 0xFF) == 0) ); - assert( var.is_ref() == bool(var.get_mask() & bsl::var::IVar::IS_REF) ); -#ifdef PHP_COMLOG - assert( var.is_bool() == bool(var.get_mask() & bsl::var::IVar::_IS_BOOL) ); -#else - assert( var.is_bool() == bool(var.get_mask() & bsl::var::IVar::IS_BOOL) ); -#endif - assert( var.is_number() == bool(var.get_mask() & bsl::var::IVar::IS_NUMBER) ); - assert( var.is_int8() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_ONE_BYTE|bsl::var::IVar::IS_SIGNED )) ); - - assert( var.is_uint8() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_ONE_BYTE, bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_int16() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_TWO_BYTE|bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_uint16() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_TWO_BYTE, bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_int32() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_FOUR_BYTE|bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_uint32() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_FOUR_BYTE, bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_int64() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_EIGHT_BYTE|bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_uint64() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_EIGHT_BYTE, bsl::var::IVar::IS_SIGNED )) ); - assert( var.is_float() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_FOUR_BYTE|bsl::var::IVar::IS_FLOATING )) ); - assert( var.is_double() == bool(bsl::var::IVar::check_mask( var.get_mask(), bsl::var::IVar::IS_NUMBER|bsl::var::IVar::IS_EIGHT_BYTE|bsl::var::IVar::IS_FLOATING )) ); -#ifdef PHP_COMLOG - assert( var.is_string() == bool(var.get_mask() & bsl::var::IVar::_IS_STRING) ); - assert( var.is_array() == bool(var.get_mask() & bsl::var::IVar::_IS_ARRAY) ); -#else - assert( var.is_string() == bool(var.get_mask() & bsl::var::IVar::IS_STRING) ); - assert( var.is_array() == bool(var.get_mask() & bsl::var::IVar::IS_ARRAY) ); -#endif - assert( var.is_dict() == bool(var.get_mask() & bsl::var::IVar::IS_DICT) ); - assert( var.is_callable() == bool(var.get_mask() & bsl::var::IVar::IS_CALLABLE) ); - assert( var.is_raw() == bool(var.get_mask() & bsl::var::IVar::IS_RAW) ); -} -inline void test_invalid_bool(bsl::var::IVar& var){ - //non-const methods - assert( !var.is_bool() ); - ASSERT_THROW( var.to_bool(), bsl::InvalidOperationException ); - ASSERT_THROW( var = true, bsl::InvalidOperationException ); - bsl::var::Bool b; - if ( !var.is_ref() ){ - ASSERT_THROW( var = b, bsl::InvalidOperationException ); - } - - //const methods - const bsl::var::IVar& const_var = var; - assert( !const_var.is_bool() ); - ASSERT_THROW( const_var.to_bool(), bsl::InvalidOperationException ); -} - -inline void test_invalid_raw(bsl::var::IVar& var){ - //non-const methods - assert(!var.is_raw()); - ASSERT_THROW( var.to_raw(), bsl::InvalidOperationException ); - bsl::var::IVar::raw_type raw_; - ASSERT_THROW( var = raw_, bsl::InvalidOperationException ); - bsl::var::ShallowRaw raw(raw_); - if ( typeid(var) != typeid(bsl::var::String) && !var.is_ref() ){ - ASSERT_THROW( var = raw, bsl::InvalidOperationException ); - } - - //const methods - const bsl::var::IVar& const_var = var; - assert(!const_var.is_raw()); - ASSERT_THROW( const_var.to_raw(), bsl::InvalidOperationException ); -} - -template //primitive type -inline void test_valid_number(const bsl::var::IVar& var, PT pv ){ -/* -signed char int8 -unsigned char uint8 -signed short int16 -unsigned short uint16 -signed int int32 -unsigned int uint32 -signed long long int64 -unsigned long long uint64 -*/ - if ( typeid(pv) == typeid(signed char) ){ - assert(var.is_int8()); - assert(var.to_int8() == static_cast(pv) ); - }else{ - assert(!var.is_int8()); - } - - if ( typeid(pv) == typeid(unsigned char) ){ - assert(var.is_uint8()); - assert(var.to_uint8() == static_cast(pv) ); - }else{ - assert(!var.is_uint8()); - } - - if ( typeid(pv) == typeid(signed short) ){ - assert(var.is_int16()); - assert(var.to_int16() == static_cast(pv) ); - }else{ - assert(!var.is_int16()); - } - - if ( typeid(pv) == typeid(unsigned short) ){ - assert(var.is_uint16()); - assert(var.to_uint16() == static_cast(pv) ); - }else{ - assert(!var.is_uint16()); - } - - if ( typeid(pv) == typeid(signed int) ){ - assert(var.is_int32()); - assert(var.to_int32() == static_cast(pv) ); - }else{ - assert(!var.is_int32()); - } - - if ( typeid(pv) == typeid(unsigned int) ){ - assert(var.is_uint32()); - assert(var.to_uint32() == static_cast(pv) ); - }else{ - assert(!var.is_uint32()); - } - - if ( typeid(pv) == typeid(signed long long) ){ - assert(var.is_int64()); - assert(var.to_int64() == static_cast(pv) ); - }else{ - assert(!var.is_int64()); - } - - if ( typeid(pv) == typeid(unsigned long long) ){ - assert(var.is_uint64()); - assert(var.to_uint64() == static_cast(pv) ); - }else{ - assert(!var.is_uint64()); - } - -#define CHECK_THROWN( expr, except, thrown )\ - do{ \ - try{ expr; thrown = 0;\ - }catch( except& ){ thrown = 1; \ - }catch( ... ){ thrown = 2; } \ - }while(0) - - /* - see(var.to_string()); - see(pv); - see(v_thrown); - see(p_thrown); - see(v_res); - see(p_res); - */ - int v_thrown = 0; - int p_thrown = 0; - { - signed char v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int8(), bsl::OverflowException, v_thrown ); - see(var.to_string()); - see(pv); - see(v_thrown); - see(p_thrown); - see(v_res); - see(p_res); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int8(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - unsigned char v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint8(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint8(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - signed short v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int16(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int16(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - unsigned short v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint16(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint16(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - signed int v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int32(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int32(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - unsigned int v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint32(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint32(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - signed long long v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int64(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_int64(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - - { - unsigned long long v_res = 0, p_res = 0; - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::OverflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint64(), bsl::OverflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - CHECK_THROWN( p_res = bsl::check_cast(pv), bsl::UnderflowException, p_thrown ); - CHECK_THROWN( v_res = var.to_uint64(), bsl::UnderflowException, v_thrown ); - assert( p_thrown == v_thrown && p_res == v_res ); - } - -#undef CHECK_THROWN - -} - -inline void test_invalid_number(bsl::var::IVar& var){ - //non-const methods - assert(!var.is_number()); - assert(!var.is_int8()); - assert(!var.is_uint8()); - assert(!var.is_int16()); - assert(!var.is_uint16()); - assert(!var.is_int32()); - assert(!var.is_uint32()); - assert(!var.is_int64()); - assert(!var.is_uint64()); - assert(!var.is_double()); - - ASSERT_THROW( var.to_int8(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_uint8(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_int16(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_uint16(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_int32(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_uint32(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_int64(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_uint64(), bsl::InvalidOperationException ); - ASSERT_THROW( var.to_double(), bsl::InvalidOperationException ); - - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = static_cast(123), bsl::InvalidOperationException ); - ASSERT_THROW( var = 4670.9394, bsl::InvalidOperationException ); - - bsl::var::Number i8; - bsl::var::Number u8; - bsl::var::Number i16; - bsl::var::Number u16; - bsl::var::Number i32; - bsl::var::Number u32; - bsl::var::Number i64; - bsl::var::Number u64; - bsl::var::Number dbl; - if ( !var.is_ref() ){ - ASSERT_THROW( var = i8, bsl::InvalidOperationException ); - ASSERT_THROW( var = u8, bsl::InvalidOperationException ); - ASSERT_THROW( var = i16, bsl::InvalidOperationException ); - ASSERT_THROW( var = u16, bsl::InvalidOperationException ); - ASSERT_THROW( var = i32, bsl::InvalidOperationException ); - ASSERT_THROW( var = u32, bsl::InvalidOperationException ); - ASSERT_THROW( var = i64, bsl::InvalidOperationException ); - ASSERT_THROW( var = u64, bsl::InvalidOperationException ); - ASSERT_THROW( var = dbl, bsl::InvalidOperationException ); - } - - //const methods - const bsl::var::IVar& const_var = var; - - assert(!const_var.is_number()); - assert(!const_var.is_int8()); - assert(!const_var.is_uint8()); - assert(!const_var.is_int16()); - assert(!const_var.is_uint16()); - assert(!const_var.is_int32()); - assert(!const_var.is_uint32()); - assert(!const_var.is_int64()); - assert(!const_var.is_uint64()); - assert(!const_var.is_double()); - - ASSERT_THROW( const_var.to_int8(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_uint8(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_int16(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_uint16(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_int32(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_uint32(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_int64(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_uint64(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.to_double(), bsl::InvalidOperationException ); - -} - -inline void test_invalid_string(bsl::var::IVar& var){ - //non-const methods - assert( !var.is_string() ); - ASSERT_THROW( var.c_str(), bsl::InvalidOperationException ); - ASSERT_THROW( var.c_str_len(), bsl::InvalidOperationException ); - if ( !var.is_number() && !var.is_bool() ){ - //number类别可能支持下列方法 - ASSERT_THROW( var = "abc", bsl::InvalidOperationException ); - ASSERT_THROW( var = bsl::var::IVar::string_type("abc"), bsl::InvalidOperationException ); - if ( !var.is_ref() ){ - bsl::var::String str("abc"); - ASSERT_THROW( var = str, bsl::InvalidOperationException ); - } - } - - //const methods - const bsl::var::IVar& const_var = var; - assert( !const_var.is_string() ); - ASSERT_THROW( const_var.c_str(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.c_str_len(), bsl::InvalidOperationException ); -} - -inline void test_invalid_array(bsl::var::IVar& var){ - //non-const methods - assert( !var.is_array() ); - //size() - if ( !var.is_dict() ){ - ASSERT_THROW( var.size(), bsl::InvalidOperationException ); - } - //get() - ASSERT_THROW( var.get(0), bsl::InvalidOperationException ); - //set() - ASSERT_THROW( var.set(0, var), bsl::InvalidOperationException ); - //del() - ASSERT_THROW( var.del(0), bsl::InvalidOperationException ); - //operator []() - ASSERT_THROW( var[-1], bsl::InvalidOperationException ); - ASSERT_THROW( var[0], bsl::InvalidOperationException ); - ASSERT_THROW( var[1], bsl::InvalidOperationException ); - //iterator - ASSERT_THROW( var.array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( var.array_end(), bsl::InvalidOperationException ); - //operator = - bsl::var::Array arr; - if ( typeid(var) != typeid(bsl::var::String) && !var.is_ref() ){ - ASSERT_THROW( var = arr, bsl::InvalidOperationException ); - } - - //const methods - const bsl::var::IVar& const_var = var; - //get() - ASSERT_THROW( const_var.get(0), bsl::InvalidOperationException ); - //operator []() - ASSERT_THROW( const_var[-1], bsl::InvalidOperationException ); - ASSERT_THROW( const_var[0], bsl::InvalidOperationException ); - ASSERT_THROW( const_var[1], bsl::InvalidOperationException ); - //iterator - ASSERT_THROW( const_var.array_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.array_end(), bsl::InvalidOperationException ); -} - -inline void test_invalid_dict(bsl::var::IVar& var){ - //non-const methods - assert( !var.is_dict() ); - //size() - if ( !var.is_array() ){ - ASSERT_THROW( var.size(), bsl::InvalidOperationException ); - } - //get() - ASSERT_THROW( var.get(""), bsl::InvalidOperationException ); - ASSERT_THROW( var.get("a key"), bsl::InvalidOperationException ); - ASSERT_THROW( var.get(bsl::var::IVar::string_type("another key")), bsl::InvalidOperationException ); - //set() - ASSERT_THROW( var.set(bsl::var::IVar::string_type(""),var), bsl::InvalidOperationException ); - ASSERT_THROW( var.set("some key",var), bsl::InvalidOperationException ); - ASSERT_THROW( var.set(bsl::var::IVar::string_type("another key"),var), bsl::InvalidOperationException ); - //del() - ASSERT_THROW( var.del("whatever"), bsl::InvalidOperationException ); - //operator [] - ASSERT_THROW( var[""], bsl::InvalidOperationException ); - ASSERT_THROW( var["awesome key"], bsl::InvalidOperationException ); - //iterator - ASSERT_THROW( var.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( var.dict_end(), bsl::InvalidOperationException ); - //operator = - bsl::var::Dict d; - if ( typeid(var) != typeid(bsl::var::String) && !var.is_ref() ){ - ASSERT_THROW( var = d, bsl::InvalidOperationException ); - } - - //const methods - const bsl::var::IVar& const_var = var; - //get() - ASSERT_THROW( const_var.get(""), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.get("a key"), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.get(bsl::var::IVar::string_type("another key")), bsl::InvalidOperationException ); - //operator [] - ASSERT_THROW( const_var[""], bsl::InvalidOperationException ); - ASSERT_THROW( const_var["awesome key"], bsl::InvalidOperationException ); - //iterator - ASSERT_THROW( const_var.dict_begin(), bsl::InvalidOperationException ); - ASSERT_THROW( const_var.dict_end(), bsl::InvalidOperationException ); -} - -inline bsl::var::IVar& echo_f( bsl::var::IVar& args, bsl::ResourcePool& ){ - return args; -} - -inline bsl::var::IVar& echo_m( bsl::var::IVar& self, bsl::var::IVar& args, bsl::ResourcePool& rp){ - bsl::var::IVar& res = rp.create(); - res["self"] = self; - res["args"] = args; - return res; -} - -inline void test_invalid_callable(bsl::var::IVar& var){ - //non-const methods - assert( !var.is_callable() ); - bsl::var::Dict self; - bsl::var::Array params; - bsl::ResourcePool rp; - - ASSERT_THROW( var(params, rp), bsl::InvalidOperationException ); - ASSERT_THROW( var(self, params, rp), bsl::InvalidOperationException ); - bsl::var::Function func(echo_f, "echo_f"); - if ( typeid(var) != typeid(bsl::var::String) && !var.is_ref() ){ - ASSERT_THROW( var = func, bsl::InvalidOperationException ); - } - bsl::var::Function method(echo_f, "echo_f"); - if ( typeid(var) != typeid(bsl::var::String) && !var.is_ref() ){ - ASSERT_THROW( var = method, bsl::InvalidOperationException ); - } - - //no const methods defined -} -#endif //__TEST_VAR_INVALID_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/unittest/test_var_utils.cpp b/bsl/var/unittest/test_var_utils.cpp deleted file mode 100644 index 97d2d697445bcef9678fd73f9f98a14906c5697f..0000000000000000000000000000000000000000 --- a/bsl/var/unittest/test_var_utils.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: test_var_utils.cpp,v 1.3 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - -#include "bsl/var/implement.h" -#include "bsl/var/utils.h" -#include "bsl/var/assign.h" -#include "bsl/var/var_traits.h" - - -/** - * @file test_var_utils.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2009/05/07 15:35:38 - * @version $Revision: 1.3 $ - * @brief - * - **/ - -#include -#include -#define see(x) do{ \ - std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<" ); - printf("i32, 0: %s", res.c_str() ); - } - { - bsl::string res; - dump_to_string( i32, res, 999, "" ); - printf("i32, 999: %s", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 0, "" ); - printf("dict, 0: %s", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 1, "" ); - printf("dict, 1: %s", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 3, "" ); - printf("dict, 3: %s", res.c_str() ); - } - { - bsl::string res; - dump_to_string( i32, res, 0, "\n" ); - printf("i32, 0: %s\n", res.c_str() ); - } - { - bsl::string res; - dump_to_string( i32, res, 999, "\n" ); - printf("i32, 999: %s\n", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 0, "\n" ); - printf("dict, 0: %s\n", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 1, "\n" ); - printf("dict, 1: %s\n", res.c_str() ); - } - { - bsl::string res; - dump_to_string( dict, res, 3, "\n" ); - printf("dict, 3: %s\n", res.c_str() ); - } -} - -void test_assign(){ - bsl::var::Int32 i32(123); - bsl::var::Int64 i64(456); - bsl::var::String str("hello"); - //array - bsl::var::Array arr; - bsl::var::assign( arr, i32, i64 ); - assert( arr.size() == 2 ); - assert( arr[0].to_int32() == 123 ); - assert( arr[1].to_int64() == 456 ); - bsl::var::assign( arr, str ); - assert( arr.size() == 1 ); - assert( arr[0].to_string() == "hello" ); - - //dict - bsl::var::Dict dict; - bsl::var::assign( dict, "haha", i32, "hehe", i64 ); - assert( dict.size() == 2 ); - assert( dict["haha"].to_int32() == 123 ); - assert( dict["hehe"].to_int64() == 456 ); - bsl::var::assign( dict, "crazy", str ); - assert( dict.size() == 1 ); - assert( dict["crazy"].to_string() == "hello" ); - -} -template -void test_traits_type(){ - bsl::var::Number v; - assert(v.get_mask() == bsl::var::var_traits::MASK); -} - -void test_traits(){ - test_traits_type(); - test_traits_type(); - test_traits_type(); - test_traits_type(); - test_traits_type(); - test_traits_type(); - test_traits_type(); - test_traits_type(); -} - -int main(){ - test_dump_to_string(); - test_assign(); - test_traits(); - return 0; -} -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/utils/BCLOUD b/bsl/var/utils/BCLOUD deleted file mode 100644 index ef1203a33ec02dfbf1dd39336ccde66c948d18db..0000000000000000000000000000000000000000 --- a/bsl/var/utils/BCLOUD +++ /dev/null @@ -1,69 +0,0 @@ -#edit-mode: -*- python -*- -#coding:gbk - -WORKROOT('../../../../') - -#platform, if not write PLATFORM('xxx') in BCLOUD file, default is 'redhat4u3' -#PLATFORM('centos4u3') - -#gcc version, default 'gcc' -#COMPILER('gcc482') - -#Preprocessor flags. -CPPFLAGS(r'-DVAR_DEBUG_FLAG -DBSL_VERSION=\"bsl1.1.0.0\" -DBSL_CVSTAG=\"bsl_1-1-0-0_PD_BL\" -DBSL_PROJECT_NAME=\"bsl\"') -#CPPFLAGS(r'-DVERSION=\"%s\"' % SVN_LAST_CHANGED_REV()) - -#C flags. -#CFLAGS('-g -pipe -W -Wall -fPIC') - -#C++ flags. -CXXFLAGS(' -g -rdynamic -pipe -fPIC -finline-functions -fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Winline -Woverloaded-virtual -Wsign-promo') - -#IDL flags. -#IDLFLAGS('--compack') - -#UBRPC flags. -#UBRPCFLAGS('--compack') - -#-I path -INCPATHS('. ./include $OUT/include') -#INCPATHS('../../../../') - -#libs which need to link with -#LIBS('$OUT/lib/libutils.a') -#LIBS('$OUT/so/libutils.so') - -#link flags -#LDFLAGS('-lpthread -lcrypto -lrt') - -#CONFIGS("lib2-64/ullib@base") - -user_sources=GLOB("*.cpp") - -#release headers -HEADERS('*.h', '$INC/bsl/var') -#HEADERS('*.h', '$INC/bsl') -#HEADERS('*.hpp', '$INC') -#HEADERS('include/*.h', '$INC') -#HEADERS('include/*.hpp', '$INC') - -#release files except headers -#OUTPUT('conf', '$OUT') - -#bin -#Application('utils', Sources(user_sources)) - -#UT -#UTApplication('utils', Sources(user_sources), UTArgs(''), UTOnServer(False)) - -#.a -StaticLibrary('bsl_var_utils', Sources(user_sources)) -#StaticLibrary('utils', PreBuilt(True)) - -#.so -#SharedLibrary('utils', Sources(user_sources)) -#SharedLibrary('utils', PreBuilt(True)) - -#sub directory -#Directory('demo') - diff --git a/bsl/var/utils/CMakeLists.txt b/bsl/var/utils/CMakeLists.txt deleted file mode 100644 index 767abc6f5f842677a795be4b1b845cda7959f9ad..0000000000000000000000000000000000000000 --- a/bsl/var/utils/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -FILE(GLOB var_utils_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp) -add_library(var_utils ${var_utils_srcs}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsl/var/utils/Makefile b/bsl/var/utils/Makefile deleted file mode 100644 index 6e0daa6cff1e10f637b6477009edba08db544075..0000000000000000000000000000000000000000 --- a/bsl/var/utils/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -###################################################### -# MAKEFILE TEMPLATE # -# AUTHOR: chenxm (chenxiaoming@baidu.com) # -# LAST UPDATE: Fri Jan 9 12:33:18 CST 2009 # -###################################################### - -####################################### CONFIGURATION ####################################### - -##### basic configuration ##### -VAR_ROOT = .. -include $(VAR_ROOT)/Makefile.env - -##### build & test configuration ##### - -PROVIDE_HEADS = $(wildcard *.h) $(patsubst %.py, %.h, $(wildcard *.py)) - -PROVIDE_OBJECTS = utils.o - -PROVIDE_LIB = bsl_var_utils - -DEPEND_HEADS = $(PROVIDE_HEADS) $(wildcard $(OUTPUT_HEAD_PATH)/*.h ) - -##### other ##### - -TAG_ROOT = $(VAR_ROOT) - -####################################### RULES ####################################### -include $(VAR_ROOT)/Makefile.rules - -####################################### SPECIAL RULES ####################################### -assign.h: assign.py - python $^ > $@ - - diff --git a/bsl/var/utils/assign.h b/bsl/var/utils/assign.h deleted file mode 100644 index 0a594e7e18c1deba907288d0687f28370397cea8..0000000000000000000000000000000000000000 --- a/bsl/var/utils/assign.h +++ /dev/null @@ -1,693 +0,0 @@ - -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * $Id: assign.py,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file assign.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/03/09 17:55:29 - * @version $Revision: 1.2 $ - * @brief this file is generated by assign.py. don't modify - * - **/ - -#ifndef __BSL_VAR_ASSIGN_H__ -#define __BSL_VAR_ASSIGN_H__ -#include "bsl/var/IVar.h" - -namespace bsl{ namespace var{ - /** - * @brief assign an array with 0 args - * - * @param [out] arr : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - ){ - arr.clear(); - return arr; - } - /** - * @brief assign an array with 1 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - ){ - arr.clear(); - arr.set(0,arg0); - return arr; - } - /** - * @brief assign an array with 2 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - return arr; - } - /** - * @brief assign an array with 3 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - return arr; - } - /** - * @brief assign an array with 4 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - return arr; - } - /** - * @brief assign an array with 5 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - return arr; - } - /** - * @brief assign an array with 6 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - , IVar& arg5 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - arr.set(5,arg5); - return arr; - } - /** - * @brief assign an array with 7 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - , IVar& arg5 - , IVar& arg6 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - arr.set(5,arg5); - arr.set(6,arg6); - return arr; - } - /** - * @brief assign an array with 8 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - , IVar& arg5 - , IVar& arg6 - , IVar& arg7 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - arr.set(5,arg5); - arr.set(6,arg6); - arr.set(7,arg7); - return arr; - } - /** - * @brief assign an array with 9 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @param [in] arg8 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - , IVar& arg5 - , IVar& arg6 - , IVar& arg7 - , IVar& arg8 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - arr.set(5,arg5); - arr.set(6,arg6); - arr.set(7,arg7); - arr.set(8,arg8); - return arr; - } - /** - * @brief assign an array with 10 args - * - * @param [out] arr : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @param [in] arg8 : IVar& - * @param [in] arg9 : IVar& - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& arr - , IVar& arg0 - , IVar& arg1 - , IVar& arg2 - , IVar& arg3 - , IVar& arg4 - , IVar& arg5 - , IVar& arg6 - , IVar& arg7 - , IVar& arg8 - , IVar& arg9 - ){ - arr.clear(); - arr.set(0,arg0); - arr.set(1,arg1); - arr.set(2,arg2); - arr.set(3,arg3); - arr.set(4,arg4); - arr.set(5,arg5); - arr.set(6,arg6); - arr.set(7,arg7); - arr.set(8,arg8); - arr.set(9,arg9); - return arr; - } - /** - * @brief assign a dict with 1 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - ){ - dict.clear(); - dict.set(key0,value0); - return dict; - } - /** - * @brief assign a dict with 2 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - return dict; - } - /** - * @brief assign a dict with 3 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - return dict; - } - /** - * @brief assign a dict with 4 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - return dict; - } - /** - * @brief assign a dict with 5 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - return dict; - } - /** - * @brief assign a dict with 6 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - , const bsl::string& key5, IVar& value5 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - dict.set(key5,value5); - return dict; - } - /** - * @brief assign a dict with 7 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - , const bsl::string& key5, IVar& value5 - , const bsl::string& key6, IVar& value6 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - dict.set(key5,value5); - dict.set(key6,value6); - return dict; - } - /** - * @brief assign a dict with 8 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - , const bsl::string& key5, IVar& value5 - , const bsl::string& key6, IVar& value6 - , const bsl::string& key7, IVar& value7 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - dict.set(key5,value5); - dict.set(key6,value6); - dict.set(key7,value7); - return dict; - } - /** - * @brief assign a dict with 9 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @param [in] arg8 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - , const bsl::string& key5, IVar& value5 - , const bsl::string& key6, IVar& value6 - , const bsl::string& key7, IVar& value7 - , const bsl::string& key8, IVar& value8 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - dict.set(key5,value5); - dict.set(key6,value6); - dict.set(key7,value7); - dict.set(key8,value8); - return dict; - } - /** - * @brief assign a dict with 10 args - * - * @param [out] dict : IVar& - * @param [in] arg0 : IVar& - * @param [in] arg1 : IVar& - * @param [in] arg2 : IVar& - * @param [in] arg3 : IVar& - * @param [in] arg4 : IVar& - * @param [in] arg5 : IVar& - * @param [in] arg6 : IVar& - * @param [in] arg7 : IVar& - * @param [in] arg8 : IVar& - * @param [in] arg9 : IVar& - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ - - inline IVar& assign( IVar& dict - , const bsl::string& key0, IVar& value0 - , const bsl::string& key1, IVar& value1 - , const bsl::string& key2, IVar& value2 - , const bsl::string& key3, IVar& value3 - , const bsl::string& key4, IVar& value4 - , const bsl::string& key5, IVar& value5 - , const bsl::string& key6, IVar& value6 - , const bsl::string& key7, IVar& value7 - , const bsl::string& key8, IVar& value8 - , const bsl::string& key9, IVar& value9 - ){ - dict.clear(); - dict.set(key0,value0); - dict.set(key1,value1); - dict.set(key2,value2); - dict.set(key3,value3); - dict.set(key4,value4); - dict.set(key5,value5); - dict.set(key6,value6); - dict.set(key7,value7); - dict.set(key8,value8); - dict.set(key9,value9); - return dict; - } -}} //namespace bsl::var -#endif // __BSL_VAR_ASSIGN_H__ -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/utils/assign.py b/bsl/var/utils/assign.py deleted file mode 100644 index 9e94bb555d64c4b9b2bcf29ec8407acab1343518..0000000000000000000000000000000000000000 --- a/bsl/var/utils/assign.py +++ /dev/null @@ -1,137 +0,0 @@ -HEADER = """ -/*************************************************************************** - * - * Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved - * $Id: assign.py,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file assign.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/03/09 17:55:29 - * @version $Revision: 1.2 $ - * @brief this file is generated by assign.py. don't modify - * - **/ - -#ifndef __BSL_VAR_ASSIGN_H__ -#define __BSL_VAR_ASSIGN_H__ -#include "bsl/var/IVar.h" - -namespace bsl{ namespace var{""" - -ARRAY_FUNC_DOC_HEADER = """ - /** - * @brief assign an array with %d args - * - * @param [out] arr : IVar&""" -ARRAY_FUNC_DOC_LOOP = """ - * @param [in] arg%d : IVar&""" -ARRAY_FUNC_DOC_FOOTER = """ - * @return IVar& - * @retval arr - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ -""" -ARRAY_PARAMS_HEADER = """ - inline IVar& assign( IVar& arr""" -ARRAY_PARAMS_LOOP = """ - , IVar& arg%d""" -ARRAY_PARAMS_FOOTER = """ - ){""" - -ARRAY_FUNC_HEADER = """ - arr.clear();""" -ARRAY_FUNC_LOOP = """ - arr.set(%d,arg%d);""" -ARRAY_FUNC_FOOTER = """ - return arr; - }""" -FOOTER = """ -}} //namespace bsl::var -#endif //__BSL_VAR_ASSIGN_H__ -/* vim: set ts=4 sw=4 sts=4 tw=100 */""" - - -DICT_FUNC_DOC_HEADER = """ - /** - * @brief assign a dict with %d args - * - * @param [out] dict : IVar&""" -DICT_FUNC_DOC_LOOP = """ - * @param [in] arg%d : IVar&""" -DICT_FUNC_DOC_FOOTER = """ - * @return IVar& - * @retval dict - * @see - * @author chenxm - * @date 2010/03/09 18:01:53 - **/ -""" -DICT_PARAMS_HEADER = """ - inline IVar& assign( IVar& dict""" -DICT_PARAMS_LOOP = """ - , const bsl::string& key%d, IVar& value%d""" -DICT_PARAMS_FOOTER = """ - ){""" - -DICT_FUNC_HEADER = """ - dict.clear();""" -DICT_FUNC_LOOP = """ - dict.set(key%d,value%d);""" -DICT_FUNC_FOOTER = """ - return dict; - }""" - -FOOTER = """ -}} //namespace bsl::var -#endif // __BSL_VAR_ASSIGN_H__ -/* vim: set ts=4 sw=4 sts=4 tw=100 */""" - -if __name__ == "__main__": - code = [ HEADER ] - #array - for i in range(11): # 0~10 args - #doc - code.append(ARRAY_FUNC_DOC_HEADER % i) - for j in range(i): - code.append(ARRAY_FUNC_DOC_LOOP % j) - code.append(ARRAY_FUNC_DOC_FOOTER) - - #params - code.append(ARRAY_PARAMS_HEADER) - for j in range(i): - code.append(ARRAY_PARAMS_LOOP % j) - code.append(ARRAY_PARAMS_FOOTER) - - #func - code.append(ARRAY_FUNC_HEADER) - for j in range(i): - code.append(ARRAY_FUNC_LOOP % (j,j)) - code.append(ARRAY_FUNC_FOOTER) - - for i in range(1,11): # 1~10 args, 0 arg is the same as array - #doc - code.append(DICT_FUNC_DOC_HEADER % i) - for j in range(i): - code.append(DICT_FUNC_DOC_LOOP % j) - code.append(DICT_FUNC_DOC_FOOTER) - - #params - code.append(DICT_PARAMS_HEADER) - for j in range(i): - code.append(DICT_PARAMS_LOOP % (j,j)) - code.append(DICT_PARAMS_FOOTER) - - #func - code.append(DICT_FUNC_HEADER) - for j in range(i): - code.append(DICT_FUNC_LOOP % (j,j)) - code.append(DICT_FUNC_FOOTER) - code.append(FOOTER) - print ''.join(code) diff --git a/bsl/var/utils/utils.cpp b/bsl/var/utils/utils.cpp deleted file mode 100644 index 804bb3f350f46c59639aeb2a425d7a9ef82a0c26..0000000000000000000000000000000000000000 --- a/bsl/var/utils/utils.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: utils.cpp,v 1.3 2010/09/08 $ - * - **************************************************************************/ - - -#include "bsl/var/utils.h" - -/** - * @file utils.cpp - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/09/08 modified by Zhu Jianwei - * @version $Revision: 1.3 $ - * @brief - * - **/ - -namespace bsl{ - namespace var{ - void dump_to_string(const IVar& var, IVar::string_type& res, size_t verbose_level, const char *line_delimiter, size_t per_indent, size_t total_indent){ - if ( NULL == line_delimiter ){ - throw NullPointerException()< 0 ){ - //输出详细内容 - bool first = true; - //如果是数组,按数组方式遍历 - if ( var.is_array() ){ - IVar::array_const_iterator iter_= var.array_begin(); - IVar::array_const_iterator end = var.array_end(); - for(; iter_ != end; ++ iter_ ){ - if ( first ){ - res.append("{").append(line_delimiter); - first = false; - }else{ - res.append(",").append(line_delimiter); - } - //输出缩进及key - res.append( total_indent + per_indent, ' ' ).appendf("%zd", iter_->key()).append(": "); - //递归输出儿子结点 - dump_to_string( iter_->value(), res, verbose_level-1, line_delimiter, per_indent, total_indent + per_indent ); - } - } - //如果是字典,按字典方式遍历 - if ( var.is_dict() ){ - IVar::dict_const_iterator iter_= var.dict_begin(); - IVar::dict_const_iterator end = var.dict_end(); - for(; iter_ != end; ++ iter_ ){ - if ( first ){ - res.append("{").append(line_delimiter); - first = false; - }else{ - res.append(",").append(line_delimiter); - } - //输出缩进及key - res.append( total_indent + per_indent, ' ' ).append(iter_->key()).append(": "); - //递归输出儿子结点 - dump_to_string( iter_->value(), res, verbose_level-1, line_delimiter, per_indent, total_indent + per_indent ); - } - } - //如果曾经输出过内容,则输出闭括号 - if ( !first ){ - res.append(line_delimiter).append(total_indent, ' ').append("}"); - } - } - }else{ - //不是数组不是字典,则按dump(verbose_level)输出 - res.append( var.dump(verbose_level) ); - } - } - - void print( const IVar& var, size_t verbose_level ){ - IVar::string_type res; - dump_to_string(var, res, verbose_level, "\n" ); - printf("%s\n", res.c_str() ); - } - - }//namespace var -}//namespace bsl -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/utils/utils.h b/bsl/var/utils/utils.h deleted file mode 100644 index 4408493cb8b217e6b4042c7f661450a16ede2106..0000000000000000000000000000000000000000 --- a/bsl/var/utils/utils.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved - * $Id: utils.h,v 1.3 2010/09/08 $ - * - **************************************************************************/ - - - -/** - * @file utils.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2010/09/08 modified by Zhu Jianwei - * @version $Revision: 1.3 $ - * @brief - * - **/ -#ifndef __UTILS_H_ -#define __UTILS_H_ -#include "bsl/var/IVar.h" -#include "bsl/var/assign.h" -#include "bsl/var/var_traits.h" -#include "bsl/var/IRef.h" - -namespace bsl{ - namespace var{ - /** - * @brief 递归打印IVar数据到字符串 - * - * @param [in] var : const IVar& 被打印的IVar根结点 - * @param [in] res : IVar::string_type& 打印到的字符串 - * @param [in] verbose_level : size_t 递归最大层数 - * @param [in] line_delimiter : const char* 分行符 - * @param [in] per_indent : size_t 每次缩进字节数 - * @param [in] total_indent : size_t 总缩进字节数 - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/05/14 16:50:12 - **/ - void dump_to_string(const IVar& var, IVar::string_type& res, size_t verbose_level, const char *line_delimiter, size_t per_indent = 4, size_t total_indent = 0 ); - - /** - * @brief 递归、缩进打印IVar到STDOUT,GDB调试专用 - * - * @param [in] var : const IVar& - * @param [in] verbose_level : size_t - * @return void - * @retval - * @see - * @author chenxm - * @date 2009/05/14 16:54:52 - **/ - void print( const IVar& var, size_t verbose_level ); - } -} -#endif //__UTILS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/var/utils/var_traits.h b/bsl/var/utils/var_traits.h deleted file mode 100644 index 8098833587654b53536a13cee71b25285326ab00..0000000000000000000000000000000000000000 --- a/bsl/var/utils/var_traits.h +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: var_traits.h,v 1.2 2010/04/28 12:45:33 scmpf Exp $ - * - **************************************************************************/ - - - -/** - * @file var_traits.h - * @author chenxm(chenxiaoming@baidu.com) - * @date 2008/09/24 01:32:42 - * @version $Revision: 1.2 $ - * @brief - * - **/ -#ifndef __BSL_VAR_TRAITS_H__ -#define __BSL_VAR_TRAITS_H__ - -#include -#include -#include "bsl/var/IVar.h" - -namespace bsl{ namespace var{ - /** - * @brief 关于var的一些类型萃取特性 - * - * - */ - template - struct var_traits; - /* - signed char int8 - unsigned char uint8 - signed short int16 - unsigned short uint16 - signed int int32 - unsigned int uint32 - signed long long int64 - unsigned long long uint64 - */ - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_SIGNED|IVar::IS_ONE_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_ONE_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING|IVar::IS_SIGNED; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_SIGNED|IVar::IS_TWO_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_TWO_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING|IVar::IS_SIGNED; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_SIGNED|IVar::IS_FOUR_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_FOUR_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING|IVar::IS_SIGNED; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_SIGNED|IVar::IS_EIGHT_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_EIGHT_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::IS_FLOATING|IVar::IS_SIGNED; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_FLOATING|IVar::IS_FOUR_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::NONE_MASK; - }; - template<> - struct var_traits{ - static const IVar::mask_type MASK = IVar::IS_NUMBER|IVar::IS_FLOATING|IVar::IS_EIGHT_BYTE; - static const IVar::mask_type ANTI_MASK = IVar::NONE_MASK; - }; - -}} //namespace bsl::var - -#endif //__BSL_VAR_TRAITS_H__ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/yperfbench/ChangeLog b/bsl/yperfbench/ChangeLog deleted file mode 100644 index f9235893a7d1550c61b7e54ab2787a4a86d76675..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/ChangeLog +++ /dev/null @@ -1,2 +0,0 @@ -Jul 31, 2008 yperfbench 1.0 - 第一版 diff --git a/bsl/yperfbench/Makefile b/bsl/yperfbench/Makefile deleted file mode 100644 index f71c4c3e23432330f1fbb096913d5113f3e91b85..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all : - chmod +x ./bin/bench - make clean -C ./lib - make -C ./lib - -clean : - make clean -C ./lib diff --git a/bsl/yperfbench/README b/bsl/yperfbench/README deleted file mode 100644 index 312cf87fb6bf48b509f2b8364e11483d2d8e7d76..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/README +++ /dev/null @@ -1,22 +0,0 @@ -性能测试框架将包含三个部分: -基础库:基础库提供了性能测试中常用的工具,如计时、多线程工具、标准格式化输出。 -配置文件和解析器:性能测试的配置文件包含了待测程序的编译方法和运行是参数,解析器根据配置文件自动调用编译器完成编译和运行,以及数据采集和统计。它可以完成一段测试代码在多个不同的参数配置下运行,并搜集性能测量数据。 -数据分析:根据测试中采集的数据,绘制图表。 - -bench(python脚本)的命令行格式为 -bench [option] [testcase] -testcase 为所要运行的testcase名字,可列出多个 -bench(python脚本)有如下命令行参数: --cFILE 指定配置文件 --dPATH 指定配置文件路径 --C –compile 仅编译 --T –test 仅测试 - --single 对于每个测试程序仅编译一次 --s --script 生成测试脚本 --r --remote SSH远程执行模式 --h --help 显示帮助信息 - --human 人读模式 - --detail 显示详细数据报表 --f --file=FILE 将测试结果输出到文件 --v 显示版本信息 ---verbose 显示详细的命令执行过程。默认值显示测试结果 diff --git a/bsl/yperfbench/bin/bench b/bsl/yperfbench/bin/bench deleted file mode 100755 index 5c228dfc53b143dc9dad8674c76b57c51471e9ee..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/bin/bench +++ /dev/null @@ -1,496 +0,0 @@ -#!/usr/bin/python -import re -import commands -import sys -import os -import getopt - -env = {} -matchenv = re.compile(r"^(\w+) *=(.*)$") -matchcase = re.compile(r"^(\w+) *(\d*) *:(.+)$") -matchcase1 = re.compile(r"^(\w+) *(\d*) *:\W*$") -matchpara = re.compile(r"^\t((?:\d+)|(?:\$\(\w+\)) *)+$") -matchpara1 = re.compile(r"^\t(\w+) *[=:] *((?:\d+ *|\$\(\w+\) *)+)$") -matchscript = re.compile(r"^\t!(.*)$") -matchsubstitution = re.compile(r"\$\((\w+)\)") -matchcomment = re.compile(r"^\t?#.*$") -matchif = re.compile(r"^if +(\w+|\$\(\w+\)) +(\w+|\$\(\w+\))$") -benchfile = [] -compile_only = False -test_only = False -compile_single = True -compile_seperate = False -compile_script = False -verbose_mode = False -output_file = sys.stdout -seperate_output = False -output_dir = "" -remote_host = "" -def echo(*lines): - if verbose_mode: - for v in lines: - print v, - print - -def validate(): - global benchfile - state = 0 - preprocess = [] - for i in range(len(benchfile)): - line = benchfile[i].strip("\r\n") - if matchif.match(line) or line == "else" or line == "endif": - preprocess.append(line) - state = 0 - elif matchenv.match(line): - preprocess.append(line) - state = 0 - elif matchcomment.match(line): - pass - elif matchcase.match(line) or matchcase1.match(line): - preprocess.append(line) - state = 1 - elif (state == 1 or state == 2) and matchscript.match(line): - preprocess.append(line) - state = 2 - elif (state == 1 or state == 2 or state == 3) and (matchpara.match(line) or matchpara1.match(line)): - preprocess.append(line) - state = 3 - elif (state == 3 or state ==4) and matchscript.match(line): - preprocess.append(line) - state = 4 - elif line == "": - pass - else: - print >>sys.stderr, "bench: Benchfile format error" - print >>sys.stderr, "line ",str(i + 1) , ": ",line - sys.exit(1) - if state == 1 or state == 2: - print >>sys.stderr, "bench: unexpected Benchfile end" - sys.exit(1) - benchfile = preprocess - -def parse_env(m): - del benchfile[0] - os.environ[m.group(1)] = m.group(2) - -scriptfile = "" -filename = 0 -def get_cc(): - m = translate_env("CC") - if m: - return m - else: - return "g++" - -def get_macro_def(apparg): - macro = [] - for i, v in apparg: - if i: - macro.append("-D" + i.upper() + "=" + v) - return " ".join(macro) - -def compile(outname, gccarg, apparg): - cmd = " ".join([get_cc(), gccarg.strip(), get_macro_def(apparg), "-o", outname]) - echo(cmd) - compile = commands.getstatusoutput(cmd) - if compile[0]: - print >>sys.stderr, compile[1] - print >>sys.stderr, "bench: error, exit" - sys.exit(compile[0]) - -def get_test_arg(apparg): - arg = [] - for i,v in apparg: - if i == "": - arg.append(v) - elif len(i) == 1: - arg.append("-" + i + "=" + v) - else: - arg.append("--" + i + "=" + v) - return " ".join(arg) - -def get_compile_name(name): - global filename - if compile_single and compile_seperate: - return ".bench." + name - elif compile_seperate: - if compile_script: - name = scriptfile + "." + name + "." + str(filename) - filename += 1 - return name - else: - name = ".bench." + name + "." + str(filename) - filename += 1 - return name - else: - return ".bench" - -def benchmark_script(name, gccarg, repeat, apparg, prescript, postscript): - testname = get_compile_name(name) - if not compile_single: - compile(testname, gccarg, apparg) - cmd = "./" + testname + " " + get_test_arg(apparg) - f = open(scriptfile, "a+") - f.write(cmd + "\n") - echo(cmd) - f.close() - return None - -def benchmark_compile_only(name, gccarg, repeat, apparg, prescript, postscript): - if compile_single or not gccarg: - return None - testname = get_compile_name(name) - compile(testname, gccarg, apparg) - return None - -def test(cmd, repeat, apparg, prescript, postscript): - result = [] - for i in range(repeat): - run_script(prescript) - echo(cmd) - bench = commands.getstatusoutput(cmd) - if bench[0]: - print >>sys.stderr, "testcase" + bench[1].encode('utf-8') - sys.exit(bench[0]) - else: - echo(bench[1]) - if not bench[1]: - print >>sys.stderr, "get no output from testcase" - sys.exit(1) - run_script(postscript) - dic = {} - for v in bench[1].splitlines()[-1].strip().split(): - s = v.split(":") - dic[s[0]]=s[1] - result.append(dic) - return (apparg, result) - -def benchmark_test_only(name, gccarg, repeat, apparg, prescript, postscript): - if gccarg: - testname = get_compile_name(name) - else: - testname = name - cmd = "./" + testname + " " + get_test_arg(apparg) - return test(cmd, repeat, apparg, prescript, postscript) - -def run_script(script): - for c in script: - echo(c) - r = commands.getstatusoutput(c) - if r[1]: - print r[1] - if r[0]: - sys.exit(r[0]) - -def run_script_remote(script): - (host, path) = remote_host.split(":",1) - for c in script: - echo(c) - r = commands.getstatusoutput(" ".join(["ssh", host, c])) - if r[1]: - print r[1] - if r[0]: - sys.exit(r[0]) - -def test_remote(realname, cmd, repeat, apparg, prescript, postscript): - (host, path) = remote_host.split(":",1) - result = [] - for i in range(repeat): - run_script_remote(prescript) - cp = commands.getstatusoutput(" ".join(["scp", realname, host+":"+path])) - if cp[0]: - print >>sys.stderr, "testcase" + cp[1].encode('utf-8') - sys.exit(cp[0]) - echo(cmd) - bench = commands.getstatusoutput(" ".join(["ssh", host, path + cmd])) - if bench[0]: - print >>sys.stderr, "testcase" + bench[1].encode('utf-8') - sys.exit(bench[0]) - else: - echo(bench[1]) - run_script_remote(postscript) - dic = {} - for v in bench[1].splitlines()[-1].strip().split(): - s = v.split(":") - dic[s[0]]=s[1] - result.append(dic) - return (apparg, result) - -def benchmark_remote(name, gccarg, repeat, apparg, prescript, postscript): - if gccarg: - realname = get_compile_name(name) - if not compile_single: - compile(realname, gccarg, apparg) - cmd = realname + " " + get_test_arg(apparg) - else: - cmd = name + get_test_arg(apparg) - realname = name - return test_remote(realname, "./" + cmd, repeat, apparg, prescript, postscript) - -def benchmark_local(name, gccarg, repeat, apparg, prescript, postscript): - if gccarg: - realname = get_compile_name(name) - if not compile_single: - compile(realname, gccarg, apparg) - cmd = realname + " " + get_test_arg(apparg) - else: - cmd = name + " " + get_test_arg(apparg) - return test("./" + cmd, repeat, apparg, prescript, postscript) - -benchmark_fun = benchmark_local -def do_case(name, gccarg, repeat, paras, apparg, prescript, postscript): - result = [] - if paras == []: - result.append(benchmark_fun(name, gccarg, [], prescript, postscript)) - elif len(paras)==1: - for p in paras[0][1]: - result.append(benchmark_fun(name, gccarg, repeat, apparg + [(paras[0][0],p)], prescript, postscript)) - else: - for p in paras[0][1]: - p = do_case(name, gccarg, repeat, paras[1:], apparg + [(paras[0][0],p)], prescript, postscript ) - result.extend(p) - return result - -def translate_env(key): - if key in os.environ.keys(): - return os.environ[key] - else: - return "" -def print_result(name, result): - global output_file - if benchmark_fun == benchmark_compile_only\ - or benchmark_fun == benchmark_script: - return - else: - if seperate_output: - # print output_dir + "/" + name+".result" - output_file = open(output_dir + "/" + name+".result", "w+") - for i in result[0][0]: - print >>output_file, i[0], '\t', - for i in result[0][1][0].keys(): - print >>output_file, i, '\t', - print >>output_file - for i, v in result: - for iv in i: - print >>output_file, iv[1], '\t', - for vv in result[0][1][0].keys(): - t = 0. - for pp in v: - t += float(pp[vv]) - print >>output_file, "%.4f" % (t/len(v)), '\t', - print >>output_file -def subtitute_var(var): - while True: - m = matchsubstitution.search(var) - if not m: - break - var = matchsubstitution.sub(translate_env(m.group(1)), var, 1) - return var - -def do_case_env(name, gccarg, repeat, paras, apparg, prescript, postscript): - gccarg = subtitute_var(gccarg) - for p in range(len(paras)): - for v in range(len(paras[p][1])): - m = matchsubstitution.match(paras[p][1][v]) - if m: - paras[p][1][v] = translate_env(key) - global filename - filename = 0 - if compile_single and gccarg and not test_only: - compile(get_compile_name(name), gccarg, []) - result = do_case(name, gccarg ,repeat, paras, apparg, prescript, postscript) - print_result(name, result) - -caselist = [] -ex_caselist = [] -def check_dup_para(paras, para): - for i, v in paras: - if i == para: - print >> sys.stderr, "Error: Duplicate parameter Name", '"'+para+'"' - sys.exit(1) -def parse_case(m): - global benchfile - del benchfile[0] - name = m.group(1) - if m.group(2): - repeat = int(m.group(2)) - else: - repeat = 1 - if len(m.groups()) == 3: - gcc = m.group(3) - else: - gcc = "" - paras = [] - prescript = [] - postscript = [] - while benchfile: - m = matchscript.match(benchfile[0]) - if m: - prescript.append(m.group(1).strip()) - del benchfile[0] - continue - break - while benchfile: - m = matchpara.match(benchfile[0]) - if m: - check_dup_para(paras, m.group(1)) - paras.append(("",benchfile[0][1:].split())) - del benchfile[0] - continue - m = matchpara1.match(benchfile[0]) - if m: - check_dup_para(paras, m.group(1)) - paras.append((m.group(1),m.group(2).split())) - del benchfile[0] - continue - break - while benchfile: - m = matchscript.match(benchfile[0]) - if m: - postscript.append(m.group(1).strip()) - del benchfile[0] - continue - break -# print paras - if not caselist or name in caselist: - do_case_env(name, gcc, repeat, paras, [], prescript, postscript) - if name in caselist: - ex_caselist.remove(name) -def print_version(): - print """Yperfbench, A Performance Benchmark Framework - Version 1.0""" -def print_help(): - print """Usage: bench [option] [testcase] -Options: - -sFILE, --script=FILE Generate benchmark script. - -cFILE Configuration file, default is Benchfile - -dDIR Configuration path, default is conf/ - -C, --compile Compile testcase only. - -T, --test Benchmark testcase only, with previously - compiled test code. - -rHOST, --remote=HOST Run test code remotely with SSH. - --dynamic Testcase is compiled dynamically. - -h, --help Show this help message. - -v, --version Show version inforamtion. - -V, --verbose Provide detailed information while runing test. - --detail Provide each test result if a test is excuted several times. - -fDIR Put each test result into seperate DIR/casename.result file. - --file=FILE Put test result to FILE. - -Report bugs to """ - sys.exit(0) - -def main(): - global test_only, benchfile, benchmark_fun, scriptfile, compile_single, compile_seperate, verbose_mode, output_file, seperate_output, caselist, ex_caselist - global output_dir, remote_host - optlist, caselist = getopt.getopt(sys.argv[1:], "CTs:c:r:hd:f:vV", ['compile','script=', 'test','dynamic','remote','help','detail','file=', 'verbose', 'version']) - ex_caselist = caselist[:] - benchfile_name = "Benchfile" - benchfile_path = "conf/" - for o,v in optlist: - if o == "-s" or o == "--script": - compile_seperate = True - compile_script = True - benchmark_fun = benchmark_script - scriptfile = v - f = open(v, "w+") - f.write("#!/bin/bash\n") - f.close() - elif o == "-c": - benchfile_name = v - elif o == "-d": - if v[-1] == "/": - benchfile_path = v - else: - benchfile_path = v + "/" - elif o == "-C" or o == "--compile": - benchmark_fun = benchmark_compile_only - compile_seperate = True - compile_only = True - elif o == "-T" or o == "--test": - benchmark_fun = benchmark_test_only - compile_seperate = True - test_only = True - elif o == "-r" or o == "--remote": - remote_host = v - benchmark_fun = benchmark_remote - elif o == "--dynamic": - compile_single = False - elif o == "-h" or o == "--help": - print_help() - elif o == "-v" or o == "version": - print_version() - elif o == "-V" or o == "--verbose": - verbose_mode = True - elif o == "-d" or o == "--detail": - pass - elif o == "-f": - seperate_output = True - try: - os.mkdir(v) - except: - pass - output_dir = v - elif o == "--file": - output_file = open(v, "w+") - else: - print >> sys.stderr, "Invalid Argument: ", o - print >> sys.stderr, "To see a complete option list, use \"bench -h\"" - sys.exit(1) - try: - benchfile = open( benchfile_path + benchfile_name).readlines() - except: - print >>sys.stderr, "bench: no Benchfile found" - sys.exit(1) - validate() - ifstack = [True] - while benchfile: - line = benchfile[0].strip() - if(not line): - del benchfile[0] - continue - m = matchif.match(line) - if(m): - c1 = subtitute_var(m.group(1)).strip() - c2 = subtitute_var(m.group(2)).strip() - if c1 == c2: - ifstack.append(True) - else: - ifstack.append(False) - del benchfile[0] - continue; - elif line == "else": - ifstack[-1] = not ifstack[-1] - del benchfile[0] - continue; - elif line == "endif": - ifstack.pop() - del benchfile[0] - continue; - if not ifstack: - print >> sys.stderr, "bench: unmatched if-else-endif" - sys.exit(1); - if not ifstack[-1]: - del benchfile[0] - continue; - else: - m = matchenv.match(line) - if(m): - parse_env(m) - continue - m = matchcase.match(line) - if(m): - parse_case(m) - continue - m = matchcase1.match(line) - if(m): - parse_case(m) - continue - print >>sys.stderr, "bench: ill-formated Benchfile:" - print >>sys.stderr, line - sys.exit(1) - if ex_caselist: - print >> sys.stderr, "bench: Error, case not found:", " ".join(caselist) - -if __name__ == "__main__": - main() diff --git a/bsl/yperfbench/conf/Benchfile b/bsl/yperfbench/conf/Benchfile deleted file mode 100644 index 2d51b9293f29c928725ecacc1d0fca71211ac7d3..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/conf/Benchfile +++ /dev/null @@ -1,24 +0,0 @@ -CFLAGS=-O -Iinclude -I../ -I../../../ -g -LDFLAGS=-lpthread -lyperfbench -Llib -if host friday -CC=g++ -else -CC=/usr/bin/g++ -endif -#lsdjflskjfdlskj -case1 3: src/test.cpp $(CFLAGS) $(LDFLAGS) $(DD) - !touch tmp - para = 1 2 3 - para1:1 2 3 - #sdfjksdlfk - p=2 3 4 - !rm tmp - -#case2 3: src/test.cpp $(CFLAGS) $(LDFLAGS) $(DD) -# !touch tmp -# para = 1 2 3 -# para1:1 2 3 - #sdfjksdlfk -# p=2 3 4 -# !rm tmp -#slkdjflskdjfslkdfjslkdjflskdjfslkdfj diff --git a/bsl/yperfbench/demo/test.cpp b/bsl/yperfbench/demo/test.cpp deleted file mode 100644 index ed949712c35e168979f4201ab3cfcf0bc7f582ec..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/demo/test.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include "yperfbench.h" - -int main(int argc, char ** argv) -{ - //printf("12\n"); - pb::init_opt(argc, argv); - //printf("%d\n", pb::getopt("para") + pb::getopt("p")); - pb::timer ti("yufan"); - pb::put_result("sum", pb::getopt("para") + pb::getopt("p")); - printf("sdfishflsifhsldhfslkfh\n"); - ti.check(); - return 0; -} diff --git a/bsl/yperfbench/include/xutils.h b/bsl/yperfbench/include/xutils.h deleted file mode 100644 index 25c72a36087f2ca23184b03351e230bcc152c1b4..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/include/xutils.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: xutils.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file xutils.h - * @author xiaowei(com@baidu.com) - * @date 2008/06/12 23:45:24 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __XUTILS_H_ -#define __XUTILS_H_ -#include -#include - -#define XTIMEDIFF(s, e) ((e.tv_sec-s.tv_sec)*1000+(e.tv_usec-s.tv_usec)/1000) - - -typedef void * thread_fun_t(void *); -struct xthread_t -{ - thread_fun_t * fun; - void * param; - int pnum; -}; - -int run_thread(void *(*fun)(void *), void *, int); -int run_thread(xthread_t *ptr, int size); - -class Slotime -{ -public: - pthread_mutex_t lock; - pthread_cond_t cond; - timeval _s, _e; - int pnum; - int inp; -public: - Slotime(int tpnum); - ~Slotime(); - int cost(); - int start(); - int stop(); -}; - -void xrecord(const char *fn, const char *fmt, ...); - - - - - - - - -#endif //__XUTILS_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/yperfbench/include/yperfbench.h b/bsl/yperfbench/include/yperfbench.h deleted file mode 100644 index 01f69e55d5edbfc99594cc05972bdf4e93ac2713..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/include/yperfbench.h +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: yperfbench.h,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file yperfbench.h - * @author yufan(com@baidu.com) - * @date 2008/07/30 17:15:22 - * @version $Revision: 1.1 $ - * @brief - * - **/ - - -#ifndef __YPERFBENCH_H_ -#define __YPERFBENCH_H_ -#include -#include -#include -#include - -#define __YPERFPENCH_NAME_LENGTH 64 -#define __YPERFPENCH_VALUE_LENGTH 64 - -namespace pb -{ - -struct output -{ - char name[__YPERFPENCH_NAME_LENGTH]; - char value[__YPERFPENCH_VALUE_LENGTH]; -}; - -extern int argc; -extern char ** argv; - - -void init_opt(int _argc, char ** _argv); -void print_result(); - - -template -T getopt(char * arg) -{ - for(int i=1; i -#include -class timer -{ - timeval start; - char name[__YPERFPENCH_NAME_LENGTH]; -public: - timer(); - timer(char * name); - void check(); -}; - - -struct threading -{ - pthread_t *threads; - int num; -}; - -threading create_threads(void *(void*), int num); -void wait_threads(threading t); -void run_threads(void *fun(void*), int num); -} - - - - - - - - - - -#endif //__YPERFBENCH_H_ - -/* vim: set ts=4 sw=4 sts=4 tw=100 */ diff --git a/bsl/yperfbench/lib/Makefile b/bsl/yperfbench/lib/Makefile deleted file mode 100644 index 9ae0834ffbe1ec18a415ed8e2f6fa50574a8b6c4..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/lib/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -CC=g++ -WORKROOT=../../ - -INCLUDES=-I../include -CFLAGS = -fsigned-char -Wall -W -pipe -Wno-unused-parameter -g -LDFLAGS= -lpthread -lm -OBJS=yperfbench.o xutils.o -TARGET= -LIB=libyperfbench.a -all : $(TARGET) $(LIB) - -%.o : %.cpp - $(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES) - -$(TARGET) : $(OBJS) - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(INCLUDES) - -$(LIB) : $(OBJS) - rm -f $@ - ar cr $@ $(OBJS) - -tags : - ctags -R * - -clean: - rm -f $(OBJS) $(TARGET) $(LIB) - - diff --git a/bsl/yperfbench/lib/xutils.cpp b/bsl/yperfbench/lib/xutils.cpp deleted file mode 100644 index f1e1220719063cdcbccf95fc15379ffdeb8a22ea..0000000000000000000000000000000000000000 --- a/bsl/yperfbench/lib/xutils.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * - * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved - * $Id: xutils.cpp,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ - * - **************************************************************************/ - - - -/** - * @file xutils.cpp - * @author xiaowei(com@baidu.com) - * @date 2008/06/12 23:45:39 - * @version $Revision: 1.1 $ - * @brief - * - **/ - -#include -#include -#include - -int run_thread(void *(*fun)(void *), void *p, int pnum) -{ - pthread_t *pid = new pthread_t[pnum]; - for (int i=0; ipnum = tpnum; - _s.tv_sec = 0; - _e.tv_sec = 0; - _s.tv_usec = 0; - _e.tv_usec = 0; - this->inp = 0; - pthread_mutex_init(&lock, NULL); - pthread_cond_init(&cond, NULL); -} -Slotime::~Slotime() { - pthread_mutex_destroy(&lock); - pthread_cond_destroy(&cond); -} -int Slotime::cost() { - return XTIMEDIFF(_s, _e); -} - -int Slotime::start() { - pthread_mutex_lock(&lock); - ++inp; - if (inp == pnum) { - for (int i=1; i -#include -#include -#include - -#include "yperfbench.h" -namespace pb -{ - -int argc; -char ** argv; - -int output_counter=0; -output outputs[40]; -pthread_mutex_t perfmutex = PTHREAD_MUTEX_INITIALIZER; -void print_result() -{ - for(int i=0; i -#include -timer::timer(char * _name) -{ - strncpy(name, _name, sizeof(name)-1); - name[sizeof(name)-1]=0; - gettimeofday(&start, NULL); -} -timer::timer() -{ - strcpy(name, "timer"); - gettimeofday(&start, NULL); -} -void timer::check() -{ - timeval end; - gettimeofday(&end, NULL); - put_result(name, 1000 * (end.tv_sec - start.tv_sec) + 0.001 * (end.tv_usec -start.tv_usec)); -} - - -void run_threads(void *fun(void*), int num) -{ - if(num == 1) - { - fun(0); - return; - } - pthread_t *threads = (pthread_t*) calloc(num, sizeof(threads)); - for(int i=0; i #include #include -#include // for bsl::mempool -#include #include #include @@ -224,7 +222,6 @@ public: } char const* debug_str() const { - _debug_str.clear(); uint32_t alloc_blocks = _free_blocks.allocate_blocks(); uint32_t free_blocks = _free_blocks.free_blocks(); uint32_t used_mem_mb = _free_blocks.real_used_size(); @@ -233,11 +230,13 @@ public: uint32_t mlc_mem_size = _mlc_mem_size.load(butil::memory_order_relaxed); uint32_t mlc_mem_count = _mlc_mem_count.load(butil::memory_order_relaxed); - _debug_str.appendf("[alloc_blks:%u,free_blks:%u,used_mem_kb:%u," - "big_mem_kb:%u,big_buf_cnt:%u,mlc_mem_kb:%u,mlc_cnt:%u]", - alloc_blocks, free_blocks, used_mem_mb, big_buf_size >> 10, - big_buf_count, mlc_mem_size >> 10, mlc_mem_count); - return _debug_str.c_str(); + std::ostringstream oss; + oss << "[alloc_blks:" << alloc_blocks << ",free_blks:" << free_blocks + << ",used_mem_kb:" << used_mem_mb << ",big_mem_kb:" << (big_buf_size >> 10) + << ",big_buf_cnt:" << big_buf_count << ",mlc_mem_kb:" << (mlc_mem_size >> 10) + << ",mlc_cnt:" << mlc_mem_count << "]"; + + return oss.str().c_str(); } Region(); @@ -269,8 +268,6 @@ private: butil::atomic _mlc_mem_size; butil::atomic _mlc_mem_count; - - bsl::string mutable _debug_str; }; } @@ -396,8 +393,14 @@ private: }; extern __thread Mempool* g_mempool; +class mempool { +public: + virtual void * malloc (size_t size) = 0; + virtual void free (void *p, size_t size) = 0; + inline virtual ~mempool(){} +}; -class GlobalMempool : public bsl::mempool { +class GlobalMempool : public mempool { public: GlobalMempool() { // do nothing; diff --git a/predictor/CMakeLists.txt b/predictor/CMakeLists.txt index 4214fb7e3ad8ae6c406dd040a35b8bee2e8c8c4c..b45b570cfaa4ac6fb80030f17e54effa949ce1b7 100644 --- a/predictor/CMakeLists.txt +++ b/predictor/CMakeLists.txt @@ -36,7 +36,7 @@ set_source_files_properties( PROPERTIES COMPILE_FLAGS "-Wno-strict-aliasing -Wno-unused-variable -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor") add_dependencies(pdserving_exe - protobuf boost brpc leveldb pdcodegen configure bsl + protobuf boost brpc leveldb pdcodegen configure ullib mempool) target_include_directories(pdserving_exe PUBLIC @@ -46,7 +46,7 @@ target_include_directories(pdserving_exe PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../configure/include ${CMAKE_CURRENT_LIST_DIR}/../mempool ${CMAKE_CURRENT_LIST_DIR}/../ullib/include) -target_link_libraries(pdserving_exe brpc protobuf leveldb bsl +target_link_libraries(pdserving_exe brpc protobuf leveldb configure ullib mempool -lpthread -lcrypto -lm -lrt -lssl -ldl -lz) diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index d799f9981acc0fdd12de3210456c36f17168e6e0..afc17e01038ceab5e460db8a84df39c909d77339 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -8,7 +8,6 @@ target_include_directories(sdk-cpp PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/../configure ${CMAKE_CURRENT_LIST_DIR}/../configure/include ${CMAKE_CURRENT_LIST_DIR}/../ullib/include - ${CMAKE_CURRENT_BINARY_DIR}/../bsl/include ) target_link_libraries(sdk-cpp brpc configure protobuf leveldb) @@ -18,8 +17,7 @@ target_include_directories(ximage PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../configure ${CMAKE_CURRENT_LIST_DIR}/../configure/include - ${CMAKE_CURRENT_LIST_DIR}/../ullib/include - ${CMAKE_CURRENT_BINARY_DIR}/../bsl/include) + ${CMAKE_CURRENT_LIST_DIR}/../ullib/include) target_link_libraries(ximage sdk-cpp -lpthread -lcrypto -lm -lrt -lssl -ldl -lz) @@ -29,8 +27,7 @@ target_include_directories(mapcnn_dense PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_CURRENT_BINARY_DIR}/../configure ${CMAKE_CURRENT_LIST_DIR}/../configure/include - ${CMAKE_CURRENT_LIST_DIR}/../ullib/include - ${CMAKE_CURRENT_BINARY_DIR}/../bsl/include) + ${CMAKE_CURRENT_LIST_DIR}/../ullib/include) target_link_libraries(mapcnn_dense sdk-cpp -lpthread -lcrypto -lm -lrt -lssl -ldl -lz) @@ -40,8 +37,7 @@ target_include_directories(mapcnn_sparse PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_CURRENT_BINARY_DIR}/../configure ${CMAKE_CURRENT_LIST_DIR}/../configure/include - ${CMAKE_CURRENT_LIST_DIR}/../ullib/include - ${CMAKE_CURRENT_BINARY_DIR}/../bsl/include) + ${CMAKE_CURRENT_LIST_DIR}/../ullib/include) target_link_libraries(mapcnn_sparse sdk-cpp -lpthread -lcrypto -lm -lrt -lssl -ldl -lz)