OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 // Original code is licensed as follows: | |
7 /* | |
8 * Copyright 2008 ZXing authors | |
9 * | |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | |
11 * you may not use this file except in compliance with the License. | |
12 * You may obtain a copy of the License at | |
13 * | |
14 * http://www.apache.org/licenses/LICENSE-2.0 | |
15 * | |
16 * Unless required by applicable law or agreed to in writing, software | |
17 * distributed under the License is distributed on an "AS IS" BASIS, | |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 * See the License for the specific language governing permissions and | |
20 * limitations under the License. | |
21 */ | |
22 | |
23 #include "barcode.h" | |
24 #include "include/BC_CommonByteArray.h" | |
25 CBC_CommonByteArray::CBC_CommonByteArray() | |
26 { | |
27 m_bytes = NULL; | |
28 m_size = 0; | |
29 m_index = 0; | |
30 } | |
31 CBC_CommonByteArray::CBC_CommonByteArray(FX_INT32 size) | |
32 { | |
33 m_size = size; | |
34 m_bytes = FX_Alloc(FX_BYTE, size); | |
35 FXSYS_memset32(m_bytes, 0, size); | |
36 m_index = 0; | |
37 } | |
38 CBC_CommonByteArray::CBC_CommonByteArray(FX_BYTE* byteArray, FX_INT32 size) | |
39 { | |
40 m_size = size; | |
41 m_bytes = FX_Alloc(FX_BYTE, size); | |
42 FXSYS_memcpy32(m_bytes, byteArray, size); | |
43 m_index = size; | |
44 } | |
45 CBC_CommonByteArray::~CBC_CommonByteArray() | |
46 { | |
47 if ( m_bytes != NULL) { | |
48 FX_Free( m_bytes ); | |
49 m_bytes = NULL; | |
50 } | |
51 m_index = 0; | |
52 m_size = 0; | |
53 } | |
54 FX_INT32 CBC_CommonByteArray::At(FX_INT32 index) | |
55 { | |
56 return m_bytes[index] & 0xff; | |
57 } | |
58 void CBC_CommonByteArray::Set(FX_INT32 index, FX_INT32 value) | |
59 { | |
60 m_bytes[index] = (FX_BYTE) value; | |
61 } | |
62 FX_INT32 CBC_CommonByteArray::Size() | |
63 { | |
64 return m_size; | |
65 } | |
66 FX_BOOL CBC_CommonByteArray::IsEmpty() | |
67 { | |
68 return m_size == 0; | |
69 } | |
70 void CBC_CommonByteArray::AppendByte(FX_INT32 value) | |
71 { | |
72 if (m_size == 0 || m_index >= m_size) { | |
73 FX_INT32 newSize = FX_MAX(32, m_size << 1); | |
74 Reserve(newSize); | |
75 } | |
76 m_bytes[m_index] = (FX_BYTE)value; | |
77 m_index++; | |
78 } | |
79 void CBC_CommonByteArray::Reserve(FX_INT32 capacity) | |
80 { | |
81 if (m_bytes == NULL || m_size < capacity) { | |
82 FX_BYTE *newArray = FX_Alloc(FX_BYTE, capacity); | |
83 FXSYS_memset32(newArray, 0, capacity); | |
84 if (m_bytes != NULL) { | |
85 FXSYS_memcpy32(newArray, m_bytes, m_size); | |
86 FX_Free( m_bytes ); | |
87 } | |
88 m_bytes = newArray; | |
89 m_size = capacity; | |
90 } | |
91 } | |
92 void CBC_CommonByteArray::Set(FX_BYTE* source, FX_INT32 offset, FX_INT32 count) | |
93 { | |
94 if (m_bytes != NULL) { | |
95 FX_Free( m_bytes ); | |
96 } | |
97 m_bytes = FX_Alloc(FX_BYTE, count); | |
98 m_size = count; | |
99 FXSYS_memcpy32(m_bytes, source + offset, count); | |
100 m_index = count; | |
101 } | |
102 void CBC_CommonByteArray::Set(CFX_ByteArray* source, FX_INT32 offset, FX_INT32 c
ount) | |
103 { | |
104 if (m_bytes != NULL) { | |
105 FX_Free( m_bytes ); | |
106 } | |
107 m_bytes = FX_Alloc(FX_BYTE, count); | |
108 m_size = count; | |
109 FX_INT32 i; | |
110 for(i = 0; i < count; i++) { | |
111 m_bytes[i] = source->operator [](i + offset); | |
112 } | |
113 m_index = m_size; | |
114 } | |
OLD | NEW |