using System;
using System.Collections.Generic;
using System.Text;

namespace DataPerformer
{
    public class DataIteratorConsumer : IteratorConsumer, IDataConsumer
    {

        #region Fields

        protected List<IMeasurements> measurements = new List<IMeasurements>();

        protected IDataConsumer consumer;
        
        #endregion

        #region Ctor

        protected DataIteratorConsumer()
        {
            consumer = this;
        }

        #endregion

        #region IDataConsumer Members

        void IDataConsumer.Add(IMeasurements measurements)
        {
            this.measurements.Add(measurements);
            SetIterators();
        }

        void IDataConsumer.Remove(IMeasurements measurements)
        {
            this.measurements.Remove(measurements);
            SetIterators();
        }

        void IDataConsumer.UpdateChildrenData()
        {
            foreach (IMeasurements m in measurements)
            {
                m.UpdateMeasurements();
            }
        }

        int IDataConsumer.Count
        {
            get { return measurements.Count; }
        }

        IMeasurements IDataConsumer.this[int n]
        {
            get { return measurements[n]; }
        }

        void IDataConsumer.Reset()
        {
            DataConsumer.Reset(this);
        }

        #endregion

        protected void SetIterators()
        {
            iterators.Clear();
            IteratorGLM.GetIterators(this, iterators);
        }
    }
}
