Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: core/include/fxcrt/fx_basic.h

Issue 372473003: Remove custom memory manager (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/include/fxcrt/fx_memory.h » ('j') | core/include/fxcrt/fx_memory.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef _FX_BASIC_H_ 7 #ifndef _FX_BASIC_H_
8 #define _FX_BASIC_H_ 8 #define _FX_BASIC_H_
9 #ifndef _FX_SYSTEM_H_ 9 #ifndef _FX_SYSTEM_H_
10 #include "fx_system.h" 10 #include "fx_system.h"
11 #endif 11 #endif
12 #ifndef _FX_MEMORY_H_ 12 #ifndef _FX_MEMORY_H_
13 #include "fx_memory.h" 13 #include "fx_memory.h"
14 #endif 14 #endif
15 #ifndef _FX_STRING_H_ 15 #ifndef _FX_STRING_H_
16 #include "fx_string.h" 16 #include "fx_string.h"
17 #endif 17 #endif
18 #ifndef _FX_STREAM_H_ 18 #ifndef _FX_STREAM_H_
19 #include "fx_stream.h" 19 #include "fx_stream.h"
20 #endif 20 #endif
21 class CFX_BinaryBuf : public CFX_Object 21 class CFX_BinaryBuf : public CFX_Object
22 { 22 {
23 public: 23 public:
24 24 CFX_BinaryBuf();
25 CFX_BinaryBuf(IFX_Allocator* pAllocator = NULL); 25 CFX_BinaryBuf(FX_STRSIZE size);
26
27 CFX_BinaryBuf(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
28 26
29 ~CFX_BinaryBuf(); 27 ~CFX_BinaryBuf();
30 28
31 void Clear(); 29 void Clear();
32 30
33 void EstimateSize(FX_STRSIZE size, FX _STRSIZE alloc_step = 0); 31 void EstimateSize(FX_STRSIZE size, FX _STRSIZE alloc_step = 0);
34 32
35 void AppendBlock(const void* pBuf, FX _STRSIZE size); 33 void AppendBlock(const void* pBuf, FX _STRSIZE size);
36 34
37 void AppendFill(FX_BYTE byte, FX_STRS IZE count); 35 void AppendFill(FX_BYTE byte, FX_STRS IZE count);
(...skipping 25 matching lines...) Expand all
63 { 61 {
64 return m_pBuffer; 62 return m_pBuffer;
65 } 63 }
66 64
67 FX_STRSIZE GetSize() const 65 FX_STRSIZE GetSize() const
68 { 66 {
69 return m_DataSize; 67 return m_DataSize;
70 } 68 }
71 69
72 CFX_ByteStringC GetByteString() const; 70 CFX_ByteStringC GetByteString() const;
73 void GetByteStringL(CFX_ByteStringL & str) const;
74 71
75 void DetachBuffer(); 72 void DetachBuffer();
76
77 IFX_Allocator* m_pAllocator;
78 protected: 73 protected:
79 74
80 FX_STRSIZE m_AllocStep; 75 FX_STRSIZE m_AllocStep;
81 76
82 FX_LPBYTE m_pBuffer; 77 FX_LPBYTE m_pBuffer;
83 78
84 FX_STRSIZE m_DataSize; 79 FX_STRSIZE m_DataSize;
85 80
86 FX_STRSIZE m_AllocSize; 81 FX_STRSIZE m_AllocSize;
87 82
88 void ExpandBuf(FX_STRSIZE size); 83 void ExpandBuf(FX_STRSIZE size);
89 }; 84 };
90 class CFX_ByteTextBuf : public CFX_BinaryBuf 85 class CFX_ByteTextBuf : public CFX_BinaryBuf
91 { 86 {
92 public: 87 public:
93 88
94 CFX_ByteTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator ) {}
95
96 void operator = (FX_BSTR str); 89 void operator = (FX_BSTR str);
97 90
98 void AppendChar(int ch) 91 void AppendChar(int ch)
99 { 92 {
100 AppendByte((FX_BYTE)ch); 93 AppendByte((FX_BYTE)ch);
101 } 94 }
102 95
103 CFX_ByteTextBuf& operator << (int i); 96 CFX_ByteTextBuf& operator << (int i);
104 97
105 CFX_ByteTextBuf& operator << (FX_DWORD i); 98 CFX_ByteTextBuf& operator << (FX_DWORD i);
106 99
107 CFX_ByteTextBuf& operator << (double f); 100 CFX_ByteTextBuf& operator << (double f);
108 101
109 CFX_ByteTextBuf& operator << (FX_BSTR lpsz); 102 CFX_ByteTextBuf& operator << (FX_BSTR lpsz);
110 103
111 CFX_ByteTextBuf& operator << (const CFX_ByteTextBuf& buf); 104 CFX_ByteTextBuf& operator << (const CFX_ByteTextBuf& buf);
112 105
113 FX_STRSIZE GetLength() const 106 FX_STRSIZE GetLength() const
114 { 107 {
115 return m_DataSize; 108 return m_DataSize;
116 } 109 }
117 }; 110 };
118 class CFX_WideTextBuf : public CFX_BinaryBuf 111 class CFX_WideTextBuf : public CFX_BinaryBuf
119 { 112 {
120 public: 113 public:
121 114
122 CFX_WideTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator ) {}
123
124 void operator = (FX_LPCWSTR lpsz); 115 void operator = (FX_LPCWSTR lpsz);
125 116
126 void operator = (FX_WSTR str); 117 void operator = (FX_WSTR str);
127 118
128 void AppendChar(FX_WCHAR wch); 119 void AppendChar(FX_WCHAR wch);
129 120
130 CFX_WideTextBuf& operator << (int i); 121 CFX_WideTextBuf& operator << (int i);
131 122
132 CFX_WideTextBuf& operator << (double f); 123 CFX_WideTextBuf& operator << (double f);
133 124
(...skipping 13 matching lines...) Expand all
147 { 138 {
148 return (FX_LPWSTR)m_pBuffer; 139 return (FX_LPWSTR)m_pBuffer;
149 } 140 }
150 141
151 void Delete(int start_index, int coun t) 142 void Delete(int start_index, int coun t)
152 { 143 {
153 CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_ WCHAR)); 144 CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_ WCHAR));
154 } 145 }
155 146
156 CFX_WideStringC GetWideString() const; 147 CFX_WideStringC GetWideString() const;
157 void GetWideStringL(CFX_WideStringL& wideText) const;
158 }; 148 };
159 class CFX_ArchiveSaver : public CFX_Object 149 class CFX_ArchiveSaver : public CFX_Object
160 { 150 {
161 public: 151 public:
162 152 CFX_ArchiveSaver() : m_pStream(NULL) {}
163 CFX_ArchiveSaver(IFX_Allocator* pAllocator = NULL) : m_SavingBuf(pAllocator) , m_pStream(NULL) {}
164 153
165 CFX_ArchiveSaver& operator << (FX_BYTE i); 154 CFX_ArchiveSaver& operator << (FX_BYTE i);
166 155
167 CFX_ArchiveSaver& operator << (int i); 156 CFX_ArchiveSaver& operator << (int i);
168 157
169 CFX_ArchiveSaver& operator << (FX_DWORD i); 158 CFX_ArchiveSaver& operator << (FX_DWORD i);
170 159
171 CFX_ArchiveSaver& operator << (FX_FLOAT i); 160 CFX_ArchiveSaver& operator << (FX_FLOAT i);
172 161
173 CFX_ArchiveSaver& operator << (double i); 162 CFX_ArchiveSaver& operator << (double i);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 216
228 FX_DWORD m_LoadingPos; 217 FX_DWORD m_LoadingPos;
229 218
230 FX_LPCBYTE m_pLoadingBuf; 219 FX_LPCBYTE m_pLoadingBuf;
231 220
232 FX_DWORD m_LoadingSize; 221 FX_DWORD m_LoadingSize;
233 }; 222 };
234 class IFX_BufferArchive 223 class IFX_BufferArchive
235 { 224 {
236 public: 225 public:
237 226 IFX_BufferArchive(FX_STRSIZE size);
238 IFX_BufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
239 227
240 228
241 virtual void Clear(); 229 virtual void Clear();
242 230
243 231
244 FX_BOOL Flush(); 232 FX_BOOL Flush();
245 233
246 234
247 FX_INT32 AppendBlock(const void* pBuf, size_t siz e); 235 FX_INT32 AppendBlock(const void* pBuf, size_t siz e);
248 236
249 FX_INT32 AppendByte(FX_BYTE byte); 237 FX_INT32 AppendByte(FX_BYTE byte);
250 238
251 FX_INT32 AppendDWord(FX_DWORD i); 239 FX_INT32 AppendDWord(FX_DWORD i);
252 240
253 241
254 FX_INT32 AppendString(FX_BSTR lpsz); 242 FX_INT32 AppendString(FX_BSTR lpsz);
255 243
256 protected: 244 protected:
257 245
258 virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0; 246 virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0;
259 247
260
261 IFX_Allocator* m_pAllocator;
262
263 FX_STRSIZE m_BufSize; 248 FX_STRSIZE m_BufSize;
264 249
265 FX_LPBYTE m_pBuffer; 250 FX_LPBYTE m_pBuffer;
266 251
267 FX_STRSIZE m_Length; 252 FX_STRSIZE m_Length;
268 }; 253 };
269 class CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object 254 class CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object
270 { 255 {
271 public: 256 public:
272 CFX_FileBufferArchive(FX_STRSIZE size = 32768, IFX_Allocator* pAllocator = N ULL); 257 CFX_FileBufferArchive(FX_STRSIZE size = 32768);
273 ~CFX_FileBufferArchive(); 258 ~CFX_FileBufferArchive();
274 virtual void Clear(); 259 virtual void Clear();
275 260
276 FX_BOOL AttachFile(IFX_StreamWrite *pFil e, FX_BOOL bTakeover = FALSE); 261 FX_BOOL AttachFile(IFX_StreamWrite *pFil e, FX_BOOL bTakeover = FALSE);
277 262
278 FX_BOOL AttachFile(FX_LPCWSTR filename); 263 FX_BOOL AttachFile(FX_LPCWSTR filename);
279 264
280 FX_BOOL AttachFile(FX_LPCSTR filename); 265 FX_BOOL AttachFile(FX_LPCSTR filename);
281 private: 266 private:
282 267
(...skipping 10 matching lines...) Expand all
293 278
294 CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteStri ng& bstr); 279 CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteStri ng& bstr);
295 280
296 CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideStri ng& wstr); 281 CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideStri ng& wstr);
297 282
298 FX_INT32 (*m_GetCodePage)(); 283 FX_INT32 (*m_GetCodePage)();
299 }; 284 };
300 class CFX_UTF8Decoder 285 class CFX_UTF8Decoder
301 { 286 {
302 public: 287 public:
303 288 CFX_UTF8Decoder()
304 CFX_UTF8Decoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
305 { 289 {
306 m_PendingBytes = 0; 290 m_PendingBytes = 0;
307 } 291 }
308 292
309 void Clear(); 293 void Clear();
310 294
311 void Input(FX_BYTE byte); 295 void Input(FX_BYTE byte);
312 296
313 void AppendChar(FX_DWORD ch); 297 void AppendChar(FX_DWORD ch);
314 298
315 void ClearStatus() 299 void ClearStatus()
316 { 300 {
317 m_PendingBytes = 0; 301 m_PendingBytes = 0;
318 } 302 }
319 303
320 CFX_WideStringC GetResult() const 304 CFX_WideStringC GetResult() const
321 { 305 {
322 return m_Buffer.GetWideString(); 306 return m_Buffer.GetWideString();
323 } 307 }
324 void GetResult(CFX_WideStringL &result) const
325 {
326 m_Buffer.GetWideStringL(result);
327 }
328 protected: 308 protected:
329 309
330 int m_PendingBytes; 310 int m_PendingBytes;
331 311
332 FX_DWORD m_PendingChar; 312 FX_DWORD m_PendingChar;
333 313
334 CFX_WideTextBuf m_Buffer; 314 CFX_WideTextBuf m_Buffer;
335 }; 315 };
336 class CFX_UTF8Encoder 316 class CFX_UTF8Encoder
337 { 317 {
338 public: 318 public:
339 319 CFX_UTF8Encoder()
340 CFX_UTF8Encoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
341 { 320 {
342 m_UTF16First = 0; 321 m_UTF16First = 0;
343 } 322 }
344 323
345 void Input(FX_WCHAR unicode); 324 void Input(FX_WCHAR unicode);
346 325
347 void AppendStr(FX_BSTR str) 326 void AppendStr(FX_BSTR str)
348 { 327 {
349 m_UTF16First = 0; 328 m_UTF16First = 0;
350 m_Buffer << str; 329 m_Buffer << str;
351 } 330 }
352 331
353 CFX_ByteStringC GetResult() const 332 CFX_ByteStringC GetResult() const
354 { 333 {
355 return m_Buffer.GetByteString(); 334 return m_Buffer.GetByteString();
356 } 335 }
357 void GetResult(CFX_ByteStringL &result) const
358 {
359 m_Buffer.GetByteStringL(result);
360 }
361 protected: 336 protected:
362 337
363 CFX_ByteTextBuf m_Buffer; 338 CFX_ByteTextBuf m_Buffer;
364 339
365 FX_DWORD m_UTF16First; 340 FX_DWORD m_UTF16First;
366 }; 341 };
367 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl); 342 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl);
368 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl); 343 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl);
369 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI); 344 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI);
370 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI); 345 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI);
371 class CFX_BasicArray : public CFX_Object 346 class CFX_BasicArray : public CFX_Object
372 { 347 {
373 public:
374
375 IFX_Allocator* m_pAllocator;
376 protected: 348 protected:
377 349 CFX_BasicArray(int unit_size);
378 CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator = NULL);
379 350
380 ~CFX_BasicArray(); 351 ~CFX_BasicArray();
381 352
382 FX_BOOL SetSize(int nNewSize, int nGrowBy); 353 FX_BOOL SetSize(int nNewSize, int nGrowBy);
383 354
384 FX_BOOL Append(const CFX_BasicArray& src); 355 FX_BOOL Append(const CFX_BasicArray& src);
385 356
386 FX_BOOL Copy(const CFX_BasicArray& src); 357 FX_BOOL Copy(const CFX_BasicArray& src);
387 358
388 FX_LPBYTE InsertSpaceAt(int nIndex, int nCount); 359 FX_LPBYTE InsertSpaceAt(int nIndex, int nCount);
(...skipping 12 matching lines...) Expand all
401 int m_nMaxSize; 372 int m_nMaxSize;
402 373
403 int m_nGrowBy; 374 int m_nGrowBy;
404 375
405 int m_nUnitSize; 376 int m_nUnitSize;
406 }; 377 };
407 template<class TYPE> 378 template<class TYPE>
408 class CFX_ArrayTemplate : public CFX_BasicArray 379 class CFX_ArrayTemplate : public CFX_BasicArray
409 { 380 {
410 public: 381 public:
411 382 CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {}
412 CFX_ArrayTemplate(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof( TYPE), pAllocator) {}
413 383
414 int GetSize() const 384 int GetSize() const
415 { 385 {
416 return m_nSize; 386 return m_nSize;
417 } 387 }
418 388
419 int GetUpperBound() const 389 int GetUpperBound() const
420 { 390 {
421 return m_nSize - 1; 391 return m_nSize - 1;
422 } 392 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray; 538 typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
569 typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray; 539 typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray;
570 typedef CFX_ArrayTemplate<void*> CFX_PtrArray; 540 typedef CFX_ArrayTemplate<void*> CFX_PtrArray;
571 typedef CFX_ArrayTemplate<FX_FILESIZE> CFX_FileSizeArray; 541 typedef CFX_ArrayTemplate<FX_FILESIZE> CFX_FileSizeArray;
572 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray; 542 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray;
573 typedef CFX_ArrayTemplate<FX_INT32> CFX_Int32Array; 543 typedef CFX_ArrayTemplate<FX_INT32> CFX_Int32Array;
574 template <class ObjectClass> 544 template <class ObjectClass>
575 class CFX_ObjectArray : public CFX_BasicArray 545 class CFX_ObjectArray : public CFX_BasicArray
576 { 546 {
577 public: 547 public:
578 548 CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {}
579 CFX_ObjectArray(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(Ob jectClass), pAllocator) {}
580 549
581 ~CFX_ObjectArray() 550 ~CFX_ObjectArray()
582 { 551 {
583 RemoveAll(); 552 RemoveAll();
584 } 553 }
585 554
586 void Add(const ObjectClass& data) 555 void Add(const ObjectClass& data)
587 { 556 {
588 new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data); 557 new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
589 } 558 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 ((ObjectClass*)GetDataPtr(i))->~ObjectClass(); 654 ((ObjectClass*)GetDataPtr(i))->~ObjectClass();
686 } 655 }
687 CFX_BasicArray::SetSize(0, -1); 656 CFX_BasicArray::SetSize(0, -1);
688 } 657 }
689 }; 658 };
690 typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray; 659 typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
691 typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray; 660 typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
692 class CFX_BaseSegmentedArray : public CFX_Object 661 class CFX_BaseSegmentedArray : public CFX_Object
693 { 662 {
694 public: 663 public:
695 664 CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index _size = 8);
696 CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index _size = 8, IFX_Allocator* pAllocator = NULL);
697 665
698 ~CFX_BaseSegmentedArray(); 666 ~CFX_BaseSegmentedArray();
699 667
700 void SetUnitSize(int unit_size, int segment_units, int index_size = 8 ); 668 void SetUnitSize(int unit_size, int segment_units, int index_size = 8 );
701 669
702 void* Add(); 670 void* Add();
703 671
704 void* GetAt(int index) const; 672 void* GetAt(int index) const;
705 673
706 void RemoveAll(); 674 void RemoveAll();
707 675
708 void Delete(int index, int count = 1); 676 void Delete(int index, int count = 1);
709 677
710 int GetSize() const 678 int GetSize() const
711 { 679 {
712 return m_DataSize; 680 return m_DataSize;
713 } 681 }
714 682
715 int GetSegmentSize() const 683 int GetSegmentSize() const
716 { 684 {
717 return m_SegmentSize; 685 return m_SegmentSize;
718 } 686 }
719 687
720 int GetUnitSize() const 688 int GetUnitSize() const
721 { 689 {
722 return m_UnitSize; 690 return m_UnitSize;
723 } 691 }
724 692
725 void* Iterate(FX_BOOL (*callback)(void* param, void* pData), void* par am) const; 693 void* Iterate(FX_BOOL (*callback)(void* param, void* pData), void* par am) const;
726
727 IFX_Allocator* m_pAllocator;
728 private: 694 private:
729 695
730 int m_UnitSize; 696 int m_UnitSize;
731 697
732 short m_SegmentSize; 698 short m_SegmentSize;
733 699
734 FX_BYTE m_IndexSize; 700 FX_BYTE m_IndexSize;
735 701
736 FX_BYTE m_IndexDepth; 702 FX_BYTE m_IndexDepth;
737 703
738 int m_DataSize; 704 int m_DataSize;
739 705
740 void* m_pIndex; 706 void* m_pIndex;
741 void** GetIndex(int seg_index) const; 707 void** GetIndex(int seg_index) const;
742 void* IterateIndex(int level, int& start, void** pIndex, FX_BOOL (*cal lback)(void* param, void* pData), void* param) const; 708 void* IterateIndex(int level, int& start, void** pIndex, FX_BOOL (*cal lback)(void* param, void* pData), void* param) const;
743 void* IterateSegment(FX_LPCBYTE pSegment, int count, FX_BOOL (*callbac k)(void* param, void* pData), void* param) const; 709 void* IterateSegment(FX_LPCBYTE pSegment, int count, FX_BOOL (*callbac k)(void* param, void* pData), void* param) const;
744 }; 710 };
745 template <class ElementType> 711 template <class ElementType>
746 class CFX_SegmentedArray : public CFX_BaseSegmentedArray 712 class CFX_SegmentedArray : public CFX_BaseSegmentedArray
747 { 713 {
748 public: 714 public:
749 715 CFX_SegmentedArray(int segment_units, int index_size = 8)
750 CFX_SegmentedArray(int segment_units, int index_size = 8, IFX_Allocator* pAl locator = NULL) 716 : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size)
751 : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size, pAllocator)
752 {} 717 {}
753 718
754 void Add(ElementType data) 719 void Add(ElementType data)
755 { 720 {
756 *(ElementType*)CFX_BaseSegmentedArray::Add() = data; 721 *(ElementType*)CFX_BaseSegmentedArray::Add() = data;
757 } 722 }
758 723
759 ElementType& operator [] (int index) 724 ElementType& operator [] (int index)
760 { 725 {
761 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index); 726 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index);
762 } 727 }
763 }; 728 };
764 template <class DataType, int FixedSize> 729 template <class DataType, int FixedSize>
765 class CFX_FixedBufGrow : public CFX_Object 730 class CFX_FixedBufGrow : public CFX_Object
766 { 731 {
767 public: 732 public:
768 CFX_FixedBufGrow(IFX_Allocator* pAllocator = NULL) 733 CFX_FixedBufGrow() : m_pData(NULL)
769 : m_pAllocator(pAllocator)
770 , m_pData(NULL)
771 {} 734 {}
772 CFX_FixedBufGrow(int data_size, IFX_Allocator* pAllocator = NULL) 735 CFX_FixedBufGrow(int data_size) : m_pData(NULL)
773 : m_pAllocator(pAllocator)
774 , m_pData(NULL)
775 { 736 {
776 if (data_size > FixedSize) { 737 if (data_size > FixedSize) {
777 m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size); 738 m_pData = FX_Alloc(DataType, data_size);
778 } else { 739 } else {
779 FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize); 740 FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
780 } 741 }
781 } 742 }
782 void SetDataSize(int data_size) 743 void SetDataSize(int data_size)
783 { 744 {
784 if (m_pData) { 745 if (m_pData) {
785 FX_Allocator_Free(m_pAllocator, m_pData); 746 FX_Free(m_pData);
786 } 747 }
787 m_pData = NULL; 748 m_pData = NULL;
788 if (data_size > FixedSize) { 749 if (data_size > FixedSize) {
789 m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size); 750 m_pData = FX_Alloc(DataType, data_size);
790 } else { 751 } else {
791 FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize); 752 FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
792 } 753 }
793 } 754 }
794 ~CFX_FixedBufGrow() 755 ~CFX_FixedBufGrow()
795 { 756 {
796 if (m_pData) { 757 if (m_pData) {
797 FX_Allocator_Free(m_pAllocator, m_pData); 758 FX_Free(m_pData);
798 } 759 }
799 } 760 }
800 operator DataType*() 761 operator DataType*()
801 { 762 {
802 return m_pData ? m_pData : m_Data; 763 return m_pData ? m_pData : m_Data;
803 } 764 }
804 private: 765 private:
805 IFX_Allocator* m_pAllocator;
806 DataType m_Data[FixedSize]; 766 DataType m_Data[FixedSize];
807 DataType* m_pData; 767 DataType* m_pData;
808 }; 768 };
809 template <class DataType> 769 template <class DataType>
810 class CFX_TempBuf 770 class CFX_TempBuf
811 { 771 {
812 public: 772 public:
813 CFX_TempBuf(int size, IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllo cator) 773 CFX_TempBuf(int size)
814 { 774 {
815 m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, size); 775 m_pData = FX_Alloc(DataType, size);
816 } 776 }
817 ~CFX_TempBuf() 777 ~CFX_TempBuf()
818 { 778 {
819 if (m_pData) { 779 if (m_pData) {
820 FX_Allocator_Free(m_pAllocator, m_pData); 780 FX_Free(m_pData);
821 } 781 }
822 } 782 }
823 DataType& operator[](int i) 783 DataType& operator[](int i)
824 { 784 {
825 FXSYS_assert(m_pData != NULL); 785 FXSYS_assert(m_pData != NULL);
826 return m_pData[i]; 786 return m_pData[i];
827 } 787 }
828 operator DataType*() 788 operator DataType*()
829 { 789 {
830 return m_pData; 790 return m_pData;
831 } 791 }
832 private: 792 private:
833 IFX_Allocator* m_pAllocator;
834 DataType* m_pData; 793 DataType* m_pData;
835 }; 794 };
836 class CFX_MapPtrToPtr : public CFX_Object 795 class CFX_MapPtrToPtr : public CFX_Object
837 { 796 {
838 protected: 797 protected:
839 798
840 struct CAssoc { 799 struct CAssoc {
841 800
842 CAssoc* pNext; 801 CAssoc* pNext;
843 802
844 void* key; 803 void* key;
845 804
846 void* value; 805 void* value;
847 }; 806 };
848 public: 807 public:
849 808 CFX_MapPtrToPtr(int nBlockSize = 10);
850 CFX_MapPtrToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
851 809
852 ~CFX_MapPtrToPtr(); 810 ~CFX_MapPtrToPtr();
853 811
854 int GetCount() const 812 int GetCount() const
855 { 813 {
856 return m_nCount; 814 return m_nCount;
857 } 815 }
858 816
859 FX_BOOL IsEmpty() const 817 FX_BOOL IsEmpty() const
860 { 818 {
(...skipping 23 matching lines...) Expand all
884 void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) co nst; 842 void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) co nst;
885 843
886 FX_DWORD GetHashTableSize() const 844 FX_DWORD GetHashTableSize() const
887 { 845 {
888 return m_nHashTableSize; 846 return m_nHashTableSize;
889 } 847 }
890 848
891 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); 849 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
892 protected: 850 protected:
893 851
894 IFX_Allocator* m_pAllocator;
895
896 CAssoc** m_pHashTable; 852 CAssoc** m_pHashTable;
897 853
898 FX_DWORD m_nHashTableSize; 854 FX_DWORD m_nHashTableSize;
899 855
900 int m_nCount; 856 int m_nCount;
901 857
902 CAssoc* m_pFreeList; 858 CAssoc* m_pFreeList;
903 859
904 struct CFX_Plex* m_pBlocks; 860 struct CFX_Plex* m_pBlocks;
905 861
906 int m_nBlockSize; 862 int m_nBlockSize;
907 863
908 FX_DWORD HashKey(void* key) const; 864 FX_DWORD HashKey(void* key) const;
909 865
910 CAssoc* NewAssoc(); 866 CAssoc* NewAssoc();
911 867
912 void FreeAssoc(CAssoc* pAssoc); 868 void FreeAssoc(CAssoc* pAssoc);
913 869
914 CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const; 870 CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
915 }; 871 };
916 template <class KeyType, class ValueType> 872 template <class KeyType, class ValueType>
917 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr 873 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr
918 { 874 {
919 public: 875 public:
920 876 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {}
921 CFX_MapPtrTemplate(IFX_Allocator* pAllocator = NULL) : CFX_MapPtrToPtr(10, p Allocator) {}
922 877
923 FX_BOOL Lookup(KeyType key, ValueType& rValue) const 878 FX_BOOL Lookup(KeyType key, ValueType& rValue) const
924 { 879 {
925 FX_LPVOID pValue = NULL; 880 FX_LPVOID pValue = NULL;
926 if (!CFX_MapPtrToPtr::Lookup((void*)(FX_UINTPTR)key, pValue)) { 881 if (!CFX_MapPtrToPtr::Lookup((void*)(FX_UINTPTR)key, pValue)) {
927 return FALSE; 882 return FALSE;
928 } 883 }
929 rValue = (ValueType)(FX_UINTPTR)pValue; 884 rValue = (ValueType)(FX_UINTPTR)pValue;
930 return TRUE; 885 return TRUE;
931 } 886 }
(...skipping 19 matching lines...) Expand all
951 void* pValue = NULL; 906 void* pValue = NULL;
952 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); 907 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
953 rKey = (KeyType)(FX_UINTPTR)pKey; 908 rKey = (KeyType)(FX_UINTPTR)pKey;
954 rValue = (ValueType)(FX_UINTPTR)pValue; 909 rValue = (ValueType)(FX_UINTPTR)pValue;
955 } 910 }
956 }; 911 };
957 class CFX_CMapDWordToDWord : public CFX_Object 912 class CFX_CMapDWordToDWord : public CFX_Object
958 { 913 {
959 public: 914 public:
960 915
961 CFX_CMapDWordToDWord(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator ) {}
962
963 FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const; 916 FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const;
964 917
965 void SetAt(FX_DWORD key, FX_DWORD value); 918 void SetAt(FX_DWORD key, FX_DWORD value);
966 919
967 void EstimateSize(FX_DWORD size, FX_DWORD grow_by); 920 void EstimateSize(FX_DWORD size, FX_DWORD grow_by);
968 921
969 FX_POSITION GetStartPosition() const; 922 FX_POSITION GetStartPosition() const;
970 923
971 void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX _DWORD& value) const; 924 void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX _DWORD& value) const;
972 protected: 925 protected:
973 926
974 CFX_BinaryBuf m_Buffer; 927 CFX_BinaryBuf m_Buffer;
975 }; 928 };
976 class CFX_MapByteStringToPtr : public CFX_Object 929 class CFX_MapByteStringToPtr : public CFX_Object
977 { 930 {
978 protected: 931 protected:
979 932
980 struct CAssoc { 933 struct CAssoc {
981 934
982 CAssoc* pNext; 935 CAssoc* pNext;
983 936
984 FX_DWORD nHashValue; 937 FX_DWORD nHashValue;
985 938
986 CFX_ByteString key; 939 CFX_ByteString key;
987 940
988 void* value; 941 void* value;
989 }; 942 };
990 public: 943 public:
991 944 CFX_MapByteStringToPtr(int nBlockSize = 10);
992 CFX_MapByteStringToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL );
993 945
994 int GetCount() const 946 int GetCount() const
995 { 947 {
996 return m_nCount; 948 return m_nCount;
997 } 949 }
998 950
999 FX_BOOL IsEmpty() const 951 FX_BOOL IsEmpty() const
1000 { 952 {
1001 return m_nCount == 0; 953 return m_nCount == 0;
1002 } 954 }
(...skipping 23 matching lines...) Expand all
1026 FX_DWORD GetHashTableSize() const 978 FX_DWORD GetHashTableSize() const
1027 { 979 {
1028 return m_nHashTableSize; 980 return m_nHashTableSize;
1029 } 981 }
1030 982
1031 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); 983 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
1032 984
1033 FX_DWORD HashKey(FX_BSTR key) const; 985 FX_DWORD HashKey(FX_BSTR key) const;
1034 protected: 986 protected:
1035 987
1036 IFX_Allocator* m_pAllocator;
1037
1038 CAssoc** m_pHashTable; 988 CAssoc** m_pHashTable;
1039 989
1040 FX_DWORD m_nHashTableSize; 990 FX_DWORD m_nHashTableSize;
1041 991
1042 int m_nCount; 992 int m_nCount;
1043 993
1044 CAssoc* m_pFreeList; 994 CAssoc* m_pFreeList;
1045 995
1046 struct CFX_Plex* m_pBlocks; 996 struct CFX_Plex* m_pBlocks;
1047 997
1048 int m_nBlockSize; 998 int m_nBlockSize;
1049 999
1050 CAssoc* NewAssoc(); 1000 CAssoc* NewAssoc();
1051 1001
1052 void FreeAssoc(CAssoc* pAssoc); 1002 void FreeAssoc(CAssoc* pAssoc);
1053 1003
1054 CAssoc* GetAssocAt(FX_BSTR key, FX_DWORD& hash) const; 1004 CAssoc* GetAssocAt(FX_BSTR key, FX_DWORD& hash) const;
1055 public: 1005 public:
1056 1006
1057 ~CFX_MapByteStringToPtr(); 1007 ~CFX_MapByteStringToPtr();
1058 }; 1008 };
1059 class CFX_CMapByteStringToPtr : public CFX_Object 1009 class CFX_CMapByteStringToPtr : public CFX_Object
1060 { 1010 {
1061 public: 1011 public:
1062 1012 CFX_CMapByteStringToPtr();
1063 CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator = NULL);
1064 1013
1065 ~CFX_CMapByteStringToPtr(); 1014 ~CFX_CMapByteStringToPtr();
1066 1015
1067 void RemoveAll(); 1016 void RemoveAll();
1068 1017
1069 FX_POSITION GetStartPosition() const; 1018 FX_POSITION GetStartPosition() const;
1070 1019
1071 void GetNextAssoc(FX_POSITION& rNextPosition, CFX_Byt eString& rKey, void*& rValue) const; 1020 void GetNextAssoc(FX_POSITION& rNextPosition, CFX_Byt eString& rKey, void*& rValue) const;
1072 1021
1073 FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const; 1022 FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const;
(...skipping 17 matching lines...) Expand all
1091 1040
1092 struct CNode { 1041 struct CNode {
1093 1042
1094 CNode* pNext; 1043 CNode* pNext;
1095 1044
1096 CNode* pPrev; 1045 CNode* pPrev;
1097 1046
1098 void* data; 1047 void* data;
1099 }; 1048 };
1100 public: 1049 public:
1101 1050 CFX_PtrList(int nBlockSize = 10);
1102 CFX_PtrList(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
1103 1051
1104 FX_POSITION GetHeadPosition() const 1052 FX_POSITION GetHeadPosition() const
1105 { 1053 {
1106 return (FX_POSITION)m_pNodeHead; 1054 return (FX_POSITION)m_pNodeHead;
1107 } 1055 }
1108 1056
1109 FX_POSITION GetTailPosition() const 1057 FX_POSITION GetTailPosition() const
1110 { 1058 {
1111 return (FX_POSITION)m_pNodeTail; 1059 return (FX_POSITION)m_pNodeTail;
1112 } 1060 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 1108
1161 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL ) const; 1109 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL ) const;
1162 1110
1163 FX_POSITION FindIndex(int index) const; 1111 FX_POSITION FindIndex(int index) const;
1164 1112
1165 void RemoveAt(FX_POSITION pos); 1113 void RemoveAt(FX_POSITION pos);
1166 1114
1167 void RemoveAll(); 1115 void RemoveAll();
1168 protected: 1116 protected:
1169 1117
1170 IFX_Allocator* m_pAllocator;
1171
1172 CNode* m_pNodeHead; 1118 CNode* m_pNodeHead;
1173 1119
1174 CNode* m_pNodeTail; 1120 CNode* m_pNodeTail;
1175 1121
1176 int m_nCount; 1122 int m_nCount;
1177 1123
1178 CNode* m_pNodeFree; 1124 CNode* m_pNodeFree;
1179 1125
1180 struct CFX_Plex* m_pBlocks; 1126 struct CFX_Plex* m_pBlocks;
1181 1127
(...skipping 16 matching lines...) Expand all
1198 FX_LPVOID m_pData; 1144 FX_LPVOID m_pData;
1199 1145
1200 PD_CALLBACK_FREEDATA m_pCallback; 1146 PD_CALLBACK_FREEDATA m_pCallback;
1201 1147
1202 FX_BOOL m_bSelfDestruct; 1148 FX_BOOL m_bSelfDestruct;
1203 }; 1149 };
1204 class CFX_PrivateData 1150 class CFX_PrivateData
1205 { 1151 {
1206 public: 1152 public:
1207 1153
1208 CFX_PrivateData(IFX_Allocator* pAllocator = NULL) : m_DataList(pAllocator) { }
1209
1210 ~CFX_PrivateData(); 1154 ~CFX_PrivateData();
1211 1155
1212 void ClearAll(); 1156 void ClearAll();
1213 1157
1214 void SetPrivateData(FX_LPVOID module_ id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback); 1158 void SetPrivateData(FX_LPVOID module_ id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback);
1215 1159
1216 void SetPrivateObj(FX_LPVOID module_i d, CFX_DestructObject* pObj); 1160 void SetPrivateObj(FX_LPVOID module_i d, CFX_DestructObject* pObj);
1217 1161
1218 FX_LPVOID GetPrivateData(FX_LPVOID module_id); 1162 FX_LPVOID GetPrivateData(FX_LPVOID module_id);
1219 1163
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1432
1489 struct DataList { 1433 struct DataList {
1490 1434
1491 FX_INT32 start; 1435 FX_INT32 start;
1492 1436
1493 FX_INT32 count; 1437 FX_INT32 count;
1494 FX_LPBYTE data; 1438 FX_LPBYTE data;
1495 }; 1439 };
1496 public: 1440 public:
1497 1441
1498 CFX_SortListArray(IFX_Allocator* pAllocator = NULL) : m_CurList(0), m_DataLi sts(pAllocator) {} 1442 CFX_SortListArray() : m_CurList(0) {}
1499 1443
1500 ~CFX_SortListArray() 1444 ~CFX_SortListArray()
1501 { 1445 {
1502 Clear(); 1446 Clear();
1503 } 1447 }
1504 1448
1505 1449
1506 void Clear() 1450 void Clear()
1507 { 1451 {
1508 IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
1509 for (FX_INT32 i = m_DataLists.GetUpperBound(); i >= 0; i--) { 1452 for (FX_INT32 i = m_DataLists.GetUpperBound(); i >= 0; i--) {
1510 DataList list = m_DataLists.ElementAt(i); 1453 DataList list = m_DataLists.ElementAt(i);
1511 if (list.data) { 1454 if (list.data) {
1512 FX_Allocator_Free(pAllocator, list.data); 1455 FX_Free(list.data);
1513 } 1456 }
1514 } 1457 }
1515 m_DataLists.RemoveAll(); 1458 m_DataLists.RemoveAll();
1516 m_CurList = 0; 1459 m_CurList = 0;
1517 } 1460 }
1518 1461
1519 void Append(FX_INT32 nStart, FX_INT32 nCount) 1462 void Append(FX_INT32 nStart, FX_INT32 nCount)
1520 { 1463 {
1521 if (nStart < 0) { 1464 if (nStart < 0) {
1522 return; 1465 return;
1523 } 1466 }
1524 IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
1525 while (nCount > 0) { 1467 while (nCount > 0) {
1526 FX_INT32 temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH); 1468 FX_INT32 temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH);
1527 DataList list; 1469 DataList list;
1528 list.data = FX_Allocator_Alloc(pAllocator, FX_BYTE, temp_count * uni t); 1470 list.data = FX_Alloc(FX_BYTE, temp_count * unit);
palmer 2014/07/07 19:17:53 Potential integer overflow here. Especially since
1529 if (!list.data) { 1471 if (!list.data) {
1530 break; 1472 break;
1531 } 1473 }
1532 FXSYS_memset32(list.data, 0, temp_count * unit); 1474 FXSYS_memset32(list.data, 0, temp_count * unit);
1533 list.start = nStart; 1475 list.start = nStart;
1534 list.count = temp_count; 1476 list.count = temp_count;
1535 Append(list); 1477 Append(list);
1536 nCount -= temp_count; 1478 nCount -= temp_count;
1537 nStart += temp_count; 1479 nStart += temp_count;
1538 } 1480 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 Ready, 1575 Ready,
1634 ToBeContinued, 1576 ToBeContinued,
1635 Found, 1577 Found,
1636 NotFound, 1578 NotFound,
1637 Failed, 1579 Failed,
1638 Done 1580 Done
1639 } FX_ProgressiveStatus; 1581 } FX_ProgressiveStatus;
1640 #define ProgressiveStatus FX_ProgressiveStatus 1582 #define ProgressiveStatus FX_ProgressiveStatus
1641 #define FX_NAMESPACE_DECLARE(namespace, type) namespace::type 1583 #define FX_NAMESPACE_DECLARE(namespace, type) namespace::type
1642 #endif 1584 #endif
OLDNEW
« no previous file with comments | « no previous file | core/include/fxcrt/fx_memory.h » ('j') | core/include/fxcrt/fx_memory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698