Implemented the compare callback for Camera, Image, Lamp and Text types:

Following a suggestion made by Jordi Rovira i Bonet, the comparison
    now is made via the pointers to the Blender objects, not their py wrappers.
This commit is contained in:
Willian Padovani Germano 2003-05-21 19:58:31 +00:00
parent 000f92e204
commit 89e9090c86
9 changed files with 108 additions and 47 deletions

@ -582,6 +582,20 @@ static int CameraSetAttr (C_Camera *self, char *name, PyObject *value)
return 0; /* normal exit */ return 0; /* normal exit */
} }
/*****************************************************************************/
/* Function: CameraCompare */
/* Description: This is a callback function for the C_Camera type. It */
/* compares two Camera_Type objects. Only the "==" and "!=" */
/* comparisons are meaninful. Returns 0 for equality and -1 if */
/* they don't point to the same Blender Camera struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
static int CameraCompare (C_Camera *a, C_Camera *b)
{
Camera *pa = a->camera, *pb = b->camera;
return (pa == pb) ? 0:-1;
}
/*****************************************************************************/ /*****************************************************************************/
/* Function: CameraPrint */ /* Function: CameraPrint */
/* Description: This is a callback function for the C_Camera type. It */ /* Description: This is a callback function for the C_Camera type. It */

@ -192,6 +192,7 @@ static void CameraDeAlloc (C_Camera *self);
static int CameraPrint (C_Camera *self, FILE *fp, int flags); static int CameraPrint (C_Camera *self, FILE *fp, int flags);
static int CameraSetAttr (C_Camera *self, char *name, PyObject *v); static int CameraSetAttr (C_Camera *self, char *name, PyObject *v);
static PyObject *CameraGetAttr (C_Camera *self, char *name); static PyObject *CameraGetAttr (C_Camera *self, char *name);
static int CameraCompare (C_Camera *a, C_Camera *b);
static PyObject *CameraRepr (C_Camera *self); static PyObject *CameraRepr (C_Camera *self);
/*****************************************************************************/ /*****************************************************************************/
@ -218,7 +219,7 @@ static PyTypeObject Camera_Type =
(printfunc)CameraPrint, /* tp_print */ (printfunc)CameraPrint, /* tp_print */
(getattrfunc)CameraGetAttr, /* tp_getattr */ (getattrfunc)CameraGetAttr, /* tp_getattr */
(setattrfunc)CameraSetAttr, /* tp_setattr */ (setattrfunc)CameraSetAttr, /* tp_setattr */
0, /* tp_compare */ (cmpfunc)CameraCompare, /* tp_compare */
(reprfunc)CameraRepr, /* tp_repr */ (reprfunc)CameraRepr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */

@ -317,6 +317,20 @@ static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
return 0; /* normal exit */ return 0; /* normal exit */
} }
/*****************************************************************************/
/* Function: ImageCompare */
/* Description: This is a callback function for the C_Image type. It */
/* compares two Image_Type objects. Only the "==" and "!=" */
/* comparisons are meaninful. Returns 0 for equality and -1 if */
/* they don't point to the same Blender Image struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
static int ImageCompare (C_Image *a, C_Image *b)
{
Image *pa = a->image, *pb = b->image;
return (pa == pb) ? 0:-1;
}
/*****************************************************************************/ /*****************************************************************************/
/* Function: ImagePrint */ /* Function: ImagePrint */
/* Description: This is a callback function for the C_Image type. It */ /* Description: This is a callback function for the C_Image type. It */

