Skip to content

Commit

Permalink
Merge pull request #920 from gbirchmeier/better-gen
Browse files Browse the repository at this point in the history
enable nullable in Messages projects; fix a warning in IMessageFactory; clean up generated MessageFactory classes
  • Loading branch information
mgatny authored Jan 2, 2025
2 parents 091420f + 1355e7c commit 250ecee
Show file tree
Hide file tree
Showing 23 changed files with 8,741 additions and 8,819 deletions.
55 changes: 23 additions & 32 deletions DDTool/DDTool/Generators/GenMessageFactories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,40 @@ private static string Generate(DataDictionary dd) {
"using System.Collections.Generic;",
"using QuickFix.FixValues;",
"",
"namespace QuickFix",
$"namespace QuickFix.{dd.IdentifierNoDots};",
"",
"public class MessageFactory : IMessageFactory",
"{",
$" namespace {dd.IdentifierNoDots}",
" public ICollection<string> GetSupportedBeginStrings()",
" {",
" public class MessageFactory : IMessageFactory",
" {",
" public ICollection<string> GetSupportedBeginStrings()",
" {",
$" return new [] {{ BeginString.{dd.IdentifierNoDots} }};",
" }",
"",
"",
" public QuickFix.Message Create(string beginString, QuickFix.Fields.ApplVerID applVerId, string msgType)",
" {",
" return Create(beginString, msgType);",
" }",
$" return new [] {{ BeginString.{dd.IdentifierNoDots} }};",
" }",
"",
" public QuickFix.Message Create(string beginString, QuickFix.Fields.ApplVerID applVerId, string msgType)",
" {",
" return Create(beginString, msgType);",
" }",
"",
" public QuickFix.Message Create(string beginString, string msgType)",
" {",
" switch (msgType)",
" {"
" public QuickFix.Message Create(string beginString, string msgType)",
" {",
" return msgType switch",
" {"
};

// TODO: foreach order is technically non-deterministic (though not in practice)
foreach (var msg in dd.Messages.Values) {
var fullname = $"QuickFix.{dd.IdentifierNoDots}.{msg.Name}";
lines.Add(new string(' ', 20) + $"case {fullname}.MsgType: return new {fullname}();");
lines.Add(new string(' ', 12) + $"{fullname}.MsgType => new {fullname}(),");
}

lines.AddRange(new List<string>
{
" }",
"",
" return new QuickFix.Message();",
" }",
"",
" _ => new QuickFix.Message()",
" };",
" }",
"",
" public Group Create(string beginString, string msgType, int correspondingFieldID)",
" {"
" public Group? Create(string beginString, string msgType, int correspondingFieldId)",
" {"
});

