File: array.h

package info (click to toggle)
asymptote 1.14-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,852 kB
  • ctags: 5,279
  • sloc: cpp: 23,050; ansic: 1,810; perl: 1,405; lisp: 759; yacc: 529; lex: 372; python: 357; makefile: 293; sh: 227
file content (82 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*****
 * array.h
 * Tom Prince 2005/06/18
 * 
 * Array type used by virtual machine.
 *****/

#ifndef ARRAY_H
#define ARRAY_H

#include "vm.h"
#include "memory.h"
#include "item.h"

namespace vm {

// Arrays are vectors with push and pop functions.
class array : public mem::deque<item>, public gc {
bool cycle;  
public:
  array(size_t n)
    : mem::deque<item>(n), cycle(false)
  {}

  void push(item i)
  {
    push_back(i);
  }

  item pop()
  {
    item i=back();
    pop_back();
    return i;
  }

  template <typename T>
  T read(size_t i)
  {
    return get<T>((*this)[i]);
  }
  
  void cyclic(bool b) {
    cycle=b;
  }
  
  bool cyclic() {
    return cycle;
  }
};

template <typename T>
inline T read(array *a, size_t i)
{
  return a->array::read<T>(i);
}

template <typename T>
inline T read(array &a, size_t i)
{
  return a.array::read<T>(i);
}

inline size_t checkArray(vm::array *a)
{
  if(a == 0) vm::error("dereference of null array");
  return a->size();
}

extern const char *arraymismatch;

inline size_t checkArrays(vm::array *a, vm::array *b) 
{
  size_t asize=checkArray(a);
  if(asize != checkArray(b))
    vm::error(arraymismatch);
  return asize;
}
 
} // namespace vm

#endif // ARRAY_H