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