diff options
Diffstat (limited to 'navit/maptool/itembin.c')
-rw-r--r-- | navit/maptool/itembin.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/navit/maptool/itembin.c b/navit/maptool/itembin.c index 6f1328355..3996d6f6a 100644 --- a/navit/maptool/itembin.c +++ b/navit/maptool/itembin.c @@ -1,4 +1,4 @@ -/** +/* * Navit, a modular navigation system. * Copyright (C) 2005-2011 Navit Team * @@ -226,6 +226,37 @@ void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min item_bin_add_attr(ib, &attr); } +/** + * @brief add a "hole" to an item + * + * This function adds a "hole" (attr_poly_hole) to a map item. It adds the + * coordinates and the coordinate count to the existing item. + * WARNING: It does NOT allocate any memory, so the memory after the item + * must be already allocated for that purpose. + * @param[inout] ib item - to add hole to + * @param[in] coord - hole coordinate array + * @param[in] ccount - number of coordinates in coord + */ +void item_bin_add_hole(struct item_bin * ib, struct coord * coord, int ccount) { + /* get space for next attr in buffer */ + int * buffer = ((int *) ib) + ib->len +1; + /* get the attr heder in binary file */ + struct attr_bin * attr = (struct attr_bin *)buffer; + /* fill header */ + attr->len = (ccount *2) + 2; + attr->type = attr_poly_hole; + /* get the first attr byte in buffer */ + buffer = (int *)(attr +1); + /* for poly_hole, the first 4 bytes are the coordinate count */ + *buffer = ccount; + /* coordinates are behind that */ + buffer ++; + /* copy in the coordinates */ + memcpy(buffer,coord, ccount * sizeof(struct coord)); + /* add the hole to the total size */ + ib->len += attr->len +1; +} + void item_bin_write(struct item_bin *ib, FILE *out) { dbg_assert(fwrite(ib, (ib->len+1)*4, 1, out)==1); } |