7#ifndef CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
8#define CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
17#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
18#include "core/fpdfapi/parser/cpdf_object.h"
19#include "core/fxcrt/fx_coordinates.h"
20#include "core/fxcrt/retain_ptr.h"
21#include "third_party/abseil-cpp/absl/types/optional.h"
22#include "third_party/base/check.h"
29 using const_iterator = std::vector<RetainPtr<CPDF_Object>>::const_iterator;
40 bool IsEmpty()
const {
return m_Objects.empty(); }
83 template <
typename T,
typename... Args>
86 return pdfium::WrapRetain(
static_cast<T*>(
87 AppendInternal(pdfium::MakeRetain<T>(
std::forward<Args>(args)...))));
89 template <
typename T,
typename... Args>
92 return pdfium::WrapRetain(
static_cast<T*>(AppendInternal(
93 pdfium::MakeRetain<T>(m_pPool, std::forward<Args>(args)...))));
95 template <
typename T,
typename... Args>
98 return pdfium::WrapRetain(
static_cast<T*>(SetAtInternal(
99 index, pdfium::MakeRetain<T>(std::forward<Args>(args)...))));
101 template <
typename T,
typename... Args>
104 return pdfium::WrapRetain(
static_cast<T*>(SetAtInternal(
105 index, pdfium::MakeRetain<T>(m_pPool, std::forward<Args>(args)...))));
107 template <
typename T,
typename... Args>
110 return pdfium::WrapRetain(
static_cast<T*>(InsertAtInternal(
111 index, pdfium::MakeRetain<T>(std::forward<Args>(args)...))));
113 template <
typename T,
typename... Args>
116 return pdfium::WrapRetain(
static_cast<T*>(InsertAtInternal(
117 index, pdfium::MakeRetain<T>(m_pPool, std::forward<Args>(args)...))));
147 explicit CPDF_Array(
const WeakPtr<ByteStringPool>& pPool);
151 const CPDF_Object* GetObjectAtInternal(size_t index)
const;
152 CPDF_Object* GetMutableObjectAtInternal(size_t index);
159 std::set<
const CPDF_Object*>* pVisited)
const override;
161 std::vector<RetainPtr<CPDF_Object>> m_Objects;
162 WeakPtr<ByteStringPool> m_pPool;
163 mutable uint32_t m_LockCount = 0;
168 FX_STACK_ALLOCATED();
177 CHECK(m_pArray->IsLocked());
178 return m_pArray->m_Objects.begin();
181 CHECK(m_pArray->IsLocked());
182 return m_pArray->m_Objects.end();
186 RetainPtr<
const CPDF_Array>
const m_pArray;
198 return RetainPtr<CPDF_Array>(ToArray(obj.Get()));
202 return RetainPtr<
const CPDF_Array>(ToArray(obj.Get()));
uint32_t FX_HashCode_GetLoweredAsIfW(ByteStringView str)
uint32_t FX_HashCode_GetLoweredA(ByteStringView str)
uint32_t FX_HashCode_GetAsIfW(ByteStringView str)
uint32_t FX_HashCode_GetA(ByteStringView str)
CPDF_ArrayLocker(RetainPtr< CPDF_Array > pArray)
const_iterator begin() const
const_iterator end() const
CPDF_ArrayLocker(const CPDF_Array *pArray)
CPDF_ArrayLocker(RetainPtr< const CPDF_Array > pArray)
void Append(RetainPtr< CPDF_Stream > stream)=delete
bool GetBooleanAt(size_t index, bool bDefault) const
void SetAt(size_t index, RetainPtr< CPDF_Object > object)
RetainPtr< CPDF_Dictionary > GetMutableDictAt(size_t index)
RetainPtr< CPDF_Object > CloneNonCyclic(bool bDirect, std::set< const CPDF_Object * > *pVisited) const override
RetainPtr< const CPDF_Object > GetDirectObjectAt(size_t index) const
RetainPtr< const CPDF_Stream > GetStreamAt(size_t index) const
Type GetType() const override
absl::optional< size_t > Find(const CPDF_Object *pThat) const
CPDF_Array * AsMutableArray() override
RetainPtr< const CPDF_Object > GetObjectAt(size_t index) const
RetainPtr< CPDF_Object > GetMutableObjectAt(size_t index)
std::enable_if<!CanInternStrings< T >::value, RetainPtr< T > >::type AppendNew(Args &&... args)
WideString GetUnicodeTextAt(size_t index) const
RetainPtr< CPDF_Array > GetMutableArrayAt(size_t index)
RetainPtr< CPDF_Object > Clone() const override
std::enable_if< CanInternStrings< T >::value, RetainPtr< T > >::type AppendNew(Args &&... args)
RetainPtr< const CPDF_Dictionary > GetDictAt(size_t index) const
std::enable_if<!CanInternStrings< T >::value, RetainPtr< T > >::type InsertNewAt(size_t index, Args &&... args)
RetainPtr< CPDF_Stream > GetMutableStreamAt(size_t index)
bool Contains(const CPDF_Object *pThat) const
void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder *pHolder)
std::enable_if< CanInternStrings< T >::value, RetainPtr< T > >::type InsertNewAt(size_t index, Args &&... args)
std::enable_if<!CanInternStrings< T >::value, RetainPtr< T > >::type SetNewAt(size_t index, Args &&... args)
bool WriteTo(IFX_ArchiveStream *archive, const CPDF_Encryptor *encryptor) const override
RetainPtr< CPDF_Object > GetMutableDirectObjectAt(size_t index)
CFX_Matrix GetMatrix() const
int GetIntegerAt(size_t index) const
void SetAt(size_t index, RetainPtr< CPDF_Stream > stream)=delete
void InsertAt(size_t index, RetainPtr< CPDF_Object > object)
ByteString GetByteStringAt(size_t index) const
std::enable_if< CanInternStrings< T >::value, RetainPtr< T > >::type SetNewAt(size_t index, Args &&... args)
void Append(RetainPtr< CPDF_Object > object)
RetainPtr< const CPDF_String > GetStringAt(size_t index) const
RetainPtr< const CPDF_Array > GetArrayAt(size_t index) const
RetainPtr< const CPDF_Number > GetNumberAt(size_t index) const
CFX_FloatRect GetRect() const
void InsertAt(size_t index, RetainPtr< CPDF_Stream > stream)=delete
void RemoveAt(size_t index)
float GetFloatAt(size_t index) const
CPDF_Creator(CPDF_Document *pDoc, RetainPtr< IFX_RetainableWriteStream > archive)
bool SetFileVersion(int32_t fileVersion)
bool Create(uint32_t flags)
const CPDF_Array * AsArray() const
virtual CPDF_Array * AsMutableArray()
virtual FX_FILESIZE CurrentOffset() const =0
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
virtual size_t ReadBlock(pdfium::span< uint8_t > buffer)
virtual FX_FILESIZE GetPosition()
virtual bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset)=0
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
virtual bool WriteBlockAtOffset(pdfium::span< const uint8_t > data, FX_FILESIZE offset)=0
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
virtual FX_FILESIZE GetSize()=0
bool WriteFilesize(FX_FILESIZE size)
bool WriteByte(uint8_t byte)
bool WriteString(ByteStringView str)
virtual ~IFX_WriteStream()=default
bool WriteDWord(uint32_t i)
virtual bool WriteBlock(pdfium::span< const uint8_t > data)=0
void TrimLeft(ByteStringView targets)
bool IsValidLength(size_t length) const
bool Contains(ByteStringView lpszSub, size_t start=0) const
const_iterator begin() const
bool IsValidIndex(size_t index) const
static ByteString FormatFloat(float f)
ByteStringView AsStringView() const
ByteString(const char *ptr)
bool EqualNoCase(ByteStringView str) const
static ByteString Format(const char *pFormat,...)
ByteString & operator+=(const ByteString &str)
bool operator!=(ByteStringView str) const
ByteString Substr(size_t first, size_t count) const
size_t GetStringLength() const
size_t InsertAtBack(char ch)
bool operator==(ByteStringView str) const
pdfium::span< const uint8_t > raw_span() const
void AllocCopy(ByteString &dest, size_t nCopyLen, size_t nCopyIndex) const
void AssignCopy(const char *pSrcData, size_t nSrcLen)
bool Contains(char ch, size_t start=0) const
absl::optional< size_t > ReverseFind(char ch) const
intptr_t ReferenceCountForTesting() const
size_t Delete(size_t index, size_t count=1)
const_reverse_iterator rend() const
ByteString & operator+=(char ch)
const uint8_t * raw_str() const
void ReallocBeforeWrite(size_t nNewLen)
ByteString(ByteStringView bstrc)
RetainPtr< StringData > m_pData
static ByteString FormatInteger(int i)
pdfium::span< char > GetBuffer(size_t nMinBufLength)
bool operator==(const ByteString &other) const
bool operator==(const char *ptr) const
const_iterator end() const
ByteString(const ByteString &other)
ByteString(const char *pStr, size_t len)
bool operator<(ByteStringView str) const
ByteString(wchar_t)=delete
ByteString & operator+=(const char *str)
ByteString & operator+=(ByteStringView str)
ByteString(const uint8_t *pStr, size_t len)
size_t Replace(ByteStringView pOld, ByteStringView pNew)
absl::optional< size_t > Find(ByteStringView subStr, size_t start=0) const
bool operator!=(const ByteString &other) const
void SetAt(size_t index, char c)
ByteString & operator=(ByteStringView str)
ByteString(ByteStringView str1, ByteStringView str2)
void Trim(ByteStringView targets)
ByteString & operator=(const char *str)
static ByteString FormatV(const char *pFormat, va_list argList)
void TrimRight(char target)
const char * c_str() const
ByteString Substr(size_t offset) const
ByteString & operator=(const ByteString &that)
ByteString & operator=(ByteString &&that) noexcept
void TrimRight(ByteStringView targets)
bool operator<(const ByteString &other) const
ByteString(const std::initializer_list< ByteStringView > &list)
CharType operator[](const size_t index) const
const_reverse_iterator rbegin() const
bool operator!=(const char *ptr) const
int Compare(ByteStringView str) const
size_t Insert(size_t index, char ch)
void ReleaseBuffer(size_t nNewLength)
ByteString(const fxcrt::ostringstream &outStream)
void TrimLeft(char target)
size_t InsertAtFront(char ch)
ByteString First(size_t count) const
void AllocBeforeWrite(size_t nNewLen)
bool operator<(const char *ptr) const
void Concat(const char *pSrcData, size_t nSrcLen)
absl::optional< size_t > Find(char ch, size_t start=0) const
ByteString(ByteString &&other) noexcept
ByteString Last(size_t count) const
RetainPtr & operator=(const RetainPtr< U > &that)
RetainPtr(std::nullptr_t ptr)
void Reset(T *obj=nullptr)
bool operator!=(const RetainPtr &that) const
void Swap(RetainPtr &that)
RetainPtr() noexcept=default
RetainPtr(RetainPtr &&that) noexcept
bool operator!=(const U &that) const
RetainPtr & operator=(const RetainPtr &that)
bool operator==(const RetainPtr &that) const
bool operator==(const U &that) const
RetainPtr & operator=(RetainPtr &&that) noexcept
RetainPtr & operator=(RetainPtr< U > &&that) noexcept
RetainPtr(const RetainPtr< U > &that)
bool operator<(const RetainPtr &that) const
RetainPtr(const RetainPtr &that) noexcept
operator T*() const noexcept
RetainPtr & operator=(std::nullptr_t) noexcept
UnownedPtr< T > BackPointer() const
RetainPtr(RetainPtr< U > &&that) noexcept
RetainPtr< U > As() const
RetainPtr(T *pObj) noexcept
virtual ~Retainable()=default
void CopyContents(const CharType *pStr, size_t nLen)
static StringDataTemplate * Create(size_t nLen)
const size_t m_nAllocLength
void CopyContents(const StringDataTemplate &other)
bool CanOperateInPlace(size_t nTotalLen) const
static StringDataTemplate * Create(const CharType *pStr, size_t nLen)
void CopyContentsAt(size_t offset, const CharType *pStr, size_t nLen)
absl::optional< size_t > Find(CharType ch) const
bool operator>(const StringViewTemplate &that) const
StringViewTemplate(const CharType *ptr) noexcept
bool operator<(const StringViewTemplate &that) const
constexpr StringViewTemplate(const UnsignedType *ptr, size_t size) noexcept
bool IsValidLength(size_t length) const
UnsignedType Back() const
constexpr StringViewTemplate(const CharType *ptr, size_t size) noexcept
bool operator!=(const CharType *ptr) const
StringViewTemplate TrimmedRight(CharType ch) const
pdfium::span< const UnsignedType > m_Span
bool EqualsASCII(const StringViewTemplate< char > &that) const
const CharType * unterminated_c_str() const
bool operator==(const CharType *ptr) const
bool Contains(CharType ch) const
bool EqualsASCIINoCase(const StringViewTemplate< char > &that) const
pdfium::span< const UnsignedType > raw_span() const
StringViewTemplate Substr(size_t first, size_t count) const
bool operator==(const StringViewTemplate &other) const
const_iterator end() const
const UnsignedType & operator[](const size_t index) const
StringViewTemplate Last(size_t count) const
CharType CharAt(const size_t index) const
bool operator!=(const StringViewTemplate &other) const
StringViewTemplate First(size_t count) const
constexpr StringViewTemplate(const pdfium::span< const CharType > &other) noexcept
constexpr StringViewTemplate(const StringViewTemplate &src) noexcept=default
const_iterator begin() const
StringViewTemplate & operator=(const StringViewTemplate &src)
const_reverse_iterator rend() const
UnsignedType Front() const
StringViewTemplate & operator=(const CharType *src)
StringViewTemplate Substr(size_t offset) const
constexpr StringViewTemplate() noexcept=default
constexpr StringViewTemplate(const CharType &ch) noexcept
const_reverse_iterator rbegin() const
const UnsignedType * raw_str() const
bool IsValidIndex(size_t index) const
constexpr StringViewTemplate(const pdfium::span< const UnsignedType > &other) noexcept
UnownedPtr(const UnownedPtr< U > &that)
bool operator==(const UnownedPtr &that) const
operator T*() const noexcept
UnownedPtr(UnownedPtr< U > &&that) noexcept
UnownedPtr & operator=(UnownedPtr< U > &&that) noexcept
constexpr UnownedPtr(const UnownedPtr &that) noexcept=default
constexpr UnownedPtr(T *pObj) noexcept
UnownedPtr & operator=(T *that) noexcept
bool operator==(std::nullptr_t ptr) const
UnownedPtr & operator=(UnownedPtr &&that) noexcept
UnownedPtr & operator=(std::nullptr_t) noexcept
UnownedPtr & operator=(const UnownedPtr< U > &that) noexcept
constexpr UnownedPtr() noexcept=default
bool operator<(const UnownedPtr &that) const
UnownedPtr & operator=(const UnownedPtr &that) noexcept=default
constexpr UnownedPtr(UnownedPtr &&that) noexcept
constexpr UnownedPtr(std::nullptr_t ptr)
CPDF_Array * ToArray(CPDF_Object *obj)
const CPDF_Array * ToArray(const CPDF_Object *obj)
RetainPtr< CPDF_Array > ToArray(RetainPtr< CPDF_Object > obj)
#define FPDFCREATE_INCREMENTAL
#define FPDFCREATE_NO_ORIGINAL
NOINLINE void FX_OutOfMemoryTerminate(size_t size)
void FXMEM_DefaultFree(void *pointer)
void * FXMEM_DefaultAlloc(size_t byte_size)
void * FXMEM_DefaultCalloc(size_t num_elems, size_t byte_size)
void * FXMEM_DefaultRealloc(void *pointer, size_t new_size)
void * FX_ArrayBufferAllocate(size_t length)
void FX_InitializeMemoryAllocators()
void FX_ArrayBufferFree(void *data)
void * FX_ArrayBufferAllocateUninitialized(size_t length)
void * FX_Random_MT_Start(uint32_t dwSeed)
uint32_t FX_Random_MT_Generate(void *pContext)
void FX_Random_MT_Close(void *pContext)
bool operator==(const char *lhs, const ByteString &rhs)
bool operator<(const ByteStringView &lhs, const char *rhs)
ByteString operator+(const ByteString &str1, const ByteString &str2)
ByteString operator+(ByteStringView str1, const char *str2)
bool operator<(const ByteStringView &lhs, const ByteString &rhs)
bool operator==(const T *lhs, const StringViewTemplate< T > &rhs)
bool operator<(const T *lhs, const StringViewTemplate< T > &rhs)
ByteString operator+(const ByteString &str1, char ch)
ByteString operator+(const ByteString &str1, const char *str2)
void PrintTo(const ByteString &str, std::ostream *os)
bool operator!=(const T *lhs, const StringViewTemplate< T > &rhs)
ByteString operator+(char ch, const ByteString &str2)
ByteString operator+(const ByteString &str1, ByteStringView str2)
ByteString operator+(const char *str1, const ByteString &str2)
bool operator!=(ByteStringView lhs, const ByteString &rhs)
bool operator!=(const char *lhs, const ByteString &rhs)
ByteString operator+(ByteStringView str1, ByteStringView str2)
ByteString operator+(ByteStringView str1, char ch)
bool operator<(const char *lhs, const ByteString &rhs)
ByteString operator+(char ch, ByteStringView str2)
ByteString operator+(ByteStringView str1, const ByteString &str2)
ByteString operator+(const char *str1, ByteStringView str2)
bool operator==(ByteStringView lhs, const ByteString &rhs)
void * CallocOrDie2D(size_t w, size_t h, size_t member_size)
void * AllocOrDie2D(size_t w, size_t h, size_t member_size)
void * StringAllocOrDie(size_t num_members, size_t member_size)
void * Alloc(size_t num_members, size_t member_size)
void * StringAlloc(size_t num_members, size_t member_size)
void * ReallocOrDie(void *ptr, size_t num_members, size_t member_size)
void * Realloc(void *ptr, size_t num_members, size_t member_size)
void StringDealloc(void *ptr)
void * AllocOrDie(size_t num_members, size_t member_size)
void * Calloc(size_t num_members, size_t member_size)
void * CallocOrDie(size_t num_members, size_t member_size)
UnownedPtr< T > WrapUnowned(T *that)
RetainPtr< T > MakeRetain(Args &&... args)
RetainPtr< T > WrapRetain(T *that)
#define CONSTRUCT_VIA_MAKE_RETAIN
void operator()(void *ptr) const
pointer allocate(size_type n, const void *hint=0)
void deallocate(pointer p, size_type n)
const_pointer address(const_reference x) const noexcept
FxPartitionAllocAllocator() noexcept=default
size_type max_size() const noexcept
~FxPartitionAllocAllocator()=default
pointer address(reference x) const noexcept
FxPartitionAllocAllocator(const FxPartitionAllocAllocator< U, Alloc, Free > &other) noexcept
bool operator!=(const FxPartitionAllocAllocator &that)
void construct(U *p, Args &&... args)
bool operator==(const FxPartitionAllocAllocator &that)
FxPartitionAllocAllocator(const FxPartitionAllocAllocator &other) noexcept=default
void operator()(T *ptr) const
size_t operator()(const ByteString &str) const
#define UNOWNED_PTR_EXCLUSION