PageRenderTime 43ms CodeModel.GetById 9ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/iostreams/detail/adapter/mode_adapter.hpp

http://hadesmem.googlecode.com/
C++ Header | 123 lines | 87 code | 25 blank | 11 comment | 1 complexity | 25eb392b8f1bacf5fe741ba585c13d40 MD5 | raw file
  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.)
  5
  6// See http://www.boost.org/libs/iostreams for documentation.
  7
  8#ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
  9#define BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
 10
 11#if defined(_MSC_VER) && (_MSC_VER >= 1020)
 12# pragma once
 13#endif              
 14
 15// Contains the definition of the class template mode_adapter, which allows
 16// a filter or device to function as if it has a different i/o mode than that
 17// deduced by the metafunction mode_of.
 18
 19#include <boost/config.hpp>                // BOOST_MSVC.
 20#include <boost/detail/workaround.hpp>
 21#include <boost/iostreams/categories.hpp>
 22#include <boost/iostreams/detail/ios.hpp>  // openmode, seekdir, int types. 
 23#include <boost/iostreams/traits.hpp>
 24#include <boost/iostreams/operations.hpp> 
 25#include <boost/mpl/if.hpp> 
 26
 27namespace boost { namespace iostreams { namespace detail {
 28
 29template<typename Mode, typename T>
 30class mode_adapter {
 31private:
 32    struct empty_base { };
 33public:
 34    typedef typename wrapped_type<T>::type  component_type;
 35    typedef typename char_type_of<T>::type  char_type;
 36    struct category 
 37        : Mode, 
 38          device_tag,
 39          mpl::if_<is_filter<T>, filter_tag, device_tag>,
 40          mpl::if_<is_filter<T>, multichar_tag, empty_base>,
 41          #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
 42              closable_tag, // VC6 can't see member close()!
 43          #endif
 44          localizable_tag
 45        { };
 46    explicit mode_adapter(const component_type& t) : t_(t) { }
 47
 48        // Device member functions.
 49
 50    std::streamsize read(char_type* s, std::streamsize n);
 51    std::streamsize write(const char_type* s, std::streamsize n);
 52    std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
 53                         BOOST_IOS::openmode which = 
 54                             BOOST_IOS::in | BOOST_IOS::out );
 55#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
 56    void close();
 57    void close(BOOST_IOS::openmode which);
 58#endif
 59
 60        // Filter member functions.
 61
 62    template<typename Source>
 63    std::streamsize read(Source& src, char_type* s, std::streamsize n)
 64    { return iostreams::read(t_, src, s, n); }
 65
 66    template<typename Sink>
 67    std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
 68    { return iostreams::write(t_, snk, s, n); }
 69
 70    template<typename Device>
 71    std::streampos seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way)
 72    { return iostreams::seek(t_, dev, off, way); }
 73
 74    template<typename Device>
 75    std::streampos seek( Device& dev, stream_offset off, 
 76                         BOOST_IOS::seekdir way, BOOST_IOS::openmode which  )
 77    { return iostreams::seek(t_, dev, off, way, which); }
 78
 79    template<typename Device>
 80    void close(Device& dev)
 81    { detail::close_all(t_, dev); }
 82
 83    template<typename Device>
 84    void close(Device& dev, BOOST_IOS::openmode which)
 85    { iostreams::close(t_, dev, which); }
 86
 87    template<typename Locale>
 88    void imbue(const Locale& loc)
 89    { iostreams::imbue(t_, loc); }
 90private:
 91    component_type t_;
 92};
 93                    
 94//------------------Implementation of mode_adapter----------------------------//
 95
 96template<typename Mode, typename T>
 97std::streamsize mode_adapter<Mode, T>::read
 98    (char_type* s, std::streamsize n)
 99{ return boost::iostreams::read(t_, s, n); }
100
101template<typename Mode, typename T>
102std::streamsize mode_adapter<Mode, T>::write
103    (const char_type* s, std::streamsize n)
104{ return boost::iostreams::write(t_, s, n); }
105
106template<typename Mode, typename T>
107std::streampos mode_adapter<Mode, T>::seek
108    (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
109{ return boost::iostreams::seek(t_, off, way, which); }
110
111#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
112    template<typename Mode, typename T>
113    void mode_adapter<Mode, T>::close() 
114    { detail::close_all(t_); }
115
116    template<typename Mode, typename T>
117    void mode_adapter<Mode, T>::close(BOOST_IOS::openmode which) 
118    { iostreams::close(t_, which); }
119#endif
120
121} } } // End namespaces detail, iostreams, boost.
122
123#endif // #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//