]> granicus.if.org Git - graphviz/commitdiff
outline dynamic box array logic into a header
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 24 Nov 2022 17:52:01 +0000 (09:52 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 30 Nov 2022 04:15:50 +0000 (20:15 -0800)
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

lib/common/CMakeLists.txt
lib/common/Makefile.am
lib/common/boxes.h [new file with mode: 0644]
lib/dotgen/dotsplines.c
lib/gvc.vcxproj
lib/gvc.vcxproj.filters

index 796ed42974058b58db06b2e9830ae3a3a508f04f..1b417bf1e787c8057765f97cfa732f29ab39d497 100644 (file)
@@ -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
index cdd0b60ba038279f8bfb781616094c87e4df46f5..8d3e1e5c8cd00ccf7ddcee3d8cb19d4a9527e0fc 100644 (file)
@@ -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 (file)
index 0000000..c8885a8
--- /dev/null
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <assert.h>
+#include <common/geom.h>
+#include <common/memory.h>
+#include <stdlib.h>
+#include <string.h>
+
+// 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));
+}
index fa917c5cd3a84d5cf50c764f252262695ca0a98d..5f740c35adbef574734b69dec6854be51a16e1a7 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <assert.h>
 #include <cgraph/alloc.h>
+#include <common/boxes.h>
 #include <dotgen/dot.h>
 #include <limits.h>
 #include <math.h>
        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;
index 5a0c446fa7e801dece41fc49f1d91bdcafec92ec..77aec363529bd287027fb6fd6e1842be6aa94f91 100644 (file)
@@ -112,6 +112,7 @@ python common\make_colortbl.py common\brewer_lib common\svgcolor_lib common\colo
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClInclude Include="common\arith.h" />
+    <ClInclude Include="common\boxes.h" />
     <ClInclude Include="common\color.h" />
     <ClInclude Include="common\colorprocs.h" />
     <ClInclude Include="common\colortbl.h" />
index c054d5aee5bb1b612491b6a8cca3c81f366b9b9c..9451332d829f0f4f3f32483723c202ddaf5f55c5 100644 (file)
@@ -18,6 +18,9 @@
     <ClInclude Include="common\arith.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="common\boxes.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="common\color.h">
       <Filter>Header Files</Filter>
     </ClInclude>