chiark / gitweb /
Change naming convention around.
[sod] / src / pset-impl.lisp
1 ;;; -*-lisp-*-
2 ;;;
3 ;;; Implementation for property sets
4 ;;;
5 ;;; (c) 2009 Straylight/Edgeware
6 ;;;
7
8 ;;;----- Licensing notice ---------------------------------------------------
9 ;;;
10 ;;; This file is part of the Sensble Object Design, an object system for C.
11 ;;;
12 ;;; SOD is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2 of the License, or
15 ;;; (at your option) any later version.
16 ;;;
17 ;;; SOD is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with SOD; if not, write to the Free Software Foundation,
24 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26 (cl:in-package #:sod)
27
28 ;;;--------------------------------------------------------------------------
29 ;;; Property representation.
30
31 (defmethod file-location ((prop property))
32   (file-location (p-location prop)))
33
34 ;;; Keywords.
35
36 (defmethod coerce-property-value
37     ((value symbol) (type (eql :symbol)) (wanted (eql :keyword)))
38   value)
39
40 (defmethod coerce-property-value
41     ((value string) (type (eql :id)) (wanted (eql :keyword)))
42   (string-to-symbol value :package :keyword))
43
44 (defmethod coerce-property-value
45     ((value string) (type (eql :string)) (wanted (eql :keyword)))
46   (string-to-symbol value :package :keyword :swap-hyphen nil))
47
48 ;;; Symbols.
49
50 (defmethod coerce-property-value
51     ((value string) (type (eql :id)) (wanted (eql :symbol)))
52   (string-to-symbol value))
53
54 (defmethod coerce-property-value
55     ((value string) (type (eql :string)) (wanted (eql :symbol)))
56   (string-to-symbol value :swap-hyphen nil))
57
58 ;;; Identifiers.
59
60 (defmethod coerce-property-value
61     ((value string) (type (eql :string)) (wanted (eql :id)))
62   value)
63
64 (defmethod coerce-property-value
65     ((value symbol) (type (eql :symbol)) (wanted (eql :id)))
66   (frob-identifier (symbol-name value)))
67
68 ;;;--------------------------------------------------------------------------
69 ;;; Property sets.
70
71 (defmethod print-object ((pset pset) stream)
72   (print-unreadable-object (pset stream :type t)
73     (pprint-logical-block (stream nil)
74       (let ((firstp t))
75         (pset-map (lambda (prop)
76                     (cond (firstp (setf firstp nil))
77                           (t (write-char #\space stream)
78                              (pprint-newline :linear stream)))
79                     (format stream "~:@<~S ~@_~S ~@_~S~:>"
80                             (p-name prop) (p-type prop) (p-value prop)))
81                   pset)))))
82
83 ;;;----- That's all, folks --------------------------------------------------