Develop Biology
The language of life
UnorderedStructureInterface.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
25#include "bio/chemical/Atom.h"
27
28namespace bio {
29namespace chemical {
30
35 virtual public ThreadSafe,
36 virtual public Atom
37{
38public:
39
44 {
45 }
46
51 {
52 }
53
54
62 template < typename T >
63 T Add(const T t)
64 {
65 T ret = 0;
66 LockThread();
67 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
68 if (implementer)
69 {
70 ret = implementer->AddImplementation(t);
71 }
73 return ret;
74 }
75
76
83 template < typename T >
84 T Remove(const T t)
85 {
86 T ret = 0;
87 LockThread();
88 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
89 if (implementer)
90 {
91 ret = implementer->RemoveImplementation(t);
92 }
94 return ret;
95 }
96
97
104 template < typename T >
105 void Import(const UnorderedMotif <T>* other)
106 {
107 LockThread();
108 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
109 if (implementer)
110 {
111 implementer->ImportImplementation(other);
112 }
113 UnlockThread();
114 }
115
123 template < typename T >
124 void Import(const std::vector< T >& other)
125 {
126 for (
127 typename std::vector< T >::const_iterator otr = other.begin();
128 otr != other.end();
129 ++otr
130 )
131 {
132 this->Add< T >(*otr);
133 }
134 }
135
142 Code ImportAll(const physical::Wave* other)
143 {
144 BIO_SANITIZE(other && other->AsAtom(), ,
145 return code::BadArgument1())
146
147 Code ret = code::Success();
148
149 LockThread(); // in case m_bonds changes.
150 Bond* bondBuffer;
151 for (
152 SmartIterator bnd = other->AsAtom()->GetAllBonds()->End();
153 !bnd.IsAtBeginning();
154 --bnd
155 )
156 {
157 bondBuffer = bnd;
158 if (bondBuffer->IsEmpty())
159 {
160 continue;
161 }
163 bondBuffer->GetBonded(),
165 {
166 continue;
167 }
168 const physical::Wave* otherBond = other->AsAtom()->GetBonded(other->AsAtom()->GetBondPosition(bondBuffer->GetId()));
169 (Cast< AbstractMotif* >(bondBuffer->GetBonded()))->ImportImplementation(otherBond); //actual work
170 }
171 UnlockThread();
172
173 return ret;
174 }
175
181 template < typename T >
182 unsigned long GetCount() const
183 {
184 unsigned long ret = 0;
185 LockThread();
186 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
187 if (implementer)
188 {
189 ret = implementer->GetCountImplementation();
190 }
191 UnlockThread();
192 return ret;
193 }
194
195
201 template < typename T >
203 {
204 Container* ret = 0;
205 LockThread();
206 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
207 if (implementer)
208 {
209 ret = implementer->GetAllImplementation();
210 }
211 UnlockThread();
212 return ret;
213 }
214
215
221 template < typename T >
222 const Container* GetAll() const
223 {
224 Container* ret = 0;
225 LockThread();
226 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
227 if (implementer)
228 {
229 ret = implementer->GetAllImplementation();
230 }
231 UnlockThread();
232 return ret;
233 }
234
235
242 template < typename T >
243 bool Has(T content) const
244 {
245 bool ret = false;
246 LockThread();
247 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
248 if (implementer)
249 {
250 ret = implementer->HasImplementation(content);
251 }
252 UnlockThread();
253 return ret;
254 }
255
261 template < typename T >
262 unsigned int GetNumMatching(const Container* other) const
263 {
264 unsigned int ret = 0;
265 LockThread();
266 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
267 if (implementer)
268 {
269 ret = implementer->GetNumMatchingImplementation(other);
270 }
271 UnlockThread();
272 return ret;
273 }
274
281 template < typename T >
282 bool HasAll(const Container* contents) const
283 {
284 bool ret = false;
285 LockThread();
286 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
287 if (implementer)
288 {
289 ret = implementer->HasAllImplementation(contents);
290 }
291 UnlockThread();
292 return ret;
293 }
294
301 template < typename T >
302 void Clear()
303 {
304 LockThread();
305 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
306 if (implementer)
307 {
308 implementer->ClearImplementation();
309 }
310 UnlockThread();
311 }
312
318 template < typename T >
319 std::string GetStringFrom(std::string separator = ", ")
320 {
321 std::string ret = "";
322 LockThread();
323 UnorderedMotif< T >* implementer = this->AsBonded< UnorderedMotif< T >* >();
324 if (implementer)
325 {
326 ret = implementer->GetStringFromImplementation(separator);
327 }
328 UnlockThread();
329 return ret;
330 }
331
337 template < typename T >
338 std::vector< T > GetAllAsVector()
339 {
340 return this->template GetAll< T >()->
341 template AsVector< T >();
342 }
343
349 template < typename T >
350 const std::vector< T > GetAllAsVector() const
351 {
352 return this->template GetAll< T >()->
353 template AsVector< T >();
354 }
355};
356
357} //chemical namespace
358} //bio namespace
#define BIO_SANITIZE(test, success, failure)
virtual SmartIterator End() const
Definition: Container.cpp:302
bool IsAtBeginning() const
void LockThread() const
Definition: ThreadSafe.cpp:84
void UnlockThread() const
Definition: ThreadSafe.cpp:97
static Properties GetClassProperties()
virtual Container * GetAllImplementation()
Wave * GetBonded(Valence position)
Definition: Atom.cpp:210
Bonds * GetAllBonds()
Definition: Atom.cpp:224
Valence GetBondPosition(AtomicNumber bondedId) const
Definition: Atom.cpp:168
bool IsEmpty() const
Definition: Bond.cpp:89
AtomicNumber GetId() const
Definition: Bond.cpp:69
physical::Wave * GetBonded()
Definition: Bond.cpp:74
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)
virtual CONTENT_TYPE AddImplementation(const CONTENT_TYPE content)
virtual bool HasAllImplementation(const Container *contents) const
virtual bool HasImplementation(const CONTENT_TYPE content) const
unsigned int GetNumMatching(const Container *other) const
void Import(const UnorderedMotif< T > *other)
std::string GetStringFrom(std::string separator=", ")
bool HasAll(const Container *contents) const
virtual chemical::Atom * AsAtom()
Definition: Wave.h:209
static Properties GetResonanceBetween(ConstWaves waves)
Definition: Wave.cpp:209
Code BadArgument1()
Code Success()
Definition: Cell.h:31