Tanoda
DelayBuffer.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap.Unity {
10
11 public class DelayBuffer<T> {
12
13 private RingBuffer<T> _buffer;
14
16 public RingBuffer<T> Buffer { get { return _buffer; } }
17
18 public int Count { get { return _buffer.Count; } }
19
20 public bool IsFull { get { return _buffer.IsFull; } }
21
22 public bool IsEmpty { get { return _buffer.IsEmpty; } }
23
24 public int Capacity { get { return _buffer.Capacity; } }
25
26 public void Clear() { _buffer.Clear(); }
27
28 public DelayBuffer(int bufferSize) {
29 _buffer = new RingBuffer<T>(bufferSize);
30 }
31
34 public bool Add(T t, out T delayedT) {
35 bool willOutputValue;
36 if (_buffer.IsFull) {
37 willOutputValue = true;
38 delayedT = _buffer.GetOldest();
39 }
40 else {
41 willOutputValue = false;
42 delayedT = default(T);
43 }
44 _buffer.Add(t);
45 return willOutputValue;
46 }
47
48 }
49
50}
DelayBuffer(int bufferSize)
Definition: DelayBuffer.cs:28
RingBuffer< T > Buffer
Returns the underlying Buffer object.
Definition: DelayBuffer.cs:16
bool Add(T t, out T delayedT)
Returns true if the buffer was full and out "delayedT" will contain the oldest value in the buffer,...
Definition: DelayBuffer.cs:34