Mercurial > hg > jslab
view src/samer/tools/SwitchTask.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
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; } }