aboutsummaryrefslogtreecommitdiffstats
path: root/al/eax_fx_slot_index.cpp
blob: 484c3499700d5a5a037c3ef390e3ea1d4cfcd5c4 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "config.h"

#include "eax_fx_slot_index.h"

#include "eax_exception.h"


namespace
{


class EaxFxSlotIndexException :
    public EaxException
{
public:
    explicit EaxFxSlotIndexException(
        const char* message)
        :
        EaxException{"EAX_FX_SLOT_INDEX", message}
    {
    }
}; // EaxFxSlotIndexException


} // namespace


EaxFxSlotIndex::EaxFxSlotIndex(
    EaxFxSlotIndexValue index)
{
    set(index);
}

EaxFxSlotIndex::EaxFxSlotIndex(
    const EaxFxSlotIndex& rhs) noexcept
    :
    has_value_{rhs.has_value_},
    value_{rhs.value_}
{
}

void EaxFxSlotIndex::operator=(
    EaxFxSlotIndexValue index)
{
    set(index);
}

void EaxFxSlotIndex::operator=(
    const GUID& guid)
{
    set(guid);
}

void EaxFxSlotIndex::operator=(
    const EaxFxSlotIndex& rhs) noexcept
{
    has_value_ = rhs.has_value_;
    value_ = rhs.value_;
}

bool EaxFxSlotIndex::has_value() const noexcept
{
    return has_value_;
}

EaxFxSlotIndexValue EaxFxSlotIndex::get() const
{
    if (!has_value_)
    {
        throw EaxFxSlotIndexException{"No value."};
    }

    return value_;
}

void EaxFxSlotIndex::reset() noexcept
{
    has_value_ = false;
}

void EaxFxSlotIndex::set(
    EaxFxSlotIndexValue index)
{
    if (index >= static_cast<EaxFxSlotIndexValue>(EAX_MAX_FXSLOTS))
    {
        fail("Index out of range.");
    }

    has_value_ = true;
    value_ = index;
}

void EaxFxSlotIndex::set(
    const GUID& guid)
{
    if (false)
    {
    }
    else if (guid == EAX_NULL_GUID)
    {
        has_value_ = false;
    }
    else if (guid == EAXPROPERTYID_EAX40_FXSlot0 || guid == EAXPROPERTYID_EAX50_FXSlot0)
    {
        has_value_ = true;
        value_ = 0;
    }
    else if (guid == EAXPROPERTYID_EAX40_FXSlot1 || guid == EAXPROPERTYID_EAX50_FXSlot1)
    {
        has_value_ = true;
        value_ = 1;
    }
    else if (guid == EAXPROPERTYID_EAX40_FXSlot2 || guid == EAXPROPERTYID_EAX50_FXSlot2)
    {
        has_value_ = true;
        value_ = 2;
    }
    else if (guid == EAXPROPERTYID_EAX40_FXSlot3 || guid == EAXPROPERTYID_EAX50_FXSlot3)
    {
        has_value_ = true;
        value_ = 3;
    }
    else
    {
        fail("Unsupported GUID.");
    }
}

EaxFxSlotIndex::operator EaxFxSlotIndexValue() const
{
    return get();
}

[[noreturn]]
void EaxFxSlotIndex::fail(
    const char* message)
{
    throw EaxFxSlotIndexException{message};
}


bool operator==(
    const EaxFxSlotIndex& lhs,
    const EaxFxSlotIndex& rhs) noexcept
{
    if (lhs.has_value() != rhs.has_value())
    {
        return false;
    }

    if (lhs.has_value())
    {
        return lhs.get() == rhs.get();
    }
    else
    {
        return true;
    }
}

bool operator!=(
    const EaxFxSlotIndex& lhs,
    const EaxFxSlotIndex& rhs) noexcept
{
    return !(lhs == rhs);
}