using System; using System.Collections; using System.ComponentModel; namespace FastReport.Utils { /// /// Represents a collection of float values. /// [TypeConverter(typeof(FastReport.TypeConverters.FloatCollectionConverter))] public class FloatCollection : CollectionBase { /// /// Gets or sets the value at the specified index. /// /// Index of a value. /// The value at the specified index. public float this[int index] { get { return (float)List[index]; } set { List[index] = value; } } /// /// Adds the specified values to the end of this collection. /// /// public void AddRange(float[] range) { foreach (float t in range) { Add(t); } } /// /// Adds a value to the end of this collection. /// /// Value to add. /// Index of the added value. public int Add(float value) { return List.Add(value); } /// /// Inserts a value into this collection at the specified index. /// /// The zero-based index at which value should be inserted. /// The value to insert. public void Insert(int index, float value) { List.Insert(index, value); } /// /// Removes the specified value from the collection. /// /// Value to remove. public void Remove(float value) { int i = IndexOf(value); if (i != -1) List.RemoveAt(i); } /// /// Returns the zero-based index of the first occurrence of a value. /// /// The value to locate in the collection. /// The zero-based index of the first occurrence of value within the entire collection, if found; /// otherwise, -1. public int IndexOf(float value) { for (int i = 0; i < Count; i++) { if (Math.Abs(this[i] - value) < 0.01) return i; } return -1; } /// /// Determines whether a value is in the collection. /// /// The value to locate in the collection. /// true if value is found in the collection; otherwise, false. public bool Contains(float value) { return IndexOf(value) != -1; } /// /// Copies values from another collection. /// /// Collection to copy from. public void Assign(FloatCollection source) { Clear(); foreach (float f in source) { Add(f); } } } }