void Operation(){ return SubOperation1() && SubOperation2() && ... && SubOperationN();}
If any of the sub-operations fail along the way, the main operation terminates immediately. Simple.
Here's where it gets complicated. I want to be able to pause Operation() at any step along the way and resume it. I want to be able to run custom code between the SubOperations if necessary. Obviously, one way to do this is with a big switch statement that takes the current step as input and returns the next step.
int Operation(int i){ switch(i) { case 0: if (SubOperation1()) return 1; else return END; case 1: if (SubOperation2()) return 2; else return END; ... case N: SubOperationN(); case END: return END; }}
But it's not very clean. Adding new sub-operations requires a lot more work than before. Can you think of a better way to implement this?
[Edited by - gunning on November 11, 2010 2:37:24 PM]