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

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2001, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.tools;
11 import samer.core.types.*;
12
13 /**
14 * This is a task that runs a single child task
15 * every N iterations, that is, at some integer
16 * sub-multiple of the main loop rate
17 */
18
19 public class SwitchTask implements Task
20 {
21 private Task task;
22 private VBoolean enable;
23
24 public SwitchTask(Task t) { this(true,t); }
25 public SwitchTask(boolean e, Task t) {
26 enable=new VBoolean("enable",e);
27 enable.value=e; enable.changed(); task=t;
28 }
29
30
31 public void enable() { enable.value=true; enable.changed(); }
32 public void disable() { enable.value=false; enable.changed(); }
33
34 public final void starting() { if (enable.value) task.starting(); }
35 public final void stopping() { if (enable.value) task.stopping(); }
36 public final void run() throws Exception { if (enable.value) task.run(); }
37
38 public void dispose() { task.dispose(); }
39 public String toString() { return "Switch("+enable.value+"):"+task; }
40 }