author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
/* |
sl@0 | 2 |
********************************************************************** |
sl@0 | 3 |
* Copyright (C) 1998-2004, International Business Machines |
sl@0 | 4 |
* Corporation and others. All Rights Reserved. |
sl@0 | 5 |
********************************************************************** |
sl@0 | 6 |
*/ |
sl@0 | 7 |
|
sl@0 | 8 |
#include "LETypes.h" |
sl@0 | 9 |
#include "LEInsertionList.h" |
sl@0 | 10 |
|
sl@0 | 11 |
U_NAMESPACE_BEGIN |
sl@0 | 12 |
|
sl@0 | 13 |
#define ANY_NUMBER 1 |
sl@0 | 14 |
|
sl@0 | 15 |
struct InsertionRecord |
sl@0 | 16 |
{ |
sl@0 | 17 |
InsertionRecord *next; |
sl@0 | 18 |
le_int32 position; |
sl@0 | 19 |
le_int32 count; |
sl@0 | 20 |
LEGlyphID glyphs[ANY_NUMBER]; |
sl@0 | 21 |
}; |
sl@0 | 22 |
|
sl@0 | 23 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEInsertionList) |
sl@0 | 24 |
|
sl@0 | 25 |
LEInsertionList::LEInsertionList(le_bool rightToLeft) |
sl@0 | 26 |
: head(NULL), tail(NULL), growAmount(0), append(rightToLeft) |
sl@0 | 27 |
{ |
sl@0 | 28 |
tail = (InsertionRecord *) &head; |
sl@0 | 29 |
} |
sl@0 | 30 |
|
sl@0 | 31 |
LEInsertionList::~LEInsertionList() |
sl@0 | 32 |
{ |
sl@0 | 33 |
reset(); |
sl@0 | 34 |
} |
sl@0 | 35 |
|
sl@0 | 36 |
void LEInsertionList::reset() |
sl@0 | 37 |
{ |
sl@0 | 38 |
while (head != NULL) { |
sl@0 | 39 |
InsertionRecord *record = head; |
sl@0 | 40 |
|
sl@0 | 41 |
head = head->next; |
sl@0 | 42 |
LE_DELETE_ARRAY(record); |
sl@0 | 43 |
} |
sl@0 | 44 |
|
sl@0 | 45 |
tail = (InsertionRecord *) &head; |
sl@0 | 46 |
growAmount = 0; |
sl@0 | 47 |
} |
sl@0 | 48 |
|
sl@0 | 49 |
le_int32 LEInsertionList::getGrowAmount() |
sl@0 | 50 |
{ |
sl@0 | 51 |
return growAmount; |
sl@0 | 52 |
} |
sl@0 | 53 |
|
sl@0 | 54 |
LEGlyphID *LEInsertionList::insert(le_int32 position, le_int32 count, |
sl@0 | 55 |
LEErrorCode &success) |
sl@0 | 56 |
{ |
sl@0 | 57 |
if (LE_FAILURE(success)) { |
sl@0 | 58 |
return 0; |
sl@0 | 59 |
} |
sl@0 | 60 |
|
sl@0 | 61 |
InsertionRecord *insertion = (InsertionRecord *) LE_NEW_ARRAY(char, sizeof(InsertionRecord) + (count - ANY_NUMBER) * sizeof (LEGlyphID)); |
sl@0 | 62 |
|
sl@0 | 63 |
if (!insertion) { |
sl@0 | 64 |
success = LE_MEMORY_ALLOCATION_ERROR; |
sl@0 | 65 |
return 0; |
sl@0 | 66 |
} |
sl@0 | 67 |
|
sl@0 | 68 |
insertion->position = position; |
sl@0 | 69 |
insertion->count = count; |
sl@0 | 70 |
|
sl@0 | 71 |
growAmount += count - 1; |
sl@0 | 72 |
|
sl@0 | 73 |
if (append) { |
sl@0 | 74 |
// insert on end of list... |
sl@0 | 75 |
insertion->next = NULL; |
sl@0 | 76 |
tail->next = insertion; |
sl@0 | 77 |
tail = insertion; |
sl@0 | 78 |
} else { |
sl@0 | 79 |
// insert on front of list... |
sl@0 | 80 |
insertion->next = head; |
sl@0 | 81 |
head = insertion; |
sl@0 | 82 |
} |
sl@0 | 83 |
|
sl@0 | 84 |
return insertion->glyphs; |
sl@0 | 85 |
} |
sl@0 | 86 |
|
sl@0 | 87 |
le_bool LEInsertionList::applyInsertions(LEInsertionCallback *callback) |
sl@0 | 88 |
{ |
sl@0 | 89 |
for (InsertionRecord *rec = head; rec != NULL; rec = rec->next) { |
sl@0 | 90 |
if (callback->applyInsertion(rec->position, rec->count, rec->glyphs)) { |
sl@0 | 91 |
return TRUE; |
sl@0 | 92 |
} |
sl@0 | 93 |
} |
sl@0 | 94 |
|
sl@0 | 95 |
return FALSE; |
sl@0 | 96 |
} |
sl@0 | 97 |
|
sl@0 | 98 |
U_NAMESPACE_END |