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