Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:45

0001 //========================================================================
0002 //
0003 // Dict.h
0004 //
0005 // Copyright 1996-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
0017 // Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
0018 // Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
0019 // Copyright (C) 2010, 2017-2022 Albert Astals Cid <aacid@kde.org>
0020 // Copyright (C) 2010 Paweł Wiejacha <pawel.wiejacha@gmail.com>
0021 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0022 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
0023 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0024 //
0025 // To see a description of the changes please see the Changelog file that
0026 // came with your tarball or type make ChangeLog if you are building from git
0027 //
0028 //========================================================================
0029 
0030 #ifndef DICT_H
0031 #define DICT_H
0032 
0033 #include <atomic>
0034 #include <mutex>
0035 #include <string>
0036 #include <vector>
0037 #include <utility>
0038 
0039 #include "poppler-config.h"
0040 #include "poppler_private_export.h"
0041 #include "Object.h"
0042 
0043 //------------------------------------------------------------------------
0044 // Dict
0045 //------------------------------------------------------------------------
0046 
0047 class POPPLER_PRIVATE_EXPORT Dict
0048 {
0049 public:
0050     // Constructor.
0051     explicit Dict(XRef *xrefA);
0052     explicit Dict(const Dict *dictA);
0053     Dict *copy(XRef *xrefA) const;
0054 
0055     Dict *deepCopy() const;
0056 
0057     Dict(const Dict &) = delete;
0058     Dict &operator=(const Dict &) = delete;
0059 
0060     // Get number of entries.
0061     int getLength() const { return static_cast<int>(entries.size()); }
0062 
0063     // Add an entry. (Copies key into Dict.)
0064     // val becomes a dead object after the call
0065     void add(const char *key, Object &&val);
0066 
0067     // Add an entry. (Takes ownership of key.)
0068     void add(char *key, Object &&val) = delete;
0069 
0070     // Update the value of an existing entry, otherwise create it
0071     // val becomes a dead object after the call
0072     void set(const char *key, Object &&val);
0073     // Remove an entry. This invalidate indexes
0074     void remove(const char *key);
0075 
0076     // Check if dictionary is of specified type.
0077     bool is(const char *type) const;
0078 
0079     // Look up an entry and return the value.  Returns a null object
0080     // if <key> is not in the dictionary.
0081     Object lookup(const char *key, int recursion = 0) const;
0082     // Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID()
0083     Object lookup(const char *key, Ref *returnRef, int recursion = 0) const;
0084     // Look up an entry and return the value.  Returns a null object
0085     // if <key> is not in the dictionary or if it is a ref to a non encrypted object in a partially encrypted document
0086     Object lookupEnsureEncryptedIfNeeded(const char *key) const;
0087     const Object &lookupNF(const char *key) const;
0088     bool lookupInt(const char *key, const char *alt_key, int *value) const;
0089 
0090     // Iterative accessors.
0091     const char *getKey(int i) const { return entries[i].first.c_str(); }
0092     Object getVal(int i) const { return entries[i].second.fetch(xref); }
0093     // Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID()
0094     Object getVal(int i, Ref *returnRef) const;
0095     const Object &getValNF(int i) const { return entries[i].second; }
0096 
0097     // Set the xref pointer.  This is only used in one special case: the
0098     // trailer dictionary, which is read before the xref table is
0099     // parsed.
0100     void setXRef(XRef *xrefA) { xref = xrefA; }
0101 
0102     XRef *getXRef() const { return xref; }
0103 
0104     bool hasKey(const char *key) const;
0105 
0106     // Returns a key name that is not in the dictionary
0107     // It will be suggestedKey itself if available
0108     // otherwise it will start adding 0, 1, 2, 3, etc. to suggestedKey until there's one available
0109     std::string findAvailableKey(const std::string &suggestedKey);
0110 
0111 private:
0112     friend class Object; // for incRef/decRef
0113 
0114     // Reference counting.
0115     int incRef() { return ++ref; }
0116     int decRef() { return --ref; }
0117 
0118     using DictEntry = std::pair<std::string, Object>;
0119     struct CmpDictEntry;
0120 
0121     XRef *xref; // the xref table for this PDF file
0122     std::vector<DictEntry> entries;
0123     std::atomic_int ref; // reference count
0124     std::atomic_bool sorted;
0125     mutable std::recursive_mutex mutex;
0126 
0127     const DictEntry *find(const char *key) const;
0128     DictEntry *find(const char *key);
0129 };
0130 
0131 #endif