[glibmm] OptionGroup: An on_post_parse() override need not call the base class.



commit 6ea6ca5074d44ed4e832cacb56b794c88de428be
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sun Feb 6 16:54:52 2011 +0100

    OptionGroup: An on_post_parse() override need not call the base class.
    
    * glib/src/optiongroup.[hg|ccg]: The C post_parse callback is a static
    protected member function, which performs all necessary post-parsing.
    OptionGroup::on_post_parse is a dummy function.
    * examples/options/main.cc: The on_pre_parse, on_post_parse, and on_error
    overrides don't call the base class functions. Bug 588988.

 ChangeLog                |   18 ++++++++++++---
 examples/options/main.cc |   13 ++++++-----
 glib/src/optiongroup.ccg |   53 +++++++++++++++++++++------------------------
 glib/src/optiongroup.hg  |    3 ++
 4 files changed, 49 insertions(+), 38 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d11b021..f6fd1d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,20 @@
+2011-02-06  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+
+	OptionGroup: An on_post_parse() override need not call the base class.
+
+	* glib/src/optiongroup.[hg|ccg]: The C post_parse callback is a static
+	protected member function, which performs all necessary post-parsing.
+	OptionGroup::on_post_parse is a dummy function.
+	* examples/options/main.cc: The on_pre_parse, on_post_parse, and on_error
+	overrides don't call the base class functions. Bug 588988.
+	
 2011-02-01  Kjell Ahlstedt  <kjell ahlstedt bredband net>
 
-  gmmproc: Add optional arguments custom_vfunc[_callback] to _WRAP_VFUNC.
+	gmmproc: Add optional arguments custom_vfunc[_callback] to _WRAP_VFUNC.
 
-  * tools/pm/Output.pm:
-  * tools/pm/WrapParser.pm: Add handling of optional arguments
-  custom_vfunc[_callback] in _WRAP_VFUNC. Bug 641165.
+	* tools/pm/Output.pm:
+	* tools/pm/WrapParser.pm: Add handling of optional arguments
+	custom_vfunc[_callback] in _WRAP_VFUNC. Bug 641165.
 
 2.27.93:
 
diff --git a/examples/options/main.cc b/examples/options/main.cc
index 4e9a6ac..64166c8 100644
--- a/examples/options/main.cc
+++ b/examples/options/main.cc
@@ -29,8 +29,8 @@ public:
   virtual bool on_post_parse(Glib::OptionContext& context, Glib::OptionGroup& group);
   virtual void on_error(Glib::OptionContext& context, Glib::OptionGroup& group);
   
-  //These int instances should live as long as the OptionGroup to which they are added, 
-  //and as long as the OptionContext to which those OptionGroups are added.
+  //These members should live as long as the OptionGroup to which they are added, 
+  //and as long as the OptionContext to which that OptionGroup is added.
   int m_arg_foo;
   std::string m_arg_filename;
   Glib::ustring m_arg_goo;
@@ -85,7 +85,8 @@ bool ExampleOptionGroup::on_pre_parse(Glib::OptionContext& context, Glib::Option
   //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,
   // in case you want to do any extra processing.
-  return Glib::OptionGroup::on_pre_parse(context, group);
+  std::cout << "on_pre_parse called" << std::endl;
+  return true;
 }
 
 bool ExampleOptionGroup::on_post_parse(Glib::OptionContext& context, Glib::OptionGroup& group)
@@ -93,14 +94,14 @@ bool ExampleOptionGroup::on_post_parse(Glib::OptionContext& context, Glib::Optio
   //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,
   // in case you want to do any extra processing.
-  return Glib::OptionGroup::on_post_parse(context, group);
+  std::cout << "on_post_parse called" << std::endl;
+  return true;
 }
 
 void ExampleOptionGroup::on_error(Glib::OptionContext& context, Glib::OptionGroup& group)
 {
-  Glib::OptionGroup::on_error(context, group);
+  std::cout << "on_error called" << std::endl;
 }
