objprop.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/async.h"
  22. #include "libguile/hashtab.h"
  23. #include "libguile/alist.h"
  24. #include "libguile/root.h"
  25. #include "libguile/weaks.h"
  26. #include "libguile/objprop.h"
  27. /* {Object Properties}
  28. */
  29. SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0,
  30. (SCM obj),
  31. "Return @var{obj}'s property list.")
  32. #define FUNC_NAME s_scm_object_properties
  33. {
  34. return scm_hashq_ref (scm_object_whash, obj, SCM_EOL);
  35. }
  36. #undef FUNC_NAME
  37. SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0,
  38. (SCM obj, SCM alist),
  39. "Set @var{obj}'s property list to @var{alist}.")
  40. #define FUNC_NAME s_scm_set_object_properties_x
  41. {
  42. SCM handle = scm_hashq_create_handle_x (scm_object_whash, obj, alist);
  43. SCM_SETCDR (handle, alist);
  44. return alist;
  45. }
  46. #undef FUNC_NAME
  47. SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0,
  48. (SCM obj, SCM key),
  49. "Return the property of @var{obj} with name @var{key}.")
  50. #define FUNC_NAME s_scm_object_property
  51. {
  52. SCM assoc;
  53. assoc = scm_assq (key, scm_object_properties (obj));
  54. return (SCM_NIMP (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F);
  55. }
  56. #undef FUNC_NAME
  57. SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0,
  58. (SCM obj, SCM key, SCM value),
  59. "In @var{obj}'s property list, set the property named @var{key}\n"
  60. "to @var{value}.")
  61. #define FUNC_NAME s_scm_set_object_property_x
  62. {
  63. SCM h;
  64. SCM assoc;
  65. h = scm_hashq_create_handle_x (scm_object_whash, obj, SCM_EOL);
  66. SCM_CRITICAL_SECTION_START;
  67. assoc = scm_assq (key, SCM_CDR (h));
  68. if (SCM_NIMP (assoc))
  69. SCM_SETCDR (assoc, value);
  70. else
  71. {
  72. assoc = scm_acons (key, value, SCM_CDR (h));
  73. SCM_SETCDR (h, assoc);
  74. }
  75. SCM_CRITICAL_SECTION_END;
  76. return value;
  77. }
  78. #undef FUNC_NAME
  79. void
  80. scm_init_objprop ()
  81. {
  82. scm_object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
  83. #include "libguile/objprop.x"
  84. }
  85. /*
  86. Local Variables:
  87. c-file-style: "gnu"
  88. End:
  89. */