Skip to content

Commit

Permalink
dexi: adds new FONTNAME and INTERVAL tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jul 2, 2024
1 parent 3325d4a commit 0fb1a61
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
36 changes: 36 additions & 0 deletions lib/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ struct Model_reader
OPTION,
SETTINGS,
FONTSIZE,
FONTNAME,
PAGEBREAK,
REPORTS,
ATTRIBUTE,
NAME,
DESCRIPTION,
SCALE,
INTERVAL,
ORDER,
SCALEVALUE,
GROUP,
Expand Down Expand Up @@ -153,12 +155,14 @@ struct Model_reader
{ "OPTION", stack_identifier::OPTION },
{ "SETTINGS", stack_identifier::SETTINGS },
{ "FONTSIZE", stack_identifier::FONTSIZE },
{ "FONTNAME", stack_identifier::FONTNAME },
{ "PAGEBREAK", stack_identifier::PAGEBREAK },
{ "REPORTS", stack_identifier::REPORTS },
{ "ATTRIBUTE", stack_identifier::ATTRIBUTE },
{ "NAME", stack_identifier::NAME },
{ "DESCRIPTION", stack_identifier::DESCRIPTION },
{ "SCALE", stack_identifier::SCALE },
{ "INTERVAL", stack_identifier::INTERVAL },
{ "ORDER", stack_identifier::ORDER },
{ "SCALEVALUE", stack_identifier::SCALEVALUE },
{ "GROUP", stack_identifier::GROUP },
Expand Down Expand Up @@ -289,6 +293,14 @@ struct Model_reader
pd->stack.push(id);
break;

case stack_identifier::FONTNAME:
if (!pd->is_parent({ stack_identifier::SETTINGS })) {
pd->stop_parser(status::dexi_parser_file_format_error);
break;
}
pd->stack.push(id);
break;

case stack_identifier::PAGEBREAK:
if (!pd->is_parent({ stack_identifier::SETTINGS })) {
pd->stop_parser(status::dexi_parser_file_format_error);
Expand Down Expand Up @@ -381,6 +393,13 @@ struct Model_reader
}
break;

case stack_identifier::INTERVAL:
if (!pd->is_parent({ stack_identifier::SCALE })) {
pd->stop_parser(status::dexi_parser_file_format_error);
break;
}
break;

case stack_identifier::SCALEVALUE:
if (!pd->is_parent({ stack_identifier::SCALE })) {
pd->stop_parser(status::dexi_parser_file_format_error);
Expand Down Expand Up @@ -491,6 +510,11 @@ struct Model_reader
pd->stack.pop();
break;

case stack_identifier::FONTNAME:
pd->model.fontname.assign(pd->char_data);
pd->stack.pop();
break;

case stack_identifier::PAGEBREAK:
pd->model.pagebreak.assign(pd->char_data);
pd->stack.pop();
Expand Down Expand Up @@ -567,7 +591,11 @@ struct Model_reader
case stack_identifier::ORDER:
if (pd->char_data == "NONE")
pd->model.attributes.back().scale.order = false;
break;

case stack_identifier::INTERVAL:
pd->model.attributes.back().scale.interval =
(pd->char_data != "False");
break;

case stack_identifier::SCALEVALUE:
Expand Down Expand Up @@ -742,6 +770,9 @@ struct Model_writer
if (!dex.fontsize.empty())
os.print(" <FONTSIZE>{}</FONTSIZE>\n", escape(dex.fontsize));

if (!dex.fontname.empty())
os.print(" <FONTNAME>{}</FONTNAME>\n", escape(dex.fontname));

if (!dex.optdatatype.empty())
os.print(" <OPTDATATYPE>{}</OPTDATATYPE>\n",
escape(dex.optdatatype));
Expand Down Expand Up @@ -860,6 +891,11 @@ struct Model_writer
os.print("<ORDER>NONE</ORDER>\n");
}

if (!att.scale.interval) {
make_space();
os.print("<INTERVAL>False</INTERVAL>\n");
}

for (const auto& sv : att.scale.scale) {
make_space();
os.print("<SCALEVALUE>\n");
Expand Down
12 changes: 6 additions & 6 deletions lib/src/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ struct function

struct scales
{
scales()
: order(true)
{
}
scales() = default;

bool order;
bool order = true;
bool interval = false;
std::vector<scalevalue> scale;

std::optional<scale_id> find_scale_value(const std::string& name) const
Expand Down Expand Up @@ -163,6 +161,7 @@ struct Model
std::string created;
std::string pagebreak = "True";
std::string fontsize;
std::string fontname;
std::string reports = "6";
std::string optdatatype;
std::string optlevels;
Expand Down Expand Up @@ -270,7 +269,8 @@ operator==(const scalevalue& lhs, const scalevalue& rhs)
inline bool
operator==(const scales& lhs, const scales& rhs)
{
return lhs.order == rhs.order && lhs.scale == rhs.scale;
return lhs.order == rhs.order && lhs.interval == rhs.interval &&
lhs.scale == rhs.scale;
}

inline bool
Expand Down

0 comments on commit 0fb1a61

Please sign in to comment.