You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/obsolete/explicit_inheritance_veneer.hpp
  3. *
  4. * Purpose: Explicit inheritance veneer class.
  5. *
  6. * Created: 13th January 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /// \file stlsoft/obsolete/explicit_inheritance_veneer.hpp
  40. ///
  41. /// Explicit inheritance veneer class.
  42. #ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER
  43. #define STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER
  44. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  45. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER_MAJOR 4
  46. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER_MINOR 0
  47. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER_REVISION 2
  48. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER_EDIT 37
  49. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  50. /* /////////////////////////////////////////////////////////////////////////
  51. * Includes
  52. */
  53. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  54. # include <stlsoft/stlsoft.h>
  55. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  56. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS
  57. # include <stlsoft/util/constraints.hpp>
  58. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS */
  59. /* /////////////////////////////////////////////////////////////////////////
  60. * Namespace
  61. */
  62. #ifndef _STLSOFT_NO_NAMESPACE
  63. namespace stlsoft
  64. {
  65. #endif /* _STLSOFT_NO_NAMESPACE */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Classes
  68. */
  69. // class explicit_inheritance_veneer
  70. /** \brief Applies a \c protected veneer over a type, which can be accessed only
  71. * through conversions to the veneered type
  72. *
  73. * \param T The type to be subject to the veneer
  74. *
  75. * \ingroup group__library__obsolete
  76. *
  77. */
  78. template <ss_typename_param_k T>
  79. struct explicit_inheritance_veneer
  80. : protected T
  81. {
  82. public:
  83. /// The base class type
  84. typedef T base_type;
  85. // Conversion
  86. public:
  87. /// The conversion operator that provides access to the base type
  88. base_type const* operator &() const
  89. {
  90. stlsoft_constraint_must_be_same_size(T, explicit_inheritance_veneer<T>);
  91. return this;
  92. }
  93. // Implementation
  94. protected:
  95. /// Access a mutable reference to the base type
  96. base_type& base_type_value()
  97. {
  98. return *this;
  99. }
  100. /// Access a non-mutable reference to the base type
  101. base_type const& base_type_value() const
  102. {
  103. return *this;
  104. }
  105. };
  106. /* ////////////////////////////////////////////////////////////////////// */
  107. #ifndef _STLSOFT_NO_NAMESPACE
  108. } // namespace stlsoft
  109. #endif /* _STLSOFT_NO_NAMESPACE */
  110. /* ////////////////////////////////////////////////////////////////////// */
  111. #endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_EXPLICIT_INHERITANCE_VENEER */
  112. /* ///////////////////////////// end of file //////////////////////////// */