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.

172 lines
5.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: dotnetstl/collections/object_enumerators.hpp
  3. *
  4. * Purpose: A simple object enumerator, based on ArrayList.
  5. *
  6. * Created: 24th June 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 dotnetstl/collections/object_enumerators.hpp
  40. *
  41. * \brief [C++ only; requires .NET] Definition of the
  42. * dotnetstl::ArrayListEnumerator class
  43. * (\ref group__library__collections "Collections" Library).
  44. */
  45. #ifndef DOTNETSTL_INCL_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS
  46. #define DOTNETSTL_INCL_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. #define DOTNETSTL_VER_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS_MAJOR 4
  49. #define DOTNETSTL_VER_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS_MINOR 0
  50. #define DOTNETSTL_VER_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS_REVISION 2
  51. #define DOTNETSTL_VER_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS_EDIT 27
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL
  57. # include <dotnetstl/dotnetstl.hpp>
  58. #endif /* !DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL */
  59. /* ////////////////////////////////////////////////////////////////////// */
  60. #ifdef _STLSOFT_NO_NAMESPACE
  61. /* There is no stlsoft namespace, so must define ::dotnetstl */
  62. namespace dotnetstl
  63. {
  64. #else
  65. /* Define stlsoft::dotnet_project */
  66. namespace stlsoft
  67. {
  68. namespace dotnetstl_project
  69. {
  70. #endif /* _STLSOFT_NO_NAMESPACE */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Classes
  73. */
  74. /** \brief Provides an IEnumerator implementation on an ArrayList
  75. *
  76. * \ingroup group__library__collections
  77. */
  78. public __gc class ArrayListEnumerator
  79. : public System::Collections::IEnumerator
  80. {
  81. // typedef System::Collections::ArrayList ArrayList;
  82. public:
  83. /// \brief Creates an enumerator for the given list.
  84. ArrayListEnumerator(System::Collections::ArrayList *objects)
  85. : m_objects(objects)
  86. , m_index(-1)
  87. {}
  88. public: // VC++ 7.1 requires that these be public
  89. /// \brief Returns the current object
  90. Object* get_Current()
  91. {
  92. if( m_index < 0 ||
  93. !(m_index < m_objects->get_Count()))
  94. {
  95. throw new System::InvalidOperationException();
  96. }
  97. return m_objects->get_Item(m_index);
  98. }
  99. /// \brief Advances the search by one position
  100. ///
  101. /// \retval true An object is available at the new position
  102. /// \retval false The enumeration is complete
  103. bool MoveNext()
  104. {
  105. if(m_index < m_objects->get_Count() - 1)
  106. {
  107. ++m_index;
  108. return true;
  109. }
  110. else
  111. {
  112. return false;
  113. }
  114. }
  115. /// \brief Resets the enumeration
  116. void Reset()
  117. {
  118. m_index = -1;
  119. }
  120. // Members
  121. private:
  122. System::Collections::ArrayList *m_objects;
  123. int m_index;
  124. // Not to be implemented
  125. private:
  126. ArrayListEnumerator(ArrayListEnumerator const&)
  127. {}
  128. // ArrayListEnumerator& operator =(ArrayListEnumerator const&);
  129. };
  130. ////////////////////////////////////////////////////////////////////////////
  131. // Unit-testing
  132. #ifdef STLSOFT_UNITTEST
  133. # include "./unittest/object_enumerators_unittest_.h"
  134. #endif /* STLSOFT_UNITTEST */
  135. /* ////////////////////////////////////////////////////////////////////// */
  136. #ifdef _STLSOFT_NO_NAMESPACE
  137. } // namespace dotnetstl
  138. #else
  139. } // namespace dotnetstl_project
  140. } // namespace stlsoft
  141. #endif /* _STLSOFT_NO_NAMESPACE */
  142. /* ////////////////////////////////////////////////////////////////////// */
  143. #endif /* DOTNETSTL_INCL_DOTNETSTL_COLLECTIONS_HPP_OBJECT_ENUMERATORS */
  144. /* ///////////////////////////// end of file //////////////////////////// */