Export <slot> from GOOPS
[bpt/guile.git] / libguile / objprop.c
CommitLineData
1ad9fdb7 1/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
0f2d19dd 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
0f2d19dd 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
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
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
1bbd0b84 18
1bbd0b84 19
0f2d19dd 20\f
dbb605f5
LC
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
0f2d19dd 24
a0599745 25#include "libguile/_scm.h"
4e047c3e 26#include "libguile/async.h"
a0599745
MD
27#include "libguile/hashtab.h"
28#include "libguile/alist.h"
29#include "libguile/root.h"
0f2d19dd 30
a0599745 31#include "libguile/objprop.h"
0f2d19dd
JB
32\f
33
34/* {Object Properties}
35 */
36
e7efe8e7
AW
37static SCM object_whash;
38
3b3b36dd 39SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0,
1bbd0b84 40 (SCM obj),
b380b885 41 "Return @var{obj}'s property list.")
1bbd0b84 42#define FUNC_NAME s_scm_object_properties
0f2d19dd 43{
203a92b6 44 return scm_weak_table_refq (object_whash, obj, SCM_EOL);
0f2d19dd 45}
1bbd0b84 46#undef FUNC_NAME
0f2d19dd
JB
47
48
3b3b36dd 49SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0,
1e6808ea 50 (SCM obj, SCM alist),
b380b885 51 "Set @var{obj}'s property list to @var{alist}.")
1bbd0b84 52#define FUNC_NAME s_scm_set_object_properties_x
0f2d19dd 53{
203a92b6 54 scm_weak_table_putq_x (object_whash, obj, alist);
f5e85438 55
1e6808ea 56 return alist;
0f2d19dd 57}
1bbd0b84 58#undef FUNC_NAME
0f2d19dd 59
3b3b36dd 60SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0,
1bbd0b84 61 (SCM obj, SCM key),
b380b885 62 "Return the property of @var{obj} with name @var{key}.")
1bbd0b84 63#define FUNC_NAME s_scm_object_property
0f2d19dd
JB
64{
65 SCM assoc;
332ab360 66 assoc = scm_assq (key, scm_object_properties (obj));
62fdadb0 67 return (scm_is_pair (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F);
0f2d19dd 68}
1bbd0b84 69#undef FUNC_NAME
0f2d19dd 70
3b3b36dd 71SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0,
1e6808ea 72 (SCM obj, SCM key, SCM value),
1e6808ea
MG
73 "In @var{obj}'s property list, set the property named @var{key}\n"
74 "to @var{value}.")
1bbd0b84 75#define FUNC_NAME s_scm_set_object_property_x
0f2d19dd 76{
1ad9fdb7 77 SCM alist;
0f2d19dd 78 SCM assoc;
f5e85438 79
203a92b6
AW
80 scm_i_pthread_mutex_lock (&scm_i_misc_mutex);
81 alist = scm_weak_table_refq (object_whash, obj, SCM_EOL);
1ad9fdb7 82 assoc = scm_assq (key, alist);
62fdadb0 83 if (scm_is_pair (assoc))
1e6808ea 84 SCM_SETCDR (assoc, value);
0f2d19dd 85 else
203a92b6
AW
86 scm_weak_table_putq_x (object_whash, obj, scm_acons (key, value, alist));
87 scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
f5e85438 88
1e6808ea 89 return value;
0f2d19dd 90}
1bbd0b84 91#undef FUNC_NAME
0f2d19dd 92
1cc91f1b 93
0f2d19dd
JB
94void
95scm_init_objprop ()
0f2d19dd 96{
203a92b6 97 object_whash = scm_c_make_weak_table (0, SCM_WEAK_TABLE_KIND_KEY);
a0599745 98#include "libguile/objprop.x"
0f2d19dd
JB
99}
100
89e00824
ML
101
102/*
103 Local Variables:
104 c-file-style: "gnu"
105 End:
106*/