You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
953 B
46 lines
953 B
#pragma once
|
|
#include <iostream>
|
|
#include "CArrayBuffer.h"
|
|
#include "CDataView.h"
|
|
|
|
class CFloat32Array {
|
|
public:
|
|
CArrayBuffer* buffer;
|
|
int byteOffset;
|
|
int byteLength;
|
|
|
|
private:
|
|
int _length;
|
|
bool _deleteBuffer;
|
|
|
|
public:
|
|
CFloat32Array(int length) {
|
|
this->buffer = new CArrayBuffer(length * sizeof(float32));
|
|
this->_length = length;
|
|
this->_deleteBuffer = true;
|
|
}
|
|
|
|
CFloat32Array(CArrayBuffer* buffer, int byteOffset, int length) {
|
|
this->buffer = buffer;
|
|
this->byteOffset = byteOffset;
|
|
this->_length = length;
|
|
this->byteLength = length * sizeof(float32);
|
|
this->_deleteBuffer = false;
|
|
}
|
|
|
|
~CFloat32Array() {
|
|
if (this->_deleteBuffer) {
|
|
delete this->buffer;
|
|
this->buffer = nullptr;
|
|
printf("delete");
|
|
}
|
|
}
|
|
|
|
float32& operator [](int idx) {
|
|
return *((float32*)(this->buffer->pData + (this->byteOffset + idx * sizeof(float32))));
|
|
}
|
|
|
|
int length() {
|
|
return this->_length;
|
|
}
|
|
};
|