This is more a question about general design than specifically about C++.
I have a class Consumer that needs to receive a sequence<A>, a sequence<B>, and a C, where A, B, and C are all unrelated. Consumer has to write these objects to a file in a specific order, and it's incorrect for the objects to be reordered or for the sequences to be overlapped (e.g. [A[0], A[1], B[0], A[2], B[1], B[2]]).
I'm trying to figure out some way that neither the producer nor the consumer have to assume correct behavior from the other party, but also to obviate error checking. In the code I'm translating, I had solved it like this:
1 2 3 4 5 6
|
class Consumer{
public:
void add_A(const A &);
void add_B(const B &);
void add_C(const C &);
};
|
And each function would set a state variable the first time it was called and check it every time to make sure it wasn't in an incorrect state. This works but it's not very nice.
Now I was going to use something more like this:
1 2 3 4
|
class Consumer{
public:
void add(coroutine &, coroutine &, const C &);
};
|
But I realized this just moves the error checking elsewhere, since extracting from the coroutines in the wrong order is still an error, because extracting changes the state of the other objects.
Can anyone think of an elegant solution for this?