123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using System;
- using System.Collections.Generic;
- namespace FairyGUI.Utils
- {
-
-
-
- public class XMLList
- {
- public List<XML> rawList;
- public XMLList()
- {
- rawList = new List<XML>();
- }
- public XMLList(List<XML> list)
- {
- rawList = list;
- }
- public void Add(XML xml)
- {
- rawList.Add(xml);
- }
- public void Clear()
- {
- rawList.Clear();
- }
- public int Count
- {
- get { return rawList.Count; }
- }
- public XML this[int index]
- {
- get { return rawList[index]; }
- }
- public Enumerator GetEnumerator()
- {
- return new Enumerator(rawList, null);
- }
- public Enumerator GetEnumerator(string selector)
- {
- return new Enumerator(rawList, selector);
- }
- static List<XML> _tmpList = new List<XML>();
- public XMLList Filter(string selector)
- {
- bool allFit = true;
- _tmpList.Clear();
- int cnt = rawList.Count;
- for (int i = 0; i < cnt; i++)
- {
- XML xml = rawList[i];
- if (xml.name == selector)
- _tmpList.Add(xml);
- else
- allFit = false;
- }
- if (allFit)
- return this;
- else
- {
- XMLList ret = new XMLList(_tmpList);
- _tmpList = new List<XML>();
- return ret;
- }
- }
- public XML Find(string selector)
- {
- int cnt = rawList.Count;
- for (int i = 0; i < cnt; i++)
- {
- XML xml = rawList[i];
- if (xml.name == selector)
- return xml;
- }
- return null;
- }
- public void RemoveAll(string selector)
- {
- rawList.RemoveAll(xml => xml.name == selector);
- }
- public struct Enumerator
- {
- List<XML> _source;
- string _selector;
- int _index;
- int _total;
- XML _current;
- public Enumerator(List<XML> source, string selector)
- {
- _source = source;
- _selector = selector;
- _index = -1;
- if (_source != null)
- _total = _source.Count;
- else
- _total = 0;
- _current = null;
- }
- public XML Current
- {
- get { return _current; }
- }
- public bool MoveNext()
- {
- while (++_index < _total)
- {
- _current = _source[_index];
- if (_selector == null || _current.name == _selector)
- return true;
- }
- return false;
- }
- public void Erase()
- {
- _source.RemoveAt(_index);
- _total--;
- }
- public void Reset()
- {
- _index = -1;
- }
- }
- }
- }
|