mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
103 lines
2.8 KiB
C#
103 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Artemis.Core
|
|
{
|
|
/// <summary>
|
|
/// Represents a collection of input pins containing values of type <typeparamref name="T" />
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of value the pins in this collection hold</typeparam>
|
|
public sealed class InputPinCollection<T> : PinCollection
|
|
{
|
|
#region Constructors
|
|
|
|
internal InputPinCollection(INode node, string name, int initialCount)
|
|
: base(node, name, initialCount)
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <inheritdoc />
|
|
protected override IPin CreatePin()
|
|
{
|
|
return new InputPin<T>(Node, string.Empty);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties & Fields
|
|
|
|
/// <inheritdoc />
|
|
public override PinDirection Direction => PinDirection.Input;
|
|
|
|
/// <inheritdoc />
|
|
public override Type Type => typeof(T);
|
|
|
|
/// <summary>
|
|
/// Gets an enumerable of the pins in this collection
|
|
/// </summary>
|
|
public new IEnumerable<InputPin<T>> Pins => base.Pins.Cast<InputPin<T>>();
|
|
|
|
/// <summary>
|
|
/// Gets an enumerable of the values of the pins in this collection
|
|
/// </summary>
|
|
public IEnumerable<T> Values => Pins.Where(p => p.Value != null).Select(p => p.Value!);
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a collection of input pins
|
|
/// </summary>
|
|
public sealed class InputPinCollection : PinCollection
|
|
{
|
|
#region Constructors
|
|
|
|
internal InputPinCollection(INode node, Type type, string name, int initialCount)
|
|
: base(node, name, 0)
|
|
{
|
|
Type = type;
|
|
|
|
// Can't do this in the base constructor because the type won't be set yet
|
|
for (int i = 0; i < initialCount; i++)
|
|
AddPin();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <inheritdoc />
|
|
protected override IPin CreatePin()
|
|
{
|
|
return new InputPin(Node, Type, string.Empty);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties & Fields
|
|
|
|
/// <inheritdoc />
|
|
public override PinDirection Direction => PinDirection.Input;
|
|
|
|
/// <inheritdoc />
|
|
public override Type Type { get; }
|
|
|
|
/// <summary>
|
|
/// Gets an enumerable of the pins in this collection
|
|
/// </summary>
|
|
public new IEnumerable<InputPin> Pins => base.Pins.Cast<InputPin>();
|
|
|
|
/// <summary>
|
|
/// Gets an enumerable of the values of the pins in this collection
|
|
/// </summary>
|
|
public IEnumerable Values => Pins.Where(p => p.Value != null).Select(p => p.Value);
|
|
|
|
#endregion
|
|
}
|
|
} |