From 0a6062ba022755ed135010c9a5846e156e000d4d Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Wed, 13 Dec 2023 16:54:23 +0100 Subject: [PATCH] added IParseable interface and applied it to all applicable types --- BeefLibs/corlib/src/Boolean.bf | 2 +- BeefLibs/corlib/src/Double.bf | 2 +- BeefLibs/corlib/src/Float.bf | 2 +- BeefLibs/corlib/src/Guid.bf | 4 ++-- BeefLibs/corlib/src/IParseable.bf | 11 +++++++++++ BeefLibs/corlib/src/Int.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Int16.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Int32.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Int64.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Int8.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Security/Cryptography/MD5.bf | 2 +- .../corlib/src/Security/Cryptography/SHA256.bf | 2 +- BeefLibs/corlib/src/UInt.bf | 16 +++++++++++++++- BeefLibs/corlib/src/UInt16.bf | 16 +++++++++++++++- BeefLibs/corlib/src/UInt32.bf | 16 +++++++++++++++- BeefLibs/corlib/src/UInt64.bf | 16 +++++++++++++++- BeefLibs/corlib/src/UInt8.bf | 16 +++++++++++++++- BeefLibs/corlib/src/Version.bf | 2 +- 18 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 BeefLibs/corlib/src/IParseable.bf diff --git a/BeefLibs/corlib/src/Boolean.bf b/BeefLibs/corlib/src/Boolean.bf index deaf0e09..3953b3a2 100644 --- a/BeefLibs/corlib/src/Boolean.bf +++ b/BeefLibs/corlib/src/Boolean.bf @@ -1,6 +1,6 @@ namespace System { - struct Boolean : bool, IHashable + struct Boolean : bool, IHashable, IParseable { // // Public Constants diff --git a/BeefLibs/corlib/src/Double.bf b/BeefLibs/corlib/src/Double.bf index 1ea43080..e6f30a14 100644 --- a/BeefLibs/corlib/src/Double.bf +++ b/BeefLibs/corlib/src/Double.bf @@ -10,7 +10,7 @@ namespace System using System.Diagnostics; #unwarn - public struct Double : double, IFloating, ISigned, IFormattable, IHashable, ICanBeNaN + public struct Double : double, IFloating, ISigned, IFormattable, IHashable, ICanBeNaN, IParseable { public const double MinValue = -1.7976931348623157E+308; public const double MaxValue = 1.7976931348623157E+308; diff --git a/BeefLibs/corlib/src/Float.bf b/BeefLibs/corlib/src/Float.bf index ed50ffb1..4676cb25 100644 --- a/BeefLibs/corlib/src/Float.bf +++ b/BeefLibs/corlib/src/Float.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable, ICanBeNaN + struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable, ICanBeNaN, IParseable { public const float MinValue = (float)-3.40282346638528859e+38; public const float Epsilon = (float)1.4e-45; diff --git a/BeefLibs/corlib/src/Guid.bf b/BeefLibs/corlib/src/Guid.bf index 03383a3f..52d159b9 100644 --- a/BeefLibs/corlib/src/Guid.bf +++ b/BeefLibs/corlib/src/Guid.bf @@ -1,6 +1,6 @@ namespace System { - struct Guid : IHashable + struct Guid : IHashable, IParseable { public static readonly Guid Empty = Guid(); @@ -58,7 +58,7 @@ namespace System (val1.mK == val2.mK); } - public static Result Parse(String str) + public static Result Parse(StringView val) { return .Err; } diff --git a/BeefLibs/corlib/src/IParseable.bf b/BeefLibs/corlib/src/IParseable.bf new file mode 100644 index 00000000..6d54b288 --- /dev/null +++ b/BeefLibs/corlib/src/IParseable.bf @@ -0,0 +1,11 @@ +namespace System; + +interface IParseable +{ + public static Result Parse(StringView val); +} + +interface IParseable +{ + public static Result Parse(StringView val); +} \ No newline at end of file diff --git a/BeefLibs/corlib/src/Int.bf b/BeefLibs/corlib/src/Int.bf index 1a782fce..c2f929e1 100644 --- a/BeefLibs/corlib/src/Int.bf +++ b/BeefLibs/corlib/src/Int.bf @@ -3,7 +3,7 @@ using System; namespace System { #unwarn - struct Int : int, IInteger, IHashable, IFormattable, IIsNaN + struct Int : int, IInteger, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -97,5 +97,19 @@ namespace System return *(Result*)&result; } } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Int16.bf b/BeefLibs/corlib/src/Int16.bf index 425a8c3c..c78178ca 100644 --- a/BeefLibs/corlib/src/Int16.bf +++ b/BeefLibs/corlib/src/Int16.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Int16 : int16, IInteger, ISigned, IHashable, IFormattable, IIsNaN + struct Int16 : int16, IInteger, ISigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -139,5 +139,19 @@ namespace System return isNeg ? -result : result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Int32.bf b/BeefLibs/corlib/src/Int32.bf index 7cef1110..4dda63d5 100644 --- a/BeefLibs/corlib/src/Int32.bf +++ b/BeefLibs/corlib/src/Int32.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Int32 : int32, IInteger, ISigned, IHashable, IFormattable, IIsNaN + struct Int32 : int32, IInteger, ISigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -188,5 +188,19 @@ namespace System return isNeg ? -result : result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Int64.bf b/BeefLibs/corlib/src/Int64.bf index 589c7ae2..d160e43d 100644 --- a/BeefLibs/corlib/src/Int64.bf +++ b/BeefLibs/corlib/src/Int64.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Int64 : int64, IInteger, ISigned, IFormattable, IHashable, IIsNaN + struct Int64 : int64, IInteger, ISigned, IFormattable, IHashable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -169,5 +169,19 @@ namespace System return isNeg ? -result : result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Int8.bf b/BeefLibs/corlib/src/Int8.bf index d4a10594..f0a2702f 100644 --- a/BeefLibs/corlib/src/Int8.bf +++ b/BeefLibs/corlib/src/Int8.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Int8 : int8, IInteger, ISigned, IHashable, IFormattable, IIsNaN + struct Int8 : int8, IInteger, ISigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -139,5 +139,19 @@ namespace System return isNeg ? -result : result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Security/Cryptography/MD5.bf b/BeefLibs/corlib/src/Security/Cryptography/MD5.bf index 8b40a62b..9a09adc8 100644 --- a/BeefLibs/corlib/src/Security/Cryptography/MD5.bf +++ b/BeefLibs/corlib/src/Security/Cryptography/MD5.bf @@ -32,7 +32,7 @@ namespace System.Security.Cryptography } } - struct MD5Hash + struct MD5Hash : IParseable { public uint8[16] mHash; diff --git a/BeefLibs/corlib/src/Security/Cryptography/SHA256.bf b/BeefLibs/corlib/src/Security/Cryptography/SHA256.bf index 6c365638..8a99fa5b 100644 --- a/BeefLibs/corlib/src/Security/Cryptography/SHA256.bf +++ b/BeefLibs/corlib/src/Security/Cryptography/SHA256.bf @@ -2,7 +2,7 @@ using System.IO; namespace System.Security.Cryptography { - struct SHA256Hash + struct SHA256Hash : IParseable { public uint8[32] mHash; diff --git a/BeefLibs/corlib/src/UInt.bf b/BeefLibs/corlib/src/UInt.bf index 354ddb63..3932fa22 100644 --- a/BeefLibs/corlib/src/UInt.bf +++ b/BeefLibs/corlib/src/UInt.bf @@ -1,7 +1,7 @@ namespace System { #unwarn - struct UInt : uint, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN + struct UInt : uint, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -87,5 +87,19 @@ namespace System return *(Result*)&result; } } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/UInt16.bf b/BeefLibs/corlib/src/UInt16.bf index bd9b8b9f..40c4469f 100644 --- a/BeefLibs/corlib/src/UInt16.bf +++ b/BeefLibs/corlib/src/UInt16.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct UInt16 : uint16, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN + struct UInt16 : uint16, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -134,5 +134,19 @@ namespace System return result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/UInt32.bf b/BeefLibs/corlib/src/UInt32.bf index c6705be7..f53ba571 100644 --- a/BeefLibs/corlib/src/UInt32.bf +++ b/BeefLibs/corlib/src/UInt32.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct UInt32 : uint32, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN + struct UInt32 : uint32, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -162,5 +162,19 @@ namespace System return result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/UInt64.bf b/BeefLibs/corlib/src/UInt64.bf index 223a212d..8ae6e3af 100644 --- a/BeefLibs/corlib/src/UInt64.bf +++ b/BeefLibs/corlib/src/UInt64.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct UInt64 : uint64, IInteger, IUnsigned, IHashable, IIsNaN, IFormattable + struct UInt64 : uint64, IInteger, IUnsigned, IHashable, IIsNaN, IFormattable, IParseable, IParseable { public enum ParseError { @@ -146,5 +146,19 @@ namespace System return result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/UInt8.bf b/BeefLibs/corlib/src/UInt8.bf index 32c0e8aa..ca5aae11 100644 --- a/BeefLibs/corlib/src/UInt8.bf +++ b/BeefLibs/corlib/src/UInt8.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct UInt8 : uint8, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN + struct UInt8 : uint8, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN, IParseable, IParseable { public enum ParseError { @@ -134,5 +134,19 @@ namespace System return result; } + + public static Result IParseable.Parse(StringView val) + { + return Parse(val); + } + + public static Result IParseable.Parse(StringView val) + { + var res = Parse(val); + if(res case .Err) + return .Err; + else + return .Ok(res.Value); + } } } diff --git a/BeefLibs/corlib/src/Version.bf b/BeefLibs/corlib/src/Version.bf index 2db8ae6f..ce18a9f3 100644 --- a/BeefLibs/corlib/src/Version.bf +++ b/BeefLibs/corlib/src/Version.bf @@ -1,6 +1,6 @@ namespace System { - struct Version + struct Version : IParseable { public uint32 Major; public uint32 Minor;