1 /*** dynacat.h -- dynamic categories (`types' on top of types) for SXEmacs
3 * Copyright (C) 2005-2008 Sebastian Freundt <hroptatyr@sxemacs.org>
6 * This file is part of SXEmacs.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
42 #ifndef INCLUDED_dynacat_h_
43 #define INCLUDED_dynacat_h_
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);
52 struct lrecord_header lheader;
54 Lisp_Object type; /* type of emod object */
55 Lisp_Object plist; /* properties list */
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 */
64 extern void dynacat_fini(dynacat_t);
65 extern Lisp_Object make_dynacat(void *ptr);
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)
77 extern Lisp_Object make_dynacat(void*);
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);
91 get_dynacat(Lisp_Object ptr)
94 return XDYNACAT(ptr)->ptr;
97 set_dynacat(Lisp_Object ptr, void *p)
100 XDYNACAT(ptr)->ptr = p;
104 set_dynacat_marker(Lisp_Object ptr, dynacat_marker_f mrkfun)
107 XDYNACAT(ptr)->mrkfun = mrkfun;
110 set_dynacat_finaliser(Lisp_Object ptr, dynacat_finaliser_f finfun)
113 XDYNACAT(ptr)->finfun = finfun;
116 set_dynacat_printer(Lisp_Object ptr, dynacat_printer_f prfun)
119 XDYNACAT(ptr)->prfun = prfun;
121 extern_inline dynacat_intprinter_f
122 get_dynacat_intprinter(Lisp_Object ptr)
125 return XDYNACAT(ptr)->intprfun;
128 set_dynacat_intprinter(Lisp_Object ptr, dynacat_intprinter_f ipf)
131 XDYNACAT(ptr)->intprfun = ipf;
134 extern_inline Lisp_Object
135 get_dynacat_type(Lisp_Object ptr)
138 return XDYNACAT(ptr)->type;
142 set_dynacat_type(Lisp_Object ptr, Lisp_Object type)
145 XDYNACAT(ptr)->type = type;
148 #endif /* INCLUDED_dynacat_h_ */