glibmm r653 - in trunk: . examples/options glib/src
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glibmm r653 - in trunk: . examples/options glib/src
- Date: Sun, 13 Apr 2008 12:16:28 +0100 (BST)
Author: murrayc
Date: Sun Apr 13 12:16:28 2008
New Revision: 653
URL: http://svn.gnome.org/viewvc/glibmm?rev=653&view=rev
Log:
2008-04-13 Murray Cumming <murrayc murrayc com>
* glib/src/optionentry.ccg: set_long_name(): Do not use NULL for an
empty string, because has a special meaning to GOptionEntry - it
is the definition of G_OPTION_REMANING.
* examples/options/main.cc: Add an entry with the long name
G_OPTION_REMAINING, to list additional non-named arguments. More
explicit API should be added for this.
Bug #526831 (Christian Lundgren).
Modified:
trunk/ChangeLog
trunk/examples/options/main.cc
trunk/glib/src/optionentry.ccg
Modified: trunk/examples/options/main.cc
==============================================================================
--- trunk/examples/options/main.cc (original)
+++ trunk/examples/options/main.cc Sun Apr 13 12:16:28 2008
@@ -36,6 +36,7 @@
Glib::ustring m_arg_goo;
bool m_arg_boolean;
Glib::OptionGroup::vecustrings m_arg_list;
+ Glib::OptionGroup::vecustrings m_remaining_list;
};
ExampleOptionGroup::ExampleOptionGroup()
@@ -69,8 +70,14 @@
Glib::OptionEntry entry5;
entry5.set_long_name("list");
entry5.set_short_name('l');
- entry5.set_description("The List");
+ entry5.set_description("A List");
add_entry(entry5, m_arg_list);
+
+ Glib::OptionEntry entry_remaining;
+ entry_remaining.set_long_name(G_OPTION_REMAINING);
+ entry_remaining.set_arg_description(G_OPTION_REMAINING);
+
+ add_entry(entry_remaining, m_remaining_list);
}
bool ExampleOptionGroup::on_pre_parse(Glib::OptionContext& context, Glib::OptionGroup& group)
@@ -140,6 +147,14 @@
std::cout << *iter << ", ";
}
std::cout << std::endl;
+
+ //This one shows the remaining arguments on the command line, which had no name= form:
+ std::cout << " remaining = ";
+ for(Glib::OptionGroup::vecustrings::const_iterator iter = group.m_remaining_list.begin(); iter != group.m_remaining_list.end(); ++iter)
+ {
+ std::cout << *iter << ", ";
+ }
+ std::cout << std::endl;
return 0;
}
Modified: trunk/glib/src/optionentry.ccg
==============================================================================
--- trunk/glib/src/optionentry.ccg (original)
+++ trunk/glib/src/optionentry.ccg Sun Apr 13 12:16:28 2008
@@ -82,7 +82,10 @@
gobject_->long_name = NULL;
}
- gobject_->long_name = (value).empty() ? NULL : g_strdup((value).c_str());
+ //Note that we do not use NULL 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()) : NULL;
}
void OptionEntry::set_description(const Glib::ustring& value)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]