I have a std::vector which stores a complex struct S (coming from a real time source) which consists of nested structs N1, N2, N3. The struct S has a time field.
A common task, is to retrieve any of the 3 nested structs between two times, for example getSequenceN1(startTime, stopTime, itrStart, itrStop), which gives 2 iterators to the start and end of the subsequence.
So the code would look something like this:
struct {
double time
struct N1;
struct N2;
struct N3;
} S;
class D {
public:
void getSequenceN1(startTime, stopTime, itrStart, itrStop);
void getSequenceN2(startTime, stopTime, itrStart, itrStop);
void getSequenceN3(startTime, stopTime, itrStart, itrStop);
private:
std::vector<S> stream;
};
What would the right way of implementing the functionality of getSequenceN1?
One way would of course be to have a vector for each N1, N2, N3, (in real live there are more than 3 subtracts) but i am wondering if std offers some nice feature for this?
I am not forced to use a vector btw, any std container (maybe even boost) works. I was hoping I could provide something like a view for the vector where we either only see N1 N2 or N3.
One way would be to provide customized Iterators which give back N1 N2 and N3 respectively.
Optimize and adjust start and end conditions to suit. For example, if S is not going to be modified while you are examining the sequence, you can use a vector of pointers to struct N1 and save a some copying.
EDIT
Playing around with the concept. Still need to abstract it because declaring a different iterator for each sub structure is a pretty stupid solution. Suggestions greatly appreciated.