Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Persistence/3.3/Core/FormatBase.cs @ 11401

Last change on this file since 11401 was 11170, checked in by ascheibe, 10 years ago

#2115 updated copyright year in stable branch

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24
25namespace HeuristicLab.Persistence.Interfaces {
26
27  /// <summary>
28  /// Common base class for defining a new serialization format.
29  /// </summary>
30  /// <typeparam name="SerialDataFormat">The type of the serial data format.</typeparam>
31  [StorableClass]
32  public abstract class FormatBase<SerialDataFormat> : IFormat<SerialDataFormat> where SerialDataFormat : ISerialData {
33
34    /// <summary>
35    /// Gets the format's name.
36    /// </summary>
37    /// <value>The format's name.</value>
38    public abstract string Name { get; }
39
40    /// <summary>
41    /// Datatype that describes the atoms used for serialization serialization.
42    /// </summary>
43    public Type SerialDataType { get { return typeof(SerialDataFormat); } }
44
45    [StorableConstructor]
46    protected FormatBase(bool deserializing) { }
47    protected FormatBase() { }
48
49    /// <summary>
50    /// Compares formats by name.
51    /// </summary>
52    /// <param name="f">The format.</param>
53    /// <returns>wheter this object and f are equal by name.</returns>
54    public bool Equals(FormatBase<SerialDataFormat> f) {
55      if (f == null)
56        return false;
57      return f.Name == this.Name;
58    }
59
60    /// <summary>
61    /// Compares foramts by name.
62    /// </summary>
63    /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
64    /// <returns>
65    ///   <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
66    /// </returns>
67    /// <exception cref="T:System.NullReferenceException">
68    /// The <paramref name="obj"/> parameter is null.
69    /// </exception>
70    public override bool Equals(object obj) {
71      FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>;
72      return Equals(f);
73    }
74
75    /// <summary>
76    /// Returns a hash code for this instance.
77    /// </summary>
78    /// <returns>
79    /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
80    /// </returns>
81    public override int GetHashCode() {
82      return Name.GetHashCode();
83    }
84
85  }
86
87}
Note: See TracBrowser for help on using the repository browser.