PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
object.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_PDF_OBJECT_H_INCLUDED_
4#define PDFSDK_CXX_PDF_OBJECT_H_INCLUDED_
5
6#include <cassert>
7#include <string>
8#include <string_view>
9#include <utility>
10
11#include <pdfsdk/core/objects.h>
12
13#include "forward_declarations.h"
14#include "wrapper_base.h"
15
16namespace PDF {
17
18class DictEnumerator;
19
25class Object {
26public:
27#ifndef SWIG
28 ~Object();
29
35 Object() noexcept;
36
42 Object(PDObject obj, bool adopt = false) noexcept;
43
48 Object(const Object& that) noexcept;
49
54 Object(Object&& that) noexcept;
55
61 Object& operator=(const Object& rhs) noexcept;
62
68 Object& operator=(Object&& rhs) noexcept;
69
75 void reset(PDObject obj, bool adopt = false) noexcept;
76
81 PDObject* operator&() noexcept;
82
87 PDObject get() const noexcept;
88
93 PDObject detach() noexcept;
94
95 explicit operator bool() const noexcept { return !Equals(nullPDObject); }
96 bool operator==(const Object& rhs) const noexcept { return Equals(rhs); }
97#endif
98
103 bool Equals(const Object& rhs) const noexcept;
104
110
114 bool IsNull() const;
115
119 bool IsBool() const;
120
124 bool IsInteger() const;
125
129 bool IsReal() const;
130
134 bool IsNumber() const;
135
139 bool IsString() const;
140
144 bool IsName() const;
145
149 bool IsDict() const;
150
154 bool IsArray() const;
155
159 bool IsStream() const;
160
166 bool IsDictOrStream() const;
167
172 bool IsIndirect() const;
173
178 uint32_t GetObjNumber() const;
179
184 uint16_t GetGenNumber() const;
185
191 uint64_t GetFileOffset() const;
192
197 bool GetBoolValue() const;
198
203 int64_t GetIntValue() const;
204
209 float GetRealValue() const;
210
215 std::wstring GetUnicodeString() const;
216
221 std::string GetStringValue() const;
222
227 PDAtom GetNameValue() const;
228
233 void ArrayAdd(const Object& object);
234
239 void ArrayAddInteger(int64_t value);
240
245 void ArrayAddReal(float value);
246
251 void ArrayAddBoolean(bool value);
252
257 void ArrayAddName(PDAtom value);
258
264 void ArrayAddString(std::string_view bytes, bool hex = false);
265
270 void ArrayAddStringUnicode(std::wstring_view unicode);
271
277
283
290 void ArrayInsert(size_t index, const Object& object);
291
298 void ArrayPut(size_t index, const Object& object);
299
305 Object ArrayGet(size_t index) const;
306
311 void ArrayRemove(size_t index);
312
317 size_t GetArrayLength() const;
318
324 void DictPut(PDAtom name, const Object& object);
325
331 void DictPutName(PDAtom name, PDAtom value);
332
338 void DictPutInteger(PDAtom name, int64_t value);
339
345 void DictPutReal(PDAtom name, float value);
346
352 void DictPutBoolean(PDAtom name, bool value);
353
360 void DictPutString(PDAtom name, std::string_view bytes, bool hex = false);
361
367 void DictPutStringUnicode(PDAtom name, std::wstring_view unicode);
368
374 Object DictPutDict(PDAtom name);
375
381 Object DictPutArray(PDAtom name);
382
388 Object DictFind(PDAtom name) const;
389
395 PDAtom DictFindName(PDAtom name) const;
396
401 void DictRemove(PDAtom name);
402
411 template<class Func>
412 void DictEnum(Func&& func) const;
413
420
425 size_t GetDictNumEntries() const;
426
432
439
445 bool DeepEquals(const Object& that);
446
447private:
448 void Acquire() noexcept;
449 void Release() noexcept;
450
451protected:
452 PDObject m_obj;
453};
454
480class DictEnumerator : public detail::RefCountedHandle<PDDictEnumerator> {
481public:
486 bool MoveNext();
487
491 void Reset();
492
496 PDAtom GetKey() const;
497
503
504#ifndef SWIG
505 // Range-based for loop support: for (auto [key, value] : dict.DictGetEnumerator()) { ... }
506 // begin() rewinds and positions at the first entry, so it is idempotent.
507 struct End {};
508 DictEnumerator& begin() { Reset(); MoveNext(); return *this; }
509 End end() const { return {}; }
510 DictEnumerator& operator++() { MoveNext(); return *this; }
511 bool operator!=(End) const { return GetKey() != kPDAtomNull; }
512 std::pair<PDAtom, Object> operator*() const;
513#endif
514
515 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(DictEnumerator, PDDictEnumerator)
516};
517
518} // namespace PDF
519
520#include "object_impl.inl"
521
522#endif // PDFSDK_CXX_PDF_OBJECT_H_INCLUDED_
Enumerator for traversing key/value pairs in a dictionary Object.
Definition object.h:480
PDAtom GetKey() const
Object GetValue() const
Represents a PDF object.
Definition object.h:25
void ArrayAddInteger(int64_t value)
void DictRemove(PDAtom name)
void ArrayAddReal(float value)
void DictPutStringUnicode(PDAtom name, std::wstring_view unicode)
PDObjectType GetObjectType() const
bool Equals(const Object &rhs) const noexcept
Compares two objects for identity.
void ArrayAddStringUnicode(std::wstring_view unicode)
Object GetStreamDict() const
void DictPutName(PDAtom name, PDAtom value)
bool IsIndirect() const
Object DictPutDict(PDAtom name)
void ArrayAdd(const Object &object)
float GetRealValue() const
void DictPutReal(PDAtom name, float value)
Object ArrayGet(size_t index) const
uint32_t GetObjNumber() const
void ArrayInsert(size_t index, const Object &object)
Object() noexcept
Object DictFind(PDAtom name) const
std::wstring GetUnicodeString() const
void ArrayAddString(std::string_view bytes, bool hex=false)
ReadStream StreamOpen(PDObjectStreamOpenMode openMode=kPDObjectStreamOpenFiltered) const
void DictPutInteger(PDAtom name, int64_t value)
bool DeepEquals(const Object &that)
PDAtom DictFindName(PDAtom name) const
DictEnumerator DictGetEnumerator() const
size_t GetArrayLength() const
Object ArrayAddArray()
bool IsNull() const
void ArrayAddBoolean(bool value)
bool IsString() const
void ArrayRemove(size_t index)
bool IsArray() const
int64_t GetIntValue() const
bool GetBoolValue() const
Object DictPutArray(PDAtom name)
void DictPutString(PDAtom name, std::string_view bytes, bool hex=false)
bool IsDictOrStream() const
uint16_t GetGenNumber() const
bool IsInteger() const
Object ArrayAddDict()
void ArrayPut(size_t index, const Object &object)
void DictEnum(Func &&func) const
void reset(PDObject obj, bool adopt=false) noexcept
bool IsReal() const
size_t GetDictNumEntries() const
bool IsStream() const
PDObject get() const noexcept
void ArrayAddName(PDAtom value)
bool IsNumber() const
bool IsBool() const
uint64_t GetFileOffset() const
bool IsName() const
std::string GetStringValue() const
PDAtom GetNameValue() const
PDObject detach() noexcept
void DictPutBoolean(PDAtom name, bool value)
void DictPut(PDAtom name, const Object &object)
bool IsDict() const
Represents a read stream for reading data from PDF objects.
Definition read_stream.h:19
Objects API.
PDObjectStreamOpenMode
Specifies how an objects' stream is accessed.
Definition objects.h:102
@ kPDObjectStreamOpenFiltered
Definition objects.h:110
PDObjectType
Represents the type of a PDObject and may be retrieved using PDObjectGetType.
Definition objects.h:25
Definition object.h:507
Definition objects.h:83