Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3010 was 3005, checked in by epitzer, 15 years ago

add support for type information interleaving and subsequently true streaming (#548)

File size: 1.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  /// <code>Format</code> and dispatches to different abstract methods for
16  /// every token type.
17  /// </summary> 
18  public abstract class GeneratorBase<T> {
19
20    public T Format(ISerializationToken token) {
21      Type type = token.GetType();
22      if (type == typeof(BeginToken))
23        return Format((BeginToken)token);
24      if (type == typeof(EndToken))
25        return Format((EndToken)token);
26      if (type == typeof(PrimitiveToken))
27        return Format((PrimitiveToken)token);
28      if (type == typeof(ReferenceToken))
29        return Format((ReferenceToken)token);
30      if (type == typeof(NullReferenceToken))
31        return Format((NullReferenceToken)token);
32      if (type == typeof(MetaInfoBeginToken))
33        return Format((MetaInfoBeginToken)token);
34      if (type == typeof(MetaInfoEndToken))
35        return Format((MetaInfoEndToken)token);
36      if (type == typeof(TypeToken))
37        return Format((TypeToken)token);
38      throw new ApplicationException("Invalid token of type " + type.FullName);
39    }
40
41    protected abstract T Format(BeginToken beginToken);
42    protected abstract T Format(EndToken endToken);
43    protected abstract T Format(PrimitiveToken primitiveToken);
44    protected abstract T Format(ReferenceToken referenceToken);
45    protected abstract T Format(NullReferenceToken nullReferenceToken);
46    protected abstract T Format(MetaInfoBeginToken metaInfoBeginToken);
47    protected abstract T Format(MetaInfoEndToken metaInfoEndToken);
48    protected abstract T Format(TypeToken typeToken);
49
50  }
51}
Note: See TracBrowser for help on using the repository browser.