From: Matthew Fernandez Date: Thu, 24 Nov 2022 17:52:01 +0000 (-0800) Subject: outline dynamic box array logic into a header X-Git-Tag: 7.0.4~2^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a29c81b8f045df073a969938dfbf17dc978d10dd;p=graphviz outline dynamic box array logic into a header This is not great practice, putting functions like this into a header. But this is a stepping stone to reusing this code in lib/ortho and it seems cleaner than trying to manage yet another set of partially exported symbols. Gitlab: #56 --- diff --git a/lib/common/CMakeLists.txt b/lib/common/CMakeLists.txt index 796ed4297..1b417bf1e 100644 --- a/lib/common/CMakeLists.txt +++ b/lib/common/CMakeLists.txt @@ -41,6 +41,7 @@ add_custom_command( add_library(common_obj OBJECT # Header files arith.h + boxes.h color.h colorprocs.h ${CMAKE_CURRENT_BINARY_DIR}/common/colortbl.h diff --git a/lib/common/Makefile.am b/lib/common/Makefile.am index cdd0b60ba..8d3e1e5c8 100644 --- a/lib/common/Makefile.am +++ b/lib/common/Makefile.am @@ -18,7 +18,7 @@ endif BUILT_SOURCES = colortbl.h htmlparse.h pkginclude_HEADERS = arith.h geom.h color.h types.h textspan.h usershape.h -noinst_HEADERS = render.h utils.h memory.h \ +noinst_HEADERS = boxes.h render.h utils.h memory.h \ geomprocs.h colorprocs.h colortbl.h entities.h globals.h \ const.h macros.h htmllex.h htmltable.h pointset.h intset.h \ textspan_lut.h ps_font_equiv.h diff --git a/lib/common/boxes.h b/lib/common/boxes.h new file mode 100644 index 000000000..c8885a81c --- /dev/null +++ b/lib/common/boxes.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include +#include +#include + +// a dynamically expanding array of boxes +typedef struct { + boxf *data; + size_t size; + size_t capacity; +} boxes_t; + +/** Add an entry to the end of a boxes array. + * + * This may expand the array if it is not already large enough to contain the + * new element. + * + * \param boxes Array to append to. + * \param item Element to append. + */ +static inline void boxes_append(boxes_t *boxes, boxf item) { + + assert(boxes != NULL); + + // do we need to expand the array? + if (boxes->size == boxes->capacity) { + size_t c = boxes->capacity == 0 ? 128 : (boxes->capacity * 2); + boxes->data = grealloc(boxes->data, c * sizeof(boxes->data[0])); + boxes->capacity = c; + } + + boxes->data[boxes->size] = item; + ++boxes->size; +} + +/** Remove all entries from a boxes array. + * + * \param boxes Array to clear. + */ +static inline void boxes_clear(boxes_t *boxes) { + assert(boxes != NULL); + boxes->size = 0; +} + +/** Deallocate memory associated with a boxes array. + * + * Following a call to this function, the array is reusable as if it had just + * been initialized. + * + * \param boxes Array to deallocate. + */ +static inline void boxes_free(boxes_t *boxes) { + assert(boxes != NULL); + free(boxes->data); + memset(boxes, 0, sizeof(*boxes)); +} diff --git a/lib/dotgen/dotsplines.c b/lib/dotgen/dotsplines.c index fa917c5cd..5f740c35a 100644 --- a/lib/dotgen/dotsplines.c +++ b/lib/dotgen/dotsplines.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -55,58 +56,6 @@ ED_to_orig(newp) = old; \ } -// a dynamically expanding array of boxes -typedef struct { - boxf *data; - size_t size; - size_t capacity; -} boxes_t; - -/** Add an entry to the end of a boxes array. - * - * This may expand the array if it is not already large enough to contain the - * new element. - * - * \param boxes Array to append to. - * \param item Element to append. - */ -static void boxes_append(boxes_t *boxes, boxf item) { - - assert(boxes != NULL); - - // do we need to expand the array? - if (boxes->size == boxes->capacity) { - size_t c = boxes->capacity == 0 ? 128 : (boxes->capacity * 2); - boxes->data = grealloc(boxes->data, c * sizeof(boxes->data[0])); - boxes->capacity = c; - } - - boxes->data[boxes->size] = item; - ++boxes->size; -} - -/** Remove all entries from a boxes array. - * - * \param boxes Array to clear. - */ -static void boxes_clear(boxes_t *boxes) { - assert(boxes != NULL); - boxes->size = 0; -} - -/** Deallocate memory associated with a boxes array. - * - * Following a call to this function, the array is reusable as if it had just - * been initialized. - * - * \param boxes Array to deallocate. - */ -static void boxes_free(boxes_t *boxes) { - assert(boxes != NULL); - free(boxes->data); - memset(boxes, 0, sizeof(*boxes)); -} - typedef struct { int LeftBound, RightBound, Splinesep, Multisep; boxf* Rank_box; diff --git a/lib/gvc.vcxproj b/lib/gvc.vcxproj index 5a0c446fa..77aec3635 100644 --- a/lib/gvc.vcxproj +++ b/lib/gvc.vcxproj @@ -112,6 +112,7 @@ python common\make_colortbl.py common\brewer_lib common\svgcolor_lib common\colo + diff --git a/lib/gvc.vcxproj.filters b/lib/gvc.vcxproj.filters index c054d5aee..9451332d8 100644 --- a/lib/gvc.vcxproj.filters +++ b/lib/gvc.vcxproj.filters @@ -18,6 +18,9 @@ Header Files + + Header Files + Header Files