Mercurial > hg > jslab
view 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 source
/* * 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; } }