home *** CD-ROM | disk | FTP | other *** search
- /*******************************<+>***************************
- ** DTA
- *************************************************************
- **
- ** $Id: Iterator.h,v 1.7 1994/03/01 23:01:22 dta Exp $
- **
- ** $Source: /cvs/lib/odmg/Iterator.h,v $
- **
- ** What @(#):
- **
- ** Author: Dale T. Anderson
- **
- *******************************<+>***************************/
-
- #ifndef Iterator_h
- #define Iterator_h
-
- #include <Odmg/Ref.h>
-
- #define INVALID_POSITION (-1)
-
- template <class T> class Collection;
-
- template <class T>
- class Iterator
- {
- protected:
-
- Ref <Collection <T> > m_collection;
- Ref <T> m_ref;
- Position m_position;
-
- public:
-
- virtual void reset (void);
- virtual void close (void);
- virtual boolean next (Ref <T> &);
-
- //
- // Additions
- //
-
- Iterator (const Ref <Collection <T> >);
- virtual ~Iterator (void);
-
- Ref <T> &operator = (Iterator <T> &iter);
- Iterator <T> &operator = (Ref <T> &ref);
-
- Position get_position (void) const;
- void set_position (const Position position);
- };
-
- //
- // Methods
- //
-
- template <class T>
- Iterator<T>::Iterator (const Ref <Collection <T> > collection) :
- m_position (INVALID_POSITION),
- m_collection (collection)
- {
- }
-
- template <class T>
- Iterator<T>::~Iterator (void)
- {
- }
-
- template <class T>
- void Iterator<T>::reset (void)
- {
- m_position = INVALID_POSITION;
- }
-
- template <class T>
- void Iterator<T>::close (void)
- {
- cerr << "void Iterator<T>::close(void) - not implemented." << endl;
- }
-
- template <class T>
- boolean Iterator<T>::next (Ref <T> &ref)
- {
- if (++m_position < m_collection->cardinality ()) {
- ref = m_collection->retrieve_element_at (m_position);
- m_ref = ref;
- return TRUE;
- }
- return FALSE;
- }
-
- //
- // Additions
- //
-
- template <class T>
- Ref <T> &Iterator<T>::operator = (Iterator <T> &iter)
- {
- return iter.m_ref;
- }
-
- template <class T>
- Iterator <T> &Iterator<T>::operator = (Ref <T> &ref)
- {
- m_ref = ref;
- return *this;
- }
-
- template <class T>
- Position Iterator<T>::get_position (void) const
- {
- return m_position;
- }
-
- template <class T>
- void Iterator<T>::set_position (const Position position)
- {
- m_position = position;
- }
-
- #endif
-