NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
s_FStateID.hpp
1#pragma once
2#include <game/sLib/s_StateID.hpp>
3#include <lib/MSL_C/string.h>
4
5/// @brief An implementation of a state ID for a given class.
6/// @details It adds the ability to call the three state methods on a state owner class.
7/// @tparam T The class that this state belongs to.
8/// @ingroup state
9template<class T>
10class sFStateID_c : public sStateID_c {
11public:
12 typedef void (T::*stateFunc)();
13
14 /**
15 * @brief Constructs a new sFStateID_c instance.
16 *
17 * @param name The name of this state ID.
18 * @param initialize The initialize method for this state ID.
19 * @param execute The execute method for this state ID.
20 * @param finalize The finalize method for this state ID.
21 */
22 sFStateID_c(const char *name, stateFunc initialize, stateFunc execute, stateFunc finalize) :
23 sStateID_c(name),
24 mpInitialize(initialize),
25 mpExecute(execute),
26 mpFinalize(finalize) {}
27
28 /// @brief Returns true if the given name matches this state ID's name.
29 virtual bool isSameName(const char *otherName) const {
30 char *part = strrchr(otherName, ':');
31 if (part != nullptr) {
32 otherName = part + 1;
33 }
34 const char *thisName = strrchr(name(), ':') + 1;
35 if (strcmp(thisName, otherName) == 0) {
36 return true;
37 } else {
38 return false;
39 }
40 }
41
42 /// @brief Calls the initialize method on the owner.
43 /// @param owner The owner of this state ID.
44 virtual void initializeState(T &owner) const { (owner.*mpInitialize)(); }
45
46 /// @brief Calls the execute method on the owner.
47 /// @param owner The owner of this state ID.
48 virtual void executeState(T &owner) const { (owner.*mpExecute)(); }
49
50 /// @brief Calls the finalize method on the owner.
51 /// @param owner The owner of this state ID.
52 virtual void finalizeState(T &owner) const { (owner.*mpFinalize)(); }
53
54private:
55 stateFunc mpInitialize; ///< The initialize method for this state ID.
56 stateFunc mpExecute; ///< The execute method for this state ID.
57 stateFunc mpFinalize; ///< The finalize method for this state ID.
58};
stateFunc mpFinalize
The finalize method for this state ID.
virtual void finalizeState(T &owner) const
Calls the finalize method on the owner.
stateFunc mpInitialize
The initialize method for this state ID.
virtual void executeState(T &owner) const
Calls the execute method on the owner.
virtual void initializeState(T &owner) const
Calls the initialize method on the owner.
stateFunc mpExecute
The execute method for this state ID.
virtual bool isSameName(const char *otherName) const
Returns true if the given name matches this state ID's name.
sFStateID_c(const char *name, stateFunc initialize, stateFunc execute, stateFunc finalize)
Constructs a new sFStateID_c instance.
virtual const char * name() const
Returns the name of this state ID.
Definition s_StateID.cpp:35