I want to maintain a buffer of 5 seconds of sensor data. The sensor data consists, among other things, of accelerometer readings in x,y,z dimensions, gyroscope readings in x,y,z dimension and magnetometer readings in x,y,z dimension.
My initial idea is to use an std::deque<SensorReading> which stores 5 seconds of the following SensorReading struct:
struct SensorReading {
double time
gyroscope g;
accelerometer a;
magnetometer m;
//more substructs
} S;
A common operation on the buffer is that the user provides a start and end time and wants two Iterators marking the first and last reading of the gyroscope (or magnetometer or accelerometer) within this time interval from the buffer (deqeue). (Sometimes the user of the gyroscope reading might also be interested in the corresponding time stamps of the parent struct S.)
In my mind I have the idea of providing some sort of “views” of the buffer, which lets the user only see the substructure he is interested in. But I have no clear idea how to achieve this.
The only conceptual solution I have so far, is to introduce custom Iterators to the deque, a magnetometerIterator, gyroscopeIterator, accelerometerIterator and then expose only the corresponding substructure to the user.
I do not like the idea of maintaining multiple buffers, one for each substructure, because it adds redundancy to the code.
What would be a way to achieve this?