Re: [sigc] provided marshallers



Am 2003.09.19 19:34 schrieb(en) Tim Flechtner:
hi everybody,
i was trying to understand how to use a marshaller in sigc++-1.2, and am a bit confused by the 'provided' ones. specifically, how they are usefull:

reading this on the web page:

The following marshallers are provided by default.

  Marshal<void>
  Marshal<T>
  Marshal<R>  (untested, may not be portable)
  FixedMarshal<T,V>
  FastMarshal<T>


1. I can't find FixedMarshal or FastMarshal defined in any of the headers.

Then the documentation is wrong. Please file a bug report at
bugzilla.gnome.org.

2. when i use the following code:

bool marshalled_callback_1()
{
  cout << "marshalled_callback_1()" << endl;
  return false;  // Not done handling signal.
}

bool marshalled_callback_2()
{
  cout << "marshalled_callback_2()" << endl;
  return true;  // Done handling signal.
}

bool marshalled_callback_3()
{
  cout << "marshalled_callback_3()" << endl;
  return false;  // Not done handling signal.
}

SigC::Signal0<bool, Marshal<bool> > signal_marshal_example;
signal_marshal_example.connect(slot(&marshalled_callback_1));
signal_marshal_example.connect(slot(&marshalled_callback_2));
signal_marshal_example.connect(slot(&marshalled_callback_3));
signal_marshal_example();

i get the following ouput, when i wasn't expecting marshalled_callback_3 to be called:
marshalled_callback_1()
marshalled_callback_2()
marshalled_callback_3()

Well, indeed, your expectation is wrong. SigC::Marshal<T>,
the default marshaller, returns the value of the last callback
executed for any type T. Signal emission doesn't stop at a
special return value. Marshal<bool> doesn't make an exception.

when i replace the Marshal<bool> parameter for signal_marshal_example with my class BoolMarshal, defined below, marshalled_callback_3 is not called. can i use the provided Marshal<bool> in some way to achieve the same thing as BoolMarshal?

You could write a template specialization for Marshal<bool> like so:

namespace SigC {

temlpate <>
class Marshal<bool> {
  [your code below]
};

}

Note, however, that Marshal<bool> is the default marshaller for
SigC::SignalX<bool,...>, i.e. your template specialization would
be used automatically for any signal that returns bool.
This is very intransparent, so I'd rather use BoolMarshal and
specify the marshaller explicitely.

Regards,

  Martin


class BoolMarshal
{
  public:
    typedef bool OutType;
    typedef bool InType;

    BoolMarshal() {}

    OutType value() { return false; }

    static OutType default_value() { return true; }

    bool marshal(InType new_val)
    {
      return new_val;
    }

  private:
};


thanks!
-tim


_______________________________________________
libsigc-list mailing list
libsigc-list gnome org
http://mail.gnome.org/mailman/listinfo/libsigc-list



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