Graphviz 15.1.1~dev.20260630.1303
Loading...
Searching...
No Matches
subg.c
Go to the documentation of this file.
1
7/*************************************************************************
8 * Copyright (c) 2011 AT&T Intellectual Property
9 * All rights reserved. This program and the accompanying materials
10 * are made available under the terms of the Eclipse Public License v2.0
11 * which accompanies this distribution, and is available at
12 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
13 *
14 * Contributors: Details at https://graphviz.org
15 *************************************************************************/
16
17#include "config.h"
18
19#include <cgraph/cghdr.h>
20#include <stdbool.h>
21#include <stddef.h>
22#include <util/alloc.h>
23
25{
27 return dtsearch(g->g_id, &(Agraph_t){.base = {.tag = {.id = id}}});
28}
29
31{
32 Agraph_t *subg;
33
34 subg = agfindsubg_by_id(g, id);
35 if (subg)
36 return subg;
37
38 subg = gv_alloc(sizeof(Agraph_t));
39 subg->clos = g->clos;
40 subg->desc = g->desc;
41 subg->desc.maingraph = false;
42 subg->parent = g;
43 subg->root = g->root;
44 AGID(subg) = id;
45 return agopen1(subg);
46}
47
49 return agfindsubg_by_id(g, id);
50}
51
52Agraph_t *agsubg(Agraph_t * g, char *name, int cflag)
53{
54 IDTYPE id;
55 Agraph_t *subg;
56
57 if (name && agmapnametoid(g, AGRAPH, name, &id, false)) {
58 /* might already exist */
59 if ((subg = agfindsubg_by_id(g, id)))
60 return subg;
61 }
62
63 if (cflag && agmapnametoid(g, AGRAPH, name, &id, true)) { /* reserve id */
64 subg = localsubg(g, id);
65 agregister(g, AGRAPH, subg);
66 return subg;
67 }
68
69 return NULL;
70}
71
73{
74 return dtfirst(g->g_seq);
75}
76
78{
79 Agraph_t *g;
80
81 g = agparent(subg);
82 return g? dtnext(g->g_seq, subg) : 0;
83}
84
86{
87 return g->parent;
88}
89
90/* this function is only responsible for deleting the entry
91 * in the parent's subg dict. the rest is done in agclose().
92 */
93int agdelsubg(Agraph_t * g, Agraph_t * subg)
94{
95 return dtdelete(g->g_seq, subg) != NULL && dtdelete(g->g_id, subg) != NULL;
96}
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define dtsearch(d, o)
Definition cdt.h:184
#define dtdelete(d, o)
Definition cdt.h:187
#define dtnext(d, o)
Definition cdt.h:181
#define dtfirst(d)
Definition cdt.h:180
cgraph.h additions
int agmapnametoid(Agraph_t *g, int objtype, char *str, IDTYPE *result, bool createflag)
Definition id.c:104
Agraph_t * agopen1(Agraph_t *g)
Definition graph.c:68
void agregister(Agraph_t *g, int objtype, void *obj)
Definition id.c:172
void agdtdisc(Dict_t *dict, Dtdisc_t *disc)
Definition utils.c:32
Dtdisc_t Ag_subgraph_id_disc
Definition graph.c:269
node NULL
Definition grammar.y:181
#define AGID(obj)
returns the unique integer ID associated with the object
Definition cgraph.h:221
uint64_t IDTYPE
unique per main graph ID
Definition cgraph.h:73
@ AGRAPH
Definition cgraph.h:207
Agraph_t * agparent(Agraph_t *g)
Definition subg.c:85
Agraph_t * agidsubg(Agraph_t *g, IDTYPE id)
constructor
Definition subg.c:48
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:72
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:77
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition subg.c:52
int agdelsubg(Agraph_t *g, Agraph_t *subg)
Definition subg.c:93
static uint64_t id
Definition gv2gml.c:42
unsigned maingraph
Definition cgraph.h:288
graph or subgraph
Definition cgraph.h:424
Dict_t * g_seq
Definition cgraph.h:432
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:433
Dict_t * g_id
subgraphs - descendants
Definition cgraph.h:432
Agclos_t * clos
shared resources
Definition cgraph.h:434
Agraph_t * parent
Definition cgraph.h:433
Agdesc_t desc
Definition cgraph.h:426
static Agraph_t * agfindsubg_by_id(Agraph_t *g, IDTYPE id)
Definition subg.c:24
static Agraph_t * localsubg(Agraph_t *g, IDTYPE id)
Definition subg.c:30