Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm currently implementing an actor library for C++ called "acedia" (there's nothing yet about it on google) that uses "type matching". The library is a project for my master thesis and you can send any kind of data to an actor with it.</p> <p>A small snippet:</p> <pre><code>recipient.send(23, 12.23f); </code></pre> <p>And on the recipient side you can either analyze the received message like this:</p> <pre><code>Message msg = receive(); if (msg.match&lt;int, float&gt;() { ... } </code></pre> <p>... or you can define a rule set that invokes a function or method for you:</p> <pre><code>void doSomething(int, float); InvokeRuleSet irs; irs.add(on&lt;int, float&gt;() &gt;&gt; doSomething); receiveAndInvoke(irs); </code></pre> <p>It's also possible to match both on type and on value:</p> <pre><code>Message msg = receive(); if (msg.match&lt;int, float&gt;(42, WILDCARD) { ... } else if (msg.match&lt;int, float&gt;() { ... } </code></pre> <p>The constant "WILDCARD" means, that any value will be acceptet. Pass no arguments is equal set all arguments to "WILDCARD"; meaning that you only want to match the types.</p> <p>This is certainly a small snippet. Also you can use "case classes" like in Scala. They are comparable to "atomics" in erlang. Here is a more detailed example:</p> <pre><code>ACEDIA_DECLARE_CASE_CLASS(ShutdownMessage) ACEDIA_DECLARE_CASE_CLASS(Event1) ACEDIA_DECLARE_CASE_CLASS(Event2) </code></pre> <p>To react to the defined case classes you can write an actor like this:</p> <pre><code>class SomeActor : public Actor { void shutdown() { done = true; } void handleEvent1(); void handleEvent1(); public: SomeActor() : done(false) { } virtual void act() { InvokeRuleSet irs; irs .add(on&lt;ShutdownMessage&gt;() &gt;&gt; method(&amp;SomeActor::shutdown)) .add(on&lt;Event1&gt;() &gt;&gt; method(&amp;SomeActor::handleEvent1)) .add(on&lt;Event2&gt;() &gt;&gt; method(&amp;SomeActor::handleEvent2)) ; while (!done) receiveAndInvoke(irs); } }; </code></pre> <p>To create a new actor and start it, all you have to write is:</p> <pre><code>Acedia::spawn&lt;SomeActor&gt;(); </code></pre> <p>Although the library not even reached beta stadium the shown snippets work and i have a first application running on it. One major goal of the library is to support distributed programming (also across a network).</p> <p>Your question is a while ago, but if you're interested in it: let me know! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload