-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputPin.cs
48 lines (41 loc) · 1.17 KB
/
OutputPin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BangaiO
{
// Allows multiple inputs connected to one output, or zero inputs connected to one output -- simplifies code.
public class OutputPin<T>
{
private List<InputPin<T>> buffers = new List<InputPin<T>>();
private T[] oneElem = new T[1];
public void Connect(InputPin<T> buf)
{
if (buf == null)
throw new ArgumentNullException();
buffers.Add(buf);
}
public void Disconnect(InputPin<T> buf)
{
buffers.Remove(buf);
}
public void Write(T t)
{
oneElem[0] = t;
Write(oneElem, 0, 1);
}
public void Write(T[] data)
{
Write(data, 0, data.Length);
}
public void Write(T[] data, int count)
{
Write(data, 0, count);
}
public void Write(T[] data, int offset, int count)
{
foreach (InputPin<T> buf in buffers)
buf.Write(data, offset, count);
}
}
}