Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-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: // Provides std::char_traits for libraries without templated streams. Should not Chris@16: // be confused with , which defines the Chris@16: // template boost::iostreams::char_traits. Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_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 Chris@16: #include Chris@16: #ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES Chris@16: # include // Make sure size_t is in std. Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------------------// Chris@16: # define BOOST_IOSTREAMS_CHAR_TRAITS(ch) std::char_traits< ch > Chris@16: #else Chris@16: # define BOOST_IOSTREAMS_CHAR_TRAITS(ch) boost::iostreams::detail::char_traits Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: struct char_traits { Chris@16: typedef char char_type; Chris@16: typedef int int_type; Chris@16: typedef std::streampos pos_type; Chris@16: typedef std::streamoff off_type; Chris@16: Chris@16: // Note: this may not be not conforming, since it treats chars as unsigned, Chris@16: // but is only used to test for equality. Chris@16: static int compare(const char* lhs, const char* rhs, std::size_t n) Chris@16: { return std::strncmp(lhs, rhs, n); } Chris@16: static char* copy(char *dest, const char *src, std::size_t n) Chris@16: { return static_cast(std::memcpy(dest, src, n)); } Chris@16: static char* move(char *dest, const char *src, std::size_t n) Chris@16: { return static_cast(std::memmove(dest, src, n)); } Chris@16: static const char* find(const char* s, std::size_t n, const char& c) Chris@16: { return (const char*) (const void*) std::memchr(s, c, n); } Chris@16: static char to_char_type(const int& c) { return c; } Chris@16: static int to_int_type(const char& c) { return c; } Chris@16: static bool eq_int_type(const int& lhs, const int& rhs) Chris@16: { return lhs == rhs; } Chris@16: static int eof() { return EOF; } Chris@16: static int not_eof(const int& c) { return c != EOF ? c : '\n'; } Chris@16: }; Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-----------------------// Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_HPP_INCLUDED