Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/09 18:13:40 (15 years ago)
Author:
epitzer
Message:

Pluginification and major refactoring. (#506)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs

    r1356 r1357  
    11using System.Collections.Generic;
    22using System;
     3using HeuristicLab.Persistence.Interfaces;
    34
    4 namespace Persistence {
     5namespace HeuristicLab.Persistence {
     6
     7
     8  struct ParentReference { }
     9  delegate void Setter(object value);
     10
     11
     12  interface IAccessibleObject {
     13    object Obj { get; }
     14    Setter GetSetter(string name);
     15  }
     16
     17
     18  class CustomObject : IAccessibleObject {
     19
     20    public object Obj { get; private set; }
     21    public readonly List<object> customValues;
     22
     23    public CustomObject(object obj) {
     24      Obj = obj;
     25      customValues = new List<object>();
     26    }
     27
     28    public void AddValue(object value) {
     29      customValues.Add(value);
     30    }
     31
     32    public Setter GetSetter(string name) {
     33      int index = customValues.Count - 1;
     34      return value => customValues[index] = value;
     35    }
     36  }
     37
     38
     39  class CompositeObject : IAccessibleObject {
     40
     41    public object Obj { get; private set; }
     42    public readonly Dictionary<string, DataMemberAccessor> accessorDict;
     43
     44    public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) {
     45      Obj = obj;
     46      this.accessorDict = new Dictionary<string, DataMemberAccessor>();
     47      foreach (KeyValuePair<string, DataMemberAccessor> pair in accessorDict) {
     48        this.accessorDict.Add(
     49          pair.Value.Name,
     50          pair.Value);
     51      }
     52    }
     53
     54    public void SetValue(string name, object value) {
     55      accessorDict[name].Set(value);
     56      accessorDict.Remove(name);
     57    }
     58
     59    public Setter GetSetter(string name) {
     60      return value => accessorDict[name].Set(value);
     61    }
     62
     63    public void PopulateDefaultValues() {
     64      foreach (var pair in accessorDict) {
     65        pair.Value.Set(pair.Value.DefaultValue);
     66      }
     67    }
     68  }
     69
    570
    671  public class DeSerializer {
    772
    8     struct ParentReference { }
    9 
    10     delegate void Setter(object value);
    11 
    12     interface IAccessibleObject {
    13       object Obj { get; }     
    14       Setter GetSetter(string name);
    15     }
    16 
    17     class CustomObject : IAccessibleObject {
    18       public object Obj { get; private set; }
    19       public readonly List<object> customValues;
    20       public CustomObject(object obj) {
    21         Obj = obj;
    22         customValues = new List<object>();
    23       }
    24       public void AddValue(object value) {
    25         customValues.Add(value);
    26       }
    27       public Setter GetSetter(string name) {
    28         int index = customValues.Count-1;
    29         return value => customValues[index] = value;
    30       }
    31     }
    32 
    33     class CompositeObject : IAccessibleObject {
    34       public object Obj { get; private set; }
    35       public readonly Dictionary<string, DataMemberAccessor> accessorDict;
    36       public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) {
    37         Obj = obj;
    38         this.accessorDict = new Dictionary<string, DataMemberAccessor>();
    39         foreach (KeyValuePair<string, DataMemberAccessor> pair in accessorDict) {
    40           this.accessorDict.Add(
    41             pair.Value.Name,
    42             pair.Value);
    43         }
    44       }
    45       public void SetValue(string name, object value) {
    46         accessorDict[name].Set(value);
    47         accessorDict.Remove(name);
    48       }
    49       public Setter GetSetter(string name) {
    50         return value => accessorDict[name].Set(value);
    51       }
    52       public void PopulateDefaultValues() {
    53         foreach (var pair in accessorDict) {
    54           pair.Value.Set(pair.Value.DefaultValue);
    55         }       
    56       }
    57     }
    58 
    5973    private delegate void Handler(ISerializationToken token);
     74    private delegate void Thunk();
    6075
    6176    private readonly Dictionary<int, object> id2obj;
     
    6378    private readonly Stack<IAccessibleObject> compositeStack;
    6479    private readonly PersistenceConfiguration persistenceConfiguration;
    65     private readonly Dictionary<int, Type> typeIds;
    66 
    67     delegate void Thunk();
     80    private readonly Dictionary<int, Type> typeIds;   
    6881    private List<Thunk> finalFixes;
    6982
     
    115128        id2obj.Add((int)start.Id, instance);
    116129    }
     130
    117131    private void CompositeEndHandler(ISerializationToken token) {
    118132      EndToken end = (EndToken)token;
     
    132146      }
    133147    }
     148
    134149    private void PrimitiveHandler(ISerializationToken token) {
    135150      PrimitiveToken primitive = (PrimitiveToken)token;
     
    142157      SetValue(primitive.Name, value);
    143158    }
     159
    144160    private void ReferenceHandler(ISerializationToken token) {
    145161      ReferenceToken reference = (ReferenceToken)token;
     
    152168      }
    153169    }
     170
    154171    private void NullHandler(ISerializationToken token) {
    155172      NullReferenceToken nil = (NullReferenceToken)token;
    156173      SetValue(nil.Name, null);
    157174    }
     175
    158176    private void SetValue(string name, object value) {
    159177      if (compositeStack.Count == 0) {
Note: See TracChangeset for help on using the changeset viewer.