fair-acc / gr-digitizers

GNU General Public License v3.0
3 stars 3 forks source link

Digitizer Block: Remove minor code duplication #100

Open alexxcons opened 2 years ago

alexxcons commented 2 years ago

The number of (enabled) AI/DI ports on the Digitizer on different occasions is counted by looping on all AI's / DI's. Here an example:

https://github.com/fair-acc/gr-digitizers/blob/19061f72b1f07717a7ff8694df0d9eaacead3bf4/lib/digitizer_block_impl.cc#L615-L626

Instead, provide a method which returns the number

wirew0rm commented 2 years ago

the counting functions already exist in the file: https://github.com/fair-acc/gr-digitizers/blob/19061f72b1f07717a7ff8694df0d9eaacead3bf4/lib/digitizer_block_impl.cc#L448 https://github.com/fair-acc/gr-digitizers/blob/19061f72b1f07717a7ff8694df0d9eaacead3bf4/lib/digitizer_block_impl.cc#L509

RalphSteinhagen commented 2 years ago

The number of (enabled) AI/DI ports on the Digitizer on different occasions is counted by looping on all AI's / DI's. Here an example:

https://github.com/fair-acc/gr-digitizers/blob/19061f72b1f07717a7ff8694df0d9eaacead3bf4/lib/digitizer_block_impl.cc#L615-L626

Instead, provide a method which returns the number

Your assessment is correct and std::accumulate is your friend, e.g.

auto nEnabled = std::accumulate(V.begin(), V.end(), 0, [](int a, int b){ return pred(b) ? a+b: a; });

The quoted code is pre-C++11 and C-like which we should start modernising ...