1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* $Id:$ */
/*
libg3d - 3D object loading library
Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "imp_dxf_types.h"
struct _DxfEntityProps {
GHashTable *hash;
};
typedef struct {
gint32 key;
DxfChunkType type;
union {
gint32 ival;
gdouble dval;
gchar *strval;
} u;
} DxfEProp;
DxfEntityProps *dxf_prop_create(void)
{
DxfEntityProps *eprop;
eprop = g_new0(DxfEntityProps, 1);
eprop->hash = g_hash_table_new(g_int_hash, g_int_equal);
return eprop;
}
static gboolean remove_p(gpointer key, gpointer value, gpointer user_data)
{
DxfEProp *p = value;
if(p->type == DXF_T_STRING)
g_free(p->u.strval);
g_free(p);
return TRUE;
}
void dxf_prop_cleanup(DxfEntityProps *eprop)
{
g_hash_table_foreach_remove(eprop->hash, remove_p, NULL);
g_hash_table_destroy(eprop->hash);
g_free(eprop);
}
static DxfEProp *prop_get(DxfEntityProps *eprop, gint32 key)
{
DxfEProp *p;
p = g_hash_table_lookup(eprop->hash, &key);
if(p)
return p;
p = g_new0(DxfEProp, 1);
p->key = key;
g_hash_table_insert(eprop->hash, &(p->key), p);
return p;
}
gboolean dxf_prop_set_int(DxfEntityProps *eprop, gint32 key, gint32 i)
{
DxfEProp *p = prop_get(eprop, key);
p->type = DXF_T_INT32;
p->u.ival = i;
return TRUE;
}
gboolean dxf_prop_set_dbl(DxfEntityProps *eprop, gint32 key, gdouble dbl)
{
DxfEProp *p = prop_get(eprop, key);
p->type = DXF_T_FLOAT64;
p->u.dval = dbl;
return TRUE;
}
gboolean dxf_prop_set_str(DxfEntityProps *eprop, gint32 key,
const gchar *str)
{
DxfEProp *p = prop_get(eprop, key);
p->type = DXF_T_STRING;
if(p->u.strval)
g_free(p->u.strval);
p->u.strval = g_strdup(str);
return TRUE;
}
gint32 dxf_prop_get_int(DxfEntityProps *eprop, gint32 key, gint32 dfl)
{
DxfEProp *p = g_hash_table_lookup(eprop->hash, &key);
if(p)
return p->u.ival;
return dfl;
}
gdouble dxf_prop_get_dbl(DxfEntityProps *eprop, gint32 key, gdouble dfl)
{
DxfEProp *p = g_hash_table_lookup(eprop->hash, &key);
if(p)
return p->u.dval;
return dfl;
}
const gchar *dxf_prop_get_str(DxfEntityProps *eprop, gint32 key,
const gchar *dfl)
{
DxfEProp *p = g_hash_table_lookup(eprop->hash, &key);
if(p)
return p->u.strval;
return dfl;
}
|