Skip to content

Commit

Permalink
Merge pull request #922 from gbirchmeier/better-gen-fields
Browse files Browse the repository at this point in the history
clean up generated Fields.cs/FieldTags.cs files
  • Loading branch information
gbirchmeier authored Jan 2, 2025
2 parents 250ecee + 30b4292 commit febd6c5
Show file tree
Hide file tree
Showing 4 changed files with 24,836 additions and 26,460 deletions.
17 changes: 7 additions & 10 deletions DDTool/DDTool/Generators/GenFieldTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ private static string Generate(List<DDField> fields) {
{
"// This is a generated file. Don't edit it directly!",
"",
"using System;",
"namespace QuickFix.Fields;",
"",
"namespace QuickFix.Fields",
"{",
" /// <summary>",
" /// FIX Field Tag Values",
" /// </summary>",
" public static class Tags",
" {"
"/// <summary>",
"/// FIX Field Tag Values",
"/// </summary>",
"public static class Tags",
"{"
};

foreach (var fld in fields)
lines.Add($" public const int {fld.Name} = {fld.Tag};");
lines.Add($" public const int {fld.Name} = {fld.Tag};");

lines.Add(" }");
lines.Add("}");
lines.Add("");

Expand Down
69 changes: 34 additions & 35 deletions DDTool/DDTool/Generators/GenFields.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using DDTool.Structures;

Expand Down Expand Up @@ -29,11 +30,11 @@ private static string Generate(List<DDField> fields) {
"",
"using System;",
"",
"namespace QuickFix.Fields",
"{"
"namespace QuickFix.Fields;",
};

foreach (var field in fields) {
lines.Add("");
switch (field.CsClass) {
case "DateTimeField":
case "TimeOnlyField":
Expand All @@ -45,56 +46,54 @@ private static string Generate(List<DDField> fields) {
}
}

lines.Add("}");
lines.Add("");
return string.Join(Environment.NewLine, lines);
}

private static void AppendDateField(List<string> lines, DDField field) {
lines.Add(" /// <summary>");
lines.Add($" /// {field.Name} Field");
lines.Add(" /// </summary>");
lines.Add($" public sealed class {field.Name} : {field.CsClass}");
lines.Add(" {");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("/// <summary>");
lines.Add($"/// {field.Name} Field");
lines.Add("/// </summary>");
lines.Add($"public sealed class {field.Name} : {field.CsClass}");
lines.Add("{");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("");

lines.Add($" public {field.Name}()");
lines.Add($" :base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" :base(Tags.{field.Name}, val) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, bool showMilliseconds)");
lines.Add($" :base(Tags.{field.Name}, val, showMilliseconds) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, Converters.TimeStampPrecision precision)");
lines.Add($" :base(Tags.{field.Name}, val, precision) {{}}");
lines.Add($" public {field.Name}()");
lines.Add($" : base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" : base(Tags.{field.Name}, val) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, bool showMilliseconds)");
lines.Add($" : base(Tags.{field.Name}, val, showMilliseconds) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val, Converters.TimeStampPrecision precision)");
lines.Add($" : base(Tags.{field.Name}, val, precision) {{}}");
lines.Add("");

AppendFieldEnumerations(lines, field);

lines.Add(" }");
lines.Add("");
lines.Add("}");
lines.Add("");
}

private static void AppendNonDateField(List<string> lines, DDField field) {
lines.Add(" /// <summary>");
lines.Add($" /// {field.Name} Field");
lines.Add(" /// </summary>");
lines.Add($" public sealed class {field.Name} : {field.CsClass}");
lines.Add(" {");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("/// <summary>");
lines.Add($"/// {field.Name} Field");
lines.Add("/// </summary>");
lines.Add($"public sealed class {field.Name} : {field.CsClass}");
lines.Add("{");
lines.Add($" public const int TAG = {field.Tag};");
lines.Add("");

lines.Add($" public {field.Name}()");
lines.Add($" :base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" :base(Tags.{field.Name}, val) {{}}");
lines.Add("");
lines.Add($" public {field.Name}()");
lines.Add($" : base(Tags.{field.Name}) {{}}");
lines.Add($" public {field.Name}({field.BaseType} val)");
lines.Add($" : base(Tags.{field.Name}, val) {{}}");

AppendFieldEnumerations(lines, field);
if (lines.Count > 0) {
AppendFieldEnumerations(lines, field);
}

lines.Add(" }");
lines.Add("");
lines.Add("}");
lines.Add("");
}

Expand All @@ -103,7 +102,7 @@ private static void AppendFieldEnumerations(List<string> lines, DDField field) {
return;

lines.Add("");
lines.Add(" // Field Enumerations");
lines.Add(" // Field Enumerations");

foreach (var enumVal in field.Enums) {
string desc = enumVal.Desc.Replace('.', '_');
Expand All @@ -122,7 +121,7 @@ private static void AppendFieldEnumerations(List<string> lines, DDField field) {
$"unsupported field type '{field.BaseType}' ({field})")
};

lines.Add($" public const {field.BaseType} {desc} = {outVal};");
lines.Add($" public const {field.BaseType} {desc} = {outVal};");
}
}
}
Loading

0 comments on commit febd6c5

Please sign in to comment.