Develop Biology
The language of life
bio::Iterator Class Reference

#include <Iterator.h>

+ Collaboration diagram for bio::Iterator:

Public Member Functions

 Iterator (const Container *container, const Index index=InvalidIndex())
 
virtual ~Iterator ()
 
virtual IteratorDecrement ()
 
Index GetIndex () const
 
virtual IteratorIncrement ()
 
virtual bool IsAtBeginning () const
 
virtual bool IsAtEnd () const
 
bool MoveTo (const Index index)
 
virtual ByteStream operator* ()
 
virtual const ByteStream operator* () const
 

Protected Attributes

Containerm_container
 
Index m_index
 

Detailed Description

An Iterator is the preferred means of accessing the elements stored in an Container. Please use increment and decrement operators to move through these elements. While untested, it is likely that starting at the end and decrementing will be faster than starting at the beginning and incrementing, due to removing the overhead of having to keep track of where the end is.

NOTE: There are no checks to guard against being given a bad Container*. These have been neglected to increase performance.

Definition at line 38 of file Iterator.h.

Constructor & Destructor Documentation

◆ Iterator()

bio::Iterator::Iterator ( const Container container,
const Index  index = InvalidIndex() 
)

Constructor is only built with a const Container*. We cast away the cv and keep only the mutable pointer. This is done in order to avoid having a separate class for const access (as is in the standard library).

Parameters
container
index

Definition at line 27 of file Iterator.cpp.

31 :
32 m_container(const_cast< Container* >(container)),
33 m_index(index)
34{
35
36}
Index m_index
Definition: Iterator.h:106
Container * m_container
Definition: Iterator.h:105

◆ ~Iterator()

bio::Iterator::~Iterator ( )
virtual

Definition at line 38 of file Iterator.cpp.

39{
40
41}

Member Function Documentation

◆ Decrement()

Iterator * bio::Iterator::Decrement ( )
virtual

Move *this down a Index.

Returns
*this following decrementing.

Definition at line 82 of file Iterator.cpp.

83{
84 if (!m_index)
85 {
86 return this;
87 }
88 while (m_container->IsFree(--m_index) && !IsAtBeginning())
89 {
90 continue; //avoid re-referencing m_index; see condition.
91 }
92 return this;
93}
virtual bool IsFree(const Index index) const
Definition: Container.cpp:94
virtual bool IsAtBeginning() const
Definition: Iterator.cpp:58

References IsAtBeginning(), bio::Container::IsFree(), m_container, and m_index.

Referenced by bio::SmartIterator::operator--().

◆ GetIndex()

Index bio::Iterator::GetIndex ( ) const
Returns
the index *this is currently at.

Definition at line 43 of file Iterator.cpp.

44{
45 return m_index;
46}

References m_index.

Referenced by bio::Container::Clear(), bio::SmartIterator::GetIndex(), bio::Container::SeekTo(), bio::physical::Line::SeekToId(), and bio::physical::Line::SeekToName().

◆ Increment()

Iterator * bio::Iterator::Increment ( )
virtual

Move *this up a Index

Returns
*this after incrementing.

Definition at line 68 of file Iterator.cpp.

69{
71 {
73 return this;
74 }
75 while (m_container->IsFree(++m_index) && !IsAtEnd())
76 {
77 continue; //avoid re-referencing m_index; see condition.
78 }
79 return this;
80}
virtual Index GetAllocatedSize() const
Definition: Container.cpp:79
virtual bool IsAtEnd() const
Definition: Iterator.cpp:63

References bio::Container::GetAllocatedSize(), IsAtEnd(), bio::Container::IsFree(), m_container, and m_index.

Referenced by bio::SmartIterator::operator++().

◆ IsAtBeginning()

bool bio::Iterator::IsAtBeginning ( ) const
virtual
Returns
whether or not *this has reached the beginning of its Arrangement.

Definition at line 58 of file Iterator.cpp.

59{
60 return !m_index;
61}

References m_index.

Referenced by bio::Container::Clear(), Decrement(), bio::Container::Import(), bio::SmartIterator::IsAtBeginning(), bio::Container::SeekTo(), bio::physical::Line::SeekToId(), and bio::physical::Line::SeekToName().

◆ IsAtEnd()

bool bio::Iterator::IsAtEnd ( ) const
virtual
Returns
whether or not *this has reached the end of its Arrangement.

Definition at line 63 of file Iterator.cpp.

64{
66}

References bio::Container::GetAllocatedSize(), m_container, and m_index.

Referenced by Increment(), and bio::SmartIterator::IsAtEnd().

◆ MoveTo()

bool bio::Iterator::MoveTo ( const Index  index)

Make *this point somewhere else;

Parameters
index
Returns
whether or not *this was moved.

Definition at line 48 of file Iterator.cpp.

49{
50 if (m_container->IsAllocated(index))
51 {
52 m_index = index;
53 return true;
54 }
55 return false;
56}
virtual bool IsAllocated(const Index index) const
Definition: Container.cpp:107

References bio::Container::IsAllocated(), m_container, and m_index.

Referenced by bio::Container::Clear(), bio::SmartIterator::MoveTo(), bio::Container::SeekTo(), bio::physical::Line::SeekToId(), and bio::physical::Line::SeekToName().

◆ operator*() [1/2]

ByteStream bio::Iterator::operator* ( )
virtual

Dereferencing gives the datum *this is currently pointing to.

Returns
a ByteStream containing the datum requested.

Definition at line 95 of file Iterator.cpp.

96{
97 return m_container->Access(m_index);
98}
virtual ByteStream Access(const Index index)
Definition: Container.cpp:185

References bio::Container::Access(), m_container, and m_index.

◆ operator*() [2/2]

const ByteStream bio::Iterator::operator* ( ) const
virtual

Dereferencing gives the datum *this is currently pointing to.

Returns
a ByteStream containing the datum requested.

Definition at line 100 of file Iterator.cpp.

101{
102 return m_container->Access(m_index);
103}

References bio::Container::Access(), m_container, and m_index.

Member Data Documentation

◆ m_container

Container* bio::Iterator::m_container
mutableprotected

Definition at line 105 of file Iterator.h.

Referenced by Decrement(), Increment(), IsAtEnd(), MoveTo(), and operator*().

◆ m_index

Index bio::Iterator::m_index
protected

Definition at line 106 of file Iterator.h.

Referenced by Decrement(), GetIndex(), Increment(), IsAtBeginning(), IsAtEnd(), MoveTo(), and operator*().


The documentation for this class was generated from the following files: