You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

88 lines
3.5 KiB

using System;
using gaemstone.Utility;
namespace gaemstone.ECS;
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
public class SourceAttribute<T> : Attribute { }
// TODO: Implement [Pair] somehow.
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
public class PairAttribute<TRelation, TTarget> : Attribute { }
public static class Pair<TRelation, TTarget>
{
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
public class RelationAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
public class TargetAttribute : Attribute { }
}
public readonly ref struct Has<T> { }
public readonly ref struct Has<TRelation, TTarget> { }
public readonly ref struct Not<T> { }
public readonly ref struct Not<TRelation, TTarget> { }
public readonly struct Or<T1, T2>
{
private readonly Union<T1, T2> _union;
public int Case { get; }
public Or(T1 value) { Case = 1; _union = new() { Value1 = value }; }
public Or(T2 value) { Case = 2; _union = new() { Value2 = value }; }
public T1 Value1 => (Case == 1) ? _union.Value1 : throw new InvalidOperationException();
public T2 Value2 => (Case == 2) ? _union.Value2 : throw new InvalidOperationException();
}
public readonly struct Or<T1, T2, T3>
{
private readonly Union<T1, T2, T3> _union;
public int Case { get; }
public Or(T1 value) { Case = 1; _union = new() { Value1 = value }; }
public Or(T2 value) { Case = 2; _union = new() { Value2 = value }; }
public Or(T3 value) { Case = 3; _union = new() { Value3 = value }; }
public T1 Value1 => (Case == 1) ? _union.Value1 : throw new InvalidOperationException();
public T2 Value2 => (Case == 2) ? _union.Value2 : throw new InvalidOperationException();
public T3 Value3 => (Case == 3) ? _union.Value3 : throw new InvalidOperationException();
}
public readonly struct Or<T1, T2, T3, T4>
{
private readonly Union<T1, T2, T3, T4> _union;
public int Case { get; }
public Or(T1 value) { Case = 1; _union = new() { Value1 = value }; }
public Or(T2 value) { Case = 2; _union = new() { Value2 = value }; }
public Or(T3 value) { Case = 3; _union = new() { Value3 = value }; }
public Or(T4 value) { Case = 4; _union = new() { Value4 = value }; }
public T1 Value1 => (Case == 1) ? _union.Value1 : throw new InvalidOperationException();
public T2 Value2 => (Case == 2) ? _union.Value2 : throw new InvalidOperationException();
public T3 Value3 => (Case == 3) ? _union.Value3 : throw new InvalidOperationException();
public T4 Value4 => (Case == 4) ? _union.Value4 : throw new InvalidOperationException();
}
public readonly struct Or<T1, T2, T3, T4, T5>
{
private readonly Union<T1, T2, T3, T4, T5> _union;
public int Case { get; }
public Or(T1 value) { Case = 1; _union = new() { Value1 = value }; }
public Or(T2 value) { Case = 2; _union = new() { Value2 = value }; }
public Or(T3 value) { Case = 3; _union = new() { Value3 = value }; }
public Or(T4 value) { Case = 4; _union = new() { Value4 = value }; }
public Or(T5 value) { Case = 5; _union = new() { Value5 = value }; }
public T1 Value1 => (Case == 1) ? _union.Value1 : throw new InvalidOperationException();
public T2 Value2 => (Case == 2) ? _union.Value2 : throw new InvalidOperationException();
public T3 Value3 => (Case == 3) ? _union.Value3 : throw new InvalidOperationException();
public T4 Value4 => (Case == 4) ? _union.Value4 : throw new InvalidOperationException();
public T5 Value5 => (Case == 5) ? _union.Value5 : throw new InvalidOperationException();
}