| 1 |
define(["dojo/_base/kernel", "dojo/_base/array", "./_base"], function(dojo, darray, dxc){ |
| 2 |
|
| 3 |
dxc.Stack=function( arr){ |
| 4 |
|
| 5 |
|
| 6 |
var q=[]; |
| 7 |
if (arr) q=q.concat(arr); |
| 8 |
this.count=q.length; |
| 9 |
this.clear=function(){ |
| 10 |
|
| 11 |
|
| 12 |
q=[]; |
| 13 |
this.count=q.length; |
| 14 |
}; |
| 15 |
this.clone=function(){ |
| 16 |
|
| 17 |
|
| 18 |
return new dxc.Stack(q); |
| 19 |
}; |
| 20 |
this.contains=function( o){ |
| 21 |
|
| 22 |
|
| 23 |
for (var i=0; i<q.length; i++){ |
| 24 |
if (q[i] == o){ |
| 25 |
return true; |
| 26 |
} |
| 27 |
} |
| 28 |
return false; |
| 29 |
}; |
| 30 |
this.copyTo=function( arr, i){ |
| 31 |
|
| 32 |
|
| 33 |
arr.splice(i,0,q); |
| 34 |
}; |
| 35 |
this.forEach=function( fn, scope){ |
| 36 |
|
| 37 |
|
| 38 |
dojo.forEach(q, fn, scope); |
| 39 |
}; |
| 40 |
this.getIterator=function(){ |
| 41 |
|
| 42 |
|
| 43 |
return new dxc.Iterator(q); |
| 44 |
}; |
| 45 |
this.peek=function(){ |
| 46 |
|
| 47 |
|
| 48 |
return q[(q.length-1)]; |
| 49 |
}; |
| 50 |
this.pop=function(){ |
| 51 |
|
| 52 |
|
| 53 |
var r=q.pop(); |
| 54 |
this.count=q.length; |
| 55 |
return r; |
| 56 |
}; |
| 57 |
this.push=function( o){ |
| 58 |
|
| 59 |
|
| 60 |
this.count=q.push(o); |
| 61 |
}; |
| 62 |
this.toArray=function(){ |
| 63 |
|
| 64 |
|
| 65 |
return [].concat(q); |
| 66 |
}; |
| 67 |
}; |
| 68 |
return dxc.Stack; |
| 69 |
}); |