From 8b8049807fd3b206a174f8a0bf8eb5cfcef44180 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 25 Dec 2021 11:09:15 -0800 Subject: [PATCH] lib/sparse: add guards, making headers safe to include from C++ An upcoming change will convert cmd/mingle/minglemain.c to C++, which transitively includes some of these headers. Related to #2154. --- lib/sparse/BinaryHeap.h | 8 ++++++++ lib/sparse/DotIO.h | 8 ++++++++ lib/sparse/IntStack.h | 8 ++++++++ lib/sparse/LinkedList.h | 8 ++++++++ lib/sparse/QuadTree.h | 8 ++++++++ lib/sparse/SparseMatrix.h | 8 ++++++++ lib/sparse/clustering.h | 8 ++++++++ lib/sparse/color_palette.h | 9 +++++++++ lib/sparse/colorutil.h | 8 ++++++++ lib/sparse/general.h | 8 ++++++++ lib/sparse/mq.h | 8 ++++++++ lib/sparse/vector.h | 9 +++++++++ 12 files changed, 98 insertions(+) diff --git a/lib/sparse/BinaryHeap.h b/lib/sparse/BinaryHeap.h index 462043f45..d634aa87e 100644 --- a/lib/sparse/BinaryHeap.h +++ b/lib/sparse/BinaryHeap.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* binary heap code. Caution: items inserted should be kept untouched, e.g., the value of the item should be kepted unchanged while the heap is still in use! To change the valud of am item, use BinaryHeap_reset @@ -70,3 +74,7 @@ size_t BinaryHeap_reset(BinaryHeap h, int id, void *item);/* reset value of an i void BinaryHeap_print(BinaryHeap h, void (*pnt)(void*)); void BinaryHeap_sanity_check(BinaryHeap h); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/DotIO.h b/lib/sparse/DotIO.h index fd20204a2..f14a74d05 100644 --- a/lib/sparse/DotIO.h +++ b/lib/sparse/DotIO.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + enum {COLOR_SCHEME_NONE, COLOR_SCHEME_PASTEL = 1, COLOR_SCHEME_BLUE_YELLOW, COLOR_SCHEME_WHITE_RED, COLOR_SCHEME_GREY_RED, COLOR_SCHEME_PRIMARY, COLOR_SCHEME_SEQUENTIAL_SINGLEHUE_RED, COLOR_SCHEME_ADAM, COLOR_SCHEME_ADAM_BLEND, COLOR_SCHEME_SEQUENTIAL_SINGLEHUE_RED_LIGHTER, COLOR_SCHEME_GREY}; extern void initDotIO (Agraph_t *g); @@ -31,3 +35,7 @@ void Dot_SetClusterColor(Agraph_t* g, float *rgb_r, float *rgb_g, float *rgb_b void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme); int Import_dot_splines(Agraph_t* g, int *ne, char ***xsplines); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/IntStack.h b/lib/sparse/IntStack.h index 03e1de2f7..68a219d07 100644 --- a/lib/sparse/IntStack.h +++ b/lib/sparse/IntStack.h @@ -12,6 +12,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* last in first out integer stack */ struct IntStack_struct{ size_t last; // position of the last element, If empty, last = SIZE_MAX @@ -33,3 +37,7 @@ size_t IntStack_push(IntStack s, int i); // add an item and return the pos int IntStack_pop(IntStack s, int *flag);/* remove the last item. If none exist, flag = -1, and return -1. */ void IntStack_print(IntStack s); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/LinkedList.h b/lib/sparse/LinkedList.h index 488dff5a7..0c098d9d0 100644 --- a/lib/sparse/LinkedList.h +++ b/lib/sparse/LinkedList.h @@ -10,6 +10,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + typedef struct SingleLinkedList_struct* SingleLinkedList; struct SingleLinkedList_struct { @@ -47,3 +51,7 @@ void* DoubleLinkedList_get_data(DoubleLinkedList l); DoubleLinkedList DoubleLinkedList_get_next(DoubleLinkedList l); void DoubleLinkedList_delete_element(DoubleLinkedList l, void (*linklist_deallocator)(void*), DoubleLinkedList *head); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/QuadTree.h b/lib/sparse/QuadTree.h index 90d2cbe51..4fd52bd4b 100644 --- a/lib/sparse/QuadTree.h +++ b/lib/sparse/QuadTree.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct QuadTree_struct *QuadTree; struct QuadTree_struct { @@ -55,3 +59,7 @@ void QuadTree_get_repulsive_force(QuadTree qt, double *force, double *x, double void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min, int *flag); QuadTree QuadTree_new_in_quadrant(int dim, double *center, double width, int max_level, int i); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/SparseMatrix.h b/lib/sparse/SparseMatrix.h index 609391350..2fbc1c6d4 100644 --- a/lib/sparse/SparseMatrix.h +++ b/lib/sparse/SparseMatrix.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define SYMMETRY_EPSILON 0.0000001 enum {FORMAT_CSC, FORMAT_CSR, FORMAT_COORD}; enum {UNMASKED = -10, MASKED = 1}; @@ -113,3 +117,7 @@ SparseMatrix SparseMatrix_from_dense(int m, int n, double *x); #define SparseMatrix_known_undirected(A) test_flag((A)->property, MATRIX_UNDIRECTED) #define SparseMatrix_known_symmetric(A) test_flag((A)->property, MATRIX_SYMMETRIC) #define SparseMatrix_known_strucural_symmetric(A) test_flag((A)->property, MATRIX_PATTERN_SYMMETRIC) + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/clustering.h b/lib/sparse/clustering.h index a8db9eece..1606cb047 100644 --- a/lib/sparse/clustering.h +++ b/lib/sparse/clustering.h @@ -10,6 +10,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + typedef struct Multilevel_Modularity_Clustering_struct *Multilevel_Modularity_Clustering; struct Multilevel_Modularity_Clustering_struct { @@ -49,3 +53,7 @@ enum {CLUSTERING_MODULARITY = 0, CLUSTERING_MQ}; */ void modularity_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, int *nclusters, int **assignment, double *modularity, int *flag); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/color_palette.h b/lib/sparse/color_palette.h index f77a918b3..778cf3c7a 100644 --- a/lib/sparse/color_palette.h +++ b/lib/sparse/color_palette.h @@ -11,6 +11,11 @@ #pragma once #include "stdio.h" + +#ifdef __cplusplus +extern "C" { +#endif + enum {MAX_COLOR = 1001}; enum {npalettes = 265}; @@ -31,3 +36,7 @@ extern float palette_sequential_singlehue_red[1001][3]; extern float palette_sequential_singlehue_red_lighter[1001][3]; extern float palette_adam_blend[1001][3]; extern float palette_adam[11][3]; + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/colorutil.h b/lib/sparse/colorutil.h index 981eca407..83c91924d 100644 --- a/lib/sparse/colorutil.h +++ b/lib/sparse/colorutil.h @@ -12,9 +12,17 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + extern int colorxlate(char *str, gvcolor_t * color, color_type_t target_type); void rgb2hex(float r, float g, float b, char *cstring, const char* opacity); /* dimension of cstring must be >=7 */ char* hue2rgb(double hue, char *color); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/general.h b/lib/sparse/general.h index bf0ea12d1..9990a4c94 100644 --- a/lib/sparse/general.h +++ b/lib/sparse/general.h @@ -27,6 +27,10 @@ #include #endif /* STANDALONE */ +#ifdef __cplusplus +extern "C" { +#endif + #define set_flag(a, flag) ((a)=((a)|(flag))) #define test_flag(a, flag) ((a)&(flag)) #define clear_flag(a, flag) ((a) &=(~(flag))) @@ -114,3 +118,7 @@ double point_distance(double *p1, double *p2, int dim); char *strip_dir(char *s); void scale_to_box(double xmin, double ymin, double xmax, double ymax, int n, int dim, double *x); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/mq.h b/lib/sparse/mq.h index 5563e0002..fb57eec34 100644 --- a/lib/sparse/mq.h +++ b/lib/sparse/mq.h @@ -10,6 +10,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + typedef struct Multilevel_MQ_Clustering_struct *Multilevel_MQ_Clustering; struct Multilevel_MQ_Clustering_struct { @@ -55,3 +59,7 @@ struct Multilevel_MQ_Clustering_struct { */ void mq_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, int *nclusters, int **assignment, double *mq, int *flag); + +#ifdef __cplusplus +} +#endif diff --git a/lib/sparse/vector.h b/lib/sparse/vector.h index 80248b160..9b2b0d84b 100644 --- a/lib/sparse/vector.h +++ b/lib/sparse/vector.h @@ -11,6 +11,11 @@ #pragma once #include + +#ifdef __cplusplus +extern "C" { +#endif + struct vector_struct { int maxlen; int len; @@ -35,3 +40,7 @@ void* Vector_get(Vector v, int i); int Vector_get_length(Vector v); Vector Vector_reset(Vector v, void *stuff, int i); + +#ifdef __cplusplus +} +#endif -- 2.40.0