summaryrefslogtreecommitdiff
path: root/include/s/s_FStateFct.hpp
blob: d3515649062e42bdebb1f4e7dc0caadaa3ec8173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef S_FSTATEFCT_H
#define S_FSTATEFCT_H

// clang-format off
#include "s/s_StateInterfaces.hpp"
#include "s/s_FState.hpp"
#include "s/s_StateID.hpp"
// clang-format on

// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib
// See include/s/README.txt for changes made

/// @brief A state factory for a given class.
/// @tparam T The class that this state belongs to.
/// @ingroup state
template <class T>
class sFStateFct_c : public sStateFctIf_c {
public:
    sFStateFct_c(T &owner) : mState(owner) {}

    virtual sStateIf_c *build(const sStateIDIf_c &id) {
        if (!id.isNull()) {
            mState.setID((const sFStateID_c<T> *)&id);
            return &mState;
        }
        return nullptr;
    }

    virtual void dispose(sStateIf_c *&id) {
        id = nullptr;
    }

private:
    sFState_c<T> mState;
};

#endif