Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Commit

Permalink
Fixed Queues, added ds_queue_copy(id,source) :)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/gjava/code@1741 0bf6c8e7-452b-0410-8c87-9aaedaf074f6
  • Loading branch information
amorri40 committed Sep 7, 2009
1 parent f75059b commit 4d1ae7b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
31 changes: 31 additions & 0 deletions Dolphin2/src/org/dolphin/game/api/GCL.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ public static Object real(Object str)

public static Object string(Object val)
{
try {
return val.toString();
} catch(Exception e){
//null val?
ErrorHandler.showError(e,false);
}
return "";
}

public static Object tostring(Object val)
Expand Down Expand Up @@ -5066,10 +5072,14 @@ public static Object ds_stack_pop(Object id)

public static Object ds_stack_top(Object id)
{
try{
if (id instanceof Stack)
{
return ((Stack)id).top();
}
} catch(Exception e){
ErrorHandler.showError(e,false);
}
return 0d;
}

Expand Down Expand Up @@ -5102,6 +5112,15 @@ public static Object ds_queue_clear(Object id)
return 0d;
}

public static Object ds_queue_copy(Object id,Object source)
{
if (id instanceof Queue && source instanceof Queue)
{
((Queue)id).l=((Queue)source).getCopy().l;
}
return 0d;
}

public static Object ds_queue_size(Object id)
{
if (id instanceof Queue)
Expand Down Expand Up @@ -5131,28 +5150,40 @@ public static Object ds_queue_enqueue(Object id, Object value)

public static Object ds_queue_dequeue(Object id)
{
try{
if (id instanceof Queue)
{
return ((Queue)id).dequeue();
}
} catch(Exception e){
ErrorHandler.showError(e,false);
}
return 0d;
}

public static Object ds_queue_head(Object id)
{
try{
if (id instanceof Queue)
{
return ((Queue)id).head();
}
} catch(Exception e){
ErrorHandler.showError(e,false);
}
return 0d;
}

public static Object ds_queue_tail(Object id)
{
try {
if (id instanceof Queue)
{
return ((Queue)id).tail();
}
} catch(Exception e){
ErrorHandler.showError(e,false);
}
return 0d;
}

Expand Down
21 changes: 14 additions & 7 deletions Dolphin2/src/org/dolphin/game/api/types/Queue.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dolphin.game.api.types;

public class Queue extends Variable {
java.util.LinkedList l;
public java.util.LinkedList l;

public Queue(){
l = new java.util.LinkedList();
Expand All @@ -16,6 +16,13 @@ public void clear()
{
l.clear();
}

public Queue getCopy()
{
Queue copy = new Queue();
copy.l.addAll(0, l);
return copy;
}

public int size()
{
Expand All @@ -34,18 +41,18 @@ public boolean enqueue(Object o)
return l.add(o);
}

public Variable dequeue()
public Object dequeue()
{
return (Variable) l.poll();
return l.poll();
}

public Variable head()
public Object head()
{
return (Variable) l.getLast();
return l.getLast();
}

public Variable tail()
public Object tail()
{
return (Variable) l.getFirst();
return l.getFirst();
}
}
4 changes: 2 additions & 2 deletions Dolphin2/src/org/dolphin/game/api/types/Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void push(Object o)

public Object pop()
{
return (Object)s.pop();
return s.pop();
}
public Object top()
{
return (Object)s.firstElement();
return s.firstElement();
}

}
15 changes: 15 additions & 0 deletions Dolphin2/src/org/dolphin/gmlUnitTests/Queue_unit_test.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Test ds_queue_copy
*/
dsi = ds_queue_create()
ds2 = ds_queue_create()
ds_queue_enqueue(dsi,10)
ds_queue_enqueue(dsi,11)
ds_queue_enqueue(ds2,2)
ds_queue_copy(ds2,dsi)
show_message("Should be 10:"+string(ds_queue_dequeue(ds2)));
show_message("Should be 11:"+string(ds_queue_dequeue(ds2)));
show_message("Should be 0:"+string(ds_queue_dequeue(ds2)));
show_message("Should be 10:"+string(ds_queue_dequeue(dsi)));
ds_queue_destroy(dsi);
ds_queue_destroy(ds2);
6 changes: 6 additions & 0 deletions Dolphin2/src/org/dolphin/gmlUnitTests/Stack_unit_test.gml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Test ds_stack_copy
*/
dsi = ds_stack_create()
ds2 = ds_stack_create()
ds_stack_push(dsi,10)
ds_stack_push(dsi,11)
ds_stack_push(ds2,2)
ds_stack_copy(ds2,dsi)
show_message("Should be 11:"+string(ds_stack_pop(ds2)));
show_message("Should be 10:"+string(ds_stack_pop(ds2)));
show_message("Should be 0:"+string(ds_stack_pop(ds2)));
show_message("Should be 11:"+string(ds_stack_pop(dsi)));
ds_stack_destroy(dsi);
ds_stack_destroy(ds2);

0 comments on commit 4d1ae7b

Please sign in to comment.