[Bf-blender-cvs] [5cda99ff526] master: Cleanup: clang-tidy for GHOST

Campbell Barton noreply at git.blender.org
Fri Jun 17 09:15:32 CEST 2022


Commit: 5cda99ff526449e3d4b564b6d10e552a1703b96f
Author: Campbell Barton
Date:   Fri Jun 17 17:14:04 2022 +1000
Branches: master
https://developer.blender.org/rB5cda99ff526449e3d4b564b6d10e552a1703b96f

Cleanup: clang-tidy for GHOST

===================================================================

M	intern/ghost/GHOST_Rect.h
M	intern/ghost/intern/GHOST_DropTargetX11.cpp
M	intern/ghost/intern/GHOST_EventPrinter.cpp
M	intern/ghost/intern/GHOST_NDOFManager.cpp
M	intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_SystemX11.cpp

===================================================================

diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h
index 0a5561b7d68..a8082bf015a 100644
--- a/intern/ghost/GHOST_Rect.h
+++ b/intern/ghost/GHOST_Rect.h
@@ -190,26 +190,34 @@ inline bool GHOST_Rect::isValid() const
 
 inline void GHOST_Rect::unionRect(const GHOST_Rect &r)
 {
-  if (r.m_l < m_l)
+  if (r.m_l < m_l) {
     m_l = r.m_l;
-  if (r.m_r > m_r)
+  }
+  if (r.m_r > m_r) {
     m_r = r.m_r;
-  if (r.m_t < m_t)
+  }
+  if (r.m_t < m_t) {
     m_t = r.m_t;
-  if (r.m_b > m_b)
+  }
+  if (r.m_b > m_b) {
     m_b = r.m_b;
+  }
 }
 
 inline void GHOST_Rect::unionPoint(int32_t x, int32_t y)
 {
-  if (x < m_l)
+  if (x < m_l) {
     m_l = x;
-  if (x > m_r)
+  }
+  if (x > m_r) {
     m_r = x;
-  if (y < m_t)
+  }
+  if (y < m_t) {
     m_t = y;
-  if (y > m_b)
+  }
+  if (y > m_b) {
     m_b = y;
+  }
 }
 
 inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis)
@@ -223,16 +231,20 @@ inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAx
   }
 
   if (axis & GHOST_kAxisX) {
-    while (x - ofs < m_l)
+    while (x - ofs < m_l) {
       x += w - (ofs * 2);
-    while (x + ofs > m_r)
+    }
+    while (x + ofs > m_r) {
       x -= w - (ofs * 2);
+    }
   }
   if (axis & GHOST_kGrabAxisY) {
-    while (y - ofs < m_t)
+    while (y - ofs < m_t) {
       y += h - (ofs * 2);
-    while (y + ofs > m_b)
+    }
+    while (y + ofs > m_b) {
       y -= h - (ofs * 2);
+    }
   }
 }
 
diff --git a/intern/ghost/intern/GHOST_DropTargetX11.cpp b/intern/ghost/intern/GHOST_DropTargetX11.cpp
index 70c2eb8c29e..900e46c3732 100644
--- a/intern/ghost/intern/GHOST_DropTargetX11.cpp
+++ b/intern/ghost/intern/GHOST_DropTargetX11.cpp
@@ -31,7 +31,7 @@ int GHOST_DropTargetX11::m_refCounter = 0;
 #define dndTypePlainText m_dndTypes[dndTypePlainTextID]
 #define dndTypeOctetStream m_dndTypes[dndTypeOctetStreamID]
 
-void GHOST_DropTargetX11::Initialize(void)
+void GHOST_DropTargetX11::Initialize()
 {
   Display *display = m_system->getXDisplay();
   int dndTypesCount = sizeof(m_dndMimeTypes) / sizeof(char *);
@@ -60,7 +60,7 @@ void GHOST_DropTargetX11::Initialize(void)
   m_dndActions[counter++] = 0;
 }
 
