NCBI C++ ToolKit
event.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS___EVENT__HPP
2 #define GUI_UTILS___EVENT__HPP
3 
4 /* $Id: event.hpp 40751 2018-04-09 18:24:49Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Vladimir Tereshkov, Andrey Yazhuk
30  *
31  * File Description:
32  * Event object for communicating between transmitter and receiver
33  */
34 
35 /** @addtogroup GUI_UTILS
36 *
37 * @{
38 */
39 
40 #include <corelib/ncbiobj.hpp>
41 #include <gui/gui_export.h>
42 
43 #include <memory>
44 #include <set>
45 
47 
48 class CEventHandler;
49 
50 /// object, that will be attached to event
52 public:
53  virtual ~IEventAttachment() { }
54 };
55 
56 
57 /// templatized IEventAttachment wrapper
58 template<typename T>
60 {
61 public:
62  typedef T TObjectType;
63 
64  /// provide non-const access to the packaged data
65  TObjectType& SetData(void) { return m_Data; }
66  void SetData(const TObjectType& data) { m_Data = data; }
67 
68  /// provide const access to the packaged data
69  const TObjectType& GetData(void) const { return m_Data; }
70 
71  /// cast operators to get the data
72  operator TObjectType& (void) { return SetData(); }
73  operator const TObjectType& (void) const { return GetData(); }
74 
75 private:
77 };
78 
79 
80 ///////////////////////////////////////////////////////////////////////////////
81 /// CEvent - generic event implementation
82 /// TODO
83 /// TODO - Attachments
84 
86 {
87 public:
88  typedef const char* TEventTypeInfo;
90  typedef Int4 TEventID;
92  typedef Int4 TEventRefs;
93 
94  typedef std::type_info TAttachmentTypeInfo;
95 
96 
97  /// default event classes
98  enum EEventClass {
99  eEvent_Message /// message from one class to another
100  };
101 
102  /// Predefining event IDs
103  enum EEventID {
104  eEvent_LastID = -1,
105  eEvent_InvalidID = -2,
106  eEvent_MinClientID = 0 // set to 0, because by default enums start from 0
107  };
108 
110  eDelete, /// delete object when ownership end
111  eRelease /// release object (do not delete)
112  };
113 
114  /// default ctor
115  CEvent();
116 
117  /// create an event for a given event ID, with event class Unknown
118  CEvent(TEventID eid);
119 
120  /// create an event for a specific event class and ID
121  CEvent(EEventClass ecl, TEventID eid, TEventSender* sender = NULL);
122 
123  /// create an event with all the bells and whistles
124  CEvent(EEventClass ecl, TEventID eid, IEventAttachment* att,
125  EOwnershipPolicy policy, TEventSender* sender);
126 
127  /// virtual dtor
128  virtual ~CEvent(void);
129 
130  const TEventRefs GetRefs(void) const;
131  void AddRef(void);
132  const TEventID GetID(void) const;
133  const EEventClass GetEventClass(void) const;
134  const TEventSender* GetSender(void) const;
135  TEventTypeInfo GetTypeInfo(void);
136 
137  /// attach an object to the Event
138  virtual void SetAttachment(IEventAttachment* att, EOwnershipPolicy policy);
139  virtual IEventAttachment* GetAttachment(void);
140  virtual bool HasAttachment(void) const;
141 
142 
143  /// Checks whether this event has been visited by the given handler.
144  /// Returns "true" if this is the first visit.
145  bool Visit(CEventHandler* handler);
146 
147 protected:
148  EEventClass m_Class; /// Event class - to speed up avoiding extra dynamic casts
149  TEventID m_ID; /// Defines unique event identity within its C++ class and Event Class
150  TEventSender* m_Sender; /// pointer to the class that sent this event
151 
152  unique_ptr<IEventAttachment> m_Attachment;
154 
155  /// list of handler who have seen this event already
157 };
158 
159 
160 /////////////////////////////////////////////////////////////////////////////
161 /// Inline Implementation
162 
163 inline
165 {
166  return m_ID;
167 }
168 
169 
170 inline
172 {
173  return m_Class;
174 }
175 
176 
177 inline
179 {
180  return m_Sender;
181 }
182 
183 
184 inline
186 {
187  return typeid(*this).name();
188 }
189 
190 
192 
193 /* @} */
194 
195 #endif // GUI_UTILS___EVENT__HPP
templatized IEventAttachment wrapper
Definition: event.hpp:60
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CObject –.
Definition: ncbiobj.hpp:180
object, that will be attached to event
Definition: event.hpp:51
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
#define T(s)
Definition: common.h:230
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
const TEventSender * GetSender(void) const
Definition: event.hpp:178
TEventSender * m_Sender
Defines unique event identity within its C++ class and Event Class.
Definition: event.hpp:150
set< CEventHandler * > m_Visited
list of handler who have seen this event already
Definition: event.hpp:156
const TEventID GetID(void) const
Inline Implementation.
Definition: event.hpp:164
TObjectType & SetData(void)
provide non-const access to the packaged data
Definition: event.hpp:65
EOwnershipPolicy m_AttPolicy
Definition: event.hpp:153
TEventID m_ID
Event class - to speed up avoiding extra dynamic casts.
Definition: event.hpp:149
EEventID
Predefining event IDs.
Definition: event.hpp:103
CEventHandler TEventSender
Definition: event.hpp:91
void AddRef(void)
Int4 TEventID
Definition: event.hpp:90
const TObjectType & GetData(void) const
provide const access to the packaged data
Definition: event.hpp:69
const char * TEventTypeInfo
Definition: event.hpp:88
CRef< CEvent > TEventObject
Definition: event.hpp:89
TEventTypeInfo GetTypeInfo(void)
Definition: event.hpp:185
std::type_info TAttachmentTypeInfo
Definition: event.hpp:94
EOwnershipPolicy
Definition: event.hpp:109
const EEventClass GetEventClass(void) const
Definition: event.hpp:171
EEventClass
default event classes
Definition: event.hpp:98
const TEventRefs GetRefs(void) const
unique_ptr< IEventAttachment > m_Attachment
pointer to the class that sent this event
Definition: event.hpp:152
Int4 TEventRefs
Definition: event.hpp:92
void SetData(const TObjectType &data)
Definition: event.hpp:66
EEventClass m_Class
Definition: event.hpp:148
TObjectType m_Data
Definition: event.hpp:76
virtual ~IEventAttachment()
Definition: event.hpp:53
@ eDelete
Definition: event.hpp:110
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIUTILS_EXPORT
Definition: gui_export.h:518
Defines to provide correct exporting from DLLs in Windows.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Thu May 02 14:27:04 2024 by modify_doxy.py rev. 669887