#ifndef H_CORAL_ATOMITERATOR
#define H_CORAL_ATOMITERATOR
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#include <coral/core/Element.h>

namespace coral {

	/**
	 *
	 * AtomIterator iterates depth-first through
	 * a cone (of model elements). Changing the model
	 * while iterating is forbidden.
	 *
	 * This class is necessary since C++ does not
	 * support continuations / generators.
	 *
	 */
	class EXPORT_coral AtomIterator {
	public:
		enum iteration_type { TYPE_DFS };
		AtomIterator(Atom*, iteration_type type = TYPE_DFS);
		~AtomIterator();
		/**
		 * Discard current branch and jump to the next.
		 * Effective if 
		 */
		void discardCurrentBranch();
		/**
		 * Returns true if there are still elements left
		 * in the cone.
		 */
		bool hasNext();
		/**
		 * Returns the next element in the cone, or
		 * NULL if no elements exist anymore.
		 * Calling hasNext() before this is not necessary.
		 */
		Atom* next();
	private:
		autounrefvector<Atom*> m_parents;
		autounrefvector<Iterator*> m_slot_iterators;
		std::list<ElementDefinition::properties_type::const_iterator> m_properties_iterators;
		Atom* m_the_next;
		enum enum_status {
		     STATUS_NEWELEM,
		     STATUS_MM_ITERATE,
		     STATUS_MF_ITERATE,
		};
		enum_status m_status;

	};
}


#endif

