ROOT logo
// @(#)root/reflex:$Id: Callback.cxx 22729 2008-03-19 10:20:10Z pcanal $
// Author: Stefan Roiser 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef REFLEX_BUILD
#define REFLEX_BUILD
#endif

#include "Reflex/Kernel.h"
#include "Reflex/Callback.h"
#include <list>

// typedef std::list<Reflex::ICallback*> CbList;
// On RH7.3 the callback list is destructed before clients Get
// the chance to uninstall their callbacks. So, let's build some
// protection. 
class  CbList : public std::list<Reflex::ICallback*> 
{
public:
   CbList() : fAlive(true) {}
   ~CbList() { fAlive = false; }
   bool IsAlive() { return fAlive; }
private:
   typedef bool Bool_t;
   Bool_t fAlive;
};

//------------------------------------------------------------------------------
static CbList & sClassCallbacks() {
//------------------------------------------------------------------------------
// Wraper for static callback list.
   static CbList m;
   return m;
}

//-------------------------------------------------------------------------------
void Reflex::InstallClassCallback( Reflex::ICallback * cb ) {
//-------------------------------------------------------------------------------
// Install a class callback.
   sClassCallbacks().push_back( cb );
}

//-------------------------------------------------------------------------------
void Reflex::UninstallClassCallback( Reflex::ICallback * cb ) {
//-------------------------------------------------------------------------------
// Uninstall a class callback.
   if( sClassCallbacks().IsAlive() ) {
      sClassCallbacks().remove( cb );
   }
}

//-------------------------------------------------------------------------------
void Reflex::FireClassCallback( const Reflex::Type & ty ) {
//-------------------------------------------------------------------------------
// Activate a class callback.
   for ( CbList::const_iterator i = sClassCallbacks().begin(); 
         i != sClassCallbacks().end(); i++ ) {
      (**i)(ty);
   }
}

//-------------------------------------------------------------------------------
void Reflex::FireFunctionCallback( const Reflex::Member & mem ) {
//-------------------------------------------------------------------------------
// Activate a function callback.
   for ( CbList::const_iterator i = sClassCallbacks().begin(); 
         i != sClassCallbacks().end(); i++ ) {
      (**i)(mem);
   }
}

 Callback.cxx:1
 Callback.cxx:2
 Callback.cxx:3
 Callback.cxx:4
 Callback.cxx:5
 Callback.cxx:6
 Callback.cxx:7
 Callback.cxx:8
 Callback.cxx:9
 Callback.cxx:10
 Callback.cxx:11
 Callback.cxx:12
 Callback.cxx:13
 Callback.cxx:14
 Callback.cxx:15
 Callback.cxx:16
 Callback.cxx:17
 Callback.cxx:18
 Callback.cxx:19
 Callback.cxx:20
 Callback.cxx:21
 Callback.cxx:22
 Callback.cxx:23
 Callback.cxx:24
 Callback.cxx:25
 Callback.cxx:26
 Callback.cxx:27
 Callback.cxx:28
 Callback.cxx:29
 Callback.cxx:30
 Callback.cxx:31
 Callback.cxx:32
 Callback.cxx:33
 Callback.cxx:34
 Callback.cxx:35
 Callback.cxx:36
 Callback.cxx:37
 Callback.cxx:38
 Callback.cxx:39
 Callback.cxx:40
 Callback.cxx:41
 Callback.cxx:42
 Callback.cxx:43
 Callback.cxx:44
 Callback.cxx:45
 Callback.cxx:46
 Callback.cxx:47
 Callback.cxx:48
 Callback.cxx:49
 Callback.cxx:50
 Callback.cxx:51
 Callback.cxx:52
 Callback.cxx:53
 Callback.cxx:54
 Callback.cxx:55
 Callback.cxx:56
 Callback.cxx:57
 Callback.cxx:58
 Callback.cxx:59
 Callback.cxx:60
 Callback.cxx:61
 Callback.cxx:62
 Callback.cxx:63
 Callback.cxx:64
 Callback.cxx:65
 Callback.cxx:66
 Callback.cxx:67
 Callback.cxx:68
 Callback.cxx:69
 Callback.cxx:70
 Callback.cxx:71
 Callback.cxx:72
 Callback.cxx:73
 Callback.cxx:74
 Callback.cxx:75
 Callback.cxx:76
 Callback.cxx:77
 Callback.cxx:78