Stroika Library 3.0d24
 
Loading...
Searching...
No Matches
DelegatedIterator.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
5
6namespace Stroika::Foundation::Traversal {
7
8 /*
9 ********************************************************************************
10 *********************** DelegatedIterator<T, EXTRA_DATA>::Rep ******************
11 ********************************************************************************
12 */
13 template <typename T, typename EXTRA_DATA>
14 DelegatedIterator<T, EXTRA_DATA>::Rep::Rep (const Iterator<T>& delegateTo, const EXTRA_DATA& extraData)
15 : fDelegateTo{delegateTo}
16 , fExtraData{extraData}
17 {
18 }
19 template <typename T, typename EXTRA_DATA>
20 auto DelegatedIterator<T, EXTRA_DATA>::Rep::Clone () const -> unique_ptr<IRep>
21 {
22 return make_unique<Rep> (*this);
23 }
24 template <typename T, typename EXTRA_DATA>
25 bool DelegatedIterator<T, EXTRA_DATA>::Rep::AtEnd () const
26 {
27 // avoid virtual call to delegate (use cached value)
28 return fDelegateTo.AtEnd ();
29 }
30 template <typename T, typename EXTRA_DATA>
31 optional<T> DelegatedIterator<T, EXTRA_DATA>::Rep::Current () const
32 {
33 // avoid virtual call to delegate (use cached value)
34 if (fDelegateTo.AtEnd ()) {
35 return nullopt;
36 }
37 return *fDelegateTo;
38 }
39 template <typename T, typename EXTRA_DATA>
40 optional<T> DelegatedIterator<T, EXTRA_DATA>::Rep::More ()
41 {
42 // Still does virtual call to delegate, but caches result into fDelegate
43 ++fDelegateTo;
44 if (fDelegateTo.AtEnd ()) {
45 return nullopt;
46 }
47 return *fDelegateTo;
48 }
49 template <typename T, typename EXTRA_DATA>
50 bool DelegatedIterator<T, EXTRA_DATA>::Rep::Equals (const IRep* rhs) const
51 {
52 return fDelegateTo.ConstGetRep ().Equals (rhs);
53 }
54
55 /*
56 ********************************************************************************
57 *********************** DelegatedIterator<T, EXTRA_DATA> ***********************
58 ********************************************************************************
59 */
60 template <typename T, typename EXTRA_DATA>
61 DelegatedIterator<T, EXTRA_DATA>::DelegatedIterator (const Iterator<T>& delegateTo, const EXTRA_DATA& extraData)
62 : Iterator<T>{make_unique<Rep> (delegateTo, extraData)}
63 {
64 }
65
66}