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.

354 lines
8.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/util/argument_proxies.hpp (originally MLRefPrx.h, ::SynesisStd)
  3. *
  4. * Purpose: Const and non-const reference and pointer proxy classes.
  5. *
  6. * Created: 28th April 2000
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2000-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/argument_proxies.hpp
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::ptr_proxy(),
  42. * stlsoft::const_ptr_proxy(), stlsoft::ref_proxy(),
  43. * stlsoft::const_ref_proxy() and stlsoft::val_proxy() argument
  44. * proxy creator functions
  45. * (\ref group__library__utility "Utility" Library).
  46. */
  47. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES
  48. #define STLSOFT_INCL_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES
  49. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  50. # define STLSOFT_VER_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES_MAJOR 4
  51. # define STLSOFT_VER_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES_MINOR 0
  52. # define STLSOFT_VER_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES_REVISION 3
  53. # define STLSOFT_VER_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES_EDIT 131
  54. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  59. # include <stlsoft/stlsoft.h>
  60. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _STLSOFT_NO_NAMESPACE
  65. namespace stlsoft
  66. {
  67. #endif /* _STLSOFT_NO_NAMESPACE */
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Classes
  70. */
  71. /** \brief Acts as a proxy for a pointer
  72. *
  73. * \ingroup group__library__utility
  74. *
  75. */
  76. // pointer_proxy
  77. template <ss_typename_param_k A>
  78. class pointer_proxy
  79. {
  80. public:
  81. typedef A argument_type;
  82. typedef argument_type* argument_pointer_type;
  83. typedef pointer_proxy<A> class_type;
  84. // const_ruction
  85. public:
  86. ss_explicit_k pointer_proxy(argument_pointer_type a)
  87. : m_a(a)
  88. {}
  89. pointer_proxy(class_type const& rhs)
  90. : m_a(rhs.m_a)
  91. {}
  92. // Accessors
  93. public:
  94. operator argument_pointer_type() const
  95. {
  96. return m_a;
  97. }
  98. // Members
  99. private:
  100. argument_pointer_type m_a;
  101. // Not to be implemented
  102. private:
  103. class_type const& operator =(class_type const&);
  104. };
  105. /** \brief Acts as a proxy for a pointer-to-const
  106. *
  107. * \ingroup group__library__utility
  108. *
  109. */
  110. // const_pointer_proxy
  111. template <ss_typename_param_k A>
  112. class const_pointer_proxy
  113. {
  114. public:
  115. typedef A argument_type;
  116. typedef argument_type const* argument_pointer_type;
  117. typedef const_pointer_proxy<A> class_type;
  118. // const_ruction
  119. public:
  120. ss_explicit_k const_pointer_proxy(argument_pointer_type a)
  121. : m_a(a)
  122. {}
  123. const_pointer_proxy(class_type const& rhs)
  124. : m_a(rhs.m_a)
  125. {}
  126. // Accessors
  127. public:
  128. operator argument_pointer_type() const
  129. {
  130. return m_a;
  131. }
  132. // Members
  133. private:
  134. argument_pointer_type m_a;
  135. // Not to be implemented
  136. private:
  137. class_type const& operator =(class_type const&);
  138. };
  139. /** \brief Acts as a proxy for a reference
  140. *
  141. * \ingroup group__library__utility
  142. *
  143. */
  144. // reference_proxy
  145. template <ss_typename_param_k A>
  146. class reference_proxy
  147. {
  148. public:
  149. typedef A argument_type;
  150. typedef argument_type& argument_reference_type;
  151. typedef reference_proxy<A> class_type;
  152. // const_ruction
  153. public:
  154. ss_explicit_k reference_proxy(argument_reference_type a)
  155. : m_a(a)
  156. {}
  157. reference_proxy(class_type const& rhs)
  158. : m_a(rhs.m_a)
  159. {}
  160. // Accessors
  161. public:
  162. operator argument_reference_type() const
  163. {
  164. return m_a;
  165. }
  166. // Members
  167. private:
  168. argument_reference_type m_a;
  169. // Not to be implemented
  170. private:
  171. class_type const& operator =(class_type const&);
  172. };
  173. /** \brief Acts as a proxy for a reference-to-const
  174. *
  175. * \ingroup group__library__utility
  176. *
  177. */
  178. // const_reference_proxy
  179. template <ss_typename_param_k A>
  180. class const_reference_proxy
  181. {
  182. public:
  183. typedef A argument_type;
  184. typedef argument_type const& argument_reference_type;
  185. typedef const_reference_proxy<A> class_type;
  186. // const_ruction
  187. public:
  188. ss_explicit_k const_reference_proxy(argument_reference_type a)
  189. : m_a(a)
  190. {}
  191. const_reference_proxy(class_type const& rhs)
  192. : m_a(rhs.m_a)
  193. {}
  194. // Accessors
  195. public:
  196. operator argument_reference_type() const
  197. {
  198. return m_a;
  199. }
  200. // Members
  201. private:
  202. argument_reference_type m_a;
  203. // Not to be implemented
  204. private:
  205. class_type const& operator =(class_type const&);
  206. };
  207. /** \brief Acts as a proxy for a value
  208. *
  209. * \ingroup group__library__utility
  210. *
  211. */
  212. // value_proxy
  213. template <ss_typename_param_k A>
  214. class value_proxy
  215. {
  216. public:
  217. typedef A argument_type;
  218. typedef value_proxy<A> class_type;
  219. // const_ruction
  220. public:
  221. ss_explicit_k value_proxy(argument_type a)
  222. : m_a(a)
  223. {}
  224. value_proxy(class_type const& rhs)
  225. : m_a(rhs.m_a)
  226. {}
  227. // Accessors
  228. public:
  229. operator argument_type() const
  230. {
  231. return m_a;
  232. }
  233. // Members
  234. private:
  235. argument_type m_a;
  236. // Not to be implemented
  237. private:
  238. class_type const& operator =(class_type const&);
  239. };
  240. /* /////////////////////////////////////////////////////////////////////////
  241. * Forwarding functions
  242. */
  243. /** \brief Creator function for the pointer_proxy
  244. *
  245. * \ingroup group__library__utility
  246. *
  247. */
  248. template <ss_typename_param_k A>
  249. inline pointer_proxy<A> ptr_proxy(A* a)
  250. {
  251. return pointer_proxy<A>(a);
  252. }
  253. /** \brief Creator function for the const_pointer_proxy
  254. *
  255. * \ingroup group__library__utility
  256. *
  257. */
  258. template <ss_typename_param_k A>
  259. inline const_pointer_proxy<A> const_ptr_proxy(A const* a)
  260. {
  261. return const_pointer_proxy<A>(a);
  262. }
  263. /** \brief Creator function for the reference_proxy
  264. *
  265. * \ingroup group__library__utility
  266. *
  267. */
  268. template <ss_typename_param_k A>
  269. inline reference_proxy<A> ref_proxy(A& a)
  270. {
  271. return reference_proxy<A>(a);
  272. }
  273. /** \brief Creator function for the const_reference_proxy
  274. *
  275. * \ingroup group__library__utility
  276. *
  277. */
  278. template <ss_typename_param_k A>
  279. inline const_reference_proxy<A> const_ref_proxy(A& a)
  280. {
  281. return const_reference_proxy<A>(a);
  282. }
  283. /** \brief Creator function for the value_proxy
  284. *
  285. * \ingroup group__library__utility
  286. *
  287. */
  288. template <ss_typename_param_k A>
  289. inline value_proxy<A> val_proxy(A a)
  290. {
  291. return value_proxy<A>(a);
  292. }
  293. ////////////////////////////////////////////////////////////////////////////
  294. // Unit-testing
  295. #ifdef STLSOFT_UNITTEST
  296. # include "./unittest/argument_proxies_unittest_.h"
  297. #endif /* STLSOFT_UNITTEST */
  298. /* ////////////////////////////////////////////////////////////////////// */
  299. #ifndef _STLSOFT_NO_NAMESPACE
  300. } // namespace stlsoft
  301. #endif /* _STLSOFT_NO_NAMESPACE */
  302. /* ////////////////////////////////////////////////////////////////////// */
  303. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_ARGUMENT_PROXIES */
  304. /* ///////////////////////////// end of file //////////////////////////// */