Iterator.Container.tlh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #pragma once
  2. #include "Iterator.Base.tlh"
  3. #include "Iterator.Random.tlh"
  4. //-----------------------------------------------------------------------------
  5. // Iterator
  6. // 一般容器 - 常量
  7. //-----------------------------------------------------------------------------
  8. namespace Iterator
  9. {
  10. template <typename _Container>
  11. class __ConstIterator : public __RandomIterator <typename _Container::const_iterator>
  12. {
  13. typedef __RandomIterator <typename _Container::const_iterator> inherited;
  14. public:
  15. using value_type = typename _Container::value_type;
  16. using reference = typename _Container::reference;
  17. using const_reference = typename _Container::const_reference;
  18. using data_type = const_reference;
  19. using deref_type = value_type;
  20. public:
  21. // 构造一个全空的迭代器, 用于容器指针为空的情形
  22. __ConstIterator () : inherited ()
  23. {
  24. }
  25. __ConstIterator (const _Container & ar)
  26. {
  27. InitFrom (ar);
  28. }
  29. __ConstIterator (const __ConstIterator & from) : inherited (from)
  30. {
  31. }
  32. __ConstIterator (__ConstIterator && from) : inherited (from)
  33. {
  34. }
  35. ~__ConstIterator () {}
  36. public:
  37. inline __ConstIterator & operator = (const __ConstIterator & from)
  38. {
  39. inherited::operator = (from);
  40. return (*this);
  41. }
  42. inline __ConstIterator & operator = (__ConstIterator && from)
  43. {
  44. inherited::operator = (from);
  45. return (*this);
  46. }
  47. public:
  48. inline data_type Current () { return (*m_stdIter); }
  49. inline data_type operator () () { return (Current ()); }
  50. inline data_type operator * () { return (Current ()); }
  51. protected:
  52. void InitFrom (const _Container & ar)
  53. {
  54. m_stdIter = m_stdBegin = ar.cbegin ();
  55. m_stdEnd = ar.cend ();
  56. m_Count = (int)ar.size ();
  57. m_Index = 0;
  58. }
  59. };
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Iterator
  63. // 一般容器 - 变量
  64. //-----------------------------------------------------------------------------
  65. namespace Iterator
  66. {
  67. template <typename _Container>
  68. class __Iterator : public __RandomIterator <typename _Container::iterator>
  69. {
  70. typedef __RandomIterator <typename _Container::iterator> inherited;
  71. public:
  72. using value_type = typename _Container::value_type;
  73. using reference = typename _Container::reference;
  74. using data_type = reference;
  75. using deref_type = value_type;
  76. public:
  77. // 构造一个全空的迭代器, 用于容器指针为空的情形
  78. __Iterator () : inherited ()
  79. {
  80. }
  81. __Iterator (_Container & ar)
  82. {
  83. InitFrom (ar);
  84. }
  85. __Iterator (const __Iterator & from) : inherited (from)
  86. {
  87. }
  88. __Iterator (__Iterator && from) : inherited (from)
  89. {
  90. }
  91. ~__Iterator () {}
  92. public:
  93. inline __Iterator & operator = (const __Iterator & from)
  94. {
  95. inherited::operator = (from);
  96. return (*this);
  97. }
  98. inline __Iterator & operator = (__Iterator && from)
  99. {
  100. inherited::operator = (from);
  101. return (*this);
  102. }
  103. public:
  104. inline data_type Current () { return (*m_stdIter); }
  105. inline data_type operator () () { return (Current ()); }
  106. inline data_type operator * () { return (Current ()); }
  107. protected:
  108. void InitFrom (_Container & ar)
  109. {
  110. m_stdIter = m_stdBegin = ar.begin ();
  111. m_stdEnd = ar.end ();
  112. m_Count = (int) ar.size ();
  113. m_Index = 0;
  114. }
  115. };
  116. }