X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..0f5d89e82340278ed3d7d50029f37cab2c41a57e:/icuSources/layoutex/layout/RunArrays.h diff --git a/icuSources/layoutex/layout/RunArrays.h b/icuSources/layoutex/layout/RunArrays.h index 68f121db..5cf6c60b 100644 --- a/icuSources/layoutex/layout/RunArrays.h +++ b/icuSources/layoutex/layout/RunArrays.h @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** - * Copyright (C) 2003, International Business Machines + * Copyright (C) 2003-2008, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -15,12 +17,17 @@ #include "unicode/utypes.h" #include "unicode/locid.h" +/** + * \file + * \brief C++ API: base class for building classes which represent data that is associated with runs of text. + */ + U_NAMESPACE_BEGIN /** * The initial size of an array if it is unspecified. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ #define INITIAL_CAPACITY 16 @@ -28,7 +35,7 @@ U_NAMESPACE_BEGIN * When an array needs to grow, it will double in size until * it becomes this large, then it will grow by this amount. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ #define CAPACITY_GROW_LIMIT 128 @@ -38,7 +45,7 @@ U_NAMESPACE_BEGIN * maintains an array of limit indices into the text, subclasses * provide one or more arrays of data. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ class U_LAYOUTEX_API RunArray : public UObject { @@ -47,13 +54,14 @@ public: * Construct a RunArray object from a pre-existing * array of limit indices. * - * @param limits is an array of limit indices. + * @param limits is an array of limit indices. This array must remain + * valid until the RunArray object is destroyed. * * @param count is the number of entries in the limit array. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - RunArray(const le_int32 *limits, le_int32 count); + inline RunArray(const le_int32 *limits, le_int32 count); /** * Construct an empty RunArray object. Clients can add limit @@ -64,14 +72,14 @@ public: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - RunArray(le_int32 initalCapacity); + RunArray(le_int32 initialCapacity); /** * The destructor; virtual so that subclass destructors are invoked as well. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual ~RunArray(); @@ -80,9 +88,19 @@ public: * * @return the number of entries in the limit indices array. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - le_int32 getCount() const; + inline le_int32 getCount() const; + + /** + * Reset the limit indices array. This method sets the number of entries in the + * limit indices array to zero. It does not delete the array. + * + * Note: Subclass arrays will also be reset and not deleted. + * + * @stable ICU 3.6 + */ + inline void reset(); /** * Get the last limit index. This is the number of characters in @@ -90,9 +108,9 @@ public: * * @return the last limit index. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - le_int32 getLimit() const; + inline le_int32 getLimit() const; /** * Get the limit index for a particular run of text. @@ -101,9 +119,9 @@ public: * * @return the limit index for the run, or -1 if run is out of bounds. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - le_int32 getLimit(le_int32 run) const; + inline le_int32 getLimit(le_int32 run) const; /** * Add a limit index to the limit indices array and return the run index @@ -127,23 +145,23 @@ public: * @see init * @see grow * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_int32 add(le_int32 limit); /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. + * ICU "poor man's RTTI", returns a UClassID for this class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } /** - * ICU "poor man's RTTI", returns a UClassID for this class. + * ICU "poor man's RTTI", returns a UClassID for the actual class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } protected: /** @@ -156,7 +174,7 @@ protected: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual void init(le_int32 capacity); @@ -170,7 +188,7 @@ protected: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual void grow(le_int32 capacity); @@ -181,7 +199,7 @@ protected: * add method won't change the arrays * and the destructor won't delete them. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_bool fClientArrays; @@ -194,9 +212,9 @@ private: le_int32 ensureCapacity(); - RunArray(); - RunArray(const RunArray & /*other*/); - RunArray &operator=(const RunArray & /*other*/) { return *this; }; + inline RunArray(); + inline RunArray(const RunArray & /*other*/); + inline RunArray &operator=(const RunArray & /*other*/) { return *this; }; const le_int32 *fLimits; le_int32 fCount; @@ -204,42 +222,31 @@ private: }; inline RunArray::RunArray() - : UObject(), fClientArrays(false), fLimits(NULL), fCount(0), fCapacity(0) + : UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0) { - // nothing else to do... + // nothing else to do... } inline RunArray::RunArray(const RunArray & /*other*/) - : UObject(), fClientArrays(false), fLimits(NULL), fCount(0), fCapacity(0) + : UObject(), fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(0) { - // nothing else to do... + // nothing else to do... } inline RunArray::RunArray(const le_int32 *limits, le_int32 count) - : UObject(), fClientArrays(true), fLimits(limits), fCount(count), fCapacity(count) + : UObject(), fClientArrays(TRUE), fLimits(limits), fCount(count), fCapacity(count) { // nothing else to do... } -inline RunArray::RunArray(le_int32 initialCapacity) - : fClientArrays(false), fLimits(NULL), fCount(0), fCapacity(initialCapacity) -{ - if (initialCapacity > 0) { - fLimits = LE_NEW_ARRAY(le_int32, fCapacity); - } -} - -inline RunArray::~RunArray() +inline le_int32 RunArray::getCount() const { - if (! fClientArrays) { - LE_DELETE_ARRAY(fLimits); - fLimits = NULL; - } + return fCount; } -inline le_int32 RunArray::getCount() const +inline void RunArray::reset() { - return fCount; + fCount = 0; } inline le_int32 RunArray::getLimit(le_int32 run) const @@ -260,7 +267,7 @@ inline le_int32 RunArray::getLimit() const * The FontRuns class associates pointers to LEFontInstance * objects with runs of text. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ class U_LAYOUTEX_API FontRuns : public RunArray { @@ -269,15 +276,18 @@ public: * Construct a FontRuns object from pre-existing arrays of fonts * and limit indices. * - * @param fonts is the address of an array of pointers to LEFontInstance objects. + * @param fonts is the address of an array of pointers to LEFontInstance objects. This + * array, and the LEFontInstance objects to which it points must remain + * valid until the FontRuns object is destroyed. * - * @param limits is the address of an array of limit indices. + * @param limits is the address of an array of limit indices. This array must remain valid until + * the FontRuns object is destroyed. * * @param count is the number of entries in the two arrays. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count); + inline FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count); /** * Construct an empty FontRuns object. Clients can add font and limit @@ -288,14 +298,14 @@ public: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ FontRuns(le_int32 initialCapacity); /** * The destructor; virtual so that subclass destructors are invoked as well. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual ~FontRuns(); @@ -310,7 +320,7 @@ public: * * @see RunArray::getLimit * - * @draft ICU 2.6 + * @stable ICU 3.2 */ const LEFontInstance *getFont(le_int32 run) const; @@ -328,29 +338,30 @@ public: * The new add method should first call this method to grow the font and limit indices * arrays, and use the returned run index to store data their own arrays. * - * @param font is the address of the LEFontInstance to add + * @param font is the address of the LEFontInstance to add. This object must + * remain valid until the FontRuns object is destroyed. * * @param limit is the limit index to add * * @return the run index where the font and limit index were stored, or -1 if the data cannot be stored. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_int32 add(const LEFontInstance *font, le_int32 limit); /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. + * ICU "poor man's RTTI", returns a UClassID for this class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } /** - * ICU "poor man's RTTI", returns a UClassID for this class. + * ICU "poor man's RTTI", returns a UClassID for the actual class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } protected: virtual void init(le_int32 capacity); @@ -358,9 +369,9 @@ protected: private: - FontRuns(); - FontRuns(const FontRuns &other); - FontRuns &operator=(const FontRuns & /*other*/) { return *this; }; + inline FontRuns(); + inline FontRuns(const FontRuns &other); + inline FontRuns &operator=(const FontRuns & /*other*/) { return *this; }; /** * The address of this static class variable serves as this class's ID @@ -372,15 +383,15 @@ private: }; inline FontRuns::FontRuns() - : RunArray(0), fFonts(NULL) + : RunArray(0), fFonts(NULL) { - // nothing else to do... + // nothing else to do... } inline FontRuns::FontRuns(const FontRuns & /*other*/) - : RunArray(0), fFonts(NULL) + : RunArray(0), fFonts(NULL) { - // nothing else to do... + // nothing else to do... } inline FontRuns::FontRuns(const LEFontInstance **fonts, const le_int32 *limits, le_int32 count) @@ -389,27 +400,11 @@ inline FontRuns::FontRuns(const LEFontInstance **fonts, const le_int32 *limits, // nothing else to do... } -inline FontRuns::FontRuns(le_int32 initialCapacity) - : RunArray(initialCapacity), fFonts(NULL) -{ - if (initialCapacity > 0) { - fFonts = LE_NEW_ARRAY(const LEFontInstance *, initialCapacity); - } -} - -inline FontRuns::~FontRuns() -{ - if (! fClientArrays) { - LE_DELETE_ARRAY(fFonts); - fFonts = NULL; - } -} - /** * The LocaleRuns class associates pointers to Locale * objects with runs of text. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ class U_LAYOUTEX_API LocaleRuns : public RunArray { @@ -418,15 +413,18 @@ public: * Construct a LocaleRuns object from pre-existing arrays of locales * and limit indices. * - * @param locales is the address of an array of pointers to Locale objects. + * @param locales is the address of an array of pointers to Locale objects. This array, + * and the Locale objects to which it points, must remain valid until + * the LocaleRuns object is destroyed. * - * @param limits is the address of an array of limit indices. + * @param limits is the address of an array of limit indices. This array must remain valid until the + * LocaleRuns object is destroyed. * * @param count is the number of entries in the two arrays. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count); + inline LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count); /** * Construct an empty LocaleRuns object. Clients can add locale and limit @@ -437,14 +435,14 @@ public: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ LocaleRuns(le_int32 initialCapacity); /** * The destructor; virtual so that subclass destructors are invoked as well. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual ~LocaleRuns(); @@ -459,7 +457,7 @@ public: * * @see RunArray::getLimit * - * @draft ICU 2.6 + * @stable ICU 3.2 */ const Locale *getLocale(le_int32 run) const; @@ -477,59 +475,63 @@ public: * The new add method should first call this method to grow the font and limit indices * arrays, and use the returned run index to store data their own arrays. * - * @param locale is the address of the Locale to add + * @param locale is the address of the Locale to add. This object must remain valid + * until the LocaleRuns object is destroyed. * * @param limit is the limit index to add * * @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_int32 add(const Locale *locale, le_int32 limit); /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. + * ICU "poor man's RTTI", returns a UClassID for this class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } /** - * ICU "poor man's RTTI", returns a UClassID for this class. + * ICU "poor man's RTTI", returns a UClassID for the actual class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } protected: virtual void init(le_int32 capacity); virtual void grow(le_int32 capacity); + /** + * @internal + */ + const Locale **fLocales; + private: - LocaleRuns(); - LocaleRuns(const LocaleRuns &other); - LocaleRuns &operator=(const LocaleRuns & /*other*/) { return *this; }; + inline LocaleRuns(); + inline LocaleRuns(const LocaleRuns &other); + inline LocaleRuns &operator=(const LocaleRuns & /*other*/) { return *this; }; /** * The address of this static class variable serves as this class's ID * for ICU "poor man's RTTI". */ static const char fgClassID; - - const Locale **fLocales; }; inline LocaleRuns::LocaleRuns() - : RunArray(0), fLocales(NULL) + : RunArray(0), fLocales(NULL) { - // nothing else to do... + // nothing else to do... } inline LocaleRuns::LocaleRuns(const LocaleRuns & /*other*/) - : RunArray(0), fLocales(NULL) + : RunArray(0), fLocales(NULL) { - // nothing else to do... + // nothing else to do... } inline LocaleRuns::LocaleRuns(const Locale **locales, const le_int32 *limits, le_int32 count) @@ -538,26 +540,10 @@ inline LocaleRuns::LocaleRuns(const Locale **locales, const le_int32 *limits, le // nothing else to do... } -inline LocaleRuns::LocaleRuns(le_int32 initialCapacity) - : RunArray(initialCapacity), fLocales(NULL) -{ - if (initialCapacity > 0) { - fLocales = LE_NEW_ARRAY(const Locale *, initialCapacity); - } -} - -inline LocaleRuns::~LocaleRuns() -{ - if (! fClientArrays) { - LE_DELETE_ARRAY(fLocales); - fLocales = NULL; - } -} - /** * The ValueRuns class associates integer values with runs of text. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ class U_LAYOUTEX_API ValueRuns : public RunArray { @@ -566,15 +552,17 @@ public: * Construct a ValueRuns object from pre-existing arrays of values * and limit indices. * - * @param values is the address of an array of integer. + * @param values is the address of an array of integer. This array must remain valid until + * the ValueRuns object is destroyed. * - * @param limits is the address of an array of limit indices. + * @param limits is the address of an array of limit indices. This array must remain valid until + * the ValueRuns object is destroyed. * * @param count is the number of entries in the two arrays. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count); + inline ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count); /** * Construct an empty ValueRuns object. Clients can add value and limit @@ -585,14 +573,14 @@ public: * * @see add * - * @draft ICU 2.6 + * @stable ICU 3.2 */ ValueRuns(le_int32 initialCapacity); /** * The destructor; virtual so that subclass destructors are invoked as well. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ virtual ~ValueRuns(); @@ -607,7 +595,7 @@ public: * * @see RunArray::getLimit * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_int32 getValue(le_int32 run) const; @@ -631,23 +619,23 @@ public: * * @return the run index where the value and limit index were stored, or -1 if the data cannot be stored. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ le_int32 add(le_int32 value, le_int32 limit); /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. + * ICU "poor man's RTTI", returns a UClassID for this class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } /** - * ICU "poor man's RTTI", returns a UClassID for this class. + * ICU "poor man's RTTI", returns a UClassID for the actual class. * - * @draft ICU 2.6 + * @stable ICU 3.2 */ - static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } protected: virtual void init(le_int32 capacity); @@ -655,9 +643,9 @@ protected: private: - ValueRuns(); - ValueRuns(const ValueRuns &other); - ValueRuns &operator=(const ValueRuns & /*other*/) { return *this; }; + inline ValueRuns(); + inline ValueRuns(const ValueRuns &other); + inline ValueRuns &operator=(const ValueRuns & /*other*/) { return *this; }; /** * The address of this static class variable serves as this class's ID @@ -669,15 +657,15 @@ private: }; inline ValueRuns::ValueRuns() - : RunArray(0), fValues(NULL) + : RunArray(0), fValues(NULL) { - // nothing else to do... + // nothing else to do... } inline ValueRuns::ValueRuns(const ValueRuns & /*other*/) - : RunArray(0), fValues(NULL) + : RunArray(0), fValues(NULL) { - // nothing else to do... + // nothing else to do... } inline ValueRuns::ValueRuns(const le_int32 *values, const le_int32 *limits, le_int32 count) @@ -686,21 +674,5 @@ inline ValueRuns::ValueRuns(const le_int32 *values, const le_int32 *limits, le_i // nothing else to do... } -inline ValueRuns::ValueRuns(le_int32 initialCapacity) - : RunArray(initialCapacity), fValues(NULL) -{ - if (initialCapacity > 0) { - fValues = LE_NEW_ARRAY(le_int32, initialCapacity); - } -} - -inline ValueRuns::~ValueRuns() -{ - if (! fClientArrays) { - LE_DELETE_ARRAY(fValues); - fValues = NULL; - } -} - U_NAMESPACE_END #endif