@@ -34,64 +34,47 @@ public int FindNodeIndex(BaseNode node)
3434 return Nodes . FindIndex ( n => n == node ) ;
3535 }
3636
37- public virtual BaseNode ReplaceChildNode ( BaseNode child , Type nodeType )
37+ public bool ReplaceChildNode ( BaseNode child , Type nodeType )
3838 {
3939 Contract . Requires ( nodeType != null ) ;
4040
41- return ReplaceChildNode ( FindNodeIndex ( child ) , nodeType ) ;
41+ List < BaseNode > dummy = null ;
42+ return ReplaceChildNode ( child , nodeType , ref dummy ) ;
4243 }
4344
44- /// <summary>Replaces the child at the specific position with the provided node.</summary>
45- /// <param name="index">Zero-based position.</param>
46- /// <param name="node">The node to add.</param>
47- /// <returns>True if it succeeds, false if it fails.</returns>
48- public virtual BaseNode ReplaceChildNode ( int index , Type nodeType )
45+ public bool ReplaceChildNode ( BaseNode child , Type nodeType , ref List < BaseNode > createdNodes )
4946 {
47+ Contract . Requires ( child != null ) ;
5048 Contract . Requires ( nodeType != null ) ;
51- Contract . Requires ( nodeType . IsSubclassOf ( typeof ( BaseNode ) ) ) ;
5249
53- var node = Activator . CreateInstance ( nodeType ) as BaseNode ;
54-
55- node . Intialize ( ) ;
56-
57- if ( ReplaceChildNode ( index , node ) )
58- {
59- return node ;
60- }
61-
62- return null ;
50+ return ReplaceChildNode ( FindNodeIndex ( child ) , nodeType , ref createdNodes ) ;
6351 }
6452
6553 /// <summary>Replaces the child at the specific position with the provided node.</summary>
6654 /// <param name="index">Zero-based position.</param>
67- /// <param name="node">The node to add.</param>
55+ /// <param name="nodeType">The type of the node.</param>
56+ /// <param name="createdNodes">[in,out] A list with the created nodes.</param>
6857 /// <returns>True if it succeeds, false if it fails.</returns>
69- public bool ReplaceChildNode ( BaseNode child , BaseNode node )
58+ public virtual bool ReplaceChildNode ( int index , Type nodeType , ref List < BaseNode > createdNodes )
7059 {
71- return ReplaceChildNode ( FindNodeIndex ( child ) , node ) ;
72- }
60+ Contract . Requires ( nodeType != null ) ;
61+ Contract . Requires ( nodeType . IsSubclassOf ( typeof ( BaseNode ) ) ) ;
7362
74- /// <summary>Replaces the child at the specific position with the provided node.</summary>
75- /// <param name="index">Zero-based position.</param>
76- /// <param name="node">The node to add.</param>
77- /// <returns>True if it succeeds, false if it fails.</returns>
78- public virtual bool ReplaceChildNode ( int index , BaseNode node )
79- {
80- if ( node == null )
81- {
82- return false ;
83- }
8463 if ( index < 0 || index >= nodes . Count )
8564 {
8665 return false ;
8766 }
8867
8968 var oldNode = nodes [ index ] ;
9069
70+ var node = Activator . CreateInstance ( nodeType ) as BaseNode ;
71+
72+ node . Intialize ( ) ;
9173 node . CopyFromNode ( oldNode ) ;
9274
75+ createdNodes ? . Add ( node ) ;
76+
9377 node . ParentNode = this ;
94- node . ClearSelection ( ) ;
9578
9679 nodes [ index ] = node ;
9780
@@ -100,12 +83,12 @@ public virtual bool ReplaceChildNode(int index, BaseNode node)
10083
10184 if ( newSize < oldSize )
10285 {
103- InsertBytes ( index + 1 , oldSize - newSize ) ;
86+ InsertBytes ( index + 1 , oldSize - newSize , ref createdNodes ) ;
10487 }
105- else if ( newSize > oldSize )
88+ /* else if (newSize > oldSize)
10689 {
107- // RemoveNodes(index + 1, newSize - oldSize);
108- }
90+ RemoveNodes(index + 1, newSize - oldSize);
91+ }*/
10992
11093 return true ;
11194 }
@@ -117,15 +100,25 @@ public void AddBytes(int size)
117100 InsertBytes ( nodes . Count , size ) ;
118101 }
119102
120- public virtual void InsertBytes ( BaseNode position , int size )
103+ public void InsertBytes ( BaseNode position , int size )
121104 {
122105 InsertBytes ( FindNodeIndex ( position ) , size ) ;
123106 }
124107
125108 /// <summary>Inserts <paramref name="size"/> bytes at the specified position.</summary>
126109 /// <param name="index">Zero-based position.</param>
127110 /// <param name="size">The number of bytes to insert.</param>
128- public virtual void InsertBytes ( int index , int size )
111+ public void InsertBytes ( int index , int size )
112+ {
113+ List < BaseNode > dummy = null ;
114+ InsertBytes ( index , size , ref dummy ) ;
115+ }
116+
117+ /// <summary>Inserts <paramref name="size"/> bytes at the specified position.</summary>
118+ /// <param name="index">Zero-based position.</param>
119+ /// <param name="size">The number of bytes to insert.</param>
120+ /// <param name="createdNodes">[in,out] A list with the created nodes.</param>
121+ public virtual void InsertBytes ( int index , int size , ref List < BaseNode > createdNodes )
129122 {
130123 if ( index < 0 || index > nodes . Count || size == 0 )
131124 {
@@ -167,6 +160,8 @@ public virtual void InsertBytes(int index, int size)
167160
168161 nodes . Insert ( index , node ) ;
169162
163+ createdNodes ? . Add ( node ) ;
164+
170165 offset += node . MemorySize ;
171166 size -= node . MemorySize ;
172167
0 commit comments