summaryrefslogtreecommitdiff
path: root/include/s/s_StateID.hpp
blob: d385f354ad055326eb15eda727cf1722e8437c7c (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
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef S_STATEID_H
#define S_STATEID_H

#include "s/s_StateInterfaces.hpp"

// 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 generic implementation of a state ID.
/// @details It simply contains a name string and a unique number.
/// @ingroup state
class sStateID_c : public sStateIDIf_c {
public:
    class NumberMemo_c {
    public:
        NumberMemo_c() : curr(0) {}
        unsigned int get() {
            curr++;
            return curr;
        }
        unsigned int curr;
    };

    sStateID_c(const char *name);
    virtual ~sStateID_c();

    virtual bool isNull() const;
    virtual bool isEqual(const sStateIDIf_c &other) const;

    virtual BOOL operator==(const sStateIDIf_c &other) const;
    virtual BOOL operator!=(const sStateIDIf_c &other) const;

    virtual bool isSameName(const char *name) const;
    virtual const char *name() const;
    virtual unsigned int number() const;

protected:
    const char *mpName;   ///< The name of this state ID.
    unsigned int mNumber; ///< The number of this state ID.

    static NumberMemo_c sm_numberMemo; ///< Used to give each state a unique number.
};

namespace sStateID {

/// @ingroup state
extern const sStateID_c null; ///< A null state instance.
} // namespace sStateID

#endif