Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions gen/cpp/templates/enum.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
namespace {{vars.namespace}}
{

namespace
{

constexpr std::string_view kWire[] = {
constexpr std::string_view k{{ident}}Wire[] = {
{{#variants}}
{{name.wire_q}},
{{/variants}}
};

} // namespace

{{#variants}}
{{type.ident}} {{type.ident}}::{{ident}}() noexcept
{
Expand All @@ -28,14 +23,14 @@ constexpr std::string_view kWire[] = {
{{/variants}}
std::string_view {{ident}}::toString() const noexcept
{
return kWire[static_cast<std::size_t>(m_tag)];
return k{{ident}}Wire[static_cast<std::size_t>(m_tag)];
}

bool {{ident}}::tryParse(std::string_view text, {{ident}} &out) noexcept
{
for (std::size_t i = 0; i < std::size(kWire); ++i)
for (std::size_t i = 0; i < std::size(k{{ident}}Wire); ++i)
{
if (kWire[i] == text)
if (k{{ident}}Wire[i] == text)
{
out = {{ident}}{static_cast<Tag>(i)};
return true;
Expand Down
13 changes: 4 additions & 9 deletions gen/cpp/templates/number.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
namespace {{vars.namespace}}
{

namespace
{

{{target_type}} clamped({{target_type}} v)
{{target_type}} clamped{{ident}}({{target_type}} v)
{
{{#clamp}}
{{#type.is_decimal}}
Expand All @@ -31,19 +28,17 @@ namespace
return v;
}

} // namespace

{{ident}}::{{ident}}() : m_value{clamped({{target_type}}{})}
{{ident}}::{{ident}}() : m_value{clamped{{ident}}({{target_type}}{})}
{
}

{{ident}}::{{ident}}({{target_type}} value) : m_value{clamped(std::move(value))}
{{ident}}::{{ident}}({{target_type}} value) : m_value{clamped{{ident}}(std::move(value))}
{
}

void {{ident}}::setValue({{target_type}} value)
{
m_value = clamped(std::move(value));
m_value = clamped{{ident}}(std::move(value));
}

std::string {{ident}}::toString() const
Expand Down
25 changes: 10 additions & 15 deletions gen/cpp/templates/smufl_prefixed.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@
namespace {{vars.namespace}}
{

namespace
{

constexpr std::string_view kPrefix[] = {
constexpr std::string_view k{{ident}}Prefix[] = {
{{#prefixes}}
{{name.wire_q}},
{{/prefixes}}
};

// The ASCII subset of XML name characters the schema's \c denotes.
bool isNameChar(char c) noexcept
bool isNameChar{{ident}}(char c) noexcept
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' ||
c == '.' || c == ':' || c == '_';
}

} // namespace

{{ident}}::{{ident}}()
{
repair();
Expand All @@ -46,7 +41,7 @@ bool isNameChar(char c) noexcept
void {{ident}}::setPrefix(Prefix value) noexcept
{
m_prefix = value;
if (static_cast<std::size_t>(m_prefix) >= std::size(kPrefix))
if (static_cast<std::size_t>(m_prefix) >= std::size(k{{ident}}Prefix))
{
m_prefix = Prefix::{{#prefixes}}{{#is_first}}{{ident}}{{/is_first}}{{/prefixes}};
}
Expand All @@ -62,7 +57,7 @@ void {{ident}}::setSuffix(std::string value)
void {{ident}}::repair()
{
{{#multi_prefix}}
if (static_cast<std::size_t>(m_prefix) >= std::size(kPrefix))
if (static_cast<std::size_t>(m_prefix) >= std::size(k{{ident}}Prefix))
{
m_prefix = Prefix::{{#prefixes}}{{#is_first}}{{ident}}{{/is_first}}{{/prefixes}};
}
Expand All @@ -71,7 +66,7 @@ void {{ident}}::repair()
cleaned.reserve(m_suffix.size());
for (const char c : m_suffix)
{
if (isNameChar(c))
if (isNameChar{{ident}}(c))
{
cleaned.push_back(c);
}
Expand All @@ -88,20 +83,20 @@ void {{ident}}::repair()
std::string {{ident}}::toString() const
{
{{#multi_prefix}}
std::string out{kPrefix[static_cast<std::size_t>(m_prefix)]};
std::string out{k{{ident}}Prefix[static_cast<std::size_t>(m_prefix)]};
{{/multi_prefix}}
{{^multi_prefix}}
std::string out{kPrefix[0]};
std::string out{k{{ident}}Prefix[0]};
{{/multi_prefix}}
out += m_suffix;
return out;
}

bool {{ident}}::tryParse(std::string_view text, {{ident}} &out)
{
for (std::size_t i = 0; i < std::size(kPrefix); ++i)
for (std::size_t i = 0; i < std::size(k{{ident}}Prefix); ++i)
{
const std::string_view prefix = kPrefix[i];
const std::string_view prefix = k{{ident}}Prefix[i];
if (text.size() < prefix.size() || text.substr(0, prefix.size()) != prefix)
{
continue;
Expand All @@ -116,7 +111,7 @@ bool {{ident}}::tryParse(std::string_view text, {{ident}} &out)
bool valid = true;
for (const char c : suffix)
{
if (!isNameChar(c))
if (!isNameChar{{ident}}(c))
{
valid = false;
break;
Expand Down
13 changes: 4 additions & 9 deletions gen/cpp/templates/string.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
namespace {{vars.namespace}}
{

namespace
{

std::string repaired(std::string v)
std::string repaired{{ident}}(std::string v)
{
{{#min_length}}
// Deterministic repair to the schema's minLength (plan §2.2.2): pad
Expand All @@ -23,21 +20,19 @@ std::string repaired(std::string v)
return v;
}

} // namespace

{{#min_length}}
{{ident}}::{{ident}}() : m_value{repaired(std::string{})}
{{ident}}::{{ident}}() : m_value{repaired{{ident}}(std::string{})}
{
}

{{/min_length}}
{{ident}}::{{ident}}(std::string value) : m_value{repaired(std::move(value))}
{{ident}}::{{ident}}(std::string value) : m_value{repaired{{ident}}(std::move(value))}
{
}

void {{ident}}::setValue(std::string value)
{
m_value = repaired(std::move(value));
m_value = repaired{{ident}}(std::move(value));
}

bool {{ident}}::tryParse(std::string_view text, {{ident}} &out)
Expand Down
13 changes: 4 additions & 9 deletions src/private/mx/core/generated/AboveBelow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
namespace mx::core
{

namespace
{

constexpr std::string_view kWire[] = {
constexpr std::string_view kAboveBelowWire[] = {
"above",
"below",
};

} // namespace

AboveBelow AboveBelow::above() noexcept
{
return AboveBelow{Tag::above};
Expand All @@ -30,14 +25,14 @@ AboveBelow AboveBelow::below() noexcept

std::string_view AboveBelow::toString() const noexcept
{
return kWire[static_cast<std::size_t>(m_tag)];
return kAboveBelowWire[static_cast<std::size_t>(m_tag)];
}

bool AboveBelow::tryParse(std::string_view text, AboveBelow &out) noexcept
{
for (std::size_t i = 0; i < std::size(kWire); ++i)
for (std::size_t i = 0; i < std::size(kAboveBelowWire); ++i)
{
if (kWire[i] == text)
if (kAboveBelowWire[i] == text)
{
out = AboveBelow{static_cast<Tag>(i)};
return true;
Expand Down
13 changes: 4 additions & 9 deletions src/private/mx/core/generated/AccidentalValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
namespace mx::core
{

namespace
{

constexpr std::string_view kWire[] = {
constexpr std::string_view kAccidentalValueWire[] = {
"sharp",
"natural",
"flat",
Expand Down Expand Up @@ -55,8 +52,6 @@ constexpr std::string_view kWire[] = {
"other",
};

} // namespace

AccidentalValue AccidentalValue::sharp() noexcept
{
return AccidentalValue{Tag::sharp};
Expand Down Expand Up @@ -264,14 +259,14 @@ AccidentalValue AccidentalValue::other() noexcept

std::string_view AccidentalValue::toString() const noexcept
{
return kWire[static_cast<std::size_t>(m_tag)];
return kAccidentalValueWire[static_cast<std::size_t>(m_tag)];
}

bool AccidentalValue::tryParse(std::string_view text, AccidentalValue &out) noexcept
{
for (std::size_t i = 0; i < std::size(kWire); ++i)
for (std::size_t i = 0; i < std::size(kAccidentalValueWire); ++i)
{
if (kWire[i] == text)
if (kAccidentalValueWire[i] == text)
{
out = AccidentalValue{static_cast<Tag>(i)};
return true;
Expand Down
13 changes: 4 additions & 9 deletions src/private/mx/core/generated/AccordionMiddle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
namespace mx::core
{

namespace
{

int clamped(int v)
int clampedAccordionMiddle(int v)
{
if (v < 1)
{
Expand All @@ -25,19 +22,17 @@ int clamped(int v)
return v;
}

} // namespace

AccordionMiddle::AccordionMiddle() : m_value{clamped(int{})}
AccordionMiddle::AccordionMiddle() : m_value{clampedAccordionMiddle(int{})}
{
}

AccordionMiddle::AccordionMiddle(int value) : m_value{clamped(std::move(value))}
AccordionMiddle::AccordionMiddle(int value) : m_value{clampedAccordionMiddle(std::move(value))}
{
}

void AccordionMiddle::setValue(int value)
{
m_value = clamped(std::move(value));
m_value = clampedAccordionMiddle(std::move(value));
}

std::string AccordionMiddle::toString() const
Expand Down
13 changes: 4 additions & 9 deletions src/private/mx/core/generated/ArrowDirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
namespace mx::core
{

namespace
{

constexpr std::string_view kWire[] = {
constexpr std::string_view kArrowDirectionWire[] = {
"left", "up", "right", "down", "northwest", "northeast",
"southeast", "southwest", "left right", "up down", "northwest southeast", "northeast southwest",
"other",
};

} // namespace

ArrowDirection ArrowDirection::left() noexcept
{
return ArrowDirection{Tag::left};
Expand Down Expand Up @@ -86,14 +81,14 @@ ArrowDirection ArrowDirection::other() noexcept

std::string_view ArrowDirection::toString() const noexcept
{
return kWire[static_cast<std::size_t>(m_tag)];
return kArrowDirectionWire[static_cast<std::size_t>(m_tag)];
}

bool ArrowDirection::tryParse(std::string_view text, ArrowDirection &out) noexcept
{
for (std::size_t i = 0; i < std::size(kWire); ++i)
for (std::size_t i = 0; i < std::size(kArrowDirectionWire); ++i)
{
if (kWire[i] == text)
if (kArrowDirectionWire[i] == text)
{
out = ArrowDirection{static_cast<Tag>(i)};
return true;
Expand Down
13 changes: 4 additions & 9 deletions src/private/mx/core/generated/ArrowStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
namespace mx::core
{

namespace
{

constexpr std::string_view kWire[] = {
constexpr std::string_view kArrowStyleWire[] = {
"single", "double", "filled", "hollow", "paired", "combined", "other",
};

} // namespace

ArrowStyle ArrowStyle::single() noexcept
{
return ArrowStyle{Tag::single};
Expand Down Expand Up @@ -54,14 +49,14 @@ ArrowStyle ArrowStyle::other() noexcept

std::string_view ArrowStyle::toString() const noexcept
{
return kWire[static_cast<std::size_t>(m_tag)];
return kArrowStyleWire[static_cast<std::size_t>(m_tag)];
}

bool ArrowStyle::tryParse(std::string_view text, ArrowStyle &out) noexcept
{
for (std::size_t i = 0; i < std::size(kWire); ++i)
for (std::size_t i = 0; i < std::size(kArrowStyleWire); ++i)
{
if (kWire[i] == text)
if (kArrowStyleWire[i] == text)
{
out = ArrowStyle{static_cast<Tag>(i)};
return true;
Expand Down
Loading
Loading