Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fx_memory_wrappers.h
Go to the documentation of this file.
1// Copyright 2019 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
6#define CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
7
8#include <limits>
9#include <type_traits>
10#include <utility>
11
12#include "core/fxcrt/fx_memory.h"
13
14// Used with std::unique_ptr to FX_Free raw memory.
16 inline void operator()(void* ptr) const { FX_Free(ptr); }
17};
18
19// Escape hatch mechanism to allow non_arithmetic types into data partition.
20template <typename T>
21struct IsFXDataPartitionException : std::false_type {};
22
23// Use with caution. No further checks are made to see if `T` is appropriate
24// for the Data Partition (e.g. no pointers, strings, vtables, etc.). This
25// declaration must occur in the top-level namespace.
26#define FX_DATA_PARTITION_EXCEPTION(T)
27 template <>
28 struct IsFXDataPartitionException<T> : std::true_type {}
29
30// Allocators for mapping STL containers onto Partition Alloc.
31// Otherwise, replacing e.g. the FX_AllocUninit/FX_Free pairs with STL may
32// undo some of the nice segregation that we get from PartitionAlloc.
33template <class T, void* Alloc(size_t, size_t), void Free(void*)>
35 public:
36#if !defined(COMPILER_MSVC) || defined(NDEBUG)
37 static_assert(std::is_arithmetic<T>::value || std::is_enum<T>::value ||
39 "Only numeric types allowed in this partition");
40#endif
41
42 using value_type = T;
43 using pointer = T*;
44 using const_pointer = const T*;
45 using reference = T&;
46 using const_reference = const T&;
49
50 template <class U>
51 struct rebind {
52 using other = FxPartitionAllocAllocator<U, Alloc, Free>;
53 };
54
55 FxPartitionAllocAllocator() noexcept = default;
57 default;
59
60 template <typename U>
62 const FxPartitionAllocAllocator<U, Alloc, Free>& other) noexcept {}
63
64 pointer address(reference x) const noexcept { return &x; }
65 const_pointer address(const_reference x) const noexcept { return &x; }
66 pointer allocate(size_type n, const void* hint = 0) {
67 return static_cast<pointer>(Alloc(n, sizeof(value_type)));
68 }
69 void deallocate(pointer p, size_type n) { Free(p); }
70 size_type max_size() const noexcept {
71 return std::numeric_limits<size_type>::max() / sizeof(value_type);
72 }
73
74 template <class U, class... Args>
75 void construct(U* p, Args&&... args) {
76 new (reinterpret_cast<void*>(p)) U(std::forward<Args>(args)...);
77 }
78
79 template <class U>
80 void destroy(U* p) {
81 p->~U();
82 }
83
84 // There's no state, so they are all the same,
85 bool operator==(const FxPartitionAllocAllocator& that) { return true; }
86 bool operator!=(const FxPartitionAllocAllocator& that) { return false; }
87};
88
89// Used to put backing store for std::vector<> and such into the
90// general partition, ensuring they contain data only.
91template <typename T,
92 typename = std::enable_if_t<std::is_arithmetic<T>::value ||
93 std::is_enum<T>::value ||
94 IsFXDataPartitionException<T>::value>>
95using FxAllocAllocator = FxPartitionAllocAllocator<T,
96 pdfium::internal::AllocOrDie,
97 pdfium::internal::Dealloc>;
98
99// Used to put backing store for std::string<> and std::ostringstream<>
100// into the string partition.
101template <typename T>
102using FxStringAllocator =
103 FxPartitionAllocAllocator<T,
104 pdfium::internal::StringAllocOrDie,
105 pdfium::internal::StringDealloc>;
106
107#endif // CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
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_Creator(CPDF_Document *pDoc, RetainPtr< IFX_RetainableWriteStream > archive)
bool SetFileVersion(int32_t fileVersion)
void RemoveSecurity()
bool Create(uint32_t flags)
virtual FX_FILESIZE CurrentOffset() const =0
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
Definition fx_stream.cpp:68
virtual size_t ReadBlock(pdfium::span< uint8_t > buffer)
Definition fx_stream.cpp:88
virtual FX_FILESIZE GetPosition()
Definition fx_stream.cpp:84
virtual bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset)=0
virtual bool IsEOF()
Definition fx_stream.cpp:80
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
Definition fx_stream.cpp:92
virtual bool WriteBlockAtOffset(pdfium::span< const uint8_t > data, FX_FILESIZE offset)=0
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
Definition fx_stream.cpp:76
virtual bool Flush()=0
virtual FX_FILESIZE GetSize()=0
bool WriteFilesize(FX_FILESIZE size)
Definition fx_stream.cpp:61
bool WriteByte(uint8_t byte)
Definition fx_stream.cpp:51
bool WriteString(ByteStringView str)
Definition fx_stream.cpp:47
virtual ~IFX_WriteStream()=default
bool WriteDWord(uint32_t i)
Definition fx_stream.cpp:55
virtual bool WriteBlock(pdfium::span< const uint8_t > data)=0
void TrimLeft(ByteStringView targets)
bool IsValidLength(size_t length) const
Definition bytestring.h:121
bool Contains(ByteStringView lpszSub, size_t start=0) const
Definition bytestring.h:187
const_iterator begin() const
Definition bytestring.h:102
bool IsValidIndex(size_t index) const
Definition bytestring.h:120
static ByteString FormatFloat(float f)
ByteStringView AsStringView() const
Definition bytestring.h:87
uint32_t GetID() const
Definition bytestring.h:213
void Reserve(size_t len)
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
Definition bytestring.h:131
size_t GetLength() const
Definition bytestring.h:115
ByteString Substr(size_t first, size_t count) const
size_t GetStringLength() const
Definition bytestring.h:116
size_t InsertAtBack(char ch)
Definition bytestring.h:162
bool operator==(ByteStringView str) const
pdfium::span< const uint8_t > raw_span() const
Definition bytestring.h:97
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
Definition bytestring.h:191
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
Definition bytestring.h:111
ByteString & operator+=(char ch)
const uint8_t * raw_str() const
Definition bytestring.h:80
void ReallocBeforeWrite(size_t nNewLen)
ByteString(ByteStringView bstrc)
RetainPtr< StringData > m_pData
Definition bytestring.h:225
static ByteString FormatInteger(int i)
pdfium::span< char > GetBuffer(size_t nMinBufLength)
void Trim(char target)
bool operator==(const ByteString &other) const
bool operator==(const char *ptr) const
const_iterator end() const
Definition bytestring.h:103
ByteString(const ByteString &other)
size_t Remove(char ch)
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
Definition bytestring.h:132
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
Definition bytestring.h:76
ByteString Substr(size_t offset) const
ByteString & operator=(const ByteString &that)
ByteString & operator=(ByteString &&that) noexcept
bool IsEmpty() const
Definition bytestring.h:119
void TrimRight(ByteStringView targets)
bool operator<(const ByteString &other) const
ByteString(const std::initializer_list< ByteStringView > &list)
CharType operator[](const size_t index) const
Definition bytestring.h:150
const_reverse_iterator rbegin() const
Definition bytestring.h:108
CharType Back() const
Definition bytestring.h:156
CharType Front() const
Definition bytestring.h:155
bool operator!=(const char *ptr) const
Definition bytestring.h:130
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)
Definition bytestring.h:161
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
#define FPDFCREATE_INCREMENTAL
#define FPDFCREATE_NO_ORIGINAL
void * FX_Random_MT_Start(uint32_t dwSeed)
Definition fx_random.cpp:85
uint32_t FX_Random_MT_Generate(void *pContext)
Definition fx_random.cpp:96
void FX_Random_MT_Close(void *pContext)
#define FX_FILESIZE
Definition fx_types.h:19
bool operator==(const char *lhs, const ByteString &rhs)
Definition bytestring.h:233
bool operator<(const ByteStringView &lhs, const char *rhs)
Definition bytestring.h:251
ByteString operator+(const ByteString &str1, const ByteString &str2)
Definition bytestring.h:270
ByteString operator+(ByteStringView str1, const char *str2)
Definition bytestring.h:258
bool operator<(const ByteStringView &lhs, const ByteString &rhs)
Definition bytestring.h:248
ByteString operator+(const ByteString &str1, char ch)
Definition bytestring.h:273
ByteString operator+(const ByteString &str1, const char *str2)
Definition bytestring.h:279
void PrintTo(const ByteString &str, std::ostream *os)
ByteString operator+(char ch, const ByteString &str2)
Definition bytestring.h:276
ByteString operator+(const ByteString &str1, ByteStringView str2)
Definition bytestring.h:285
ByteString operator+(const char *str1, const ByteString &str2)
Definition bytestring.h:282
bool operator!=(ByteStringView lhs, const ByteString &rhs)
Definition bytestring.h:242
bool operator!=(const char *lhs, const ByteString &rhs)
Definition bytestring.h:239
ByteString operator+(ByteStringView str1, ByteStringView str2)
Definition bytestring.h:255
ByteString operator+(ByteStringView str1, char ch)
Definition bytestring.h:264
bool operator<(const char *lhs, const ByteString &rhs)
Definition bytestring.h:245
ByteString operator+(char ch, ByteStringView str2)
Definition bytestring.h:267
ByteString operator+(ByteStringView str1, const ByteString &str2)
Definition bytestring.h:288
ByteString operator+(const char *str1, ByteStringView str2)
Definition bytestring.h:261
bool operator==(ByteStringView lhs, const ByteString &rhs)
Definition bytestring.h:236
#define CHECK(cvref)
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
size_t operator()(const ByteString &str) const
Definition bytestring.h:315