Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MarkdownElementChildren.cs
3
5{
10 {
11 private ChunkedList<MarkdownElement> children;
12
19 : base(Document)
20 {
21 this.children = Children;
22 }
23
30 : base(Document)
31 {
32 this.children = new ChunkedList<MarkdownElement>(Children);
33 }
34
39 public virtual void AddChild(MarkdownElement NewChild)
40 {
41 this.children.Add(NewChild);
42 }
43
48 public virtual void AddChildren(ChunkedList<MarkdownElement> NewChildren)
49 {
50 this.children.AddRange(NewChildren);
51 }
52
56 public bool HasFirstChild => this.children.HasFirstItem;
57
61 public MarkdownElement FirstChild => this.children.FirstItem;
62
66 public bool HasLastChild => this.children.HasLastItem;
67
71 public MarkdownElement LastChild => this.children.LastItem;
72
76 public bool HasOneChild => this.children.Count == 1;
77
81 public override ChunkedList<MarkdownElement> Children => this.children;
82
88 {
89 this.children = Children;
90 }
91
100
104 internal virtual bool JoinOverParagraphs => false;
105
112 public override bool ForEach(MarkdownElementHandler Callback, object State)
113 {
114 if (!Callback(this, State))
115 return false;
116
117 if (!(this.children is null))
118 {
119 ChunkNode<MarkdownElement> Loop = this.children.FirstChunk;
120 int i, c;
121
122 while (!(Loop is null))
123 {
124 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
125 {
126 if (!Loop[i].ForEach(Callback, State))
127 return false;
128 }
129
130 Loop = Loop.Next;
131 }
132 }
133
134 return true;
135 }
136
142 public override bool Equals(object obj)
143 {
144 if (!(obj is MarkdownElementChildren x) || !base.Equals(obj))
145 return false;
146
147 IEnumerator<MarkdownElement> e1 = null;
148 IEnumerator<MarkdownElement> e2 = null;
149
150 try
151 {
152 e1 = this.children.GetEnumerator();
153 e2 = x.children.GetEnumerator();
154
155 bool b1, b2;
156
157 while (true)
158 {
159 b1 = e1.MoveNext();
160 b2 = e2.MoveNext();
161
162 if (b1 ^ b2)
163 return false;
164
165 if (!b1)
166 return true;
167
168 if (!e1.Current.Equals(e2.Current))
169 return false;
170 }
171 }
172 finally
173 {
174 e1?.Dispose();
175 e2?.Dispose();
176 }
177 }
178
183 public override int GetHashCode()
184 {
185 ChunkNode<MarkdownElement> Loop = this.children.FirstChunk;
186 int i, c;
187 int h1 = base.GetHashCode();
188 int h2;
189
190 while (!(Loop is null))
191 {
192 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
193 {
194 h2 = Loop[i].GetHashCode();
195 h1 = ((h1 << 5) + h1) ^ h2;
196 }
197
198 Loop = Loop.Next;
199 }
200
201 return h1;
202 }
203
204 }
205}
Contains a markdown document. This markdown document class supports original markdown,...
Abstract base class for all markdown elements with a variable number of child elements.
virtual void AddChildren(ChunkedList< MarkdownElement > NewChildren)
Adds children to the element.
MarkdownElement LastChild
Last child, or null if none.
MarkdownElementChildren(MarkdownDocument Document, ChunkedList< MarkdownElement > Children)
Abstract base class for all markdown elements with a variable number of child elements.
void SetChildren(ChunkedList< MarkdownElement > Children)
Sets the children of the node.
override int GetHashCode()
Serves as the default hash function.
override ChunkedList< MarkdownElement > Children
Any children of the element.
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
MarkdownElementChildren(MarkdownDocument Document, params MarkdownElement[] Children)
Abstract base class for all markdown elements with a variable number of child elements.
virtual void AddChild(MarkdownElement NewChild)
Adds a child to the element.
override bool ForEach(MarkdownElementHandler Callback, object State)
Loops through all child-elements for the element.
bool HasOneChild
If the element has only one child.
abstract MarkdownElementChildren Create(ChunkedList< MarkdownElement > Children, MarkdownDocument Document)
Creates an object of the same type, and meta-data, as the current object, but with content defined by...
MarkdownElement FirstChild
First child, or null if none.
Abstract base class for all markdown elements.
MarkdownDocument Document
Markdown document.
Node referencing a chunk in a ChunkedList<T>
Definition: ChunkNode.cs:11
ChunkNode< T > Next
Next chunk
Definition: ChunkNode.cs:26
int Pos
Index after the last element in chunk.
Definition: ChunkNode.cs:51
int Start
Index of first element in chunk.
Definition: ChunkNode.cs:46
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
IEnumerator< T > GetEnumerator()
Returns an enumerator for the collection.
Definition: ChunkedList.cs:418
T LastItem
Last item in the collection.
Definition: ChunkedList.cs:732
void AddRange(IEnumerable< T > Collection)
Adds a range of elements (last) to the list.
ChunkNode< T > FirstChunk
First chunk
Definition: ChunkedList.cs:259
bool HasFirstItem
If there is a first item in the collection
Definition: ChunkedList.cs:778
bool HasLastItem
If there is a last item in the collection
Definition: ChunkedList.cs:726
T FirstItem
First item in the collection.
Definition: ChunkedList.cs:784
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
delegate bool MarkdownElementHandler(MarkdownElement Element, object State)
Delegate for markdown element callback methods.