| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #pragma once
- namespace Framework
- {
- template<typename T> class BasicIterator
- {
- public:
- virtual ~BasicIterator() {}
- virtual operator bool() = 0;
- virtual T val() = 0;
- virtual void plusPlus() = 0;
- };
- /**
- * Iterator interface
- * \tparam T type of the value that is iterated
- * \tparam I type of the iterator subclass
- */
- template<typename T, typename I> class Iterator : public BasicIterator<T>
- {
- public:
- virtual ~Iterator()
- {
- static_assert(std::is_base_of<Iterator, I>::value,
- "Type Argument I must be an implementation of Iterator");
- }
- virtual bool hasNext()
- {
- return (bool)next();
- }
- virtual I next() = 0;
- virtual void plusPlus() override
- {
- *(I*)this = next();
- }
- virtual I& operator++() //! prefix
- {
- *(I*)this = next();
- return *(I*)this;
- }
- virtual I operator++(int) //! postfix
- {
- I tmp(*(I*)this);
- operator++();
- return tmp;
- }
- /**
- * adds a value before the current element.
- * after executing this function, the current element is the new value.
- *
- * \param val the new value to add
- */
- virtual void addBefore(T val) = 0;
- virtual void set(T val) = 0;
- virtual void remove() = 0;
- operator T()
- {
- return this->val();
- }
- virtual T operator->()
- {
- return this->val();
- }
- virtual T operator*()
- {
- return this->val();
- }
- };
- } // namespace Framework
|