Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/11 11:04:02 (13 years ago)
Author:
cneumuel
Message:

#1424

  • created extension method GetObjectGraphObjects for objects
  • created IStatefulItem interface, which means an object has a state which can be initialized and cleared
  • after an algorithm stopped, all objects of the algorithm-objectgraph with the type IStatefulItem are cleared
  • on prepare, all IStatefulItem objects are initialized
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r5768 r6103  
    3333  [Item("Parameter", "A base class for parameters.")]
    3434  [StorableClass]
    35   public abstract class Parameter : NamedItem, IParameter {
     35  public abstract class Parameter : NamedItem, IParameter, IStatefulItem {
    3636    public override Image ItemImage {
    3737      get {
     
    9292    protected Parameter(bool deserializing)
    9393      : base(deserializing) {
    94       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    95       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     94      InitializeState();
    9695    }
    9796    protected Parameter(Parameter original, Cloner cloner)
     
    9998      dataType = original.dataType;
    10099      hidden = original.hidden;
    101       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    102       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     100      InitializeState();
    103101    }
    104102    protected Parameter()
     
    106104      dataType = typeof(IItem);
    107105      hidden = false;
    108       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    109       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     106      InitializeState();
    110107    }
    111108    protected Parameter(string name, Type dataType)
     
    114111      this.dataType = dataType;
    115112      hidden = false;
    116       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    117       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     113      InitializeState();
    118114    }
    119115    protected Parameter(string name, string description, Type dataType)
     
    122118      this.dataType = dataType;
    123119      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);
     126    }
     127    public virtual void ClearState() {
     128      cachedActualValues = null;
     129      executionContexts = null;
    126130    }
    127131
Note: See TracChangeset for help on using the changeset viewer.