Develop Biology
The language of life
Quantum.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) 2021 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 "Symmetry.h"
28#include "bio/common/TypeName.h"
29
30namespace bio {
31namespace physical {
32
40template < typename T >
41class Quantum :
42 public physical::Class< Quantum< T > >
43{
44public:
45
51
52
55 Quantum()
56 :
57 physical::Class< Quantum< T > >(
58 this,
59 new Symmetry(
60 TypeName< T >().c_str(),
61 symmetry_type::DefineVariable())),
62 m_quantized(new T())
63 {
64
65 }
66
70 Quantum(const T& assignment)
71 :
72 physical::Class< Quantum< T > >(
73 this,
74 new Symmetry(
75 TypeName< T >().c_str(),
76 symmetry_type::DefineVariable())),
77 m_quantized(new T(assignment))
78 {
79 }
80
84 Quantum(const Quantum< T >& other)
85 :
86 physical::Class< Quantum< T > >(
87 this,
88 new Symmetry(
89 TypeName< T >().c_str(),
90 symmetry_type::DefineVariable())),
91 m_quantized(new T(other))
92 {
93
94 }
95
99 virtual ~Quantum()
100 {
101 delete this->m_quantized;
102 }
103
108 operator T*()
109 {
110 return this->m_quantized;
111 }
112
118 operator T() const
119 {
121 return *this->m_quantized,
122 return T());
123 }
124
129 virtual Symmetry* Spin() const
130 {
131 this->m_symmetry->AccessValue()->Set(*this->m_quantized);
132 return this->Wave::Spin();
133 }
134
140 virtual Code Reify(Symmetry* symmetry)
141 {
142 BIO_SANITIZE(symmetry, ,
143 return code::BadArgument1());
144 //Wave::Reify(symmetry); //this does nothing useful.
145 *this->m_quantized = symmetry->GetValue();
146 return code::Success();
147 }
148
149protected:
151};
152
153} //physical namespace
154} //bio namespace
#define BIO_SANITIZE(test, success, failure)
void Set(T in)
Definition: ByteStream.h:147
Quantum(const T &assignment)
Definition: Quantum.h:70
virtual Code Reify(Symmetry *symmetry)
Definition: Quantum.h:140
virtual Symmetry * Spin() const
Definition: Quantum.h:129
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, Quantum< T >) Quantum()
Definition: Quantum.h:49
virtual ~Quantum()
Definition: Quantum.h:99
Quantum(const Quantum< T > &other)
Definition: Quantum.h:84
virtual const ByteStream & GetValue() const
Definition: Symmetry.cpp:125
virtual ByteStream * AccessValue()
Definition: Symmetry.cpp:130
virtual Symmetry * Spin() const
Definition: Wave.cpp:59
Symmetry * m_symmetry
Definition: Wave.h:272
Code BadArgument1()
Code Success()
SymmetryType DefineVariable()
Definition: Cell.h:31
const std::string TypeName()