]> git.saurik.com Git - apple/icu.git/blob - icuSources/layoutex/layout/RunArrays.h
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / layoutex / layout / RunArrays.h
1 /*
2 **********************************************************************
3 * Copyright (C) 2003-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7
8 #ifndef __RUNARRAYS_H
9
10 #define __RUNARRAYS_H
11
12 #include "layout/LETypes.h"
13 #include "layout/LEFontInstance.h"
14
15 #include "unicode/utypes.h"
16 #include "unicode/locid.h"
17
18 U_NAMESPACE_BEGIN
19
20 /**
21 * The initial size of an array if it is unspecified.
22 *
23 * @draft ICU 2.6
24 */
25 #define INITIAL_CAPACITY 16
26
27 /**
28 * When an array needs to grow, it will double in size until
29 * it becomes this large, then it will grow by this amount.
30 *
31 * @draft ICU 2.6
32 */
33 #define CAPACITY_GROW_LIMIT 128
34
35 /**
36 * The <code>RunArray</code> class is a base class for building classes
37 * which represent data that is associated with runs of text. This class
38 * maintains an array of limit indices into the text, subclasses
39 * provide one or more arrays of data.
40 *
41 * @draft ICU 2.6
42 */
43 class U_LAYOUTEX_API RunArray : public UObject
44 {
45 public:
46 /**
47 * Construct a <code>RunArray</code> object from a pre-existing
48 * array of limit indices.
49 *
50 * @param limits is an array of limit indices. This array must remain
51 * valid until the <code>RunArray</code> object is destroyed.
52 *
53 * @param count is the number of entries in the limit array.
54 *
55 * @draft ICU 2.6
56 */
57 RunArray(const le_int32 *limits, le_int32 count);
58
59 /**
60 * Construct an empty <code>RunArray</code> object. Clients can add limit
61 * indices array using the <code>add</code> method.
62 *
63 * @param initialCapacity is the initial size of the limit indices array. If
64 * this value is zero, no array will be allocated.
65 *
66 * @see add
67 *
68 * @draft ICU 2.6
69 */
70 RunArray(le_int32 initialCapacity);
71
72 /**
73 * The destructor; virtual so that subclass destructors are invoked as well.
74 *
75 * @draft ICU 2.6
76 */
77 virtual ~RunArray();
78
79 /**
80 * Get the number of entries in the limit indices array.
81 *
82 * @return the number of entries in the limit indices array.
83 *
84 * @draft ICU 2.6
85 */
86 le_int32 getCount() const;
87
88 /**
89 * Get the last limit index. This is the number of characters in
90 * the text.
91 *
92 * @return the last limit index.
93 *
94 * @draft ICU 2.6
95 */
96 le_int32 getLimit() const;
97
98 /**
99 * Get the limit index for a particular run of text.
100 *
101 * @param run is the run. This is an index into the limit index array.
102 *
103 * @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
104 *
105 * @draft ICU 2.6
106 */
107 le_int32 getLimit(le_int32 run) const;
108
109 /**
110 * Add a limit index to the limit indices array and return the run index
111 * where it was stored. If the array does not exist, it will be created by
112 * calling the <code>init</code> method. If it is full, it will be grown by
113 * calling the <code>grow</code> method.
114 *
115 * If the <code>RunArray</code> object was created with a client-supplied
116 * limit indices array, this method will return a run index of -1.
117 *
118 * Subclasses should not override this method. Rather they should provide
119 * a new <code>add</code> method which takes a limit index along with whatever
120 * other data they implement. The new <code>add</code> method should
121 * first call this method to grow the data arrays, and use the return value
122 * to store the data in their own arrays.
123 *
124 * @param limit is the limit index to add to the array.
125 *
126 * @return the run index where the limit index was stored, or -1 if the limit index cannt be stored.
127 *
128 * @see init
129 * @see grow
130 *
131 * @draft ICU 2.6
132 */
133 le_int32 add(le_int32 limit);
134
135 /**
136 * ICU "poor man's RTTI", returns a UClassID for the actual class.
137 *
138 * @draft ICU 2.6
139 */
140 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
141
142 /**
143 * ICU "poor man's RTTI", returns a UClassID for this class.
144 *
145 * @draft ICU 2.6
146 */
147 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
148
149 protected:
150 /**
151 * Create a data array with the given initial size. This method will be
152 * called by the <code>add</code> method if there is no limit indices
153 * array. Subclasses which override this method must also call it from
154 * the overriding method to create the limit indices array.
155 *
156 * @param capacity is the initial size of the data array.
157 *
158 * @see add
159 *
160 * @draft ICU 2.6
161 */
162 virtual void init(le_int32 capacity);
163
164 /**
165 * Grow a data array to the given initial size. This method will be
166 * called by the <code>add</code> method if the limit indices
167 * array is full. Subclasses which override this method must also call it from
168 * the overriding method to grow the limit indices array.
169 *
170 * @param capacity is the initial size of the data array.
171 *
172 * @see add
173 *
174 * @draft ICU 2.6
175 */
176 virtual void grow(le_int32 capacity);
177
178 /**
179 * Set by the constructors to indicate whether
180 * or not the client supplied the data arrays.
181 * If they were supplied by the client, the
182 * <code>add</code> method won't change the arrays
183 * and the destructor won't delete them.
184 *
185 * @draft ICU 2.6
186 */
187 le_bool fClientArrays;
188
189 private:
190 /**
191 * The address of this static class variable serves as this class's ID
192 * for ICU "poor man's RTTI".
193 */
194 static const char fgClassID;
195
196 le_int32 ensureCapacity();
197
198 RunArray();
199 RunArray(const RunArray & /*other*/);
200 RunArray &operator=(const RunArray & /*other*/) { return *this; };
201
202 const le_int32 *fLimits;
203 le_int32 fCount;
204 le_int32 fCapacity;
205 };
206
207 inline RunArray::RunArray()
208 : UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0)
209 {
210 // nothing else to do...
211 }
212
213 inline RunArray::RunArray(const RunArray & /*other*/)
214 : UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0)
215 {
216 // nothing else to do...
217 }
218
219 inline RunArray::RunArray(const le_int32 *limits, le_int32 count)
220 : UObject(), fClientArrays(TRUE), fLimits(limits), fCount(count), fCapacity(count)
221 {
222 // nothing else to do...
223 }
224
225 inline le_int32 RunArray::getCount() const
226 {
227 return fCount;
228 }
229
230 inline le_int32 RunArray::getLimit(le_int32 run) const
231 {
232 if (run < 0 || run >= fCount) {
233 return -1;
234 }
235
236 return fLimits[run];
237 }
238
239 inline le_int32 RunArray::getLimit() const
240 {
241 return getLimit(fCount - 1);
242 }
243
244 /**
245 * The <code>FontRuns</code> class associates pointers to <code>LEFontInstance</code>
246 * objects with runs of text.
247 *
248 * @draft ICU 2.6
249 */
250 class U_LAYOUTEX_API FontRuns : public RunArray
251 {
252 public:
253 /**
254 * Construct a <code>FontRuns</code> object from pre-existing arrays of fonts
255 * and limit indices.
256 *
257 * @param fonts is the address of an array of pointers to <code>LEFontInstance</code> objects. This
258 * array, and the <code>LEFontInstance</code> objects to which it points must remain
259 * valid until the <code>FontRuns</code> object is destroyed.
260 *
261 * @param limits is the address of an array of limit indices. This array must remain valid until
262 * the <code>FontRuns</code> object is destroyed.
263 *
264 * @param count is the number of entries in the two arrays.
265 *
266 * @draft ICU 2.6
267 */
268 FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count);
269
270 /**
271 * Construct an empty <code>FontRuns</code> object. Clients can add font and limit
272 * indices arrays using the <code>add</code> method.
273 *
274 * @param initialCapacity is the initial size of the font and limit indices arrays. If
275 * this value is zero, no arrays will be allocated.
276 *
277 * @see add
278 *
279 * @draft ICU 2.6
280 */
281 FontRuns(le_int32 initialCapacity);
282
283 /**
284 * The destructor; virtual so that subclass destructors are invoked as well.
285 *
286 * @draft ICU 2.6
287 */
288 virtual ~FontRuns();
289
290 /**
291 * Get the <code>LEFontInstance</code> object assoicated with the given run
292 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
293 * limit index.
294 *
295 * @param run is the index into the font and limit indices arrays.
296 *
297 * @return the <code>LEFontInstance</code> associated with the given text run.
298 *
299 * @see RunArray::getLimit
300 *
301 * @draft ICU 2.6
302 */
303 const LEFontInstance *getFont(le_int32 run) const;
304
305
306 /**
307 * Add an <code>LEFontInstance</code> and limit index pair to the data arrays and return
308 * the run index where the data was stored. This method calls
309 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
310 *
311 * If the <code>FontRuns</code> object was created with a client-supplied
312 * font and limit indices arrays, this method will return a run index of -1.
313 *
314 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
315 * method which takes a font and a limit index along with whatever other data they implement.
316 * The new <code>add</code> method should first call this method to grow the font and limit indices
317 * arrays, and use the returned run index to store data their own arrays.
318 *
319 * @param font is the address of the <code>LEFontInstance</code> to add. This object must
320 * remain valid until the <code>FontRuns</code> object is destroyed.
321 *
322 * @param limit is the limit index to add
323 *
324 * @return the run index where the font and limit index were stored, or -1 if the data cannot be stored.
325 *
326 * @draft ICU 2.6
327 */
328 le_int32 add(const LEFontInstance *font, le_int32 limit);
329
330 /**
331 * ICU "poor man's RTTI", returns a UClassID for the actual class.
332 *
333 * @draft ICU 2.6
334 */
335 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
336
337 /**
338 * ICU "poor man's RTTI", returns a UClassID for this class.
339 *
340 * @draft ICU 2.6
341 */
342 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
343
344 protected:
345 virtual void init(le_int32 capacity);
346 virtual void grow(le_int32 capacity);
347
348 private:
349
350 FontRuns();
351 FontRuns(const FontRuns &other);
352 FontRuns &operator=(const FontRuns & /*other*/) { return *this; };
353
354 /**
355 * The address of this static class variable serves as this class's ID
356 * for ICU "poor man's RTTI".
357 */
358 static const char fgClassID;
359
360 const LEFontInstance **fFonts;
361 };
362
363 inline FontRuns::FontRuns()
364 : RunArray(0), fFonts(NULL)
365 {
366 // nothing else to do...
367 }
368
369 inline FontRuns::FontRuns(const FontRuns & /*other*/)
370 : RunArray(0), fFonts(NULL)
371 {
372 // nothing else to do...
373 }
374
375 inline FontRuns::FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count)
376 : RunArray(limits, count), fFonts(fonts)
377 {
378 // nothing else to do...
379 }
380
381 /**
382 * The <code>LocaleRuns</code> class associates pointers to <code>Locale</code>
383 * objects with runs of text.
384 *
385 * @draft ICU 2.6
386 */
387 class U_LAYOUTEX_API LocaleRuns : public RunArray
388 {
389 public:
390 /**
391 * Construct a <code>LocaleRuns</code> object from pre-existing arrays of locales
392 * and limit indices.
393 *
394 * @param locales is the address of an array of pointers to <code>Locale</code> objects. This array,
395 * and the <code>Locale</code> objects to which it points, must remain valid until
396 * the <code>LocaleRuns</code> object is destroyed.
397 *
398 * @param limits is the address of an array of limit indices. This array must remain valid until the
399 * <code>LocaleRuns</code> object is destroyed.
400 *
401 * @param count is the number of entries in the two arrays.
402 *
403 * @draft ICU 2.6
404 */
405 LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count);
406
407 /**
408 * Construct an empty <code>LocaleRuns</code> object. Clients can add locale and limit
409 * indices arrays using the <code>add</code> method.
410 *
411 * @param initialCapacity is the initial size of the locale and limit indices arrays. If
412 * this value is zero, no arrays will be allocated.
413 *
414 * @see add
415 *
416 * @draft ICU 2.6
417 */
418 LocaleRuns(le_int32 initialCapacity);
419
420 /**
421 * The destructor; virtual so that subclass destructors are invoked as well.
422 *
423 * @draft ICU 2.6
424 */
425 virtual ~LocaleRuns();
426
427 /**
428 * Get the <code>Locale</code> object assoicated with the given run
429 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
430 * limit index.
431 *
432 * @param run is the index into the font and limit indices arrays.
433 *
434 * @return the <code>Locale</code> associated with the given text run.
435 *
436 * @see RunArray::getLimit
437 *
438 * @draft ICU 2.6
439 */
440 const Locale *getLocale(le_int32 run) const;
441
442
443 /**
444 * Add a <code>Locale</code> and limit index pair to the data arrays and return
445 * the run index where the data was stored. This method calls
446 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
447 *
448 * If the <code>LocaleRuns</code> object was created with a client-supplied
449 * locale and limit indices arrays, this method will return a run index of -1.
450 *
451 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
452 * method which takes a locale and a limit index along with whatever other data they implement.
453 * The new <code>add</code> method should first call this method to grow the font and limit indices
454 * arrays, and use the returned run index to store data their own arrays.
455 *
456 * @param locale is the address of the <code>Locale</code> to add. This object must remain valid
457 * until the <code>LocaleRuns</code> object is destroyed.
458 *
459 * @param limit is the limit index to add
460 *
461 * @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored.
462 *
463 * @draft ICU 2.6
464 */
465 le_int32 add(const Locale *locale, le_int32 limit);
466
467 /**
468 * ICU "poor man's RTTI", returns a UClassID for the actual class.
469 *
470 * @draft ICU 2.6
471 */
472 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
473
474 /**
475 * ICU "poor man's RTTI", returns a UClassID for this class.
476 *
477 * @draft ICU 2.6
478 */
479 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
480
481 protected:
482 virtual void init(le_int32 capacity);
483 virtual void grow(le_int32 capacity);
484
485 private:
486
487 LocaleRuns();
488 LocaleRuns(const LocaleRuns &other);
489 LocaleRuns &operator=(const LocaleRuns & /*other*/) { return *this; };
490
491 /**
492 * The address of this static class variable serves as this class's ID
493 * for ICU "poor man's RTTI".
494 */
495 static const char fgClassID;
496
497 const Locale **fLocales;
498 };
499
500 inline LocaleRuns::LocaleRuns()
501 : RunArray(0), fLocales(NULL)
502 {
503 // nothing else to do...
504 }
505
506 inline LocaleRuns::LocaleRuns(const LocaleRuns & /*other*/)
507 : RunArray(0), fLocales(NULL)
508 {
509 // nothing else to do...
510 }
511
512 inline LocaleRuns::LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count)
513 : RunArray(limits, count), fLocales(locales)
514 {
515 // nothing else to do...
516 }
517
518 /**
519 * The <code>ValueRuns</code> class associates integer values with runs of text.
520 *
521 * @draft ICU 2.6
522 */
523 class U_LAYOUTEX_API ValueRuns : public RunArray
524 {
525 public:
526 /**
527 * Construct a <code>ValueRuns</code> object from pre-existing arrays of values
528 * and limit indices.
529 *
530 * @param values is the address of an array of integer. This array must remain valid until
531 * the <code>ValueRuns</code> object is destroyed.
532 *
533 * @param limits is the address of an array of limit indices. This array must remain valid until
534 * the <code>ValueRuns</code> object is destroyed.
535 *
536 * @param count is the number of entries in the two arrays.
537 *
538 * @draft ICU 2.6
539 */
540 ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count);
541
542 /**
543 * Construct an empty <code>ValueRuns</code> object. Clients can add value and limit
544 * indices arrays using the <code>add</code> method.
545 *
546 * @param initialCapacity is the initial size of the value and limit indices arrays. If
547 * this value is zero, no arrays will be allocated.
548 *
549 * @see add
550 *
551 * @draft ICU 2.6
552 */
553 ValueRuns(le_int32 initialCapacity);
554
555 /**
556 * The destructor; virtual so that subclass destructors are invoked as well.
557 *
558 * @draft ICU 2.6
559 */
560 virtual ~ValueRuns();
561
562 /**
563 * Get the integer value assoicated with the given run
564 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
565 * limit index.
566 *
567 * @param run is the index into the font and limit indices arrays.
568 *
569 * @return the integer value associated with the given text run.
570 *
571 * @see RunArray::getLimit
572 *
573 * @draft ICU 2.6
574 */
575 le_int32 getValue(le_int32 run) const;
576
577
578 /**
579 * Add an integer value and limit index pair to the data arrays and return
580 * the run index where the data was stored. This method calls
581 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
582 *
583 * If the <code>ValueRuns</code> object was created with a client-supplied
584 * font and limit indices arrays, this method will return a run index of -1.
585 *
586 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
587 * method which takes an integer value and a limit index along with whatever other data they implement.
588 * The new <code>add</code> method should first call this method to grow the font and limit indices
589 * arrays, and use the returned run index to store data their own arrays.
590 *
591 * @param value is the integer value to add
592 *
593 * @param limit is the limit index to add
594 *
595 * @return the run index where the value and limit index were stored, or -1 if the data cannot be stored.
596 *
597 * @draft ICU 2.6
598 */
599 le_int32 add(le_int32 value, le_int32 limit);
600
601 /**
602 * ICU "poor man's RTTI", returns a UClassID for the actual class.
603 *
604 * @draft ICU 2.6
605 */
606 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
607
608 /**
609 * ICU "poor man's RTTI", returns a UClassID for this class.
610 *
611 * @draft ICU 2.6
612 */
613 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
614
615 protected:
616 virtual void init(le_int32 capacity);
617 virtual void grow(le_int32 capacity);
618
619 private:
620
621 ValueRuns();
622 ValueRuns(const ValueRuns &other);
623 ValueRuns &operator=(const ValueRuns & /*other*/) { return *this; };
624
625 /**
626 * The address of this static class variable serves as this class's ID
627 * for ICU "poor man's RTTI".
628 */
629 static const char fgClassID;
630
631 const le_int32 *fValues;
632 };
633
634 inline ValueRuns::ValueRuns()
635 : RunArray(0), fValues(NULL)
636 {
637 // nothing else to do...
638 }
639
640 inline ValueRuns::ValueRuns(const ValueRuns & /*other*/)
641 : RunArray(0), fValues(NULL)
642 {
643 // nothing else to do...
644 }
645
646 inline ValueRuns::ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count)
647 : RunArray(limits, count), fValues(values)
648 {
649 // nothing else to do...
650 }
651
652 U_NAMESPACE_END
653 #endif