I am stuck on a logic problem.
I have the following struct:
Code:
struct MeasurementData { bool complete = false; std::bitset<3> mode; std::bitset<12> frame_counter; std::bitset<16> expo_time; std::bitset<16> expo_time_max; std::bitset<24> ntc_val0_ref_2_4V; std::bitset<24> ntc_val0_ref_2_1V; std::bitset<24> ntc_val0_temp_2_4V; std::bitset<24> ntc_val0_temp_2_1V; };
Where the field frame_counter is a progressive number incremented after each measurement (starting from value 0).
To fill in the fields of the structure I analyze an input file where each row contains the values that I have to insert in the structure.
So I create a vector of structures and I create a new struct each time I parse a new row
Code:
std::vector<MeasurementData> frames; std::string line; while (std::getline(input, line)) { processLine(line, frames); // <- Here I create a new struct instance and add it to the vector } input.close();
My need is to find the missing frame_counter values when processing the corresponding file line
For example:
In my file I have 48 rows, this implies the creation of 48 struct instances and the frame_counter should start at 0 and end at 47 but in my case I have 3 missing measurement
frame_counter = 0 is missing
frame_counter = 9 is missing
frame_counter = 12 is missing
I determine it by postprocessing the vector of structs. Is not what I want, I would determine it at the "file line processing" time but I can not find a good logic that solves my problem.
Below is how I do it now:
Code:
std::vector<MeasurementData> frames; std::vector<int> counters; for (const auto& frame : frames) // frames is my structs vector { int counter = (int)(frame.frame_counter.to_ulong()); counters.push_back(counter); } // And search for missing frames (assuming vector is ordered) for (int i = 0; i < counters.size(); i++) { if (!std::binary_search(counters.begin(), counters.end(), i)) { std::cout << "Frame " << i << " is missing" << std::endl; } }