#ifndef __JLANG__JABSTRACTOBJECTITERATOR__ #define __JLANG__JABSTRACTOBJECTITERATOR__ #include "JLang/JObjectIterator.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Abstract object iterator. * * This class implements the JObjectIterator interface via a single interface method setObject().\n * An internal object is used for which the default constructor should exist. */ template class JAbstractObjectIterator : public virtual JObjectIterator { protected: /** * Default constructor. */ JAbstractObjectIterator() : has_next(false) {} T object; //!< object bool has_next; //!< status public: typedef typename JObjectIterator::pointer_type pointer_type; /** * Set object. * * \param object reference to object to be set * \return true if set; else false */ virtual bool setObject(T& object) = 0; /** * Check availability of next element. * * \return true if the iteration has more elements; else false */ virtual bool hasNext() override { if (!has_next) { has_next = this->setObject(object); } return has_next; } /** * Get next element. * * \return pointer to element */ virtual const pointer_type& next() override { if (has_next) ps.reset(&this->object); else ps.reset(NULL); has_next = false; return ps; } private: pointer_type ps; }; /** * Abstract object iterator with rewinding. */ template class JRewindableAbstractObjectIterator : public JRewindableObjectIterator, public JAbstractObjectIterator {}; /** * Abstract object iterator with named access. */ template class JAccessibleAbstractObjectIterator : public JAccessibleObjectIterator, public JAbstractObjectIterator {}; } #endif