source: NonGTP/Boost/boost/iostreams/detail/access_control.hpp @ 857

Revision 857, 2.9 KB checked in by igarcia, 18 years ago (diff)
Line 
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// Contains the definition of the class template access_control, which
8// allows the type of inheritance from a provided base class to be specified
9// using a template parameter.
10
11
12#ifndef BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED
13#define BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED
14
15#if defined(_MSC_VER) && (_MSC_VER >= 1020)
16# pragma once
17#endif             
18
19#include <boost/iostreams/detail/select.hpp>
20#include <boost/mpl/identity.hpp>
21#include <boost/type_traits/is_same.hpp>
22
23namespace boost { namespace iostreams {
24
25struct protected_ { };  // Represents protected inheritance.
26struct public_ { };     // Represents public inheritance.
27
28
29namespace detail {
30
31    // Implements protected inheritance.
32    template<typename U>
33    struct prot_ : protected U
34    {
35        prot_() { }
36        template<typename V> prot_(V v) : U(v) { }
37    };
38
39    // Implements public inheritance.
40    template<typename U> struct pub_ : public U {
41        pub_() { }
42        template<typename V> pub_(V v) : U(v) { }
43    };
44
45//
46// Used to deduce the base type for the template access_control.
47//
48template<typename T, typename Access>
49struct access_control_base {
50    typedef int                                 bad_access_specifier;
51    typedef typename
52            iostreams::select<  // Disambiguation for Tru64
53                ::boost::is_same<
54                    Access, protected_
55                >,                              prot_<T>,
56                ::boost::is_same<
57                    Access, public_
58                >,                              pub_<T>,
59                else_,                          bad_access_specifier
60            >::type                             type;
61};
62
63} // End namespace detail.
64
65//
66// Template name: access_control.
67// Description: Allows the type of inheritance from a provided base class
68//      to be specified using an int template parameter.
69// Template parameters:
70//      Base - The class from which to inherit (indirectly.)
71//      Access - The type of access desired. Must be one of the
72//          values access_base::prot or access_base::pub.
73//
74template< typename T, typename Access,
75          typename Base = // VC6 workaraound (Compiler Error C2516)
76              typename detail::access_control_base<T, Access>::type >
77struct access_control : public Base {
78    access_control() { }
79    template<typename U> explicit access_control(U u) : Base(u) { }
80};
81
82//----------------------------------------------------------------------------//
83
84} } // End namespaces iostreams, boost.
85
86#endif // #ifndef BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.