1 | define(["dojo/_base/kernel", "dojo/_base/array", "./_base"], function(dojo, darray, dxc){ |
---|
2 | |
---|
3 | dxc.Stack=function(/*array?*/ arr){ |
---|
4 | // summary: |
---|
5 | // returns an object of type dojox.collections.Stack |
---|
6 | var q=[]; |
---|
7 | if (arr) q=q.concat(arr); |
---|
8 | this.count=q.length; |
---|
9 | this.clear=function(){ |
---|
10 | // summary: |
---|
11 | // Clear the internal array and reset the count |
---|
12 | q=[]; |
---|
13 | this.count=q.length; |
---|
14 | }; |
---|
15 | this.clone=function(){ |
---|
16 | // summary: |
---|
17 | // Create and return a clone of this Stack |
---|
18 | return new dxc.Stack(q); |
---|
19 | }; |
---|
20 | this.contains=function(/*object*/ o){ |
---|
21 | // summary: |
---|
22 | // check to see if the stack contains object o |
---|
23 | for (var i=0; i<q.length; i++){ |
---|
24 | if (q[i] == o){ |
---|
25 | return true; // bool |
---|
26 | } |
---|
27 | } |
---|
28 | return false; // bool |
---|
29 | }; |
---|
30 | this.copyTo=function(/*array*/ arr, /*int*/ i){ |
---|
31 | // summary: |
---|
32 | // copy the stack into array arr at index i |
---|
33 | arr.splice(i,0,q); |
---|
34 | }; |
---|
35 | this.forEach=function(/*function*/ fn, /*object?*/ scope){ |
---|
36 | // summary: |
---|
37 | // functional iterator, following the mozilla spec. |
---|
38 | dojo.forEach(q, fn, scope); |
---|
39 | }; |
---|
40 | this.getIterator=function(){ |
---|
41 | // summary: |
---|
42 | // get an iterator for this collection |
---|
43 | return new dxc.Iterator(q); // dojox.collections.Iterator |
---|
44 | }; |
---|
45 | this.peek=function(){ |
---|
46 | // summary: |
---|
47 | // Return the next item without altering the stack itself. |
---|
48 | return q[(q.length-1)]; // object |
---|
49 | }; |
---|
50 | this.pop=function(){ |
---|
51 | // summary: |
---|
52 | // pop and return the next item on the stack |
---|
53 | var r=q.pop(); |
---|
54 | this.count=q.length; |
---|
55 | return r; // object |
---|
56 | }; |
---|
57 | this.push=function(/*object*/ o){ |
---|
58 | // summary: |
---|
59 | // Push object o onto the stack |
---|
60 | this.count=q.push(o); |
---|
61 | }; |
---|
62 | this.toArray=function(){ |
---|
63 | // summary: |
---|
64 | // create and return an array based on the internal collection |
---|
65 | return [].concat(q); // array |
---|
66 | }; |
---|
67 | }; |
---|
68 | return dxc.Stack; |
---|
69 | }); |
---|