1 #include "vectorprototype.h"
2 #include <QtScript/QScriptEngine>
11 VectorPrototype::~VectorPrototype()
15 QDaqVector *VectorPrototype::thisVector()
const
24 return *thisVector() == other;
27 QString VectorPrototype::toString()
const
29 return QString(
"[object Vector]");
36 context()->throwError(QScriptContext::RangeError,
"Pushing to a null capacity circular vector.");
40 thisVector()->
push(val.toNumber());
41 else if (val.isArray()) {
42 quint32 n = val.property(
"length").toUInt32();
44 for(quint32 i=0; i<n; i++) {
45 QScriptValue vi = val.property(i);
46 if (vi.isNumber()) vec->
push(vi.toNumber());
50 else if (val.instanceOf(engine()->globalObject().property(
"Vector"))) {
53 if (rhs) vec->
push(*rhs);
64 thisVector()->resize(n);
67 QScriptValue VectorPrototype::toArray()
const
70 QScriptValue v = engine()->newArray(vec->
size());
71 for(
int i=0; i<vec->
size(); i++)
72 v.setProperty(quint32(i),qScriptValueFromValue(engine(),vec->
get(i)));
76 void VectorPrototype::clear()
78 thisVector()->
clear();
81 double VectorPrototype::min()
const
83 return thisVector()->
vmin();
85 double VectorPrototype::max()
const
87 return thisVector()->
vmax();
89 double VectorPrototype::mean()
const
91 return thisVector()->
mean();
93 double VectorPrototype::std()
const
95 return thisVector()->
std();
100 return thisObject().data();
103 bool VectorPrototype::checkRange(
int offset,
int sz)
const
105 int len = thisVector()->
size();
106 if (offset<0 || len<sz || offset>len-sz)
108 context()->throwError(QScriptContext::RangeError,tr(
"Index out of range"));
double vmin() const
Minimum value in the buffer.
double mean() const
Mean value in the buffer.
double std() const
Standard deviation the buffer values.
int size() const
Return the number of elememts stored in the buffer.
bool equals(const QDaqVector &other)
Returns true if this Vector is equal to other.
The prototype for the Vector class.
A buffer for storing double numbers.
double get(int i) const
Get the i-th element.
QScriptValue valueOf() const
Return the data stored by the object.
void push(double v)
Append a value to the buffer.
double vmax() const
Maximum value in the buffer.
bool isCircular() const
Return true if Circular.
void pop()
Remove the last element.
void clear()
Empty the buffer.
int capacity() const
Return the currently allocated memory capacity (in number of elements).
void push(const QScriptValue &val)
Push a number, a Vector or a numeric Array at the end.
void pop()
Remove the last point.
void resize(int n)
Resize to n elements keeping the first n.