#ifndef __JLANG__JCONVERSIONITERATOR__ #define __JLANG__JCONVERSIONITERATOR__ #include "JLang/JObjectIterator.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Interface for object iteration with type conversion. */ template<class JInput_t, class JOutput_t> class JConversionIterator : public JObjectIterator<JOutput_t> { public: typedef typename JObjectIterator<JOutput_t>::pointer_type pointer_type; /** * Constructor. * * \param input input iterator */ JConversionIterator(JObjectIterator<JInput_t>& input) : in(input) {} /** * Check availability of next element. * * \return true if the iteration has more elements; else false */ virtual bool hasNext() override { return in.hasNext(); } /** * Get next element. * * \return pointer to element */ virtual const pointer_type& next() override { const JInput_t* p = in.next(); if (p != NULL) ps.reset(new JOutput_t(*p)); // type conversion else ps.reset(NULL); return ps; } protected: JObjectIterator<JInput_t>& in; private: pointer_type ps; }; } #endif