Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cllbklst.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Callback list class.                              *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //                                                                     *
00009 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00010 //                                                                     *
00011 //    This program is free software; you can redistribute it and/or    *
00012 //    modify it under the terms of the GNU General Public License      *
00013 //    as published by the Free Software Foundation; either version 2   *
00014 //    of the License, or any later version.                            *
00015 //                                                                     *
00016 //    This program is distributed in the hope that it will be useful,  *
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00019 //    GNU General Public License for more details.                     *
00020 //                                                                     *
00021 //    You should have received a copy of the GNU General Public        *
00022 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00023 //    program; if not, write to:                                       *
00024 //       The Free Software Foundation Inc.,                            *
00025 //       59 Temple Place - Suite 330,                                  *
00026 //       Boston, MA  02111-1307,                                       *
00027 //       USA.                                                          *
00028 //                                                                     *
00029 //**********************************************************************
00030 //                                                                     *
00031 //    Notes:                                                           *
00032 //                                                                     *
00033 //**********************************************************************
00034 
00035 
00036 #include <classlib\listimp.h>
00037 
00038 #include <callback.h>
00039 
00040 #include "mytrace.h"
00041 
00042 
00043 #include "cllbklst.h"
00044 
00045 
00046 using namespace Monitor::Utility;
00047 
00048 
00049 
00050 CallbackList::CallbackList()
00051     :
00052     myList(new List())
00053 {
00054     _USEMYTRACE_("CallbackList::CallbackList()")
00055 }
00056 
00057 
00058 
00059 CallbackList::~CallbackList()
00060 {
00061     _USEMYTRACE_("CallbackList::~CallbackList()")
00062 
00063     if (!myList->IsEmpty())
00064     {
00065         myList->Flush(!0);
00066     }
00067 
00068     delete myList, myList = 0;
00069 }
00070 
00071 
00072 
00073 const CallbackBase&
00074 CallbackList::addCallback(const CallbackBase&    newCallback)
00075 {
00076     _USEMYTRACE_("CallbackList::addCallback(newCallback)")
00077 
00078     myList->Add(newCallback.clone());
00079 
00080     return newCallback;
00081 }
00082 
00083 
00084 
00085 void
00086 CallbackList::removeCallback(const CallbackBase&    oldCallback)
00087 {
00088     _USEMYTRACE_("CallbackList::removeCallback(oldCallback)")
00089 
00090     if (!myList->IsEmpty())
00091     {
00092         ListIterator    callbacks(*myList);
00093 
00094         while (0 != callbacks.Current())
00095         {
00096             if(oldCallback == *callbacks.Current())
00097             {
00098                 myList->Detach(callbacks.Current());
00099                 callbacks.Restart();
00100             }
00101             else
00102            {
00103                callbacks++;
00104            }
00105         }
00106     }
00107 }
00108 
00109 
00110 
00111 void
00112 CallbackList::removeTarget(const void*    target)
00113 {
00114     _USEMYTRACE_("CallbackList::removeTarget(target)")
00115 
00116 
00117     if (!myList->IsEmpty())
00118     {
00119         ListIterator    callbacks(*myList);
00120 
00121         while (0 != callbacks.Current())
00122         {
00123             if((callbacks.Current())->isTarget(target))
00124             {
00125                 removeCallback(*callbacks.Current());
00126                 callbacks.Restart();
00127             }
00128             else
00129            {
00130                callbacks++;
00131            }
00132         }
00133     }
00134 }
00135 
00136 
00137 
00138 void
00139 CallbackList::invoke(const void*    invocationData)
00140 {
00141     _USEMYTRACE_("CallbackList::invoke(invocationData)")
00142 
00143 
00144     if (!myList->IsEmpty())
00145     {
00146         ListIterator    callbacks(*myList);
00147 
00148         while (0 != callbacks.Current())
00149         {
00150             CallbackBase*    currentCallback = callbacks.Current();
00151 
00152             callbacks++;
00153 
00154             currentCallback->invoke(invocationData);
00155         }
00156     }
00157 }
00158 

Generated on Wed Oct 29 20:51:59 2003 for Utility BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002