1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2003-2008, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
14 #include "layout/LETypes.h"
15 #include "layout/LEFontInstance.h"
17 #include "unicode/utypes.h"
18 #include "unicode/locid.h"
22 * \brief C++ API: base class for building classes which represent data that is associated with runs of text.
28 * The initial size of an array if it is unspecified.
32 #define INITIAL_CAPACITY 16
35 * When an array needs to grow, it will double in size until
36 * it becomes this large, then it will grow by this amount.
40 #define CAPACITY_GROW_LIMIT 128
43 * The <code>RunArray</code> class is a base class for building classes
44 * which represent data that is associated with runs of text. This class
45 * maintains an array of limit indices into the text, subclasses
46 * provide one or more arrays of data.
50 class U_LAYOUTEX_API RunArray
: public UObject
54 * Construct a <code>RunArray</code> object from a pre-existing
55 * array of limit indices.
57 * @param limits is an array of limit indices. This array must remain
58 * valid until the <code>RunArray</code> object is destroyed.
60 * @param count is the number of entries in the limit array.
64 inline RunArray(const le_int32
*limits
, le_int32 count
);
67 * Construct an empty <code>RunArray</code> object. Clients can add limit
68 * indices array using the <code>add</code> method.
70 * @param initialCapacity is the initial size of the limit indices array. If
71 * this value is zero, no array will be allocated.
77 RunArray(le_int32 initialCapacity
);
80 * The destructor; virtual so that subclass destructors are invoked as well.
87 * Get the number of entries in the limit indices array.
89 * @return the number of entries in the limit indices array.
93 inline le_int32
getCount() const;
96 * Reset the limit indices array. This method sets the number of entries in the
97 * limit indices array to zero. It does not delete the array.
99 * Note: Subclass arrays will also be reset and not deleted.
106 * Get the last limit index. This is the number of characters in
109 * @return the last limit index.
113 inline le_int32
getLimit() const;
116 * Get the limit index for a particular run of text.
118 * @param run is the run. This is an index into the limit index array.
120 * @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
124 inline le_int32
getLimit(le_int32 run
) const;
127 * Add a limit index to the limit indices array and return the run index
128 * where it was stored. If the array does not exist, it will be created by
129 * calling the <code>init</code> method. If it is full, it will be grown by
130 * calling the <code>grow</code> method.
132 * If the <code>RunArray</code> object was created with a client-supplied
133 * limit indices array, this method will return a run index of -1.
135 * Subclasses should not override this method. Rather they should provide
136 * a new <code>add</code> method which takes a limit index along with whatever
137 * other data they implement. The new <code>add</code> method should
138 * first call this method to grow the data arrays, and use the return value
139 * to store the data in their own arrays.
141 * @param limit is the limit index to add to the array.
143 * @return the run index where the limit index was stored, or -1 if the limit index cannt be stored.
150 le_int32
add(le_int32 limit
);
153 * ICU "poor man's RTTI", returns a UClassID for this class.
157 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
160 * ICU "poor man's RTTI", returns a UClassID for the actual class.
164 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
168 * Create a data array with the given initial size. This method will be
169 * called by the <code>add</code> method if there is no limit indices
170 * array. Subclasses which override this method must also call it from
171 * the overriding method to create the limit indices array.
173 * @param capacity is the initial size of the data array.
179 virtual void init(le_int32 capacity
);
182 * Grow a data array to the given initial size. This method will be
183 * called by the <code>add</code> method if the limit indices
184 * array is full. Subclasses which override this method must also call it from
185 * the overriding method to grow the limit indices array.
187 * @param capacity is the initial size of the data array.
193 virtual void grow(le_int32 capacity
);
196 * Set by the constructors to indicate whether
197 * or not the client supplied the data arrays.
198 * If they were supplied by the client, the
199 * <code>add</code> method won't change the arrays
200 * and the destructor won't delete them.
204 le_bool fClientArrays
;
208 * The address of this static class variable serves as this class's ID
209 * for ICU "poor man's RTTI".
211 static const char fgClassID
;
213 le_int32
ensureCapacity();
216 inline RunArray(const RunArray
& /*other*/);
217 inline RunArray
&operator=(const RunArray
& /*other*/) { return *this; };
219 const le_int32
*fLimits
;
224 inline RunArray::RunArray()
225 : UObject(), fClientArrays(FALSE
), fLimits(NULL
), fCount(0), fCapacity(0)
227 // nothing else to do...
230 inline RunArray::RunArray(const RunArray
& /*other*/)
231 : UObject(), fClientArrays(FALSE
), fLimits(NULL
), fCount(0), fCapacity(0)
233 // nothing else to do...
236 inline RunArray::RunArray(const le_int32
*limits
, le_int32 count
)
237 : UObject(), fClientArrays(TRUE
), fLimits(limits
), fCount(count
), fCapacity(count
)
239 // nothing else to do...
242 inline le_int32
RunArray::getCount() const
247 inline void RunArray::reset()
252 inline le_int32
RunArray::getLimit(le_int32 run
) const
254 if (run
< 0 || run
>= fCount
) {
261 inline le_int32
RunArray::getLimit() const
263 return getLimit(fCount
- 1);
267 * The <code>FontRuns</code> class associates pointers to <code>LEFontInstance</code>
268 * objects with runs of text.
272 class U_LAYOUTEX_API FontRuns
: public RunArray
276 * Construct a <code>FontRuns</code> object from pre-existing arrays of fonts
279 * @param fonts is the address of an array of pointers to <code>LEFontInstance</code> objects. This
280 * array, and the <code>LEFontInstance</code> objects to which it points must remain
281 * valid until the <code>FontRuns</code> object is destroyed.
283 * @param limits is the address of an array of limit indices. This array must remain valid until
284 * the <code>FontRuns</code> object is destroyed.
286 * @param count is the number of entries in the two arrays.
290 inline FontRuns(const LEFontInstance
**fonts
, const le_int32
*limits
, le_int32 count
);
293 * Construct an empty <code>FontRuns</code> object. Clients can add font and limit
294 * indices arrays using the <code>add</code> method.
296 * @param initialCapacity is the initial size of the font and limit indices arrays. If
297 * this value is zero, no arrays will be allocated.
303 FontRuns(le_int32 initialCapacity
);
306 * The destructor; virtual so that subclass destructors are invoked as well.
313 * Get the <code>LEFontInstance</code> object assoicated with the given run
314 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
317 * @param run is the index into the font and limit indices arrays.
319 * @return the <code>LEFontInstance</code> associated with the given text run.
321 * @see RunArray::getLimit
325 const LEFontInstance
*getFont(le_int32 run
) const;
329 * Add an <code>LEFontInstance</code> and limit index pair to the data arrays and return
330 * the run index where the data was stored. This method calls
331 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
333 * If the <code>FontRuns</code> object was created with a client-supplied
334 * font and limit indices arrays, this method will return a run index of -1.
336 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
337 * method which takes a font and a limit index along with whatever other data they implement.
338 * The new <code>add</code> method should first call this method to grow the font and limit indices
339 * arrays, and use the returned run index to store data their own arrays.
341 * @param font is the address of the <code>LEFontInstance</code> to add. This object must
342 * remain valid until the <code>FontRuns</code> object is destroyed.
344 * @param limit is the limit index to add
346 * @return the run index where the font and limit index were stored, or -1 if the data cannot be stored.
350 le_int32
add(const LEFontInstance
*font
, le_int32 limit
);
353 * ICU "poor man's RTTI", returns a UClassID for this class.
357 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
360 * ICU "poor man's RTTI", returns a UClassID for the actual class.
364 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
367 virtual void init(le_int32 capacity
);
368 virtual void grow(le_int32 capacity
);
373 inline FontRuns(const FontRuns
&other
);
374 inline FontRuns
&operator=(const FontRuns
& /*other*/) { return *this; };
377 * The address of this static class variable serves as this class's ID
378 * for ICU "poor man's RTTI".
380 static const char fgClassID
;
382 const LEFontInstance
**fFonts
;
385 inline FontRuns::FontRuns()
386 : RunArray(0), fFonts(NULL
)
388 // nothing else to do...
391 inline FontRuns::FontRuns(const FontRuns
& /*other*/)
392 : RunArray(0), fFonts(NULL
)
394 // nothing else to do...
397 inline FontRuns::FontRuns(const LEFontInstance
**fonts
, const le_int32
*limits
, le_int32 count
)
398 : RunArray(limits
, count
), fFonts(fonts
)
400 // nothing else to do...
404 * The <code>LocaleRuns</code> class associates pointers to <code>Locale</code>
405 * objects with runs of text.
409 class U_LAYOUTEX_API LocaleRuns
: public RunArray
413 * Construct a <code>LocaleRuns</code> object from pre-existing arrays of locales
416 * @param locales is the address of an array of pointers to <code>Locale</code> objects. This array,
417 * and the <code>Locale</code> objects to which it points, must remain valid until
418 * the <code>LocaleRuns</code> object is destroyed.
420 * @param limits is the address of an array of limit indices. This array must remain valid until the
421 * <code>LocaleRuns</code> object is destroyed.
423 * @param count is the number of entries in the two arrays.
427 inline LocaleRuns(const Locale
**locales
, const le_int32
*limits
, le_int32 count
);
430 * Construct an empty <code>LocaleRuns</code> object. Clients can add locale and limit
431 * indices arrays using the <code>add</code> method.
433 * @param initialCapacity is the initial size of the locale and limit indices arrays. If
434 * this value is zero, no arrays will be allocated.
440 LocaleRuns(le_int32 initialCapacity
);
443 * The destructor; virtual so that subclass destructors are invoked as well.
447 virtual ~LocaleRuns();
450 * Get the <code>Locale</code> object assoicated with the given run
451 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
454 * @param run is the index into the font and limit indices arrays.
456 * @return the <code>Locale</code> associated with the given text run.
458 * @see RunArray::getLimit
462 const Locale
*getLocale(le_int32 run
) const;
466 * Add a <code>Locale</code> and limit index pair to the data arrays and return
467 * the run index where the data was stored. This method calls
468 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
470 * If the <code>LocaleRuns</code> object was created with a client-supplied
471 * locale and limit indices arrays, this method will return a run index of -1.
473 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
474 * method which takes a locale and a limit index along with whatever other data they implement.
475 * The new <code>add</code> method should first call this method to grow the font and limit indices
476 * arrays, and use the returned run index to store data their own arrays.
478 * @param locale is the address of the <code>Locale</code> to add. This object must remain valid
479 * until the <code>LocaleRuns</code> object is destroyed.
481 * @param limit is the limit index to add
483 * @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored.
487 le_int32
add(const Locale
*locale
, le_int32 limit
);
490 * ICU "poor man's RTTI", returns a UClassID for this class.
494 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
497 * ICU "poor man's RTTI", returns a UClassID for the actual class.
501 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
504 virtual void init(le_int32 capacity
);
505 virtual void grow(le_int32 capacity
);
510 const Locale
**fLocales
;
515 inline LocaleRuns(const LocaleRuns
&other
);
516 inline LocaleRuns
&operator=(const LocaleRuns
& /*other*/) { return *this; };
519 * The address of this static class variable serves as this class's ID
520 * for ICU "poor man's RTTI".
522 static const char fgClassID
;
525 inline LocaleRuns::LocaleRuns()
526 : RunArray(0), fLocales(NULL
)
528 // nothing else to do...
531 inline LocaleRuns::LocaleRuns(const LocaleRuns
& /*other*/)
532 : RunArray(0), fLocales(NULL
)
534 // nothing else to do...
537 inline LocaleRuns::LocaleRuns(const Locale
**locales
, const le_int32
*limits
, le_int32 count
)
538 : RunArray(limits
, count
), fLocales(locales
)
540 // nothing else to do...
544 * The <code>ValueRuns</code> class associates integer values with runs of text.
548 class U_LAYOUTEX_API ValueRuns
: public RunArray
552 * Construct a <code>ValueRuns</code> object from pre-existing arrays of values
555 * @param values is the address of an array of integer. This array must remain valid until
556 * the <code>ValueRuns</code> object is destroyed.
558 * @param limits is the address of an array of limit indices. This array must remain valid until
559 * the <code>ValueRuns</code> object is destroyed.
561 * @param count is the number of entries in the two arrays.
565 inline ValueRuns(const le_int32
*values
, const le_int32
*limits
, le_int32 count
);
568 * Construct an empty <code>ValueRuns</code> object. Clients can add value and limit
569 * indices arrays using the <code>add</code> method.
571 * @param initialCapacity is the initial size of the value and limit indices arrays. If
572 * this value is zero, no arrays will be allocated.
578 ValueRuns(le_int32 initialCapacity
);
581 * The destructor; virtual so that subclass destructors are invoked as well.
585 virtual ~ValueRuns();
588 * Get the integer value assoicated with the given run
589 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
592 * @param run is the index into the font and limit indices arrays.
594 * @return the integer value associated with the given text run.
596 * @see RunArray::getLimit
600 le_int32
getValue(le_int32 run
) const;
604 * Add an integer value and limit index pair to the data arrays and return
605 * the run index where the data was stored. This method calls
606 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
608 * If the <code>ValueRuns</code> object was created with a client-supplied
609 * font and limit indices arrays, this method will return a run index of -1.
611 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
612 * method which takes an integer value and a limit index along with whatever other data they implement.
613 * The new <code>add</code> method should first call this method to grow the font and limit indices
614 * arrays, and use the returned run index to store data their own arrays.
616 * @param value is the integer value to add
618 * @param limit is the limit index to add
620 * @return the run index where the value and limit index were stored, or -1 if the data cannot be stored.
624 le_int32
add(le_int32 value
, le_int32 limit
);
627 * ICU "poor man's RTTI", returns a UClassID for this class.
631 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
634 * ICU "poor man's RTTI", returns a UClassID for the actual class.
638 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
641 virtual void init(le_int32 capacity
);
642 virtual void grow(le_int32 capacity
);
647 inline ValueRuns(const ValueRuns
&other
);
648 inline ValueRuns
&operator=(const ValueRuns
& /*other*/) { return *this; };
651 * The address of this static class variable serves as this class's ID
652 * for ICU "poor man's RTTI".
654 static const char fgClassID
;
656 const le_int32
*fValues
;
659 inline ValueRuns::ValueRuns()
660 : RunArray(0), fValues(NULL
)
662 // nothing else to do...
665 inline ValueRuns::ValueRuns(const ValueRuns
& /*other*/)
666 : RunArray(0), fValues(NULL
)
668 // nothing else to do...
671 inline ValueRuns::ValueRuns(const le_int32
*values
, const le_int32
*limits
, le_int32 count
)
672 : RunArray(limits
, count
), fValues(values
)
674 // nothing else to do...