Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2004-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // BOOST_MSVC, make sure size_t is in std. Chris@16: #include Chris@16: #include // std::size_t. Chris@16: #include // pair. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: class array_adapter { Chris@16: public: Chris@16: typedef Ch char_type; Chris@16: typedef std::pair pair_type; Chris@16: struct category Chris@16: : public Mode, Chris@16: public device_tag, Chris@16: public direct_tag Chris@16: { }; Chris@16: array_adapter(char_type* begin, char_type* end); Chris@16: array_adapter(char_type* begin, std::size_t length); Chris@16: array_adapter(const char_type* begin, const char_type* end); Chris@16: array_adapter(const char_type* begin, std::size_t length); Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) Chris@16: template Chris@16: array_adapter(char_type (&ar)[N]) Chris@16: : begin_(ar), end_(ar + N) Chris@16: { } Chris@16: #endif Chris@16: pair_type input_sequence(); Chris@16: pair_type output_sequence(); Chris@16: private: Chris@16: char_type* begin_; Chris@16: char_type* end_; Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: // Local macros, #undef'd below. Chris@16: #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) Chris@16: # define BOOST_IOSTREAMS_ARRAY_CTOR(name, ch) \ Chris@16: template \ Chris@16: BOOST_PP_CAT(basic_, name)(ch (&ar)[N]) \ Chris@16: : base_type(ar) { } \ Chris@16: /**/ Chris@16: #else Chris@16: # define BOOST_IOSTREAMS_ARRAY_CTOR(name, ch) Chris@16: #endif Chris@16: #define BOOST_IOSTREAMS_ARRAY(name, mode) \ Chris@16: template \ Chris@16: struct BOOST_PP_CAT(basic_, name) : detail::array_adapter { \ Chris@16: private: \ Chris@16: typedef detail::array_adapter base_type; \ Chris@16: public: \ Chris@16: typedef typename base_type::char_type char_type; \ Chris@16: typedef typename base_type::category category; \ Chris@16: BOOST_PP_CAT(basic_, name)(char_type* begin, char_type* end) \ Chris@16: : base_type(begin, end) { } \ Chris@16: BOOST_PP_CAT(basic_, name)(char_type* begin, std::size_t length) \ Chris@16: : base_type(begin, length) { } \ Chris@16: BOOST_PP_CAT(basic_, name)(const char_type* begin, const char_type* end) \ Chris@16: : base_type(begin, end) { } \ Chris@16: BOOST_PP_CAT(basic_, name)(const char_type* begin, std::size_t length) \ Chris@16: : base_type(begin, length) { } \ Chris@16: BOOST_IOSTREAMS_ARRAY_CTOR(name, Ch) \ Chris@16: }; \ Chris@16: typedef BOOST_PP_CAT(basic_, name) name; \ Chris@16: typedef BOOST_PP_CAT(basic_, name) BOOST_PP_CAT(w, name); \ Chris@16: /**/ Chris@16: BOOST_IOSTREAMS_ARRAY(array_source, input_seekable) Chris@16: BOOST_IOSTREAMS_ARRAY(array_sink, output_seekable) Chris@16: BOOST_IOSTREAMS_ARRAY(array, seekable) Chris@16: #undef BOOST_IOSTREAMS_ARRAY_CTOR Chris@16: #undef BOOST_IOSTREAMS_ARRAY Chris@16: Chris@16: Chris@16: //------------------Implementation of array_adapter---------------------------// Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: array_adapter::array_adapter Chris@16: (char_type* begin, char_type* end) Chris@16: : begin_(begin), end_(end) Chris@16: { } Chris@16: Chris@16: template Chris@16: array_adapter::array_adapter Chris@16: (char_type* begin, std::size_t length) Chris@16: : begin_(begin), end_(begin + length) Chris@16: { } Chris@16: Chris@16: template Chris@16: array_adapter::array_adapter Chris@16: (const char_type* begin, const char_type* end) Chris@16: : begin_(const_cast(begin)), // Treated as read-only. Chris@16: end_(const_cast(end)) // Treated as read-only. Chris@16: { BOOST_STATIC_ASSERT((!is_convertible::value)); } Chris@16: Chris@16: template Chris@16: array_adapter::array_adapter Chris@16: (const char_type* begin, std::size_t length) Chris@16: : begin_(const_cast(begin)), // Treated as read-only. Chris@16: end_(const_cast(begin) + length) // Treated as read-only. Chris@16: { BOOST_STATIC_ASSERT((!is_convertible::value)); } Chris@16: Chris@16: template Chris@16: typename array_adapter::pair_type Chris@16: array_adapter::input_sequence() Chris@16: { BOOST_STATIC_ASSERT((is_convertible::value)); Chris@16: return pair_type(begin_, end_); } Chris@16: Chris@16: template Chris@16: typename array_adapter::pair_type Chris@16: array_adapter::output_sequence() Chris@16: { BOOST_STATIC_ASSERT((is_convertible::value)); Chris@16: return pair_type(begin_, end_); } Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: //----------------------------------------------------------------------------// Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED