/src/poppler/poppler/Array.h
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // Array.h |
4 | | // |
5 | | // Copyright 1996-2003 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | //======================================================================== |
10 | | // |
11 | | // Modified under the Poppler project - http://poppler.freedesktop.org |
12 | | // |
13 | | // All changes made under the Poppler project to this file are licensed |
14 | | // under GPL version 2 or later |
15 | | // |
16 | | // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com> |
17 | | // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it> |
18 | | // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> |
19 | | // Copyright (C) 2017-2019, 2021, 2024 Albert Astals Cid <aacid@kde.org> |
20 | | // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com> |
21 | | // Copyright (C) 2018, 2019 Adam Reichold <adam.reichold@t-online.de> |
22 | | // |
23 | | // To see a description of the changes please see the Changelog file that |
24 | | // came with your tarball or type make ChangeLog if you are building from git |
25 | | // |
26 | | //======================================================================== |
27 | | |
28 | | #ifndef ARRAY_H |
29 | | #define ARRAY_H |
30 | | |
31 | | #include <atomic> |
32 | | #include <mutex> |
33 | | #include <vector> |
34 | | |
35 | | #include "poppler-config.h" |
36 | | #include "poppler_private_export.h" |
37 | | #include "Object.h" |
38 | | |
39 | | class XRef; |
40 | | |
41 | | //------------------------------------------------------------------------ |
42 | | // Array |
43 | | //------------------------------------------------------------------------ |
44 | | |
45 | | class POPPLER_PRIVATE_EXPORT Array |
46 | | { |
47 | | public: |
48 | | // Constructor. |
49 | | explicit Array(XRef *xrefA); |
50 | | |
51 | | // Destructor. |
52 | | ~Array(); |
53 | | |
54 | | Array(const Array &) = delete; |
55 | | Array &operator=(const Array &) = delete; |
56 | | |
57 | | // Get number of elements. |
58 | 256M | int getLength() const { return elems.size(); } |
59 | | |
60 | | // Copy array with new xref |
61 | | Array *copy(XRef *xrefA) const; |
62 | | |
63 | | Array *deepCopy() const; |
64 | | |
65 | | // Add an element |
66 | | // elem becomes a dead object after this call |
67 | | void add(Object &&elem); |
68 | | |
69 | | // Remove an element by position |
70 | | void remove(int i); |
71 | | |
72 | | // Accessors. |
73 | | Object get(int i, int recursion = 0) const; |
74 | | // Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID() |
75 | | Object get(int i, Ref *returnRef, int recursion = 0) const; |
76 | | const Object &getNF(int i) const; |
77 | | bool getString(int i, GooString *string) const; |
78 | | |
79 | | private: |
80 | | friend class Object; // for incRef/decRef |
81 | | |
82 | | // Reference counting. |
83 | 22.3M | int incRef() { return ++ref; } |
84 | 63.8M | int decRef() { return --ref; } |
85 | | |
86 | | XRef *xref; // the xref table for this PDF file |
87 | | std::vector<Object> elems; // array of elements |
88 | | std::atomic_int ref; // reference count |
89 | | mutable std::recursive_mutex mutex; |
90 | | }; |
91 | | |
92 | | //------------------------------------------------------------------------ |
93 | | // Object Array accessors. |
94 | | //------------------------------------------------------------------------ |
95 | | |
96 | | inline int Object::arrayGetLength() const |
97 | 149M | { |
98 | 149M | OBJECT_TYPE_CHECK(objArray); |
99 | 149M | return array->getLength(); |
100 | 149M | } |
101 | | |
102 | | inline void Object::arrayAdd(Object &&elem) |
103 | 586M | { |
104 | 586M | OBJECT_TYPE_CHECK(objArray); |
105 | 586M | array->add(std::move(elem)); |
106 | 586M | } |
107 | | |
108 | | inline void Object::arrayRemove(int i) |
109 | 0 | { |
110 | 0 | OBJECT_TYPE_CHECK(objArray); |
111 | 0 | array->remove(i); |
112 | 0 | } |
113 | | |
114 | | inline Object Object::arrayGet(int i, int recursion = 0) const |
115 | 239M | { |
116 | 239M | OBJECT_TYPE_CHECK(objArray); |
117 | 239M | return array->get(i, recursion); |
118 | 239M | } |
119 | | |
120 | | inline const Object &Object::arrayGetNF(int i) const |
121 | 2.84M | { |
122 | 2.84M | OBJECT_TYPE_CHECK(objArray); |
123 | 2.84M | return array->getNF(i); |
124 | 2.84M | } |
125 | | |
126 | | #endif |