Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/cbks is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_cbks
0005 #define tools_sg_cbks
0006 
0007 // A dedicated container for callbacks.
0008 
0009 #include "bcbk"
0010 #include "../forit"
0011 #include "../vmanip"
0012 
0013 #include <vector>
0014 
0015 namespace tools {
0016 namespace sg {
0017 
0018 class cbks {
0019 public:
0020   cbks() {}
0021   virtual ~cbks(){clear();}
0022 public:
0023   cbks(const cbks& a_from){copy(a_from);}
0024   cbks& operator=(const cbks& a_from){
0025     if(&a_from==this) return *this;
0026     copy(a_from);
0027     return *this;
0028   }
0029 public:
0030   void add(bcbk* a_cbk) {
0031     //we take ownership of a_cbk
0032     m_cbks.push_back(a_cbk);
0033   }
0034   void copy(const cbks& a_from,bool a_clear = true) {
0035     if(&a_from==this) return;
0036     if(a_clear) clear();
0037     tools_vforcit(bcbk*,a_from.m_cbks,it) m_cbks.push_back((*it)->copy());
0038   }
0039   void clear() {
0040     safe_clear<bcbk>(m_cbks);
0041   }
0042 
0043   void do_actions() const {
0044     // WARNING : dangerous. Used by offscreen apps.
0045     tools_vforcit(bcbk*,m_cbks,it) (*it)->action();
0046   }
0047 
0048   const std::vector<bcbk*>& callbacks() const {return m_cbks;}
0049   std::vector<bcbk*>& callbacks() {return m_cbks;}
0050   bool is_empty() const {return m_cbks.empty();}
0051 protected:
0052   std::vector<bcbk*> m_cbks;
0053 };
0054 
0055 }}
0056 
0057 #endif