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/include/fxcrt/fx_basic.h" | 7 #include "core/include/fxcrt/fx_basic.h" |
8 #include "core/include/fxcrt/fx_ext.h" | 8 #include "core/include/fxcrt/fx_ext.h" |
9 | 9 |
10 #include <cctype> | 10 #include <cctype> |
11 | 11 |
12 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 12 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <dirent.h> | 14 #include <dirent.h> |
15 #else | 15 #else |
16 #include <direct.h> | 16 #include <direct.h> |
17 #endif | 17 #endif |
18 | 18 |
19 CFX_PrivateData::~CFX_PrivateData() { | 19 CFX_PrivateData::~CFX_PrivateData() { |
20 ClearAll(); | 20 ClearAll(); |
21 } | 21 } |
22 void FX_PRIVATEDATA::FreeData() { | 22 void FX_PRIVATEDATA::FreeData() { |
23 if (m_pData == NULL) { | 23 if (!m_pData) { |
24 return; | 24 return; |
25 } | 25 } |
26 if (m_bSelfDestruct) { | 26 if (m_bSelfDestruct) { |
27 delete (CFX_DestructObject*)m_pData; | 27 delete (CFX_DestructObject*)m_pData; |
28 } else if (m_pCallback) { | 28 } else if (m_pCallback) { |
29 m_pCallback(m_pData); | 29 m_pCallback(m_pData); |
30 } | 30 } |
31 } | 31 } |
32 void CFX_PrivateData::AddData(void* pModuleId, | 32 void CFX_PrivateData::AddData(void* pModuleId, |
33 void* pData, | 33 void* pData, |
34 PD_CALLBACK_FREEDATA callback, | 34 PD_CALLBACK_FREEDATA callback, |
35 FX_BOOL bSelfDestruct) { | 35 FX_BOOL bSelfDestruct) { |
36 if (pModuleId == NULL) { | 36 if (!pModuleId) { |
37 return; | 37 return; |
38 } | 38 } |
39 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 39 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
40 int count = m_DataList.GetSize(); | 40 int count = m_DataList.GetSize(); |
41 for (int i = 0; i < count; i++) { | 41 for (int i = 0; i < count; i++) { |
42 if (pList[i].m_pModuleId == pModuleId) { | 42 if (pList[i].m_pModuleId == pModuleId) { |
43 pList[i].FreeData(); | 43 pList[i].FreeData(); |
44 pList[i].m_pData = pData; | 44 pList[i].m_pData = pData; |
45 pList[i].m_pCallback = callback; | 45 pList[i].m_pCallback = callback; |
46 return; | 46 return; |
47 } | 47 } |
48 } | 48 } |
49 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; | 49 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; |
50 m_DataList.Add(data); | 50 m_DataList.Add(data); |
51 } | 51 } |
52 void CFX_PrivateData::SetPrivateData(void* pModuleId, | 52 void CFX_PrivateData::SetPrivateData(void* pModuleId, |
53 void* pData, | 53 void* pData, |
54 PD_CALLBACK_FREEDATA callback) { | 54 PD_CALLBACK_FREEDATA callback) { |
55 AddData(pModuleId, pData, callback, FALSE); | 55 AddData(pModuleId, pData, callback, FALSE); |
56 } | 56 } |
57 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) { | 57 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) { |
58 AddData(pModuleId, pObj, NULL, TRUE); | 58 AddData(pModuleId, pObj, NULL, TRUE); |
59 } | 59 } |
60 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { | 60 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { |
61 if (pModuleId == NULL) { | 61 if (!pModuleId) { |
62 return FALSE; | 62 return FALSE; |
63 } | 63 } |
64 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 64 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
65 int count = m_DataList.GetSize(); | 65 int count = m_DataList.GetSize(); |
66 for (int i = 0; i < count; i++) { | 66 for (int i = 0; i < count; i++) { |
67 if (pList[i].m_pModuleId == pModuleId) { | 67 if (pList[i].m_pModuleId == pModuleId) { |
68 m_DataList.RemoveAt(i); | 68 m_DataList.RemoveAt(i); |
69 return TRUE; | 69 return TRUE; |
70 } | 70 } |
71 } | 71 } |
72 return FALSE; | 72 return FALSE; |
73 } | 73 } |
74 void* CFX_PrivateData::GetPrivateData(void* pModuleId) { | 74 void* CFX_PrivateData::GetPrivateData(void* pModuleId) { |
75 if (pModuleId == NULL) { | 75 if (!pModuleId) { |
76 return NULL; | 76 return NULL; |
77 } | 77 } |
78 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 78 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
79 int count = m_DataList.GetSize(); | 79 int count = m_DataList.GetSize(); |
80 for (int i = 0; i < count; i++) { | 80 for (int i = 0; i < count; i++) { |
81 if (pList[i].m_pModuleId == pModuleId) { | 81 if (pList[i].m_pModuleId == pModuleId) { |
82 return pList[i].m_pData; | 82 return pList[i].m_pData; |
83 } | 83 } |
84 } | 84 } |
85 return NULL; | 85 return NULL; |
86 } | 86 } |
87 void CFX_PrivateData::ClearAll() { | 87 void CFX_PrivateData::ClearAll() { |
88 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 88 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
89 int count = m_DataList.GetSize(); | 89 int count = m_DataList.GetSize(); |
90 for (int i = 0; i < count; i++) { | 90 for (int i = 0; i < count; i++) { |
91 pList[i].FreeData(); | 91 pList[i].FreeData(); |
92 } | 92 } |
93 m_DataList.RemoveAll(); | 93 m_DataList.RemoveAll(); |
94 } | 94 } |
95 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { | 95 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { |
96 if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) { | 96 if (!FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength())) { |
97 bInteger = TRUE; | 97 bInteger = TRUE; |
98 int cc = 0, integer = 0; | 98 int cc = 0, integer = 0; |
99 const FX_CHAR* str = strc.GetCStr(); | 99 const FX_CHAR* str = strc.GetCStr(); |
100 int len = strc.GetLength(); | 100 int len = strc.GetLength(); |
101 FX_BOOL bNegative = FALSE; | 101 FX_BOOL bNegative = FALSE; |
102 if (str[0] == '+') { | 102 if (str[0] == '+') { |
103 cc++; | 103 cc++; |
104 } else if (str[0] == '-') { | 104 } else if (str[0] == '-') { |
105 bNegative = TRUE; | 105 bNegative = TRUE; |
106 cc++; | 106 cc++; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 pData->m_bEnd = FALSE; | 250 pData->m_bEnd = FALSE; |
251 return pData; | 251 return pData; |
252 #else | 252 #else |
253 DIR* dir = opendir(CFX_ByteString::FromUnicode(path)); | 253 DIR* dir = opendir(CFX_ByteString::FromUnicode(path)); |
254 return dir; | 254 return dir; |
255 #endif | 255 #endif |
256 } | 256 } |
257 FX_BOOL FX_GetNextFile(void* handle, | 257 FX_BOOL FX_GetNextFile(void* handle, |
258 CFX_ByteString& filename, | 258 CFX_ByteString& filename, |
259 FX_BOOL& bFolder) { | 259 FX_BOOL& bFolder) { |
260 if (handle == NULL) { | 260 if (!handle) { |
261 return FALSE; | 261 return FALSE; |
262 } | 262 } |
263 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 263 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
264 #ifndef _WIN32_WCE | 264 #ifndef _WIN32_WCE |
265 CFindFileDataA* pData = (CFindFileDataA*)handle; | 265 CFindFileDataA* pData = (CFindFileDataA*)handle; |
266 if (pData->m_bEnd) { | 266 if (pData->m_bEnd) { |
267 return FALSE; | 267 return FALSE; |
268 } | 268 } |
269 filename = pData->m_FindData.cFileName; | 269 filename = pData->m_FindData.cFileName; |
270 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 270 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
(...skipping 11 matching lines...) Expand all Loading... |
282 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | 282 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { |
283 pData->m_bEnd = TRUE; | 283 pData->m_bEnd = TRUE; |
284 } | 284 } |
285 return TRUE; | 285 return TRUE; |
286 #endif | 286 #endif |
287 #elif defined(__native_client__) | 287 #elif defined(__native_client__) |
288 abort(); | 288 abort(); |
289 return FALSE; | 289 return FALSE; |
290 #else | 290 #else |
291 struct dirent* de = readdir((DIR*)handle); | 291 struct dirent* de = readdir((DIR*)handle); |
292 if (de == NULL) { | 292 if (!de) { |
293 return FALSE; | 293 return FALSE; |
294 } | 294 } |
295 filename = de->d_name; | 295 filename = de->d_name; |
296 bFolder = de->d_type == DT_DIR; | 296 bFolder = de->d_type == DT_DIR; |
297 return TRUE; | 297 return TRUE; |
298 #endif | 298 #endif |
299 } | 299 } |
300 FX_BOOL FX_GetNextFile(void* handle, | 300 FX_BOOL FX_GetNextFile(void* handle, |
301 CFX_WideString& filename, | 301 CFX_WideString& filename, |
302 FX_BOOL& bFolder) { | 302 FX_BOOL& bFolder) { |
303 if (handle == NULL) { | 303 if (!handle) { |
304 return FALSE; | 304 return FALSE; |
305 } | 305 } |
306 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 306 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
307 CFindFileDataW* pData = (CFindFileDataW*)handle; | 307 CFindFileDataW* pData = (CFindFileDataW*)handle; |
308 if (pData->m_bEnd) { | 308 if (pData->m_bEnd) { |
309 return FALSE; | 309 return FALSE; |
310 } | 310 } |
311 filename = pData->m_FindData.cFileName; | 311 filename = pData->m_FindData.cFileName; |
312 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 312 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
313 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | 313 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { |
314 pData->m_bEnd = TRUE; | 314 pData->m_bEnd = TRUE; |
315 } | 315 } |
316 return TRUE; | 316 return TRUE; |
317 #elif defined(__native_client__) | 317 #elif defined(__native_client__) |
318 abort(); | 318 abort(); |
319 return FALSE; | 319 return FALSE; |
320 #else | 320 #else |
321 struct dirent* de = readdir((DIR*)handle); | 321 struct dirent* de = readdir((DIR*)handle); |
322 if (de == NULL) { | 322 if (!de) { |
323 return FALSE; | 323 return FALSE; |
324 } | 324 } |
325 filename = CFX_WideString::FromLocal(de->d_name); | 325 filename = CFX_WideString::FromLocal(de->d_name); |
326 bFolder = de->d_type == DT_DIR; | 326 bFolder = de->d_type == DT_DIR; |
327 return TRUE; | 327 return TRUE; |
328 #endif | 328 #endif |
329 } | 329 } |
330 void FX_CloseFolder(void* handle) { | 330 void FX_CloseFolder(void* handle) { |
331 if (handle == NULL) { | 331 if (!handle) { |
332 return; | 332 return; |
333 } | 333 } |
334 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 334 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
335 CFindFileData* pData = (CFindFileData*)handle; | 335 CFindFileData* pData = (CFindFileData*)handle; |
336 FindClose(pData->m_Handle); | 336 FindClose(pData->m_Handle); |
337 delete pData; | 337 delete pData; |
338 #else | 338 #else |
339 closedir((DIR*)handle); | 339 closedir((DIR*)handle); |
340 #endif | 340 #endif |
341 } | 341 } |
(...skipping 24 matching lines...) Expand all Loading... |
366 d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i, | 366 d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i, |
367 g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h, | 367 g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h, |
368 g * m.c + h * m.f + i * m.i); | 368 g * m.c + h * m.f + i * m.i); |
369 } | 369 } |
370 | 370 |
371 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) { | 371 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) { |
372 return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c, | 372 return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c, |
373 d * v.a + e * v.b + f * v.c, | 373 d * v.a + e * v.b + f * v.c, |
374 g * v.a + h * v.b + i * v.c); | 374 g * v.a + h * v.b + i * v.c); |
375 } | 375 } |
OLD | NEW |