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

#pragma once

#include <AK/Types.h>

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;
};