1 #include "rs_core.rsh" 2 #include "rs_structs.h" 3 4 /** 5 * Element 6 */ 7 extern uint32_t __attribute__((overloadable)) rsElementGetSubElementCount(rs_element e)8 rsElementGetSubElementCount(rs_element e) { 9 Element_t *element = (Element_t *)e.p; 10 if (element == NULL) { 11 return 0; 12 } 13 return element->mHal.state.fieldsCount; 14 } 15 16 extern rs_element __attribute__((overloadable)) rsElementGetSubElement(rs_element e,uint32_t index)17 rsElementGetSubElement(rs_element e, uint32_t index) { 18 Element_t *element = (Element_t *)e.p; 19 if (element == NULL || index >= element->mHal.state.fieldsCount) { 20 rs_element nullElem = {0}; 21 return nullElem; 22 } 23 rs_element returnElem = {element->mHal.state.fields[index]}; 24 return returnElem; 25 } 26 27 extern uint32_t __attribute__((overloadable)) rsElementGetSubElementNameLength(rs_element e,uint32_t index)28 rsElementGetSubElementNameLength(rs_element e, uint32_t index) { 29 Element_t *element = (Element_t *)e.p; 30 if (element == NULL || index >= element->mHal.state.fieldsCount) { 31 return 0; 32 } 33 return element->mHal.state.fieldNameLengths[index]; 34 } 35 36 extern uint32_t __attribute__((overloadable)) rsElementGetSubElementName(rs_element e,uint32_t index,char * name,uint32_t nameLength)37 rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) { 38 Element_t *element = (Element_t *)e.p; 39 if (element == NULL || index >= element->mHal.state.fieldsCount || 40 nameLength == 0 || name == 0) { 41 return 0; 42 } 43 44 uint32_t numToCopy = element->mHal.state.fieldNameLengths[index]; 45 if (nameLength < numToCopy) { 46 numToCopy = nameLength; 47 } 48 // Place the null terminator manually, in case of partial string 49 numToCopy --; 50 name[numToCopy] = '\0'; 51 const char *nameSource = element->mHal.state.fieldNames[index]; 52 for (uint32_t i = 0; i < numToCopy; i ++) { 53 name[i] = nameSource[i]; 54 } 55 return numToCopy; 56 } 57 58 extern uint32_t __attribute__((overloadable)) rsElementGetSubElementArraySize(rs_element e,uint32_t index)59 rsElementGetSubElementArraySize(rs_element e, uint32_t index) { 60 Element_t *element = (Element_t *)e.p; 61 if (element == NULL || index >= element->mHal.state.fieldsCount) { 62 return 0; 63 } 64 return element->mHal.state.fieldArraySizes[index]; 65 } 66 67 extern uint32_t __attribute__((overloadable)) rsElementGetSubElementOffsetBytes(rs_element e,uint32_t index)68 rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) { 69 Element_t *element = (Element_t *)e.p; 70 if (element == NULL || index >= element->mHal.state.fieldsCount) { 71 return 0; 72 } 73 return element->mHal.state.fieldOffsetBytes[index]; 74 } 75 76 extern uint32_t __attribute__((overloadable)) rsElementGetBytesSize(rs_element e)77 rsElementGetBytesSize(rs_element e) { 78 Element_t *element = (Element_t *)e.p; 79 if (element == NULL) { 80 return 0; 81 } 82 return element->mHal.state.elementSizeBytes; 83 } 84 85 extern rs_data_type __attribute__((overloadable)) rsElementGetDataType(rs_element e)86 rsElementGetDataType(rs_element e) { 87 Element_t *element = (Element_t *)e.p; 88 if (element == NULL) { 89 return RS_TYPE_INVALID; 90 } 91 return element->mHal.state.dataType; 92 } 93 94 extern rs_data_kind __attribute__((overloadable)) rsElementGetDataKind(rs_element e)95 rsElementGetDataKind(rs_element e) { 96 Element_t *element = (Element_t *)e.p; 97 if (element == NULL) { 98 return RS_KIND_INVALID; 99 } 100 return element->mHal.state.dataKind; 101 } 102 103 extern uint32_t __attribute__((overloadable)) rsElementGetVectorSize(rs_element e)104 rsElementGetVectorSize(rs_element e) { 105 Element_t *element = (Element_t *)e.p; 106 if (element == NULL) { 107 return 0; 108 } 109 return element->mHal.state.vectorSize; 110 } 111