1 | // (C) Copyright Jonathan Turkanis 2003. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
---|
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
---|
4 | |
---|
5 | // Provides std::char_traits for libraries without templated streams. Should not |
---|
6 | // be confused with <boost/iostreams/char_traits.hpp>, which defines the |
---|
7 | // template boost::iostreams::char_traits. |
---|
8 | |
---|
9 | // See http://www.boost.org/libs/iostreams for documentation. |
---|
10 | |
---|
11 | #ifndef BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_HPP_INCLUDED |
---|
12 | #define BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_HPP_INCLUDED |
---|
13 | |
---|
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
15 | # pragma once |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <iosfwd> |
---|
19 | #include <boost/iostreams/detail/config/wide_streams.hpp> |
---|
20 | #ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES |
---|
21 | # include <boost/config.hpp> // Make sure size_t is in std. |
---|
22 | # include <cstddef> |
---|
23 | # include <cstring> |
---|
24 | # include <cstdio> |
---|
25 | #endif |
---|
26 | |
---|
27 | #ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------------------// |
---|
28 | # define BOOST_IOSTREAMS_CHAR_TRAITS(ch) std::char_traits< ch > |
---|
29 | #else |
---|
30 | # define BOOST_IOSTREAMS_CHAR_TRAITS(ch) boost::iostreams::detail::char_traits |
---|
31 | |
---|
32 | namespace boost { namespace iostreams { namespace detail { |
---|
33 | |
---|
34 | struct char_traits { |
---|
35 | typedef char char_type; |
---|
36 | typedef int int_type; |
---|
37 | typedef std::streampos pos_type; |
---|
38 | typedef std::streamoff off_type; |
---|
39 | |
---|
40 | // Note: this may not be not conforming, since it treats chars as unsigned, |
---|
41 | // but is only used to test for equality. |
---|
42 | static int compare(const char* lhs, const char* rhs, std::size_t n) |
---|
43 | { return std::strncmp(lhs, rhs, n); } |
---|
44 | static char* copy(char *dest, const char *src, std::size_t n) |
---|
45 | { return static_cast<char*>(std::memcpy(dest, src, n)); } |
---|
46 | static char* move(char *dest, const char *src, std::size_t n) |
---|
47 | { return static_cast<char*>(std::memmove(dest, src, n)); } |
---|
48 | static const char* find(const char* s, std::size_t n, const char& c) |
---|
49 | { return (const char*) (const void*) std::memchr(s, c, n); } |
---|
50 | static char to_char_type(const int& c) { return c; } |
---|
51 | static int to_int_type(const char& c) { return c; } |
---|
52 | static bool eq_int_type(const int& lhs, const int& rhs) |
---|
53 | { return lhs == rhs; } |
---|
54 | static int eof() { return EOF; } |
---|
55 | static int not_eof(const int& c) { return c != EOF ? c : '\n'; } |
---|
56 | }; |
---|
57 | |
---|
58 | } } } // End namespaces detail, iostreams, boost. |
---|
59 | |
---|
60 | #endif // #ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-----------------------// |
---|
61 | |
---|
62 | #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CHAR_TRAITS_HPP_INCLUDED |
---|