using System;
using System.Runtime.CompilerServices;
namespace QuanTAlib;
///
/// Abstract base class for all indicators.
/// Enforces a consistent contract for State, Name, WarmupPeriod, and core methods.
///
public abstract class AbstractBase : ITValuePublisher, IDisposable
{
///
/// Display name for the indicator.
///
public string Name { get; protected init; } = string.Empty;
///
/// Number of periods before the indicator is considered "hot" (valid).
///
public int WarmupPeriod { get; protected init; }
///
/// Current value of the indicator.
///
public TValue Last { get; protected set; }
///
/// True if the indicator has enough data to produce valid results.
///
public abstract bool IsHot { get; }
///
/// Event triggered when a new TValue is available.
///
public event TValuePublishedHandler? Pub;
///
/// Helper to invoke the Pub event.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void PubEvent(TValue value, bool isNew = true)
{
Pub?.Invoke(this, new TValueEventArgs { Value = value, IsNew = isNew });
}
///
/// Initializes the indicator state using the provided history.
///
/// Historical data
/// Time interval between values (default: 1 second)
public abstract void Prime(ReadOnlySpan source, TimeSpan? step = null);
///
/// Updates the indicator with a single value.
///
/// Input value
/// True if this is a new bar, False if it's an update to the last bar
/// Updated value
public abstract TValue Update(TValue input, bool isNew = true);
///
/// Updates the indicator with a series of values.
///
/// Input series
/// Series of calculated values
public abstract TSeries Update(TSeries source);
///
/// Resets the indicator to its initial state.
///
public abstract void Reset();
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
}