mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-23 10:08:00 +02:00
Merge pull request #1911 from Booklordofthedings/master
added IParseable interface and applied it to all applicable types
This commit is contained in:
commit
3f7fc178e5
18 changed files with 169 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
namespace System
|
||||
{
|
||||
struct Boolean : bool, IHashable
|
||||
struct Boolean : bool, IHashable, IParseable<bool>
|
||||
{
|
||||
//
|
||||
// Public Constants
|
||||
|
|
|
@ -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<double>
|
||||
{
|
||||
public const double MinValue = -1.7976931348623157E+308;
|
||||
public const double MaxValue = 1.7976931348623157E+308;
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Globalization;
|
|||
namespace System
|
||||
{
|
||||
#unwarn
|
||||
struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable<float>, ICanBeNaN
|
||||
struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable<float>, ICanBeNaN, IParseable<float>
|
||||
{
|
||||
public const float MinValue = (float)-3.40282346638528859e+38;
|
||||
public const float Epsilon = (float)1.4e-45;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace System
|
||||
{
|
||||
struct Guid : IHashable
|
||||
struct Guid : IHashable, IParseable<Guid>
|
||||
{
|
||||
public static readonly Guid Empty = Guid();
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace System
|
|||
(val1.mK == val2.mK);
|
||||
}
|
||||
|
||||
public static Result<Guid> Parse(String str)
|
||||
public static Result<Guid> Parse(StringView val)
|
||||
{
|
||||
return .Err;
|
||||
}
|
||||
|
|
11
BeefLibs/corlib/src/IParseable.bf
Normal file
11
BeefLibs/corlib/src/IParseable.bf
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace System;
|
||||
|
||||
interface IParseable<T>
|
||||
{
|
||||
public static Result<T> Parse(StringView val);
|
||||
}
|
||||
|
||||
interface IParseable<T, TErr>
|
||||
{
|
||||
public static Result<T,TErr> Parse(StringView val);
|
||||
}
|
|
@ -3,7 +3,7 @@ using System;
|
|||
namespace System
|
||||
{
|
||||
#unwarn
|
||||
struct Int : int, IInteger, IHashable, IFormattable, IIsNaN
|
||||
struct Int : int, IInteger, IHashable, IFormattable, IIsNaN, IParseable<int, ParseError>, IParseable<int>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -97,5 +97,19 @@ namespace System
|
|||
return *(Result<int, ParseError>*)&result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<int, ParseError> IParseable<int, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<int> IParseable<int>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<int16, ParseError>, IParseable<int16>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -139,5 +139,19 @@ namespace System
|
|||
|
||||
return isNeg ? -result : result;
|
||||
}
|
||||
|
||||
public static Result<int16, ParseError> IParseable<int16, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<int16> IParseable<int16>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<int32, ParseError>, IParseable<int32>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -188,5 +188,19 @@ namespace System
|
|||
|
||||
return isNeg ? -result : result;
|
||||
}
|
||||
|
||||
public static Result<int32, ParseError> IParseable<int32, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<int32> IParseable<int32>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<int64, ParseError>, IParseable<int64>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -169,5 +169,19 @@ namespace System
|
|||
|
||||
return isNeg ? -result : result;
|
||||
}
|
||||
|
||||
public static Result<int64, ParseError> IParseable<int64, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<int64> IParseable<int64>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<int8, ParseError>, IParseable<int8>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -139,5 +139,19 @@ namespace System
|
|||
|
||||
return isNeg ? -result : result;
|
||||
}
|
||||
|
||||
public static Result<int8, ParseError> IParseable<int8, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<int8> IParseable<int8>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace System.Security.Cryptography
|
|||
}
|
||||
}
|
||||
|
||||
struct MD5Hash
|
||||
struct MD5Hash : IParseable<MD5Hash>
|
||||
{
|
||||
public uint8[16] mHash;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ using System.IO;
|
|||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
struct SHA256Hash
|
||||
struct SHA256Hash : IParseable<SHA256Hash>
|
||||
{
|
||||
public uint8[32] mHash;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace System
|
||||
{
|
||||
#unwarn
|
||||
struct UInt : uint, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN
|
||||
struct UInt : uint, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN, IParseable<uint, ParseError>, IParseable<uint>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -87,5 +87,19 @@ namespace System
|
|||
return *(Result<uint, ParseError>*)&result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<uint, ParseError> IParseable<uint, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<uint> IParseable<uint>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<uint16, ParseError>, IParseable<uint16>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -134,5 +134,19 @@ namespace System
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result<uint16, ParseError> IParseable<uint16, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<uint16> IParseable<uint16>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<uint32, ParseError>, IParseable<uint32>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -162,5 +162,19 @@ namespace System
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result<uint32, ParseError> IParseable<uint32, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<uint32> IParseable<uint32>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<uint64, ParseError>, IParseable<uint64>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -146,5 +146,19 @@ namespace System
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result<uint64, ParseError> IParseable<uint64, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<uint64> IParseable<uint64>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<uint8, ParseError>, IParseable<uint8>
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
|
@ -134,5 +134,19 @@ namespace System
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result<uint8, ParseError> IParseable<uint8, ParseError>.Parse(StringView val)
|
||||
{
|
||||
return Parse(val);
|
||||
}
|
||||
|
||||
public static Result<uint8> IParseable<uint8>.Parse(StringView val)
|
||||
{
|
||||
var res = Parse(val);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
else
|
||||
return .Ok(res.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace System
|
||||
{
|
||||
struct Version
|
||||
struct Version : IParseable<Version>
|
||||
{
|
||||
public uint32 Major;
|
||||
public uint32 Minor;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue