1 /***********************************************************
2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Use this file as a template to start implementing a new object type.
26 If your objects will be called foobar, start by copying this file to
27 foobarobject.c, changing all occurrences of xx to foobar and all
28 occurrences of Xx by Foobar. You will probably want to delete all
29 references to 'x_attr' and add your own types of attributes
30 instead. Maybe you want to name your local variables other than
31 'xp'. If your object type is needed in other files, you'll have to
32 create a file "foobarobject.h"; see intobject.h for an example. */
37 #include "allobjects.h"
38 #include "modsupport.h" /* For getargs() etc. */
42 object
*x_attr
; /* Attributes dictionary */
45 staticforward typeobject Xxtype
;
47 #define is_xxobject(v) ((v)->ob_type == &Xxtype)
54 xp
= NEWOBJ(xxobject
, &Xxtype
);
82 static struct methodlist xx_methods
[] = {
83 {"demo", (method
)xx_demo
},
84 {NULL
, NULL
} /* sentinel */
92 if (xp
->x_attr
!= NULL
) {
93 object
*v
= dictlookup(xp
->x_attr
, name
);
99 return findmethod(xx_methods
, (object
*)xp
, name
);
103 xx_setattr(xp
, name
, v
)
108 if (xp
->x_attr
== NULL
) {
109 xp
->x_attr
= newdictobject();
110 if (xp
->x_attr
== NULL
)
114 int rv
= dictremove(xp
->x_attr
, name
);
116 err_setstr(AttributeError
,
117 "delete non-existing xx attribute");
121 return dictinsert(xp
->x_attr
, name
, v
);
124 static typeobject Xxtype
= {
125 OB_HEAD_INIT(&Typetype
)
128 sizeof(xxobject
), /*tp_basicsize*/
131 (destructor
)xx_dealloc
, /*tp_dealloc*/
133 (getattrfunc
)xx_getattr
, /*tp_getattr*/
134 (setattrfunc
)xx_setattr
, /*tp_setattr*/
138 0, /*tp_as_sequence*/