[gnome-system-monitor] Replaced defines with constants (fixes #141)



commit 436065fef68a3050a81ace1dd352405249aa7d56
Author: Artem Vorotnikov <artem vorotnikov me>
Date:   Fri May 29 09:33:30 2020 +0300

    Replaced defines with constants (fixes #141)

 src/load-graph.cpp | 23 +++++++++--------------
 src/openfiles.cpp  |  2 +-
 src/procdialogs.h  |  8 ++++----
 3 files changed, 14 insertions(+), 19 deletions(-)
---
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 21ef5f16..9d874b19 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -52,7 +52,7 @@ unsigned LoadGraph::num_bars() const
 
 
 
-#define FRAME_WIDTH 4
+const int FRAME_WIDTH = 4;
 static void draw_background(LoadGraph *graph) {
     GtkAllocation allocation;
     cairo_t *cr;
@@ -349,18 +349,16 @@ get_load (LoadGraph *graph)
 
     glibtop_get_cpu (&cpu);
 
-#undef NOW
-#undef LAST
-#define NOW  (graph->cpu.times[graph->cpu.now])
-#define LAST (graph->cpu.times[graph->cpu.now ^ 1])
+    auto NOW  = [&]() -> guint64 (&)[GLIBTOP_NCPU][N_CPU_STATES] { return graph->cpu.times[graph->cpu.now]; 
};
+    auto LAST = [&]() -> guint64 (&)[GLIBTOP_NCPU][N_CPU_STATES] { return graph->cpu.times[graph->cpu.now ^ 
1]; };
 
     if (graph->n == 1) {
-        NOW[0][CPU_TOTAL] = cpu.total;
-        NOW[0][CPU_USED] = cpu.user + cpu.nice + cpu.sys;
+        NOW()[0][CPU_TOTAL] = cpu.total;
+        NOW()[0][CPU_USED] = cpu.user + cpu.nice + cpu.sys;
     } else {
         for (i = 0; i < graph->n; i++) {
-            NOW[i][CPU_TOTAL] = cpu.xcpu_total[i];
-            NOW[i][CPU_USED] = cpu.xcpu_user[i] + cpu.xcpu_nice[i]
+            NOW()[i][CPU_TOTAL] = cpu.xcpu_total[i];
+            NOW()[i][CPU_USED] = cpu.xcpu_user[i] + cpu.xcpu_nice[i]
                 + cpu.xcpu_sys[i];
         }
     }
@@ -377,8 +375,8 @@ get_load (LoadGraph *graph)
         float total, used;
         gchar *text;
 
-        total = NOW[i][CPU_TOTAL] - LAST[i][CPU_TOTAL];
-        used  = NOW[i][CPU_USED]  - LAST[i][CPU_USED];
+        total = NOW()[i][CPU_TOTAL] - LAST()[i][CPU_TOTAL];
+        used  = NOW()[i][CPU_USED]  - LAST()[i][CPU_USED];
 
         load = used / MAX(total, 1.0f);
         graph->data[0][i] = load;
@@ -396,9 +394,6 @@ get_load (LoadGraph *graph)
     }
 
     graph->cpu.now ^= 1;
-
-#undef NOW
-#undef LAST
 }
 
 
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 9516f060..edf359bf 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -18,7 +18,7 @@
 #include "legacy/treeview.h"
 
 #ifndef NI_IDN
-#define NI_IDN 0
+const int NI_IDN = 0;
 #endif
 
 enum
diff --git a/src/procdialogs.h b/src/procdialogs.h
index ce099102..e94a7e5e 100644
--- a/src/procdialogs.h
+++ b/src/procdialogs.h
@@ -27,11 +27,11 @@
    are scaled back to these limits. So show these limits in the slider
 */
 #ifdef __linux__
-#define RENICE_VAL_MIN -20
-#define RENICE_VAL_MAX 19
+const int RENICE_VAL_MIN = -20;
+const int RENICE_VAL_MAX = 19;
 #else /* ! linux */
-#define RENICE_VAL_MIN -20
-#define RENICE_VAL_MAX 20
+const int RENICE_VAL_MIN = -20;
+const int RENICE_VAL_MAX = 20;
 #endif
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]