1/*
2 **********************************************************************
3 *   Copyright (C) 1998-2011, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 **********************************************************************
6 */
7
8#ifndef __LEINSERTIONLIST_H
9#define __LEINSERTIONLIST_H
10
11#include "LETypes.h"
12
13U_NAMESPACE_BEGIN
14
15struct InsertionRecord;
16
17#ifndef U_HIDE_INTERNAL_API
18/**
19 * This class encapsulates the callback used by <code>LEInsertionList</code>
20 * to apply an insertion from the insertion list.
21 *
22 * @internal
23 */
24class U_LAYOUT_API LEInsertionCallback
25{
26public:
27    /**
28     * This method will be called by <code>LEInsertionList::applyInsertions</code> for each
29     * entry on the insertion list.
30     *
31     * @param atPosition the position of the insertion
32     * @param count the number of glyphs to insert
33     * @param newGlyphs the address of the glyphs to insert
34     *
35     * @return <code>TRUE</code> if <code>LEInsertions::applyInsertions</code> should
36     *         stop after applying this insertion.
37     *
38     * @internal
39     */
40    virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]) = 0;
41
42    /**
43     * The destructor
44     */
45     virtual ~LEInsertionCallback();
46};
47
48/**
49 * This class is used to keep track of insertions to an array of
50 * <code>LEGlyphIDs</code>. The insertions are kept on a linked
51 * list of <code>InsertionRecords</code> so that the glyph array
52 * doesn't have to be grown for each insertion. The insertions are
53 * stored on the list from leftmost to rightmost to make it easier
54 * to do the insertions.
55 *
56 * The insertions are applied to the array by calling the
57 * <code>applyInsertions</code> method, which calls a client
58 * supplied <code>LEInsertionCallback</code> object to actually
59 * apply the individual insertions.
60 *
61 * @internal
62 */
63class LEInsertionList : public UObject
64{
65public:
66    /**
67     * Construct an empty insertion list.
68     *
69     * @param rightToLeft <code>TRUE</code> if the glyphs are stored
70     *                    in the array in right to left order.
71     *
72     * @internal
73     */
74    LEInsertionList(le_bool rightToLeft);
75
76    /**
77     * The destructor.
78     */
79    ~LEInsertionList();
80
81    /**
82     * Add an entry to the insertion list.
83     *
84     * @param position the glyph at this position in the array will be
85     *                 replaced by the new glyphs.
86     * @param count the number of new glyphs
87     * @param success set to an error code if the auxillary data cannot be retrieved.
88     *
89     * @return the address of an array in which to store the new glyphs. This will
90     *         <em>not</em> be in the glyph array.
91     *
92     * @internal
93     */
94    LEGlyphID *insert(le_int32 position, le_int32 count, LEErrorCode &success);
95
96    /**
97     * Return the number of new glyphs that have been inserted.
98     *
99     * @return the number of new glyphs which have been inserted
100     *
101     * @internal
102     */
103    le_int32 getGrowAmount();
104
105    /**
106     * Call the <code>LEInsertionCallback</code> once for each
107     * entry on the insertion list.
108     *
109     * @param callback the <code>LEInsertionCallback</code> to call for each insertion.
110     *
111     * @return <code>TRUE</code> if <code>callback</code> returned <code>TRUE</code> to
112     *         terminate the insertion list processing.
113     *
114     * @internal
115     */
116    le_bool applyInsertions(LEInsertionCallback *callback);
117
118    /**
119     * Empty the insertion list and free all associated
120     * storage.
121     *
122     * @internal
123     */
124    void reset();
125
126    /**
127     * ICU "poor man's RTTI", returns a UClassID for the actual class.
128     *
129     * @stable ICU 2.8
130     */
131    virtual UClassID getDynamicClassID() const;
132
133    /**
134     * ICU "poor man's RTTI", returns a UClassID for this class.
135     *
136     * @stable ICU 2.8
137     */
138    static UClassID getStaticClassID();
139
140private:
141
142    /**
143     * The head of the insertion list.
144     *
145     * @internal
146     */
147    InsertionRecord *head;
148
149    /**
150     * The tail of the insertion list.
151     *
152     * @internal
153     */
154    InsertionRecord *tail;
155
156    /**
157     * The total number of new glyphs on the insertion list.
158     *
159     * @internal
160     */
161    le_int32 growAmount;
162
163    /**
164     * Set to <code>TRUE</code> if the glyphs are in right
165     * to left order. Since we want the rightmost insertion
166     * to be first on the list, we need to append the
167     * insertions in this case. Otherwise they're prepended.
168     *
169     * @internal
170     */
171    le_bool  append;
172};
173#endif  /* U_HIDE_INTERNAL_API */
174
175U_NAMESPACE_END
176#endif
177
178