]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layoutex/RunArrays.cpp
2 **********************************************************************
3 * Copyright (C) 2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #include "layout/LETypes.h"
9 #include "layout/LEFontInstance.h"
11 #include "unicode/locid.h"
13 #include "layout/RunArrays.h"
17 const char RunArray::fgClassID
= 0;
19 RunArray::RunArray(le_int32 initialCapacity
)
20 : fClientArrays(FALSE
), fLimits(NULL
), fCount(0), fCapacity(initialCapacity
)
22 if (initialCapacity
> 0) {
23 fLimits
= LE_NEW_ARRAY(le_int32
, fCapacity
);
29 if (! fClientArrays
) {
30 LE_DELETE_ARRAY(fLimits
);
35 le_int32
RunArray::ensureCapacity()
37 if (fCount
>= fCapacity
) {
39 fCapacity
= INITIAL_CAPACITY
;
42 fCapacity
+= (fCapacity
< CAPACITY_GROW_LIMIT
? fCapacity
: CAPACITY_GROW_LIMIT
);
50 void RunArray::init(le_int32 capacity
)
52 fLimits
= LE_NEW_ARRAY(le_int32
, capacity
);
55 void RunArray::grow(le_int32 newCapacity
)
57 fLimits
= (le_int32
*) LE_GROW_ARRAY(fLimits
, newCapacity
);
60 le_int32
RunArray::add(le_int32 limit
)
66 le_int32 index
= ensureCapacity();
67 le_int32
*limits
= (le_int32
*) fLimits
;
69 limits
[index
] = limit
;
74 const char FontRuns::fgClassID
= 0;
76 FontRuns::FontRuns(le_int32 initialCapacity
)
77 : RunArray(initialCapacity
), fFonts(NULL
)
79 if (initialCapacity
> 0) {
80 fFonts
= LE_NEW_ARRAY(const LEFontInstance
*, initialCapacity
);
86 if (! fClientArrays
) {
87 LE_DELETE_ARRAY(fFonts
);
92 void FontRuns::init(le_int32 capacity
)
94 RunArray::init(capacity
);
95 fFonts
= LE_NEW_ARRAY(const LEFontInstance
*, capacity
);
98 void FontRuns::grow(le_int32 capacity
)
100 RunArray::grow(capacity
);
101 fFonts
= (const LEFontInstance
**) LE_GROW_ARRAY(fFonts
, capacity
);
104 le_int32
FontRuns::add(const LEFontInstance
*font
, le_int32 limit
)
106 le_int32 index
= RunArray::add(limit
);
109 LEFontInstance
**fonts
= (LEFontInstance
**) fFonts
;
111 fonts
[index
] = (LEFontInstance
*) font
;
117 const LEFontInstance
*FontRuns::getFont(le_int32 run
) const
119 if (run
< 0 || run
>= getCount()) {
126 const char LocaleRuns::fgClassID
= 0;
128 LocaleRuns::LocaleRuns(le_int32 initialCapacity
)
129 : RunArray(initialCapacity
), fLocales(NULL
)
131 if (initialCapacity
> 0) {
132 fLocales
= LE_NEW_ARRAY(const Locale
*, initialCapacity
);
136 LocaleRuns::~LocaleRuns()
138 if (! fClientArrays
) {
139 LE_DELETE_ARRAY(fLocales
);
144 void LocaleRuns::init(le_int32 capacity
)
146 RunArray::init(capacity
);
147 fLocales
= LE_NEW_ARRAY(const Locale
*, capacity
);
150 void LocaleRuns::grow(le_int32 capacity
)
152 RunArray::grow(capacity
);
153 fLocales
= (const Locale
**) LE_GROW_ARRAY(fLocales
, capacity
);
156 le_int32
LocaleRuns::add(const Locale
*locale
, le_int32 limit
)
158 le_int32 index
= RunArray::add(limit
);
161 Locale
**locales
= (Locale
**) fLocales
;
163 locales
[index
] = (Locale
*) locale
;
169 const Locale
*LocaleRuns::getLocale(le_int32 run
) const
171 if (run
< 0 || run
>= getCount()) {
175 return fLocales
[run
];
178 const char ValueRuns::fgClassID
= 0;
180 ValueRuns::ValueRuns(le_int32 initialCapacity
)
181 : RunArray(initialCapacity
), fValues(NULL
)
183 if (initialCapacity
> 0) {
184 fValues
= LE_NEW_ARRAY(le_int32
, initialCapacity
);
188 ValueRuns::~ValueRuns()
190 if (! fClientArrays
) {
191 LE_DELETE_ARRAY(fValues
);
196 void ValueRuns::init(le_int32 capacity
)
198 RunArray::init(capacity
);
199 fValues
= LE_NEW_ARRAY(le_int32
, capacity
);
202 void ValueRuns::grow(le_int32 capacity
)
204 RunArray::grow(capacity
);
205 fValues
= (const le_int32
*) LE_GROW_ARRAY(fValues
, capacity
);
208 le_int32
ValueRuns::add(le_int32 value
, le_int32 limit
)
210 le_int32 index
= RunArray::add(limit
);
213 le_int32
*values
= (le_int32
*) fValues
;
215 values
[index
] = value
;
221 le_int32
ValueRuns::getValue(le_int32 run
) const
223 if (run
< 0 || run
>= getCount()) {