Graphviz 13.0.0~dev.20241220.2304
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 v1.0
11 * which accompanies this distribution, and is available at
12 * https://www.eclipse.org/legal/epl-v10.html
13 *
14 * Contributors: Details at https://graphviz.org
15 *************************************************************************/
16
17#include <cgraph/cghdr.h>
18#include <stdbool.h>
19#include <stddef.h>
20#include <util/alloc.h>
21
23{
24 Agraph_t template;
25
27 AGID(&template) = id;
28 return dtsearch(g->g_id, &template);
29}
30
32{
33 Agraph_t *subg;
34
35 subg = agfindsubg_by_id(g, id);
36 if (subg)
37 return subg;
38
39 subg = gv_alloc(sizeof(Agraph_t));
40 subg->clos = g->clos;
41 subg->desc = g->desc;
42 subg->desc.maingraph = false;
43 subg->parent = g;
44 subg->root = g->root;
45 AGID(subg) = id;
46 return agopen1(subg);
47}
48
49Agraph_t *agidsubg(Agraph_t * g, IDTYPE id, int cflag)
50{
51 Agraph_t *subg;
52 subg = agfindsubg_by_id(g, id);
53 if (subg == NULL && cflag && agallocid(g, AGRAPH, id))
54 subg = localsubg(g, id);
55 return subg;
56}
57
58Agraph_t *agsubg(Agraph_t * g, char *name, int cflag)
59{
60 IDTYPE id;
61 Agraph_t *subg;
62
63 if (name && agmapnametoid(g, AGRAPH, name, &id, false)) {
64 /* might already exist */
65 if ((subg = agfindsubg_by_id(g, id)))
66 return subg;
67 }
68
69 if (cflag && agmapnametoid(g, AGRAPH, name, &id, true)) { /* reserve id */
70 subg = localsubg(g, id);
71 agregister(g, AGRAPH, subg);
72 return subg;
73 }
74
75 return NULL;
76}
77
79{
80 return dtfirst(g->g_seq);
81}
82
84{
85 Agraph_t *g;
86
87 g = agparent(subg);
88 return g? dtnext(g->g_seq, subg) : 0;
89}
90
92{
93 return g->parent;
94}
95
96/* this function is only responsible for deleting the entry
97 * in the parent's subg dict. the rest is done in agclose().
98 */
99int agdelsubg(Agraph_t * g, Agraph_t * subg)
100{
101 Agraphs_remove(g_seq2(g), subg);
102 return ( (dtdelete(g->g_seq, subg) != NULL) &&
103 (dtdelete(g->g_id, subg) != NULL) );
104}
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:183
#define dtdelete(d, o)
Definition cdt.h:186
#define dtnext(d, o)
Definition cdt.h:180
#define dtfirst(d)
Definition cdt.h:179
cgraph.h additions
void agdtdisc(Agraph_t *g, Dict_t *dict, Dtdisc_t *disc)
Definition utils.c:42
int agmapnametoid(Agraph_t *g, int objtype, char *str, IDTYPE *result, bool createflag)
Definition id.c:112
Agraph_t * agopen1(Agraph_t *g)
Definition graph.c:68
static Agraphs_t * g_seq2(Agraph_t *g)
Definition cghdr.h:188
int agallocid(Agraph_t *g, int objtype, IDTYPE request)
Definition id.c:141
void agregister(Agraph_t *g, int objtype, void *obj)
Definition id.c:185
Dtdisc_t Ag_subgraph_id_disc
Definition graph.c:279
node NULL
Definition grammar.y:163
#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:91
Agraph_t * agidsubg(Agraph_t *g, IDTYPE id, int cflag)
Definition subg.c:49
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:78
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:83
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition subg.c:58
int agdelsubg(Agraph_t *g, Agraph_t *subg)
Definition subg.c:99
static uint64_t id
Definition gv2gml.c:42
unsigned maingraph
Definition cgraph.h:288
graph or subgraph
Definition cgraph.h:425
Dict_t * g_seq
Definition cgraph.h:433
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:434
Dict_t * g_id
subgraphs - descendants
Definition cgraph.h:433
Agclos_t * clos
shared resources
Definition cgraph.h:435
Agraph_t * parent
Definition cgraph.h:434
Agdesc_t desc
Definition cgraph.h:427
static Agraph_t * agfindsubg_by_id(Agraph_t *g, IDTYPE id)
Definition subg.c:22
static Agraph_t * localsubg(Agraph_t *g, IDTYPE id)
Definition subg.c:31