NCBI C++ ToolKit
events_tools.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: events_tools.cpp 40279 2018-01-19 17:48:49Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 
35 #include "events_tools.hpp"
36 
37 
39 
40 static const char* kTraceSeparator = " | ";
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 /// CTraceEvent
44 
45 CTraceEvent::CTraceEvent(TEventClass ecl, TEventID eid)
46 : CEvent(ecl, eid)
47 {
48 }
49 
50 
52  EOwnershipPolicy policy, TEventSender* sender)
53 : CEvent(ecl, eid, att, policy, sender)
54 {
55 }
56 
57 
59 {
60  return m_Trace;
61 }
62 
63 
65 {
66  if( ! m_Trace.empty()) {
68  }
69  m_Trace += trace;
70 }
71 
72 
73 ///////////////////////////////////////////////////////////////////////////////
74 /// CTracingHandler
75 
77 : m_ID(id),
78  m_Trace(NULL)
79 {
80 }
81 
82 
84 : m_ID(id),
85  m_Trace(&trace)
86 {
87 }
88 
89 
93 
96 
100 
101  ON_UPDATE_COMMAND_UI(eCmd_1, &CTracingHandler::OnUpdateCommand_1)
102  ON_UPDATE_COMMAND_UI(eCmd_2, &CTracingHandler::OnUpdateCommand_2)
103  ON_UPDATE_COMMAND_UI_RANGE(eCmd_3, eCmd_4, &CTracingHandler::OnUpdateCommand_Range)
105 
106 
107 void CTracingHandler::ClearTrace()
108 {
109  m_Trace->clear();
110 }
111 
112 
114 {
115  return m_Trace;
116 }
117 
118 
120 {
121  x_AddTrace(evt, "OnEvent_A");
122 }
123 
124 
126 {
127  x_AddTrace(evt, "OnEvent_B");
128 }
129 
130 
132 {
133  x_AddTrace(evt, "OnMessage_A");
134 }
135 
136 
138 {
139  x_AddTrace(evt, "OnMessage_B");
140 }
141 
142 
144 {
145  x_AddTrace(x_GetMethodTrace("OnCommand_1"));
146 }
147 
148 
150 {
151  x_AddTrace(x_GetMethodTrace("OnCommand_2"));
152 }
153 
154 
156 {
157  string s = x_GetMethodTrace("OnCommand_Range ");
158  s += NStr::IntToString(cmd);
159  x_AddTrace(s);
160 }
161 
162 
164 {
165  x_AddTrace(x_GetMethodTrace("OnUpdateCommand_1"));
166  pCmdUI->Enable(true);
167 }
168 
169 
171 {
172  x_AddTrace(x_GetMethodTrace("OnUpdateCommand_2"));
173  pCmdUI->Enable(true);
174 }
175 
176 
178 {
179  string s = x_GetMethodTrace("OnUpdateCommand_Range ");
180  s += NStr::IntToString(pCmdUI->GetCommand());
181  x_AddTrace(s);
182 
183  pCmdUI->Enable(true);
184 }
185 
186 
187 string CTracingHandler::x_GetMethodTrace(const string& method) const
188 {
189  string s = NStr::IntToString(m_ID);
190  s += "::";
191  s += method;
192  return s;
193 }
194 
195 
196 void CTracingHandler::x_AddTrace(CEvent* evt, const string& method)
197 {
198  CTraceEvent* tr_evt = dynamic_cast<CTraceEvent*>(evt);
199  _ASSERT(tr_evt);
200 
201  tr_evt->AddTrace(x_GetMethodTrace(method));
202 }
203 
204 
206 {
207  _ASSERT(m_Trace);
209 }
210 
211 
212 ///////////////////////////////////////////////////////////////////////////////
213 /// CTestCmdUI
214 
216 : m_Cmd(cmd), m_Label(label),
217  m_Enabled(false), m_Checked(false), m_Radio(false), m_Visited(false)
218 {
219 }
220 
221 
222 CTestCmdUI::CTestCmdUI(TCmdID cmd, const string& label, bool en, bool check, bool radio)
223 : m_Cmd(cmd), m_Label(label),
224  m_Enabled(en), m_Checked(check), m_Radio(radio), m_Visited(false)
225 {
226 }
227 
228 
230 {
231  return m_Cmd;
232 }
233 
234 
235 void CTestCmdUI::Enable(bool en)
236 {
237  m_Enabled = en;
238  m_Visited = true;
239 }
240 
241 
243 {
244  m_Checked = true;
245  m_Visited = true;
246 }
247 
248 
250 {
251  m_Radio = true;
252  m_Visited = true;
253 }
254 
255 
256 void CTestCmdUI::SetLabel(const string& label)
257 {
258  m_Label = label;
259  m_Visited = true;
260 }
261 
262 
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CTestCmdUI(TCmdID cmd, const string &label)
CTestCmdUI.
virtual void Enable(bool en)
virtual TCmdID GetCommand() const
virtual void SetRadio(bool set)
string m_Label
virtual void SetLabel(const string &label)
virtual void SetCheck(bool set)
CTraceEvent.
const TTrace & GetTrace() const
CTraceEvent(CEvent::TEventClass cls, CEvent::TEventID id)
void AddTrace(const TTrace &trace)
TTrace m_Trace
CTracingHandler.
void OnEvent_A(CEvent *evt)
void OnUpdateCommand_2(ICmdUI *pCmdUI)
void OnUpdateCommand_Range(ICmdUI *pCmdUI)
const TTrace * GetTrace()
string x_GetMethodTrace(const string &method) const
void OnMessage_B(CEvent *evt)
void x_AddTrace(CEvent *evt, const string &method)
void OnEvent_B(CEvent *evt)
CTraceEvent::TTrace TTrace
void OnCommand_Range(TCmdID cmd)
CTracingHandler(int id=-1)
CTracingHandler.
void OnUpdateCommand_1(ICmdUI *pCmdUI)
void OnMessage_A(CEvent *evt)
object, that will be attached to event
Definition: event.hpp:51
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * kTraceSeparator
@ eCmd_4
@ eCmd_3
@ eCmd_1
@ eCmd_2
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define false
Definition: bool.h:36
#define check(s)
Definition: describecol2.c:21
static bool trace
#define NULL
Definition: ncbistd.hpp:225
Int4 TEventID
Definition: event.hpp:90
EOwnershipPolicy
Definition: event.hpp:109
#define ON_EVENT(type, id, handler)
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
int TCmdID
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5078
static const char label[]
#define _ASSERT
Modified on Fri Sep 20 14:57:08 2024 by modify_doxy.py rev. 669887