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.

265 lines
7.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/util/static_initialisers.hpp (originally MLClsCtr.h, ::SynesisStd)
  3. *
  4. * Purpose: Initialiser classes for the STLSoft libraries.
  5. *
  6. * Created: 17th February 1997
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1997-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/util/static_initialisers.hpp
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::static_initialiser,
  42. * stlsoft::api_constructor classes, and the stlsoft::class_constructor
  43. * class template
  44. * (\ref group__library__utility "Utility" Library).
  45. */
  46. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STATIC_INITIALISERS
  47. #define STLSOFT_INCL_STLSOFT_UTIL_HPP_STATIC_INITIALISERS
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define STLSOFT_VER_STLSOFT_UTIL_HPP_STATIC_INITIALISERS_MAJOR 4
  50. # define STLSOFT_VER_STLSOFT_UTIL_HPP_STATIC_INITIALISERS_MINOR 0
  51. # define STLSOFT_VER_STLSOFT_UTIL_HPP_STATIC_INITIALISERS_REVISION 1
  52. # define STLSOFT_VER_STLSOFT_UTIL_HPP_STATIC_INITIALISERS_EDIT 217
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  58. # include <stlsoft/stlsoft.h>
  59. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Namespace
  62. */
  63. #ifndef _STLSOFT_NO_NAMESPACE
  64. namespace stlsoft
  65. {
  66. #endif /* _STLSOFT_NO_NAMESPACE */
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Classes
  69. */
  70. #if 0
  71. class method_constructor
  72. {
  73. public:
  74. template<ss_typename_param_k T>
  75. method_constructor(T const& t, void (T::*const fn)())
  76. {
  77. (t.*fn)();
  78. }
  79. template< ss_typename_param_k T
  80. , ss_typename_param_k R
  81. >
  82. method_constructor(T const& t, R (T::*const fn)())
  83. {
  84. (t.*fn)();
  85. }
  86. };
  87. #endif /* 0 */
  88. /** \brief static_initialiser
  89. *
  90. * \ingroup group__library__utility
  91. *
  92. * Initialises any non-class function or type
  93. *
  94. */
  95. class static_initialiser
  96. {
  97. public:
  98. typedef static_initialiser class_type;
  99. /// \name Constructors
  100. /// @{
  101. public:
  102. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  103. template <ss_typename_param_k T>
  104. static_initialiser(T const& /* t */)
  105. {}
  106. template <ss_typename_param_k T>
  107. static_initialiser(T const* /* pt */)
  108. {}
  109. #else
  110. static_initialiser(int /* t */)
  111. {}
  112. static_initialiser(void const* /* pt */)
  113. {}
  114. #endif // STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  115. /// @}
  116. /// \name Not to be implemented
  117. /// @{
  118. private:
  119. static_initialiser(class_type const&);
  120. static_initialiser& operator =(class_type const&);
  121. #ifndef new
  122. # ifdef STLSOFT_COMPILER_IS_COMO
  123. void *operator new(ss_size_t) stlsoft_throw_0()
  124. {
  125. return 0;
  126. }
  127. # else /* ? compiler */
  128. void *operator new(ss_size_t) stlsoft_throw_0();
  129. # endif /* compiler */
  130. #endif /* !new */
  131. void operator delete(void*)
  132. {}
  133. /// @}
  134. };
  135. /** \brief Used to initialise APIs
  136. *
  137. * \ingroup group__library__utility
  138. *
  139. */
  140. class api_constructor
  141. {
  142. /// \name Constructors
  143. /// @{
  144. public:
  145. api_constructor(void (*pfnInit)(), void (*pfnUninit)())
  146. : m_pfnUninit(pfnUninit)
  147. {
  148. if(NULL != pfnInit)
  149. {
  150. (*pfnInit)();
  151. }
  152. }
  153. ~api_constructor() stlsoft_throw_0()
  154. {
  155. if(NULL != m_pfnUninit)
  156. {
  157. (*m_pfnUninit)();
  158. }
  159. }
  160. /// @}
  161. /// \name Members
  162. /// @{
  163. private:
  164. void (*m_pfnUninit)(void);
  165. /// @}
  166. /// \name Not to be implemented
  167. /// @{
  168. private:
  169. api_constructor(api_constructor const&);
  170. api_constructor& operator =(api_constructor const&);
  171. #ifndef new
  172. # ifdef STLSOFT_COMPILER_IS_COMO
  173. void *operator new(ss_size_t) stlsoft_throw_0()
  174. {
  175. return 0;
  176. }
  177. # else /* ? compiler */
  178. void *operator new(ss_size_t) stlsoft_throw_0();
  179. # endif /* compiler */
  180. #endif /* !new */
  181. void operator delete(void*)
  182. {}
  183. /// @}
  184. };
  185. /** \brief Used to initialise classes
  186. *
  187. * \ingroup group__library__utility
  188. *
  189. */
  190. template <ss_typename_param_k T>
  191. class class_constructor
  192. : protected api_constructor
  193. {
  194. /// \name Member types
  195. /// @{
  196. public:
  197. typedef void (*class_init_fn_t)();
  198. typedef void (*class_uninit_fn_t)();
  199. /// @}
  200. /// \name Constructors
  201. /// @{
  202. public:
  203. ss_explicit_k class_constructor()
  204. : api_constructor(&T::class_init, &T::class_uninit)
  205. {}
  206. ss_explicit_k class_constructor( class_init_fn_t pfnInit
  207. , class_uninit_fn_t pfnUninit)
  208. : api_constructor(pfnInit, pfnUninit)
  209. {}
  210. /// @}
  211. /// \name Not to be implemented
  212. /// @{
  213. private:
  214. class_constructor(class_constructor const&);
  215. class_constructor& operator =(class_constructor const&);
  216. #ifndef new
  217. # ifdef STLSOFT_COMPILER_IS_COMO
  218. void *operator new(ss_size_t) stlsoft_throw_0()
  219. {
  220. return 0;
  221. }
  222. # else /* ? compiler */
  223. void *operator new(ss_size_t) stlsoft_throw_0();
  224. # endif /* compiler */
  225. #endif /* !new */
  226. void operator delete(void*)
  227. {}
  228. /// @}
  229. };
  230. /* ////////////////////////////////////////////////////////////////////// */
  231. #ifndef _STLSOFT_NO_NAMESPACE
  232. } // namespace stlsoft
  233. #endif /* _STLSOFT_NO_NAMESPACE */
  234. /* ////////////////////////////////////////////////////////////////////// */
  235. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STATIC_INITIALISERS */
  236. /* ///////////////////////////// end of file //////////////////////////// */