Develop Biology
The language of life
UnorderedMotif.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 "AbstractMotif.h"
29#include <vector>
30#include <algorithm>
31
32namespace bio {
33namespace chemical {
34
39template < typename CONTENT_TYPE >
41 public chemical::Class< UnorderedMotif< CONTENT_TYPE > >,
42 public AbstractMotif
43{
44public:
45
47
53
54
58 :
59 chemical::Class< UnorderedMotif< CONTENT_TYPE > >(this) //TODO: Define Symmetry.
60 {
61 this->m_contents = new Contents(4);
62 }
63
67 UnorderedMotif(const Contents* contents)
68 :
69 chemical::Class< UnorderedMotif< CONTENT_TYPE > >(this) //TODO: Define Symmetry.
70 {
71 this->m_contents = new Contents(*contents);
72 }
73
78 :
79 chemical::Class< UnorderedMotif< CONTENT_TYPE > >(this) //TODO: Define Symmetry.
80 {
81 this->m_contents = new Contents(*toCopy->m_contents);
82 }
83
88 {
89 //NOTE: Children are responsible for clearing m_contents (e.g. through ClearImplementation()).
90 }
91
95 virtual void ClearImplementation()
96 {
97 this->m_contents->Clear();
98 }
99
104 virtual unsigned long GetCountImplementation() const
105 {
106 return this->m_contents->GetNumberOfElements();
107 }
108
114 virtual CONTENT_TYPE AddImplementation(const CONTENT_TYPE content)
115 {
116 CONTENT_TYPE ret = this->m_contents->Access(this->m_contents->Add(content));
117 return ret;
118 }
119
124 virtual CONTENT_TYPE RemoveImplementation(const CONTENT_TYPE content)
125 {
126 Index toErase = this->m_contents->SeekTo(content);
127 CONTENT_TYPE ret = this->m_contents->Access(toErase);
128 this->m_contents->Erase(toErase);
129 return ret;
130 }
131
137 virtual bool HasImplementation(const CONTENT_TYPE content) const
138 {
139 return this->m_contents->Has(content);
140 }
141
147 {
148 BIO_SANITIZE(other, ,
149 return);
150
151 this->m_contents->Import(other->GetAllImplementation());
152 }
153
159 virtual unsigned int GetNumMatchingImplementation(const Container* other) const
160 {
161 BIO_SANITIZE(other, ,
162 return 0);
163
164 unsigned int ret = 0;
165 for (
166 SmartIterator otr = other->End();
167 !otr.IsAtBeginning();
168 --otr
169 )
170 {
171 if (this->HasImplementation(*otr))
172 {
173 ++ret;
174 }
175 }
176 return ret;
177 }
178
184 virtual bool HasAllImplementation(const Container* contents) const
185 {
186 BIO_SANITIZE(contents, ,
187 return false);
188 return this->GetNumMatchingImplementation(contents) == contents->GetNumberOfElements();
189 }
190
196 virtual std::string GetStringFromImplementation(std::string separator = ", ")
197 {
198 std::string ret = "";
199 SmartIterator cnt = this->m_contents->Begin();
200 while (true)
201 {
202 ret += string::From< CONTENT_TYPE >(*cnt);
203 ++cnt;
204 if (cnt.IsAtEnd())
205 {
206 break;
207 }
208 ret += separator;
209 }
210 return ret;
211 }
212};
213
214} //chemical namespace
215} //bio namespace
#define BIO_SANITIZE(test, success, failure)
virtual SmartIterator End() const
Definition: Container.cpp:302
virtual SmartIterator Begin() const
Definition: Container.cpp:295
virtual ByteStream Access(const Index index)
Definition: Container.cpp:185
virtual void Clear()
Definition: Container.cpp:265
virtual Index GetNumberOfElements() const
Definition: Container.cpp:84
Index SeekTo(const ByteStream content) const
Definition: Container.cpp:209
virtual void Import(const Container *other)
Definition: Container.cpp:251
bool Has(const ByteStream content) const
Definition: Container.cpp:232
virtual Index Add(const ByteStream content)
Definition: Container.cpp:129
virtual bool Erase(Index index)
Definition: Container.cpp:237
bool IsAtBeginning() const
bool IsAtEnd() const
virtual Container * GetAllImplementation()
virtual std::string GetStringFromImplementation(std::string separator=", ")
virtual CONTENT_TYPE RemoveImplementation(const CONTENT_TYPE content)
virtual unsigned int GetNumMatchingImplementation(const Container *other) const
virtual void ClearImplementation()
virtual unsigned long GetCountImplementation() const
virtual void ImportImplementation(const UnorderedMotif< CONTENT_TYPE > *other)
physical::Arrangement< CONTENT_TYPE > Contents
UnorderedMotif(const Contents *contents)
virtual CONTENT_TYPE AddImplementation(const CONTENT_TYPE content)
virtual bool HasAllImplementation(const Container *contents) const
UnorderedMotif(const UnorderedMotif< CONTENT_TYPE > *toCopy)
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(chemical, UnorderedMotif< CONTENT_TYPE >) UnorderedMotif()
virtual bool HasImplementation(const CONTENT_TYPE content) const
Definition: Cell.h:31
uint32_t Index
Definition: Types.h:57