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.
Unfortunately I have a segfault on arg->set_x (100);
I got the wrong way.



Do you know how I need to do to achieve this ?



PS : If I'm misunderstanding do not hesitate to tell me


2013/6/10 Kjell Ahlstedt <kjell.ahlst...@bredband.net <mailto:kjell.ahlst...@bredband.net>>

    Perhaps the glibmm example program at
    https://git.gnome.org/browse/glibmm/tree/examples/options/main.cc
    can help you.

    MyOptionGroup::add_entry() is unnecessary. You can call
    Glib::OptionGroup::add_entry() directly. Or, if you prefer to keep
    MyOptionGroup::add_entry(), the argument Gdk::Rectangle& arg is
    unnecessary. You don't use it, anyway.

    I don't see any problem in
    MyOptionGroup::on_option_arg_rectangle(). I suppose
    MyOptionGroup::m_arg_box is a Gdk::Rectangle. If rect is a local
    Gdk::Rectangle in MyOptionGroup::on_option_arg_rectangle(), you
    can just assign "m_arg_box = rect;" once you have decoded the
    string 'value' and stored the result in 'rect'.

    Have I misunderstood you? Probably, because I don't see what's the
    problem.

    Kjell

    2013-06-10 14:57, Maggio Mago skrev:
    Hello all,

    I have a command line with an option "box" than is a Rectangle:
    I would like to do :
    $] prog --box="0 0 600 400"
    Instead of :
    $] prog --box-x="0"  --box-y="0" --box-width="600" --box-height="400"


    I wrote my programme in Gtkmm, so I have subclassed
    Glib::OptionGroup and add this function :

    void MyOptionGroup::add_entry(const Glib::OptionEntry& entry,
    Gdk::Rectangle& arg) {
    Glib::OptionGroup::add_entry(entry, sigc::mem_fun(*this,
    &OptionGroup::on_option_arg_rectangle));

    }
    bool MyOptionGroup::on_option_arg_rectangle(const Glib::ustring&
    option_name, const Glib::ustring& value, bool has_value)
    {
        bool succes = true;
        // parse value to Gdk::Rectangle(0, 0, 600, 400);
        // How I can set MyOptionGroup->m_arg_box ?
        return succes;
    }

    How to store the parsed valuein the function on_option_rectangle()


    PS : I tried to show you the code that I did but maybe I have it
    all wrong






_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to