libbio
Loading...
Searching...
No Matches
PlasmidPerspective.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) 2024 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
26
27namespace bio {
28
35{
36public:
38 {
39 if (name == InvalidName())
40 {
41 return InvalidId();
42 }
43
45 if (existing != InvalidId())
46 {
47 return existing;
48 }
49
50 const Id idFromGlobal = IdPerspective::Instance().GetIdWithoutCreation(name);
51 if (idFromGlobal != InvalidId())
52 {
53 EnsureBrane(idFromGlobal, name);
54 return idFromGlobal;
55 }
56
58 }
59
60private:
61 void EnsureBrane(const Id& id, const Name& name)
62 {
63 if (id == InvalidId() || name == InvalidName())
64 {
65 return;
66 }
67
68 SmartIterator brn = this->Find(id);
69 if (!brn.IsValid())
70 {
71 Pointer< physical::Brane< Id > > brane = this->CreateBrane(id, name);
72 this->RegisterBrane(brane);
73 if (this->mNextId <= id)
74 {
75 this->mNextId = id + 1;
76 }
77 return;
78 }
79
80 Pointer< physical::Brane< Id > > brane =
81 brn.As< Pointer< physical::Brane< Id > > >();
82 if (brane && brane->mName == InvalidName())
83 {
84 brane->mName = name;
85 }
86 }
87};
88
89BIO_SINGLETON(PlasmidPerspective, PlasmidPerspectiveImplementation)
90
91} //bio namespace
#define BIO_SINGLETON(className, baseClass)
Definition SingletonMacros.h:78
Definition PlasmidPerspective.h:35
Id GetIdFromName(const Name &name)
Definition PlasmidPerspective.h:37
Definition Pointer.h:115
Definition String.h:55
virtual DIMENSION GetIdFromName(const Name &name)
Definition Perspective.h:217
static Name InvalidName()
Definition Perspective.h:131
virtual DIMENSION GetIdWithoutCreation(const Name &name) const
Definition Perspective.h:345
static DIMENSION InvalidId()
Definition Perspective.h:122
DIMENSION mNextId
Definition Perspective.h:523
void RegisterBrane(Pointer< Brane< DIMENSION > > brane)
Definition Perspective.h:429
SmartIterator Find(const DIMENSION &id)
Definition Perspective.h:187
Definition TypedPerspective.h:41
virtual Pointer< Brane< Id > > CreateBrane(Id id, const Name &name)
Definition TypedPerspective.h:244
Definition FinalCell.h:29