Graphviz  2.41.20171026.1811
utils.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include <cghdr.h>
15 
16 static Agraph_t *Ag_dictop_G;
17 
18 /* only indirect call through dtopen() is expected */
19 void *agdictobjmem(Dict_t * dict, void * p, size_t size, Dtdisc_t * disc)
20 {
21  Agraph_t *g;
22 
23  NOTUSED(dict);
24  NOTUSED(disc);
25  g = Ag_dictop_G;
26  if (g) {
27  if (p)
28  agfree(g, p);
29  else
30  return agalloc(g, size);
31  } else {
32  if (p)
33  free(p);
34  else
35  return malloc(size);
36  }
37  return NIL(void *);
38 }
39 
40 void agdictobjfree(Dict_t * dict, void * p, Dtdisc_t * disc)
41 {
42  Agraph_t *g;
43 
44  NOTUSED(dict);
45  NOTUSED(disc);
46  g = Ag_dictop_G;
47  if (g)
48  agfree(g, p);
49  else
50  free(p);
51 }
52 
53 Dict_t *agdtopen(Agraph_t * g, Dtdisc_t * disc, Dtmethod_t * method)
54 {
55  Dtmemory_f memf;
56  Dict_t *d;
57 
58  memf = disc->memoryf;
59  disc->memoryf = agdictobjmem;
60  Ag_dictop_G = g;
61  d = dtopen(disc, method);
62  disc->memoryf = memf;
63  Ag_dictop_G = NIL(Agraph_t*);
64  return d;
65 }
66 
67 long agdtdelete(Agraph_t * g, Dict_t * dict, void *obj)
68 {
69  Ag_dictop_G = g;
70  return (long) dtdelete(dict, obj);
71 }
72 
73 int agobjfinalize(void * obj)
74 {
75  agfree(Ag_dictop_G, obj);
76  return 0;
77 }
78 
79 int agdtclose(Agraph_t * g, Dict_t * dict)
80 {
81  Dtmemory_f memf;
82  Dtdisc_t *disc;
83 
84  disc = dtdisc(dict, NIL(Dtdisc_t *), 0);
85  memf = disc->memoryf;
86  disc->memoryf = agdictobjmem;
87  Ag_dictop_G = g;
88  if (dtclose(dict))
89  return 1;
90  disc->memoryf = memf;
91  Ag_dictop_G = NIL(Agraph_t*);
92  return 0;
93 }
94 
95 void agdtdisc(Agraph_t * g, Dict_t * dict, Dtdisc_t * disc)
96 {
97  if (disc && (dtdisc(dict, NIL(Dtdisc_t *), 0) != disc)) {
98  dtdisc(dict, disc, 0);
99  }
100  /* else unchanged, disc is same as old disc */
101 }
void agdtdisc(Agraph_t *g, Dict_t *dict, Dtdisc_t *disc)
Definition: utils.c:95
CDT_API int dtclose(Dt_t *)
int agdtclose(Agraph_t *g, Dict_t *dict)
Definition: utils.c:79
Dtmemory_f memoryf
Definition: cdt.h:88
#define dtdelete(d, o)
Definition: cdt.h:264
CDT_API Dtdisc_t * dtdisc(Dt_t *dt, Dtdisc_t *, int)
Definition: dtdisc.c:22
#define NOTUSED(var)
Definition: cghdr.h:54
Definition: cdt.h:80
int agobjfinalize(void *obj)
Definition: utils.c:73
CGRAPH_API void agfree(Agraph_t *g, void *ptr)
Definition: mem.c:89
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition: dtopen.c:9
#define NIL(t)
Definition: dthdr.h:13
long agdtdelete(Agraph_t *g, Dict_t *dict, void *obj)
Definition: utils.c:67
void *(* Dtmemory_f)(Dt_t *, void *, size_t, Dtdisc_t *)
Definition: cdt.h:36
Dict_t * agdtopen(Agraph_t *g, Dtdisc_t *disc, Dtmethod_t *method)
Definition: utils.c:53
CGRAPH_API void * agalloc(Agraph_t *g, size_t size)
Definition: mem.c:62
void * agdictobjmem(Dict_t *dict, void *p, size_t size, Dtdisc_t *disc)
Definition: utils.c:19
Definition: cdt.h:99
void agdictobjfree(Dict_t *dict, void *p, Dtdisc_t *disc)
Definition: utils.c:40