@@ -56,8 +56,8 @@ struct SVPolyLineBuffer {
5656static std::map<int , ScrollView *> svmap;
5757static std::mutex *svmap_mu;
5858// A map of all semaphores waiting for a specific event on a specific window.
59- static std::map<std::pair<ScrollView *, SVEventType>, std::pair<SVSemaphore *, SVEvent *>>
60- waiting_for_events;
59+ static std::map<std::pair<ScrollView *, SVEventType>,
60+ std::pair<SVSemaphore *, std::unique_ptr<SVEvent>>> waiting_for_events;
6161static std::mutex *waiting_for_events_mu;
6262
6363SVEvent *SVEvent::copy () const {
@@ -158,13 +158,13 @@ void ScrollView::MessageReceiver() {
158158 SVET_ANY);
159159 waiting_for_events_mu->lock ();
160160 if (waiting_for_events.count (awaiting_list) > 0 ) {
161- waiting_for_events[awaiting_list].second = cur. release ( );
161+ waiting_for_events[awaiting_list].second = std::move (cur );
162162 waiting_for_events[awaiting_list].first ->Signal ();
163163 } else if (waiting_for_events.count (awaiting_list_any) > 0 ) {
164- waiting_for_events[awaiting_list_any].second = cur. release ( );
164+ waiting_for_events[awaiting_list_any].second = std::move (cur );
165165 waiting_for_events[awaiting_list_any].first ->Signal ();
166166 } else if (waiting_for_events.count (awaiting_list_any_window) > 0 ) {
167- waiting_for_events[awaiting_list_any_window].second = cur. release ( );
167+ waiting_for_events[awaiting_list_any_window].second = std::move (cur );
168168 waiting_for_events[awaiting_list_any_window].first ->Signal ();
169169 }
170170 waiting_for_events_mu->unlock ();
@@ -367,8 +367,7 @@ ScrollView::~ScrollView() {
367367 // So the event handling thread can quit.
368368 SendMsg (" destroy()" );
369369
370- SVEvent *sve = AwaitEvent (SVET_DESTROY);
371- delete sve;
370+ AwaitEvent (SVET_DESTROY);
372371 svmap_mu->lock ();
373372 svmap[window_id_] = nullptr ;
374373 svmap_mu->unlock ();
@@ -442,19 +441,19 @@ void ScrollView::SetEvent(const SVEvent *svevent) {
442441// / Block until an event of the given type is received.
443442// / Note: The calling function is responsible for deleting the returned
444443// / SVEvent afterwards!
445- SVEvent * ScrollView::AwaitEvent (SVEventType type) {
444+ std::unique_ptr< SVEvent> ScrollView::AwaitEvent (SVEventType type) {
446445 // Initialize the waiting semaphore.
447446 auto *sem = new SVSemaphore ();
448447 std::pair<ScrollView *, SVEventType> ea (this , type);
449448 waiting_for_events_mu->lock ();
450- waiting_for_events[ea] = std::pair<SVSemaphore *, SVEvent *>( sem, (SVEvent *) nullptr ) ;
449+ waiting_for_events[ea] = { sem, nullptr } ;
451450 waiting_for_events_mu->unlock ();
452451 // Wait on it, but first flush.
453452 stream_->Flush ();
454453 sem->Wait ();
455454 // Process the event we got woken up for (its in waiting_for_events pair).
456455 waiting_for_events_mu->lock ();
457- SVEvent * ret = waiting_for_events[ea].second ;
456+ auto ret = std::move ( waiting_for_events[ea].second ) ;
458457 waiting_for_events.erase (ea);
459458 delete sem;
460459 waiting_for_events_mu->unlock ();
@@ -734,23 +733,19 @@ void ScrollView::Brush(Color color) {
734733// Shows a modal Input Dialog which can return any kind of String
735734char *ScrollView::ShowInputDialog (const char *msg) {
736735 SendMsg (" showInputDialog(\" %s\" )" , msg);
737- SVEvent *ev;
738736 // wait till an input event (all others are thrown away)
739- ev = AwaitEvent (SVET_INPUT);
737+ auto ev = AwaitEvent (SVET_INPUT);
740738 char *p = new char [strlen (ev->parameter ) + 1 ];
741739 strcpy (p, ev->parameter );
742- delete ev;
743740 return p;
744741}
745742
746743// Shows a modal Yes/No Dialog which will return 'y' or 'n'
747744int ScrollView::ShowYesNoDialog (const char *msg) {
748745 SendMsg (" showYesNoDialog(\" %s\" )" , msg);
749- SVEvent *ev;
750746 // Wait till an input event (all others are thrown away)
751- ev = AwaitEvent (SVET_INPUT);
747+ auto ev = AwaitEvent (SVET_INPUT);
752748 int a = ev->parameter [0 ];
753- delete ev;
754749 return a;
755750}
756751
0 commit comments