-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfifo-class.el
76 lines (64 loc) · 2.37 KB
/
fifo-class.el
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; fifo-class.el --- First in first out abstract class -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2015-2016 Mola-T
;; Author: Mola-T <Mola@molamola.xyz>
;; URL: https://github.com/mola-T/fifo-class
;; Version: 1.0
;; Keywords: lisp
;;
;;; License:
;; This file is NOT part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; Provides first in first out quene for class slot.
;;
;;; Code:
(require 'eieio)
(defclass fifo-class ()
()
"Inherit this class to get first in first out slot."
:abstract t)
(defmethod fifo-class-push ((obj fifo-class) slot data)
"First in first out push.
Push DATA to the back of quene of slot SLOT in object OBJ."
(let ((original (eieio-oref obj slot)))
(unless (listp original)
(signal 'wrong-type-argument
(list 'listp 'obj: (eieio-object-class obj) 'slot: slot)))
(if original
(nconc original (list data))
(setf (eieio-oref obj slot) (list data)))
t))
(defmethod fifo-class-pop ((obj fifo-class) slot)
"First in first out pop.
Remove the first element of slot SLOT in object OBJ."
(unless (listp (eieio-oref obj slot))
(signal 'wrong-type-argument
(list 'listp 'obj: (eieio-object-class obj) 'slot: slot)))
(let ((return (car (eieio-oref obj slot))))
(setf (eieio-oref obj slot) (cdr (eieio-oref obj slot)))
return))
(defmethod fifo-class-first ((obj fifo-class) slot)
"Get the first element of the SLOT without removing it."
(unless (listp (eieio-oref obj slot))
(signal 'wrong-type-argument
(list 'listp 'obj: (eieio-object-class obj) 'slot: slot)))
(car (eieio-oref obj slot)))
(provide 'fifo-class)
;;; fifo-class.el ends here