Changeset 15341 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
- Timestamp:
- 08/28/17 09:03:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r15334 r15341 175 175 176 176 public static Expression GetStatelessExpression<T>() where T : StatelessExpression { 177 return GetStatelessExpression(typeToNameTable[typeof(T)]); 177 Expression expression; 178 var type = typeof(T); 179 180 if (StatelessExpressionTable.TryGetValue(type, out expression)) 181 return expression; 182 183 throw new NotSupportedException("Expression not supported: " + type.Name); 178 184 } 179 185 180 186 public static Expression GetStatelessExpression(string name) { 181 if (NameToTypeTable.ContainsKey(name) && StatelessExpressionTable.ContainsKey(NameToTypeTable[name])) 182 return StatelessExpressionTable[NameToTypeTable[name]]; 187 Type type; 188 Expression expression; 189 190 if (NameToTypeTable.TryGetValue(name, out type) && StatelessExpressionTable.TryGetValue(type, out expression)) 191 return expression; 192 183 193 throw new NotSupportedException("Expression not supported: " + name); 184 194 } 185 195 186 196 public static bool TryGetStatelessExpression(string name, out Expression expression) { 187 if (!NameToTypeTable.ContainsKey(name) || !StatelessExpressionTable.ContainsKey(NameToTypeTable[name])) { 197 Type type; 198 if (!NameToTypeTable.TryGetValue(name, out type) || !StatelessExpressionTable.TryGetValue(type, out expression)) { 188 199 expression = null; 189 200 return false; 190 201 } 191 202 192 expression = StatelessExpressionTable[NameToTypeTable[name]];193 203 return true; 194 204 } … … 199 209 200 210 public static Expression GetStatefulExpression(string name) { 201 if (NameToTypeTable.ContainsKey(name)) { 202 Func<Expression> creator; 203 var type = NameToTypeTable[name]; 204 205 if (StatefulExpressionFactory.TryGetValue(type, out creator)) 206 return creator(); 211 Type type; 212 Func<Expression> creator; 213 214 if (NameToTypeTable.TryGetValue(name, out type) && StatefulExpressionFactory.TryGetValue(type, out creator)) { 215 return creator(); 207 216 } 208 217
Note: See TracChangeset
for help on using the changeset viewer.