access_control.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // See http://www.boost.org/libs/iostreams for documentation.
  6. // Contains the definition of the class template access_control, which
  7. // allows the type of inheritance from a provided base class to be specified
  8. // using a template parameter.
  9. #ifndef BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED
  10. #define BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED
  11. #if defined(_MSC_VER)
  12. # pragma once
  13. #endif
  14. #include <boost/iostreams/detail/select.hpp>
  15. #include <boost/mpl/identity.hpp>
  16. #include <boost/type_traits/is_same.hpp>
  17. namespace boost { namespace iostreams {
  18. struct protected_ { }; // Represents protected inheritance.
  19. struct public_ { }; // Represents public inheritance.
  20. namespace detail {
  21. // Implements protected inheritance.
  22. template<typename U>
  23. struct prot_ : protected U
  24. {
  25. prot_() { }
  26. template<typename V> prot_(V v) : U(v) { }
  27. };
  28. // Implements public inheritance.
  29. template<typename U> struct pub_ : public U {
  30. pub_() { }
  31. template<typename V> pub_(V v) : U(v) { }
  32. };
  33. //
  34. // Used to deduce the base type for the template access_control.
  35. //
  36. template<typename T, typename Access>
  37. struct access_control_base {
  38. typedef int bad_access_specifier;
  39. typedef typename
  40. iostreams::select< // Disambiguation for Tru64
  41. ::boost::is_same<
  42. Access, protected_
  43. >, prot_<T>,
  44. ::boost::is_same<
  45. Access, public_
  46. >, pub_<T>,
  47. else_, bad_access_specifier
  48. >::type type;
  49. };
  50. } // End namespace detail.
  51. //
  52. // Template name: access_control.
  53. // Description: Allows the type of inheritance from a provided base class
  54. // to be specified using an int template parameter.
  55. // Template parameters:
  56. // Base - The class from which to inherit (indirectly.)
  57. // Access - The type of access desired. Must be one of the
  58. // values access_base::prot or access_base::pub.
  59. //
  60. template< typename T, typename Access,
  61. typename Base = // VC6 workaraound (Compiler Error C2516)
  62. typename detail::access_control_base<T, Access>::type >
  63. struct access_control : public Base {
  64. access_control() { }
  65. template<typename U> explicit access_control(U u) : Base(u) { }
  66. };
  67. //----------------------------------------------------------------------------//
  68. } } // End namespaces iostreams, boost.
  69. #endif // #ifndef BOOST_IOSTREAMS_ACCESS_CONTROL_HPP_INCLUDED