1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_SEEK_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_SEEK_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
15 #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
16 #include <boost/integer_traits.hpp>
17 #include <boost/iostreams/categories.hpp>
18 #include <boost/iostreams/detail/dispatch.hpp>
19 #include <boost/iostreams/detail/ios.hpp> // streamsize, seekdir, openmode.
20 #include <boost/iostreams/detail/streambuf.hpp>
21 #include <boost/iostreams/detail/wrap_unwrap.hpp>
22 #include <boost/iostreams/operations_fwd.hpp>
23 #include <boost/iostreams/positioning.hpp>
24 #include <boost/mpl/if.hpp>
27 #include <boost/iostreams/detail/config/disable_warnings.hpp>
29 namespace boost
{ namespace iostreams
{
34 struct seek_device_impl
;
37 struct seek_filter_impl
;
39 } // End namespace detail.
43 seek( T
& t
, stream_offset off
, BOOST_IOS::seekdir way
,
44 BOOST_IOS::openmode which
= BOOST_IOS::in
| BOOST_IOS::out
)
46 using namespace detail
;
47 return seek_device_impl
<T
>::seek(detail::unwrap(t
), off
, way
, which
);
50 template<typename T
, typename Device
>
52 seek( T
& t
, Device
& dev
, stream_offset off
, BOOST_IOS::seekdir way
,
53 BOOST_IOS::openmode which
= BOOST_IOS::in
| BOOST_IOS::out
)
55 using namespace detail
;
56 return seek_filter_impl
<T
>::seek(detail::unwrap(t
), dev
, off
, way
, which
);
61 //------------------Definition of seek_device_impl----------------------------//
64 struct seek_device_impl
69 BOOST_DEDUCED_TYPENAME
71 T
, iostream_tag
, istream_tag
, ostream_tag
,
72 streambuf_tag
, two_head
, any_tag
78 struct seek_impl_basic_ios
{
80 static std::streampos
seek( T
& t
, stream_offset off
,
81 BOOST_IOS::seekdir way
,
82 BOOST_IOS::openmode which
)
84 if ( way
== BOOST_IOS::beg
&&
85 ( off
< integer_traits
<std::streamoff
>::const_min
||
86 off
> integer_traits
<std::streamoff
>::const_max
) )
88 return t
.rdbuf()->pubseekpos(offset_to_position(off
));
90 return t
.rdbuf()->pubseekoff(off
, way
, which
);
96 struct seek_device_impl
<iostream_tag
> : seek_impl_basic_ios
{ };
99 struct seek_device_impl
<istream_tag
> : seek_impl_basic_ios
{ };
102 struct seek_device_impl
<ostream_tag
> : seek_impl_basic_ios
{ };
105 struct seek_device_impl
<streambuf_tag
> {
107 static std::streampos
seek( T
& t
, stream_offset off
,
108 BOOST_IOS::seekdir way
,
109 BOOST_IOS::openmode which
)
111 if ( way
== BOOST_IOS::beg
&&
112 ( off
< integer_traits
<std::streamoff
>::const_min
||
113 off
> integer_traits
<std::streamoff
>::const_max
) )
115 return t
.BOOST_IOSTREAMS_PUBSEEKPOS(offset_to_position(off
));
117 return t
.BOOST_IOSTREAMS_PUBSEEKOFF(off
, way
, which
);
123 struct seek_device_impl
<two_head
> {
125 static std::streampos
seek( T
& t
, stream_offset off
,
126 BOOST_IOS::seekdir way
,
127 BOOST_IOS::openmode which
)
128 { return t
.seek(off
, way
, which
); }
132 struct seek_device_impl
<any_tag
> {
134 static std::streampos
seek( T
& t
, stream_offset off
,
135 BOOST_IOS::seekdir way
,
136 BOOST_IOS::openmode
)
137 { return t
.seek(off
, way
); }
140 //------------------Definition of seek_filter_impl----------------------------//
143 struct seek_filter_impl
148 BOOST_DEDUCED_TYPENAME
149 dispatch
<T
, two_head
, any_tag
>::type
155 struct seek_filter_impl
<two_head
> {
156 template<typename T
, typename Device
>
157 static std::streampos
seek( T
& t
, Device
& d
,
159 BOOST_IOS::seekdir way
,
160 BOOST_IOS::openmode which
)
161 { return t
.seek(d
, off
, way
, which
); }
165 struct seek_filter_impl
<any_tag
> {
166 template<typename T
, typename Device
>
167 static std::streampos
seek( T
& t
, Device
& d
,
169 BOOST_IOS::seekdir way
,
170 BOOST_IOS::openmode
)
171 { return t
.seek(d
, off
, way
); }
174 } // End namespace detail.
176 } } // End namespaces iostreams, boost.
178 #include <boost/iostreams/detail/config/enable_warnings.hpp>
180 #endif // #ifndef BOOST_IOSTREAMS_SEEK_HPP_INCLUDED