aboutsummaryrefslogtreecommitdiffstats
path: root/al/eax_fx_slot_index.cpp
blob: fe74097de9da4276e2da1efcfa9b0c5ccf39b487 (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
#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


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

    emplace(index);
}

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

[[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 == *rhs;
    return true;
}

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