libbio
Loading...
Searching...
No Matches
chemical/common/Cast.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
27
28namespace bio {
29
30namespace physical {
31class Wave;
32}
33
34namespace chemical_cast_detail {
35
36template < typename TO, bool IS_POINTER >
38{
39 template < typename ATOM >
41 {
42 return atom->template As< TO >();
43 }
44};
45
46template < typename TO >
48{
49 template < typename ATOM >
51 {
52 typedef typename type::RemovePointer< TO >::Type Pointee;
54 Pointee* raw = wrapped.Get(); // BIO_RAW_POINTER_ALLOWLIST: cast internals unwrap to the raw address being cast
55 return raw;
56 }
57};
58
59} //chemical_cast_detail namespace
60
69template < typename TO, typename FROM >
71{
72 BIO_STATIC_ASSERT(type::IsPointer< FROM >())
73 // Null-safe: a NULL input (or a FROM with no Atom) yields NULL, never a
74 // deref. ChemicalCast's contract is "the bonded TO or 0", and callers
75 // routinely cast results that can legitimately be NULL (e.g. a GetByName
76 // miss); without this guard ChemicalCast< X* >(NULL) dereferenced NULL.
77 if (!toCast || !toCast->AsAtom())
78 {
79 return NULL;
80 }
82 TO,
84 >::Cast(toCast->AsAtom());
85}
86
92template < typename T >
94{
95 //Dereference here might be dangerous & need sanitization.
96 ::bio::physical::Wave* clone = toClone->Clone()->AsWave();
98}
99
100
101} //bio namespace
#define BIO_STATIC_ASSERT(condition)
Definition AssertMacros.h:34
Definition Pointer.h:115
T * Get() const
Definition Pointer.h:271
Definition Wave.h:82
Definition FinalCell.h:29
TO ChemicalCast(FROM toCast)
Definition chemical/common/Cast.h:70
TO Cast(FROM &toCast)
Definition common/Cast.h:160
T CloneAndCast(const T &toClone)
Definition chemical/common/Cast.h:93
static TO Cast(Pointer< ATOM > atom)
Definition chemical/common/Cast.h:50
Definition chemical/common/Cast.h:38
static TO Cast(Pointer< ATOM > atom)
Definition chemical/common/Cast.h:40
Definition IsPointer.h:38