1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Switch to lambda.

This commit is contained in:
Thomas Harte 2024-01-22 21:22:56 -05:00
parent cb125e6336
commit cc165b65be

View File

@ -88,22 +88,23 @@ void Parser::inspect_waves(const std::vector<WaveType> &waves) {
} }
break; break;
case SlowData: case SlowData: {
#define CHECK_RUN(length, type, symbol) \ const auto check_run = [&](std::size_t length, WaveType type, SymbolType symbol) -> bool {
if(waves.size() >= length) {\ if(waves.size() >= length) {
std::size_t c;\ std::size_t c;
for(c = 0; c < length; c++) if(waves[c] != type) break;\ for(c = 0; c < length; c++) if(waves[c] != type) break;
if(c == length) {\ if(c == length) {
push_symbol(symbol, length);\ push_symbol(symbol, int(length));
return;\ return true;
}\ }
} }
return false;
};
CHECK_RUN(4, WaveType::Long, SymbolType::Zero); if(check_run(4, WaveType::Long, SymbolType::Zero)) return;
CHECK_RUN(8, WaveType::Short, SymbolType::One); if(check_run(8, WaveType::Short, SymbolType::One)) return;
#undef CHECK_RUN
if(waves.size() < 16) return; // TODO, maybe: if there are any inconsistencies in the first 8, don't return if(waves.size() < 16) return; // TODO, maybe: if there are any inconsistencies in the first 8, don't return
break; } break;
case Sync: { case Sync: {
// Sync is 0x16, either encoded fast or slow; i.e. 0 0110 1000 1 // Sync is 0x16, either encoded fast or slow; i.e. 0 0110 1000 1