Changeset 3004 for trunk/sources/HeuristicLab.Persistence/3.3/Core
- Timestamp:
- 03/11/10 12:54:14 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Core
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Configuration.cs
r2994 r3004 6 6 namespace HeuristicLab.Persistence.Core { 7 7 8 /// <summary> 9 /// Defines the set of primitive and composite serializers that are to be used 10 /// for a certain seraial format. The configuration can be obtained from the 11 /// <code>ConfigurationService</code>. 12 /// </summary> 8 13 [StorableClass(StorableClassType.MarkedOnly)] 9 14 public class Configuration { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs
r2876 r3004 13 13 namespace HeuristicLab.Persistence.Core { 14 14 15 /// <summary> 16 /// Provides a persistable configuration of primitive and composite serializers for 17 /// all registered serial formats. Custom formats can be defined and will be saved 18 /// for future sessions. A default configuration can be generated through reflection. 19 /// 20 /// This class has only a single instance. 21 /// </summary> 15 22 public class ConfigurationService { 16 23 17 24 private static ConfigurationService instance; 18 25 private readonly Dictionary<IFormat, Configuration> customConfigurations; 26 27 /// <summary> 28 /// List of all available primitive serializers. 29 /// </summary> 19 30 public Dictionary<Type, List<IPrimitiveSerializer>> PrimitiveSerializers { get; private set; } 31 32 /// <summary> 33 /// List of all available composite serializers (discovered through reflection). 34 /// </summary> 20 35 public List<ICompositeSerializer> CompositeSerializers { get; private set; } 36 37 /// <summary> 38 /// List of all available formats (discovered through reflection). 39 /// </summary> 21 40 public List<IFormat> Formats { get; private set; } 22 41 … … 92 111 } 93 112 113 114 /// <summary> 115 /// Rediscover available serializers and discard all custom configurations. 116 /// </summary> 94 117 public void Reset() { 95 118 customConfigurations.Clear(); … … 108 131 } 109 132 110 class PriortiySorter : IComparer<ICompositeSerializer> {133 private class PriortiySorter : IComparer<ICompositeSerializer> { 111 134 public int Compare(ICompositeSerializer x, ICompositeSerializer y) { 112 135 return y.Priority - x.Priority; … … 169 192 } 170 193 194 /// <summary> 195 /// Get the default (automatically discovered) configuration for a certain format. 196 /// </summary> 171 197 public Configuration GetDefaultConfig(IFormat format) { 172 198 Dictionary<Type, IPrimitiveSerializer> primitiveConfig = new Dictionary<Type, IPrimitiveSerializer>(); … … 188 214 } 189 215 216 217 /// <summary> 218 /// Get a configuration for a certain format. This returns a custom configuration 219 /// if defined, otherwise returns the default (automatically discovered) configuration. 220 /// </summary> 190 221 public Configuration GetConfiguration(IFormat format) { 191 222 if (customConfigurations.ContainsKey(format)) … … 194 225 } 195 226 227 /// <summary> 228 /// Define a new custom configuration for a ceratin format. 229 /// </summary> 196 230 public void DefineConfiguration(Configuration configuration) { 197 231 customConfigurations[configuration.Format] = configuration; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r2873 r3004 9 9 namespace HeuristicLab.Persistence.Core { 10 10 11 /// <summary> 12 /// Core hub for deserialization. Reads the serialization token stream, 13 /// instantiates objects and fills in values. 14 /// </summary> 11 15 public class Deserializer { 12 16 13 class Midwife { 17 /// <summary> 18 /// Helps in delivering the class instance and acts as proxy while 19 /// the object cannot yet be instantiate. 20 /// </summary> 21 private class Midwife { 14 22 15 23 public int? Id { get; private set; } … … 53 61 } 54 62 } 55 63 56 64 private readonly Dictionary<int, object> id2obj; 57 65 private readonly Dictionary<Type, object> serializerMapping; … … 59 67 private readonly Dictionary<int, Type> typeIds; 60 68 69 /// <summary> 70 /// Instantiates a new deserializer with the given type cache, 71 /// that contains information about the serializers to use 72 /// for every type and their type ids. 73 /// </summary> 61 74 public Deserializer( 62 75 IEnumerable<TypeMapping> typeCache) { … … 92 105 } 93 106 94 107 /// <summary> 108 /// Process the token stream and deserialize an instantate a new object graph. 109 /// </summary> 95 110 public object Deserialize(IEnumerable<ISerializationToken> tokens) { 96 111 foreach (ISerializationToken token in tokens) { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatBase.cs
r2994 r3004 4 4 namespace HeuristicLab.Persistence.Interfaces { 5 5 6 /// <summary> 7 /// Common base class for defining a new serialization format. 8 /// </summary> 6 9 [StorableClass(StorableClassType.Empty)] 7 10 public abstract class FormatBase<SerialDataFormat> : IFormat<SerialDataFormat> where SerialDataFormat : ISerialData { 8 11 9 12 public abstract string Name { get; } 10 13 14 15 /// <summary> 16 /// Datatype that describes the atoms used for serialization serialization. 17 /// </summary> 11 18 public Type SerialDataType { get { return typeof(SerialDataFormat); } } 12 19 20 /// <summary> 21 /// Compares formats by name. 22 /// </summary> 13 23 public bool Equals(FormatBase<SerialDataFormat> f) { 14 24 if (f == null) … … 17 27 } 18 28 29 /// <summary> 30 /// Compares foramts by name. 31 /// </summary> 19 32 public override bool Equals(object obj) { 20 33 FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/GeneratorBase.cs
r2718 r3004 11 11 namespace HeuristicLab.Persistence.Core { 12 12 13 /// <summary> 14 /// Base class for serialization generators. Provides a common entry point 15 /// <code>Format</code> and dispatches to different abstract methods for 16 /// every token type. 17 /// </summary> 13 18 public abstract class GeneratorBase<T> { 14 19 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/PrimitiveSerializerBase.cs
r2994 r3004 5 5 namespace HeuristicLab.Persistence.Interfaces { 6 6 7 /// <summary> 8 /// Base class for primitive serializers. These are serializers that map 9 /// directly to a single datatype and directly produce a serializable object. 10 /// </summary> 7 11 [StorableClass(StorableClassType.Empty)] 8 12 public abstract class PrimitiveSerializerBase<Source, SerialData> : -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r2993 r3004 13 13 namespace HeuristicLab.Persistence.Core { 14 14 15 /// <summary> 16 /// The core hub for serialization. This class transforms an object graph 17 /// into a tree and later into a stream of serialization tokens using 18 /// the given configuration. 19 /// 20 /// <para>Primitive serializers directly format an object to a serializable type.</para> 21 /// 22 /// <para>Composite serializers decompose an object into other object that are then 23 /// recursively serialized.</para> 24 /// 25 /// A constructed serializer is enumerable and continuously analyses 26 /// and traverses the object graph while the enumerator is iterated 27 /// </summary> 15 28 public class Serializer : IEnumerable<ISerializationToken> { 16 29 17 class ReferenceEqualityComparer : IEqualityComparer<object> {30 private class ReferenceEqualityComparer : IEqualityComparer<object> { 18 31 19 32 public new bool Equals(object a, object b) { … … 37 50 private readonly List<Exception> exceptions; 38 51 52 /// <summary> 53 /// Contains a mapping of type id to type and serializer. 54 /// </summary> 39 55 public List<TypeMapping> TypeCache { 40 56 get { … … 43 59 } 44 60 } 45 61 62 /// <summary> 63 /// Contains a list of files (mostly assemblies) that are 64 /// necessary to deserialize the object graph again. 65 /// </summary> 46 66 public List<string> RequiredFiles { 47 67 get { … … 76 96 requiredFiles = new List<string>(files.Keys); 77 97 } 78 98 79 99 public Serializer(object obj, Configuration configuration) : 80 100 this(obj, configuration, "ROOT") { } … … 83 103 : this(obj, configuration, rootName, false) { } 84 104 105 /// <param name="isTestRun">Try to complete the whole object graph, 106 /// don't stop at the first exception</param> 85 107 public Serializer(object obj, Configuration configuration, string rootName, bool isTestRun) { 86 108 this.obj = obj; … … 106 128 } 107 129 108 p ublicIEnumerator<ISerializationToken> AddExceptionCompiler(IEnumerator<ISerializationToken> enumerator) {130 private IEnumerator<ISerializationToken> AddExceptionCompiler(IEnumerator<ISerializationToken> enumerator) { 109 131 while (enumerator.MoveNext()) 110 132 yield return enumerator.Current; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tag.cs
r1623 r3004 3 3 namespace HeuristicLab.Persistence.Core { 4 4 5 /// <summary> 6 /// Vehicle used inside the serialization/deserizalisation process 7 /// between composite serializers and the core. 8 /// </summary> 5 9 public class Tag { 6 10 public string Name { get; private set; } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/BeginToken.cs
r1562 r3004 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 6 /// <summary> 7 /// Marks the beginning of a composite element. 8 /// </summary> 5 9 public class BeginToken : CompositeTokenBase { 6 10 public BeginToken(string name, int typeId, int? id) : base(name, typeId, id) { } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/CompositeTokenBase.cs
r1562 r3004 2 2 namespace HeuristicLab.Persistence.Core.Tokens { 3 3 4 /// <summary> 5 /// Common base class of <code>BeginToken</code> and <code>EndToken</code> 6 /// that surround a composite element. 7 /// </summary> 4 8 public abstract class CompositeTokenBase : SerializationTokenBase { 5 9 public readonly int TypeId; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/EndToken.cs
r1562 r3004 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 /// <summary> 6 /// Marks the end of a composite element. 7 /// </summary> 5 8 public class EndToken : CompositeTokenBase { 6 9 public EndToken(string name, int typeId, int? id) : base(name, typeId, id) { } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/MetaInfoBeginToken.cs
r1556 r3004 2 2 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 5 public class MetaInfoBeginToken : ISerializationToken { } 6 6 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/NulLReferenceToken.cs
r1566 r3004 2 2 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 5 public class NullReferenceToken : SerializationTokenBase { 6 6 public NullReferenceToken(string name) : base(name) { } -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/PrimitiveToken.cs
r1566 r3004 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 /// <summary> 6 /// Encapsulated the serialization of a single primitive value. 7 /// </summary> 5 8 public class PrimitiveToken : SerializationTokenBase { 6 9 public readonly int TypeId; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/ReferenceToken.cs
r1566 r3004 3 3 namespace HeuristicLab.Persistence.Core.Tokens { 4 4 5 6 /// <summary> 7 /// References a previously used token (composite or primitive). 8 /// </summary> 5 9 public class ReferenceToken : SerializationTokenBase { 6 10 public readonly int Id; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/SerializationTokenBase.cs
r1615 r3004 4 4 5 5 namespace HeuristicLab.Persistence.Core.Tokens { 6 6 7 7 public abstract class SerializationTokenBase : ISerializationToken { 8 8 public readonly string Name; -
trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeMapping.cs
r1623 r3004 3 3 namespace HeuristicLab.Persistence.Core { 4 4 5 /// <summary> 6 /// Association of id, type name and serializer 7 /// </summary> 5 8 public class TypeMapping { 6 9
Note: See TracChangeset
for help on using the changeset viewer.