summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/array.h
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
committerKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
commitbab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch)
tree10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/array.h
parent8643d90372e9c31e0f461c15c596b60a545bd7d3 (diff)
asymptote 1.72 sources (not integrated into build yet)
git-svn-id: svn://tug.org/texlive/trunk@13110 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/array.h')
-rw-r--r--Build/source/utils/asymptote/array.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/array.h b/Build/source/utils/asymptote/array.h
new file mode 100644
index 00000000000..0fab8f5f693
--- /dev/null
+++ b/Build/source/utils/asymptote/array.h
@@ -0,0 +1,112 @@
+/*****
+ * array.h
+ * Tom Prince 2005/06/18
+ *
+ * Array type used by virtual machine.
+ *****/
+
+#ifndef ARRAY_H
+#define ARRAY_H
+
+#include "vm.h"
+#include "common.h"
+#include "item.h"
+
+namespace vm {
+
+// Arrays are vectors with push and pop functions.
+class array : public mem::vector<item> {
+ bool cycle;
+
+ void setNonBridgingSlice(size_t l, size_t r, mem::vector<item> *a);
+ void setBridgingSlice(size_t l, size_t r, mem::vector<item> *a);
+public:
+ array() : cycle(false) {}
+
+ array(size_t n)
+ : mem::vector<item>(n), cycle(false)
+ {}
+
+ array(size_t n, item i, Int depth);
+
+ void push(item i)
+ {
+ push_back(i);
+ }
+
+ item pop()
+ {
+ item i=back();
+ pop_back();
+ return i;
+ }
+
+ template <typename T>
+ T read(size_t i) const
+ {
+ return get<T>((*this)[i]);
+ }
+
+ array *slice(Int left, Int right);
+ void setSlice(Int left, Int right, array *a);
+
+ void cyclic(bool b) {
+ cycle=b;
+ }
+
+ bool cyclic() const {
+ return cycle;
+ }
+
+ array *copyToDepth(Int depth);
+};
+
+template <typename T>
+inline T read(array *a, size_t i)
+{
+ return a->array::read<T>(i);
+}
+
+template <typename T>
+inline T read(const array &a, size_t i)
+{
+ return a.array::read<T>(i);
+}
+
+inline size_t checkArray(const vm::array *a)
+{
+ if(a == 0) vm::error("dereference of null array");
+ return a->size();
+}
+
+inline void checkEqual(size_t i, size_t j) {
+ if(i == j) return;
+ ostringstream buf;
+ buf << "operation attempted on arrays of different lengths: "
+ << i << " != " << j;
+ vm::error(buf);
+}
+
+inline size_t checkArrays(const vm::array *a, const vm::array *b)
+{
+ size_t asize=checkArray(a);
+ size_t bsize=checkArray(b);
+ checkEqual(asize,bsize);
+ return asize;
+}
+
+// Tests if an item is actually an array. This needs to be defined here,
+// after the array type is declared.
+inline bool isarray(const item& it)
+{
+ return *it.kind == typeid(array);
+}
+
+// Copies an item to a depth d. If d==0 or if the item is not array, then the
+// item is just returned without copying, otherwise, the array and its
+// subarrays are copied as deeply as possible up to a depth d.
+item copyItemToDepth(item i, Int depth);
+
+} // namespace vm
+
+#endif // ARRAY_H