• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_TYPED_ARRAYS_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_TYPED_ARRAYS_H
18 
19 #include "plugins/ets/runtime/types/ets_object.h"
20 #include "plugins/ets/runtime/types/ets_string.h"
21 
22 namespace ark::ets {
23 class EtsEscompatTypedArrayBase : public EtsObject {
24 public:
25     EtsEscompatTypedArrayBase() = delete;
26     ~EtsEscompatTypedArrayBase() = delete;
27 
28     NO_COPY_SEMANTIC(EtsEscompatTypedArrayBase);
29     NO_MOVE_SEMANTIC(EtsEscompatTypedArrayBase);
30 
GetClassSize()31     static constexpr size_t GetClassSize()
32     {
33         return sizeof(EtsEscompatTypedArrayBase);
34     }
35 
GetBufferOffset()36     static constexpr size_t GetBufferOffset()
37     {
38         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, buffer_);
39     }
40 
GetBytesPerElementOffset()41     static constexpr size_t GetBytesPerElementOffset()
42     {
43         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, bytesPerElement_);
44     }
45 
GetByteOffsetOffset()46     static constexpr size_t GetByteOffsetOffset()
47     {
48         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, byteOffset_);
49     }
50 
GetByteLengthOffset()51     static constexpr size_t GetByteLengthOffset()
52     {
53         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, byteLength_);
54     }
55 
GetNameOffset()56     static constexpr size_t GetNameOffset()
57     {
58         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, name_);
59     }
60 
GetLengthIntOffset()61     static constexpr size_t GetLengthIntOffset()
62     {
63         return MEMBER_OFFSET(EtsEscompatTypedArrayBase, lengthInt_);
64     }
65 
GetBuffer()66     ObjectPointer<EtsObject> GetBuffer() const
67     {
68         return EtsObject::FromCoreType(ObjectAccessor::GetObject(this, GetBufferOffset()));
69     }
70 
SetBuffer(ObjectPointer<EtsObject> buffer)71     void SetBuffer(ObjectPointer<EtsObject> buffer)
72     {
73         buffer_ = buffer;
74     }
75 
GetByteOffset()76     EtsDouble GetByteOffset() const
77     {
78         return byteOffset_;
79     }
80 
SetByteOffset(EtsDouble offset)81     void SetByteOffset(EtsDouble offset)
82     {
83         byteOffset_ = offset;
84     }
85 
GetByteLength()86     EtsDouble GetByteLength() const
87     {
88         return byteLength_;
89     }
90 
SetByteLength(EtsDouble byteLength)91     void SetByteLength(EtsDouble byteLength)
92     {
93         byteLength_ = byteLength;
94     }
95 
GetBytesPerElement()96     EtsDouble GetBytesPerElement() const
97     {
98         return bytesPerElement_;
99     }
100 
GetLengthInt()101     EtsInt GetLengthInt() const
102     {
103         return lengthInt_;
104     }
105 
SetLengthInt(EtsInt length)106     void SetLengthInt(EtsInt length)
107     {
108         lengthInt_ = length;
109     }
110 
GetName()111     ObjectPointer<EtsString> GetName() const
112     {
113         return EtsString::FromEtsObject(EtsObject::FromCoreType(ObjectAccessor::GetObject(this, GetNameOffset())));
114     }
115 
116 private:
117     ObjectPointer<EtsObject> buffer_;
118     ObjectPointer<EtsString> name_;
119     EtsDouble bytesPerElement_;
120     EtsDouble byteOffset_;
121     EtsDouble byteLength_;
122     EtsInt lengthInt_;
123 };
124 
125 template <typename T>
126 class EtsEscompatTypedArray : public EtsEscompatTypedArrayBase {
127 public:
128     using ElementType = T;
129 };
130 
131 class EtsEscompatInt8Array : public EtsEscompatTypedArray<EtsByte> {};
132 class EtsEscompatInt16Array : public EtsEscompatTypedArray<EtsShort> {};
133 class EtsEscompatInt32Array : public EtsEscompatTypedArray<EtsInt> {};
134 class EtsEscompatBigInt64Array : public EtsEscompatTypedArray<EtsLong> {};
135 class EtsEscompatFloat32Array : public EtsEscompatTypedArray<EtsFloat> {};
136 class EtsEscompatFloat64Array : public EtsEscompatTypedArray<EtsDouble> {};
137 }  // namespace ark::ets
138 
139 #endif  // PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_TYPED_ARRAYS_H
140