add Field.getarraylen()
This commit is contained in:
@ -196,6 +196,25 @@ static PyObject *pyField_getarray(pyField *self)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *pyField_getlen(pyField *self)
|
||||||
|
{
|
||||||
|
rset *prset;
|
||||||
|
|
||||||
|
if(self->addr.special==SPC_DBADDR &&
|
||||||
|
(prset=dbGetRset(&self->addr)) &&
|
||||||
|
prset->get_array_info)
|
||||||
|
{
|
||||||
|
char *datasave=self->addr.pfield;
|
||||||
|
long noe, off;
|
||||||
|
prset->get_array_info(&self->addr, &noe, &off);
|
||||||
|
/* get_array_info can modify pfield in >3.15.0.1 */
|
||||||
|
self->addr.pfield = datasave;
|
||||||
|
return PyInt_FromLong(noe);
|
||||||
|
|
||||||
|
} else
|
||||||
|
return PyInt_FromLong(1);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *pyField_setlen(pyField *self, PyObject *args)
|
static PyObject *pyField_setlen(pyField *self, PyObject *args)
|
||||||
{
|
{
|
||||||
rset *prset = dbGetRset(&self->addr);
|
rset *prset = dbGetRset(&self->addr);
|
||||||
@ -282,8 +301,10 @@ static PyMethodDef pyField_methods[] = {
|
|||||||
"Sets field value from a scalar"},
|
"Sets field value from a scalar"},
|
||||||
{"getarray", (PyCFunction)pyField_getarray, METH_NOARGS,
|
{"getarray", (PyCFunction)pyField_getarray, METH_NOARGS,
|
||||||
"Return a numpy ndarray refering to this field for in-place operations."},
|
"Return a numpy ndarray refering to this field for in-place operations."},
|
||||||
|
{"getarraylen", (PyCFunction)pyField_getlen, METH_NOARGS,
|
||||||
|
"Return current number of valid elements for array fields."},
|
||||||
{"putarraylen", (PyCFunction)pyField_setlen, METH_VARARGS,
|
{"putarraylen", (PyCFunction)pyField_setlen, METH_VARARGS,
|
||||||
"Set array field length."},
|
"Set number of valid elements for array fields."},
|
||||||
{"getTime", (PyCFunction)pyField_getTime, METH_NOARGS,
|
{"getTime", (PyCFunction)pyField_getTime, METH_NOARGS,
|
||||||
"Return link target timestamp as a tuple (sec, nsec)."},
|
"Return link target timestamp as a tuple (sec, nsec)."},
|
||||||
{"getAlarm", (PyCFunction)pyField_getAlarm, METH_NOARGS,
|
{"getAlarm", (PyCFunction)pyField_getAlarm, METH_NOARGS,
|
||||||
|
@ -168,6 +168,13 @@ class _Field(object):
|
|||||||
lock is held (ie withing :meth:`process <DeviceSupport.process>`).
|
lock is held (ie withing :meth:`process <DeviceSupport.process>`).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def getarraylen(self):
|
||||||
|
"""Return the number of active elements for the field.
|
||||||
|
|
||||||
|
>>> F = Field(...)
|
||||||
|
>>> assert len(F)>=F.getarraylen()
|
||||||
|
"""
|
||||||
|
|
||||||
def putarraylen(self, len):
|
def putarraylen(self, len):
|
||||||
"""Set the number of active elements in field's array.
|
"""Set the number of active elements in field's array.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user