Serenity Operating System
at master 45 lines 1.2 kB view raw
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 8#pragma once 9 10#include <AK/Types.h> 11 12namespace PDF { 13 14class Reference { 15 // We store refs as u32, with 18 bits for the index and 14 bits for the 16 // generation index. The generation index is stored in the higher bits. 17 // This may need to be rethought later, as the max generation index is 18 // 2^16 and the max for the object index is probably 2^32 (I don't know 19 // exactly) 20 static constexpr auto MAX_REF_INDEX = (1 << 19) - 1; // 2 ^ 19 - 1 21 static constexpr auto MAX_REF_GENERATION_INDEX = (1 << 15) - 1; // 2 ^ 15 - 1 22 23public: 24 Reference(u32 index, u32 generation_index) 25 { 26 VERIFY(index < MAX_REF_INDEX); 27 VERIFY(generation_index < MAX_REF_GENERATION_INDEX); 28 m_combined = (generation_index << 14) | index; 29 } 30 31 [[nodiscard]] ALWAYS_INLINE u32 as_ref_index() const 32 { 33 return m_combined & 0x3ffff; 34 } 35 36 [[nodiscard]] ALWAYS_INLINE u32 as_ref_generation_index() const 37 { 38 return m_combined >> 18; 39 } 40 41private: 42 u32 m_combined; 43}; 44 45}