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.

231 lines
7.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/obsolete/proxy_sequence.hpp
  3. *
  4. * Purpose: proxy_sequence template class.
  5. *
  6. * Created: 10th September 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/proxy_sequence.hpp
  40. ///
  41. /// proxy_sequence template class.
  42. #ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE
  43. #define STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE
  44. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  45. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE_MAJOR 3
  46. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE_MINOR 0
  47. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE_REVISION 3
  48. # define STLSOFT_VER_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE_EDIT 34
  49. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  50. /* /////////////////////////////////////////////////////////////////////////
  51. * Compatibility
  52. */
  53. /*
  54. [Incompatibilies-start]
  55. STLSOFT_COMPILER_IS_WATCOM:
  56. [Incompatibilies-end]
  57. */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Includes
  60. */
  61. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  62. # include <stlsoft/stlsoft.h>
  63. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  64. #ifndef STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_PROXY_ITERATOR
  65. # include <stlsoft/obsolete/proxy_iterator.hpp>
  66. #endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_PROXY_ITERATOR */
  67. #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
  68. # include <stlsoft/collections/util/collections.hpp>
  69. #endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
  70. /* /////////////////////////////////////////////////////////////////////////
  71. * Namespace
  72. */
  73. #ifndef _STLSOFT_NO_NAMESPACE
  74. namespace stlsoft
  75. {
  76. #endif /* _STLSOFT_NO_NAMESPACE */
  77. /* /////////////////////////////////////////////////////////////////////////
  78. * Classes
  79. */
  80. /** \brief Enables a non-STL sequence to provide an STL interface
  81. *
  82. * \ingroup group__library__collections
  83. *
  84. * \param E The element type. This type is the element in the underlying sequence
  85. * \param V The value type. This is the type to which the element type is translated
  86. * \param T The traits_type. This type provides a static method \c make_value(), which
  87. * converts the element type to the value type
  88. *
  89. * \deprecated This is maintained for backwards compatibility with the
  90. * recls/COM library. New users should instead use
  91. * stlsoft::transform_iterator.
  92. */
  93. template< ss_typename_param_k E
  94. , ss_typename_param_k V
  95. , ss_typename_param_k T
  96. >
  97. class proxy_sequence
  98. : public stl_collection_tag
  99. {
  100. private:
  101. typedef stlsoft_ns_qual_std(random_access_iterator_tag) tag_type;
  102. public:
  103. typedef E element_type;
  104. typedef V value_type;
  105. typedef T traits_type;
  106. typedef proxy_sequence<E, V, T> class_type;
  107. typedef proxy_iterator<E, V, T, tag_type> iterator;
  108. typedef proxy_iterator<E, const V, T, tag_type> const_iterator;
  109. typedef ss_size_t size_type;
  110. public:
  111. /// Constructs a default proxy_sequence
  112. proxy_sequence()
  113. : m_begin(0)
  114. , m_end(0)
  115. {}
  116. #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
  117. defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
  118. /// Constructs a proxy_sequence from a given range.
  119. proxy_sequence(element_type* first, element_type* last)
  120. : m_begin(first)
  121. , m_end(last)
  122. {}
  123. #endif /* !STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT || STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED */
  124. #if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
  125. /// Constructs a proxy_sequence from a given range.
  126. template <ss_typename_param_k P>
  127. proxy_sequence(P* first, P* last)
  128. : m_begin(first)
  129. , m_end(last)
  130. {}
  131. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  132. #if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
  133. defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
  134. /// Constructs a proxy_sequence from a given range.
  135. proxy_sequence(element_type *first, size_type n)
  136. : m_begin(first)
  137. , m_end(&first[n])
  138. {}
  139. #endif /* !STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT || STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED */
  140. #if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
  141. /// Constructs a proxy_sequence from a given range.
  142. template <ss_typename_param_k P>
  143. proxy_sequence(P *first, size_type n)
  144. : m_begin(first)
  145. , m_end(&first[n])
  146. {}
  147. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  148. /// \name Iteration
  149. /// @{
  150. public:
  151. /// Begins the iteration
  152. ///
  153. /// \return An iterator representing the start of the sequence
  154. iterator begin()
  155. {
  156. return iterator(m_begin, m_end);
  157. }
  158. /// Ends the iteration
  159. ///
  160. /// \return An iterator representing the end of the sequence
  161. iterator end()
  162. {
  163. return iterator();
  164. }
  165. /// Begins the iteration
  166. ///
  167. /// \return An iterator representing the start of the sequence
  168. const_iterator begin() const
  169. {
  170. return const_iterator(m_begin, m_end);
  171. }
  172. /// Ends the iteration
  173. ///
  174. /// \return An iterator representing the end of the sequence
  175. const_iterator end() const
  176. {
  177. return const_iterator();
  178. }
  179. /// @}
  180. /// \name Attributes
  181. /// @{
  182. public:
  183. /// Indicates whether the sequence is empty
  184. bool empty() const
  185. {
  186. return m_begin == m_end;
  187. }
  188. /// Indicates whether the sequence is empty
  189. size_type size() const
  190. {
  191. return m_end - m_begin;
  192. }
  193. /// @}
  194. // Members
  195. private:
  196. element_type *m_begin;
  197. element_type *m_end;
  198. };
  199. /* ////////////////////////////////////////////////////////////////////// */
  200. #ifndef _STLSOFT_NO_NAMESPACE
  201. } /* namespace stlsoft */
  202. #endif /* _STLSOFT_NO_NAMESPACE */
  203. /* ////////////////////////////////////////////////////////////////////// */
  204. #endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_PROXY_SEQUENCE */
  205. /* ///////////////////////////// end of file //////////////////////////// */