CanonicalIndex.h 618 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. class CanonicalIndex {
  9. public:
  10. enum class Type {
  11. Index,
  12. Numeric,
  13. Undefined,
  14. };
  15. CanonicalIndex(Type type, u32 index)
  16. : m_type(type)
  17. , m_index(index)
  18. {
  19. }
  20. u32 as_index() const
  21. {
  22. VERIFY(is_index());
  23. return m_index;
  24. }
  25. bool is_index() const { return m_type == Type::Index; }
  26. bool is_undefined() const { return m_type == Type::Undefined; }
  27. private:
  28. Type m_type;
  29. u32 m_index;
  30. };