Use hold_until_date in item_scheduler.
[order_line_extra.git] / hincludes / lib / HList.class.php
1 <?php
2
3 class HList implements IteratorAggregate{
4         public function __construct() {
5                 if(!php_Boot::$skip_constructor) {
6                 $this->length = 0;
7         }}
8         public function getIterator() {
9                 return $this->iterator();
10         }
11         public function map($f) {
12                 $b = new HList();
13                 $l = $this->h;
14                 while($l !== null) {
15                         $v = $l[0];
16                         $l = $l[1];
17                         $b->add(call_user_func_array($f, array($v)));
18                         unset($v);
19                 }
20                 return $b;
21         }
22         public function filter($f) {
23                 $l2 = new HList();
24                 $l = $this->h;
25                 while($l !== null) {
26                         $v = $l[0];
27                         $l = $l[1];
28                         if(call_user_func_array($f, array($v))) {
29                                 $l2->add($v);
30                         }
31                         unset($v);
32                 }
33                 return $l2;
34         }
35         public function join($sep) {
36                 $s = "";
37                 $first = true;
38                 $l = $this->h;
39                 while($l !== null) {
40                         if($first) {
41                                 $first = false;
42                         } else {
43                                 $s .= $sep;
44                         }
45                         $s .= Std::string($l[0]);
46                         $l = $l[1];
47                 }
48                 return $s;
49         }
50         public function toString() {
51                 $s = "";
52                 $first = true;
53                 $l = $this->h;
54                 while($l !== null) {
55                         if($first) {
56                                 $first = false;
57                         } else {
58                                 $s .= ", ";
59                         }
60                         $s .= Std::string($l[0]);
61                         $l = $l[1];
62                 }
63                 return "{" . $s . "}";
64         }
65         public function iterator() {
66                 return new _hx_list_iterator($this);
67         }
68         public function remove($v) {
69                 $prev = null;
70                 $l = & $this->h;
71                 while($l !== null) {
72                         if($l[0] === $v) {
73                                 if($prev === null) {
74                                         $this->h =& $l[1];
75                                 } else {
76                                         $prev[1] =& $l[1];
77                                 }
78                                 if(($this->q === $l)) {
79                                         $this->q =& $prev;
80                                 }
81                                 $this->length--;
82                                 return true;
83                         }
84                         $prev =& $l;
85                         $l =& $l[1];
86                 }
87                 return false;
88         }
89         public function clear() {
90                 $this->h = null;
91                 $this->q = null;
92                 $this->length = 0;
93         }
94         public function isEmpty() {
95                 return $this->h === null;
96         }
97         public function pop() {
98                 if($this->h === null) {
99                         return null;
100                 }
101                 $x = $this->h[0];
102                 $this->h = $this->h[1];
103                 if($this->h === null) {
104                         $this->q = null;
105                 }
106                 $this->length--;
107                 return $x;
108         }
109         public function last() {
110                 return HList_0($this);
111         }
112         public function first() {
113                 return HList_1($this);
114         }
115         public function push($item) {
116                 $x = array($item, &$this->h);
117                 $this->h =& $x;
118                 if($this->q === null) {
119                         $this->q =& $x;
120                 }
121                 $this->length++;
122         }
123         public function add($item) {
124                 $x = array($item, null);
125                 if($this->h === null) {
126                         $this->h =& $x;
127                 } else {
128                         $this->q[1] =& $x;
129                 }
130                 $this->q =& $x;
131                 $this->length++;
132         }
133         public $length;
134         public $q;
135         public $h;
136         public function __call($m, $a) {
137                 if(isset($this->$m) && is_callable($this->$m))
138                         return call_user_func_array($this->$m, $a);
139                 else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
140                         return call_user_func_array($this->»dynamics[$m], $a);
141                 else if('toString' == $m)
142                         return $this->__toString();
143                 else
144                         throw new HException('Unable to call «'.$m.'»');
145         }
146         function __toString() { return $this->toString(); }
147 }
148 function HList_0(&$»this) {
149         if($»this->q === null) {
150                 return null;
151         } else {
152                 return $»this->q[0];
153         }
154 }
155 function HList_1(&$»this) {
156         if($»this->h === null) {
157                 return null;
158         } else {
159                 return $»this->h[0];
160         }
161 }