Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / src / dynacat.h
1 /*** dynacat.h -- dynamic categories (`types' on top of types) for SXEmacs
2  *
3  * Copyright (C) 2005-2008 Sebastian Freundt <hroptatyr@sxemacs.org>
4  *
5  *
6  * This file is part of SXEmacs.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the author nor the names of any contributors
20  *    may be used to endorse or promote products derived from this
21  *    software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Alternatively, for testing purposes, this file can be redistributed under
36  * the following licence:
37  * You can do whatever the fuck you want with this, except stop anyone else
38  * doing whatever the fuck they want.
39  *
40  **/
41
42 #ifndef INCLUDED_dynacat_h_
43 #define INCLUDED_dynacat_h_
44
45 typedef struct dynacat_s *dynacat_t;
46 typedef void(*dynacat_marker_f)(Lisp_Object);
47 typedef void(*dynacat_finaliser_f)(Lisp_Object, int);
48 typedef void(*dynacat_printer_f)(Lisp_Object, Lisp_Object, int);
49 typedef void(*dynacat_intprinter_f)(void*, Lisp_Object);
50
51 struct dynacat_s {
52         struct lrecord_header lheader;
53
54         Lisp_Object type;               /* type of emod object */
55         Lisp_Object plist;              /* properties list */
56
57         void *ptr;                      /* pointer to foreign data */
58         dynacat_marker_f mrkfun;        /* marker function */
59         dynacat_finaliser_f finfun;     /* finaliser function */
60         dynacat_printer_f prfun;        /* print function */
61         dynacat_intprinter_f intprfun;  /* internal print function */
62 };
63
64 extern void dynacat_fini(dynacat_t);
65 extern Lisp_Object make_dynacat(void *ptr);
66
67
68 DECLARE_LRECORD(dynacat, struct dynacat_s);
69 #define XDYNACAT(x)             XRECORD(x, dynacat, struct dynacat_s)
70 #define XSETDYNACAT(x, p)       XSETRECORD(x, p, dynacat)
71 #define DYNACATP(x)             RECORDP(x, dynacat)
72 #define CHECK_DYNACAT(x)        CHECK_RECORD(x, dynacat)
73 #define CONCHECK_DYNACAT(x)     CONCHECK_RECORD(x, dynacat)
74 #define XDYNACAT_TYPE(x)        (XDYNACAT(x)->type)
75 #define XDYNACAT_PLIST(x)       (XDYNACAT(x)->plist)
76
77 extern Lisp_Object make_dynacat(void*);
78
79 extern_inline void *get_dynacat(Lisp_Object);
80 extern_inline void set_dynacat(Lisp_Object, void *p);
81 extern_inline void set_dynacat_marker(Lisp_Object, dynacat_marker_f);
82 extern_inline void set_dynacat_finaliser(Lisp_Object, dynacat_finaliser_f);
83 extern_inline void set_dynacat_printer(Lisp_Object, dynacat_printer_f);
84 extern_inline dynacat_intprinter_f get_dynacat_intprinter(Lisp_Object);
85 extern_inline void set_dynacat_intprinter(Lisp_Object, dynacat_intprinter_f);
86 extern_inline Lisp_Object get_dynacat_type(Lisp_Object);
87 extern_inline void set_dynacat_type(Lisp_Object, Lisp_Object);
88
89 \f
90 extern_inline void *
91 get_dynacat(Lisp_Object ptr)
92 {
93         CHECK_DYNACAT(ptr);
94         return XDYNACAT(ptr)->ptr;
95 }
96 extern_inline void
97 set_dynacat(Lisp_Object ptr, void *p)
98 {
99         CHECK_DYNACAT(ptr);
100         XDYNACAT(ptr)->ptr = p;
101         return;
102 }
103 extern_inline void
104 set_dynacat_marker(Lisp_Object ptr, dynacat_marker_f mrkfun)
105 {
106         CHECK_DYNACAT(ptr);
107         XDYNACAT(ptr)->mrkfun = mrkfun;
108 }
109 extern_inline void
110 set_dynacat_finaliser(Lisp_Object ptr, dynacat_finaliser_f finfun)
111 {
112         CHECK_DYNACAT(ptr);
113         XDYNACAT(ptr)->finfun = finfun;
114 }
115 extern_inline void
116 set_dynacat_printer(Lisp_Object ptr, dynacat_printer_f prfun)
117 {
118         CHECK_DYNACAT(ptr);
119         XDYNACAT(ptr)->prfun = prfun;
120 }
121 extern_inline dynacat_intprinter_f
122 get_dynacat_intprinter(Lisp_Object ptr)
123 {
124         CHECK_DYNACAT(ptr);
125         return XDYNACAT(ptr)->intprfun;
126 }
127 extern_inline void
128 set_dynacat_intprinter(Lisp_Object ptr, dynacat_intprinter_f ipf)
129 {
130         CHECK_DYNACAT(ptr);
131         XDYNACAT(ptr)->intprfun = ipf;
132 }
133
134 extern_inline Lisp_Object
135 get_dynacat_type(Lisp_Object ptr)
136 {
137         CHECK_DYNACAT(ptr);
138         return XDYNACAT(ptr)->type;
139 }
140
141 extern_inline void
142 set_dynacat_type(Lisp_Object ptr, Lisp_Object type)
143 {
144         CHECK_DYNACAT(ptr);
145         XDYNACAT(ptr)->type = type;
146 }
147
148 #endif  /* INCLUDED_dynacat_h_ */