mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* Save work. * three billion tweaks * Rune-aware parser. * a * all shedded out for the night * a * oogh * Publicizes a lot of common generic commands, so custom toolshed envs can include them. * Implement parsing for all number types. * i think i might implode * a * Tests. * a * Enum parser test. * do u like parsers * oopls * ug fixes * Toolshed is approaching a non-insignificant part of the engine's size. * Pool toolshed's tests, also type tests. * bwa * tests pass :yay: * Update Robust.Shared/CVars.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * how did this not fail tests * awa * many levels of silly --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
|
|
namespace Robust.Shared.Toolshed.Commands.Math;
|
|
|
|
[ToolshedCommand]
|
|
public sealed class BIByteCountCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public int Operation<T>([PipedArgument] T x)
|
|
where T : IBinaryInteger<T>
|
|
{
|
|
return x.GetByteCount();
|
|
}
|
|
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<int> Operation<T>([PipedArgument] IEnumerable<T> x)
|
|
where T : IBinaryInteger<T>
|
|
=> x.Select(Operation);
|
|
}
|
|
|
|
[ToolshedCommand]
|
|
public sealed class ShortestBitLengthCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public int Operation<T>([PipedArgument] T x)
|
|
where T : IBinaryInteger<T>
|
|
{
|
|
return x.GetShortestBitLength();
|
|
}
|
|
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<int> Operation<T>([PipedArgument] IEnumerable<T> x)
|
|
where T : IBinaryInteger<T>
|
|
=> x.Select(Operation);
|
|
}
|
|
|
|
|
|
[ToolshedCommand]
|
|
public sealed class CountLeadZerosCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public T Operation<T>([PipedArgument] T x)
|
|
where T : IBinaryInteger<T>
|
|
{
|
|
return T.LeadingZeroCount(x);
|
|
}
|
|
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<T> Operation<T>([PipedArgument] IEnumerable<T> x)
|
|
where T : IBinaryInteger<T>
|
|
=> x.Select(Operation);
|
|
}
|
|
|
|
[ToolshedCommand]
|
|
public sealed class CountTrailingZerosCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public T Operation<T>([PipedArgument] T x)
|
|
where T : IBinaryInteger<T>
|
|
{
|
|
return T.TrailingZeroCount(x);
|
|
}
|
|
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<T> Operation<T>([PipedArgument] IEnumerable<T> x)
|
|
where T : IBinaryInteger<T>
|
|
=> x.Select(Operation);
|
|
}
|