8 #include "Arp/System/Core/IEnumerator.hxx" 9 #include "Arp/System/Core/Exception.hpp" 30 Empty(
void) =
default;
39 virtual ~Empty(
void) =
default;
85 using Stack = std::stack<typename IEnumerator<T>::Ptr>;
112 size_t GetSize()
const;
119 template<
class Iterator>
120 class IteratorAdapters
126 T& operator()(Iterator i)
const 133 T& operator()(Iterator i)
const 140 T& operator()(Iterator i)
const 152 template<class Iterator, class IteratorAdapter = typename IteratorAdapters<Iterator>::Value>
179 bool firstMove =
true;
180 IteratorAdapter iteratorAdapter;
186 template<
class Predicate>
246 template<
class TIterator>
253 template<
class TContainer>
260 template<
class TContainer>
267 template<
class TContainer>
275 template<
class Predicate>
285 using TCurrent =
typename std::remove_const<typename std::remove_reference<T>::type>::type;
302 throw Exception(
"IEnumerator::GetCurrent() is not supported by empty enumerators");
319 if (this->first->MoveNext())
326 return this->second->MoveNext();
334 return this->first->GetCurrent();
337 return this->second->GetCurrent();
345 this->enumerators.push(e);
351 while (!this->enumerators.empty())
353 if (this->enumerators.top()->MoveNext())
358 this->enumerators.pop();
367 return this->enumerators.top()->GetCurrent();
373 return this->enumerators.size();
379 template<
class Iterator,
class IteratorAdapter>
388 template<
class Iterator,
class IteratorAdapter>
393 this->firstMove =
false;
394 return this->begin != this->end;
397 return ++this->begin != this->end;
401 template<
class Iterator,
class IteratorAdapter>
404 return this->iteratorAdapter(this->begin);
410 template<
class Predicate>
413 : source(std::move(source)), predicate(std::move(predicate))
419 template<
class Predicate>
424 if (this->predicate(this->source->
GetCurrent()))
434 template<
class Predicate>
452 return std::make_shared<Empty>();
458 return std::make_shared<Composite>(first, second);
462 template<
class TIterator>
465 return std::make_shared<StlAdapter<TIterator>>(begin, end);
469 template<
class TContainer>
476 template<
class TContainer>
479 return std::make_shared<StlAdapter<typename TContainer::const_iterator, typename IteratorAdapters<typename TContainer::const_iterator>::Key>>(c.begin(), c.end());
483 template<
class TContainer>
486 return std::make_shared<StlAdapter<typename TContainer::const_iterator, typename IteratorAdapters<typename TContainer::const_iterator>::Mapped>>(c.begin(), c.end());
491 template<
class Predicate>
495 return std::make_shared<Enumerator<T>::FilterEnumerator<Predicate>>(source, predicate);
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom...
Definition: IEnumerator.hxx:47
static IEnumerator< T >::Ptr CreateStlAdapter(TIterator begin, TIterator end)
Creates an enumerator adapter from the given STL iterators.
Definition: Enumerator.hxx:463
std::shared_ptr< IEnumerator > Ptr
The smart pointer tpye of this interface.
Definition: IEnumerator.hxx:51
Enumerator(void)=default
Constructs an Enumerator instance.
virtual bool MoveNext(void)=0
Moves this enumerator to the next position.
static IEnumerator< T >::Ptr CreateComposite(typename IEnumerator< T >::Ptr first, typename IEnumerator< T >::Ptr second)
Creates a composite enumerator from the two given enumerators, e.g. to enumerate trees easily...
Definition: Enumerator.hxx:456
Composite(typename IEnumerator< T >::Ptr first, typename IEnumerator< T >::Ptr second)
Constructs an Composite instance.
Definition: Enumerator.hxx:308
Implements an empty enumerator, that is, the first call of MoveNext() will return false...
Definition: Enumerator.hxx:26
size_t GetSize() const
Get the size of this stack.
Definition: Enumerator.hxx:371
static IEnumerator< T >::Ptr CreateMappedAdapter(TContainer &c)
Creates an enumerator adapter from the given STL map enumerating the mapped items.
Definition: Enumerator.hxx:484
Use this class to build a single enumerator by two given enumerator, e.g. to enumerate multiple conta...
Definition: Enumerator.hxx:82
T GetCurrent(void) override
Gets the element at the current position.
Definition: Enumerator.hxx:330
void Push(typename IEnumerator< T >::Ptr e)
Adds the as argument passed enumerator to this stack.
Definition: Enumerator.hxx:343
Empty(void)=default
Constructs an Empty instance.
static IEnumerator< T >::Ptr CreateEmpty(void)
Creates an empty enumerator.
Definition: Enumerator.hxx:450
static IEnumerator< T >::Ptr CreateFilter(typename IEnumerator< T >::Ptr source, Predicate predicate)
Creates a filtering adapter enumerating only the nodes matching a given predicate.
Definition: Enumerator.hxx:492
static Empty Null
A static empty enumerator instance.
Definition: Enumerator.hxx:221
Root namespace for the PLCnext API
Empty & operator=(const Empty &arg)=default
Assignment operator.
virtual T GetCurrent(void) override
Gets the element at the current position.
Definition: Enumerator.hxx:444
This class implements an enumerator adapter for STL container based on iterators.
Definition: Enumerator.hxx:153
virtual ~Enumerator(void)=default
Destructs this instance and frees all resources.
bool MoveNext(void) override
Moves this enumerator to the next position.
Definition: Enumerator.hxx:315
virtual ~Empty(void)=default
Destructs this instance and frees all resources.
virtual bool MoveNext(void)=0
Moves this enumerator to the next position.
This is the base class of all Arp exception classes.
Definition: Exception.hpp:15
T GetCurrent(void) override
Gets the element at the current position.
Definition: Enumerator.hxx:365
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:21
static IEnumerator< T >::Ptr CreateKeysAdapter(TContainer &c)
Creates an enumerator adapter from the given STL map enumerating the keys.
Definition: Enumerator.hxx:477
bool MoveNext(void) override
Moves this enumerator to the next position.
Definition: Enumerator.hxx:349
virtual T GetCurrent(void)=0
Gets the element at the current position.
Use this class to build a single enumerator by two given enumerator, e.g. to enumerate multiple conta...
Definition: Enumerator.hxx:52
bool MoveNext(void) override
Moves this enumerator to the next position.
Definition: Enumerator.hxx:294
TCurrent current
The current field of this enumerator.
Definition: Enumerator.hxx:288
T GetCurrent(void) override
Gets the element at the current position.
Definition: Enumerator.hxx:300