x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
range_adapter.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\iostreams\detail\adapter\range_adapter.hpp
旋转
特效
属性
历史版本
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) // (C) Copyright 2003-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_DETAIL_RANGE_ADAPTER_HPP_INCLUDED #define BOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include
// min. #include
#include
// ptrdiff_t. #include
// streamsize, streamoff. #include
// boost::iterator_traits. #include
#include
#include
#include
#include
#include
// Must come last. #include
// MSVC. namespace boost { namespace iostreams { namespace detail { // Used for simulated tag dispatch. template
struct range_adapter_impl; // // Template name: range_adapter // Description: Device based on an instance of boost::iterator_range. // Template paramters: // Mode - A mode tag. // Range - An instance of iterator_range. // template
class range_adapter { private: typedef typename Range::iterator iterator; typedef boost::detail::iterator_traits
iter_traits; typedef typename iter_traits::iterator_category iter_cat; public: typedef typename Range::value_type char_type; struct category : Mode, device_tag { }; typedef typename mpl::if_< is_convertible< iter_cat, std::random_access_iterator_tag >, std::random_access_iterator_tag, std::forward_iterator_tag >::type tag; typedef range_adapter_impl
impl; explicit range_adapter(const Range& rng); range_adapter(iterator first, iterator last); std::streamsize read(char_type* s, std::streamsize n); std::streamsize write(const char_type* s, std::streamsize n); std::streampos seek(stream_offset off, BOOST_IOS::seekdir way); private: iterator first_, cur_, last_; }; //------------------Implementation of range_adapter---------------------------// template
range_adapter
::range_adapter(const Range& rng) : first_(rng.begin()), cur_(rng.begin()), last_(rng.end()) { } template
range_adapter
::range_adapter(iterator first, iterator last) : first_(first), cur_(first), last_(last) { } template
inline std::streamsize range_adapter
::read (char_type* s, std::streamsize n) { return impl::read(cur_, last_, s, n); } template
inline std::streamsize range_adapter
::write (const char_type* s, std::streamsize n) { return impl::write(cur_, last_, s, n); } template
std::streampos range_adapter
::seek (stream_offset off, BOOST_IOS::seekdir way) { impl::seek(first_, cur_, last_, off, way); return offset_to_position(cur_ - first_); } //------------------Implementation of range_adapter_impl----------------------// template<> struct range_adapter_impl
{ template
static std::streamsize read (Iter& cur, Iter& last, Ch* s,std::streamsize n) { std::streamsize rem = n; // No. of chars remaining. while (cur != last && rem-- > 0) *s++ = *cur++; return n - rem != 0 ? n - rem : -1; } template
static std::streamsize write (Iter& cur, Iter& last, const Ch* s, std::streamsize n) { while (cur != last && n-- > 0) *cur++ = *s++; if (cur == last && n > 0) throw write_area_exhausted(); return n; } }; template<> struct range_adapter_impl
{ template
static std::streamsize read (Iter& cur, Iter& last, Ch* s,std::streamsize n) { std::streamsize result = (std::min)(static_cast
(last - cur), n); if (result) std::copy(cur, cur + result, s); cur += result; return result != 0 ? result : -1; } template
static std::streamsize write (Iter& cur, Iter& last, const Ch* s, std::streamsize n) { std::streamsize count = (std::min)(static_cast
(last - cur), n); std::copy(s, s + count, cur); cur += count; if (count < n) throw write_area_exhausted(); return n; } template
static void seek ( Iter& first, Iter& cur, Iter& last, stream_offset off, BOOST_IOS::seekdir way ) { using namespace std; switch (way) { case BOOST_IOS::beg: if (off > last - first || off < 0) throw bad_seek(); cur = first + off; break; case BOOST_IOS::cur: { std::ptrdiff_t newoff = cur - first + off; if (newoff > last - first || newoff < 0) throw bad_seek(); cur += off; break; } case BOOST_IOS::end: if (last - first + off < 0 || off > 0) throw bad_seek(); cur = last + off; break; default: assert(0); } } }; } } } // End namespaces detail, iostreams, boost. #include
// MSVC. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED //---------------//
range_adapter.hpp
网页地址
文件地址
上一页
8/8 下一页
下载
( 6 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.