File: keyedobj.l

package info (click to toggle)
euslisp 9.27%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 55,344 kB
  • sloc: ansic: 41,162; lisp: 3,339; makefile: 256; sh: 208; asm: 138; python: 53
file content (36 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(defclass keyed-object-list  :slots (object-list klass try))

(defmethod keyed-object-list
 (:get (&optional key)
   (if key 
	(find key object-list :key #'(lambda (x) (send x :key)))
        (if (< (length object-list) 1)
	    nil
            (prog1 (nth try object-list)
	           (inc try)
	           (if (>= try (length object-list)) (setq try 0))))))
 (:new (key)
   (let ((g (find key object-list :key #'(lambda (x) (send x :key)))))
     (if g
	 g
         (progn
            (setq g (instantiate klass))
	    (send g :key key)
	    (setq object-list (nconc object-list (list g)))
	    g))))
 (:add (obj)
   (let ((key (send obj :key)))
     (if (find key object-list :key #'(lambda (x) (send x :key)))
	 nil
	 (setq object-list (nconc object-list (list obj))))))
 (:keys ()
   (mapcar #'(lambda (x) (send x :key)) object-list))
 (:remove (key)
   (setq object-list
	 (delete (send self :get key) object-list))
   (if (>= try (length object-list)) (setq try 0)))
 (:reset-try (&optional (n 0)) (setq try n))
 (:init (c)
   (setq object-list nil try 0 klass c)
   self))