cghdr.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * @file
  3. * @brief cgraph.h additions
  4. * @ingroup core
  5. */
  6. /*************************************************************************
  7. * Copyright (c) 2011 AT&T Intellectual Property
  8. * All rights reserved. This program and the accompanying materials
  9. * are made available under the terms of the Eclipse Public License v1.0
  10. * which accompanies this distribution, and is available at
  11. * https://www.eclipse.org/legal/epl-v10.html
  12. *
  13. * Contributors: Details at https://graphviz.org
  14. *************************************************************************/
  15. #pragma once
  16. #include "config.h"
  17. #ifdef GVDLL
  18. #ifdef EXPORT_CGHDR
  19. #define CGHDR_API __declspec(dllexport)
  20. #else
  21. #define CGHDR_API __declspec(dllimport)
  22. #endif
  23. #endif
  24. #ifndef CGHDR_API
  25. #define CGHDR_API /* nothing */
  26. #endif
  27. #include <cgraph.h>
  28. #include <cgraph/list.h>
  29. #include <ctype.h>
  30. #include <sys/types.h>
  31. #include <stdarg.h>
  32. #include <stdbool.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <assert.h>
  36. #include <stdint.h>
  37. #define SUCCESS 0
  38. #define FAILURE -1
  39. #define LOCALNAMEPREFIX '%'
  40. #define AGDISC(g,d) ((g)->clos->disc.d)
  41. #define AGCLOS(g,d) ((g)->clos->state.d)
  42. #define AGNEW(g,t) ((t*)(agalloc(g,sizeof(t))))
  43. /* functional definitions */
  44. typedef Agobj_t *(*agobjsearchfn_t) (Agraph_t * g, Agobj_t * obj);
  45. CGHDR_API int agapply(Agraph_t * g, Agobj_t * obj, agobjfn_t fn, void *arg,
  46. int preorder);
  47. /* global variables */
  48. extern Agraph_t *Ag_G_global;
  49. extern char *AgDataRecName;
  50. /* set ordering disciplines */
  51. extern Dtdisc_t Ag_subnode_seq_disc;
  52. extern Dtdisc_t Ag_mainedge_id_disc;
  53. extern Dtdisc_t Ag_subedge_id_disc;
  54. extern Dtdisc_t Ag_mainedge_seq_disc;
  55. extern Dtdisc_t Ag_subedge_seq_disc;
  56. extern Dtdisc_t Ag_subgraph_id_disc;
  57. extern Dtdisc_t Ag_subgraph_seq_disc;
  58. /* internal constructor of graphs and subgraphs */
  59. Agraph_t *agopen1(Agraph_t * g);
  60. int agstrclose(Agraph_t * g);
  61. /* ref string management */
  62. void agmarkhtmlstr(char *s);
  63. /// Mask of `Agtag_s.seq` width
  64. enum { SEQ_MASK = (1 << (sizeof(unsigned) * 8 - 4)) - 1 };
  65. /* object set management */
  66. Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id);
  67. uint64_t agnextseq(Agraph_t * g, int objtype);
  68. /* dict helper functions */
  69. Dict_t *agdtopen(Agraph_t * g, Dtdisc_t * disc, Dtmethod_t * method);
  70. void agdtdisc(Agraph_t * g, Dict_t * dict, Dtdisc_t * disc);
  71. int agdtdelete(Agraph_t * g, Dict_t * dict, void *obj);
  72. int agdtclose(Agraph_t * g, Dict_t * dict);
  73. void agdictobjfree(void *p);
  74. /** @addtogroup cgraph_attr
  75. * @{
  76. */
  77. /* name-value pair operations */
  78. CGHDR_API Agdatadict_t *agdatadict(Agraph_t *g, bool cflag);
  79. CGHDR_API Agattr_t *agattrrec(void *obj);
  80. void agraphattr_init(Agraph_t * g);
  81. int agraphattr_delete(Agraph_t * g);
  82. void agnodeattr_init(Agraph_t *g, Agnode_t * n);
  83. void agnodeattr_delete(Agnode_t * n);
  84. void agedgeattr_init(Agraph_t *g, Agedge_t * e);
  85. void agedgeattr_delete(Agedge_t * e);
  86. /// @}
  87. /* parsing and lexing graph files
  88. *
  89. * aagscan_t is opaque, because it is generated
  90. * by flex based on scan.l.
  91. * See https://westes.github.io/flex/manual/About-yyscan_005ft.html
  92. */
  93. typedef void *aagscan_t;
  94. typedef struct aagextra_s aagextra_t;
  95. int aagparse(void);
  96. void aglexinit(Agdisc_t * disc, void *ifile);
  97. int aaglex(void);
  98. void aglexeof(void);
  99. void aglexbad(void);
  100. /* ID management */
  101. int agmapnametoid(Agraph_t *g, int objtype, char *str, IDTYPE *result,
  102. bool createflag);
  103. int agallocid(Agraph_t * g, int objtype, IDTYPE request);
  104. void agfreeid(Agraph_t * g, int objtype, IDTYPE id);
  105. char *agprintid(Agobj_t * obj);
  106. bool aginternalmaplookup(Agraph_t *g, int objtype, char *str, IDTYPE *result);
  107. void aginternalmapinsert(Agraph_t * g, int objtype, char *str,
  108. IDTYPE result);
  109. char *aginternalmapprint(Agraph_t * g, int objtype, IDTYPE id);
  110. int aginternalmapdelete(Agraph_t * g, int objtype, IDTYPE id);
  111. void aginternalmapclose(Agraph_t * g);
  112. void agregister(Agraph_t * g, int objtype, void *obj);
  113. /* internal set operations */
  114. void agedgesetop(Agraph_t * g, Agedge_t * e, int insertion);
  115. void agdelnodeimage(Agraph_t * g, Agnode_t * node, void *ignored);
  116. void agdeledgeimage(Agraph_t * g, Agedge_t * edge, void *ignored);
  117. CGHDR_API int agrename(Agobj_t * obj, char *newname);
  118. void agrecclose(Agobj_t * obj);
  119. /// @addtogroup cgraph_callback
  120. /// @{
  121. void agmethod_init(Agraph_t * g, void *obj);
  122. void agmethod_upd(Agraph_t * g, void *obj, Agsym_t * sym);
  123. void agmethod_delete(Agraph_t * g, void *obj);
  124. void aginitcb(Agraph_t * g, void *obj, Agcbstack_t * disc);
  125. void agupdcb(Agraph_t * g, void *obj, Agsym_t * sym, Agcbstack_t * disc);
  126. void agdelcb(Agraph_t * g, void *obj, Agcbstack_t * disc);
  127. /// @}
  128. DEFINE_LIST(Agraphs, Agraph_t *)
  129. /// two alternative representations of a graph collection
  130. ///
  131. /// The subgraphs of a graph have traditionally been stored in a `Dt_t`. However
  132. /// it is much faster to iterate through a C array of the subgraphs instead of a
  133. /// cdt tree of them. To preserve backwards compatibility, we maintain both:
  134. ///
  135. /// what the cgraph.h user sees: what we see internally:
  136. ///
  137. /// Agraph_t Agraph_t
  138. /// ┌─────────┐ ┌─────────┐
  139. /// │ … │ │ … │
  140. /// ├─────────┤ ┌───────────┐ ├─────────┤ ┌───────────┐
  141. /// │ g_seq ─┼───►│ Dt_t │ │ g_seq ─┼───►│ Dt_t │
  142. /// ├─────────┤ └───────────┘ ├─────────┤ ├───────────┤
  143. /// │ … │ │ … │ │ Agraphs_t │
  144. /// └───────────┘
  145. ///
  146. /// To facilitate this, `g_seq2` can be used to access the second
  147. /// representation.
  148. typedef struct {
  149. Dt_t legacy; ///< the traditional tree of subgraphs
  150. Agraphs_t linear; ///< the newer contiguous collection
  151. } g_seq_t;
  152. /// access the list of subgraphs of a graph
  153. ///
  154. /// See `g_seq_t` for an extended explanation of this.
  155. ///
  156. /// @param g The parent graph to inspect
  157. /// @return A generic list of the subgraphs
  158. static inline Agraphs_t *g_seq2(Agraph_t *g) {
  159. g_seq_t *seq = (g_seq_t *)g->g_seq;
  160. return &seq->linear;
  161. }