Codechange: Use wrapper struct to automatically manage command depth tracking.

This commit is contained in:
Michael Lutz
2021-10-29 14:41:20 +02:00
parent 996b16de70
commit c88b104ec6
2 changed files with 34 additions and 36 deletions

View File

@@ -72,4 +72,15 @@ static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
return flags;
}
/** Helper class to keep track of command nesting level. */
struct RecursiveCommandCounter {
RecursiveCommandCounter() noexcept { _counter++; }
~RecursiveCommandCounter() noexcept { _counter--; }
/** Are we in the top-level command execution? */
bool IsTopLevel() const { return _counter == 1; }
private:
static int _counter;
};
#endif /* COMMAND_FUNC_H */