Coverage Report

Created: 2025-07-11 06:58

/src/qpdf/include/qpdf/QPDFXRefEntry.hh
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2005-2021 Jay Berkenbilt
2
// Copyright (c) 2022-2025 Jay Berkenbilt and Manfred Holger
3
//
4
// This file is part of qpdf.
5
//
6
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
// in compliance with the License. You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software distributed under the License
12
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
// or implied. See the License for the specific language governing permissions and limitations under
14
// the License.
15
//
16
// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic
17
// License. At your option, you may continue to consider qpdf to be licensed under those terms.
18
// Please see the manual for additional information.
19
20
#ifndef QPDFXREFENTRY_HH
21
#define QPDFXREFENTRY_HH
22
23
#include <qpdf/DLL.h>
24
#include <qpdf/Types.h>
25
26
class QPDFXRefEntry
27
{
28
  public:
29
    // Type constants are from the PDF spec section "Cross-Reference Streams":
30
    // 0 = free entry; not used
31
    // 1 = "uncompressed"; field 1 = offset
32
    // 2 = "compressed"; field 1 = object stream number, field 2 = index
33
34
    // Create a type 0 "free" entry.
35
    QPDF_DLL
36
    QPDFXRefEntry();
37
    QPDF_DLL
38
    QPDFXRefEntry(int type, qpdf_offset_t field1, int field2);
39
    // Create a type 1 "uncompressed" entry.
40
    QPDFXRefEntry(qpdf_offset_t offset) :
41
0
        type(1),
42
0
        field1(offset)
43
0
    {
44
0
    }
45
    // Create a type 2 "compressed" entry.
46
    QPDFXRefEntry(int stream_number, int index) :
47
0
        type(2),
48
0
        field1(stream_number),
49
0
        field2(index)
50
0
    {
51
0
    }
52
53
    QPDF_DLL
54
    int getType() const;
55
    QPDF_DLL
56
    qpdf_offset_t getOffset() const; // only for type 1
57
    QPDF_DLL
58
    int getObjStreamNumber() const; // only for type 2
59
    QPDF_DLL
60
    int getObjStreamIndex() const; // only for type 2
61
62
  private:
63
    // This class does not use the Members pattern to avoid a memory allocation for every one of
64
    // these. A lot of these get created.
65
66
    // The layout can be changed to reduce the size from 24 to 16 bytes. However, this would have a
67
    // definite runtime cost.
68
    int type{0};
69
    qpdf_offset_t field1{0};
70
    int field2{0};
71
};
72
73
#endif // QPDFXREFENTRY_HH