CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FWCore/Utilities/interface/Signal.h

Go to the documentation of this file.
00001 #ifndef FWCore_ServiceRegistry_Signal_h
00002 #define FWCore_ServiceRegistry_Signal_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     ServiceRegistry
00006 // Class  :     Signal
00007 // 
00019 //
00020 // Original Author:  Chris Jones
00021 //         Created:  Thu Jan 17 16:03:51 CST 2013
00022 // $Id: Signal.h,v 1.1 2013/01/20 16:56:21 chrjones Exp $
00023 //
00024 
00025 // system include files
00026 #include <vector>
00027 #include <functional>
00028 
00029 // user include files
00030 
00031 // forward declarations
00032 
00033 namespace edm {
00034   namespace signalslot {
00035     template <typename T>
00036     class Signal
00037     {
00038       
00039     public:
00040       typedef std::function<T> slot_type;
00041       typedef std::vector<slot_type> slot_list_type;
00042       
00043       Signal() = default;
00044       ~Signal() = default;
00045       
00046       // ---------- const member functions ---------------------
00047       template<typename... Args>
00048       void emit(Args&&... args) const {
00049         for(auto& slot:m_slots) {
00050           slot(std::forward<Args>(args)...);
00051         }
00052       }
00053       
00054       template<typename... Args>
00055       void operator()(Args&&... args) const {
00056         emit(std::forward<Args>(args)...);
00057       }
00058       
00059       slot_list_type const& slots() const {return m_slots;}
00060       // ---------- static member functions --------------------
00061       
00062       // ---------- member functions ---------------------------
00063       template<typename U>
00064       void connect(U iFunc) {
00065         m_slots.push_back(std::function<T>(iFunc));
00066       }
00067 
00068       template<typename U>
00069       void connect_front(U iFunc) {
00070         m_slots.insert(m_slots.begin(),std::function<T>(iFunc));
00071       }
00072 
00073     private:
00074       Signal(const Signal&) = delete; // stop default
00075       
00076       const Signal& operator=(const Signal&) = delete; // stop default
00077       
00078       // ---------- member data --------------------------------
00079       slot_list_type m_slots;
00080       
00081     };
00082   }
00083 }
00084 
00085 #endif