Changeset 1361


Ignore:
Timestamp:
03/19/09 13:30:58 (12 years ago)
Author:
epitzer
Message:

Split all classes into their own file (#506)

Location:
branches/New Persistence Exploration/Persistence
Files:
22 added
6 deleted
4 edited

Legend:

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

    r1360 r1361  
    1616
    1717
    18   class CustomObject : IAccessibleObject {
     18  class CustomComposite : IAccessibleObject {
    1919
    2020    public object Obj { get; private set; }
    2121    public readonly List<object> customValues;
    2222
    23     public CustomObject(object obj) {
     23    public CustomComposite(object obj) {
    2424      Obj = obj;
    2525      customValues = new List<object>();
     
    3737
    3838
    39   class CompositeObject : IAccessibleObject {
     39  class StorableComposite : IAccessibleObject {
    4040
    4141    public object Obj { get; private set; }
    4242    public readonly Dictionary<string, DataMemberAccessor> accessorDict;
    4343
    44     public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) {
     44    public StorableComposite(object obj, Dictionary<string, DataMemberAccessor> accessorDict) {
    4545      Obj = obj;
    4646      this.accessorDict = new Dictionary<string, DataMemberAccessor>();
     
    7676    private readonly Dictionary<int, object> id2obj;
    7777    private readonly Dictionary<Type, Handler> handlers;
    78     private readonly Stack<IAccessibleObject> compositeStack;
     78    private readonly Stack<IAccessibleObject> parentStack;
    7979    private readonly Configuration configuration;
    8080    private readonly Dictionary<int, Type> typeIds;   
     
    8686      this.configuration = configuration;
    8787      id2obj = new Dictionary<int, object>();
    88       compositeStack = new Stack<IAccessibleObject>();
     88      parentStack = new Stack<IAccessibleObject>();
    8989      handlers = new Dictionary<Type, Handler> {
    9090                     {typeof (BeginToken), CompositeStartHandler},
     
    109109        fix();
    110110      }
    111       return compositeStack.Pop().Obj;
     111      return parentStack.Pop().Obj;
    112112    }
    113113
     
    118118      if (configuration.GetDecomposer(type) != null) {
    119119        instance = new ParentReference();
    120         compositeStack.Push(new CustomObject(instance));       
     120        parentStack.Push(new CustomComposite(instance));       
    121121      } else {       
    122122        instance = Activator.CreateInstance(type, true);
    123123        Dictionary<string, DataMemberAccessor> accessorDict =
    124124          StorableAttribute.GetAutostorableAccessors(instance);
    125         compositeStack.Push(new CompositeObject(instance, accessorDict));       
     125        parentStack.Push(new StorableComposite(instance, accessorDict));       
    126126      }
    127127      if ( start.Id != null )
     
    134134      IDecomposer decomposer = configuration.GetDecomposer(type);
    135135      if (decomposer != null) {
    136         CustomObject customObject = (CustomObject)compositeStack.Pop();
     136        CustomComposite customComposite = (CustomComposite)parentStack.Pop();
    137137        object deserializedObject =
    138           decomposer.Compose(customObject.customValues, type);
     138          decomposer.Compose(customComposite.customValues, type);
    139139        if ( end.Id != null )
    140140          id2obj[(int)end.Id] = deserializedObject;       
    141141        SetValue(end.Name, deserializedObject);         
    142142      } else {
    143         CompositeObject compositeObject = (CompositeObject)compositeStack.Pop();
    144         compositeObject.PopulateDefaultValues();
    145         SetValue(end.Name, compositeObject.Obj);
     143        StorableComposite storableComposite = (StorableComposite)parentStack.Pop();
     144        storableComposite.PopulateDefaultValues();
     145        SetValue(end.Name, storableComposite.Obj);
    146146      }
    147147    }
     
    163163      SetValue(reference.Name, id2obj[reference.Id]);
    164164      if (referredObject is ParentReference) {
    165         Setter set = compositeStack.Peek().GetSetter(reference.Name);       
     165        Setter set = parentStack.Peek().GetSetter(reference.Name);       
    166166        int id = reference.Id;
    167167        finalFixes.Add(() => set(id2obj[id]));
     
    175175
    176176    private void SetValue(string name, object value) {
    177       if (compositeStack.Count == 0) {
    178         compositeStack.Push(new CompositeObject(value, new Dictionary<string, DataMemberAccessor>()));
     177      if (parentStack.Count == 0) {
     178        parentStack.Push(new StorableComposite(value, new Dictionary<string, DataMemberAccessor>()));
    179179      } else {
    180         object accessibleObject = compositeStack.Peek();
    181         if (accessibleObject is CompositeObject) {
    182           ((CompositeObject)accessibleObject).SetValue(name, value);
    183         } else if (accessibleObject is CustomObject) {
    184           ((CustomObject)accessibleObject).AddValue(value);
     180        object accessibleObject = parentStack.Peek();
     181        if (accessibleObject is StorableComposite) {
     182          ((StorableComposite)accessibleObject).SetValue(name, value);
     183        } else if (accessibleObject is CustomComposite) {
     184          ((CustomComposite)accessibleObject).AddValue(value);
    185185        }
    186186      }
  • branches/New Persistence Exploration/Persistence/Persistence/Core/Serializer.cs

    r1360 r1361  
    4545        yield return iterator.Current;     
    4646    }
    47 
    4847   
    4948    private IEnumerator<ISerializationToken> Serialize(DataMemberAccessor accessor) {
    5049      object value = accessor.Get();
    5150      if (value == null)
    52         return NullReferenceEnumeration(accessor.Name);
     51        return NullReferenceEnumerator(accessor.Name);
    5352      if (obj2id.ContainsKey(value))
    54         return ReferenceTokenEnumeration(accessor.Name, obj2id[value]);             
     53        return ReferenceEnumerator(accessor.Name, obj2id[value]);             
    5554      if ( ! typeCache.ContainsKey(value.GetType()))
    5655        typeCache.Add(value.GetType(), typeCache.Count);
     
    6362      IFormatter formatter = configuration.GetFormatter(value.GetType());
    6463      if (formatter != null)
    65         return PrimitiveEnumeration(accessor.Name, typeId, formatter.DoFormat(value), id);
     64        return PrimitiveEnumerator(accessor.Name, typeId, formatter.DoFormat(value), id);
    6665      IDecomposer decomposer = configuration.GetDecomposer(value.GetType());
    6766      if (decomposer != null)
    68         return CompositeEnumeration(accessor.Name, decomposer.DeCompose(value), id, typeId);           
    69       return StorableEnumeration(accessor.Name, value, id, typeId);
     67        return CompositeEnumerator(accessor.Name, decomposer.DeCompose(value), id, typeId);           
     68      return StorableEnumerator(accessor.Name, value, id, typeId);
    7069    }
    7170
    72     private IEnumerator<ISerializationToken> NullReferenceEnumeration(string name) {
     71    private IEnumerator<ISerializationToken> NullReferenceEnumerator(string name) {
    7372      yield return new NullReferenceToken(name);
    7473    }
    7574
    76     private IEnumerator<ISerializationToken> ReferenceTokenEnumeration(string name, int id) {
     75    private IEnumerator<ISerializationToken> ReferenceEnumerator(string name, int id) {
    7776      yield return new ReferenceToken(name, id);
    7877    }
    7978
    80     private IEnumerator<ISerializationToken> PrimitiveEnumeration(string name, int typeId, object serializedValue, int? id) {
     79    private IEnumerator<ISerializationToken> PrimitiveEnumerator(string name,
     80        int typeId, object serializedValue, int? id) {
    8181      yield return new PrimitiveToken(name, typeId, serializedValue, id);
    8282    }
    8383
    84     private IEnumerator<ISerializationToken> CompositeEnumeration(string name, IEnumerable values, int? id, int typeId) {
     84    private IEnumerator<ISerializationToken> CompositeEnumerator(string name,
     85        IEnumerable values, int? id, int typeId) {
    8586      yield return new BeginToken(name, typeId, id);     
    8687        foreach (object o in values) {
     
    9293    }
    9394
    94     private IEnumerator<ISerializationToken> StorableEnumeration(string name, object value, int? id, int typeId) {           
     95    private IEnumerator<ISerializationToken> StorableEnumerator(string name,
     96        object value, int? id, int typeId) {           
    9597      yield return new BeginToken(name, typeId, id);
    9698      int nSubComponents = 0;
    9799      foreach (KeyValuePair<string, DataMemberAccessor> mapping in
    98100        StorableAttribute.GetAutostorableAccessors(value)) {
    99         nSubComponents += 1;
     101        nSubComponents += 1;               
    100102        IEnumerator<ISerializationToken> iterator = Serialize(mapping.Value);
    101103        while (iterator.MoveNext()) {
     
    104106      }
    105107      if (nSubComponents == 0) {
    106         throw new ApplicationException(String.Format(
    107                                          "Composite value of type \"{0}\" contains no subcomponents",
    108                                          value.GetType().FullName));
     108        throw new ApplicationException(
     109          String.Format(
     110            "CustomComposite value of type \"{0}\" contains no subcomponents",
     111            value.GetType().FullName));
    109112      }
    110113      yield return new EndToken(name, typeId, id);
  • branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence.csproj

    r1360 r1361  
    5555  </ItemGroup>
    5656  <ItemGroup>
    57     <Compile Include="Default\NumberArrayFormatters.cs" />
     57    <Compile Include="Default\Decomposers\EnumerableDecomposer.cs" />
     58    <Compile Include="Default\Decomposers\ArrayDecomposer.cs" />
     59    <Compile Include="Default\Decomposers\KeyValuePairDecomposer.cs" />
     60    <Compile Include="Default\Decomposers\DictionaryDecomposer.cs" />
     61    <Compile Include="Default\Xml\Compact\IntArray2XmlFormatters.cs" />
     62    <Compile Include="Default\Xml\Compact\DoubleArray2XmlFormatters.cs" />
     63    <Compile Include="Default\Xml\Compact\DoubleList2XmlFormatter.cs" />
     64    <Compile Include="Default\Xml\Compact\NumberEnumeration2XmlFormatter.cs" />
     65    <Compile Include="Default\Xml\Compact\NumberArray2XmlFormatters.cs" />
    5866    <Compile Include="Core\DataMemberAccessor.cs" />
    59     <Compile Include="Default\EnumerableFormatters.cs" />
     67    <Compile Include="Default\Xml\Compact\IntList2XmlFormatter.cs" />
     68    <Compile Include="Default\Xml\Primitive\Sting2XmlFormatter.cs" />
     69    <Compile Include="Default\Xml\Primitive\Int2XmlFormatter.cs" />
     70    <Compile Include="Default\Xml\Primitive\Double2XmlFormatter.cs" />
     71    <Compile Include="Default\Xml\Primitive\Boolean2XmlFormatter.cs" />
     72    <Compile Include="Default\Xml\Primitive\DateTime2XmlFormatter.cs" />
     73    <Compile Include="Default\Xml\XmlFormat.cs" />
    6074    <Compile Include="HeuristicLabPersistencePlugin.cs" />
    6175    <Compile Include="Core\DeSerializer.cs" />
     
    6579    <Compile Include="Properties\AssemblyInfo.cs" />
    6680    <Compile Include="Core\Serializer.cs" />
    67     <Compile Include="Default\Decomposers.cs" />
    68     <Compile Include="Default\PrimitiveFormatters.cs" />
    6981    <Compile Include="Interfaces\Tokens.cs" />
    7082    <Compile Include="Util.cs" />
    7183    <Compile Include="Core\StorableAttribute.cs" />
    72     <Compile Include="Default\XmlFormatter.cs" />
    73     <Compile Include="Default\XmlParser.cs" />
     84    <Compile Include="Default\Xml\XmlGenerator.cs" />
     85    <Compile Include="Default\Xml\XmlParser.cs" />
    7486  </ItemGroup>
    7587  <PropertyGroup>
  • branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs

    r1360 r1361  
    44using System.IO;
    55using HeuristicLab.Persistence.Core;
     6using HeuristicLab.Persistence.Default.Xml;
    67using HeuristicLab.Persistence.Interfaces;
    78
     
    154155      r.dict.Add("three", 3);
    155156      Serializer s = new Serializer(r, ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));       
    156       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
     157      XmlGenerator xmlGenerator = new XmlGenerator();
    157158      StreamWriter writer = new StreamWriter("test.xml");
    158159      foreach (ISerializationToken token in s) {
    159         string line = xmlFormatter.Format(token);
     160        string line = xmlGenerator.Format(token);
    160161        writer.Write(line);
    161162        Console.Out.Write(line);
     
    163164      writer.Close();
    164165      writer = new StreamWriter("test-types.xml");
    165       foreach (string line in xmlFormatter.Format(s.TypeCache)) {
     166      foreach (string line in xmlGenerator.Format(s.TypeCache)) {
    166167        writer.WriteLine(line);
    167168        Console.Out.WriteLine(line);
     
    181182      Serializer s = new Serializer(m,
    182183        ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));
    183       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
     184      XmlGenerator xmlGenerator = new XmlGenerator();
    184185      StreamWriter writer = new StreamWriter("test2.xml");
    185186      foreach (ISerializationToken token in s) {
    186         string line = xmlFormatter.Format(token);
     187        string line = xmlGenerator.Format(token);
    187188        writer.Write(line);
    188189        Console.Out.Write(line);
Note: See TracChangeset for help on using the changeset viewer.