Skip to content

Commit

Permalink
viewer: Replace NULL by nullptr
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 22, 2018
1 parent 39cfbd0 commit f785d5c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 70 deletions.
62 changes: 31 additions & 31 deletions viewer/scrollview.cpp
Expand Up @@ -86,11 +86,11 @@ SVEvent* SVEvent::copy() {
/// It is run from a different thread and synchronizes via SVSync.
void* ScrollView::MessageReceiver(void* a) {
int counter_event_id = 0; // ongoing counter
char* message = NULL;
char* message = nullptr;
// Wait until a new message appears in the input stream_.
do {
message = ScrollView::GetStream()->Receive();
} while (message == NULL);
} while (message == nullptr);

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

if (cur->window != NULL) {
if (cur->window != nullptr) {
cur->parameter = new char[strlen(p) + 1];
strcpy(cur->parameter, p);
if (strlen(p) > 0) { // remove the last \n
Expand Down Expand Up @@ -167,7 +167,7 @@ void* ScrollView::MessageReceiver(void* a) {
waiting_for_events_mu->Unlock();
// Signal the corresponding semaphore twice (for both copies).
ScrollView* sv = svmap[window_id];
if (sv != NULL) {
if (sv != nullptr) {
sv->Signal();
sv->Signal();
}
Expand All @@ -179,9 +179,9 @@ void* ScrollView::MessageReceiver(void* a) {
// Wait until a new message appears in the input stream_.
do {
message = ScrollView::GetStream()->Receive();
} while (message == NULL);
} while (message == nullptr);
}
return 0;
return nullptr;
}

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

SVNetwork* ScrollView::stream_ = NULL;
SVNetwork* ScrollView::stream_ = nullptr;
int ScrollView::nr_created_windows_ = 0;
int ScrollView::image_index_ = 0;

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

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

for (int i = 0; i < SVET_COUNT; i++) {
event_table_[i] = NULL;
event_table_[i] = nullptr;
}

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

for (int i = 0; i < SVET_COUNT; i++) {
if (sv->event_table_[i] != NULL &&
if (sv->event_table_[i] != nullptr &&
(serial < 0 || sv->event_table_[i]->counter < serial)) {
new_event = sv->event_table_[i];
serial = sv->event_table_[i]->counter;
k = i;
}
}
// If we didn't find anything we had an old alarm and just sleep again.
if (new_event != NULL) {
sv->event_table_[k] = NULL;
if (new_event != nullptr) {
sv->event_table_[k] = nullptr;
sv->mutex_->Unlock();
if (sv->event_handler_ != NULL) { sv->event_handler_->Notify(new_event); }
if (sv->event_handler_ != nullptr) { sv->event_handler_->Notify(new_event); }
if (new_event->type == SVET_DESTROY) {
// Signal the destructor that it is safe to terminate.
sv->event_handler_ended_ = true;
sv = NULL;
sv = nullptr;
}
delete new_event; // Delete the pointer after it has been processed.
} else { sv->mutex_->Unlock(); }
// The thread should run as long as its associated window is alive.
} while (sv != NULL);
return 0;
} while (sv != nullptr);
return nullptr;
}
#endif // GRAPHICS_DISABLED

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

SVEvent* sve = AwaitEvent(SVET_DESTROY);
delete sve;
svmap_mu->Lock();
svmap[window_id_] = NULL;
svmap[window_id_] = nullptr;
svmap_mu->Unlock();
// The event handler thread for this window *must* receive the
// destroy event and set its pointer to this to NULL before we allow
// destroy event and set its pointer to this to nullptr before we allow
// the destructor to exit.
while (!event_handler_ended_)
Update();
Expand Down Expand Up @@ -431,9 +431,9 @@ void ScrollView::SetEvent(SVEvent* svevent) {
// Place both events into the queue.
mutex_->Lock();
// Delete the old objects..
if (event_table_[specific->type] != NULL) {
if (event_table_[specific->type] != nullptr) {
delete event_table_[specific->type]; }
if (event_table_[SVET_ANY] != NULL) {
if (event_table_[SVET_ANY] != nullptr) {
delete event_table_[SVET_ANY]; }
// ...and put the new ones in the table.
event_table_[specific->type] = specific;
Expand Down Expand Up @@ -668,7 +668,7 @@ void ScrollView::Image(const char* image, int x_pos, int y_pos) {
// Add new checkboxmenuentry to menubar.
void ScrollView::MenuItem(const char* parent, const char* name,
int cmdEvent, bool flag) {
if (parent == NULL) { parent = ""; }
if (parent == nullptr) { parent = ""; }
if (flag) { SendMsg("addMenuBarItem('%s','%s',%d,true)",
parent, name, cmdEvent);
} else { SendMsg("addMenuBarItem('%s','%s',%d,false)",
Expand All @@ -677,26 +677,26 @@ void ScrollView::MenuItem(const char* parent, const char* name,

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

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

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

// Add new submenuentry to popupmenu.
void ScrollView::PopupItem(const char* parent, const char* name,
int cmdEvent, const char* value, const char* desc) {
if (parent == NULL) { parent = ""; }
if (parent == nullptr) { parent = ""; }
char* esc = AddEscapeChars(value);
char* esc2 = AddEscapeChars(desc);
SendMsg("addPopupMenuItem('%s','%s',%d,'%s','%s')", parent, name,
Expand All @@ -715,7 +715,7 @@ void ScrollView::Update() {
svmap_mu->Lock();
for (std::map<int, ScrollView*>::iterator iter = svmap.begin();
iter != svmap.end(); ++iter) {
if (iter->second != NULL)
if (iter->second != nullptr)
iter->second->UpdateWindow();
}
svmap_mu->Unlock();
Expand Down Expand Up @@ -817,7 +817,7 @@ char* ScrollView::AddEscapeChars(const char* input) {
const char* lastptr = input;
char* message = new char[kMaxMsgSize];
int pos = 0;
while (nextptr != NULL) {
while (nextptr != nullptr) {
strncpy(message+pos, lastptr, nextptr-lastptr);
pos += nextptr - lastptr;
message[pos] = '\\';
Expand Down
4 changes: 2 additions & 2 deletions viewer/scrollview.h
Expand Up @@ -72,8 +72,8 @@ struct SVEvent {
int counter; // Used to detect which kind of event to process next.

SVEvent() {
window = NULL;
parameter = NULL;
window = nullptr;
parameter = nullptr;
}

SVEvent(const SVEvent&);
Expand Down
32 changes: 16 additions & 16 deletions viewer/svmnode.cpp
Expand Up @@ -44,9 +44,9 @@
// be added to this or one of the submenus.
SVMenuNode::SVMenuNode() {
cmd_event_ = -1;
child_ = NULL;
next_ = NULL;
parent_ = NULL;
child_ = nullptr;
next_ = nullptr;
parent_ = nullptr;
toggle_value_ = false;
is_check_box_entry_ = false;
}
Expand All @@ -57,21 +57,21 @@ SVMenuNode::~SVMenuNode() {
// Create a new sub menu node with just a caption. This is used to create
// nodes which act as parent nodes to other nodes (e.g. submenus).
SVMenuNode* SVMenuNode::AddChild(const char* txt) {
SVMenuNode* s = new SVMenuNode(-1, txt, false, false, NULL, NULL);
SVMenuNode* s = new SVMenuNode(-1, txt, false, false, nullptr, nullptr);
this->AddChild(s);
return s;
}

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

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

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

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

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

child_ = NULL;
next_ = NULL;
parent_ = NULL;
child_ = nullptr;
next_ = nullptr;
parent_ = nullptr;
toggle_value_ = tv != 0;
is_check_box_entry_ = check_box_entry;
}
Expand All @@ -104,11 +104,11 @@ SVMenuNode::SVMenuNode(int command_event, const char* txt,
void SVMenuNode::AddChild(SVMenuNode* svmn) {
svmn->parent_ = this;
// No children yet.
if (child_ == NULL) {
if (child_ == nullptr) {
child_ = svmn;
} else {
SVMenuNode* cur = child_;
while (cur->next_ != NULL) { cur = cur->next_; }
while (cur->next_ != nullptr) { cur = cur->next_; }
cur->next_ = svmn;
}
}
Expand All @@ -119,24 +119,24 @@ void SVMenuNode::AddChild(SVMenuNode* svmn) {
// built which gets shown by right clicking on the window.
// Deletes itself afterwards.
void SVMenuNode::BuildMenu(ScrollView* sv, bool menu_bar) {
if ((parent_ != NULL) && (menu_bar)) {
if ((parent_ != nullptr) && (menu_bar)) {
if (is_check_box_entry_) {
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_,
toggle_value_);
} else {
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_); }
} else if ((parent_ != NULL) && (!menu_bar)) {
} else if ((parent_ != nullptr) && (!menu_bar)) {
if (description_.length() > 0) {
sv->PopupItem(parent_->text_.string(), text_.string(), cmd_event_,
value_.string(), description_.string());
} else {
sv->PopupItem(parent_->text_.string(), text_.string());
}
}
if (child_ != NULL) {
if (child_ != nullptr) {
child_->BuildMenu(sv, menu_bar); delete child_;
}
if (next_ != NULL) {
if (next_ != nullptr) {
next_->BuildMenu(sv, menu_bar); delete next_;
}
}
Expand Down

0 comments on commit f785d5c

Please sign in to comment.