// TODO: foreach order is technically non-deterministic (though not in practice)
Expand All @@ -83,7 +77,7 @@ private static string Generate(DataDictionary dd) {

xLines.Add($"if (QuickFix.{dd.IdentifierNoDots}.{msg.Name}.MsgType.Equals(msgType))");
xLines.Add("{");
xLines.Add(" switch (correspondingFieldID)");
xLines.Add(" switch (correspondingFieldId)");
xLines.Add(" {");

foreach (var group in groups) {
Expand All @@ -94,15 +88,12 @@ private static string Generate(DataDictionary dd) {
xLines.Add("}");

// indent lines
lines.AddRange(xLines.Select(xl => new string(' ', 16) + xl));
lines.AddRange(xLines.Select(xl => new string(' ', 8) + xl));
lines.Add("");
}

lines.AddRange(new List<string>{
" return null;",
" }",
"",
" }",
" return null;",
" }",
"}",
""
Expand Down
169 changes: 80 additions & 89 deletions Messages/FIX40/MessageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,101 @@
using System.Collections.Generic;
using QuickFix.FixValues;

namespace QuickFix
namespace QuickFix.FIX40;

public class MessageFactory : IMessageFactory
{
namespace FIX40
public ICollection<string> GetSupportedBeginStrings()
{
return new [] { BeginString.FIX40 };
}

public QuickFix.Message Create(string beginString, QuickFix.Fields.ApplVerID applVerId, string msgType)
{
return Create(beginString, msgType);
}

public QuickFix.Message Create(string beginString, string msgType)
{
return msgType switch
{
QuickFix.FIX40.Heartbeat.MsgType => new QuickFix.FIX40.Heartbeat(),
QuickFix.FIX40.Logon.MsgType => new QuickFix.FIX40.Logon(),
QuickFix.FIX40.TestRequest.MsgType => new QuickFix.FIX40.TestRequest(),
QuickFix.FIX40.ResendRequest.MsgType => new QuickFix.FIX40.ResendRequest(),
QuickFix.FIX40.Reject.MsgType => new QuickFix.FIX40.Reject(),
QuickFix.FIX40.SequenceReset.MsgType => new QuickFix.FIX40.SequenceReset(),
QuickFix.FIX40.Logout.MsgType => new QuickFix.FIX40.Logout(),
QuickFix.FIX40.Advertisement.MsgType => new QuickFix.FIX40.Advertisement(),
QuickFix.FIX40.IndicationofInterest.MsgType => new QuickFix.FIX40.IndicationofInterest(),
QuickFix.FIX40.News.MsgType => new QuickFix.FIX40.News(),
QuickFix.FIX40.Email.MsgType => new QuickFix.FIX40.Email(),
QuickFix.FIX40.QuoteRequest.MsgType => new QuickFix.FIX40.QuoteRequest(),
QuickFix.FIX40.Quote.MsgType => new QuickFix.FIX40.Quote(),
QuickFix.FIX40.NewOrderSingle.MsgType => new QuickFix.FIX40.NewOrderSingle(),
QuickFix.FIX40.ExecutionReport.MsgType => new QuickFix.FIX40.ExecutionReport(),
QuickFix.FIX40.DontKnowTrade.MsgType => new QuickFix.FIX40.DontKnowTrade(),
QuickFix.FIX40.OrderCancelReplaceRequest.MsgType => new QuickFix.FIX40.OrderCancelReplaceRequest(),
QuickFix.FIX40.OrderCancelRequest.MsgType => new QuickFix.FIX40.OrderCancelRequest(),
QuickFix.FIX40.OrderCancelReject.MsgType => new QuickFix.FIX40.OrderCancelReject(),
QuickFix.FIX40.OrderStatusRequest.MsgType => new QuickFix.FIX40.OrderStatusRequest(),
QuickFix.FIX40.Allocation.MsgType => new QuickFix.FIX40.Allocation(),
QuickFix.FIX40.AllocationACK.MsgType => new QuickFix.FIX40.AllocationACK(),
QuickFix.FIX40.NewOrderList.MsgType => new QuickFix.FIX40.NewOrderList(),
QuickFix.FIX40.ListStatus.MsgType => new QuickFix.FIX40.ListStatus(),
QuickFix.FIX40.ListExecute.MsgType => new QuickFix.FIX40.ListExecute(),
QuickFix.FIX40.ListCancelRequest.MsgType => new QuickFix.FIX40.ListCancelRequest(),
QuickFix.FIX40.ListStatusRequest.MsgType => new QuickFix.FIX40.ListStatusRequest(),
_ => new QuickFix.Message()
};
}

public Group? Create(string beginString, string msgType, int correspondingFieldId)
{
public class MessageFactory : IMessageFactory
if (QuickFix.FIX40.News.MsgType.Equals(msgType))
{
public ICollection<string> GetSupportedBeginStrings()
switch (correspondingFieldId)
{
return new [] { BeginString.FIX40 };
case QuickFix.Fields.Tags.LinesOfText: return new QuickFix.FIX40.News.LinesOfTextGroup();
}
}


public QuickFix.Message Create(string beginString, QuickFix.Fields.ApplVerID applVerId, string msgType)
if (QuickFix.FIX40.Email.MsgType.Equals(msgType))
{
switch (correspondingFieldId)
{
return Create(beginString, msgType);
case QuickFix.Fields.Tags.LinesOfText: return new QuickFix.FIX40.Email.LinesOfTextGroup();
}
}


public QuickFix.Message Create(string beginString, string msgType)
if (QuickFix.FIX40.ExecutionReport.MsgType.Equals(msgType))
{
switch (correspondingFieldId)
{
switch (msgType)
{
case QuickFix.FIX40.Heartbeat.MsgType: return new QuickFix.FIX40.Heartbeat();
case QuickFix.FIX40.Logon.MsgType: return new QuickFix.FIX40.Logon();
case QuickFix.FIX40.TestRequest.MsgType: return new QuickFix.FIX40.TestRequest();
case QuickFix.FIX40.ResendRequest.MsgType: return new QuickFix.FIX40.ResendRequest();
case QuickFix.FIX40.Reject.MsgType: return new QuickFix.FIX40.Reject();
case QuickFix.FIX40.SequenceReset.MsgType: return new QuickFix.FIX40.SequenceReset();
case QuickFix.FIX40.Logout.MsgType: return new QuickFix.FIX40.Logout();
case QuickFix.FIX40.Advertisement.MsgType: return new QuickFix.FIX40.Advertisement();
case QuickFix.FIX40.IndicationofInterest.MsgType: return new QuickFix.FIX40.IndicationofInterest();
case QuickFix.FIX40.News.MsgType: return new QuickFix.FIX40.News();
case QuickFix.FIX40.Email.MsgType: return new QuickFix.FIX40.Email();
case QuickFix.FIX40.QuoteRequest.MsgType: return new QuickFix.FIX40.QuoteRequest();
case QuickFix.FIX40.Quote.MsgType: return new QuickFix.FIX40.Quote();
case QuickFix.FIX40.NewOrderSingle.MsgType: return new QuickFix.FIX40.NewOrderSingle();
case QuickFix.FIX40.ExecutionReport.MsgType: return new QuickFix.FIX40.ExecutionReport();
case QuickFix.FIX40.DontKnowTrade.MsgType: return new QuickFix.FIX40.DontKnowTrade();
case QuickFix.FIX40.OrderCancelReplaceRequest.MsgType: return new QuickFix.FIX40.OrderCancelReplaceRequest();
case QuickFix.FIX40.OrderCancelRequest.MsgType: return new QuickFix.FIX40.OrderCancelRequest();
case QuickFix.FIX40.OrderCancelReject.MsgType: return new QuickFix.FIX40.OrderCancelReject();
case QuickFix.FIX40.OrderStatusRequest.MsgType: return new QuickFix.FIX40.OrderStatusRequest();
case QuickFix.FIX40.Allocation.MsgType: return new QuickFix.FIX40.Allocation();
case QuickFix.FIX40.AllocationACK.MsgType: return new QuickFix.FIX40.AllocationACK();
case QuickFix.FIX40.NewOrderList.MsgType: return new QuickFix.FIX40.NewOrderList();
case QuickFix.FIX40.ListStatus.MsgType: return new QuickFix.FIX40.ListStatus();
case QuickFix.FIX40.ListExecute.MsgType: return new QuickFix.FIX40.ListExecute();
case QuickFix.FIX40.ListCancelRequest.MsgType: return new QuickFix.FIX40.ListCancelRequest();
case QuickFix.FIX40.ListStatusRequest.MsgType: return new QuickFix.FIX40.ListStatusRequest();
}

return new QuickFix.Message();
case QuickFix.Fields.Tags.NoMiscFees: return new QuickFix.FIX40.ExecutionReport.NoMiscFeesGroup();
}
}


public Group Create(string beginString, string msgType, int correspondingFieldID)
if (QuickFix.FIX40.Allocation.MsgType.Equals(msgType))
{
switch (correspondingFieldId)
{
if (QuickFix.FIX40.News.MsgType.Equals(msgType))
{
switch (correspondingFieldID)
{
case QuickFix.Fields.Tags.LinesOfText: return new QuickFix.FIX40.News.LinesOfTextGroup();
}
}

if (QuickFix.FIX40.Email.MsgType.Equals(msgType))
{
switch (correspondingFieldID)
{
case QuickFix.Fields.Tags.LinesOfText: return new QuickFix.FIX40.Email.LinesOfTextGroup();
}
}

if (QuickFix.FIX40.ExecutionReport.MsgType.Equals(msgType))
{
switch (correspondingFieldID)
{
case QuickFix.Fields.Tags.NoMiscFees: return new QuickFix.FIX40.ExecutionReport.NoMiscFeesGroup();
}
}

if (QuickFix.FIX40.Allocation.MsgType.Equals(msgType))
{
switch (correspondingFieldID)
{
case QuickFix.Fields.Tags.NoOrders: return new QuickFix.FIX40.Allocation.NoOrdersGroup();
case QuickFix.Fields.Tags.NoExecs: return new QuickFix.FIX40.Allocation.NoExecsGroup();
case QuickFix.Fields.Tags.NoMiscFees: return new QuickFix.FIX40.Allocation.NoMiscFeesGroup();
case QuickFix.Fields.Tags.NoAllocs: return new QuickFix.FIX40.Allocation.NoAllocsGroup();
case QuickFix.Fields.Tags.NoDlvyInst: return new QuickFix.FIX40.Allocation.NoAllocsGroup.NoDlvyInstGroup();
}
}

if (QuickFix.FIX40.ListStatus.MsgType.Equals(msgType))
{
switch (correspondingFieldID)
{
case QuickFix.Fields.Tags.NoOrders: return new QuickFix.FIX40.ListStatus.NoOrdersGroup();
}
}

return null;
case QuickFix.Fields.Tags.NoOrders: return new QuickFix.FIX40.Allocation.NoOrdersGroup();
case QuickFix.Fields.Tags.NoExecs: return new QuickFix.FIX40.Allocation.NoExecsGroup();
case QuickFix.Fields.Tags.NoMiscFees: return new QuickFix.FIX40.Allocation.NoMiscFeesGroup();
case QuickFix.Fields.Tags.NoAllocs: return new QuickFix.FIX40.Allocation.NoAllocsGroup();
case QuickFix.Fields.Tags.NoDlvyInst: return new QuickFix.FIX40.Allocation.NoAllocsGroup.NoDlvyInstGroup();
}
}

if (QuickFix.FIX40.ListStatus.MsgType.Equals(msgType))
{
switch (correspondingFieldId)
{
case QuickFix.Fields.Tags.NoOrders: return new QuickFix.FIX40.ListStatus.NoOrdersGroup();
}
}

return null;
}
}
1 change: 1 addition & 0 deletions Messages/FIX40/QuickFix.FIX40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>qfn-icon.png</PackageIcon>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 250ecee

Please sign in to comment.