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

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

Issue 2558373002: Remove last usage of CFX_ObjectArray. (Closed)
Patch Set: disallow copy and assign Created 4 years 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 | « core/fpdfapi/parser/cpdf_stream_acc.h ('k') | xfa/fxfa/app/xfa_ffapp.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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 314 }
315 return -1; 315 return -1;
316 } 316 }
317 }; 317 };
318 318
319 #ifdef PDF_ENABLE_XFA 319 #ifdef PDF_ENABLE_XFA
320 typedef CFX_ArrayTemplate<CFX_WideStringC> CFX_WideStringCArray; 320 typedef CFX_ArrayTemplate<CFX_WideStringC> CFX_WideStringCArray;
321 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray; 321 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray;
322 typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray; 322 typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray;
323 typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array; 323 typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array;
324
325 template <class ObjectClass>
326 class CFX_ObjectArray : public CFX_BasicArray {
327 public:
328 CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {}
329
330 ~CFX_ObjectArray() { RemoveAll(); }
331
332 void Add(const ObjectClass& data) {
333 new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
334 }
335
336 ObjectClass& Add() {
337 return *(ObjectClass*)new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass();
338 }
339
340 void* AddSpace() { return InsertSpaceAt(m_nSize, 1); }
341
342 int32_t Append(const CFX_ObjectArray& src,
343 int32_t nStart = 0,
344 int32_t nCount = -1) {
345 if (nCount == 0) {
346 return 0;
347 }
348 int32_t nSize = src.GetSize();
349 if (!nSize) {
350 return 0;
351 }
352 ASSERT(nStart > -1 && nStart < nSize);
353 if (nCount < 0) {
354 nCount = nSize;
355 }
356 if (nStart + nCount > nSize) {
357 nCount = nSize - nStart;
358 }
359 if (nCount < 1) {
360 return 0;
361 }
362 nSize = m_nSize;
363 InsertSpaceAt(m_nSize, nCount);
364 ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize);
365 nSize = nStart + nCount;
366 for (int32_t i = nStart; i < nSize; i++, pStartObj++) {
367 new ((void*)pStartObj) ObjectClass(src[i]);
368 }
369 return nCount;
370 }
371
372 int32_t Copy(const CFX_ObjectArray& src,
373 int32_t nStart = 0,
374 int32_t nCount = -1) {
375 if (nCount == 0) {
376 return 0;
377 }
378 int32_t nSize = src.GetSize();
379 if (!nSize) {
380 return 0;
381 }
382 ASSERT(nStart > -1 && nStart < nSize);
383 if (nCount < 0) {
384 nCount = nSize;
385 }
386 if (nStart + nCount > nSize) {
387 nCount = nSize - nStart;
388 }
389 if (nCount < 1) {
390 return 0;
391 }
392 RemoveAll();
393 SetSize(nCount);
394 ObjectClass* pStartObj = (ObjectClass*)m_pData;
395 nSize = nStart + nCount;
396 for (int32_t i = nStart; i < nSize; i++, pStartObj++) {
397 new ((void*)pStartObj) ObjectClass(src[i]);
398 }
399 return nCount;
400 }
401
402 int GetSize() const { return m_nSize; }
403
404 ObjectClass& operator[](int index) const {
405 ASSERT(index < m_nSize);
406 return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index);
407 }
408
409 ObjectClass* GetDataPtr(int index) {
410 return (ObjectClass*)CFX_BasicArray::GetDataPtr(index);
411 }
412
413 void RemoveAt(int index) {
414 ASSERT(index < m_nSize);
415 ((ObjectClass*)GetDataPtr(index))->~ObjectClass();
416 CFX_BasicArray::RemoveAt(index, 1);
417 }
418
419 void RemoveAll() {
420 for (int i = 0; i < m_nSize; i++) {
421 ((ObjectClass*)GetDataPtr(i))->~ObjectClass();
422 }
423 CFX_BasicArray::SetSize(0);
424 }
425 };
426 #endif // PDF_ENABLE_XFA 324 #endif // PDF_ENABLE_XFA
427 325
428 template <class DataType, int FixedSize> 326 template <class DataType, int FixedSize>
429 class CFX_FixedBufGrow { 327 class CFX_FixedBufGrow {
430 public: 328 public:
431 explicit CFX_FixedBufGrow(int data_size) { 329 explicit CFX_FixedBufGrow(int data_size) {
432 if (data_size > FixedSize) { 330 if (data_size > FixedSize) {
433 m_pGrowData.reset(FX_Alloc(DataType, data_size)); 331 m_pGrowData.reset(FX_Alloc(DataType, data_size));
434 return; 332 return;
435 } 333 }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 FX_FLOAT e; 744 FX_FLOAT e;
847 FX_FLOAT f; 745 FX_FLOAT f;
848 FX_FLOAT g; 746 FX_FLOAT g;
849 FX_FLOAT h; 747 FX_FLOAT h;
850 FX_FLOAT i; 748 FX_FLOAT i;
851 }; 749 };
852 750
853 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); 751 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits);
854 752
855 #endif // CORE_FXCRT_FX_BASIC_H_ 753 #endif // CORE_FXCRT_FX_BASIC_H_
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream_acc.h ('k') | xfa/fxfa/app/xfa_ffapp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698