I think this will work:
void MyOptionGroup::add_entry(const Glib::OptionEntry& entry,
Gdk::Rectangle& arg) {
Glib::OptionGroup::add_entry(entry,
sigc::bind(sigc::mem_fun(*this,
&MyOptionGroup::on_option_arg_rectangle), sigc::ref(arg)));
}
bool MyOptionGroup::on_option_arg_rectangle(const
Glib::ustring& option_name,
const Glib::ustring& value, bool has_value,
Gdk::Rectangle& arg)
{
bool success = true;
// parse value to Gdk::Rectangle rect(0, 0, 600, 400);
// How I can set MyOptionGroup->m_arg_box ?
arg = rect;
return success;
}
There are some restrictions on how you can use references with
sigc::bind(). If you can't get it to work, try pointers instead:
void MyOptionGroup::add_entry(const Glib::OptionEntry& entry,
Gdk::Rectangle* arg) {
Glib::OptionGroup::add_entry(entry,
sigc::bind(sigc::mem_fun(*this,
&MyOptionGroup::on_option_arg_rectangle), arg));
}
bool MyOptionGroup::on_option_arg_rectangle(const
Glib::ustring& option_name,
const Glib::ustring& value, bool has_value,
Gdk::Rectangle* arg)
{
bool success = true;
// parse value to Gdk::Rectangle rect(0, 0, 600, 400);
// How I can set MyOptionGroup->m_arg_box ?
*arg = rect;
return success;
}
2013-06-10 17:51, Maggio Mago skrev:
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.
|