Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame^] | 1 | // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) |
| 2 | // (C) Copyright 2003-2007 Jonathan Turkanis |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
| 5 | |
| 6 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | // Contains the definition of the class template access_control, which |
| 9 | // allows the type of inheritance from a provided base class to be specified |
| 10 | // using a template parameter. |
| 11 | |
| 12 | |
| 13 | #ifndef NDNBOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED |
| 14 | #define NDNBOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED |
| 15 | |
| 16 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 17 | # pragma once |
| 18 | #endif |
| 19 | |
| 20 | #include <ndnboost/iostreams/detail/select.hpp> |
| 21 | #include <ndnboost/mpl/identity.hpp> |
| 22 | #include <ndnboost/type_traits/is_same.hpp> |
| 23 | |
| 24 | namespace ndnboost { namespace iostreams { |
| 25 | |
| 26 | struct protected_ { }; // Represents protected inheritance. |
| 27 | struct public_ { }; // Represents public inheritance. |
| 28 | |
| 29 | |
| 30 | namespace detail { |
| 31 | |
| 32 | // Implements protected inheritance. |
| 33 | template<typename U> |
| 34 | struct prot_ : protected U |
| 35 | { |
| 36 | prot_() { } |
| 37 | template<typename V> prot_(V v) : U(v) { } |
| 38 | }; |
| 39 | |
| 40 | // Implements public inheritance. |
| 41 | template<typename U> struct pub_ : public U { |
| 42 | pub_() { } |
| 43 | template<typename V> pub_(V v) : U(v) { } |
| 44 | }; |
| 45 | |
| 46 | // |
| 47 | // Used to deduce the base type for the template access_control. |
| 48 | // |
| 49 | template<typename T, typename Access> |
| 50 | struct access_control_base { |
| 51 | typedef int bad_access_specifier; |
| 52 | typedef typename |
| 53 | iostreams::select< // Disambiguation for Tru64 |
| 54 | ::ndnboost::is_same< |
| 55 | Access, protected_ |
| 56 | >, prot_<T>, |
| 57 | ::ndnboost::is_same< |
| 58 | Access, public_ |
| 59 | >, pub_<T>, |
| 60 | else_, bad_access_specifier |
| 61 | >::type type; |
| 62 | }; |
| 63 | |
| 64 | } // End namespace detail. |
| 65 | |
| 66 | // |
| 67 | // Template name: access_control. |
| 68 | // Description: Allows the type of inheritance from a provided base class |
| 69 | // to be specified using an int template parameter. |
| 70 | // Template parameters: |
| 71 | // Base - The class from which to inherit (indirectly.) |
| 72 | // Access - The type of access desired. Must be one of the |
| 73 | // values access_base::prot or access_base::pub. |
| 74 | // |
| 75 | template< typename T, typename Access, |
| 76 | typename Base = // VC6 workaraound (Compiler Error C2516) |
| 77 | typename detail::access_control_base<T, Access>::type > |
| 78 | struct access_control : public Base { |
| 79 | access_control() { } |
| 80 | template<typename U> explicit access_control(U u) : Base(u) { } |
| 81 | }; |
| 82 | |
| 83 | //----------------------------------------------------------------------------// |
| 84 | |
| 85 | } } // End namespaces iostreams, boost. |
| 86 | |
| 87 | #endif // #ifndef NDNBOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED |