Commit | Line | Data |
---|---|---|
231a4ea8 | 1 | /* Copyright (C) 1995,1996, 2000, 2001, 2003 Free Software Foundation, Inc. |
0f2d19dd | 2 | * |
73be1d9e MV |
3 | * This library is free software; you can redistribute it and/or |
4 | * modify it under the terms of the GNU Lesser General Public | |
5 | * License as published by the Free Software Foundation; either | |
6 | * version 2.1 of the License, or (at your option) any later version. | |
0f2d19dd | 7 | * |
73be1d9e MV |
8 | * This library is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * Lesser General Public License for more details. | |
0f2d19dd | 12 | * |
73be1d9e MV |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with this library; if not, write to the Free Software | |
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | */ | |
1bbd0b84 | 17 | |
1bbd0b84 | 18 | |
0f2d19dd JB |
19 | \f |
20 | ||
a0599745 MD |
21 | #include "libguile/_scm.h" |
22 | #include "libguile/hashtab.h" | |
23 | #include "libguile/alist.h" | |
24 | #include "libguile/root.h" | |
25 | #include "libguile/weaks.h" | |
0f2d19dd | 26 | |
a0599745 | 27 | #include "libguile/objprop.h" |
0f2d19dd JB |
28 | \f |
29 | ||
30 | /* {Object Properties} | |
31 | */ | |
32 | ||
3b3b36dd | 33 | SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0, |
1bbd0b84 | 34 | (SCM obj), |
b380b885 | 35 | "Return @var{obj}'s property list.") |
1bbd0b84 | 36 | #define FUNC_NAME s_scm_object_properties |
0f2d19dd | 37 | { |
8ba7a00b | 38 | return scm_hashq_ref (scm_object_whash, obj, SCM_EOL); |
0f2d19dd | 39 | } |
1bbd0b84 | 40 | #undef FUNC_NAME |
0f2d19dd JB |
41 | |
42 | ||
3b3b36dd | 43 | SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0, |
1e6808ea | 44 | (SCM obj, SCM alist), |
b380b885 | 45 | "Set @var{obj}'s property list to @var{alist}.") |
1bbd0b84 | 46 | #define FUNC_NAME s_scm_set_object_properties_x |
0f2d19dd | 47 | { |
1e6808ea MG |
48 | SCM handle = scm_hashq_create_handle_x (scm_object_whash, obj, alist); |
49 | SCM_SETCDR (handle, alist); | |
50 | return alist; | |
0f2d19dd | 51 | } |
1bbd0b84 | 52 | #undef FUNC_NAME |
0f2d19dd | 53 | |
3b3b36dd | 54 | SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0, |
1bbd0b84 | 55 | (SCM obj, SCM key), |
b380b885 | 56 | "Return the property of @var{obj} with name @var{key}.") |
1bbd0b84 | 57 | #define FUNC_NAME s_scm_object_property |
0f2d19dd JB |
58 | { |
59 | SCM assoc; | |
332ab360 | 60 | assoc = scm_assq (key, scm_object_properties (obj)); |
0f2d19dd JB |
61 | return (SCM_NIMP (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F); |
62 | } | |
1bbd0b84 | 63 | #undef FUNC_NAME |
0f2d19dd | 64 | |
3b3b36dd | 65 | SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0, |
1e6808ea | 66 | (SCM obj, SCM key, SCM value), |
1e6808ea MG |
67 | "In @var{obj}'s property list, set the property named @var{key}\n" |
68 | "to @var{value}.") | |
1bbd0b84 | 69 | #define FUNC_NAME s_scm_set_object_property_x |
0f2d19dd JB |
70 | { |
71 | SCM h; | |
72 | SCM assoc; | |
73 | h = scm_hashq_create_handle_x (scm_object_whash, obj, SCM_EOL); | |
74 | SCM_DEFER_INTS; | |
e869585c | 75 | assoc = scm_assq (key, SCM_CDR (h)); |
0f2d19dd | 76 | if (SCM_NIMP (assoc)) |
1e6808ea | 77 | SCM_SETCDR (assoc, value); |
0f2d19dd JB |
78 | else |
79 | { | |
1e6808ea | 80 | assoc = scm_acons (key, value, SCM_CDR (h)); |
0f2d19dd JB |
81 | SCM_SETCDR (h, assoc); |
82 | } | |
83 | SCM_ALLOW_INTS; | |
1e6808ea | 84 | return value; |
0f2d19dd | 85 | } |
1bbd0b84 | 86 | #undef FUNC_NAME |
0f2d19dd | 87 | |
1cc91f1b | 88 | |
0f2d19dd JB |
89 | void |
90 | scm_init_objprop () | |
0f2d19dd | 91 | { |
231a4ea8 | 92 | scm_object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED); |
a0599745 | 93 | #include "libguile/objprop.x" |
0f2d19dd JB |
94 | } |
95 | ||
89e00824 ML |
96 | |
97 | /* | |
98 | Local Variables: | |
99 | c-file-style: "gnu" | |
100 | End: | |
101 | */ |