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.

147 lines
4.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/obsolete/outer_initialiser.hpp
  3. *
  4. * Purpose: Contains the outer_initialiser template class.
  5. *
  6. * Created: 9th July 2004
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2004-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/outer_initialiser.hpp
  40. ///
  41. /// Contains the outer_initialiser template class.
  42. #ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER
  43. #define STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER
  44. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  45. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER_MAJOR 3
  46. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER_MINOR 2
  47. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER_REVISION 1
  48. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER_EDIT 24
  49. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  50. /* /////////////////////////////////////////////////////////////////////////
  51. * Auto-generation and compatibility
  52. */
  53. /*
  54. [<[STLSOFT-AUTO:TO-BE-OBSOLETE]>]
  55. */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  60. # include <stlsoft/stlsoft.h>
  61. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  62. #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
  63. # include <stlsoft/conversion/sap_cast.hpp>
  64. #endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
  65. /* /////////////////////////////////////////////////////////////////////////
  66. * Namespace
  67. */
  68. #ifndef _STLSOFT_NO_NAMESPACE
  69. namespace stlsoft
  70. {
  71. #endif /* _STLSOFT_NO_NAMESPACE */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Classes
  74. */
  75. // class outer_initialiser
  76. /** \brief Initialises
  77. *
  78. * \ingroup group__library__obsolete
  79. */
  80. template<ss_typename_param_k O>
  81. class outer_initialiser
  82. {
  83. public:
  84. typedef O outer_type;
  85. typedef outer_initialiser<O> class_type;
  86. private:
  87. /// Ensures packing is correct
  88. struct pack_tester
  89. {
  90. /// Used to assert structure alignment
  91. struct large_type
  92. {
  93. int i;
  94. long double ld;
  95. };
  96. large_type lrg;
  97. int sml;
  98. };
  99. public:
  100. outer_initialiser(outer_type *outer, void (O::*fn)())
  101. : m_outer(outer)
  102. , m_fn(fn)
  103. {
  104. // Ensure that there's a good chance that outer_initialiser
  105. // is in the right place in the outer type
  106. STLSOFT_ASSERT(sap_cast<char*>(outer) < sap_cast<char*>(this));
  107. (m_outer->*m_fn)();
  108. }
  109. outer_initialiser(class_type const&)
  110. {
  111. (m_outer->*m_fn)();
  112. }
  113. private:
  114. outer_type *const m_outer;
  115. void (O::*m_fn)();
  116. };
  117. /* ////////////////////////////////////////////////////////////////////// */
  118. #ifndef _STLSOFT_NO_NAMESPACE
  119. } // namespace stlsoft
  120. #endif /* _STLSOFT_NO_NAMESPACE */
  121. /* ////////////////////////////////////////////////////////////////////// */
  122. #endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_OUTER_INITIALISER */
  123. /* ///////////////////////////// end of file //////////////////////////// */