Debian Codegraph @

src/common/rcm.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2004 Dizzy
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "common/setup_before.h"
20 #include "common/rcm.h"
21
22 #include <cassert>
23
24 #include "common/xalloc.h"
25 #include "common/elist.h"
26 #include "common/setup_after.h"
27
28 namespace pvpgn
29 {
30
31 extern void rcm_init(t_rcm *rcm)
32 {
33 assert(rcm);
34
35 elist_init(&rcm->refs);
36 rcm->count = 0;
37 }
38
39 extern void rcm_regref_init(t_rcm_regref *regref, t_chref_cb cb, void *data)
40 {
41 assert(regref);
42
43 elist_init(&regref->refs_link);
44 regref->chref = cb;
45 regref->data = data;
46 }
47
48 extern void rcm_get(t_rcm *rcm, t_rcm_regref *regref)
49 {
50 assert(rcm);
51 assert(regref);
52
53 rcm->count++;
54 elist_add_tail(&rcm->refs, &regref->refs_link);
55 }
56
57 extern void rcm_put(t_rcm *rcm, t_rcm_regref *regref)
58 {
59 assert(rcm);
60 assert(regref);
61 assert(rcm->count); /* might use eventlog but I want this stopped fast */
62
63 rcm->count--;
64 elist_del(&regref->refs_link);
65 }
66
67 extern void rcm_chref(t_rcm *rcm, void *newref)
68 {
69 t_elist *curr, *save;
70 t_rcm_regref *regref;
71
72 assert(rcm);
73
74 elist_for_each_safe(curr, &rcm->refs, save) {
75 regref = elist_entry(curr, t_rcm_regref, refs_link);
76 if (regref->chref) regref->chref(regref->data, newref);
77 }
78 }
79
80 }