libbio
Loading...
Searching...
No Matches
TypedPerspective.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 "Perspective.h"
29
30namespace bio {
31namespace physical {
32
38template < typename DIMENSION >
40 public Perspective< DIMENSION >
41{
42public:
47 {
48
49 }
50
55 {
56
57 }
58
73 virtual bool AssociateType(
74 const DIMENSION& id,
76 )
77 {
78 BIO_SANITIZE(type, , return false)
81 BIO_SANITIZE(brane, , return false)
82 if (brane->mType)
83 {
84 return false;
85 }
86 brane->mType = type;
87 return true;
88 }
89
96 virtual bool DisassociateType(const DIMENSION& id)
97 {
100 BIO_SANITIZE(brane, , return false)
101 if (brane->mType)
102 {
103 Delete(brane->mType);
104 brane->mType = NULL;
105 }
106 return true;
107 }
108
114 virtual bool IsTypeAssociated(const DIMENSION& id) const
115 {
116 const SmartIterator brn = this->Find(id);
117 return brn.IsValid();
118 }
119
126 {
129 BIO_SANITIZE(brane, , return NULL)
130 return brane->mType;
131 }
132
139 {
140 const DIMENSION id = this->GetIdWithoutCreation(name);
142 {
143 return NULL;
144 }
145 return this->GetTypeFromId(id);
146 }
147
154 template < typename T >
155 const T GetTypeFromIdAs(const DIMENSION& id) const
156 {
157 BIO_STATIC_ASSERT(type::IsPointer< T >())
160 return NULL
161 )
162 }
163
170 template < typename T >
171 const T GetTypeFromNameAs(const Name& name) const
172 {
173 BIO_STATIC_ASSERT(type::IsPointer< T >())
176 return NULL
177 )
178 }
179
186 {
187 Pointer< const Wave > type = this->GetTypeFromId(id);
188 BIO_SANITIZE(type, , return NULL)
189 return type->Clone();
190 }
191
198 {
199 Pointer< const Wave > type = this->GetTypeFromName(name);
200 BIO_SANITIZE(type, , return NULL)
201 return type->Clone();
202 }
203
210 template < typename T >
212 {
213 BIO_STATIC_ASSERT(type::IsPointer< T >())
214 BIO_STATIC_ASSERT(type::IsWave< T >())
217 return *(ForceCast< Pointer< physical::Class< T > > >(RESULT)->GetWaveObject()) //GetWaveObject gives T, which, if T is a pointer-wrapper, is a nested pointer handle.
218 ),
219 return NULL
220 )
221 }
222
229 template < typename T >
231 {
232 return this->GetNewObjectFromIdAs< T >(this->GetIdWithoutCreation(name));
233 }
234
235
236protected:
237
245 {
246 return new TypedBrane< DIMENSION >(id, name, NULL);
247 }
248};
249
250} //physical namespace
251} //bio namespace
#define BIO_STATIC_ASSERT(condition)
Definition AssertMacros.h:34
#define BIO_SANITIZE(test, success, failure)
Definition SanitizeMacros.h:94
#define BIO_SANITIZE_WITH_CACHE(test, success, failure)
Definition SanitizeMacros.h:118
Definition Pointer.h:115
Definition SmartIterator.h:40
bool IsValid() const
Definition SmartIterator.cpp:79
Definition String.h:55
Definition physical/common/Class.h:56
Definition Perspective.h:69
virtual DIMENSION GetIdWithoutCreation(const Name &name) const
Definition Perspective.h:345
SmartIterator Find(const DIMENSION &id)
Definition Perspective.h:187
Definition TypedPerspective.h:41
const T GetTypeFromNameAs(const Name &name) const
Definition TypedPerspective.h:171
T GetNewObjectFromIdAs(const DIMENSION &id)
Definition TypedPerspective.h:211
virtual ~TypedPerspective()
Definition TypedPerspective.h:54
virtual Pointer< const Wave > GetTypeFromName(const Name &name) const
Definition TypedPerspective.h:138
virtual bool DisassociateType(const DIMENSION &id)
Definition TypedPerspective.h:96
virtual Pointer< const Wave > GetTypeFromId(const DIMENSION &id) const
Definition TypedPerspective.h:125
virtual Pointer< Wave > GetNewObjectFromId(const DIMENSION &id) const
Definition TypedPerspective.h:185
const T GetTypeFromIdAs(const DIMENSION &id) const
Definition TypedPerspective.h:155
virtual bool IsTypeAssociated(const DIMENSION &id) const
Definition TypedPerspective.h:114
virtual Pointer< Brane< DIMENSION > > CreateBrane(DIMENSION id, const Name &name)
Definition TypedPerspective.h:244
T GetNewObjectFromNameAs(const Name &name)
Definition TypedPerspective.h:230
TypedPerspective()
Definition TypedPerspective.h:46
virtual Pointer< Wave > GetNewObjectFromName(const Name &name)
Definition TypedPerspective.h:197
virtual bool AssociateType(const DIMENSION &id, Pointer< physical::Wave > type)
Definition TypedPerspective.h:73
#define BIO_SINGLE_ARG(...)
Definition common/macro/Macros.h:68
Definition FinalCell.h:29
void Delete(Pointer< T > wrapped)
Definition Pointer.h:412
TO ForceCast(FROM &toCast)
Definition common/Cast.h:223