@ -130,11 +130,12 @@ static PyMethodDef C_Image_methods[] = {
/*****************************************************************************/ /*****************************************************************************/
/* Python Image_Type callback function prototypes: */ /* Python Image_Type callback function prototypes: */
/*****************************************************************************/ /*****************************************************************************/
static void ImageDeAlloc (C_Image *cam); static void ImageDeAlloc (C_Image *self);
static int ImagePrint (C_Image *cam, FILE *fp, int flags); static int ImagePrint (C_Image *self, FILE *fp, int flags);
static int ImageSetAttr (C_Image *cam, char *name, PyObject *v); static int ImageSetAttr (C_Image *self, char *name, PyObject *v);
static PyObject *ImageGetAttr (C_Image *cam, char *name); static PyObject *ImageGetAttr (C_Image *self, char *name);
static PyObject *ImageRepr (C_Image *cam); static int ImageCompare (C_Image *a, C_Image *b);
static PyObject *ImageRepr (C_Image *self);
/*****************************************************************************/ /*****************************************************************************/
/* Python Image_Type structure definition: */ /* Python Image_Type structure definition: */
@ -142,26 +143,26 @@ static PyObject *ImageRepr (C_Image *cam);
static PyTypeObject Image_Type = static PyTypeObject Image_Type =
{ {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */ 0, /* ob_size */
"Image", /* tp_name */ "Image", /* tp_name */
sizeof (C_Image), /* tp_basicsize */ sizeof (C_Image), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
/* methods */ /* methods */
(destructor)ImageDeAlloc, /* tp_dealloc */ (destructor)ImageDeAlloc, /* tp_dealloc */
(printfunc)ImagePrint, /* tp_print */ (printfunc)ImagePrint, /* tp_print */
(getattrfunc)ImageGetAttr, /* tp_getattr */ (getattrfunc)ImageGetAttr, /* tp_getattr */
(setattrfunc)ImageSetAttr, /* tp_setattr */ (setattrfunc)ImageSetAttr, /* tp_setattr */
0, /* tp_compare */ (cmpfunc)ImageCompare, /* tp_compare */
(reprfunc)ImageRepr, /* tp_repr */ (reprfunc)ImageRepr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */
0, /* tp_as_mapping */ 0, /* tp_as_mapping */
0, /* tp_as_hash */ 0, /* tp_as_hash */
0,0,0,0,0,0, 0,0,0,0,0,0,
0, /* tp_doc */ 0, /* tp_doc */
0,0,0,0,0,0, 0,0,0,0,0,0,
C_Image_methods, /* tp_methods */ C_Image_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
}; };
#endif /* EXPP_IMAGE_H */ #endif /* EXPP_IMAGE_H */

@ -172,9 +172,9 @@ PyObject *M_Lamp_Init (void)
/* Three Python Lamp_Type helper functions needed by the Object module: */ /* Three Python Lamp_Type helper functions needed by the Object module: */
/*****************************************************************************/ /*****************************************************************************/
/* Function: Lamp_createPyObject */ /* Function: Lamp_createPyObject */
/* Description: This function will create a new C_Lamp from an existing */ /* Description: This function will create a new C_Lamp from an existing */
/* Blender camera structure. */ /* Blender lamp structure. */
/*****************************************************************************/ /*****************************************************************************/
PyObject *Lamp_createPyObject (Lamp *lamp) PyObject *Lamp_createPyObject (Lamp *lamp)
{ {
@ -935,6 +935,20 @@ static int LampSetAttr (C_Lamp *self, char *name, PyObject *value)
return 0; /* normal exit */ return 0; /* normal exit */
} }
/*****************************************************************************/
/* Function: LampCompare */
/* Description: This is a callback function for the C_Lamp type. It */
/* compares two Lamp_Type objects. Only the "==" and "!=" */
/* comparisons are meaninful. Returns 0 for equality and -1 if */
/* they don't point to the same Blender Lamp struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
static int LampCompare (C_Lamp *a, C_Lamp *b)
{
Lamp *pa = a->lamp, *pb = b->lamp;
return (pa == pb) ? 0:-1;
}
/*****************************************************************************/ /*****************************************************************************/
/* Function: LampPrint */ /* Function: LampPrint */
/* Description: This is a callback function for the C_Lamp type. It */ /* Description: This is a callback function for the C_Lamp type. It */

@ -290,6 +290,7 @@ static PyMethodDef C_Lamp_methods[] = {
static void LampDeAlloc (C_Lamp *lamp); static void LampDeAlloc (C_Lamp *lamp);
static PyObject *LampGetAttr (C_Lamp *lamp, char *name); static PyObject *LampGetAttr (C_Lamp *lamp, char *name);
static int LampSetAttr (C_Lamp *lamp, char *name, PyObject *v); static int LampSetAttr (C_Lamp *lamp, char *name, PyObject *v);
static int LampCompare (C_Lamp *a, C_Lamp *b);
static PyObject *LampRepr (C_Lamp *lamp); static PyObject *LampRepr (C_Lamp *lamp);
static int LampPrint (C_Lamp *lamp, FILE *fp, int flags); static int LampPrint (C_Lamp *lamp, FILE *fp, int flags);
@ -308,26 +309,26 @@ int LampCheckPyObject (PyObject *pyobj);
static PyTypeObject Lamp_Type = static PyTypeObject Lamp_Type =
{ {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */ 0, /* ob_size */
"Lamp", /* tp_name */ "Lamp", /* tp_name */
sizeof (C_Lamp), /* tp_basicsize */ sizeof (C_Lamp), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
/* methods */ /* methods */
(destructor)LampDeAlloc, /* tp_dealloc */ (destructor)LampDeAlloc, /* tp_dealloc */
(printfunc)LampPrint, /* tp_print */ (printfunc)LampPrint, /* tp_print */
(getattrfunc)LampGetAttr, /* tp_getattr */ (getattrfunc)LampGetAttr, /* tp_getattr */
(setattrfunc)LampSetAttr, /* tp_setattr */ (setattrfunc)LampSetAttr, /* tp_setattr */
0, /* tp_compare */ (cmpfunc)LampCompare, /* tp_compare */
(reprfunc)LampRepr, /* tp_repr */ (reprfunc)LampRepr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */
0, /* tp_as_mapping */ 0, /* tp_as_mapping */
0, /* tp_as_hash */ 0, /* tp_as_hash */
0,0,0,0,0,0, 0,0,0,0,0,0,
0, /* tp_doc */ 0, /* tp_doc */
0,0,0,0,0,0, 0,0,0,0,0,0,
C_Lamp_methods, /* tp_methods */ C_Lamp_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
}; };
#endif /* EXPP_LAMP_H */ #endif /* EXPP_LAMP_H */

@ -442,6 +442,20 @@ static int TextSetAttr (C_Text *self, char *name, PyObject *value)
return 0; /* normal exit */ return 0; /* normal exit */
} }
/*****************************************************************************/
/* Function: TextCompare */
/* Description: This is a callback function for the C_Text type. It */
/* compares two Text_Type objects. Only the "==" and "!=" */
/* comparisons are meaninful. Returns 0 for equality and -1 if */
/* they don't point to the same Blender Text struct. */
/* In Python it becomes 1 if they are equal, 0 otherwise. */
/*****************************************************************************/
static int TextCompare (C_Text *a, C_Text *b)
{
Text *pa = a->text, *pb = b->text;
return (pa == pb) ? 0:-1;
}
/*****************************************************************************/ /*****************************************************************************/
/* Function: TextPrint */ /* Function: TextPrint */
/* Description: This is a callback function for the C_Text type. It */ /* Description: This is a callback function for the C_Text type. It */

