From 7d58ebf2819562893df2f07b916c9712d5b7413f Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:43:49 -0500 Subject: ZVISION: Convert Puzzle to a class It needed a copy constructor and destructor to handle the heap memory ResultActions --- engines/zvision/puzzle.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 06c228d367..08d8a5cfd7 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -58,7 +58,27 @@ enum StateFlags { DISABLED = 0x04 }; -struct Puzzle { +class Puzzle { +public: + ~Puzzle() { + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + delete (*iter); + } + } + + Puzzle() {} + + // Copy constructor + Puzzle(const Puzzle &other) + : key(other.key), + criteriaList(other.criteriaList), + flags(flags) { + // We have to clone the ResultActions since they are on the heap + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + resultActions.push_back((*iter)->clone()); + } + } + uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract -- cgit v1.2.3