-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmethystElementTerminalParentChildrenCollection.cs
122 lines (99 loc) · 3.01 KB
/
AmethystElementTerminalParentChildrenCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*****************************************************************************
* *
* AmethystElementTerminalParentChildrenCollection.cs *
* 3 April 2008 *
* Project: Amethyst *
* Written by: Richard Sartor *
* Copyright © 2008 Metaphysics Industries, Inc. *
* *
* An unordered collection of Terminals. *
* *
*****************************************************************************/
using System;
using System.Collections.Generic;
using MetaphysicsIndustries.Collections;
namespace MetaphysicsIndustries.Amethyst
{
[Serializable]
public class AmethystElementTerminalParentChildrenCollection : ICollection<Terminal>, IDisposable
{
public AmethystElementTerminalParentChildrenCollection(AmethystElement parent)
{
_parent = parent;
}
public virtual void Dispose()
{
Clear();
}
//ICollection<Terminal>
public virtual void Add(Terminal item)
{
if (!Contains(item))
{
item.ParentAmethystElement = null;
_set.Add(item);
_parent.TerminalsByConnection[item.ConnectionBase] = item;
item.ParentAmethystElement = _parent;
}
}
public virtual bool Contains(Terminal item)
{
return _set.Contains(item);
}
public virtual bool Remove(Terminal item)
{
if (Contains(item))
{
bool ret = _set.Remove(item);
item.ParentAmethystElement = null;
_parent.TerminalsByConnection.Remove(item.ConnectionBase);
item.DisconnectTerminal();
return ret;
}
return false;
}
public virtual void Clear()
{
foreach (Terminal item in this.ToArray())
{
Remove(item);
}
_set.Clear();
}
public virtual void CopyTo(Terminal[] array, int arrayIndex)
{
_set.CopyTo(array, arrayIndex);
}
public virtual IEnumerator<Terminal> GetEnumerator()
{
return _set.GetEnumerator();
}
//ICollection<Terminal>
public virtual int Count
{
get { return _set.Count; }
}
public virtual bool IsReadOnly
{
get
{
return (_set as ICollection<Terminal>).IsReadOnly;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
private AmethystElement _parent;
private Set<Terminal> _set = new Set<Terminal>();
//public T[] Extract<T>()
// where T : Terminal
//{
// return _set.Extract<T>();
//}
public Terminal[] ToArray()
{
return _set.ToArray();
}
}
}