callback.hh revision 2
12686Sksewell@umich.edu/* 22686Sksewell@umich.edu * Copyright (c) 2003 The Regents of The University of Michigan 32022SN/A * All rights reserved. 42022SN/A * 52022SN/A * Redistribution and use in source and binary forms, with or without 62022SN/A * modification, are permitted provided that the following conditions are 72022SN/A * met: redistributions of source code must retain the above copyright 82022SN/A * notice, this list of conditions and the following disclaimer; 92022SN/A * redistributions in binary form must reproduce the above copyright 102022SN/A * notice, this list of conditions and the following disclaimer in the 112022SN/A * documentation and/or other materials provided with the distribution; 122022SN/A * neither the name of the copyright holders nor the names of its 132022SN/A * contributors may be used to endorse or promote products derived from 142447SN/A * this software without specific prior written permission. 152022SN/A * 162022SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172022SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182447SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192022SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202022SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212687Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222523SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232523SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242686Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252022SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262022SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272022SN/A */ 282022SN/A 292022SN/A#ifndef __CALLBACK_HH__ 302447SN/A#define __CALLBACK_HH__ 312447SN/A 322022SN/A#include <list> 332022SN/A 342022SN/Aclass Callback { 352523SN/A public: 362447SN/A virtual ~Callback() {} 372686Sksewell@umich.edu virtual void process() = 0; 382686Sksewell@umich.edu}; 392022SN/A 402022SN/Aclass CallbackQueue 412022SN/A{ 422022SN/A protected: 432022SN/A std::list<Callback *> callbacks; 442022SN/A 452022SN/A public: 462022SN/A void add(Callback *callback) { callbacks.push_back(callback); } 472022SN/A bool empty() const { return callbacks.empty(); } 482022SN/A void processOne() { 492022SN/A Callback *c = callbacks.front(); 502447SN/A callbacks.pop_front(); 512447SN/A c->process(); 522022SN/A } 532022SN/A void processAll() { while (!empty()) processOne(); } 54}; 55 56#endif // __CALLBACK_HH__ 57