-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignalSample.cs
More file actions
115 lines (107 loc) · 5.21 KB
/
SignalSample.cs
File metadata and controls
115 lines (107 loc) · 5.21 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using RapidField.SolidInstruments.Core.ArgumentValidation;
using System;
namespace RapidField.SolidInstruments.SignalProcessing
{
/// <summary>
/// Represents the result of a read operation performed against an <see cref="IChannel{T}" />.
/// </summary>
/// <remarks>
/// <see cref="SignalSample{T}" /> is the default implementation of <see cref="ISignalSample{T}" />.
/// </remarks>
/// <typeparam name="T">
/// The type of the sampled channel's output value.
/// </typeparam>
public sealed class SignalSample<T> : ISignalSample<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="SignalSample{T}" /> class.
/// </summary>
/// <param name="unitOfOutput">
/// The discrete unit of output that was read from the channel's output stream.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="unitOfOutput" /> is <see langword="null" />.
/// </exception>
public SignalSample(IDiscreteUnitOfOutput<T> unitOfOutput)
: this(unitOfOutput, new OutputRange<T>())
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="SignalSample{T}" /> class.
/// </summary>
/// <param name="unitOfOutput">
/// The discrete unit of output that was read from the channel's output stream.
/// </param>
/// <param name="lookBehindRange">
/// A range of discrete units of output preceding <paramref name="unitOfOutput" /> in the channel's output stream, or an
/// empty range if look-behind was not requested.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="unitOfOutput" /> is <see langword="null" /> -or- <paramref name="lookBehindRange" /> is
/// <see langword="null" />.
/// </exception>
public SignalSample(IDiscreteUnitOfOutput<T> unitOfOutput, IOutputRange<T> lookBehindRange)
: this(unitOfOutput, lookBehindRange, new OutputRange<T>())
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="SignalSample{T}" /> class.
/// </summary>
/// <param name="unitOfOutput">
/// The discrete unit of output that was read from the channel's output stream.
/// </param>
/// <param name="lookBehindRange">
/// A range of discrete units of output preceding <paramref name="unitOfOutput" /> in the channel's output stream, or an
/// empty range if look-behind was not requested.
/// </param>
/// <param name="lookAheadRange">
/// A range of discrete units of output following <paramref name="unitOfOutput" /> in the channel's output stream, or an
/// empty range if look-ahead was not requested.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="unitOfOutput" /> is <see langword="null" /> -or- <paramref name="lookAheadRange" /> is
/// <see langword="null" /> -or- <paramref name="lookBehindRange" /> is <see langword="null" />.
/// </exception>
public SignalSample(IDiscreteUnitOfOutput<T> unitOfOutput, IOutputRange<T> lookBehindRange, IOutputRange<T> lookAheadRange)
{
UnitOfOutput = unitOfOutput.RejectIf().IsNull(nameof(unitOfOutput)).TargetArgument;
LookAheadRange = lookAheadRange.RejectIf().IsNull(nameof(lookAheadRange)).TargetArgument;
LookBehindRange = lookBehindRange.RejectIf().IsNull(nameof(lookBehindRange)).TargetArgument;
}
/// <summary>
/// Converts the value of the current <see cref="SignalSample{T}" /> to its equivalent string representation.
/// </summary>
/// <returns>
/// A string representation of the current <see cref="SignalSample{T}" />.
/// </returns>
public override String ToString() => $"{{ \"{nameof(UnitOfOutput)}\": {UnitOfOutput} }}";
/// <summary>
/// Gets a range of discrete units of output following <see cref="UnitOfOutput" /> in the channel's output stream, or an
/// empty range if look-ahead was not requested.
/// </summary>
public IOutputRange<T> LookAheadRange
{
get;
}
/// <summary>
/// Gets a range of discrete units of output preceding <see cref="UnitOfOutput" /> in the channel's output stream, or an
/// empty range if look-behind was not requested.
/// </summary>
public IOutputRange<T> LookBehindRange
{
get;
}
/// <summary>
/// Gets the discrete unit of output that was read from the channel's output stream.
/// </summary>
public IDiscreteUnitOfOutput<T> UnitOfOutput
{
get;
}
}
}