x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
test.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\iostreams\filter\test.hpp
旋转
特效
属性
历史版本
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) // (C) Copyright 2005-2007 Jonathan Turkanis // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) // See http://www.boost.org/libs/iostreams for documentation. #ifndef BOOST_IOSTREAMS_FILTER_TEST_HPP_INCLUDED #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include
// BOOST_MSVC,put size_t in std. #include
#include
// min. #include
// size_t. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || \ BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) || \ BOOST_WORKAROUND(__MWERKS__, <= 0x3003) \ /**/ # include
// rand. #endif #include
// memcpy, strlen. #include
#include
#include
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \ !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \ !BOOST_WORKAROUND(__MWERKS__, <= 0x3003) \ /**/ # include
# include
#endif #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#undef memcpy #undef rand #undef strlen #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__LIBCOMO__) namespace std { using ::memcpy; using ::strlen; #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || \ BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) || \ BOOST_WORKAROUND(__MWERKS__, <= 0x3003) \ /**/ using ::rand; #endif } #endif namespace boost { namespace iostreams { BOOST_IOSTREAMS_BOOL_TRAIT_DEF(is_string, std::basic_string, 3) const std::streamsize default_increment = 5; #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \ !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \ !BOOST_WORKAROUND(__MWERKS__, <= 0x3003) \ /**/ std::streamsize rand(int inc) { static rand48 random_gen; static uniform_smallint
random_dist(0, inc); return random_dist(random_gen); } #else std::streamsize rand(int inc) { return (std::rand() * inc + 1) / RAND_MAX; } #endif class non_blocking_source { public: typedef char char_type; struct category : source_tag, peekable_tag { }; explicit non_blocking_source( const std::string& data, std::streamsize inc = default_increment ) : data_(data), inc_(inc), pos_(0) { } std::streamsize read(char* s, std::streamsize n) { if (pos_ == static_cast
(data_.size())) return -1; std::streamsize avail = (std::min) (n, static_cast
(data_.size() - pos_)); std::streamsize amt = (std::min) (rand(inc_), avail); if (amt) std::memcpy(s, data_.c_str() + pos_, amt); pos_ += amt; return amt; } bool putback(char c) { if (pos_ > 0) { data_[--pos_] = c; return true; } return false; } private: std::string data_; std::streamsize inc_, pos_; }; class non_blocking_sink : public sink { public: non_blocking_sink( std::string& dest, std::streamsize inc = default_increment ) : dest_(dest), inc_(inc) { } std::streamsize write(const char* s, std::streamsize n) { std::streamsize amt = (std::min) (rand(inc_), n); dest_.insert(dest_.end(), s, s + amt); return amt; } private: non_blocking_sink& operator=(const non_blocking_sink&); std::string& dest_; std::streamsize inc_; }; //--------------Definition of test_input_filter-------------------------------// template
bool test_input_filter( Filter filter, const std::string& input, const std::string& output, mpl::true_ ) { for ( int inc = default_increment; inc < default_increment * 40; inc += default_increment ) { non_blocking_source src(input, inc); std::string dest; iostreams::copy(compose(filter, src), iostreams::back_inserter(dest)); if (dest != output) return false; } return true; } template
bool test_input_filter( Filter filter, const Source1& input, const Source2& output, mpl::false_ ) { std::string in; std::string out; iostreams::copy(input, iostreams::back_inserter(in)); iostreams::copy(output, iostreams::back_inserter(out)); return test_input_filter(filter, in, out); } template
bool test_input_filter( Filter filter, const Source1& input, const Source2& output ) { // Use tag dispatch to compensate for bad overload resolution. return test_input_filter( filter, input, output, is_string
() ); } //--------------Definition of test_output_filter------------------------------// template
bool test_output_filter( Filter filter, const std::string& input, const std::string& output, mpl::true_ ) { for ( int inc = default_increment; inc < default_increment * 40; inc += default_increment ) { array_source src(input.data(), input.data() + input.size()); std::string dest; iostreams::copy(src, compose(filter, non_blocking_sink(dest, inc))); if (dest != output ) return false; } return true; } template
bool test_output_filter( Filter filter, const Source1& input, const Source2& output, mpl::false_ ) { std::string in; std::string out; iostreams::copy(input, iostreams::back_inserter(in)); iostreams::copy(output, iostreams::back_inserter(out)); return test_output_filter(filter, in, out); } template
bool test_output_filter( Filter filter, const Source1& input, const Source2& output ) { // Use tag dispatch to compensate for bad overload resolution. return test_output_filter( filter, input, output, is_string
() ); } //--------------Definition of test_filter_pair--------------------------------// template
bool test_filter_pair( OutputFilter out, InputFilter in, const std::string& data, mpl::true_ ) { for ( int inc = default_increment; inc <= default_increment * 40; inc += default_increment ) { array_source src(data.data(), data.data() + data.size()); std::string temp; std::string dest; iostreams::copy(src, compose(out, non_blocking_sink(temp, inc))); iostreams::copy( compose(in, non_blocking_source(temp, inc)), iostreams::back_inserter(dest) ); if (dest != data) return false; } return true; } template
bool test_filter_pair( OutputFilter out, InputFilter in, const Source& data, mpl::false_ ) { std::string str; iostreams::copy(data, iostreams::back_inserter(str)); return test_filter_pair(out, in, str); } template
bool test_filter_pair( OutputFilter out, InputFilter in, const Source& data ) { // Use tag dispatch to compensate for bad overload resolution. return test_filter_pair(out, in, data, is_string
()); } } } // End namespaces iostreams, boost. #endif // #ifndef BOOST_IOSTREAMS_FILTER_TEST_HPP_INCLUDED
test.hpp
网页地址
文件地址
上一页
10/11
下一页
下载
( 8 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.