libbio
Loading...
Searching...
No Matches
Comparisons.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) 2024 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 "bio/common/Cast.h"
33#include <cstring>
34
35namespace bio {
36namespace arrangement_detail {
37
39 const String& externalName,
41)
42{
44 {
45 return true;
46 }
47 // Allow for compiler formatting differences like "class/struct/const" qualifiers.
51}
52
53template < typename T >
54inline typename type::EnableIf<
56 bool
58 const ByteStream& external,
59 const T& internalValue
60)
61{
62 if (external.GetSize() != sizeof(T))
63 {
64 return false;
65 }
66 const void* raw = external.DirectAccess();
67 BIO_SANITIZE(raw, , return false)
69 ::std::memcpy(&externalValue, raw, sizeof(T));
70 if (IsTypeNameEquivalent(external.GetTypeName(), type::TypeName< T >()))
71 {
73 }
74 // Allow wrapped primitives to compare by value even if type names differ.
76}
77
78template < typename T >
79inline typename type::EnableIf<
81 bool
83 const ByteStream&,
84 const T&
85)
86{
87 return false;
88}
89
90template < typename T >
91inline typename type::EnableIf<
93 bool
95 const ByteStream& external,
96 const T& internalValue
97)
98{
99 if (!external.IsPointerLike())
100 {
101 return false;
102 }
103 const void* raw = external.DirectAccess();
104 BIO_SANITIZE(raw, , return false)
105 if (external.GetSize() == sizeof(T))
106 {
108 BIO_SANITIZE(externalPtr, , return false)
109 return internalValue == *externalPtr;
110 }
112 {
113 typedef typename type::RemovePointer< T >::Type Pointee;
115 BIO_SANITIZE(externalPtr, , return false)
116 return internalValue == *externalPtr;
117 }
118 return false;
119}
120
121template < typename T >
122inline typename type::EnableIf<
124 bool
126 const ByteStream&,
127 const T&
128)
129{
130 return false;
131}
132
133} //arrangement_detail namespace
134} //bio namespace
#define BIO_SANITIZE(test, success, failure)
Definition SanitizeMacros.h:94
Definition ByteStream.h:63
Definition ImmutableString.h:38
Definition Pointer.h:115
Definition String.h:55
type::EnableIf< type::IsPointerImplementation< T >::sValue, bool >::Type CompareExternalPointer(const ByteStream &external, const T &internalValue)
Definition Comparisons.h:94
bool IsTypeNameEquivalent(const String &externalName, const ImmutableString &internalName)
Definition Comparisons.h:38
type::EnableIf< type::IsPrimitiveImplementation< T >::sValue, bool >::Type CompareExternalPrimitive(const ByteStream &external, const T &internalValue)
Definition Comparisons.h:57
String NormalizeTypeName(const String &name)
Definition NormalizeTypeName.h:41
Definition FinalCell.h:29
Definition EnableIf.h:34
Definition IsPointer.h:38
Definition IsPointer.h:79
Definition IsPrimitive.h:120