Develop Biology
The language of life
Iterator.cpp
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2022 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
24
25namespace bio {
26
28 const Container* container,
29 const Index index
30)
31 :
32 m_container(const_cast< Container* >(container)),
33 m_index(index)
34{
35
36}
37
39{
40
41}
42
44{
45 return m_index;
46}
47
48bool Iterator::MoveTo(const Index index)
49{
50 if (m_container->IsAllocated(index))
51 {
52 m_index = index;
53 return true;
54 }
55 return false;
56}
57
59{
60 return !m_index;
61}
62
64{
66}
67
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}
81
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}
94
96{
97 return m_container->Access(m_index);
98}
99
101{
102 return m_container->Access(m_index);
103}
104
105} //bio namespace
virtual ByteStream Access(const Index index)
Definition: Container.cpp:185
virtual bool IsFree(const Index index) const
Definition: Container.cpp:94
virtual bool IsAllocated(const Index index) const
Definition: Container.cpp:107
virtual Index GetAllocatedSize() const
Definition: Container.cpp:79
bool MoveTo(const Index index)
Definition: Iterator.cpp:48
Index m_index
Definition: Iterator.h:106
virtual bool IsAtBeginning() const
Definition: Iterator.cpp:58
virtual ~Iterator()
Definition: Iterator.cpp:38
virtual Iterator * Increment()
Definition: Iterator.cpp:68
Index GetIndex() const
Definition: Iterator.cpp:43
Iterator(const Container *container, const Index index=InvalidIndex())
Definition: Iterator.cpp:27
Container * m_container
Definition: Iterator.h:105
virtual bool IsAtEnd() const
Definition: Iterator.cpp:63
virtual ByteStream operator*()
Definition: Iterator.cpp:95
virtual Iterator * Decrement()
Definition: Iterator.cpp:82
Definition: Cell.h:31
uint32_t Index
Definition: Types.h:57