#ifndef Int32Array_h
#define Int32Array_h
#include "ArrayBufferView.h"
#include <limits>
#include <wtf/MathExtras.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
namespace WebCore {
class Int32Array : public ArrayBufferView {
public:
virtual bool isIntArray() const { return true; }
static PassRefPtr<Int32Array> create(unsigned length);
static PassRefPtr<Int32Array> create(int* array, unsigned length);
static PassRefPtr<Int32Array> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length);
int* data() { return static_cast<int*>(baseAddress()); }
virtual unsigned length() const;
virtual unsigned byteLength() const;
virtual PassRefPtr<ArrayBufferView> slice(int start, int end);
void set(unsigned index, double value)
{
if (index >= m_size)
return;
if (isnan(value)) value = 0;
if (value < std::numeric_limits<int>::min())
value = std::numeric_limits<int>::min();
else if (value > std::numeric_limits<int>::max())
value = std::numeric_limits<int>::max();
int* storage = static_cast<int*>(m_baseAddress);
storage[index] = static_cast<int>(value);
}
bool get(unsigned index, int& result) const
{
if (index >= m_size)
return false;
result = item(index);
return true;
}
int get(unsigned index) const
{
return item(index);
}
int item(unsigned index) const
{
ASSERT(index < m_size);
int* storage = static_cast<int*>(m_baseAddress);
return storage[index];
}
void set(Int32Array* array, unsigned offset, ExceptionCode& ec);
private:
Int32Array(PassRefPtr<ArrayBuffer> buffer,
unsigned byteOffset,
unsigned length);
unsigned m_size;
};
}
#endif // Int32Array_h