summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/CanonicalIndex.h
blob: 71f81d515579e1b15e53f27c89b418abdf9c4f1b (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
/*
 * Copyright (c) 2022, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

class CanonicalIndex {
public:
    enum class Type {
        Index,
        Numeric,
        Undefined,
    };

    CanonicalIndex(Type type, u32 index)
        : m_type(type)
        , m_index(index)
    {
    }

    u32 as_index() const
    {
        VERIFY(is_index());
        return m_index;
    }

    bool is_index() const { return m_type == Type::Index; }
    bool is_undefined() const { return m_type == Type::Undefined; }

private:
    Type m_type;
    u32 m_index;
};