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 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
39class XRef;
40
41//------------------------------------------------------------------------
42// Array
43//------------------------------------------------------------------------
44
45class POPPLER_PRIVATE_EXPORT Array
46{
47public:
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 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
79private:
80 friend class Object; // for incRef/decRef
81
82 // Reference counting.
83 int incRef() { return ++ref; }
84 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#endif
93

source code of poppler/poppler/Array.h