1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef GDCMEVENT_H
15 #define GDCMEVENT_H
16 
17 #include "gdcmTypes.h"
18 
19 namespace gdcm
20 {
21 //-----------------------------------------------------------------------------
22 /**
23  * \brief superclass for callback/observer methods
24  * \see Command Subject
25  */
26 class GDCM_EXPORT Event
27 {
28 public :
29   Event();
30   virtual ~Event();
31   Event(const Event&);
32   void operator=(const Event&) = delete;
33 
34   /**  Create an Event of this type This method work as a Factory for
35    *  creating events of each particular type. */
36   virtual Event* MakeObject() const = 0;
37 
38   /** Print Event information.  This method can be overridden by
39    * specific Event subtypes.  The default is to print out the type of
40    * the event. */
41   virtual void Print(std::ostream& os) const;
42 
43   /** Return the StringName associated with the event. */
44   virtual const char * GetEventName() const = 0;
45 
46   /** Check if given event matches or derives from this event. */
47   virtual bool CheckEvent(const Event*) const = 0;
48 
49 };
50 
51 /// Generic inserter operator for Event and its subclasses.
52 inline std::ostream& operator<<(std::ostream& os, Event &e)
53 {
54   e.Print(os);
55   return os;
56 }
57 
58 /*
59  *  Macro for creating new Events
60  */
61 #define gdcmEventMacro( classname , super ) \
62  /** \brief classname */  \
63  class  classname : public super { \
64    public: \
65      typedef classname Self; \
66      typedef super Superclass; \
67      classname() {} \
68      virtual ~classname() override = default; \
69      virtual const char * GetEventName() const override { return #classname; } \
70      virtual bool CheckEvent(const ::gdcm::Event* e) const override \
71        { return dynamic_cast<const Self*>(e) ? true : false; } \
72      virtual ::gdcm::Event* MakeObject() const override \
73        { return new Self; } \
74      classname(const Self&s) : super(s){}; \
75    private: \
76      void operator=(const Self&); \
77  }
78 
79 /**
80  *      Define some common GDCM events
81  */
82 gdcmEventMacro( NoEvent            , Event );
83 gdcmEventMacro( AnyEvent           , Event );
84 gdcmEventMacro( StartEvent         , AnyEvent );
85 gdcmEventMacro( EndEvent           , AnyEvent );
86 //gdcmEventMacro( ProgressEvent      , AnyEvent );
87 gdcmEventMacro( ExitEvent          , AnyEvent );
88 gdcmEventMacro( AbortEvent         , AnyEvent );
89 gdcmEventMacro( ModifiedEvent      , AnyEvent );
90 gdcmEventMacro( InitializeEvent    , AnyEvent );
91 gdcmEventMacro( IterationEvent     , AnyEvent );
92 //gdcmEventMacro( AnonymizeEvent     , AnyEvent );
93 gdcmEventMacro( UserEvent          , AnyEvent );
94 
95 
96 } // end namespace gdcm
97 //-----------------------------------------------------------------------------
98 #endif //GDCMEVENT_H
99