Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Core/GeneratorBase.cs @ 3328

Last change on this file since 3328 was 3016, checked in by epitzer, 15 years ago

Update API docs. (#548)

File size: 3.9 KB
Line 
1using System.Collections.Generic;
2using System;
3using System.Text;
4using HeuristicLab.Persistence.Interfaces;
5using HeuristicLab.Persistence.Core;
6using System.IO;
7using ICSharpCode.SharpZipLib.Zip;
8using HeuristicLab.Tracing;
9using HeuristicLab.Persistence.Core.Tokens;
10
11namespace HeuristicLab.Persistence.Core {
12
13  /// <summary>
14  /// Base class for serialization generators. Provides a common entry point
15  /// <c>Format</c> and dispatches to different abstract methods for
16  /// every token type.
17  /// </summary>
18  /// <typeparam name="T">The type of the serialization format.</typeparam>
19  public abstract class GeneratorBase<T> {
20
21    /// <summary>
22    /// Processes a serialization token and formats the specified token.
23    /// </summary>
24    /// <param name="token">The token.</param>
25    /// <returns>An object suitable for serialziation</returns>
26    public T Format(ISerializationToken token) {
27      Type type = token.GetType();
28      if (type == typeof(BeginToken))
29        return Format((BeginToken)token);
30      if (type == typeof(EndToken))
31        return Format((EndToken)token);
32      if (type == typeof(PrimitiveToken))
33        return Format((PrimitiveToken)token);
34      if (type == typeof(ReferenceToken))
35        return Format((ReferenceToken)token);
36      if (type == typeof(NullReferenceToken))
37        return Format((NullReferenceToken)token);
38      if (type == typeof(MetaInfoBeginToken))
39        return Format((MetaInfoBeginToken)token);
40      if (type == typeof(MetaInfoEndToken))
41        return Format((MetaInfoEndToken)token);
42      if (type == typeof(TypeToken))
43        return Format((TypeToken)token);
44      throw new ApplicationException("Invalid token of type " + type.FullName);
45    }
46
47    /// <summary>
48    /// Formats the specified begin token.
49    /// </summary>
50    /// <param name="beginToken">The begin token.</param>
51    /// <returns>The token in serialized form.</returns>
52    protected abstract T Format(BeginToken beginToken);
53
54    /// <summary>
55    /// Formats the specified end token.
56    /// </summary>
57    /// <param name="endToken">The end token.</param>
58    /// <returns>The token in serialized form.</returns>
59    protected abstract T Format(EndToken endToken);
60
61    /// <summary>
62    /// Formats the specified primitive token.
63    /// </summary>
64    /// <param name="primitiveToken">The primitive token.</param>
65    /// <returns>The token in serialized form.</returns>
66    protected abstract T Format(PrimitiveToken primitiveToken);
67
68    /// <summary>
69    /// Formats the specified reference token.
70    /// </summary>
71    /// <param name="referenceToken">The reference token.</param>
72    /// <returns>The token in serialized form.</returns>
73    protected abstract T Format(ReferenceToken referenceToken);
74
75    /// <summary>
76    /// Formats the specified null reference token.
77    /// </summary>
78    /// <param name="nullReferenceToken">The null reference token.</param>
79    /// <returns>The token in serialized form.</returns>
80    protected abstract T Format(NullReferenceToken nullReferenceToken);
81
82    /// <summary>
83    /// Formats the specified meta info begin token.
84    /// </summary>
85    /// <param name="metaInfoBeginToken">The meta info begin token.</param>
86    /// <returns>The token in serialized form.</returns>
87    protected abstract T Format(MetaInfoBeginToken metaInfoBeginToken);
88
89    /// <summary>
90    /// Formats the specified meta info end token.
91    /// </summary>
92    /// <param name="metaInfoEndToken">The meta info end token.</param>
93    /// <returns>The token in serialized form.</returns>
94    protected abstract T Format(MetaInfoEndToken metaInfoEndToken);
95
96    /// <summary>
97    /// Formats the specified type token.
98    /// </summary>
99    /// <param name="typeToken">The type token.</param>
100    /// <returns>The token in serialized form.</returns>
101    protected abstract T Format(TypeToken typeToken);
102
103  }
104}
Note: See TracBrowser for help on using the repository browser.