diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-10-29 14:41:20 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | c88b104ec662ea80bec89f58aa7ad9d0baac7704 (patch) | |
tree | fbbc73c845ec43a648408bc147761f17be8584f0 /src/command_func.h | |
parent | 996b16de707c449a83676c614edbd5a81d37b253 (diff) | |
download | openttd-c88b104ec662ea80bec89f58aa7ad9d0baac7704.tar.xz |
Codechange: Use wrapper struct to automatically manage command depth tracking.
Diffstat (limited to 'src/command_func.h')
-rw-r--r-- | src/command_func.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/command_func.h b/src/command_func.h index 0b539746d..2a6f0c68a 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -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 */ |