libbio
Loading...
Searching...
No Matches
TransparentWrapper.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) 2023 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 <ostream>
26
27namespace bio {
28
29//@formatter:off
30
62template < typename T >
64{
65public:
66 typedef T Type;
67
70 // NON-virtual since v12 (no vtable / no vptr). Never delete a subclass through
71 // a TransparentWrapper< T >* base pointer — see the class doc above.
73 {
74 #if BIO_CPP_VERSION >= 17
75 if BIO_CONSTEXPR(type::IsPointer<T>())
76 {
77 delete mT;
78 }
79 #endif
80 //FIXME: memory leaks when wrapping pointers on cpp < 17
81 }
82 operator T() {return mT;}
83// explicit operator const T() const {return mT;} // Breaks everything....
84
85 //START: Support for basic types
86 //TODO: Add pointer support for basic methods
87 TransparentWrapper<T>& operator=(const T& t) {mT = t; return *this;}
89 bool operator==(const T& t) const {return mT == t;}
90 bool operator!=(const T& t) const {return mT != t;}
91 bool operator<=(const T& t) const {return mT <= t;}
92 bool operator>=(const T& t) const {return mT >= t;}
93 bool operator<(const T& t) const {return mT < t;}
94 bool operator>(const T& t) const {return mT > t;}
95 bool operator==(const TransparentWrapper& other) const {return mT == other.mT;}
96 bool operator!=(const TransparentWrapper& other) const {return mT != other.mT;}
97 bool operator<=(const TransparentWrapper& other) const {return mT <= other.mT;}
98 bool operator>=(const TransparentWrapper& other) const {return mT >= other.mT;}
99 bool operator<(const TransparentWrapper& other) const {return mT < other.mT;}
100 bool operator>(const TransparentWrapper& other) const {return mT > other.mT;}
101 T& operator++() {return ++mT;}
102 T operator++(int) {return mT++;}
103 T& operator--() {return --mT;}
104 T operator--(int) {return mT--;}
105 T operator+=(const T& t) {return mT += t;}
106 T operator-=(const T& t) {return mT -= t;}
107 T operator+=(const TransparentWrapper& other) {return mT += other.mT;}
108 T operator-=(const TransparentWrapper& other) {return mT -= other.mT;}
109 T operator+(const T& t) const {return mT + t;}
110 T operator-(const T& t) const {return mT - t;}
111 T operator+(const TransparentWrapper& other) const {return mT + other.mT;}
112 T operator-(const TransparentWrapper& other) const {return mT - other.mT;}
113 T operator*=(const T& t) {return mT *= t;}
114 T operator/=(const T& t) {return mT /= t;}
115 T operator*=(const TransparentWrapper& other) {return mT *= other.mT;}
116 T operator/=(const TransparentWrapper& other) {return mT /= other.mT;}
117 T operator*(const T& t) const {return mT * t;}
118 T operator/(const T& t) const {return mT / t;}
119 T operator*(const TransparentWrapper& other) const {return mT * other.mT;}
120 T operator/(const TransparentWrapper& other) const {return mT / other.mT;}
121 friend ::std::ostream& operator <<(std::ostream& out, const TransparentWrapper& t)
122 {
123 out << t.mT;
124 return out;
125 }
126 //END: Support for basic types
127
128 //START: Support for pointers
130 if BIO_CONSTEXPR(type::IsPointer<T>())
131 {
132 return mT;
133 }
134 return &mT;
135 }
136 const T* operator->() const
137 {
138 if BIO_CONSTEXPR(type::IsPointer<T>())
139 {
140 return mT;
141 }
142 return &mT;
143 }
144 //END: Support for pointers
145
146 //that's all we're doing for now. Please add to this list as necessary
147
148 //public because we need to treat this as T when we don't know the T.
149public:
151};
152//@formatter:on
153
154} //bio namespace
#define BIO_CONSTEXPR
Definition KeywordMacros.h:29
Definition Pointer.h:115
Definition TransparentWrapper.h:64
T operator/=(const TransparentWrapper &other)
Definition TransparentWrapper.h:116
T operator+(const T &t) const
Definition TransparentWrapper.h:109
TransparentWrapper(T t)
Definition TransparentWrapper.h:68
bool operator>=(const T &t) const
Definition TransparentWrapper.h:92
T & operator++()
Definition TransparentWrapper.h:101
T operator-(const T &t) const
Definition TransparentWrapper.h:110
T operator-(const TransparentWrapper &other) const
Definition TransparentWrapper.h:112
bool operator<=(const TransparentWrapper &other) const
Definition TransparentWrapper.h:97
TransparentWrapper< T > & operator=(const T &t)
Definition TransparentWrapper.h:87
T mT
Definition TransparentWrapper.h:150
T operator/(const TransparentWrapper &other) const
Definition TransparentWrapper.h:120
TransparentWrapper< T > & operator=(const TransparentWrapper< T > &other)
Definition TransparentWrapper.h:88
T operator+(const TransparentWrapper &other) const
Definition TransparentWrapper.h:111
bool operator==(const TransparentWrapper &other) const
Definition TransparentWrapper.h:95
TransparentWrapper(const TransparentWrapper< T > &other)
Definition TransparentWrapper.h:69
bool operator!=(const T &t) const
Definition TransparentWrapper.h:90
T operator-=(const TransparentWrapper &other)
Definition TransparentWrapper.h:108
T operator+=(const TransparentWrapper &other)
Definition TransparentWrapper.h:107
T operator+=(const T &t)
Definition TransparentWrapper.h:105
T operator++(int)
Definition TransparentWrapper.h:102
bool operator>(const TransparentWrapper &other) const
Definition TransparentWrapper.h:100
T operator--(int)
Definition TransparentWrapper.h:104
bool operator>(const T &t) const
Definition TransparentWrapper.h:94
T operator*=(const TransparentWrapper &other)
Definition TransparentWrapper.h:115
bool operator<(const T &t) const
Definition TransparentWrapper.h:93
const T * operator->() const
Definition TransparentWrapper.h:136
T operator-=(const T &t)
Definition TransparentWrapper.h:106
T & operator--()
Definition TransparentWrapper.h:103
friend::std::ostream & operator<<(std::ostream &out, const TransparentWrapper &t)
Definition TransparentWrapper.h:121
T Type
Definition TransparentWrapper.h:66
bool operator!=(const TransparentWrapper &other) const
Definition TransparentWrapper.h:96
~TransparentWrapper()
Definition TransparentWrapper.h:72
bool operator<=(const T &t) const
Definition TransparentWrapper.h:91
T operator*(const TransparentWrapper &other) const
Definition TransparentWrapper.h:119
bool operator<(const TransparentWrapper &other) const
Definition TransparentWrapper.h:99
T operator*=(const T &t)
Definition TransparentWrapper.h:113
bool operator>=(const TransparentWrapper &other) const
Definition TransparentWrapper.h:98
T * operator->()
Definition TransparentWrapper.h:129
bool operator==(const T &t) const
Definition TransparentWrapper.h:89
T operator/=(const T &t)
Definition TransparentWrapper.h:114
T operator/(const T &t) const
Definition TransparentWrapper.h:118
T operator*(const T &t) const
Definition TransparentWrapper.h:117
Definition FinalCell.h:29