[glibmm] Glib::OptionEntry: Use _MEMBER_SET_STR where possible



commit 8724cfedd70991c8545fe96d5cf6b7f051e69ce1
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Mar 2 11:06:27 2018 +0100

    Glib::OptionEntry: Use _MEMBER_SET_STR where possible
    
    No need to hand-code member functions that set a text string.

 glib/src/optionentry.ccg |   40 ----------------------------------------
 glib/src/optionentry.hg  |   20 ++++++++++----------
 2 files changed, 10 insertions(+), 50 deletions(-)
---
diff --git a/glib/src/optionentry.ccg b/glib/src/optionentry.ccg
index 44a5dd3..4e56b4d 100644
--- a/glib/src/optionentry.ccg
+++ b/glib/src/optionentry.ccg
@@ -99,44 +99,4 @@ OptionEntry::operator=(OptionEntry&& other) noexcept
   return *this;
 }
 
-void
-OptionEntry::set_long_name(const Glib::ustring& value)
-{
-  if (gobject_->long_name)
-  {
-    g_free((gchar*)(gobject_->long_name));
-    gobject_->long_name = nullptr;
-  }
-
-  // Note that we do not use nullptr for an empty string,
-  // because G_OPTION_REMAINING is actually a "", so it actually has a distinct meaning:
-  // TODO: Wrap G_OPTION_REMAINING in C++ somehow, maybe as an explicit set_long_name(void) or
-  // set_is_remaining()? murrayc.
-  gobj()->long_name = (value).c_str() ? g_strdup((value).c_str()) : nullptr;
-}
-
-void
-OptionEntry::set_description(const Glib::ustring& value)
-{
-  if (gobject_->description)
-  {
-    g_free((gchar*)(gobject_->description));
-    gobject_->description = nullptr;
-  }
-
-  gobj()->description = (value).empty() ? nullptr : g_strdup((value).c_str());
-}
-
-void
-OptionEntry::set_arg_description(const Glib::ustring& value)
-{
-  if (gobject_->arg_description)
-  {
-    g_free((gchar*)(gobject_->arg_description));
-    gobject_->arg_description = nullptr;
-  }
-
-  gobj()->arg_description = (value).empty() ? nullptr : g_strdup((value).c_str());
-}
-
 } // namespace Glib
diff --git a/glib/src/optionentry.hg b/glib/src/optionentry.hg
index 4e02700..bf9847d 100644
--- a/glib/src/optionentry.hg
+++ b/glib/src/optionentry.hg
@@ -22,7 +22,6 @@ _DEFS(glibmm,glib)
 extern "C" { typedef struct _GOptionEntry GOptionEntry; }
 #endif
 
-
 namespace Glib
 {
 
@@ -56,11 +55,13 @@ public:
 
   OptionEntry& operator=(const OptionEntry& src);
 
-  //#m4 _CONVERSION(`Glib::ustring',`const gchar*',`($3).empty() ? nullptr : g_strdup(($3).c_str())')
-
+  // We do not use nullptr for an empty string in set_long_name(),
+  // because G_OPTION_REMAINING is actually a "", so it has a distinct meaning.
+  // TODO: Wrap G_OPTION_REMAINING in C++ somehow, maybe as an overloaded
+  // set_long_name(void) or set_is_remaining()? murrayc.
+  #m4 _CONVERSION(`Glib::ustring',`const char*',`($3).c_str()')
   _MEMBER_GET(long_name, long_name, Glib::ustring, const char*)
-
-  void set_long_name(const Glib::ustring& value);
+  _MEMBER_SET_STR(long_name, long_name, Glib::ustring, const char*)
 
   _MEMBER_GET(short_name, short_name, gchar, gchar)
   _MEMBER_SET(short_name, short_name, gchar, gchar)
@@ -75,13 +76,13 @@ public:
    */
   _MEMBER_SET(flags, flags, Flags, int)
 
+  // We use nullptr for an empty string in set_description() and set_arg_description().
+  #m4 _CONVERSION(`Glib::ustring',`const char*',`Glib::c_str_or_nullptr($3)')
   _MEMBER_GET(description, description, Glib::ustring, const char*)
-
-  void set_description(const Glib::ustring& value);
+  _MEMBER_SET_STR(description, description, Glib::ustring, const char*)
 
   _MEMBER_GET(arg_description, arg_description, Glib::ustring, const char*)
-
-  void set_arg_description(const Glib::ustring& value);
+  _MEMBER_SET_STR(arg_description, arg_description, Glib::ustring, const char*)
 
   GOptionEntry*       gobj()       { return gobject_; }
   const GOptionEntry* gobj() const { return gobject_; }
@@ -90,7 +91,6 @@ private:
   void release_gobject() noexcept;
 
 protected:
-
   GOptionEntry* gobject_;
 };
 


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