-  
 
 
 int main(int argc, char** argv)
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index 04f5aed..ed5e45a 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -46,20 +46,6 @@ static gboolean g_callback_pre_parse(GOptionContext* context, GOptionGroup* /* g
     return false;
 }
 
-static gboolean g_callback_post_parse(GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error */)
-{
-  OptionContext cppContext(context, false /* take_ownership */);
-  //OptionGroup cppGroup(group, true /* take_copy */); //Maybe this should be option_group.
-
-  OptionGroup* option_group = static_cast<OptionGroup*>(data);
-  if(option_group)
-  {
-    return option_group->on_post_parse(cppContext, *option_group);
-  }
-  else
-    return false;
-}
-
 static void g_callback_error(GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error*/)
 {
   OptionContext cppContext(context, false /* take_ownership */);
@@ -98,13 +84,37 @@ static void OptionGroup_Translate_glibmm_callback_destroy(void* data)
 
 } //anonymous namespace
 
+//static
+gboolean OptionGroup::post_parse_callback(GOptionContext* context,
+  GOptionGroup* /* group */, gpointer data, GError** /* TODO error */)
+{
+  OptionContext cppContext(context, false /* take_ownership */);
+  //OptionGroup cppGroup(group, true /* take_copy */); //Maybe this should be option_group.
+
+  OptionGroup* option_group = static_cast<OptionGroup*>(data);
+  if(option_group)
+  {
+    //The C args have now been given values by g_option_context_parse().
+    //Convert C values to C++ values:
+
+    for(type_map_entries::iterator iter = option_group->map_entries_.begin();
+        iter != option_group->map_entries_.end(); ++iter)
+    {
+      CppOptionEntry& cpp_entry = iter->second;
+      cpp_entry.convert_c_to_cpp();
+    }
+    return option_group->on_post_parse(cppContext, *option_group);
+  }
+  else
+    return false;
+}
 
 OptionGroup::OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description)
 : gobject_( g_option_group_new(name.c_str(), description.c_str(), help_description.c_str(), this, 0 /* destroy_func */) ),
   has_ownership_(true)
 {
   //Connect callbacks, so that derived classes can override the virtual methods:
-  g_option_group_set_parse_hooks(gobj(), &g_callback_pre_parse, &g_callback_post_parse);
+  g_option_group_set_parse_hooks(gobj(), &g_callback_pre_parse, &post_parse_callback);
   g_option_group_set_error_hook(gobj(), &g_callback_error);
 }
 
@@ -218,19 +228,6 @@ bool OptionGroup::on_pre_parse(OptionContext& /* context */, OptionGroup& /* gro
 
 bool OptionGroup::on_post_parse(OptionContext& /* context */, OptionGroup& /* group */)
 {
-  //Call this at the start of overrides.
-
-  //TODO: Maybe put this in the C callback:
-
-  //The C args have now been given values by GOption.
-  //Convert C values to C++ values:
-
-  for(type_map_entries::iterator iter = map_entries_.begin(); iter != map_entries_.end(); ++iter)
-  {
-    CppOptionEntry& cpp_entry = iter->second;
-    cpp_entry.convert_c_to_cpp();
-  }
-
   return true;
 }
 
diff --git a/glib/src/optiongroup.hg b/glib/src/optiongroup.hg
index ce08b94..8d687b2 100644
--- a/glib/src/optiongroup.hg
+++ b/glib/src/optiongroup.hg
@@ -125,6 +125,9 @@ protected:
 
   void add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg);
 
+  static gboolean post_parse_callback(GOptionContext* context,
+    GOptionGroup* group, gpointer data, GError** error);
+
   //Map of entry names to CppOptionEntry:
   typedef std::map<Glib::ustring, CppOptionEntry> type_map_entries;
   type_map_entries map_entries_;



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