[chronojump] class SessionLoadDisplay refactorized inheriting new class BooleansInt



commit 8add783924b7351fa8de4158dbadd1ba047974ad
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 18 16:05:27 2021 +0100

    class SessionLoadDisplay refactorized inheriting new class BooleansInt

 src/gui/app1/session/loadAndImport.cs | 44 ++++++--------------
 src/util.cs                           | 75 +++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 31 deletions(-)
---
diff --git a/src/gui/app1/session/loadAndImport.cs b/src/gui/app1/session/loadAndImport.cs
index d550644c..994d947b 100644
--- a/src/gui/app1/session/loadAndImport.cs
+++ b/src/gui/app1/session/loadAndImport.cs
@@ -360,7 +360,7 @@ public partial class ChronoJumpWindow
                                app1s_checkbutton_show_data_other_tests.Active);
 
                SqlitePreferences.Update (SqlitePreferences.SessionLoadDisplay,
-                               preferences.sessionLoadDisplay.Selection.ToString(), false);
+                               preferences.sessionLoadDisplay.GetInt.ToString(), false);
        }
 
        void app1s_recreateTreeView(string message)
@@ -814,6 +814,7 @@ public partial class ChronoJumpWindow
        }
 }
 
+
 /*
    manage if show athletes info, jumps/races or other tests
 1: athletes
@@ -825,66 +826,47 @@ tested with:
 for(int i = 0; i <= 7; i++)
        LogB.Information(new SessionLoadDisplay(i).ToString());
 */
-public class SessionLoadDisplay
+public class SessionLoadDisplay : BooleansInt
 {
-       private int selection;
+//     private int selection;
 
        //constructor when we have the 0-7 value
        public SessionLoadDisplay(int selection)
        {
-               this.selection = selection;
+               this.i = selection;
        }
 
        //constructo with the 3 booleans
        public SessionLoadDisplay(bool showBit1, bool showBit2, bool showBit3)
        {
-               this.selection = 0;
+               this.i = 0;
                if(showBit1)
-                       selection ++;
+                       i ++;
                if(showBit2)
-                       selection += 2;
+                       i += 2;
                if(showBit3)
-                       selection += 4;
+                       i += 4;
        }
 
        public bool ShowOtherTests
        {
-               get { return (selection >= 4); }
+               get { return Bit3; }
        }
 
        public bool ShowJumpsRaces
        {
-               get {
-                       int temp = selection;
-                       if(temp >= 4)
-                               temp -= 4;
-
-                       return (temp >= 2);
-               }
+               get { return Bit2; }
        }
 
        public bool ShowAthletesInfo
        {
-               get {
-                       int temp = selection;
-                       if(temp >= 4)
-                               temp -= 4;
-                       if(temp >= 2)
-                               temp -= 2;
-
-                       return (temp == 1);
-               }
-       }
-
-       public int Selection
-       {
-               get { return selection; }
+               get { return Bit1; }
        }
 
        //just to debug
        public override string ToString()
        {
                return string.Format("selected: {0} (AthletesInfo: {1}, JumpsRaces: {2}, Other: {3})",
-                               selection, ShowAthletesInfo, ShowJumpsRaces, ShowOtherTests);
+                               i, ShowAthletesInfo, ShowJumpsRaces, ShowOtherTests);
        }
 }
diff --git a/src/util.cs b/src/util.cs
index af9134c7..95254726 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -2478,3 +2478,78 @@ public class UtilCopy
                }
        }
 }
+
+/*
+   Manage conversions between 3 booleans (or maybe more) and one int.
+   Booleans have weights 1, 2, 4
+   eg 6 will be false, false, true
+   tested with:
+   for(int i = 0; i <= 7; i++)
+     LogB.Information(new SessionLoadDisplay(i).ToString());
+*/
+public class BooleansInt
+{
+       protected int i;
+
+       //to inherit
+       public BooleansInt()
+       {
+       }
+
+       public BooleansInt(int i)
+       {
+               this.i = i;
+       }
+
+       public BooleansInt(bool b1, bool b2, bool b3)
+       {
+               this.i = 0;
+               if(b1)
+                       i ++;
+               if(b2)
+                       i += 2;
+               if(b3)
+                       i += 4;
+       }
+
+       public bool Bit3
+       {
+               get { return (i >= 4); }
+       }
+
+       public bool Bit2
+       {
+               get {
+                       int temp = i;
+                       if(temp >= 4)
+                               temp -= 4;
+
+                       return (temp >= 2);
+               }
+       }
+
+       public bool Bit1
+       {
+               get {
+                       int temp = i;
+                       if(temp >= 4)
+                               temp -= 4;
+                       if(temp >= 2)
+                               temp -= 2;
+
+                       return (temp == 1);
+               }
+       }
+
+       public int GetInt
+       {
+               get { return i; }
+       }
+
+       //just to debug
+       public override string ToString()
+       {
+               return string.Format("i: {0} (bit1: {1}, bit2: {2}, bit3: {3})",
+                               i, Bit1, Bit2, Bit3);
+       }
+}


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