Skip to content

Commit

Permalink
Fixed incorrect default value for sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBAM committed Nov 23, 2021
1 parent 0c137b9 commit 9486d41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/mfast/xml_parser/field_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,26 @@ void field_builder::visit(const set_field_instruction *inst, void *)
(alloc().allocate(names.size() * sizeof(const char*)));
std::copy(names.begin(), names.end(), set_element_names);
}
else
if (init_value_str)
{
std::optional<std::uint64_t> value_int;
try
{
value_int = std::stoul(init_value_str);
} catch (...) {}
if (value_int)
fop.initial_value_.set<uint64_t>(*value_int);
else
{
for (auto i = 0ul; i < num_elements; ++i)
if (std::strcmp(set_element_names[i], init_value_str) == 0)
{
fop.initial_value_.set<uint64_t>(1 << i);
break;
}
}
}

auto instruction = new (alloc()) set_field_instruction(
fop.op_, get_presence(inst), get_id(inst), get_name(alloc()),
Expand Down
11 changes: 7 additions & 4 deletions tests/test_eurex_fast_1_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TEST_CASE("eurex sets", "[test_eurex_sets]")

DepthIncremental md(&alloc);
DepthIncremental_mref md_mref(md.mref());
REQUIRE(md_mref.get_TradeCondition().value() == 1);
REQUIRE(md_mref.get_TradeCondition().has_ExchangeLast());
md_mref.omit_TradeCondition();
REQUIRE_THROWS_AS(md_mref.try_get_TradeCondition(), const mfast::bad_optional_access&);
Expand All @@ -94,10 +95,12 @@ TEST_CASE("eurex sets", "[test_eurex_sets]")
REQUIRE(!md_mref.get_TradeCondition().has_LowPrice());
REQUIRE(md_mref.get_TradeCondition().has_TradeAtClose());
md_mref.set_TradeCondition().unset_TradeAtClose();
md_mref.set_TradeConditionSet().set_VolumeOnly();
REQUIRE(!md_mref.get_TradeCondition().has_LowPrice());
REQUIRE(!md_mref.get_TradeCondition().has_TradeAtClose());
REQUIRE(md_mref.get_TradeConditionSet().has_VolumeOnly());
REQUIRE(md_mref.set_TradeConditionSet().value() == 9);
REQUIRE(md_mref.get_TradeConditionSet().has_ExchangeLast());
REQUIRE(!md_mref.get_TradeConditionSet().has_HighPrice());
REQUIRE(md_mref.get_TradeConditionSet().has_LowPrice());
REQUIRE(!md_mref.get_TradeConditionSet().has_OfficialClosingPrice());
REQUIRE(!md_mref.get_TradeConditionSet().has_TradeAtClose());
}


Expand Down

0 comments on commit 9486d41

Please sign in to comment.