- Timestamp:
- 11/24/15 16:59:57 (9 years ago)
- Location:
- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/ProtoBufSerializer.cs
r13347 r13367 29 29 30 30 protected override Bundle DeserializeBundle(Stream stream) { 31 return Bundle.ParseFrom(stream );31 return Bundle.ParseFrom(stream, Mapper.StaticCache.GetExtensionRegistry()); 32 32 } 33 33 } -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StaticCache.cs
r13358 r13367 36 36 private Dictionary<Type, Guid> type2Guid; 37 37 private Dictionary<Type, TypeInfo> typeInfos; 38 private ExtensionRegistry extensionRegistry; 38 39 39 40 internal StaticCache() { … … 47 48 type2Guid = new Dictionary<Type, Guid>(); 48 49 typeInfos = new Dictionary<Type, TypeInfo>(); 50 extensionRegistry = ExtensionRegistry.CreateInstance(); 49 51 50 foreach (var transformer in ApplicationManager.Manager.GetInstances<ITransformer>().OrderBy(x => x. Order)) {52 foreach (var transformer in ApplicationManager.Manager.GetInstances<ITransformer>().OrderBy(x => x.Priority)) { 51 53 guid2Transformer.Add(transformer.Guid, transformer); 52 54 transformer2Guid.Add(transformer, transformer.Guid); … … 71 73 RegisterType(StorableClassAttribute.GetStorableClassAttribute(t).Guid, t); 72 74 } 75 76 RegisterExtension(BoolBox.Bool); 77 RegisterExtension(IntBox.Int); 78 RegisterExtension(LongBox.Long); 79 RegisterExtension(UnsignedIntBox.UnsignedInt); 80 RegisterExtension(UnsignedLongBox.UnsignedLong); 81 RegisterExtension(FloatBox.Float); 82 RegisterExtension(DoubleBox.Double); 83 RegisterExtension(StringBox.String); 84 RegisterExtension(BytesBox.Bytes); 85 RegisterExtension(BoolArrayBox.BoolArray); 86 RegisterExtension(IntArrayBox.IntArray); 87 RegisterExtension(MatrixBox.Matrix); 88 RegisterExtension(BoolMatrixBox.BoolMatrix); 89 RegisterExtension(IntMatrixBox.IntMatrix); 90 RegisterExtension(DictionaryBox.Dictionary); 73 91 } 74 92 } … … 79 97 type2Guid.Add(type, guid); 80 98 } 99 } 100 public void RegisterExtension<TExtension>(GeneratedExtensionBase<TExtension> extension) { 101 extensionRegistry.Add(extension); 81 102 } 82 103 … … 104 125 } 105 126 } 127 public ExtensionRegistry GetExtensionRegistry() { 128 return extensionRegistry; 129 } 106 130 } 107 131 } -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Transformer.cs
r13358 r13367 25 25 public abstract class Transformer : ITransformer { 26 26 public Guid Guid { get; private set; } 27 public uint Id { get; private set; } 28 public uint Order { get; private set; } 27 public uint Priority { get; private set; } 29 28 30 29 protected Transformer() { 31 30 Guid = TransformerAttribute.GetGuid(this.GetType()); 32 Order = TransformerAttribute.GetOrder(this.GetType()); 33 Id = 0; 34 } 35 36 public void Initialize(uint id) { 37 Id = id; 31 Priority = TransformerAttribute.GetPriority(this.GetType()); 38 32 } 39 33 -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/TransformerAttribute.cs
r13347 r13367 26 26 public sealed class TransformerAttribute : Attribute { 27 27 public Guid Guid { get; private set; } 28 public uint Order{ get; private set; }28 public uint Priority { get; private set; } 29 29 30 public TransformerAttribute(string guid, uint order) {30 public TransformerAttribute(string guid, uint priority) { 31 31 Guid = new Guid(guid); 32 Order = order;32 Priority = priority; 33 33 } 34 34 … … 42 42 return GetTransformerAttribute(type).Guid; 43 43 } 44 public static uint Get Order(Type type) {45 return GetTransformerAttribute(type). Order;44 public static uint GetPriority(Type type) { 45 return GetTransformerAttribute(type).Priority; 46 46 } 47 47 } -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/ITransformer.cs
r13347 r13367 25 25 public interface ITransformer { 26 26 Guid Guid { get; } 27 uint Id { get; } 28 uint Order { get; } 29 30 void Initialize(uint id); 27 uint Priority { get; } 31 28 32 29 bool CanTransformType(Type type); -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto
r13347 r13367 16 16 } 17 17 18 // valueboxes18 // scalar boxes 19 19 message BoolBox { 20 20 extend Box { … … 73 73 74 74 // array boxes 75 message ArrayBox {75 message BoolArrayBox { 76 76 extend Box { 77 required ArrayBox array = 120; 78 } 79 optional uint32 element_type_id = 1; 80 81 extensions 100 to max; 82 } 83 message BoolArrayBox { 84 extend ArrayBox { 85 required BoolArrayBox bool_array = 100; 77 required BoolArrayBox bool_array = 120; 86 78 } 87 79 repeated bool values = 1 [packed = true]; 88 80 } 89 81 message IntArrayBox { 90 extend ArrayBox {91 required IntArrayBox int_array = 1 01;82 extend Box { 83 required IntArrayBox int_array = 121; 92 84 } 93 85 repeated int32 values = 1 [packed = true]; -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs
r13358 r13367 20 20 #endregion 21 21 22 using Google.ProtocolBuffers; 22 23 using System; 24 using System.Collections.Generic; 23 25 using System.Drawing; 26 using System.Linq; 24 27 25 28 namespace HeuristicLab.Persistence { … … 43 46 } 44 47 45 #region Scalar Value Boxes48 #region Scalar Box Transformers 46 49 public abstract class BoolBoxTransformer<T> : BoxTransformer<T> { 47 50 protected override void Populate(Box.Builder box, T value, Mapper mapper) { … … 68 71 protected abstract T ToValueType(int value, Type type, Mapper mapper); 69 72 } 73 public abstract class LongBoxTransformer<T> : BoxTransformer<T> { 74 protected override void Populate(Box.Builder box, T value, Mapper mapper) { 75 var b = LongBox.CreateBuilder(); 76 b.Value = ToBoxType(value, mapper); 77 box.SetExtension<LongBox>(LongBox.Long, b.Build()); 78 } 79 protected override T Extract(Box box, Type type, Mapper mapper) { 80 return ToValueType(box.GetExtension(LongBox.Long).Value, type, mapper); 81 } 82 protected abstract long ToBoxType(T value, Mapper mapper); 83 protected abstract T ToValueType(long value, Type type, Mapper mapper); 84 } 70 85 public abstract class UnsignedIntBoxTransformer<T> : BoxTransformer<T> { 71 86 protected override void Populate(Box.Builder box, T value, Mapper mapper) { … … 80 95 protected abstract T ToValueType(uint value, Type type, Mapper mapper); 81 96 } 82 public abstract class LongBoxTransformer<T> : BoxTransformer<T> {83 protected override void Populate(Box.Builder box, T value, Mapper mapper) {84 var b = LongBox.CreateBuilder();85 b.Value = ToBoxType(value, mapper);86 box.SetExtension<LongBox>(LongBox.Long, b.Build());87 }88 protected override T Extract(Box box, Type type, Mapper mapper) {89 return ToValueType(box.GetExtension(LongBox.Long).Value, type, mapper);90 }91 protected abstract long ToBoxType(T value, Mapper mapper);92 protected abstract T ToValueType(long value, Type type, Mapper mapper);93 }94 97 public abstract class UnsignedLongBoxTransformer<T> : BoxTransformer<T> { 95 98 protected override void Populate(Box.Builder box, T value, Mapper mapper) { … … 139 142 protected abstract string ToBoxType(T value, Mapper mapper); 140 143 protected abstract T ToValueType(string value, Type type, Mapper mapper); 144 } 145 public abstract class BytesBoxTransformer<T> : BoxTransformer<T> { 146 protected override void Populate(Box.Builder box, T value, Mapper mapper) { 147 var b = BytesBox.CreateBuilder(); 148 b.Value = ByteString.CopyFrom(ToBoxType(value, mapper)); 149 box.SetExtension<BytesBox>(BytesBox.Bytes, b.Build()); 150 } 151 protected override T Extract(Box box, Type type, Mapper mapper) { 152 return ToValueType(box.GetExtension(BytesBox.Bytes).Value.ToByteArray(), type, mapper); 153 } 154 protected abstract byte[] ToBoxType(T value, Mapper mapper); 155 protected abstract T ToValueType(byte[] value, Type type, Mapper mapper); 156 } 157 #endregion 158 159 #region Array Box Transformers 160 public abstract class BoolArrayBoxTransformer<T> : BoxTransformer<T> { 161 protected override void Populate(Box.Builder box, T value, Mapper mapper) { 162 var b = BoolArrayBox.CreateBuilder(); 163 b.AddRangeValues(ToBoxType(value, mapper)); 164 box.SetExtension<BoolArrayBox>(BoolArrayBox.BoolArray, b.Build()); 165 } 166 protected override T Extract(Box box, Type type, Mapper mapper) { 167 return ToValueType(box.GetExtension(BoolArrayBox.BoolArray).ValuesList, type, mapper); 168 } 169 protected abstract IEnumerable<bool> ToBoxType(T value, Mapper mapper); 170 protected abstract T ToValueType(IEnumerable<bool> value, Type type, Mapper mapper); 171 } 172 public abstract class IntArrayBoxTransformer<T> : BoxTransformer<T> { 173 protected override void Populate(Box.Builder box, T value, Mapper mapper) { 174 var b = IntArrayBox.CreateBuilder(); 175 b.AddRangeValues(ToBoxType(value, mapper)); 176 box.SetExtension<IntArrayBox>(IntArrayBox.IntArray, b.Build()); 177 } 178 protected override T Extract(Box box, Type type, Mapper mapper) { 179 return ToValueType(box.GetExtension(IntArrayBox.IntArray).ValuesList, type, mapper); 180 } 181 protected abstract IEnumerable<int> ToBoxType(T value, Mapper mapper); 182 protected abstract T ToValueType(IEnumerable<int> value, Type type, Mapper mapper); 141 183 } 142 184 #endregion … … 226 268 protected override TimeSpan ToValueType(long value, Type type, Mapper mapper) { return new TimeSpan(value); } 227 269 } 270 [Transformer("0B540EAC-79AB-40CF-8277-D2C81135FEB6", 217)] 271 internal sealed class ColorTransformers : IntBoxTransformer<Color> { 272 protected override int ToBoxType(Color value, Mapper mapper) { return value.ToArgb(); } 273 protected override Color ToValueType(int value, Type type, Mapper mapper) { return Color.FromArgb(value); } 274 } 228 275 #endregion 229 276 … … 251 298 #endregion 252 299 253 #region Color254 [Transformer("0B540EAC-79AB-40CF-8277-D2C81135FEB6", 217)]255 internal sealed class ColorTransformers : IntBoxTransformer<Color> {256 protected override int ToBoxType(Color value, Mapper mapper) { return value.ToArgb(); }257 protected override Color ToValueType(int value, Type type, Mapper mapper) { return Color.FromArgb(value); }258 }259 #endregion260 261 300 #region Type 262 301 [Transformer("8D17FD28-383B-44E9-9BBF-B19D351C5E38", 218)] … … 269 308 } 270 309 #endregion 310 311 #region Primitive Array Types 312 [Transformer("F25A73B2-6B67-4493-BD59-B836AF4455D1", 300)] 313 internal sealed class BoolArrayTransformer : BoolArrayBoxTransformer<bool[]> { 314 protected override IEnumerable<bool> ToBoxType(bool[] value, Mapper mapper) { return value; } 315 protected override bool[] ToValueType(IEnumerable<bool> value, Type type, Mapper mapper) { return value.ToArray(); } 316 } 317 [Transformer("5F6DC3BC-4433-4AE9-A636-4BD126F7DACD", 306)] 318 internal sealed class IntArrayTransformer : IntArrayBoxTransformer<int[]> { 319 protected override IEnumerable<int> ToBoxType(int[] value, Mapper mapper) { return value; } 320 protected override int[] ToValueType(IEnumerable<int> value, Type type, Mapper mapper) { return value.ToArray(); } 321 } 322 #endregion 271 323 }
Note: See TracChangeset
for help on using the changeset viewer.