• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_CFX_FIXEDBUFGROW_H_
8 #define CORE_FXCRT_CFX_FIXEDBUFGROW_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_memory.h"
13 
14 template <class DataType, int FixedSize>
15 class CFX_FixedBufGrow {
16  public:
CFX_FixedBufGrow(int data_size)17   explicit CFX_FixedBufGrow(int data_size) {
18     if (data_size > FixedSize) {
19       m_pGrowData.reset(FX_Alloc(DataType, data_size));
20       return;
21     }
22     memset(m_FixedData, 0, sizeof(DataType) * FixedSize);
23   }
24   operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; }
25 
26  private:
27   DataType m_FixedData[FixedSize];
28   std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData;
29 };
30 
31 #endif  // CORE_FXCRT_CFX_FIXEDBUFGROW_H_
32