using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace CppSharp.AST { public struct DeclIterator : IEnumerable where T : Declaration { private readonly List Declarations; public DeclIterator(List declarations) { Declarations = declarations; } public int Count { get { return Declarations.OfType().ToArray().Length; } } public T this[int index] { get { return Declarations.OfType().ToArray()[index]; } } public void Add(T declaration) { Declarations.Add(declaration); } public void AddRange(IEnumerable range) { Declarations.AddRange(range); } public T Find(Func predicate) { return Declarations.OfType().SingleOrDefault(predicate); } public int FindIndex(Predicate predicate) { return Declarations.OfType().ToList().FindIndex(predicate); } public bool Exists(Func predicate) { return Declarations.OfType().Any(predicate); } public IEnumerator GetEnumerator() { return Declarations.OfType().GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Replace(T decl, T newDecl) { Declarations[Declarations.FindIndex(d => d == decl)] = newDecl; } } }