@@ -157,6 +157,16 @@ class Text {
157
157
}
158
158
};
159
159
160
+ class ListItem {
161
+
162
+ private:
163
+
164
+
165
+ public:
166
+
167
+
168
+ };
169
+
160
170
/*
161
171
TextArray is a memory-efficient class for managing arrays of strings.
162
172
A typically usage is to break a piece of text into lines and have them
@@ -167,9 +177,11 @@ class TextArray {
167
177
168
178
private:
169
179
const char * name;
170
- int size = 0 ; // the number of items
171
- Text** array = nullptr ; // the array of items
172
- LinkedList* list; // A list to hold new data items as they are added
180
+ int size = 0 ; // the number of items
181
+ Text** array = nullptr ; // an array of Text objects
182
+ TextArray** array2 = nullptr ; // an array of TextArray objects
183
+ LinkedList* list; // A list to hold new Text items as they are added
184
+ LinkedList* list2; // A list to hold new TextArray items as they are added
173
185
174
186
public:
175
187
@@ -180,7 +192,7 @@ class TextArray {
180
192
}
181
193
182
194
// /////////////////////////////////////////////////////////////////////
183
- // Get a specified item .
195
+ // Get a specified Text .
184
196
// If the index is greater than the array size but not greater than
185
197
// the combined size of array and list, return the item from the list.
186
198
Text* get (int n) {
@@ -193,6 +205,20 @@ class TextArray {
193
205
return nullptr ;
194
206
}
195
207
208
+ // /////////////////////////////////////////////////////////////////////
209
+ // Get a specified TextArray.
210
+ // If the index is greater than the array size but not greater than
211
+ // the combined size of array and list, return the item from the list.
212
+ TextArray* getArray (int n) {
213
+ if (n < size) {
214
+ return array2[n];
215
+ }
216
+ else if (n < size + list2->getSize ()) {
217
+ return (TextArray*)list2->get (n - size);
218
+ }
219
+ return nullptr ;
220
+ }
221
+
196
222
// /////////////////////////////////////////////////////////////////////
197
223
// Get the item whose index is passed in as a Text.
198
224
Text* get (Text* t) {
@@ -209,12 +235,18 @@ class TextArray {
209
235
// Add an item. This goes into the linked list.
210
236
void add (Text* item) {
211
237
list->add (item);
238
+ list2->add (nullptr );
212
239
}
213
240
214
241
void add (const char * item) {
215
242
list->add (new Text (item));
216
243
}
217
244
245
+ void add (TextArray* array) {
246
+ list->add (nullptr );
247
+ list2->add (array);
248
+ }
249
+
218
250
// /////////////////////////////////////////////////////////////////////
219
251
// Test if this array contains the given text
220
252
bool contains (Text* t) {
@@ -231,26 +263,32 @@ class TextArray {
231
263
// Flatten this item by creating a single array to hold all the data.
232
264
void flatten () {
233
265
Text** oldArray = array;
266
+ TextArray** oldArray2 = array2;
234
267
int oldSize = size;
235
268
// Create a new array big enough for the old array and the list
236
269
int total = oldSize + list->getSize ();
237
270
if (total > 0 ) {
238
271
array = new Text*[total];
272
+ array2 = new TextArray*[total];
239
273
// Copy the old array to the new
240
274
size = 0 ;
241
275
while (size < oldSize) {
242
276
array[size] = oldArray[size];
277
+ array2[size] = oldArray2[size];
243
278
size++;
244
279
}
245
280
if (oldArray != nullptr ) {
246
281
delete oldArray;
282
+ delete oldArray2;
247
283
}
248
284
// Copy the list to the new array
249
285
int n = 0 ;
250
286
while (n < list->getSize ()) {
251
- array[size++] = (Text*)list->get (n++);
287
+ array[size] = (Text*)list->get (n);
288
+ array2[size++] = (TextArray*)list2->get (n++);
252
289
}
253
290
list->clear ();
291
+ list2->clear ();
254
292
}
255
293
}
256
294
@@ -275,21 +313,27 @@ class TextArray {
275
313
TextArray (const char * name) {
276
314
this ->name = name;
277
315
list = new LinkedList (name);
316
+ list2 = new LinkedList (name);
278
317
}
279
318
280
319
// /////////////////////////////////////////////////////////////////////
281
320
// Default constructor
282
321
TextArray () {
283
322
list = new LinkedList (" <noname>" );
323
+ list2 = new LinkedList (" <noname>" );
284
324
}
285
325
286
326
// /////////////////////////////////////////////////////////////////////
287
327
// Destructor
288
328
~TextArray () {
289
329
delete array;
290
330
array = nullptr ;
331
+ delete array2;
332
+ array2 = nullptr ;
291
333
delete list;
292
334
list = nullptr ;
335
+ delete list2;
336
+ list2 = nullptr ;
293
337
#if DESTROY
294
338
print (" TextArray: Delete %s\n " , name);
295
339
#endif
0 commit comments