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

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

Issue 2612773007: Remove CFX_MapPtrToPtr and templates. (Closed)
Patch Set: Created 3 years, 11 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 | « BUILD.gn ('k') | core/fxcrt/fx_basic_maps.cpp » ('j') | no next file with comments »
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 CORE_FXCRT_FX_BASIC_H_ 7 #ifndef CORE_FXCRT_FX_BASIC_H_
8 #define CORE_FXCRT_FX_BASIC_H_ 8 #define CORE_FXCRT_FX_BASIC_H_
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 328 }
329 FXSYS_memset(m_FixedData, 0, sizeof(DataType) * FixedSize); 329 FXSYS_memset(m_FixedData, 0, sizeof(DataType) * FixedSize);
330 } 330 }
331 operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; } 331 operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; }
332 332
333 private: 333 private:
334 DataType m_FixedData[FixedSize]; 334 DataType m_FixedData[FixedSize];
335 std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData; 335 std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData;
336 }; 336 };
337 337
338 #ifdef PDF_ENABLE_XFA
339 class CFX_MapPtrToPtr {
340 protected:
341 struct CAssoc {
342 CAssoc* pNext;
343 void* key;
344 void* value;
345 };
346
347 public:
348 explicit CFX_MapPtrToPtr(int nBlockSize = 10);
349 ~CFX_MapPtrToPtr();
350
351 int GetCount() const { return m_nCount; }
352 bool IsEmpty() const { return m_nCount == 0; }
353
354 bool Lookup(void* key, void*& rValue) const;
355
356 void* GetValueAt(void* key) const;
357
358 void*& operator[](void* key);
359
360 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; }
361
362 bool RemoveKey(void* key);
363
364 void RemoveAll();
365
366 FX_POSITION GetStartPosition() const {
367 return m_nCount == 0 ? nullptr : (FX_POSITION)-1;
368 }
369
370 void GetNextAssoc(FX_POSITION& rNextPosition,
371 void*& rKey,
372 void*& rValue) const;
373
374 uint32_t GetHashTableSize() const { return m_nHashTableSize; }
375
376 void InitHashTable(uint32_t hashSize, bool bAllocNow = true);
377
378 protected:
379 CAssoc** m_pHashTable;
380
381 uint32_t m_nHashTableSize;
382
383 int m_nCount;
384
385 CAssoc* m_pFreeList;
386
387 struct CFX_Plex* m_pBlocks;
388
389 int m_nBlockSize;
390
391 uint32_t HashKey(void* key) const;
392
393 CAssoc* NewAssoc();
394
395 void FreeAssoc(CAssoc* pAssoc);
396
397 CAssoc* GetAssocAt(void* key, uint32_t& hash) const;
398 };
399
400 template <class KeyType, class ValueType>
401 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
402 public:
403 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {}
404
405 bool Lookup(KeyType key, ValueType& rValue) const {
406 void* pValue = nullptr;
407 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) {
408 return false;
409 }
410 rValue = (ValueType)(uintptr_t)pValue;
411 return true;
412 }
413
414 ValueType& operator[](KeyType key) {
415 return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key);
416 }
417
418 void SetAt(KeyType key, ValueType newValue) {
419 CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue);
420 }
421
422 bool RemoveKey(KeyType key) {
423 return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key);
424 }
425
426 void GetNextAssoc(FX_POSITION& rNextPosition,
427 KeyType& rKey,
428 ValueType& rValue) const {
429 void* pKey = nullptr;
430 void* pValue = nullptr;
431 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
432 rKey = (KeyType)(uintptr_t)pKey;
433 rValue = (ValueType)(uintptr_t)pValue;
434 }
435 };
436
437 typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
438 #endif // PDF_ENABLE_XFA
439
440 class CFX_BitStream { 338 class CFX_BitStream {
441 public: 339 public:
442 void Init(const uint8_t* pData, uint32_t dwSize); 340 void Init(const uint8_t* pData, uint32_t dwSize);
443 341
444 uint32_t GetBits(uint32_t nBits); 342 uint32_t GetBits(uint32_t nBits);
445 343
446 void ByteAlign(); 344 void ByteAlign();
447 345
448 bool IsEOF() { return m_BitPos >= m_BitSize; } 346 bool IsEOF() { return m_BitPos >= m_BitSize; }
449 347
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 FX_FLOAT e; 565 FX_FLOAT e;
668 FX_FLOAT f; 566 FX_FLOAT f;
669 FX_FLOAT g; 567 FX_FLOAT g;
670 FX_FLOAT h; 568 FX_FLOAT h;
671 FX_FLOAT i; 569 FX_FLOAT i;
672 }; 570 };
673 571
674 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); 572 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits);
675 573
676 #endif // CORE_FXCRT_FX_BASIC_H_ 574 #endif // CORE_FXCRT_FX_BASIC_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/fxcrt/fx_basic_maps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698