Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.
[bpt/guile.git] / libguile / objprop.c
1 /* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008 Free Software Foundation, Inc.
2 *
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.
7 *
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.
12 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18
19 \f
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include "libguile/_scm.h"
25 #include "libguile/async.h"
26 #include "libguile/hashtab.h"
27 #include "libguile/alist.h"
28 #include "libguile/root.h"
29 #include "libguile/weaks.h"
30
31 #include "libguile/objprop.h"
32 \f
33
34 /* {Object Properties}
35 */
36
37 SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0,
38 (SCM obj),
39 "Return @var{obj}'s property list.")
40 #define FUNC_NAME s_scm_object_properties
41 {
42 return scm_hashq_ref (scm_object_whash, obj, SCM_EOL);
43 }
44 #undef FUNC_NAME
45
46
47 SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0,
48 (SCM obj, SCM alist),
49 "Set @var{obj}'s property list to @var{alist}.")
50 #define FUNC_NAME s_scm_set_object_properties_x
51 {
52 SCM handle = scm_hashq_create_handle_x (scm_object_whash, obj, alist);
53 SCM_SETCDR (handle, alist);
54 return alist;
55 }
56 #undef FUNC_NAME
57
58 SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0,
59 (SCM obj, SCM key),
60 "Return the property of @var{obj} with name @var{key}.")
61 #define FUNC_NAME s_scm_object_property
62 {
63 SCM assoc;
64 assoc = scm_assq (key, scm_object_properties (obj));
65 return (SCM_NIMP (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F);
66 }
67 #undef FUNC_NAME
68
69 SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0,
70 (SCM obj, SCM key, SCM value),
71 "In @var{obj}'s property list, set the property named @var{key}\n"
72 "to @var{value}.")
73 #define FUNC_NAME s_scm_set_object_property_x
74 {
75 SCM h;
76 SCM assoc;
77 h = scm_hashq_create_handle_x (scm_object_whash, obj, SCM_EOL);
78 SCM_CRITICAL_SECTION_START;
79 assoc = scm_assq (key, SCM_CDR (h));
80 if (SCM_NIMP (assoc))
81 SCM_SETCDR (assoc, value);
82 else
83 {
84 assoc = scm_acons (key, value, SCM_CDR (h));
85 SCM_SETCDR (h, assoc);
86 }
87 SCM_CRITICAL_SECTION_END;
88 return value;
89 }
90 #undef FUNC_NAME
91
92
93 void
94 scm_init_objprop ()
95 {
96 scm_object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
97 #include "libguile/objprop.x"
98 }
99
100
101 /*
102 Local Variables:
103 c-file-style: "gnu"
104 End:
105 */