Reference.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Types.h>
  9. namespace PDF {
  10. class Reference {
  11. // We store refs as u32, with 18 bits for the index and 14 bits for the
  12. // generation index. The generation index is stored in the higher bits.
  13. // This may need to be rethought later, as the max generation index is
  14. // 2^16 and the max for the object index is probably 2^32 (I don't know
  15. // exactly)
  16. static constexpr auto MAX_REF_INDEX = (1 << 19) - 1; // 2 ^ 19 - 1
  17. static constexpr auto MAX_REF_GENERATION_INDEX = (1 << 15) - 1; // 2 ^ 15 - 1
  18. public:
  19. Reference(u32 index, u32 generation_index)
  20. {
  21. VERIFY(index < MAX_REF_INDEX);
  22. VERIFY(generation_index < MAX_REF_GENERATION_INDEX);
  23. m_combined = (generation_index << 14) | index;
  24. }
  25. [[nodiscard]] ALWAYS_INLINE u32 as_ref_index() const
  26. {
  27. return m_combined & 0x3ffff;
  28. }
  29. [[nodiscard]] ALWAYS_INLINE u32 as_ref_generation_index() const
  30. {
  31. return m_combined >> 18;
  32. }
  33. private:
  34. u32 m_combined;
  35. };
  36. }