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

Side by Side Diff: core/fpdfapi/parser/cpdf_array.h

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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_FPDFAPI_PARSER_CPDF_ARRAY_H_ 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
8 #define CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <type_traits>
12 #include <vector> 13 #include <vector>
13 14
14 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" 15 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
15 #include "core/fpdfapi/parser/cpdf_object.h" 16 #include "core/fpdfapi/parser/cpdf_object.h"
16 #include "core/fxcrt/fx_basic.h" 17 #include "core/fxcrt/fx_basic.h"
17 #include "core/fxcrt/fx_coordinates.h" 18 #include "core/fxcrt/fx_coordinates.h"
18 #include "third_party/base/ptr_util.h" 19 #include "third_party/base/ptr_util.h"
19 20
20 class CPDF_Array : public CPDF_Object { 21 class CPDF_Array : public CPDF_Object {
21 public: 22 public:
(...skipping 23 matching lines...) Expand all
45 FX_FLOAT GetFloatAt(size_t index) const { return GetNumberAt(index); } 46 FX_FLOAT GetFloatAt(size_t index) const { return GetNumberAt(index); }
46 CFX_Matrix GetMatrix(); 47 CFX_Matrix GetMatrix();
47 CFX_FloatRect GetRect(); 48 CFX_FloatRect GetRect();
48 49
49 // Takes ownership of |pObj|, returns unowned pointer to it. 50 // Takes ownership of |pObj|, returns unowned pointer to it.
50 CPDF_Object* Add(std::unique_ptr<CPDF_Object> pObj); 51 CPDF_Object* Add(std::unique_ptr<CPDF_Object> pObj);
51 CPDF_Object* SetAt(size_t index, std::unique_ptr<CPDF_Object> pObj); 52 CPDF_Object* SetAt(size_t index, std::unique_ptr<CPDF_Object> pObj);
52 CPDF_Object* InsertAt(size_t index, std::unique_ptr<CPDF_Object> pObj); 53 CPDF_Object* InsertAt(size_t index, std::unique_ptr<CPDF_Object> pObj);
53 54
54 // Creates object owned by the array, returns unowned pointer to it. 55 // Creates object owned by the array, returns unowned pointer to it.
56 // We have special cases for objects that can intern strings from
57 // a ByteStringPool.
55 template <typename T, typename... Args> 58 template <typename T, typename... Args>
56 T* AddNew(Args... args) { 59 typename std::enable_if<!std::is_same<T, CPDF_Name>::value, T*>::type AddNew(
Tom Sepez 2016/11/16 22:35:47 note: the return value type is nonsense if T is CP
60 Args... args) {
57 return static_cast<T*>(Add(pdfium::MakeUnique<T>(args...))); 61 return static_cast<T*>(Add(pdfium::MakeUnique<T>(args...)));
58 } 62 }
59 template <typename T, typename... Args> 63 template <typename T, typename... Args>
60 T* SetNewAt(size_t index, Args... args) { 64 typename std::enable_if<std::is_same<T, CPDF_Name>::value, T*>::type AddNew(
Tom Sepez 2016/11/16 22:35:47 Exact opposite. Inject a nullptr argument for the
65 Args... args) {
66 return static_cast<T*>(Add(pdfium::MakeUnique<T>(nullptr, args...)));
67 }
68 template <typename T, typename... Args>
69 typename std::enable_if<!std::is_same<T, CPDF_Name>::value, T*>::type
70 SetNewAt(size_t index, Args... args) {
61 return static_cast<T*>(SetAt(index, pdfium::MakeUnique<T>(args...))); 71 return static_cast<T*>(SetAt(index, pdfium::MakeUnique<T>(args...)));
62 } 72 }
63 template <typename T, typename... Args> 73 template <typename T, typename... Args>
64 T* InsertNewAt(size_t index, Args... args) { 74 typename std::enable_if<std::is_same<T, CPDF_Name>::value, T*>::type SetNewAt(
75 size_t index,
76 Args... args) {
77 return static_cast<T*>(
78 SetAt(index, pdfium::MakeUnique<T>(nullptr, args...)));
79 }
80 template <typename T, typename... Args>
81 typename std::enable_if<!std::is_same<T, CPDF_Name>::value, T*>::type
82 InsertNewAt(size_t index, Args... args) {
65 return static_cast<T*>(InsertAt(index, pdfium::MakeUnique<T>(args...))); 83 return static_cast<T*>(InsertAt(index, pdfium::MakeUnique<T>(args...)));
66 } 84 }
85 template <typename T, typename... Args>
86 typename std::enable_if<std::is_same<T, CPDF_Name>::value, T*>::type
87 InsertNewAt(size_t index, Args... args) {
88 return static_cast<T*>(
89 InsertAt(index, pdfium::MakeUnique<T>(nullptr, args...)));
90 }
67 91
68 void RemoveAt(size_t index, size_t nCount = 1); 92 void RemoveAt(size_t index, size_t nCount = 1);
69 void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc); 93 void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc);
70 94
71 const_iterator begin() const { return m_Objects.begin(); } 95 const_iterator begin() const { return m_Objects.begin(); }
72 const_iterator end() const { return m_Objects.end(); } 96 const_iterator end() const { return m_Objects.end(); }
73 97
74 protected: 98 protected:
75 std::unique_ptr<CPDF_Object> CloneNonCyclic( 99 std::unique_ptr<CPDF_Object> CloneNonCyclic(
76 bool bDirect, 100 bool bDirect,
(...skipping 12 matching lines...) Expand all
89 113
90 inline std::unique_ptr<CPDF_Array> ToArray(std::unique_ptr<CPDF_Object> obj) { 114 inline std::unique_ptr<CPDF_Array> ToArray(std::unique_ptr<CPDF_Object> obj) {
91 CPDF_Array* pArray = ToArray(obj.get()); 115 CPDF_Array* pArray = ToArray(obj.get());
92 if (!pArray) 116 if (!pArray)
93 return nullptr; 117 return nullptr;
94 obj.release(); 118 obj.release();
95 return std::unique_ptr<CPDF_Array>(pArray); 119 return std::unique_ptr<CPDF_Array>(pArray);
96 } 120 }
97 121
98 #endif // CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_ 122 #endif // CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698