27#ifndef COSMO_ENUMERABLE_INTERFACE_H
28#define COSMO_ENUMERABLE_INTERFACE_H
30#include <Pt/Cosmo/AutoPtr.h>
31#include <Pt/Cosmo/IAutoReleasePool.h>
81Enumerator<T> end(
const IEnumerable<T>& e)
83 return Enumerator<T>();
107 virtual bool onIsValid()
const = 0;
109 virtual void onAdvance() = 0;
121 typedef const T& Reference;
133 virtual const T& onGet()
const = 0;
143 typedef const T* Reference;
155 virtual const T* onGet()
const = 0;
160class EnumeratorBase :
public AutoReleasable
171 : AutoReleasable(pool)
179 template <
typename Enumeration,
typename Deleter>
183 : AutoReleasable(pool)
191 EnumeratorBase(EnumeratorBase&& other) noexcept
192 : AutoReleasable( std::move(other) )
194 , _res( std::move(other._res) )
196 if(other._e == &other._invalid)
202 virtual ~EnumeratorBase()
205 EnumeratorBase& operator=(EnumeratorBase&& other)
noexcept
210 if(other._e == &other._invalid)
215 _res = std::move(other._res);
222 return _e->isValid();
230 explicit operator bool()
const
232 return this->isValid();
235 bool operator !()
const
237 return ! this->isValid();
240 bool operator ==(
const EnumeratorBase& other)
const
242 return ! operator !=(other);
245 bool operator !=(
const EnumeratorBase& other)
const
247 const bool isValid = this->isValid() || other.isValid();
248 return _e != other._e && isValid;
252 virtual void onRelease()
override
259 EnumeratorBase(
const EnumeratorBase& other) =
delete;
261 EnumeratorBase& operator=(
const EnumeratorBase& other) =
delete;
267 virtual bool onIsValid()
const
270 virtual void onAdvance()
282class Enumerator :
public EnumeratorBase
285 template <
typename P>
288 typedef const P& Reference;
294 const P& operator*()
const
302 template <
typename P>
305 typedef const P* Reference;
311 const P* operator*()
const
319 typedef long difference_type;
320 typedef typename Proxy<T>::Reference Reference;
329 : EnumeratorBase(pool, e)
333 template <
typename Enumeration,
typename Deleter>
337 : EnumeratorBase(pool, e, d)
341 Enumerator(Enumerator&& other) noexcept
342 : EnumeratorBase( std::move(other) )
348 Enumerator& operator=(Enumerator&& other)
noexcept
351 EnumeratorBase::operator=(other);
358 Reference get()
const
363 Reference operator*()
const
368 const T* operator->()
const
373 Enumerator& operator++()
379 Proxy<T> operator++(
int)
387 virtual void onRelease()
override
390 EnumeratorBase::onRelease();
Owning smart pointer.
Definition AutoPtr.h:123
Enumerator for IEnumerables.
Definition IEnumerable.h:161
Enumerator for IEnumerables.
Definition IEnumerable.h:283
Auto-release pool interface.
Definition IAutoReleasePool.h:46
Enumerable interface.
Definition IEnumerable.h:58
Enumerator base implementation.
Definition IEnumerable.h:91
Enumerator implementation.
Definition IEnumerable.h:118
Cosmo Component Model.
Definition Api.h:53
Core module.
Definition Allocator.h:33