50 using std::ostringstream;
51 using std::make_tuple;
59 using lib::test::showSizeof;
62 using LERR_(MISSING_MEMENTO);
79 static int instanceCnt;
81 Tracker (TY init = TY()) : element_(init) { ++instanceCnt; }
82 Tracker (
Tracker const& otr) : element_(otr.element_) { ++instanceCnt; }
91 operator string()
const {
return element_; }
97 return tra1.element_ == tra2.element_;
101 template<
typename TY>
139 static _Fmt fmt (
"doIt( Time=%s \"%s\" rand=%2d )");
140 cout <<
"invoke operation..." << endl;
141 protocol << fmt % *time % *str % rand;
147 cout <<
"capture state..." << endl;
148 return protocol.str() + *xstr;
154 cout <<
"undo... memento=" << memento << endl;
155 protocol <<
"undoIt(time="<<time<<
")----memento-:"<< *memento;
161 int dummyC (
int u,
int o) {
return u + rand() % (o-u+1); }
174 TODO (
"implement serialisation/de-serialisation-Check");
175 cout <<
"would be serialised....." << clo << endl;
184 return 10 + rand() % 90;
209 ArgTuples testTuples;
211 Tracker<TimeVar>::instanceCnt = 0;
212 Tracker<string>::instanceCnt = 0;
214 createTuples (testTuples);
215 serialiseArgTuples (testTuples);
218 simulateCmdLifecycle();
221 CHECK (0 == Tracker<TimeVar>::instanceCnt);
222 CHECK (0 == Tracker<string>::instanceCnt);
226 typedef Tracker<TimeVar> TTime;
227 typedef Tracker<string> Tstr;
244 A1* arg1 =
new A1(); tup.
manage (arg1);
245 A2* arg2 =
new A2(); tup.
manage (arg2);
246 A3* arg3 =
new A3(); tup.
manage (arg3);
247 A4* arg4 =
new A4(); tup.
manage (arg4);
248 A5* arg5 =
new A5(); tup.
manage (arg5);
250 CHECK (isnil (*arg1));
251 CHECK (isnil (*arg2));
252 CHECK (isnil (*arg3));
253 CHECK (isnil (*arg4));
254 CHECK (isnil (*arg5));
256 for_each (tup, showIt);
258 arg1->storeTuple (std::tuple<>());
259 arg2->storeTuple (make_tuple (rand() % 10));
260 arg3->storeTuple (make_tuple (rand() % 10,
TimeVar(randTime())));
261 arg4->storeTuple (make_tuple (rand() % 10,
TimeVar(randTime())));
263 arg5->storeTuple (make_tuple (TTime (randTime()), Tstr(
"glorious"), twoRandomDigits() ));
265 CHECK (!arg5->canUndo());
267 arg5->tie(undoIt, captureState)
269 (TTime(), Tstr(
"destruction"), 11);
271 CHECK (arg5->canUndo());
272 CHECK (*arg5->memento() ==
"destruction");
274 VERIFY_ERROR(MISSING_MEMENTO, arg4->memento().i[3] = 513 );
276 for_each (tup, showIt);
287 for_each (tup, checkSerialisation);
298 typedef void SIG_do(Tracker<TimeVar>, Tracker<string>,
int);
303 CHECK (isnil (args));
304 cout << showSizeof(args) << endl;
308 make_tuple (TTime(randTime()), Tstr(
"Lumiera rocks"), twoRandomDigits() ));
309 CHECK (!isnil (args));
310 cout << args << endl;
312 CHECK (!args.canUndo());
315 MemHolder& memHolder = args.tie(undoIt,captureState);
317 CHECK (!args.canUndo());
319 function<SIG_do> doItFun = doIt;
320 function<SIG_do> undoFun = memHolder.tieUndoFunc();
321 function<SIG_do> captFun = memHolder.tieCaptureFunc();
323 typedef function<void()> OpFun;
334 cout <<
"captured state: " << args.memento() << endl;
336 CHECK (!isnil (*args.memento()));
337 CHECK (args.canUndo());
338 cout << args << endl;
346 Args argsCopy (args);
352 make_tuple (TTime(
TimeValue(123456)), Tstr(
"unbelievable"), twoRandomDigits() ));
353 cout <<
"modified: " << args << endl;
354 cout <<
"copied : " << argsCopy << endl;
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
FunErasure< StoreFunction > CmdFunctor
A neutral container internally holding the functor used to implement the Command. ...
void prepareEmptyMemento()
prepare a (singleton) empty value for the memento.
ostringstream protocol
used to verify the test function calls
Singleton holder for NIL or default value objects.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
void createTuples(ArgTuples &tup)
void simulateCmdLifecycle()
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
Managing lifecycle for a collection of objects.
Simple vector based collection of pointers, managing lifecycle of the pointed-to objects.
watching the instance creation of some parameter values
Lumiera's internal time value datatype.
virtual void invoke(CmdFunctor const &)=0
invoke functor using the stored parameter values
void dummyU(int, int, int)
another dummy-UNDO function
Simple test class runner.
void serialiseArgTuples(ArgTuples &tup)
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
Dummy custom memento datatype.
lib::time::Time randTime()
create a random but not insane Time value between 1s ...
basic constant internal time value.
Binding together state capturing and execution of the undo operation.
Perform operations "for each element" of a collection.
T & manage(T *obj)
take ownership of the given object, adding it at the end of the collection
This is "the" top level CmdClosure implementation.
A passive container record holding the actual command arguments & UNDO state.