[3743] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3743] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[1625] | 23 | using System.Text;
|
---|
[16565] | 24 | using HEAL.Attic;
|
---|
[1564] | 25 |
|
---|
| 26 | namespace HeuristicLab.Persistence.Interfaces {
|
---|
[1566] | 27 |
|
---|
[3004] | 28 | /// <summary>
|
---|
| 29 | /// Base class for primitive serializers. These are serializers that map
|
---|
| 30 | /// directly to a single datatype and directly produce a serializable object.
|
---|
| 31 | /// </summary>
|
---|
[3016] | 32 | /// <typeparam name="Source">The source type.</typeparam>
|
---|
| 33 | /// <typeparam name="SerialData">The serialized type.</typeparam>
|
---|
[16571] | 34 | [StorableType("A43393DF-4A1F-42A0-BA2D-1DFEA04EBD97")]
|
---|
[1823] | 35 | public abstract class PrimitiveSerializerBase<Source, SerialData> :
|
---|
| 36 | IPrimitiveSerializer<Source, SerialData>
|
---|
| 37 | where SerialData : ISerialData {
|
---|
[1564] | 38 |
|
---|
[3016] | 39 | /// <summary>
|
---|
| 40 | /// Formats the specified object.
|
---|
| 41 | /// </summary>
|
---|
| 42 | /// <param name="o">The object.</param>
|
---|
| 43 | /// <returns>A serialized version of the object.</returns>
|
---|
[1564] | 44 | public abstract SerialData Format(Source o);
|
---|
| 45 |
|
---|
[3016] | 46 | /// <summary>
|
---|
| 47 | /// Parses the specified serialized data back into an object.
|
---|
| 48 | /// </summary>
|
---|
[3036] | 49 | /// <param name="data">The serial data.</param>
|
---|
| 50 | /// <returns>
|
---|
| 51 | /// A newly created object representing the serialized data.
|
---|
| 52 | /// </returns>
|
---|
[3016] | 53 | public abstract Source Parse(SerialData data);
|
---|
[1564] | 54 |
|
---|
[3016] | 55 | /// <summary>
|
---|
| 56 | /// Gets the type of the serial data.
|
---|
| 57 | /// </summary>
|
---|
| 58 | /// <value>The type of the serial data.</value>
|
---|
[1564] | 59 | public Type SerialDataType { get { return typeof(SerialData); } }
|
---|
| 60 |
|
---|
[3016] | 61 | /// <summary>
|
---|
| 62 | /// Gets the type of the source.
|
---|
| 63 | /// </summary>
|
---|
| 64 | /// <value>The type of the source.</value>
|
---|
[1564] | 65 | public Type SourceType { get { return typeof(Source); } }
|
---|
| 66 |
|
---|
[3016] | 67 | /// <summary>
|
---|
| 68 | /// Formats the specified object.
|
---|
| 69 | /// </summary>
|
---|
| 70 | /// <param name="o">The object.</param>
|
---|
| 71 | /// <returns>A serialized version of the object.</returns>
|
---|
[1823] | 72 | ISerialData IPrimitiveSerializer.Format(object o) {
|
---|
[1566] | 73 | return Format((Source)o);
|
---|
[1564] | 74 | }
|
---|
| 75 |
|
---|
[3016] | 76 | /// <summary>
|
---|
| 77 | /// Parses the specified serialized data back into an object.
|
---|
| 78 | /// </summary>
|
---|
[3036] | 79 | /// <param name="data">The serial data.</param>
|
---|
[3016] | 80 | /// <returns>A newly created object representing the serialized data.</returns>
|
---|
[3036] | 81 | object IPrimitiveSerializer.Parse(ISerialData data) {
|
---|
| 82 | return Parse((SerialData)data);
|
---|
[1564] | 83 | }
|
---|
| 84 |
|
---|
[3016] | 85 | /// <summary>
|
---|
| 86 | /// Returns a <see cref="System.String"/> that represents this instance.
|
---|
| 87 | /// </summary>
|
---|
| 88 | /// <returns>
|
---|
| 89 | /// A <see cref="System.String"/> that represents this instance.
|
---|
| 90 | /// </returns>
|
---|
[1625] | 91 | public override string ToString() {
|
---|
| 92 | return new StringBuilder()
|
---|
| 93 | .Append(this.GetType().Name)
|
---|
| 94 | .Append('(')
|
---|
| 95 | .Append(SourceType.Name)
|
---|
| 96 | .Append("->")
|
---|
| 97 | .Append(SerialDataType.Name)
|
---|
| 98 | .ToString();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[1564] | 101 | }
|
---|
[1566] | 102 |
|
---|
[1564] | 103 | } |
---|