diff --git a/viewer/scrollview.cpp b/viewer/scrollview.cpp index 3bcfd2555c..791f86e388 100644 --- a/viewer/scrollview.cpp +++ b/viewer/scrollview.cpp @@ -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 @@ -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 @@ -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(); } @@ -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. @@ -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; @@ -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; @@ -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(); @@ -327,14 +327,14 @@ 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; @@ -342,27 +342,27 @@ void* ScrollView::StartEventHandler(void* a) { } } // 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()"); @@ -370,10 +370,10 @@ ScrollView::~ScrollView() { 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(); @@ -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; @@ -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)", @@ -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, @@ -715,7 +715,7 @@ void ScrollView::Update() { svmap_mu->Lock(); for (std::map::iterator iter = svmap.begin(); iter != svmap.end(); ++iter) { - if (iter->second != NULL) + if (iter->second != nullptr) iter->second->UpdateWindow(); } svmap_mu->Unlock(); @@ -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] = '\\'; diff --git a/viewer/scrollview.h b/viewer/scrollview.h index 96c14a7674..234c56a923 100644 --- a/viewer/scrollview.h +++ b/viewer/scrollview.h @@ -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&); diff --git a/viewer/svmnode.cpp b/viewer/svmnode.cpp index 625835271a..f128ffb40a 100644 --- a/viewer/svmnode.cpp +++ b/viewer/svmnode.cpp @@ -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; } @@ -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_. @@ -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 @@ -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; } @@ -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; } } @@ -119,13 +119,13 @@ 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()); @@ -133,10 +133,10 @@ void SVMenuNode::BuildMenu(ScrollView* sv, bool menu_bar) { 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_; } } diff --git a/viewer/svutil.cpp b/viewer/svutil.cpp index 5bd1b240c0..3868bc76e4 100644 --- a/viewer/svutil.cpp +++ b/viewer/svutil.cpp @@ -63,7 +63,7 @@ SVMutex::SVMutex() { #ifdef _WIN32 mutex_ = CreateMutex(0, FALSE, 0); #else - pthread_mutex_init(&mutex_, NULL); + pthread_mutex_init(&mutex_, nullptr); #endif } @@ -88,7 +88,7 @@ void SVSync::StartThread(void* (*func)(void*), void* arg) { #ifdef _WIN32 LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE)func; DWORD threadid; - HANDLE newthread = CreateThread(NULL, // default security attributes + HANDLE newthread = CreateThread(nullptr, // default security attributes 0, // use default stack size f, // thread function arg, // argument to thread function @@ -112,7 +112,7 @@ void SVSync::ExitThread() { #ifdef _WIN32 // ExitThread(0); #else - pthread_exit(0); + pthread_exit(nullptr); #endif } @@ -127,8 +127,8 @@ void SVSync::StartProcess(const char* executable, const char* args) { STARTUPINFO start_info; PROCESS_INFORMATION proc_info; GetStartupInfo(&start_info); - if (!CreateProcess(NULL, const_cast(proc.c_str()), NULL, NULL, FALSE, - CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL, + if (!CreateProcess(nullptr, const_cast(proc.c_str()), nullptr, nullptr, FALSE, + CREATE_NO_WINDOW | DETACHED_PROCESS, nullptr, nullptr, &start_info, &proc_info)) return; #else @@ -161,7 +161,7 @@ void SVSync::StartProcess(const char* executable, const char* args) { mutable_args[i] = ' '; } } - argv[argc] = NULL; + argv[argc] = nullptr; execvp(executable, argv); free(argv[0]); free(argv[1]); @@ -188,7 +188,7 @@ SVSemaphore::SVSemaphore() { void SVSemaphore::Signal() { #ifdef _WIN32 - ReleaseSemaphore(semaphore_, 1, NULL); + ReleaseSemaphore(semaphore_, 1, nullptr); #elif defined(__APPLE__) sem_post(semaphore_); #else @@ -226,18 +226,18 @@ void SVNetwork::Flush() { // Receive a message from the server. // This will always return one line of char* (denoted by \n). char* SVNetwork::Receive() { - char* result = NULL; + char* result = nullptr; #if defined(_WIN32) || defined(__CYGWIN__) - if (has_content) { result = strtok (NULL, "\n"); } + if (has_content) { result = strtok (nullptr, "\n"); } #else - if (buffer_ptr_ != NULL) { result = strtok_r(NULL, "\n", &buffer_ptr_); } + if (buffer_ptr_ != nullptr) { result = strtok_r(nullptr, "\n", &buffer_ptr_); } #endif // This means there is something left in the buffer and we return it. - if (result != NULL) { return result; + if (result != nullptr) { return result; // Otherwise, we read from the stream_. } else { - buffer_ptr_ = NULL; + buffer_ptr_ = nullptr; has_content = false; // The timeout length is not really important since we are looping anyway @@ -251,16 +251,16 @@ char* SVNetwork::Receive() { FD_ZERO(&readfds); FD_SET(stream_, &readfds); - int i = select(stream_+1, &readfds, NULL, NULL, &tv); + int i = select(stream_+1, &readfds, nullptr, nullptr, &tv); // The stream_ died. - if (i == 0) { return NULL; } + if (i == 0) { return nullptr; } // Read the message buffer. i = recv(stream_, msg_buffer_in_, kMaxMsgSize, 0); // Server quit (0) or error (-1). - if (i <= 0) { return NULL; } + if (i <= 0) { return nullptr; } msg_buffer_in_[i] = '\0'; has_content = true; #ifdef _WIN32 @@ -355,9 +355,9 @@ static int GetAddrInfoNonLinux(const char* hostname, int port, name = gethostbyname(hostname); #endif - if (name == NULL) { + if (name == nullptr) { FreeAddrInfo(*addr_info); - *addr_info = NULL; + *addr_info = nullptr; return -1; } @@ -378,7 +378,7 @@ static int GetAddrInfo(const char* hostname, int port, #if defined(__linux__) char port_str[40]; snprintf(port_str, 40, "%d", port); - return getaddrinfo(hostname, port_str, NULL, address); + return getaddrinfo(hostname, port_str, nullptr, address); #else return GetAddrInfoNonLinux(hostname, port, address); #endif @@ -391,9 +391,9 @@ SVNetwork::SVNetwork(const char* hostname, int port) { msg_buffer_in_[0] = '\0'; has_content = false; - buffer_ptr_ = NULL; + buffer_ptr_ = nullptr; - struct addrinfo *addr_info = NULL; + struct addrinfo *addr_info = nullptr; if (GetAddrInfo(hostname, port, &addr_info) != 0) { std::cerr << "Error resolving name for ScrollView host " @@ -406,7 +406,7 @@ SVNetwork::SVNetwork(const char* hostname, int port) { // If server is not there, we will start a new server as local child process. if (connect(stream_, addr_info->ai_addr, addr_info->ai_addrlen) < 0) { const char* scrollview_path = getenv("SCROLLVIEW_PATH"); - if (scrollview_path == NULL) { + if (scrollview_path == nullptr) { #ifdef SCROLLVIEW_PATH #define _STR(a) #a #define _XSTR(a) _STR(a)