Debian Codegraph @

src/bnetd/attr.h

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 #ifndef __ATTR_INCLUDED__
20 #define __ATTR_INCLUDED__
21
22 #include "common/elist.h"
23 #include "common/xalloc.h"
24
25 namespace pvpgn
26 {
27
28 namespace bnetd
29 {
30
31 typedef struct attr_struct {
32 const char *key;
33 const char *val;
34 int dirty;
35 t_hlist link;
36 } t_attr;
37
38 static inline t_attr *attr_create(const char *key, const char *val)
39 {
40 t_attr *attr;
41
42 attr = (t_attr*)xmalloc(sizeof(t_attr));
43 attr->dirty = 0;
44 hlist_init(&attr->link);
45 attr->key = key ? xstrdup(key) : NULL;
46 attr->val = val ? xstrdup(val) : NULL;
47
48 return attr;
49 }
50
51 static inline int attr_destroy(t_attr *attr)
52 {
53 if (attr->key) xfree((void*)attr->key);
54 if (attr->val) xfree((void*)attr->val);
55
56 xfree((void*)attr);
57
58 return 0;
59 }
60
61 static inline int attr_get_dirty(t_attr *attr)
62 {
63 return attr->dirty;
64 }
65
66 static inline void attr_clear_dirty(t_attr *attr)
67 {
68 attr->dirty = 0;
69 }
70
71 static inline const char *attr_get_key(t_attr *attr)
72 {
73 return attr->key;
74 }
75
76 static inline const char *attr_get_val(t_attr *attr)
77 {
78 return attr->val;
79 }
80
81 static inline void attr_set_val(t_attr *attr, const char *val)
82 {
83 if (attr->val) xfree((void*)attr->val);
84
85 if (val) attr->val = xstrdup(val);
86 else attr->val = NULL;
87 }
88
89 static inline void attr_set_dirty(t_attr *attr)
90 {
91 attr->dirty = 1;
92 }
93
94 }
95
96 }
97
98 #endif /* __ATTR_H_INCLUDED__ */