#ifndef __JLANG__JSTDOBJECTITERATOR__ #define __JLANG__JSTDOBJECTITERATOR__ #include #include #include "JLang/JObjectIterator.hh" #include "JLang/JClass.hh" #include "JLang/JCategory.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Implementation of object iteration from STD container. */ template struct JSTDObjectIterator : public JRewindableObjectIterator::is_constant>::value_type> { typedef typename JCategory::is_constant>::value_type value_type; typedef typename JRewindableObjectIterator::pointer_type pointer_type; /** * Default constructor. */ JSTDObjectIterator() {} /** * Constructor. * * \param begin begin of data * \param end end of data */ JSTDObjectIterator(T begin, T end) : __begin(begin), __end (end), __i (begin) {} /** * Rewind. */ virtual void rewind() override { __i = __begin; } /** * Check availability of next element. * * \return true if the iteration has more elements; else false */ virtual bool hasNext() override { return __i != __end; } /** * Get next element. * * \return pointer to element */ virtual const pointer_type& next() override { if (hasNext()) ps.reset(&(*__i++)); else ps.reset(NULL); return ps; } /** * Skip items. * * \param ns number of items to skip * \return number of items skipped */ virtual skip_type skip(const skip_type ns) override { using namespace std; skip_type i = min(ns, (skip_type) distance(__i, __end)); advance(__i, i); return i; } protected: T __begin; T __end; T __i; private: pointer_type ps; }; } #endif