diff src/samer/tools/SwitchTask.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/samer/tools/SwitchTask.java	Tue Jan 17 17:50:20 2012 +0000
@@ -0,0 +1,40 @@
+/*
+ *	Copyright (c) 2001, Samer Abdallah, King's College London.
+ *	All rights reserved.
+ *
+ *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
+ *	without even the implied warranty of MERCHANTABILITY or 
+ *	FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+package samer.tools;
+import samer.core.types.*;
+
+/**
+  *		This is a task that runs a single child task
+  *		every N iterations, that is, at some integer
+  *      sub-multiple of the main loop rate
+  */
+
+public class SwitchTask implements Task
+{
+	private Task	task;
+	private VBoolean	enable;
+
+	public SwitchTask(Task t) { this(true,t); }
+	public SwitchTask(boolean e, Task t) { 
+		enable=new VBoolean("enable",e); 
+		enable.value=e; enable.changed(); task=t; 
+	}
+
+
+	public void enable() { enable.value=true; enable.changed(); }
+	public void disable() { enable.value=false; enable.changed(); }
+
+	public final void starting() { if (enable.value) task.starting(); }
+	public final void stopping() { if (enable.value) task.stopping(); }
+	public final void run() throws Exception { if (enable.value) task.run(); }
+
+	public void dispose() { task.dispose(); }
+	public String toString() { return "Switch("+enable.value+"):"+task; }
+}