[glibmm] Glib::OptionGroup: Modify on_[pre|post]_parse(), on_error()



commit 51a0e045b39d684854da0e71bd322fb335b4d6b2
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Mar 21 16:45:24 2017 +0100

    Glib::OptionGroup: Modify on_[pre|post]_parse(), on_error()
    
    Remove the OptionGroup& parameter in on_pre_parse(), on_post_parse() and
    on_error(). It's unnecessary. It's always identical to *this.
    Add a const Error& parameter to on_error(). It's an input parameter with
    information about an error that has occurred in OptionContext::parse().

 examples/options/main.cc |   12 ++++++------
 glib/src/optiongroup.ccg |   31 +++++++++++++++++++------------
 glib/src/optiongroup.hg  |    6 +++---
 3 files changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/examples/options/main.cc b/examples/options/main.cc
index 4f8e5e3..ca7ea0c 100644
--- a/examples/options/main.cc
+++ b/examples/options/main.cc
@@ -25,9 +25,9 @@ public:
   ExampleOptionGroup();
 
 private:
-  bool on_pre_parse(Glib::OptionContext& context, Glib::OptionGroup& group) override;
-  bool on_post_parse(Glib::OptionContext& context, Glib::OptionGroup& group) override;
-  void on_error(Glib::OptionContext& context, Glib::OptionGroup& group) override;
+  bool on_pre_parse(Glib::OptionContext& context) override;
+  bool on_post_parse(Glib::OptionContext& context) override;
+  void on_error(Glib::OptionContext& context, const Glib::Error& error) override;
 
   bool on_option_arg_string(
     const Glib::ustring& option_name, const Glib::ustring& value, bool has_value);
@@ -108,7 +108,7 @@ ExampleOptionGroup::ExampleOptionGroup()
 }
 
 bool
-ExampleOptionGroup::on_pre_parse(Glib::OptionContext& /* context */, Glib::OptionGroup& /* group */)
+ExampleOptionGroup::on_pre_parse(Glib::OptionContext& /* context */)
 {
   // This is called before the m_arg_* instances are given their values.
   // You do not need to override this method. This is just here to show you how,
@@ -119,7 +119,7 @@ ExampleOptionGroup::on_pre_parse(Glib::OptionContext& /* context */, Glib::Optio
 
 bool
 ExampleOptionGroup::on_post_parse(
-  Glib::OptionContext& /* context */, Glib::OptionGroup& /* group */)
+  Glib::OptionContext& /* context */)
 {
   // This is called after the m_arg_* instances are given their values.
   // You do not need to override this method. This is just here to show you how,
@@ -129,7 +129,7 @@ ExampleOptionGroup::on_post_parse(
 }
 
 void
-ExampleOptionGroup::on_error(Glib::OptionContext& /* context */, Glib::OptionGroup& /* group */)
+ExampleOptionGroup::on_error(Glib::OptionContext& /* context */, const Glib::Error& /* error */)
 {
   std::cout << "on_error called" << std::endl;
 }
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index b4e63a8..ab80bcb 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -84,7 +84,7 @@ g_callback_pre_parse(
 
   try
   {
-    return option_group->on_pre_parse(cppContext, *option_group);
+    return option_group->on_pre_parse(cppContext);
   }
   catch (Glib::Error& err)
   {
@@ -99,18 +99,25 @@ g_callback_pre_parse(
 
 static void
 g_callback_error(
-  GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error */)
+  GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** error)
 {
-  // TODO GError** error is input data containing information on an error that
-  // has occurred before this function is called. When API can be broken,
-  // the function prototype of on_error ought to be changed to
-  // void on_error(OptionContext& context, Error& error).
+  // GError** error is input data containing information on an error that
+  // has occurred before this function is called.
 
   OptionContext cppContext(context, false /* take_ownership */);
 
   auto option_group = static_cast<OptionGroup*>(data);
-  if (option_group)
-    return option_group->on_error(cppContext, *option_group);
+  if (option_group && error && *error)
+  {
+    try
+    {
+      Error::throw_exception(g_error_copy(*error));
+    }
+    catch (const Error& err)
+    {
+      return option_group->on_error(cppContext, err);
+    }
+  }
 }
 
 const gchar*
@@ -167,7 +174,7 @@ OptionGroup::post_parse_callback(
 
   try
   {
-    return option_group->on_post_parse(cppContext, *option_group);
+    return option_group->on_post_parse(cppContext);
   }
   catch (Glib::Error& err)
   {
@@ -477,19 +484,19 @@ OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_typ
 }
 
 bool
-OptionGroup::on_pre_parse(OptionContext& /* context */, OptionGroup& /* group */)
+OptionGroup::on_pre_parse(OptionContext& /* context */)
 {
   return true;
 }
 
 bool
-OptionGroup::on_post_parse(OptionContext& /* context */, OptionGroup& /* group */)
+OptionGroup::on_post_parse(OptionContext& /* context */)
 {
   return true;
 }
 
 void
-OptionGroup::on_error(OptionContext& /* context */, OptionGroup& /* group */)
+OptionGroup::on_error(OptionContext& /* context */, const Error& /* error */)
 {
 }
 
diff --git a/glib/src/optiongroup.hg b/glib/src/optiongroup.hg
index e7a7b2e..12d5dc7 100644
--- a/glib/src/optiongroup.hg
+++ b/glib/src/optiongroup.hg
@@ -84,9 +84,9 @@ public:
   _IGNORE(g_option_group_free, g_option_group_unref)
 
 
-  virtual bool on_pre_parse(OptionContext& context, OptionGroup& group);
-  virtual bool on_post_parse(OptionContext& context, OptionGroup& group);
-  virtual void on_error(OptionContext& context, OptionGroup& group);
+  virtual bool on_pre_parse(OptionContext& context);
+  virtual bool on_post_parse(OptionContext& context);
+  virtual void on_error(OptionContext& context, const Error& error);
   _IGNORE(g_option_group_set_parse_hooks, g_option_group_set_error_hook)
 
   void add_entry(const OptionEntry& entry);


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