summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/runpair.cc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-05-09 00:26:15 +0000
committerKarl Berry <karl@freefriends.org>2010-05-09 00:26:15 +0000
commit0114fbc0beecd9a094b260d78cccdc6ff3e85f1e (patch)
tree53f68a7eb4cd90f611560e9b477b55c671b94717 /Build/source/utils/asymptote/runpair.cc
parent539c0d5c885fa1c451a55ef8e7e1a2bbf1a32861 (diff)
asy 1.94
git-svn-id: svn://tug.org/texlive/trunk@18161 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/runpair.cc')
-rw-r--r--Build/source/utils/asymptote/runpair.cc53
1 files changed, 47 insertions, 6 deletions
diff --git a/Build/source/utils/asymptote/runpair.cc b/Build/source/utils/asymptote/runpair.cc
index c4e98e1b763..cd44539d9e3 100644
--- a/Build/source/utils/asymptote/runpair.cc
+++ b/Build/source/utils/asymptote/runpair.cc
@@ -31,6 +31,7 @@
using vm::stack;
using vm::error;
using vm::array;
+using vm::read;
using vm::callable;
using types::formal;
using types::function;
@@ -49,12 +50,52 @@ array *copyArray(array *a);
array *copyArray2(array *a);
array *copyArray3(array *a);
-double *copyArrayC(const array *a, size_t dim=0, GCPlacement placement=NoGC);
-double *copyArray2C(const array *a, bool square=true, size_t dim2=0,
- GCPlacement placement=NoGC);
+inline size_t checkdimension(const array *a, size_t dim)
+{
+ size_t size=checkArray(a);
+ if(dim && size != dim) {
+ ostringstream buf;
+ buf << "array of length " << dim << " expected";
+ error(buf);
+ }
+ return size;
+}
+
+template<class T>
+void copyArrayC(T* &dest, const array *a, size_t dim=0,
+ GCPlacement placement=NoGC)
+{
+ size_t size=checkdimension(a,dim);
+ dest=(placement == NoGC) ? new T[size] : new(placement) T[size];
+ for(size_t i=0; i < size; i++)
+ dest[i]=read<T>(a,i);
+}
+
+template<class T>
+void copyArray2C(T* &dest, const array *a, bool square=true, size_t dim2=0,
+ GCPlacement placement=NoGC)
+{
+ size_t n=checkArray(a);
+ size_t m=(square || n == 0) ? n : checkArray(read<array*>(a,0));
+ if(n > 0 && dim2 && m != dim2) {
+ ostringstream buf;
+ buf << "second matrix dimension must be " << dim2;
+ error(buf);
+ }
+
+ dest=(placement == NoGC) ? new T[n*m] : new(placement) T[n*m];
+ for(size_t i=0; i < n; i++) {
+ array *ai=read<array*>(a,i);
+ size_t aisize=checkArray(ai);
+ if(aisize == m) {
+ T *desti=dest+i*m;
+ for(size_t j=0; j < m; j++)
+ desti[j]=read<T>(ai,j);
+ } else
+ error(square ? "matrix must be square" : "matrix must be rectangular");
+ }
+}
-triple *copyTripleArrayC(const array *a, size_t dim=0);
-triple *copyTripleArray2C(const array *a, bool square=true, size_t dim2=0);
double *copyTripleArray2Components(array *a, bool square=true, size_t dim2=0,
GCPlacement placement=NoGC);
}
@@ -380,7 +421,7 @@ void gen_runpair29(stack *Stack)
pair w=vm::pop<pair>(Stack);
pair z=vm::pop<pair>(Stack);
#line 203 "runpair.in"
- {Stack->push<pair>(pair (z.getx()*w.getx(),z.gety()*w.gety())); return;}
+ {Stack->push<pair>(pair(z.getx()*w.getx(),z.gety()*w.gety())); return;}
}
// To avoid confusion, a dot product requires explicit pair arguments.