Boost logo

Boost :

Subject: Re: [boost] [MSM] Is there any interest in C++14 Boost.MSM-eUML like library which compiles up to 60x quicker whilst being a slightly faster too?
From: Kris (krzysztof_at_[hidden])
Date: 2016-02-08 14:32:56


On Sat, Feb 6, 2016 at 10:34 PM, Vicente Botet [via Boost] <
ml-node+s2283326n4683294h33_at_[hidden]> wrote:

> Le 06/02/2016 22:07, Krzysztof Jusiak a écrit :
>
> > On Sat, Feb 6, 2016 at 12:03 AM, Vicente J. Botet Escriba <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4683294&i=0>>
> wrote:
> >
> >> Le 05/02/2016 22:30, Krzysztof Jusiak a écrit :
> >>
> > Thanks for materials and ideas. It's a really intresesting idea with the
> > pseudo states. I'm not sure if it is not to complex for msm-lite, but I
> > will defo take a look.
> > Your approach also gave me and idea to add exception handling into the
> > transition table the way events are handled too. Not sure about such
> > approach, but I guess, it's worth to consider too.
> >
> > src + event [guard]/action = dst // guard throws runtime_error
> > src + exception<runtime_error> = X // handle exception
> Yes, this is the idea.

Great. I have improved error handling if it comes to exceptions.
Right now, if you do NOT compile with `-fno-exceptions` and do not specify
configure noexcept then you can handle any exceptions thrown on the
transition table.

make_transition_table(
    *"idle"_s + "event1"_t / [] { throw std::runtime_error{"error"}; }
  , "idle"_s + "event2"_t / [] { throw 0; }

  , *"error_handling"_s + exception<std::runtime_error> / [] { std::cout <<
"exception caught" << std::endl; }
  , "error_handling"_s + exception<> / [] { std::cout << "generic
exception caught, terminate..." << std::endl; } = X
);

You can handle specific type of the exception(exception<type>) or just
any(exception<>).

Improved documentation and examples here:
*
http://boost-experimental.github.io/msm-lite/overview/index.html#exception-safety
*
http://boost-experimental.github.io/msm-lite/tutorial/index.html#8-error-handling

*
http://boost-experimental.github.io/msm-lite/examples/index.html#error-handling

> > Anyway, I have created a ticket for it here ->
> > http://boost-experimental.github.io/msm-lite/TODO/index.html
> >
> >
> >> Suggestions are more
> >>> than welcome as I'm not sure what would be the best solution here.
> >>>
> >>> Can you elaborate what you mean by `inheritance of state machines`,
> >>> please?
> >>> Is the question related to composite/sub state machines or just
> whether a
> >>> state machine might be inherited?
> >>>
> >> A derived state machine can refine a base state machine in different
> ways:
> >>
> >> 1* adding new transitions
> >> 2* refining a state by adding sub-states and transitions
> >> 3* refining the next state of a transition with a sub-state of the
> derived
> >> next state (or an entry point, but I believe that MSM-lite has no
> >> entry/exit points associated to an state, isn't it?)
> >>
> > Not yet, explicit entry/exit points are not supported yet.
> >
> >
> >> 4* refining the guard of a transition
> >> 5* refining the action of a transition
> >>
> >> I'm for at least the 3 first extension mechanisms. The last two can be
> >> emulated with virtual functions.
> >> Point 3* could be not needed if the base class transitions make use of
> >> entry points.
> >>
> >>
> > Okay, well, msm-lite doesn't support that as a feature. However, you can
> > achieve more or less all of mentioned things just by using C++.
> > For example, you can extend transiton table of a state machine by
> joining
> > it with another one.
> >
> > auto table1 = make_transition_table(transitions...);
> > auto table2 = make_transition_table(table1, other_transitions...);
> >
> This should respond to point 1*. 2* should need to replace the refined
> state in table1.
> Point 3 would covered if the make_transition_table function overrides
> the redefined transitions.
>

I was wondering whether your point with extending transitions can't be
achieved using sub machines instead ? For example.

struct example {
  auto configure() const noexcept {
    using namespace msm;
      return make_transition_table(
       *"idle"_s + event<e1> / [] { std::cout << "in sub sm" << std::endl;
} = "s1"_s
      , "s1"_s + event<e2> / [] { std::cout << "finish sub sm" <<
std::endl; } = X
      );
  }
};

struct extend_example
  auto configure() const noexcept {
    using namespace msm;
    state<sm<example>> composite;
      return make_transition_table(
        *composite = composite // composite region
       //-----------------------------------//
       // add new transitions for error handling
     , *"error_handling"_s + unexpected_event<> / [] { std::cout <<
"unexpected event, terminate..." << std::endl; } = X
     , "error_handling"_s + exception<std::runtime_error> / [] { std::cout
<< "exception caught" << std::endl; }
     , "error_handling"_s + exception<> / [] { std::cout << "generic
exception caught, terminate..." << std::endl; } = X
      );
  }
};

Right now,
sm<example> sm;
sm.process_event(e1{}); // handled by example
sm.process_event(e2{}); // handled by example
sm.process_event(e3{}); // handled by extended_example error handling

>
> It would be great if you show how the user can address these points with
> your library using some run-able concrete examples.
>

Yea, I will work on that. Cheers for the pointers.

> Vicente
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://boost.2283326.n4.nabble.com/MSM-Is-there-any-interest-in-C-14-Boost-MSM-eUML-like-library-which-compiles-up-to-60x-quicker-whils-tp4683016p4683294.html
> To unsubscribe from [MSM] Is there any interest in C++14 Boost.MSM-eUML
> like library which compiles up to 60x quicker whilst being a slightly
> faster too?, click here
> <http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4683016&code=a3J6eXN6dG9mQGp1c2lhay5uZXR8NDY4MzAxNnwtMTY0MTkzNTIwMA==>
> .
> NAML
> <http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

--
View this message in context: http://boost.2283326.n4.nabble.com/MSM-Is-there-any-interest-in-C-14-Boost-MSM-eUML-like-library-which-compiles-up-to-60x-quicker-whils-tp4683016p4683329.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk