anatomist  5.1.2
3D neuroimaging data viewer
event.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANATOMIST_PROCESSOR_EVENT_H
36 #define ANATOMIST_PROCESSOR_EVENT_H
37 
39 
40 namespace anatomist
41 {
42 
46  {
47  public:
61  OutputEvent( const std::string & evname, carto::Object contents,
62  bool allocIDs = true,
63  const std::set<std::string> & discrimintantAttribs
64  = std::set<std::string>() );
65  virtual ~OutputEvent();
67  virtual void send();
68  std::string eventType() const { return _name; }
69  carto::Object contents() const { return _contents; }
70 
71  protected:
73 
74  private:
75  std::string _name;
76  bool _allocateIDs;
77  carto::Object _contents;
78  std::set<std::string> _discrim;
79  };
80 
81 
83  {
84  public:
87 
88  void filter( const std::string & evtype );
89  void filter( const std::set<std::string> & evtype );
90  void unfilter( const std::string & evtype );
91  void unfilter( const std::set<std::string> & evtype );
92  const std::set<std::string> & filters() const { return _filtered; }
93  void setDefaultIsFiltering( bool );
94  bool isDefaultFiltering() const { return _deffiltering; }
95  void clear();
96 
97  private:
98  bool _deffiltering;
99  std::set<std::string> _filtered;
100  };
101 
102 
106  {
107  public:
109  virtual ~EventHandler();
112  virtual void doit( const OutputEvent & ) = 0;
113 
114  static void registerHandler( const std::string & evtype,
116  static void unregisterHandler( const std::string & evtype,
118  static const std::map<std::string, std::set<carto::rc_ptr<EventHandler> > >
119  & handlers() { return _handlers(); }
120 
121  private:
122  static std::map<std::string, std::set<carto::rc_ptr<EventHandler> > >
123  & _handlers();
124  };
125 
126 }
127 
128 
129 #endif
130 
Event handlers are called internally when the default context outputs an event.
Definition: event.h:106
static const std::map< std::string, std::set< carto::rc_ptr< EventHandler > > > & handlers()
Definition: event.h:119
virtual void doit(const OutputEvent &)=0
this method should be defined by derived classes to do something when an event of the matching type o...
static void registerHandler(const std::string &evtype, carto::rc_ptr< EventHandler >)
static void unregisterHandler(const std::string &evtype, carto::rc_ptr< EventHandler >)
Filering of events sent to the external wolrd (output streams)
Definition: event.h:83
bool isDefaultFiltering() const
Definition: event.h:94
void filter(const std::set< std::string > &evtype)
void filter(const std::string &evtype)
const std::set< std::string > & filters() const
Definition: event.h:92
void unfilter(const std::set< std::string > &evtype)
void unfilter(const std::string &evtype)
This class holds events to send to output streams so that external programs are notified when somethi...
Definition: event.h:46
virtual void send()
sends the event to all output streams
OutputEvent(const std::string &evname, carto::Object contents, bool allocIDs=true, const std::set< std::string > &discrimintantAttribs=std::set< std::string >())
Builds an Event.
std::string eventType() const
Definition: event.h:68
carto::Object contents() const
Definition: event.h:69