OLD | NEW |
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_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 7 #ifndef CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
8 #define CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 8 #define CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
9 | 9 |
10 #include "core/fxcrt/include/fx_memory.h" | 10 #include "core/fxcrt/include/fx_memory.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ASSERT(offset >= 0 && nLen >= 0 && offset + nLen <= m_nAllocLength); | 78 ASSERT(offset >= 0 && nLen >= 0 && offset + nLen <= m_nAllocLength); |
79 FXSYS_memcpy(m_String + offset, pStr, nLen * sizeof(CharType)); | 79 FXSYS_memcpy(m_String + offset, pStr, nLen * sizeof(CharType)); |
80 m_String[offset + nLen] = 0; | 80 m_String[offset + nLen] = 0; |
81 } | 81 } |
82 | 82 |
83 // To ensure ref counts do not overflow, consider the worst possible case: | 83 // To ensure ref counts do not overflow, consider the worst possible case: |
84 // the entire address space contains nothing but pointers to this object. | 84 // the entire address space contains nothing but pointers to this object. |
85 // Since the count increments with each new pointer, the largest value is | 85 // Since the count increments with each new pointer, the largest value is |
86 // the number of pointers that can fit into the address space. The size of | 86 // the number of pointers that can fit into the address space. The size of |
87 // the address space itself is a good upper bound on it. | 87 // the address space itself is a good upper bound on it. |
88 intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. | 88 intptr_t m_nRefs; |
89 | 89 |
90 // |FX_STRSIZE| is currently typedef'd as |int|. | 90 // |FX_STRSIZE| is currently typedef'd as |int|. |
91 // TODO(palmer): It should be a |size_t|, or at least unsigned. | 91 // TODO(palmer): It should be a |size_t|, or at least unsigned. |
92 // These lengths are in terms of number of characters, not bytes, and do not | 92 // These lengths are in terms of number of characters, not bytes, and do not |
93 // include the terminating NUL character, but the underlying buffer is sized | 93 // include the terminating NUL character, but the underlying buffer is sized |
94 // to be capable of holding it. | 94 // to be capable of holding it. |
95 FX_STRSIZE m_nDataLength; | 95 FX_STRSIZE m_nDataLength; |
96 FX_STRSIZE m_nAllocLength; | 96 FX_STRSIZE m_nAllocLength; |
97 | 97 |
98 // Not really 1, variable size. | 98 // Not really 1, variable size. |
99 CharType m_String[1]; | 99 CharType m_String[1]; |
100 | 100 |
101 private: | 101 private: |
102 CFX_StringDataTemplate(FX_STRSIZE dataLen, FX_STRSIZE allocLen) | 102 CFX_StringDataTemplate(FX_STRSIZE dataLen, FX_STRSIZE allocLen) |
103 : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) { | 103 : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) { |
104 ASSERT(dataLen >= 0); | 104 ASSERT(dataLen >= 0); |
105 ASSERT(dataLen <= allocLen); | 105 ASSERT(dataLen <= allocLen); |
106 m_String[dataLen] = 0; | 106 m_String[dataLen] = 0; |
107 } | 107 } |
108 | 108 |
109 ~CFX_StringDataTemplate() = delete; | 109 ~CFX_StringDataTemplate() = delete; |
110 }; | 110 }; |
111 | 111 |
112 extern template class CFX_StringDataTemplate<FX_CHAR>; | 112 extern template class CFX_StringDataTemplate<FX_CHAR>; |
113 extern template class CFX_StringDataTemplate<FX_WCHAR>; | 113 extern template class CFX_StringDataTemplate<FX_WCHAR>; |
114 | 114 |
115 #endif // CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 115 #endif // CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
OLD | NEW |