! * \brief boxaInsertBox() * * \param[in] boxa * \param[in] index location in boxa to insert new value * \param[in] box new box to be inserted * \return 0 if OK, 1 on error * * * Notes: * (1) This shifts box[i] --> box[i + 1] for all i >= index, * and then inserts box as box[index]. * (2) To insert at the beginning of the array, set index = 0. *
| 978 | * </pre> |
| 979 | */ |
| 980 | l_int32 |
| 981 | boxaInsertBox(BOXA *boxa, |
| 982 | l_int32 index, |
| 983 | BOX *box) |
| 984 | { |
| 985 | l_int32 i, n; |
| 986 | BOX **array; |
| 987 | |
| 988 | PROCNAME("boxaInsertBox"); |
| 989 | |
| 990 | if (!boxa) |
| 991 | return ERROR_INT("boxa not defined", procName, 1); |
| 992 | n = boxaGetCount(boxa); |
| 993 | if (index < 0 || index > n) |
| 994 | return ERROR_INT("index not in {0...n}", procName, 1); |
| 995 | if (!box) |
| 996 | return ERROR_INT("box not defined", procName, 1); |
| 997 | |
| 998 | if (n >= boxa->nalloc) |
| 999 | boxaExtendArray(boxa); |
| 1000 | array = boxa->box; |
| 1001 | boxa->n++; |
| 1002 | for (i = n; i > index; i--) |
| 1003 | array[i] = array[i - 1]; |
| 1004 | array[index] = box; |
| 1005 | |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | |
| 1010 | /*! |
no test coverage detected