-void GHOST_DropTargetX11::Uninitialize(void)
+void GHOST_DropTargetX11::Uninitialize()
 {
   xdnd_shut(&m_dndClass);
 
@@ -98,12 +98,12 @@ GHOST_DropTargetX11::~GHOST_DropTargetX11()
 
 /* Based on: https://stackoverflow.com/a/2766963/432509 */
 
-typedef enum DecodeState_e {
+using DecodeState_e = enum DecodeState_e {
   /** Searching for an ampersand to convert. */
   STATE_SEARCH = 0,
   /** Convert the two proceeding characters from hex. */
   STATE_CONVERTING
-} DecodeState_e;
+};
 
 void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char *encodedIn)
 {
@@ -122,7 +122,7 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char
       case STATE_SEARCH:
         if (encodedIn[i] != '%') {
           strncat(decodedOut, &encodedIn[i], 1);
-          assert(strlen(decodedOut) < bufferSize);
+          assert((int)strlen(decodedOut) < bufferSize);
           break;
         }
 
@@ -145,18 +145,19 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char
         /* Ensure both characters are hexadecimal */
 
         for (j = 0; j < 2; ++j) {
-          if (!isxdigit(tempNumBuf[j]))
+          if (!isxdigit(tempNumBuf[j])) {
             bothDigits = false;
+          }
         }
 
-        if (!bothDigits)
+        if (!bothDigits) {
           break;
-
+        }
         /* Convert two hexadecimal characters into one character */
         sscanf(tempNumBuf, "%x", &asciiCharacter);
 
         /* Ensure we aren't going to overflow */
-        assert(strlen(decodedOut) < bufferSize);
+        assert((int)strlen(decodedOut) < bufferSize);
 
         /* Concatenate this character onto the output */
         strncat(decodedOut, (char *)&asciiCharacter, 1);
diff --git a/intern/ghost/intern/GHOST_EventPrinter.cpp b/intern/ghost/intern/GHOST_EventPrinter.cpp
index 758938e879e..2620bcc075d 100644
--- a/intern/ghost/intern/GHOST_EventPrinter.cpp
+++ b/intern/ghost/intern/GHOST_EventPrinter.cpp
@@ -12,7 +12,7 @@
 #include "GHOST_EventKey.h"
 #include <iostream>
 
-#include <stdio.h>
+#include <cstdio>
 
 bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
 {
@@ -20,9 +20,9 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
 
   GHOST_ASSERT(event, "event==0");
 
-  if (event->getType() == GHOST_kEventWindowUpdate)
+  if (event->getType() == GHOST_kEventWindowUpdate) {
     return false;
-
+  }
   std::cout << "GHOST_EventPrinter::processEvent, time: " << (int32_t)event->getTime()
             << ", type: ";
   switch (event->getType()) {
@@ -106,8 +106,9 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
           std::cout << " type : GHOST_kDragnDropTypeFilenames,";
           std::cout << "\n  Received " << strArray->count << " filename"
                     << (strArray->count > 1 ? "s:" : ":");
-          for (i = 0; i < strArray->count; i++)
+          for (i = 0; i < strArray->count; i++) {
             std::cout << "\n    File[" << i << "] : " << strArray->strings[i];
+          }
         } break;
         default:
           break;
@@ -117,10 +118,12 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
     case GHOST_kEventOpenMainFile: {
       GHOST_TEventDataPtr eventData = ((GHOST_IEvent *)event)->getData();
 
-      if (eventData)
+      if (eventData) {
         std::cout << "GHOST_kEventOpenMainFile for path : " << (char *)eventData;
-      else
+      }
+      else {
         std::cout << "GHOST_kEventOpenMainFile with no path specified!!";
+      }
     } break;
 
     case GHOST_kEventQuitRequest:
@@ -167,7 +170,7 @@ void GHOST_EventPrinter::getKeyString(GHOST_TKey key, char str[32]) const
     sprintf(str, "F%d", key - GHOST_kKeyF1 + 1);
   }
   else {
-    const char *tstr = NULL;
+    const char *tstr = nullptr;
     switch (key) {
       case GHOST_kKeyBackSpace:
         tstr = "BackSpace";
diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp
index 7f6b5f53316..2298ba86521 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManager.cpp
@@ -6,10 +6,10 @@
 #include "GHOST_EventNDOF.h"
 #include "GHOST_WindowManager.h"
 
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>  /* For error/info reporting. */
-#include <string.h> /* For memory functions. */
+#include <climits>
+#include <cmath>
+#include <cstdio>  /* For error/info reporting. */
+#include <cstring> /* For memory functions. */
 
 #ifdef DEBUG_NDOF_MOTION
 /* Printable version of each GHOST_TProgress value. */
@@ -255,8 +255,9 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ
       printf("ndof: unknown device %04hx:%04hx\n", vendor_id, product_id);
   }
 
-  if (m_buttonMask == 0)
+  if (m_buttonMask == 0) {
     m_buttonMask = (int)~(UINT_MAX << m_buttonCount);
+  }
 
 #ifdef DEBUG_NDOF_BUTTONS
   printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
diff --git a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
index 7e53ce45f70..7770f5f39ce 100644
--- a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
@@ -32,10 +32,11 @@ GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System &sys)
       char line[MAX_LINE_LENGTH] = {0};
       while (fgets(line, MAX_LINE_LENGTH, command_output)) {
         unsigned short vendor_id = 0, product_id = 0;
-        if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2)
+        if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2) {
           if (setDevice(vendor_id, product_id)) {
             break; /* stop looking once the first 3D mouse is found */
           }
+        }
       }
       pclose(command_output);
     }
