Friday, November 11, 2011

Pattern Matching Changes

The new pattern matching implementation is now merged back into master. There are a lot changes under the hood to significantly speedup pattern matching. However, there is one change to the user interface as well: any_type no longer exists. There is a replacement though, but it's usage differs a little bit: anything.
This is a snipped using the old any_type syntax:
on<int, any_type>() >> [](int v1) { }, // 1
on<int, any_type*>() >> [](int v1) { } // 2
The semantic of the first line - matching exactly one element of any type - is no longer supported. The second line just needs to replace any_type* with anything to work:
// equal to 2
on<int, anything>() >> [](int v1) { }
This will match any message with an integer as first element.

6 comments:

  1. Just one suggestion. I know it might be tedious for you, but I think lots of people would like to take a look at the doxygen-generated doc online, without git-cloning and compiling it. It might be a good idea if you compiled it and uploaded somewhere for everyone to see it.
    Keep up with the good work!

    ReplyDelete
  2. Hi,

    you're absolutely right.
    The doxygen documentation is currently under construction and lacks a lot of details. But I'm working on it and I'll upload it as soon as it reaches a presentable state.

    ReplyDelete
  3. When I write
    on() >> [](int v1) { }
    Is there any way for me to use that "anything"? Just as an example, what can be done if I want to use this class to resend everything that came after the integer to another actor? Something similar to:
    on() >> [](int v1, "anything my_var") {
    send(other_actor, my_var);
    }

    ReplyDelete
  4. Sorry but for some reasons the brackets disappeared... It was
    on< int, anything > () >> [](int v1, "anything my_var")

    ReplyDelete
  5. You could use "last_received()" to access other elements of the received message. A short example:

    on<int,anything>() >> [](int v1)
    {
        auto msg = last_received();
        if (msg.size() == 2)
        {
            if (msg.utype_info_at(1) == typeid(float))
            {
                auto v2 = msg.get_as<float>(1);
                // ...
            }
            else if (msg.utype_info_at(2) == typeid(double))
            {
                auto v2 = msg.get_as<double>(1);
                // ...
            }
        }
        // ...
    }

    ReplyDelete
  6. Should be "(msg.utype_info_at(1) == typeid(double))" of course.

    ReplyDelete