source: NonGTP/Boost/boost/iostreams/concepts.hpp @ 857

Revision 857, 4.0 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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// See http://www.boost.org/libs/iostreams for documentation.
6
7#ifndef BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED
8#define BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED
9
10#if defined(_MSC_VER) && (_MSC_VER >= 1020)
11# pragma once
12#endif
13
14#include <boost/config.hpp>  // BOOST_MSVC
15#include <boost/detail/workaround.hpp>
16#include <boost/iostreams/categories.hpp>
17#include <boost/iostreams/detail/default_arg.hpp>
18#include <boost/iostreams/detail/ios.hpp>  // openmode.
19#include <boost/iostreams/positioning.hpp>
20#include <boost/static_assert.hpp>
21#include <boost/type_traits/is_convertible.hpp>
22
23namespace boost { namespace iostreams {
24
25//--------------Definitions of helper templates for device concepts-----------//
26
27template<typename Mode, typename Ch = BOOST_IOSTREAMS_DEFAULT_ARG(char)>
28struct device {
29    typedef Ch char_type;
30    struct category
31        : Mode,
32          device_tag,
33          closable_tag,
34          localizable_tag
35        { };
36
37    void close()
38    {
39        using namespace detail;
40        BOOST_STATIC_ASSERT((!is_convertible<Mode, two_sequence>::value));
41    }
42
43    void close(BOOST_IOS::openmode)
44    {
45        using namespace detail;
46        BOOST_STATIC_ASSERT((is_convertible<Mode, two_sequence>::value));
47    }
48
49    template<typename Locale>
50    void imbue(const Locale&) { }
51};
52
53template<typename Mode, typename Ch = BOOST_IOSTREAMS_DEFAULT_ARG(wchar_t)>
54struct wdevice : device<Mode, Ch> { };
55
56typedef device<input>    source;
57typedef wdevice<input>   wsource;
58typedef device<output>   sink;
59typedef wdevice<output>  wsink;
60
61//--------------Definitions of helper templates for simple filter concepts----//
62
63template<typename Mode, typename Ch = BOOST_IOSTREAMS_DEFAULT_ARG(char)>
64struct filter {
65    typedef Ch char_type;
66    struct category
67        : Mode,
68          filter_tag,
69          closable_tag,
70          localizable_tag
71        { };
72
73    template<typename Device>
74    void close(Device&)
75    {
76        using namespace detail;
77        BOOST_STATIC_ASSERT((!is_convertible<Mode, two_sequence>::value));
78        BOOST_STATIC_ASSERT((!is_convertible<Mode, dual_use>::value));
79    }
80
81    template<typename Device>
82    void close(Device&, BOOST_IOS::openmode)
83    {
84        using namespace detail;
85        BOOST_STATIC_ASSERT(
86            (is_convertible<Mode, two_sequence>::value) ||
87            (is_convertible<Mode, dual_use>::value)
88        );
89    }
90
91    template<typename Locale>
92    void imbue(const Locale&) { }
93};
94
95template<typename Mode, typename Ch = BOOST_IOSTREAMS_DEFAULT_ARG(wchar_t)>
96struct wfilter : filter<Mode, Ch> { };
97
98typedef filter<input>      input_filter;
99typedef wfilter<input>     input_wfilter;
100typedef filter<output>     output_filter;
101typedef wfilter<output>    output_wfilter;
102typedef filter<seekable>   seekable_filter;
103typedef wfilter<seekable>  seekable_wfilter;
104typedef filter<dual_use>   dual_use_filter;
105typedef wfilter<dual_use>  dual_use_wfilter;
106       
107//------Definitions of helper templates for multi-character filter cncepts----//
108
109template<typename Mode, typename Ch = char>
110struct multichar_filter : filter<Mode, Ch> {
111    struct category : filter<Mode, Ch>::category, multichar_tag { };
112};
113
114template<typename Mode, typename Ch = wchar_t>
115struct multichar_wfilter : multichar_filter<Mode, Ch> { };
116
117typedef multichar_filter<input>     multichar_input_filter;
118typedef multichar_filter<input>     multichar_input_wfilter;
119typedef multichar_filter<output>    multichar_output_filter;
120typedef multichar_filter<output>    multichar_output_wfilter;
121typedef multichar_filter<dual_use>  multichar_dual_use_filter;
122typedef multichar_filter<dual_use>  multichar_dual_use_wfilter;
123
124//----------------------------------------------------------------------------//
125
126} } // End namespaces iostreams, boost.
127
128#endif // #ifndef BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.