using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace FastReport.Utils
{
///
/// Represents a collection of FastReport base objects.
///
public class FRCollectionBase : CollectionBase
{
private Base owner;
///
/// Gets an owner of this collection.
///
public Base Owner
{
get { return owner; }
}
///
/// Adds the specified elements to the end of this collection.
///
/// Range of elements.
public void AddRange(Base[] range)
{
foreach (Base c in range)
{
Add(c);
}
}
///
/// Adds the specified elements to the end of this collection.
///
/// Collection of elements.
public void AddRange(ObjectCollection range)
{
foreach (Base c in range)
{
Add(c);
}
}
///
/// Adds an object to the end of this collection.
///
/// Object to add.
/// Index of the added object.
public int Add(Base value)
{
if (value == null)
return -1;
return List.Add(value);
}
///
/// Inserts an object into this collection at the specified index.
///
/// The zero-based index at which value should be inserted.
/// The object to insert.
public void Insert(int index, Base value)
{
if (value != null)
List.Insert(index, value);
}
///
/// Removes the specified object from the collection.
///
/// Object to remove.
public void Remove(Base value)
{
if (Contains(value))
List.Remove(value);
}
///
/// Returns the zero-based index of the first occurrence of an object.
///
/// The object 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(Base value)
{
return List.IndexOf(value);
}
///
/// Determines whether an element is in the collection.
///
/// The object to locate in the collection.
/// true if object is found in the collection; otherwise, false.
public bool Contains(Base value)
{
return List.Contains(value);
}
///
/// Returns an array of collection items.
///
///
public object[] ToArray()
{
return InnerList.ToArray();
}
///
/// Determines whether two collections are equal.
///
/// The collection to compare with.
/// true if collections are equal; false otherwise.
public bool Equals(FRCollectionBase list)
{
bool result = Count == list.Count;
if (result)
{
for (int i = 0; i < list.Count; i++)
if (List[i] != list.List[i])
{
result = false;
break;
}
}
return result;
}
///
/// Copies the content to another collection.
///
/// The collection to copy to.
public void CopyTo(FRCollectionBase list)
{
list.Clear();
for (int i = 0; i < Count; i++)
list.Add(List[i] as Base);
}
///
protected override void OnInsert(int index, Object value)
{
if (Owner != null)
{
Base c = value as Base;
c.Parent = null;
c.SetParent(Owner);
}
}
///
protected override void OnRemove(int index, object value)
{
if (Owner != null)
(value as Base).SetParent(null);
}
///
protected override void OnClear()
{
if (owner != null)
{
while (Count > 0)
{
(List[0] as Base).Dispose();
}
}
}
///
/// Initializes a new instance of the FRCollectionBase class with default settings.
///
public FRCollectionBase() : this(null)
{
}
///
/// Initializes a new instance of the FRCollectionBase class with specified owner.
///
/// The owner of this collection.
public FRCollectionBase(Base owner)
{
this.owner = owner;
}
}
}