ECIterators.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef ECIterators_INCLUDED
  18. #define ECIterators_INCLUDED
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/mapi_ptr.h>
  21. namespace KC {
  22. class _kc_export ECHierarchyIteratorBase {
  23. public:
  24. _kc_hidden ECHierarchyIteratorBase(void) :
  25. m_ulFlags(0), m_ulDepth(0), m_ulRowIndex(0)
  26. {
  27. // creates the "end" iterator
  28. }
  29. ECHierarchyIteratorBase(LPMAPICONTAINER lpContainer, ULONG ulFlags = 0, ULONG ulDepth = 0);
  30. _kc_hidden MAPIContainerPtr &dereference(void) const
  31. {
  32. assert(m_ptrCurrent != NULL && "attempt to dereference end iterator");
  33. return const_cast<MAPIContainerPtr&>(m_ptrCurrent);
  34. }
  35. void increment();
  36. _kc_hidden bool equal(const ECHierarchyIteratorBase &rhs) const
  37. {
  38. return m_ptrCurrent == rhs.m_ptrCurrent;
  39. }
  40. private:
  41. MAPIContainerPtr m_ptrContainer;
  42. ULONG m_ulFlags;
  43. ULONG m_ulDepth;
  44. MAPITablePtr m_ptrTable;
  45. SRowSetPtr m_ptrRows;
  46. ULONG m_ulRowIndex;
  47. MAPIContainerPtr m_ptrCurrent;
  48. };
  49. template<typename ContainerPtrType> class ECHierarchyIterator _kc_final :
  50. public ECHierarchyIteratorBase
  51. {
  52. public:
  53. ECHierarchyIterator(void) = default;
  54. ECHierarchyIterator(LPMAPICONTAINER lpContainer, ULONG ulFlags = 0, ULONG ulDepth = 0)
  55. : ECHierarchyIteratorBase(lpContainer, ulFlags, ulDepth) {}
  56. bool operator==(const ECHierarchyIterator<ContainerPtrType> &r) const
  57. {
  58. return ECHierarchyIteratorBase::equal(r);
  59. }
  60. bool operator!=(const ECHierarchyIterator<ContainerPtrType> &r) const
  61. {
  62. return !operator==(r);
  63. }
  64. ECHierarchyIterator<ContainerPtrType> &operator++(void)
  65. {
  66. ECHierarchyIteratorBase::increment();
  67. return *this;
  68. }
  69. ContainerPtrType &operator*(void) const
  70. {
  71. ECHierarchyIteratorBase::dereference().QueryInterface(m_ptr);
  72. return m_ptr;
  73. }
  74. private:
  75. mutable ContainerPtrType m_ptr;
  76. };
  77. typedef ECHierarchyIterator<MAPIFolderPtr> ECFolderIterator;
  78. typedef ECHierarchyIterator<ABContainerPtr> ECABContainerIterator;
  79. } /* namespace */
  80. #endif // ndef ECIterators_INCLUDED