public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 01/13] Change packagemeta::_actions to an enum
Date: Sun, 05 Aug 2018 22:09:00 -0000	[thread overview]
Message-ID: <20180805220851.270212-2-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20180805220851.270212-1-jon.turney@dronecode.org.uk>

---
 PickCategoryLine.cc |  6 +++---
 package_meta.cc     | 35 +++++++----------------------------
 package_meta.h      | 29 +++++++++--------------------
 3 files changed, 19 insertions(+), 51 deletions(-)

diff --git a/PickCategoryLine.cc b/PickCategoryLine.cc
index 24fecb3..e428419 100644
--- a/PickCategoryLine.cc
+++ b/PickCategoryLine.cc
@@ -55,7 +55,8 @@ PickCategoryLine::paint (HDC hdc, HRGN hUpdRgn, int x, int y, int row, int show_
       
       // draw the caption ('Default', 'Install', etc)
       TextOut (hdc, spin_x + SPIN_WIDTH + ICON_MARGIN, r, 
-               current_default.caption (), strlen (current_default.caption ()));
+               packagemeta::action_caption (current_default),
+               strlen (packagemeta::action_caption (current_default)));
       row++;
     }
   if (collapsed)
@@ -110,8 +111,7 @@ PickCategoryLine::click (int const myrow, int const ClickedRow, int const x)
     {
       if ((size_t) x >= spin_x)
 	{
-	  ++current_default;
-	  
+	  current_default = (packagemeta::_actions)((current_default + 1) % 4);
 	  return set_action (current_default);
 	}
       else
diff --git a/package_meta.cc b/package_meta.cc
index f765baf..dffe3ac 100644
--- a/package_meta.cc
+++ b/package_meta.cc
@@ -54,35 +54,22 @@ bool hasManualSelections = 0;
 
 /*****************/
 
-const
-  packagemeta::_actions
-packagemeta::Default_action (0);
-const
-  packagemeta::_actions
-packagemeta::Install_action (1);
-const
-  packagemeta::_actions
-packagemeta::Reinstall_action (2);
-const
-  packagemeta::_actions
-packagemeta::Uninstall_action (3);
-
 char const *
-packagemeta::_actions::caption ()
+packagemeta::action_caption (_actions _value)
 {
   switch (_value)
     {
-    case 0:
+    case Default_action:
       return "Default";
-    case 1:
+    case Install_action:
       return "Install";
-    case 2:
+    case Reinstall_action:
       return "Reinstall";
-    case 3:
+    case Uninstall_action:
       return "Uninstall";
     }
-  // Pacify GCC: (all case options are checked above)
-  return 0;
+
+  return "Unknown";
 }
 
 packagemeta::packagemeta (packagemeta const &rhs) :
@@ -96,14 +83,6 @@ packagemeta::packagemeta (packagemeta const &rhs) :
   
 }
 
-packagemeta::_actions & packagemeta::_actions::operator++ ()
-{
-  ++_value;
-  if (_value > 3)
-    _value = 0;
-  return *this;
-}
-
 template<class T> struct removeCategory : public unary_function<T, void>
 {
   removeCategory(packagemeta *pkg) : _pkg (pkg) {}
diff --git a/package_meta.h b/package_meta.h
index 8db10e2..df66bda 100644
--- a/package_meta.h
+++ b/package_meta.h
@@ -50,26 +50,15 @@ public:
   void setDefaultCategories();
   void addToCategoryAll();
 
-  class _actions
-  {
-  public:
-    _actions ():_value (0) {};
-    _actions (int aInt) {
-    _value = aInt;
-    if (_value < 0 ||  _value > 3)
-      _value = 0;
-    }
-    _actions & operator ++ ();
-    bool operator == (_actions const &rhs) { return _value == rhs._value; }
-    bool operator != (_actions const &rhs) { return _value != rhs._value; }
-    const char *caption ();
-  private:
-    int _value;
-  };
-  static const _actions Default_action;
-  static const _actions Install_action;
-  static const _actions Reinstall_action;
-  static const _actions Uninstall_action;
+  enum _actions
+    {
+     Default_action,
+     Install_action,
+     Reinstall_action,
+     Uninstall_action,
+    };
+  static const char *action_caption (_actions value);
+
   void set_action (trusts const t);
   void set_action (_actions, packageversion const & default_version);
 
-- 
2.17.0

  parent reply	other threads:[~2018-08-05 22:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-05 22:09 [PATCH setup 00/13] ListView Package Chooser Jon Turney
2018-08-05 22:09 ` [PATCH setup 02/13] Add OnNotify virtual function to class Window for WM_NOTIFY notifications Jon Turney
2018-08-05 22:09 ` Jon Turney [this message]
2018-08-05 22:09 ` [PATCH setup 03/13] Drop 'using namespace std;' from PickView.cc Jon Turney
2018-08-05 22:10 ` [PATCH setup 09/13] Use an icon to represent expanded/collapsed state Jon Turney
2018-08-05 22:10 ` [PATCH setup 08/13] Show the count of packages in a category Jon Turney
2018-08-05 22:10 ` [PATCH setup 06/13] Add methods for listing possible actions on, and applying one to, a package Jon Turney
2018-08-05 22:10 ` [PATCH setup 07/13] Custom draw popup menus in ListView control Jon Turney
2018-08-05 22:10 ` [PATCH setup 04/13] Use a ListView common control rather than a hand-built grid Jon Turney
2018-08-05 22:10 ` [PATCH setup 05/13] Custom draw checkboxes in ListView control Jon Turney
2018-08-05 22:11 ` [PATCH setup 10/13] Use indents in category view Jon Turney
2018-08-05 22:12 ` [PATCH setup 12/13] Restore packagemeta::LDesc() Jon Turney
2018-08-05 22:12 ` [PATCH setup 11/13] Add LDesc() accessor method to SolvableVersion Jon Turney
2018-08-05 22:12 ` [PATCH setup 13/13] Add ldesc tooltips to sdesc column of listview Jon Turney
2018-08-06 14:15 ` [PATCH setup 00/13] ListView Package Chooser Ken Brown
2018-08-06 16:41   ` Achim Gratz
2018-08-06 16:47     ` Achim Gratz
2018-08-06 19:19   ` Ken Brown
2018-10-13 18:46     ` Jon Turney
2018-08-06 16:40 ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180805220851.270212-2-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).