home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / STRUCTMEMBER.H < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-01  |  1.9 KB  |  72 lines

  1. #ifndef Py_STRUCTMEMBER_H
  2. #define Py_STRUCTMEMBER_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7.  
  8. /* Interface to map C struct members to Python object attributes */
  9.  
  10. #ifdef HAVE_STDDEF_H
  11. #include <stddef.h> /* For offsetof */
  12. #endif
  13.  
  14. /* The offsetof() macro calculates the offset of a structure member
  15.    in its structure.  Unfortunately this cannot be written down
  16.    portably, hence it is provided by a Standard C header file.
  17.    For pre-Standard C compilers, here is a version that usually works
  18.    (but watch out!): */
  19.  
  20. #ifndef offsetof
  21. #define offsetof(type, member) ( (int) & ((type*)0) -> member )
  22. #endif
  23.  
  24. /* An array of memberlist structures defines the name, type and offset
  25.    of selected members of a C structure.  These can be read by
  26.    PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
  27.    is set).  The array must be terminated with an entry whose name
  28.    pointer is NULL. */
  29.  
  30. struct memberlist {
  31.     char *name;
  32.     int type;
  33.     int offset;
  34.     int readonly;
  35. };
  36.  
  37. /* Types */
  38. #define T_SHORT        0
  39. #define T_INT        1
  40. #define T_LONG        2
  41. #define T_FLOAT        3
  42. #define T_DOUBLE    4
  43. #define T_STRING    5
  44. #define T_OBJECT    6
  45. /* XXX the ordering here is weird for binary compatibility */
  46. #define T_CHAR        7    /* 1-character string */
  47. #define T_BYTE        8    /* 8-bit signed int */
  48. /* unsigned variants: */
  49. #define T_UBYTE        9
  50. #define T_USHORT    10
  51. #define T_UINT        11
  52. #define T_ULONG        12
  53.  
  54. /* Added by Jack: strings contained in the structure */
  55. #define T_STRING_INPLACE    13
  56. #ifdef macintosh
  57. #define T_PSTRING    14    /* macintosh pascal-style counted string */
  58. #define T_PSTRING_INPLACE    15
  59. #endif /* macintosh */
  60.  
  61. /* Readonly flag */
  62. #define READONLY    1
  63. #define RO        READONLY        /* Shorthand */
  64.  
  65. DL_IMPORT(PyObject *) PyMember_Get(char *, struct memberlist *, char *);
  66. DL_IMPORT(int) PyMember_Set(char *, struct memberlist *, char *, PyObject *);
  67.  
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif /* !Py_STRUCTMEMBER_H */
  72.