- Timestamp:
- 08/02/11 12:53:25 (13 years ago)
- Location:
- branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
r6620 r6622 190 190 void ISymbolicExpressionGrammar.AddSymbol(ISymbol symbol) { 191 191 if (ReadOnly) throw new InvalidOperationException(); 192 base.AddSymbol(symbol);192 AddSymbol(symbol); 193 193 } 194 194 void ISymbolicExpressionGrammar.RemoveSymbol(ISymbol symbol) { 195 195 if (ReadOnly) throw new InvalidOperationException(); 196 base.RemoveSymbol(symbol);196 RemoveSymbol(symbol); 197 197 } 198 198 … … 235 235 #region symbol events 236 236 private void RegisterSymbolEvents(ISymbol symbol) { 237 symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 238 symbol.NameChanged += new EventHandler(Symbol_NameChanged); 239 240 var groupSymbol = symbol as GroupSymbol; 241 if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol); 242 else symbol.Changed += new EventHandler(Symbol_Changed); 237 foreach (var s in symbol.Flatten()) { 238 s.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 239 s.NameChanged += new EventHandler(Symbol_NameChanged); 240 241 var groupSymbol = s as GroupSymbol; 242 if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol); 243 else symbol.Changed += new EventHandler(Symbol_Changed); 244 } 243 245 } 244 246 private void DeregisterSymbolEvents(ISymbol symbol) { 245 symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 246 symbol.NameChanged -= new EventHandler(Symbol_NameChanged); 247 248 var groupSymbol = symbol as GroupSymbol; 249 if (groupSymbol != null) DeregisterGroupSymbolEvents(groupSymbol); 250 else symbol.Changed -= new EventHandler(Symbol_Changed); 247 foreach (var s in symbol.Flatten()) { 248 s.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 249 s.NameChanged -= new EventHandler(Symbol_NameChanged); 250 251 var groupSymbol = s as GroupSymbol; 252 if (groupSymbol != null) DeregisterGroupSymbolEvents(groupSymbol); 253 else symbol.Changed -= new EventHandler(Symbol_Changed); 254 } 251 255 } 252 256 -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6620 r6622 123 123 protected virtual void AddSymbol(ISymbol symbol) { 124 124 if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined."); 125 symbols.Add(symbol.Name, symbol); 126 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0)); 125 foreach (var s in symbol.Flatten()) { 126 symbols.Add(s.Name, s); 127 symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, s.MaximumArity)); 128 } 127 129 ClearCaches(); 128 130 } 129 131 130 132 protected virtual void RemoveSymbol(ISymbol symbol) { 131 symbols.Remove(symbol.Name); 132 allowedChildSymbols.Remove(symbol.Name); 133 for (int i = 0; i < GetMaximumSubtreeCount(symbol); i++) 134 allowedChildSymbolsPerIndex.Remove(Tuple.Create(symbol.Name, i)); 135 symbolSubtreeCount.Remove(symbol.Name); 136 137 foreach (var parent in Symbols) { 138 List<string> allowedChilds; 139 if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds)) 140 allowedChilds.Remove(symbol.Name); 141 142 for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) { 143 if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds)) 144 allowedChilds.Remove(symbol.Name); 133 foreach (var s in symbol.Flatten()) { 134 symbols.Remove(s.Name); 135 allowedChildSymbols.Remove(s.Name); 136 for (int i = 0; i < GetMaximumSubtreeCount(s); i++) 137 allowedChildSymbolsPerIndex.Remove(Tuple.Create(s.Name, i)); 138 symbolSubtreeCount.Remove(s.Name); 139 140 foreach (var parent in Symbols) { 141 List<string> allowedChilds; 142 if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds)) 143 allowedChilds.Remove(s.Name); 144 145 for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) { 146 if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds)) 147 allowedChilds.Remove(s.Name); 148 } 145 149 } 146 150 } 151 ClearCaches(); 147 152 } 148 153
Note: See TracChangeset
for help on using the changeset viewer.