Overte C++ Documentation
TypedArrays.h
1 //
2 // TypedArrays.h
3 //
4 //
5 // Created by Clement on 7/9/14.
6 // Copyright 2014 High Fidelity, Inc.
7 // Copyright 2023 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 
16 
17 #ifndef hifi_TypedArrays_h
18 #define hifi_TypedArrays_h
19 
20 // V8TODO Do not remove yet, this will be useful in later PRs
21 /*#include "ArrayBufferViewClass.h"
22 
23 static const QString BYTES_PER_ELEMENT_PROPERTY_NAME = "BYTES_PER_ELEMENT";
24 static const QString LENGTH_PROPERTY_NAME = "length";
25 
26 static const QString INT_8_ARRAY_CLASS_NAME = "Int8Array";
27 static const QString UINT_8_ARRAY_CLASS_NAME = "Uint8Array";
28 static const QString UINT_8_CLAMPED_ARRAY_CLASS_NAME = "Uint8ClampedArray";
29 static const QString INT_16_ARRAY_CLASS_NAME = "Int16Array";
30 static const QString UINT_16_ARRAY_CLASS_NAME = "Uint16Array";
31 static const QString INT_32_ARRAY_CLASS_NAME = "Int32Array";
32 static const QString UINT_32_ARRAY_CLASS_NAME = "Uint32Array";
33 static const QString FLOAT_32_ARRAY_CLASS_NAME = "Float32Array";
34 static const QString FLOAT_64_ARRAY_CLASS_NAME = "Float64Array";
35 
37 class TypedArray : public ArrayBufferViewClass {
38  Q_OBJECT
39 public:
40  TypedArray(ScriptEngineV8* scriptEngine, QString name);
41  virtual V8ScriptValue newInstance(quint32 length);
42  virtual V8ScriptValue newInstance(V8ScriptValue array);
43  virtual V8ScriptValue newInstance(V8ScriptValue buffer, quint32 byteOffset, quint32 length);
44 
45  virtual QueryFlags queryProperty(const V8ScriptValue& object,
46  const V8ScriptString& name,
47  QueryFlags flags, uint* id) override;
48  virtual V8ScriptValue property(const V8ScriptValue& object,
49  const V8ScriptString& name, uint id) override;
50  virtual void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override = 0;
51  virtual V8ScriptValue::PropertyFlags propertyFlags(const V8ScriptValue& object,
52  const V8ScriptString& name, uint id) override;
53 
54  QString name() const override;
55  V8ScriptValue prototype() const override;
56 
57 protected:
58  static V8ScriptValue construct(V8ScriptContext* context, QScriptEngine* engine);
59 
60  void setBytesPerElement(quint32 bytesPerElement);
61 
62  V8ScriptValue _proto;
63  V8ScriptValue _ctor;
64 
65  V8ScriptString _name;
66  V8ScriptString _bytesPerElementName;
67  V8ScriptString _lengthName;
68 
69  quint32 _bytesPerElement;
70 
71  friend class TypedArrayPrototype;
72 };
73 
74 class Int8ArrayClass : public TypedArray {
75  Q_OBJECT
76 public:
77  Int8ArrayClass(ScriptEngineV8* scriptEngine);
78 
79  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
80  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
81 };
82 
83 class Uint8ArrayClass : public TypedArray {
84  Q_OBJECT
85 public:
86  Uint8ArrayClass(ScriptEngineV8* scriptEngine);
87 
88  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
89  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
90 };
91 
92 class Uint8ClampedArrayClass : public TypedArray {
93  Q_OBJECT
94 public:
95  Uint8ClampedArrayClass(ScriptEngineV8* scriptEngine);
96 
97  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
98  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
99 };
100 
101 class Int16ArrayClass : public TypedArray {
102  Q_OBJECT
103 public:
104  Int16ArrayClass(ScriptEngineV8* scriptEngine);
105 
106  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
107  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
108 };
109 
110 class Uint16ArrayClass : public TypedArray {
111  Q_OBJECT
112 public:
113  Uint16ArrayClass(ScriptEngineV8* scriptEngine);
114 
115  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
116  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
117 };
118 
119 class Int32ArrayClass : public TypedArray {
120  Q_OBJECT
121 public:
122  Int32ArrayClass(ScriptEngineV8* scriptEngine);
123 
124  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
125  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
126 };
127 
128 class Uint32ArrayClass : public TypedArray {
129  Q_OBJECT
130 public:
131  Uint32ArrayClass(ScriptEngineV8* scriptEngine);
132 
133  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
134  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
135 };
136 
137 class Float32ArrayClass : public TypedArray {
138  Q_OBJECT
139 public:
140  Float32ArrayClass(ScriptEngineV8* scriptEngine);
141 
142  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
143  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
144 };
145 
146 class Float64ArrayClass : public TypedArray {
147  Q_OBJECT
148 public:
149  Float64ArrayClass(ScriptEngineV8* scriptEngine);
150 
151  V8ScriptValue property(const V8ScriptValue& object, const V8ScriptString& name, uint id) override;
152  void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value) override;
153 };
154 */
155 #endif // hifi_TypedArrays_h
156