1 | using System.Collections.Generic;
|
---|
2 | using System;
|
---|
3 | using System.Text;
|
---|
4 | using HeuristicLab.Persistence.Interfaces;
|
---|
5 | using HeuristicLab.Persistence.Core;
|
---|
6 | using System.IO;
|
---|
7 | using ICSharpCode.SharpZipLib.Zip;
|
---|
8 | using HeuristicLab.Tracing;
|
---|
9 | using HeuristicLab.Persistence.Core.Tokens;
|
---|
10 |
|
---|
11 | namespace 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 | } |
---|