Skip to content

Commit f785d5c

Browse files
committed
viewer: Replace NULL by nullptr
Signed-off-by: Stefan Weil <[email protected]>
1 parent 39cfbd0 commit f785d5c

File tree

4 files changed

+70
-70
lines changed

4 files changed

+70
-70
lines changed

viewer/scrollview.cpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ SVEvent* SVEvent::copy() {
8686
/// It is run from a different thread and synchronizes via SVSync.
8787
void* ScrollView::MessageReceiver(void* a) {
8888
int counter_event_id = 0; // ongoing counter
89-
char* message = NULL;
89+
char* message = nullptr;
9090
// Wait until a new message appears in the input stream_.
9191
do {
9292
message = ScrollView::GetStream()->Receive();
93-
} while (message == NULL);
93+
} while (message == nullptr);
9494

9595
// This is the main loop which iterates until the server is dead (strlen = -1).
9696
// It basically parses for 3 different messagetypes and then distributes the
@@ -112,7 +112,7 @@ void* ScrollView::MessageReceiver(void* a) {
112112
svmap_mu->Lock();
113113
cur->window = svmap[window_id];
114114

115-
if (cur->window != NULL) {
115+
if (cur->window != nullptr) {
116116
cur->parameter = new char[strlen(p) + 1];
117117
strcpy(cur->parameter, p);
118118
if (strlen(p) > 0) { // remove the last \n
@@ -167,7 +167,7 @@ void* ScrollView::MessageReceiver(void* a) {
167167
waiting_for_events_mu->Unlock();
168168
// Signal the corresponding semaphore twice (for both copies).
169169
ScrollView* sv = svmap[window_id];
170-
if (sv != NULL) {
170+
if (sv != nullptr) {
171171
sv->Signal();
172172
sv->Signal();
173173
}
@@ -179,9 +179,9 @@ void* ScrollView::MessageReceiver(void* a) {
179179
// Wait until a new message appears in the input stream_.
180180
do {
181181
message = ScrollView::GetStream()->Receive();
182-
} while (message == NULL);
182+
} while (message == nullptr);
183183
}
184-
return 0;
184+
return nullptr;
185185
}
186186

187187
// Table to implement the color index values in the old system.
@@ -242,7 +242,7 @@ int table_colors[ScrollView::GREEN_YELLOW+1][4]= {
242242
* Scrollview implementation.
243243
*******************************************************************************/
244244

245-
SVNetwork* ScrollView::stream_ = NULL;
245+
SVNetwork* ScrollView::stream_ = nullptr;
246246
int ScrollView::nr_created_windows_ = 0;
247247
int ScrollView::image_index_ = 0;
248248

@@ -274,19 +274,19 @@ void ScrollView::Initialize(const char* name, int x_pos, int y_pos, int x_size,
274274
bool y_axis_reversed, const char* server_name) {
275275
// If this is the first ScrollView Window which gets created, there is no
276276
// network connection yet and we have to set it up in a different thread.
277-
if (stream_ == NULL) {
277+
if (stream_ == nullptr) {
278278
nr_created_windows_ = 0;
279279
stream_ = new SVNetwork(server_name, kSvPort);
280280
waiting_for_events_mu = new SVMutex();
281281
svmap_mu = new SVMutex();
282282
SendRawMessage(
283283
"svmain = luajava.bindClass('com.google.scrollview.ScrollView')\n");
284-
SVSync::StartThread(MessageReceiver, NULL);
284+
SVSync::StartThread(MessageReceiver, nullptr);
285285
}
286286

287287
// Set up the variables on the clientside.
288288
nr_created_windows_++;
289-
event_handler_ = NULL;
289+
event_handler_ = nullptr;
290290
event_handler_ended_ = false;
291291
y_axis_is_reversed_ = y_axis_reversed;
292292
y_size_ = y_canvas_size;
@@ -301,7 +301,7 @@ void ScrollView::Initialize(const char* name, int x_pos, int y_pos, int x_size,
301301
svmap_mu->Unlock();
302302

303303
for (int i = 0; i < SVET_COUNT; i++) {
304-
event_table_[i] = NULL;
304+
event_table_[i] = nullptr;
305305
}
306306

307307
mutex_ = new SVMutex();
@@ -327,53 +327,53 @@ void* ScrollView::StartEventHandler(void* a) {
327327
do {
328328
stream_->Flush();
329329
sv->semaphore_->Wait();
330-
new_event = NULL;
330+
new_event = nullptr;
331331
int serial = -1;
332332
int k = -1;
333333
sv->mutex_->Lock();
334334
// Check every table entry if he is is valid and not already processed.
335335

336336
for (int i = 0; i < SVET_COUNT; i++) {
337-
if (sv->event_table_[i] != NULL &&
337+
if (sv->event_table_[i] != nullptr &&
338338
(serial < 0 || sv->event_table_[i]->counter < serial)) {
339339
new_event = sv->event_table_[i];
340340
serial = sv->event_table_[i]->counter;
341341
k = i;
342342
}
343343
}
344344
// If we didn't find anything we had an old alarm and just sleep again.
345-
if (new_event != NULL) {
346-
sv->event_table_[k] = NULL;
345+
if (new_event != nullptr) {
346+
sv->event_table_[k] = nullptr;
347347
sv->mutex_->Unlock();
348-
if (sv->event_handler_ != NULL) { sv->event_handler_->Notify(new_event); }
348+
if (sv->event_handler_ != nullptr) { sv->event_handler_->Notify(new_event); }
349349
if (new_event->type == SVET_DESTROY) {
350350
// Signal the destructor that it is safe to terminate.
351351
sv->event_handler_ended_ = true;
352-
sv = NULL;
352+
sv = nullptr;
353353
}
354354
delete new_event; // Delete the pointer after it has been processed.
355355
} else { sv->mutex_->Unlock(); }
356356
// The thread should run as long as its associated window is alive.
357-
} while (sv != NULL);
358-
return 0;
357+
} while (sv != nullptr);
358+
return nullptr;
359359
}
360360
#endif // GRAPHICS_DISABLED
361361

362362
ScrollView::~ScrollView() {
363363
#ifndef GRAPHICS_DISABLED
364364
svmap_mu->Lock();
365-
if (svmap[window_id_] != NULL) {
365+
if (svmap[window_id_] != nullptr) {
366366
svmap_mu->Unlock();
367367
// So the event handling thread can quit.
368368
SendMsg("destroy()");
369369

370370
SVEvent* sve = AwaitEvent(SVET_DESTROY);
371371
delete sve;
372372
svmap_mu->Lock();
373-
svmap[window_id_] = NULL;
373+
svmap[window_id_] = nullptr;
374374
svmap_mu->Unlock();
375375
// The event handler thread for this window *must* receive the
376-
// destroy event and set its pointer to this to NULL before we allow
376+
// destroy event and set its pointer to this to nullptr before we allow
377377
// the destructor to exit.
378378
while (!event_handler_ended_)
379379
Update();
@@ -431,9 +431,9 @@ void ScrollView::SetEvent(SVEvent* svevent) {
431431
// Place both events into the queue.
432432
mutex_->Lock();
433433
// Delete the old objects..
434-
if (event_table_[specific->type] != NULL) {
434+
if (event_table_[specific->type] != nullptr) {
435435
delete event_table_[specific->type]; }
436-
if (event_table_[SVET_ANY] != NULL) {
436+
if (event_table_[SVET_ANY] != nullptr) {
437437
delete event_table_[SVET_ANY]; }
438438
// ...and put the new ones in the table.
439439
event_table_[specific->type] = specific;
@@ -668,7 +668,7 @@ void ScrollView::Image(const char* image, int x_pos, int y_pos) {
668668
// Add new checkboxmenuentry to menubar.
669669
void ScrollView::MenuItem(const char* parent, const char* name,
670670
int cmdEvent, bool flag) {
671-
if (parent == NULL) { parent = ""; }
671+
if (parent == nullptr) { parent = ""; }
672672
if (flag) { SendMsg("addMenuBarItem('%s','%s',%d,true)",
673673
parent, name, cmdEvent);
674674
} else { SendMsg("addMenuBarItem('%s','%s',%d,false)",
@@ -677,26 +677,26 @@ void ScrollView::MenuItem(const char* parent, const char* name,
677677

678678
// Add new menuentry to menubar.
679679
void ScrollView::MenuItem(const char* parent, const char* name, int cmdEvent) {
680-
if (parent == NULL) { parent = ""; }
680+
if (parent == nullptr) { parent = ""; }
681681
SendMsg("addMenuBarItem('%s','%s',%d)", parent, name, cmdEvent);
682682
}
683683

684684
// Add new submenu to menubar.
685685
void ScrollView::MenuItem(const char* parent, const char* name) {
686-
if (parent == NULL) { parent = ""; }
686+
if (parent == nullptr) { parent = ""; }
687687
SendMsg("addMenuBarItem('%s','%s')", parent, name);
688688
}
689689

690690
// Add new submenu to popupmenu.
691691
void ScrollView::PopupItem(const char* parent, const char* name) {
692-
if (parent == NULL) { parent = ""; }
692+
if (parent == nullptr) { parent = ""; }
693693
SendMsg("addPopupMenuItem('%s','%s')", parent, name);
694694
}
695695

696696
// Add new submenuentry to popupmenu.
697697
void ScrollView::PopupItem(const char* parent, const char* name,
698698
int cmdEvent, const char* value, const char* desc) {
699-
if (parent == NULL) { parent = ""; }
699+
if (parent == nullptr) { parent = ""; }
700700
char* esc = AddEscapeChars(value);
701701
char* esc2 = AddEscapeChars(desc);
702702
SendMsg("addPopupMenuItem('%s','%s',%d,'%s','%s')", parent, name,
@@ -715,7 +715,7 @@ void ScrollView::Update() {
715715
svmap_mu->Lock();
716716
for (std::map<int, ScrollView*>::iterator iter = svmap.begin();
717717
iter != svmap.end(); ++iter) {
718-
if (iter->second != NULL)
718+
if (iter->second != nullptr)
719719
iter->second->UpdateWindow();
720720
}
721721
svmap_mu->Unlock();
@@ -817,7 +817,7 @@ char* ScrollView::AddEscapeChars(const char* input) {
817817
const char* lastptr = input;
818818
char* message = new char[kMaxMsgSize];
819819
int pos = 0;
820-
while (nextptr != NULL) {
820+
while (nextptr != nullptr) {
821821
strncpy(message+pos, lastptr, nextptr-lastptr);
822822
pos += nextptr - lastptr;
823823
message[pos] = '\\';

viewer/scrollview.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ struct SVEvent {
7272
int counter; // Used to detect which kind of event to process next.
7373

7474
SVEvent() {
75-
window = NULL;
76-
parameter = NULL;
75+
window = nullptr;
76+
parameter = nullptr;
7777
}
7878

7979
SVEvent(const SVEvent&);

viewer/svmnode.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
// be added to this or one of the submenus.
4545
SVMenuNode::SVMenuNode() {
4646
cmd_event_ = -1;
47-
child_ = NULL;
48-
next_ = NULL;
49-
parent_ = NULL;
47+
child_ = nullptr;
48+
next_ = nullptr;
49+
parent_ = nullptr;
5050
toggle_value_ = false;
5151
is_check_box_entry_ = false;
5252
}
@@ -57,21 +57,21 @@ SVMenuNode::~SVMenuNode() {
5757
// Create a new sub menu node with just a caption. This is used to create
5858
// nodes which act as parent nodes to other nodes (e.g. submenus).
5959
SVMenuNode* SVMenuNode::AddChild(const char* txt) {
60-
SVMenuNode* s = new SVMenuNode(-1, txt, false, false, NULL, NULL);
60+
SVMenuNode* s = new SVMenuNode(-1, txt, false, false, nullptr, nullptr);
6161
this->AddChild(s);
6262
return s;
6363
}
6464

6565
// Create a "normal" menu node which is associated with a command event.
6666
void SVMenuNode::AddChild(const char* txt, int command_event) {
67-
this->AddChild(new SVMenuNode(command_event, txt, false, false, NULL, NULL));
67+
this->AddChild(new SVMenuNode(command_event, txt, false, false, nullptr, nullptr));
6868
}
6969

7070
// Create a menu node with an associated value (which might be changed
7171
// through the gui).
7272
void SVMenuNode::AddChild(const char* txt, int command_event,
7373
const char* val) {
74-
this->AddChild(new SVMenuNode(command_event, txt, false, false, val, NULL));
74+
this->AddChild(new SVMenuNode(command_event, txt, false, false, val, nullptr));
7575
}
7676

7777
// Create a menu node with an associated value and description_.
@@ -82,7 +82,7 @@ void SVMenuNode::AddChild(const char* txt, int command_event, const char* val,
8282

8383
// Create a flag menu node.
8484
void SVMenuNode::AddChild(const char* txt, int command_event, int tv) {
85-
this->AddChild(new SVMenuNode(command_event, txt, tv, true, NULL, NULL));
85+
this->AddChild(new SVMenuNode(command_event, txt, tv, true, nullptr, nullptr));
8686
}
8787

8888
// Convenience function called from the different constructors to initialize
@@ -93,9 +93,9 @@ SVMenuNode::SVMenuNode(int command_event, const char* txt,
9393
: text_(txt), value_(val), description_(desc) {
9494
cmd_event_ = command_event;
9595

96-
child_ = NULL;
97-
next_ = NULL;
98-
parent_ = NULL;
96+
child_ = nullptr;
97+
next_ = nullptr;
98+
parent_ = nullptr;
9999
toggle_value_ = tv != 0;
100100
is_check_box_entry_ = check_box_entry;
101101
}
@@ -104,11 +104,11 @@ SVMenuNode::SVMenuNode(int command_event, const char* txt,
104104
void SVMenuNode::AddChild(SVMenuNode* svmn) {
105105
svmn->parent_ = this;
106106
// No children yet.
107-
if (child_ == NULL) {
107+
if (child_ == nullptr) {
108108
child_ = svmn;
109109
} else {
110110
SVMenuNode* cur = child_;
111-
while (cur->next_ != NULL) { cur = cur->next_; }
111+
while (cur->next_ != nullptr) { cur = cur->next_; }
112112
cur->next_ = svmn;
113113
}
114114
}
@@ -119,24 +119,24 @@ void SVMenuNode::AddChild(SVMenuNode* svmn) {
119119
// built which gets shown by right clicking on the window.
120120
// Deletes itself afterwards.
121121
void SVMenuNode::BuildMenu(ScrollView* sv, bool menu_bar) {
122-
if ((parent_ != NULL) && (menu_bar)) {
122+
if ((parent_ != nullptr) && (menu_bar)) {
123123
if (is_check_box_entry_) {
124124
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_,
125125
toggle_value_);
126126
} else {
127127
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_); }
128-
} else if ((parent_ != NULL) && (!menu_bar)) {
128+
} else if ((parent_ != nullptr) && (!menu_bar)) {
129129
if (description_.length() > 0) {
130130
sv->PopupItem(parent_->text_.string(), text_.string(), cmd_event_,
131131
value_.string(), description_.string());
132132
} else {
133133
sv->PopupItem(parent_->text_.string(), text_.string());
134134
}
135135
}
136-
if (child_ != NULL) {
136+
if (child_ != nullptr) {
137137
child_->BuildMenu(sv, menu_bar); delete child_;
138138
}
139-
if (next_ != NULL) {
139+
if (next_ != nullptr) {
140140
next_->BuildMenu(sv, menu_bar); delete next_;
141141
}
142142
}

0 commit comments

Comments
 (0)