| OLD | NEW |
| 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 #include "core/fxcrt/include/fx_basic.h" | 7 #include "core/fxcrt/include/fx_basic.h" |
| 8 #include "core/fxcrt/include/fx_ext.h" | 8 #include "core/fxcrt/include/fx_ext.h" |
| 9 | 9 |
| 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 11 #include <dirent.h> | 11 #include <dirent.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #else | 13 #else |
| 14 #include <direct.h> | 14 #include <direct.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include <cctype> | 18 #include <cctype> |
| 19 | 19 |
| 20 CFX_PrivateData::CFX_PrivateData() {} | 20 CFX_PrivateData::CFX_PrivateData() {} |
| 21 | 21 |
| 22 CFX_PrivateData::~CFX_PrivateData() { | 22 CFX_PrivateData::~CFX_PrivateData() { |
| 23 ClearAll(); | 23 ClearAll(); |
| 24 } | 24 } |
| 25 void FX_PRIVATEDATA::FreeData() { | 25 void FX_PRIVATEDATA::FreeData() { |
| 26 if (!m_pData) { | 26 if (!m_pData) { |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 if (m_bSelfDestruct) { | 29 if (m_bSelfDestruct) { |
| 30 delete (CFX_DestructObject*)m_pData; | 30 delete static_cast<CFX_Deletable*>(m_pData); |
| 31 } else if (m_pCallback) { | 31 } else if (m_pCallback) { |
| 32 m_pCallback(m_pData); | 32 m_pCallback(m_pData); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 void CFX_PrivateData::AddData(void* pModuleId, | 35 void CFX_PrivateData::AddData(void* pModuleId, |
| 36 void* pData, | 36 void* pData, |
| 37 PD_CALLBACK_FREEDATA callback, | 37 PD_CALLBACK_FREEDATA callback, |
| 38 FX_BOOL bSelfDestruct) { | 38 FX_BOOL bSelfDestruct) { |
| 39 if (!pModuleId) { | 39 if (!pModuleId) { |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 42 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 43 int count = m_DataList.GetSize(); | 43 int count = m_DataList.GetSize(); |
| 44 for (int i = 0; i < count; i++) { | 44 for (int i = 0; i < count; i++) { |
| 45 if (pList[i].m_pModuleId == pModuleId) { | 45 if (pList[i].m_pModuleId == pModuleId) { |
| 46 pList[i].FreeData(); | 46 pList[i].FreeData(); |
| 47 pList[i].m_pData = pData; | 47 pList[i].m_pData = pData; |
| 48 pList[i].m_pCallback = callback; | 48 pList[i].m_pCallback = callback; |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; | 52 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; |
| 53 m_DataList.Add(data); | 53 m_DataList.Add(data); |
| 54 } | 54 } |
| 55 void CFX_PrivateData::SetPrivateData(void* pModuleId, | 55 void CFX_PrivateData::SetPrivateData(void* pModuleId, |
| 56 void* pData, | 56 void* pData, |
| 57 PD_CALLBACK_FREEDATA callback) { | 57 PD_CALLBACK_FREEDATA callback) { |
| 58 AddData(pModuleId, pData, callback, FALSE); | 58 AddData(pModuleId, pData, callback, FALSE); |
| 59 } | 59 } |
| 60 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) { | 60 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_Deletable* pObj) { |
| 61 AddData(pModuleId, pObj, NULL, TRUE); | 61 AddData(pModuleId, pObj, NULL, TRUE); |
| 62 } | 62 } |
| 63 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { | 63 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { |
| 64 if (!pModuleId) { | 64 if (!pModuleId) { |
| 65 return FALSE; | 65 return FALSE; |
| 66 } | 66 } |
| 67 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 67 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 68 int count = m_DataList.GetSize(); | 68 int count = m_DataList.GetSize(); |
| 69 for (int i = 0; i < count; i++) { | 69 for (int i = 0; i < count; i++) { |
| 70 if (pList[i].m_pModuleId == pModuleId) { | 70 if (pList[i].m_pModuleId == pModuleId) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 dstShift -= 8; | 388 dstShift -= 8; |
| 389 result |= *dataPtr++ << dstShift; | 389 result |= *dataPtr++ << dstShift; |
| 390 } | 390 } |
| 391 if (dstShift > 0) { | 391 if (dstShift > 0) { |
| 392 bitShift = 8 - dstShift; | 392 bitShift = 8 - dstShift; |
| 393 bitMask = (1 << dstShift) - 1; | 393 bitMask = (1 << dstShift) - 1; |
| 394 result |= *dataPtr++ >> bitShift & bitMask; | 394 result |= *dataPtr++ >> bitShift & bitMask; |
| 395 } | 395 } |
| 396 return result; | 396 return result; |
| 397 } | 397 } |
| OLD | NEW |