Develop Biology
The language of life
Container.h
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
22#pragma once
23
24#include "bio/common/Types.h"
26#include "bio/common/Cast.h"
27#include "SmartIterator.h"
28#include <deque>
29
30namespace bio {
31
32class Iterator;
33
62{
63public:
64
69 const Index expectedSize = 2,
70 std::size_t stepSize = sizeof(ByteStream));
71
77 Container(const Container& other);
78
82 virtual ~Container();
83
87 virtual Index GetBeginIndex() const;
88
92 virtual Index GetEndIndex() const;
93
97 virtual Index GetCapacity() const;
98
103 virtual Index GetAllocatedSize() const;
104
109 virtual Index GetNumberOfElements() const;
110
117 virtual bool IsFree(const Index index) const;
118
124 virtual bool IsInRange(const Index index) const;
125
130 virtual bool IsAllocated(const Index index) const;
131
136 virtual void Expand();
137
143 virtual Index Add(const ByteStream content);
144
155 virtual Index Insert(
156 const ByteStream content,
157 const Index index
158 );
159
167 virtual ByteStream Access(const Index index);
168
176 virtual const ByteStream Access(const Index index) const;
177
184 {
185 return Access(itt.GetIndex());
186 }
187
193 virtual const ByteStream Access(const SmartIterator itt) const
194 {
195 return Access(itt.GetIndex());
196 }
197
203 Index SeekTo(const ByteStream content) const;
204
209 bool Has(const ByteStream content) const;
210
216 virtual bool Erase(Index index);
217
223 inline bool Erase(const SmartIterator itt)
224 {
225 return Erase(itt.GetIndex());
226 }
227
231 virtual void Clear();
232
237 virtual void Import(const Container* other);
238
245 virtual ByteStream operator[](const Index index);
246
253 virtual const ByteStream operator[](const Index index) const;
254
261 virtual ByteStream operator[](const SmartIterator itt);
262
269 virtual const ByteStream operator[](const SmartIterator itt) const;
270
276 virtual Iterator* ConstructClassIterator(const Index index = InvalidIndex()) const;
277
282 virtual SmartIterator Begin() const;
283
288 virtual SmartIterator End() const;
289
296 template < typename T >
297 std::vector< T > AsVector() const
298 {
299 std::vector< T > ret;
300 for (
301 SmartIterator rct = End();
302 !rct.IsAtBeginning();
303 --rct
304 )
305 {
306 ret.push_back(rct.As< T >());
307 }
308 return ret;
309 }
310
311protected:
312
317 virtual const std::size_t GetStepSize() const;
318
325
332 virtual bool AreEqual(
333 Index internal,
334 const ByteStream external
335 ) const;
336
340 unsigned char* m_store;
341
344 std::deque< Index > m_deallocated;
345
351};
352
353} //bio namespace
virtual SmartIterator End() const
Definition: Container.cpp:302
std::vector< T > AsVector() const
Definition: Container.h:297
virtual SmartIterator Begin() const
Definition: Container.cpp:295
virtual ByteStream Access(const Index index)
Definition: Container.cpp:185
virtual Index GetCapacity() const
Definition: Container.cpp:74
virtual void Clear()
Definition: Container.cpp:265
virtual bool AreEqual(Index internal, const ByteStream external) const
Definition: Container.cpp:345
Container(const Index expectedSize=2, std::size_t stepSize=sizeof(ByteStream))
Definition: Container.cpp:29
unsigned char * m_store
Definition: Container.h:340
virtual bool IsInRange(const Index index) const
Definition: Container.cpp:89
virtual Index Insert(const ByteStream content, const Index index)
Definition: Container.cpp:141
virtual Index GetNextAvailableIndex()
Definition: Container.cpp:329
virtual Index GetNumberOfElements() const
Definition: Container.cpp:84
Index m_firstFree
Definition: Container.h:343
Index SeekTo(const ByteStream content) const
Definition: Container.cpp:209
bool Erase(const SmartIterator itt)
Definition: Container.h:223
virtual bool IsFree(const Index index) const
Definition: Container.cpp:94
virtual bool IsAllocated(const Index index) const
Definition: Container.cpp:107
virtual ByteStream operator[](const Index index)
Definition: Container.cpp:309
virtual Index GetAllocatedSize() const
Definition: Container.cpp:79
virtual const std::size_t GetStepSize() const
Definition: Container.cpp:353
virtual Index GetBeginIndex() const
Definition: Container.cpp:64
virtual void Import(const Container *other)
Definition: Container.cpp:251
ByteStream Access(const SmartIterator itt)
Definition: Container.h:183
virtual ~Container()
Definition: Container.cpp:53
bool Has(const ByteStream content) const
Definition: Container.cpp:232
virtual Index Add(const ByteStream content)
Definition: Container.cpp:129
std::deque< Index > m_deallocated
Definition: Container.h:344
virtual bool Erase(Index index)
Definition: Container.cpp:237
virtual Iterator * ConstructClassIterator(const Index index=InvalidIndex()) const
Definition: Container.cpp:285
virtual const ByteStream Access(const SmartIterator itt) const
Definition: Container.h:193
virtual void Expand()
Definition: Container.cpp:112
Iterator * m_tempItt
Definition: Container.h:350
virtual Index GetEndIndex() const
Definition: Container.cpp:69
Index GetIndex() const
bool IsAtBeginning() const
Definition: Cell.h:31
uint32_t Index
Definition: Types.h:57
const Index InvalidIndex()
Definition: Types.cpp:26