spacepaste

  1.  
  2. #
  3. # This is my declarative definition of a function
  4. #
  5. Function('iFail', 'AOM_ask_value_strings', '''\
  6. Asks one or more values of a property. The property can be single-valued or multi-valued (i.e., array or list).
  7. This function uses #PROP_ask_value_strings_msg if multi-valued and #PROP_ask_value_string_msg if single-valued.
  8. To customize the behavior of this function, register a method against one of these messages.''',
  9. [('tag_t' , 'object_tag', 'I' , '< (I) Unique identifier (tag) of the object instance.'),
  10. ('const char*', 'prop_name' , 'I' , '< (I) A property name of the object instance.'),
  11. ('int*' , 'num' , 'OC' , '< (O) Number of values asked.'),
  12. ('char***' , 'values' , 'OL(num)F', '< (OF) num Actual values of the property. This must be a list or array \n'
  13. ' of constant chars. If the property is an array, the number of \n'
  14. ' values passed in must equal the size of the array.\n'
  15. ' Iterate through the output array and call MEM_free on each element to de-allocate\n'
  16. ' the nested memory block and then free the memory pointed by itself using MEM_free.'),
  17. ]),
  18. #
  19. # This is automatically created in a .pxd
  20. #
  21. cdef int AOM_ask_value_strings(
  22. # Asks one or more values of a property. The property can be single-valued or multi-valued (i.e., array or list).
  23. #
  24. # This function uses #PROP_ask_value_strings_msg if multi-valued and #PROP_ask_value_string_msg if single-valued.
  25. # To customize the behavior of this function, register a method against one of these messages.
  26. tag_t object_tag, # < (I) Unique identifier (tag) of the object instance.
  27. char* prop_name , # < (I) A property name of the object instance.
  28. int* num , # < (O) Number of values asked.
  29. char*** values # < (OF) num Actual values of the property. This must be a list or array
  30. # of constant chars. If the property is an array, the number of
  31. # values passed in must equal the size of the array.
  32. # Iterate through the output array and call MEM_free on each element to de-allocate
  33. # the nested memory block and then free the memory pointed by itself using MEM_free.
  34. )
  35. #
  36. # So is this in a .pyx
  37. #
  38. def AOM_ask_value_strings(tag_t object_tag, prop_name__py_str):
  39. '''
  40. Input:
  41. tag_t object_tag (I) -- < (I) Unique identifier (tag) of the object instance.
  42. const char* prop_name (I) -- < (I) A property name of the object instance.
  43. Output:
  44. char*** values (OL(num)F) -- < (OF) num Actual values of the property. This must be a list or array
  45. of constant chars. If the property is an array, the number of
  46. values passed in must equal the size of the array.
  47. Iterate through the output array and call MEM_free on each element to de-allocate
  48. the nested memory block and then free the memory pointed by itself using MEM_free.
  49. Asks one or more values of a property. The property can be single-valued or multi-valued (i.e., array or list).
  50. This function uses #PROP_ask_value_strings_msg if multi-valued and #PROP_ask_value_string_msg if single-valued.
  51. To customize the behavior of this function, register a method against one of these messages.
  52. '''
  53. cdef int __pytk__ifail__return__
  54. cdef char* prop_name
  55. cdef int num
  56. cdef char** values
  57. prop_name = PyString_AsString(prop_name__py_str) if prop_name__py_str != None else NULL
  58. if utils._nogil:
  59. with nogil:
  60. __pytk__ifail__return__ = ctccore__aom_prop.AOM_ask_value_strings(object_tag, prop_name, &num, &values)
  61. else:
  62. __pytk__ifail__return__ = ctccore__aom_prop.AOM_ask_value_strings(object_tag, prop_name, &num, &values)
  63. iFail2Exception(__pytk__ifail__return__)
  64. values__py_list = [str(values[pytk_i]) if values[pytk_i] != NULL else None for pytk_i in xrange(num)]
  65. for pytk_i in xrange(num):
  66. MEM_free(values[pytk_i])
  67. MEM_free(values)
  68. return values__py_list
  69.