- Timestamp:
- 02/05/10 05:23:56 (14 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs
r2754 r2756 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 32 /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope. 32 33 /// </summary> 33 [Item("SubScopes ItemParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]34 public class SubScopes ItemParameter<T> : Parameterwhere T : class, IItem {34 [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")] 35 public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem { 35 36 [Storable] 36 37 private string actualName; … … 46 47 } 47 48 48 public T[] Values {49 get { return Get Values(); }50 set { Set Values(value); }49 public T[] ActualValues { 50 get { return GetActualValues(); } 51 set { SetActualValues(value); } 51 52 } 52 53 53 public SubScopes ItemParameter()54 : base("Anonymous", null,typeof(T)) {54 public SubScopesLookupParameter() 55 : base("Anonymous", typeof(T)) { 55 56 actualName = Name; 56 57 } 57 public SubScopesItemParameter(string name, string description) 58 public SubScopesLookupParameter(string name) 59 : base(name, typeof(T)) { 60 actualName = Name; 61 } 62 public SubScopesLookupParameter(string name, string description) 58 63 : base(name, description, typeof(T)) { 59 64 actualName = Name; … … 61 66 62 67 public override IDeepCloneable Clone(Cloner cloner) { 63 SubScopes ItemParameter<T> clone = (SubScopesItemParameter<T>)base.Clone(cloner);68 SubScopesLookupParameter<T> clone = (SubScopesLookupParameter<T>)base.Clone(cloner); 64 69 clone.actualName = actualName; 65 70 return clone; … … 70 75 } 71 76 72 protected string GetActualName() { 73 string name = Name; 74 ExecutionContext current = ExecutionContext; 75 while (current != null) { 76 if (current.Operator.Parameters.ContainsKey(name)) 77 name = ((SubScopesItemParameter<T>)current.Operator.Parameters[name]).ActualName; 78 current = current.Parent; 77 protected virtual T[] GetActualValues() { 78 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 79 IScope scope = ExecutionContext.Scope; 80 T[] values = new T[scope.SubScopes.Count]; 81 IVariable var; 82 T value; 83 84 for (int i = 0; i < values.Length; i++) { 85 scope.SubScopes[i].Variables.TryGetValue(name, out var); 86 if (var != null) { 87 value = var.Value as T; 88 if (value == null) 89 throw new InvalidOperationException( 90 string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".", 91 name, 92 typeof(T).GetPrettyName()) 93 ); 94 values[i] = value; 95 } 79 96 } 80 return name;97 return values; 81 98 } 82 protected virtual T[] GetValues() { 83 string name = GetActualName(); 84 IScope scope = ExecutionContext.Scope; 85 T[] value = new T[scope.SubScopes.Count]; 86 IVariable var; 87 88 for (int i = 0; i < value.Length; i++) { 89 scope.SubScopes[i].Variables.TryGetValue(name, out var); 90 if (var != null) value[i] = (T)var.Value; 91 } 92 return value; 93 } 94 protected virtual void SetValues(T[] values) { 95 string name = GetActualName(); 99 protected virtual void SetActualValues(T[] values) { 100 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 96 101 IScope scope = ExecutionContext.Scope; 97 102 IVariable var;
Note: See TracChangeset
for help on using the changeset viewer.