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     rs_element rs_retval = {0};
25     rsSetObject(&rs_retval, returnElem);
26     return rs_retval;
27 }
28 
29 extern uint32_t __attribute__((overloadable))
rsElementGetSubElementNameLength(rs_element e,uint32_t index)30         rsElementGetSubElementNameLength(rs_element e, uint32_t index) {
31     Element_t *element = (Element_t *)e.p;
32     if (element == NULL || index >= element->mHal.state.fieldsCount) {
33         return 0;
34     }
35     return element->mHal.state.fieldNameLengths[index];
36 }
37 
38 extern uint32_t __attribute__((overloadable))
rsElementGetSubElementName(rs_element e,uint32_t index,char * name,uint32_t nameLength)39         rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) {
40     Element_t *element = (Element_t *)e.p;
41     if (element == NULL || index >= element->mHal.state.fieldsCount ||
42         nameLength == 0 || name == 0) {
43         return 0;
44     }
45 
46     uint32_t numToCopy = element->mHal.state.fieldNameLengths[index];
47     if (nameLength < numToCopy) {
48         numToCopy = nameLength;
49     }
50     // Place the null terminator manually, in case of partial string
51     numToCopy --;
52     name[numToCopy] = '\0';
53     const char *nameSource = element->mHal.state.fieldNames[index];
54     for (uint32_t i = 0; i < numToCopy; i ++) {
55         name[i] = nameSource[i];
56     }
57     return numToCopy;
58 }
59 
60 extern uint32_t __attribute__((overloadable))
rsElementGetSubElementArraySize(rs_element e,uint32_t index)61         rsElementGetSubElementArraySize(rs_element e, uint32_t index) {
62     Element_t *element = (Element_t *)e.p;
63     if (element == NULL || index >= element->mHal.state.fieldsCount) {
64         return 0;
65     }
66     return element->mHal.state.fieldArraySizes[index];
67 }
68 
69 extern uint32_t __attribute__((overloadable))
rsElementGetSubElementOffsetBytes(rs_element e,uint32_t index)70         rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) {
71     Element_t *element = (Element_t *)e.p;
72     if (element == NULL || index >= element->mHal.state.fieldsCount) {
73         return 0;
74     }
75     return element->mHal.state.fieldOffsetBytes[index];
76 }
77 
78 extern uint32_t __attribute__((overloadable))
rsElementGetBytesSize(rs_element e)79         rsElementGetBytesSize(rs_element e) {
80     Element_t *element = (Element_t *)e.p;
81     if (element == NULL) {
82         return 0;
83     }
84     return element->mHal.state.elementSizeBytes;
85 }
86 
87 extern rs_data_type __attribute__((overloadable))
rsElementGetDataType(rs_element e)88         rsElementGetDataType(rs_element e) {
89     Element_t *element = (Element_t *)e.p;
90     if (element == NULL) {
91         return RS_TYPE_INVALID;
92     }
93     return element->mHal.state.dataType;
94 }
95 
96 extern rs_data_kind __attribute__((overloadable))
rsElementGetDataKind(rs_element e)97         rsElementGetDataKind(rs_element e) {
98     Element_t *element = (Element_t *)e.p;
99     if (element == NULL) {
100         return RS_KIND_INVALID;
101     }
102     return element->mHal.state.dataKind;
103 }
104 
105 extern uint32_t __attribute__((overloadable))
rsElementGetVectorSize(rs_element e)106         rsElementGetVectorSize(rs_element e) {
107     Element_t *element = (Element_t *)e.p;
108     if (element == NULL) {
109         return 0;
110     }
111     return element->mHal.state.vectorSize;
112 }
113