Develop Biology
The language of life
Localization.cpp
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
26
27namespace bio {
28namespace genetic {
29
30Localization::Localization(
31 Site site,
32 Name name
33)
34 :
35 physical::Class< Localization >(this),
36 m_name(NULL),
37 mc_method(NULL)
38{
39 SetNameOfSite(name);
40 SetSite(site);
41}
42
43Localization::~Localization()
44{
45 if (m_name)
46 {
47 delete[] m_name;
48 m_name = NULL;
49 }
50 if (mc_method)
51 {
52 delete mc_method;
53 mc_method = NULL;
54 }
55}
56
57chemical::Substance* Localization::ResolvePrevious(chemical::Substance* seekIn) const
58{
59 BIO_SANITIZE(seekIn, ,
60 return seekIn);
61
62 //TODO: What if *this has been Modulated with something other than a Localization?
63 Localization* previous = ForceCast< Localization* >(Demodulate());
64
65 if (previous)
66 {
67 seekIn = previous->Seek(seekIn);
68 }
69 return seekIn;
70}
71
72chemical::Substance* Localization::Seek(chemical::Substance* seekIn) const
73{
74 seekIn = ResolvePrevious(seekIn);
75
76 BIO_SANITIZE(seekIn, ,
77 return seekIn);
78
79 if (m_site == LocalizationSitePerspective::InvalidId())
80 {
81 return seekIn;
82 }
83
84 BIO_SANITIZE(mc_method, ,
85 return NULL)
86 ByteStream newName(m_name);
87 (const_cast< chemical::ExcitationBase* >(mc_method))->EditArg(
88 0,
89 newName
90 );
91 ByteStream result;
92 mc_method->CallDown(
93 seekIn->AsWave(),
94 result
95 );
96 chemical::Substance* extract = ChemicalCast< chemical::Substance* >(Cast< physical::Wave* >(result.IKnowWhatImDoing())); //This is about as safe as we can get right now.
97 BIO_SANITIZE(extract, ,
98 return NULL)
99 return extract;
100}
101
102void Localization::SetNameOfSite(Name name)
103{
104 if (m_name)
105 {
106 delete[] m_name;
107 }
109 name,
110 m_name
111 );
112}
113
114Name Localization::GetNameOfSite() const
115{
116 return m_name;
117}
118
119void Localization::SetSite(Site site)
120{
121 m_site = site;
122 if (mc_method)
123 {
124 delete mc_method;
125 }
126 mc_method = LocalizationSitePerspective::Instance().GetNewObjectFromIdAs< chemical::ExcitationBase* >(m_site);
127}
128
129Site Localization::GetSite() const
130{
131 return m_site;
132}
133
134} //genetic namespace
135} //bio namespace
#define BIO_SANITIZE(test, success, failure)
void * IKnowWhatImDoing()
Definition: ByteStream.cpp:78
virtual chemical::Substance * Seek(chemical::Substance *seekIn) const
virtual Wave * AsWave()
Definition: Class.h:99
void CloneInto(const char *source, const char *&target)
Definition: String.cpp:236
Definition: Cell.h:31
const char * Name
Definition: Types.h:46