Re: [Glib::OptionGroup] How to add_entry() for custom data
- From: Maggio Mago <dev maggio gmail com>
- To: Kjell Ahlstedt <kjell ahlstedt bredband net>
- Cc: gtkmm-list gnome org
- Subject: Re: [Glib::OptionGroup] How to add_entry() for custom data
- Date: Mon, 10 Jun 2013 17:51:35 +0200
Thanks for you reply. Excuse me, I was not specific enough.
My problem is about store the parse result in MyOptionGroup object.
Yes:) MyOptionGroup::m_arg_box is a Gdk::Rectangle.
What bothers me with the example you showed me is that I need to create a new function for each options of type Gdk::Rectangle. I wish I do like add_entry(..., bool & arg), ..., add_entry (..., int & arg) functions : The value of the option is parsed and assigned to my object MyObjectGroup on the fly.
My command is:
$] prog --box-in="0 0300400" --box-out = "0 0150200"
Simply put, I'd avoid making comparisons with the names of options. So no:
if (option_name = "-o" && option_name =! "--box-out")
I looked at the source code of Glib :: OptionGroup and I came to this code below:
void OptionGroup :: add_entry (const Glib::OptionEntry & entry, Gdk::Rectangle & arg)
{
SlotOptionArgString slot = sigc :: mem_fun (* this, & OptionGroup::on_option_arg_rectangle);
Glib::OptionGroup add_entry (entry, slot);
}
OptionGroup on_option_arg_rectangle :: bool (const Glib::ustring & option_name, const Glib::ustring & value, bool has_value)
{
bool success = true;
OptionGroup type_map_entries::const_iterator iterFind map_entries_.end = ();
if (option_name [1] == '-')
{
const Glib::ustring long_option_name = Glib::ustring (option_name.c_str () +2);
iterFind map_entries_.find = (long_option_name);
Glib::OptionGroup CppOptionEntry iterFind = entry-> second;
Gdk::Rectangle * arg = static_cast <Gdk::Rectangle*> (entry.cpparg_);
arg-> set_x (100);// <-- SegFault
}
return success;
}
In this way, I can use this code for each option Rectangle kind.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]