]> git.saurik.com Git - apple/icu.git/blame - icuSources/layoutex/RunArrays.cpp
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / layoutex / RunArrays.cpp
CommitLineData
b75a7d8f
A
1/*
2 **********************************************************************
3 * Copyright (C) 2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7
8#include "layout/LETypes.h"
9#include "layout/LEFontInstance.h"
10
11#include "unicode/locid.h"
12
13#include "layout/RunArrays.h"
14
15U_NAMESPACE_BEGIN
16
17const char RunArray::fgClassID = 0;
18
374ca955
A
19RunArray::RunArray(le_int32 initialCapacity)
20 : fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(initialCapacity)
21{
22 if (initialCapacity > 0) {
23 fLimits = LE_NEW_ARRAY(le_int32, fCapacity);
24 }
25}
26
27RunArray::~RunArray()
28{
29 if (! fClientArrays) {
30 LE_DELETE_ARRAY(fLimits);
31 fLimits = NULL;
32 }
33}
34
b75a7d8f
A
35le_int32 RunArray::ensureCapacity()
36{
37 if (fCount >= fCapacity) {
38 if (fCapacity == 0) {
39 fCapacity = INITIAL_CAPACITY;
40 init(fCapacity);
41 } else {
42 fCapacity += (fCapacity < CAPACITY_GROW_LIMIT ? fCapacity : CAPACITY_GROW_LIMIT);
43 grow(fCapacity);
44 }
45 }
46
47 return fCount++;
48}
49
50void RunArray::init(le_int32 capacity)
51{
52 fLimits = LE_NEW_ARRAY(le_int32, capacity);
53}
54
55void RunArray::grow(le_int32 newCapacity)
56{
57 fLimits = (le_int32 *) LE_GROW_ARRAY(fLimits, newCapacity);
58}
59
60le_int32 RunArray::add(le_int32 limit)
61{
62 if (fClientArrays) {
63 return -1;
64 }
65
66 le_int32 index = ensureCapacity();
67 le_int32 *limits = (le_int32 *) fLimits;
68
69 limits[index] = limit;
70
71 return index;
72}
73
74const char FontRuns::fgClassID = 0;
75
374ca955
A
76FontRuns::FontRuns(le_int32 initialCapacity)
77 : RunArray(initialCapacity), fFonts(NULL)
78{
79 if (initialCapacity > 0) {
80 fFonts = LE_NEW_ARRAY(const LEFontInstance *, initialCapacity);
81 }
82}
83
84FontRuns::~FontRuns()
85{
86 if (! fClientArrays) {
87 LE_DELETE_ARRAY(fFonts);
88 fFonts = NULL;
89 }
90}
91
b75a7d8f
A
92void FontRuns::init(le_int32 capacity)
93{
94 RunArray::init(capacity);
95 fFonts = LE_NEW_ARRAY(const LEFontInstance *, capacity);
96}
97
98void FontRuns::grow(le_int32 capacity)
99{
100 RunArray::grow(capacity);
101 fFonts = (const LEFontInstance **) LE_GROW_ARRAY(fFonts, capacity);
102}
103
104le_int32 FontRuns::add(const LEFontInstance *font, le_int32 limit)
105{
106 le_int32 index = RunArray::add(limit);
107
108 if (index >= 0) {
109 LEFontInstance **fonts = (LEFontInstance **) fFonts;
110
111 fonts[index] = (LEFontInstance *) font;
112 }
113
114 return index;
115}
116
117const LEFontInstance *FontRuns::getFont(le_int32 run) const
118{
119 if (run < 0 || run >= getCount()) {
120 return NULL;
121 }
122
123 return fFonts[run];
124}
125
126const char LocaleRuns::fgClassID = 0;
127
374ca955
A
128LocaleRuns::LocaleRuns(le_int32 initialCapacity)
129 : RunArray(initialCapacity), fLocales(NULL)
130{
131 if (initialCapacity > 0) {
132 fLocales = LE_NEW_ARRAY(const Locale *, initialCapacity);
133 }
134}
135
136LocaleRuns::~LocaleRuns()
137{
138 if (! fClientArrays) {
139 LE_DELETE_ARRAY(fLocales);
140 fLocales = NULL;
141 }
142}
143
b75a7d8f
A
144void LocaleRuns::init(le_int32 capacity)
145{
146 RunArray::init(capacity);
147 fLocales = LE_NEW_ARRAY(const Locale *, capacity);
148}
149
150void LocaleRuns::grow(le_int32 capacity)
151{
152 RunArray::grow(capacity);
153 fLocales = (const Locale **) LE_GROW_ARRAY(fLocales, capacity);
154}
155
156le_int32 LocaleRuns::add(const Locale *locale, le_int32 limit)
157{
158 le_int32 index = RunArray::add(limit);
159
160 if (index >= 0) {
161 Locale **locales = (Locale **) fLocales;
162
163 locales[index] = (Locale *) locale;
164 }
165
166 return index;
167}
168
169const Locale *LocaleRuns::getLocale(le_int32 run) const
170{
171 if (run < 0 || run >= getCount()) {
172 return NULL;
173 }
174
175 return fLocales[run];
176}
177
178const char ValueRuns::fgClassID = 0;
179
374ca955
A
180ValueRuns::ValueRuns(le_int32 initialCapacity)
181 : RunArray(initialCapacity), fValues(NULL)
182{
183 if (initialCapacity > 0) {
184 fValues = LE_NEW_ARRAY(le_int32, initialCapacity);
185 }
186}
187
188ValueRuns::~ValueRuns()
189{
190 if (! fClientArrays) {
191 LE_DELETE_ARRAY(fValues);
192 fValues = NULL;
193 }
194}
195
b75a7d8f
A
196void ValueRuns::init(le_int32 capacity)
197{
198 RunArray::init(capacity);
199 fValues = LE_NEW_ARRAY(le_int32, capacity);
200}
201
202void ValueRuns::grow(le_int32 capacity)
203{
204 RunArray::grow(capacity);
205 fValues = (const le_int32 *) LE_GROW_ARRAY(fValues, capacity);
206}
207
208le_int32 ValueRuns::add(le_int32 value, le_int32 limit)
209{
210 le_int32 index = RunArray::add(limit);
211
212 if (index >= 0) {
213 le_int32 *values = (le_int32 *) fValues;
214
215 values[index] = value;
216 }
217
218 return index;
219}
220
221le_int32 ValueRuns::getValue(le_int32 run) const
222{
223 if (run < 0 || run >= getCount()) {
224 return -1;
225 }
226
227 return fValues[run];
228}
229
230U_NAMESPACE_END