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