@@ -44,8 +45,9 @@ GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System &sys)
 
 GHOST_NDOFManagerUnix::~GHOST_NDOFManagerUnix()
 {
-  if (m_available)
+  if (m_available) {
     spnav_close();
+  }
 }
 
 bool GHOST_NDOFManagerUnix::available()
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index c8308b3586b..cc8d0915c5a 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -158,7 +158,7 @@ GHOST_TSuccess GHOST_System::updateFullScreen(const GHOST_DisplaySetting &settin
   return success;
 }
 
-GHOST_TSuccess GHOST_System::endFullScreen(void)
+GHOST_TSuccess GHOST_System::endFullScreen()
 {
   GHOST_TSuccess success = GHOST_kFailure;
   GHOST_ASSERT(m_windowManager, "GHOST_System::endFullScreen(): invalid window manager");
@@ -177,7 +177,7 @@ GHOST_TSuccess GHOST_System::endFullScreen(void)
   return success;
 }
 
-bool GHOST_System::getFullScreen(void)
+bool GHOST_System::getFullScreen()
 {
   bool fullScreen;
   if (m_windowManager) {
@@ -289,7 +289,7 @@ void GHOST_System::setTabletAPI(GHOST_TTabletAPI api)
   m_tabletAPI = api;
 }
 
-GHOST_TTabletAPI GHOST_System::getTabletAPI(void)
+GHOST_TTabletAPI GHOST_System::getTabletAPI()
 {
   return m_tabletAPI;
 }
@@ -319,9 +319,7 @@ GHOST_TSuccess GHOST_System::init()
   if (m_timerManager && m_windowManager && m_eventManager) {
     return GHOST_kSuccess;
   }
-  else {
-    return GHOST_kFailure;
-  }
+  return GHOST_kFailure;
 }
 
 GHOST_TSuccess GHOST_System::exit()
@@ -357,10 +355,12 @@ GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window,
 {
   GHOST_GLSettings glSettings = {0};
 
-  if (stereoVisual)
+  if (stereoVisual) {
     glSettings.flags |= GHOST_glStereoVisual;
-  if (alphaBackground)
+  }
+  if (alphaBackground) {
     glSettings.flags |= GHOST_glAlphaBackground;
+  }
 
   /* NOTE: don't use #getCurrentDisplaySetting() because on X11 we may
    * be zoomed in and the desktop may be bigger than the viewport. */
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index e93a56cc8d4..bed9cd6c784 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list