mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-18 16:10:26 +02:00
Moving corlib files out of "System" directory into root
This commit is contained in:
parent
4cd58262e4
commit
7dbfd15292
179 changed files with 3 additions and 0 deletions
81
BeefLibs/corlib/src/Int.bf
Normal file
81
BeefLibs/corlib/src/Int.bf
Normal file
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
|
||||
namespace System
|
||||
{
|
||||
struct Int : int, IInteger, IHashable, IFormattable, IOpComparable, IIsNaN, IOpNegatable, IOpAddable
|
||||
{
|
||||
public enum ParseError
|
||||
{
|
||||
case Ok;
|
||||
case NoValue;
|
||||
case InvalidChar(int partialResult);
|
||||
}
|
||||
|
||||
public static int operator<=>(Self a, Self b)
|
||||
{
|
||||
return (SelfBase)a <=> (SelfBase)b;
|
||||
}
|
||||
|
||||
public static Self operator+(Self lhs, Self rhs)
|
||||
{
|
||||
return (SelfBase)lhs + (SelfBase)rhs;
|
||||
}
|
||||
|
||||
public static Self operator-(Self value)
|
||||
{
|
||||
return (SelfBase)value;
|
||||
}
|
||||
|
||||
int IHashable.GetHashCode()
|
||||
{
|
||||
return (int)this;
|
||||
}
|
||||
|
||||
bool IIsNaN.IsNaN
|
||||
{
|
||||
[SkipCall]
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
||||
{
|
||||
if (sizeof(int) == sizeof(int64))
|
||||
{
|
||||
((int64)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
((int32)this).ToString(outString, format, formatProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ToString(String outString)
|
||||
{
|
||||
if (sizeof(int) == sizeof(int64))
|
||||
{
|
||||
((int64)this).ToString(outString);
|
||||
}
|
||||
else
|
||||
{
|
||||
((int32)this).ToString(outString);
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<int, ParseError> Parse(StringView val)
|
||||
{
|
||||
if (sizeof(int) == sizeof(int64))
|
||||
{
|
||||
var result = Int64.Parse(val);
|
||||
return *(Result<int, ParseError>*)&result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = Int32.Parse(val);
|
||||
return *(Result<int, ParseError>*)&result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue