Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
dtview.c
Go to the documentation of this file.
1#include <cdt/dthdr.h>
2#include <stddef.h>
3
4/* Set a view path from dict to view.
5**
6** Written by Kiem-Phong Vo (5/25/96)
7*/
8
9
10static void* dtvsearch(Dt_t* dt, void* obj, int type)
11{
12 Dt_t *d, *p;
13 void *o = NULL, *n, *ok, *nk;
14 int cmp, lk, sz, ky;
16 (void)lk;
17
18 /* these operations only happen at the top level */
20 return dt->meth->searchf(dt, obj, type);
21
22 if((type&(DT_MATCH|DT_SEARCH)) || /* order sets first/last done below */
23 ((type&(DT_FIRST|DT_LAST)) && !(dt->meth->type&(DT_OBAG|DT_OSET)) ) )
24 { for(d = dt; d; d = d->view)
25 if ((o = d->meth->searchf(d, obj, type)))
26 break;
27 dt->walk = d;
28 return o;
29 }
30
31 if(dt->meth->type & (DT_OBAG|DT_OSET) )
32 { if(!(type & (DT_FIRST|DT_LAST|DT_NEXT|DT_PREV)) )
33 return NULL;
34
35 n = nk = NULL; p = NULL;
36 for(d = dt; d; d = d->view)
37 { if (!(o = d->meth->searchf(d, obj, type)))
38 continue;
39 _DTDSC(d->disc,ky,sz,lk,cmpf);
40 ok = _DTKEY(o,ky,sz);
41
42 if(n) /* get the right one among all dictionaries */
43 { cmp = _DTCMP(ok, nk, cmpf, sz);
44 if(((type & (DT_NEXT|DT_FIRST)) && cmp < 0) ||
45 ((type & (DT_PREV|DT_LAST)) && cmp > 0) )
46 goto a_dj;
47 }
48 else /* looks good for now */
49 { a_dj: p = d;
50 n = o;
51 nk = ok;
52 }
53 }
54
55 dt->walk = p;
56 return n;
57 }
58
59 /* non-ordered methods */
60 if(!(type & (DT_NEXT|DT_PREV)) )
61 return NULL;
62
63 if(!dt->walk || obj != _DTOBJ(dt->walk->data.here, dt->walk->disc->link) )
64 { for(d = dt; d; d = d->view)
65 if ((o = d->meth->searchf(d, obj, DT_SEARCH)))
66 break;
67 dt->walk = d;
68 if(!(obj = o) )
69 return NULL;
70 }
71
72 for (d = dt->walk, obj = d->meth->searchf(d, obj, type);; )
73 { while(obj) /* keep moving until finding an uncovered object */
74 { for(p = dt; ; p = p->view)
75 { if(p == d) /* adjacent object is uncovered */
76 return obj;
77 if (p->meth->searchf(p, obj, DT_SEARCH))
78 break;
79 }
80 obj = d->meth->searchf(d, obj, type);
81 }
82
83 if(!(d = dt->walk = d->view) ) /* move on to next dictionary */
84 return NULL;
85 else if(type&DT_NEXT)
86 obj = d->meth->searchf(d, NULL, DT_FIRST);
87 else obj = d->meth->searchf(d, NULL, DT_LAST);
88 }
89}
90
92{
93 Dt_t* d;
94
95 UNFLATTEN(dt);
96 if(view)
97 { UNFLATTEN(view);
98 if(view->meth != dt->meth) /* must use the same method */
99 return NULL;
100 }
101
102 /* make sure there won't be a cycle */
103 for(d = view; d; d = d->view)
104 if(d == dt)
105 return NULL;
106
107 /* no more viewing lower dictionary */
108 if((d = dt->view) )
109 d->nview -= 1;
110 dt->view = dt->walk = NULL;
111
112 if(!view)
113 { dt->searchf = dt->meth->searchf;
114 return d;
115 }
116
117 /* ok */
118 dt->view = view;
119 dt->searchf = dtvsearch;
120 view->nview += 1;
121
122 return view;
123}
#define DT_MATCH
Definition cdt.h:135
#define _DTKEY(o, ky, sz)
Definition cdt.h:169
#define _DTDSC(dc, ky, sz, lk, cmpf)
Definition cdt.h:165
#define DT_LAST
Definition cdt.h:134
#define DT_OBAG
Definition cdt.h:122
#define DT_PREV
Definition cdt.h:130
#define DT_NEXT
Definition cdt.h:129
int(* Dtcompar_f)(void *, void *)
Definition cdt.h:48
#define DT_SEARCH
Definition cdt.h:128
#define DT_DELETE
Definition cdt.h:127
#define DT_CLEAR
Definition cdt.h:132
#define DT_INSERT
Definition cdt.h:126
#define DT_RENEW
Definition cdt.h:131
#define DT_OSET
Definition cdt.h:121
#define _DTCMP(k1, k2, cmpf, sz)
Definition cdt.h:171
#define _DTOBJ(e, lk)
Definition cdt.h:168
#define DT_FIRST
Definition cdt.h:133
static int cmpf(void *key1, void *key2)
Definition dijkstra.c:81
#define UNFLATTEN(dt)
Definition dthdr.h:27
static void * dtvsearch(Dt_t *dt, void *obj, int type)
Definition dtview.c:10
Dt_t * dtview(Dt_t *dt, Dt_t *view)
Definition dtview.c:91
expr procedure type
Definition exparse.y:208
static int cmp(const void *key, const void *candidate)
node NULL
Definition grammar.y:163
bool ok(Agraph_t *g)
Definition gv.cpp:362
ViewInfo * view
Definition viewport.c:37
Dtlink_t * here
Definition cdt.h:73
Dtsearch_f searchf
Definition cdt.h:66
int type
Definition cdt.h:67
Definition cdt.h:100
Dtmethod_t * meth
Definition cdt.h:103
Dt_t * walk
Definition cdt.h:106
Dtsearch_f searchf
Definition cdt.h:100
Dtdata_t data
sharable data
Definition cdt.h:102
int nview
Definition cdt.h:104
Dtdisc_t * disc
Definition cdt.h:101
Dt_t * view
Definition cdt.h:105
int link
Definition cdt.h:87