1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*
A* -------------------------------------------------------------------
B* This file contains source code for the PyMOL computer program
C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific.
D* -------------------------------------------------------------------
E* It is unlawful to modify or remove this copyright notice.
F* -------------------------------------------------------------------
G* Please see the accompanying LICENSE file for further information.
H* -------------------------------------------------------------------
I* Additional authors of this source file include:
-*
-*
-*
Z* -------------------------------------------------------------------
*/
#ifndef _H_PConv
#define _H_PConv
#include"os_python.h"
#ifndef _PYMOL_NOPY
#include"Base.h"
#include"OVLexicon.h"
/* Convenient conversion routines for C<->Python data interchange
Note that all of these routines assume that we have the global
interpreter lock - blocking all other threads.
There are three ways to get it:
- call PBlock() [followe by PUnblock() when done]
- call PBlockAndUnlockAPI - [followed by PLockAPIAndUnblock() when
done]
- or in response to a call to the PM API, you will have the main
Python thread by default. [Note that within an
APIEntry(),APIExit() block the lock is released, so these
functions should be called outside of that block].
*/
/* == error-checking routines: true = success, false = failure. */
/* NOTE: the string routines will write strings up to the specified
* length, PLUS a NULL...so watch out for array overruns */
int PConvAttrToStrMaxLen(PyObject * obj, char *attr, char *str, ov_size ll);
int PConvPyListToExtent(PyObject * obj, float *mn, float *mx);
int PConvAttrToFloatArrayInPlace(PyObject * obj, char *attr, float *ff, ov_size ll);
int PConvAttrToIntArrayInPlace(PyObject * obj, char *attr, int *ff, ov_size ll);
int PConvAttrToPtr(PyObject * obj, char *name, void **cobj);
int PConvCObjectToPtr(PyObject * obj, void **ptr);
int PConvPyListToStrVLAList(PyObject * obj, char **vla, int *n_str);
int PConvPyListToStringVLA(PyObject * obj, char **vla_ptr);
int PConvPyListToIntVLA(PyObject * obj, int **f);
int PConvPyStrToStr(PyObject * obj, char *ptr, int l);
int PConvPyStrToStrPtr(PyObject * obj, char **ptr);
int PConvPyStrToLexRef(PyObject * obj, OVLexicon * lex, int *lex_ref);
int PConvPyFloatToFloat(PyObject * obj, float *ptr);
int PConvPyIntToChar(PyObject * obj, char *ptr);
int PConvPyIntToInt(PyObject * obj, int *ptr);
int PConvPyListToLabPosVLA(PyObject * obj, LabPosType ** vla_ptr);
/* Jenarix conventions -- returns before args */
ov_status PConvPyTupleToIntVLA(int **result, PyObject * tuple);
ov_status PConvPyTupleToFloatVLA(float **result, PyObject * tuple);
/* === end === */
/* categories below... */
PyObject *PConvFloatVLAToPyList(float *vla);
PyObject *PConvFloatVLAToPyTuple(float *vla);
PyObject *PConvIntVLAToPyList(int *vla);
PyObject *PConvIntVLAToPyTuple(int *vla);
PyObject *PConvIntArrayToPyList(int *f, int l);
PyObject *PConvSIntArrayToPyList(short int *f, int l);
PyObject *PConvSCharArrayToPyList(signed char *f, int l);
PyObject *PConvLabPosVLAToPyList(LabPosType * vla, int l);
/* WARNING: the returned PyObject is unowned - it is intended for use
* only for efficient detection of changes to dictionary values
* following evaluation of some expression in the context of the
* dictionary PAlter, PAlterState, etc. */
PyObject *PConvFloatToPyDictItem(PyObject * dict, char *key, float f);
PyObject *PConvStringToPyDictItem(PyObject * dict, char *key, char *f);
PyObject *PConvIntToPyDictItem(PyObject * dict, char *key, int i);
/* end WARNING */
void PConvFloat3ToPyObjAttr(PyObject * obj, char *attr, float *v);
void PConvFloatToPyObjAttr(PyObject * obj, char *attr, float f);
void PConvIntToPyObjAttr(PyObject * obj, char *attr, int i);
void PConvInt2ToPyObjAttr(PyObject * obj, char *attr, int *v);
void PConvStringToPyObjAttr(PyObject * obj, char *attr, char *f);
int PConvPyObjectToFloat(PyObject * object, float *value);
int PConvPyObjectToInt(PyObject * object, int *value);
int PConvPyObjectToChar(PyObject * object, char *value);
/* NOTE: the string routines will write strings up to the specified
* length, PLUS a NULL...so watch out for array overruns */
int PConvPyObjectToStrMaxLen(PyObject * object, char *value, int ln);
int PConvPyObjectToStrMaxClean(PyObject * object, char *value, int ln);
PyObject *PConvStringListToPyList(int l, char **str);
PyObject *PConvStringVLAToPyList(char *str);
void PConv44PyListTo44f(PyObject * src, float *dest); /* note loss of precision */
int PConvPyListToFloatVLA(PyObject * obj, float **f);
int PConvPyListToFloatVLANoneOkay(PyObject * obj, float **f);
int PConvPyList3ToFloatVLA(PyObject * obj, float **f);
int PConvPyListToFloatArray(PyObject * obj, float **f);
int PConvPyListToDoubleArray(PyObject * obj, double **f);
int PConvPyListToFloatArrayInPlace(PyObject * obj, float *ff, ov_size ll);
int PConvPyListToFloatArrayInPlaceAutoZero(PyObject * obj, float *ii, ov_size ll);
int PConvPyListToDoubleArrayInPlace(PyObject * obj, double *ff, ov_size ll);
PyObject *PConvFloatArrayToPyList(float *f, int l);
PyObject *PConvFloatArrayToPyListNullOkay(float *f, int l);
PyObject *PConvDoubleArrayToPyList(double *f, int l);
int PConvPyListToIntArray(PyObject * obj, int **f);
int PConvPyListToIntArrayInPlace(PyObject * obj, int *ff, ov_size ll);
int PConvPyListToIntArrayInPlaceAutoZero(PyObject * obj, int *ii, ov_size ll);
int PConvPyListToSIntArrayInPlaceAutoZero(PyObject * obj, short int *ii, ov_size ll);
int PConvPyListToSCharArrayInPlaceAutoZero(PyObject * obj, signed char *ii, ov_size ll);
PyObject *PConv3DIntArrayTo3DPyList(int ***array, int *dim);
PyObject *PConvAutoNone(PyObject * result); /* automatically own Py_None */
#endif
#endif
|