chore: replace hard-coded -1 sentinels with named constexpr constants#295
Merged
Conversation
…tants Adds INDEX_UNSPECIFIED, NUMBER_LEVEL_UNSPECIFIED, VALUE_UNSPECIFIED, and DOUBLE_UNSPECIFIED to ApiCommon.h and uses them in place of the hard-coded -1 / -1.0 sentinel literals across the mx::api headers and the mx::impl translation layer. No behavior change; the constants equal the old literals. Closes #282.
Coverage reportCore-dev coverage
|
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 77.8% | 28487 / 36624 |
| Functions | 74.3% | 6349 / 8550 |
| Branches | 50.6% | 22632 / 44725 |
API coverage src/private/mx/{api,impl,utility}/
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 78.7% | 6117 / 7776 |
| Functions | 64.3% | 2091 / 3252 |
| Branches | 47.9% | 5206 / 10866 |
Core HTML report | API HTML report
Commit 49f6a7270c5b29db9f4962ef3769e4db5ecd2d52.
gen-quality
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Summary
Seems pretty mechanical and straightforward. I haven't read every line but I see that it added a few sentinel constants and wired them into the codebase.
Summary
The
mx::apilayer used hard-coded-1(and-1.0) literals as "unspecified" sentinels, e.g.staffIndex{-1}inKeyData.h. This change gives those sentinels names, defined inApiCommon.hnext to the existing constants:INDEX_UNSPECIFIED- staff/part indices and staff numbers (e.g.KeyData::staffIndex,PartGroupData::firstPartIndex,PartSymbolData::topStaff)NUMBER_LEVEL_UNSPECIFIED- MusicXMLnumberattributes (e.g.SpannerStart::numberLevel, wedges, tuplets, curves,PartGroupData::number)VALUE_UNSPECIFIED- other absent-able ints (e.g.DirectionData::voice, midibank/channel/program,BeatsPerMinute::beatsPerMinute,EncodingDate)DOUBLE_UNSPECIFIED- absent-able doubles (e.g.StaffData::staffSize,SoundData::tempo,DefaultsData::scalingMillimeters,MeasureData::width)The constants equal the old literals, so this is non-breaking and there is no behavior change. The api headers and the impl translation layer now use the names wherever the literal carried this sentinel meaning; unrelated
-1s (musical alter values, arithmetic, mx::core internals) are untouched. Comments that documented "-1 means unspecified" now name the constant instead.This is deliberately the lightweight named-constant version; moving these fields to
std::optionalis a separate breaking change tracked in #249.Testing
make fmtandmake checkpassmake testpasses: 4458 assertions in 346 test cases, examples runconstexprand equal to the old literalsReferences
isSpecifiedbool pairs with an explicit optional value type #249