Changeset 6114


Ignore:
Timestamp:
05/03/11 19:25:13 (10 years ago)
Author:
swagner
Message:

Code formatting and minor changes (#1424)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs

    r6103 r6114  
    3737      objects.Add(obj);
    3838
    39       if (obj is ValueType || obj is string) return;
     39      //if (obj is ValueType || obj is string) return;
     40      if (obj is Pointer) return;
    4041
    4142      IEnumerable enumerable = obj as IEnumerable;
  • trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs

    r6103 r6114  
    4747      return sb.ToString();
    4848    }
     49
    4950    public static IEnumerable<FieldInfo> GetAllFields(this Type type) {
    50       foreach(var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     51      foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
    5152        yield return field;
    5253
    53       foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 
     54      foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
    5455        yield return field;
    55      
     56
    5657      if (type.BaseType != null) {
    5758        foreach (var field in type.BaseType.GetAllFields())
     
    5960      }
    6061    }
     62
    6163    // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class
    6264    public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) {
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r6103 r6114  
    7474    protected Operator(bool deserializing)
    7575      : base(deserializing) {
    76       InitializeState();
     76      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    7777    }
    7878    protected Operator(Operator original, Cloner cloner)
    7979      : base(original, cloner) {
    80       InitializeState();
     80      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    8181      this.breakpoint = original.breakpoint;
    8282    }
    8383    protected Operator()
    8484      : base() {
    85       InitializeState();
     85      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    8686      breakpoint = false;
    8787    }
    8888    protected Operator(string name)
    8989      : base(name) {
    90       InitializeState();
     90      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    9191      breakpoint = false;
    9292    }
    9393    protected Operator(string name, ParameterCollection parameters)
    9494      : base(name, parameters) {
    95       InitializeState();
     95      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    9696      breakpoint = false;
    9797    }
    9898    protected Operator(string name, string description)
    9999      : base(name, description) {
    100       InitializeState();
     100      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    101101      breakpoint = false;
    102102    }
    103103    protected Operator(string name, string description, ParameterCollection parameters)
    104104      : base(name, description, parameters) {
    105       InitializeState();
     105      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    106106      breakpoint = false;
    107107    }
    108108
    109     public virtual void InitializeState() {
     109    public virtual void InitializeState() { }
     110    public virtual void ClearState() {
    110111      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    111     }
    112     public virtual void ClearState() {
    113       executionContexts = null;
    114112    }
    115113
     
    123121        OnExecuted();
    124122        return next;
    125       } finally {
     123      }
     124      finally {
    126125        foreach (IParameter param in Parameters)
    127126          param.ExecutionContext = null;
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r6103 r6114  
    260260    public event EventHandler Prepared;
    261261    protected virtual void OnPrepared() {
     262      ExecutionState = ExecutionState.Prepared;
    262263      ExecutionTime = TimeSpan.Zero;
    263264      foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) {
    264265        statefulObject.InitializeState();
    265266      }
    266       ExecutionState = ExecutionState.Prepared;
    267267      EventHandler handler = Prepared;
    268268      if (handler != null) handler(this, EventArgs.Empty);
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r6103 r6114  
    9292    protected Parameter(bool deserializing)
    9393      : base(deserializing) {
    94       InitializeState();
     94      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     95      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    9596    }
    9697    protected Parameter(Parameter original, Cloner cloner)
     
    9899      dataType = original.dataType;
    99100      hidden = original.hidden;
    100       InitializeState();
     101      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     102      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    101103    }
    102104    protected Parameter()
     
    104106      dataType = typeof(IItem);
    105107      hidden = false;
    106       InitializeState();
     108      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     109      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    107110    }
    108111    protected Parameter(string name, Type dataType)
     
    111114      this.dataType = dataType;
    112115      hidden = false;
    113       InitializeState();
     116      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     117      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    114118    }
    115119    protected Parameter(string name, string description, Type dataType)
     
    118122      this.dataType = dataType;
    119123      hidden = false;
    120       InitializeState();
    121     }
    122 
    123     public virtual void InitializeState() {
    124124      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    125125      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    126126    }
     127
     128    public virtual void InitializeState() { }
    127129    public virtual void ClearState() {
    128       cachedActualValues = null;
    129       executionContexts = null;
     130      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     131      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    130132    }
    131133
Note: See TracChangeset for help on using the changeset viewer.