@ -142,11 +142,12 @@ static PyMethodDef C_Text_methods[] = {
/*****************************************************************************/ /*****************************************************************************/
/* Python Text_Type callback function prototypes: */ /* Python Text_Type callback function prototypes: */
/*****************************************************************************/ /*****************************************************************************/
static void TextDeAlloc (C_Text *cam); static void TextDeAlloc (C_Text *self);
static int TextPrint (C_Text *cam, FILE *fp, int flags); static int TextPrint (C_Text *self, FILE *fp, int flags);
static int TextSetAttr (C_Text *cam, char *name, PyObject *v); static int TextSetAttr (C_Text *self, char *name, PyObject *v);
static PyObject *TextGetAttr (C_Text *cam, char *name); static PyObject *TextGetAttr (C_Text *self, char *name);
static PyObject *TextRepr (C_Text *cam); static int TextCompare (C_Text *a, C_Text *b);
static PyObject *TextRepr (C_Text *self);
/*****************************************************************************/ /*****************************************************************************/
/* Python Text_Type structure definition: */ /* Python Text_Type structure definition: */
@ -154,26 +155,26 @@ static PyObject *TextRepr (C_Text *cam);
static PyTypeObject Text_Type = static PyTypeObject Text_Type =
{ {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */ 0, /* ob_size */
"Text", /* tp_name */ "Text", /* tp_name */
sizeof (C_Text), /* tp_basicsize */ sizeof (C_Text), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
/* methods */ /* methods */
(destructor)TextDeAlloc, /* tp_dealloc */ (destructor)TextDeAlloc, /* tp_dealloc */
(printfunc)TextPrint, /* tp_print */ (printfunc)TextPrint, /* tp_print */
(getattrfunc)TextGetAttr, /* tp_getattr */ (getattrfunc)TextGetAttr, /* tp_getattr */
(setattrfunc)TextSetAttr, /* tp_setattr */ (setattrfunc)TextSetAttr, /* tp_setattr */
0, /* tp_compare */ (cmpfunc)TextCompare, /* tp_compare */
(reprfunc)TextRepr, /* tp_repr */ (reprfunc)TextRepr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */
0, /* tp_as_mapping */ 0, /* tp_as_mapping */
0, /* tp_as_hash */ 0, /* tp_as_hash */
0,0,0,0,0,0, 0,0,0,0,0,0,
0, /* tp_doc */ 0, /* tp_doc */
0,0,0,0,0,0, 0,0,0,0,0,0,
C_Text_methods, /* tp_methods */ C_Text_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
}; };
#endif /* EXPP_TEXT_H */ #endif /* EXPP_TEXT_H */

@ -33,6 +33,7 @@
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
* *
*/ */
#ifndef EXPP_vector_h #ifndef EXPP_vector_h
#define EXPP_vector_h #define EXPP_vector_h