CAF (c + + actor Framework) (serialization, no serialization, direct transmission) (ii)

Source: Internet
Author: User

Yesterday said the struct, or is not satisfied, after all, C + + inside the class with more well, that first class, this code is I slightly adapted the results.

#include <utility>#include<iostream>#include<vector>#include"caf/all.hpp"usingstd::cout;usingStd::endl;usingStd::make_pair;usingstd::vector;using namespaceCAF;classFoo {Private:  intA_; Vector<int>b_; Public: foo (inta0 =0, vector<int> B0 = vector<int> (0): A_ (A0), b_ (B0) {} foo (Constfoo&) =default; Foo&operator=(Constfoo&) =default; intA ()Const{returnA_;} voidSet_a (intval) {A_ =Val;} Vector<int> B ()Const{return(vector<int>) B_; }  voidSet_b (Constvector<int> val) {b_ =Val;}};BOOL operator==(Constfoo& LHS,Constfoo&RHS) {  returnLHS.A () = =RHS.A ()&& lhs.b () = =rhs.b ();}voidTestee (event_based_actor*Self ) { Self-become ([=](Constfoo&val) {aout (self)<< VAL.A () <<Endl; Auto B=val.b ();  for(Auto it = B.begin (); It! = B.end (); + +it) {aout (self)<<* (IT) <<Endl; } Self-quit (); }  );}intMainint,Char**) {   //################## #First method####################Announce<foo> ("Foo", Make_pair (&AMP;FOO::A, &foo::set_a), Make_pair (&AMP;FOO::B, &foo::set_b)); //################### #Second method####################//a member function pointer to get an attribute of Foo  usingFoo_getter =int(foo::*) ()Const; usingFoo_getter1 = vector<int> (foo::*) ()Const; //a member function pointer to set an attribute of Foo  usingFoo_setter =void(foo::*) (int); usingFoo_setter1 =void(foo::*) (Constvector<int>); Foo_getter G1= &foo::a; Foo_setter S1= &foo::set_a; //same is true for BFoo_getter1 g2 = &foo::b; Foo_setter1 S2= &Foo::set_b; Announce<foo> ("Foo", Make_pair (G1, S1), Make_pair (G2, S2)); //################### #Third method######################//alternative syntax that uses casts instead of variables//(returns false since Foo is already announced)Announce<foo> ("Foo", Make_pair (static_cast<foo_getter> (&foo::a), static_cast<foo_setter> (&foo::set_a)), Make_pair (static_cast<foo_getter1> (&foo::b), static_cast<foo_setter1> (&( foo::set_b)));    {Scoped_actor self; Auto T=spawn (testee); Self->send (T, foo{1,{2,3}});  } await_all_actors_done ();  Shutdown (); return 0;}

Paste the results

The CAF tells us that you want to send a class in the message, you just have to tell it all of your members ' getter and setter functions, and then it provides three ways to (generally choose the first one without any difference = =).

A little more in-depth is the class inside the class object, in fact, is also very convenient knowledge more than a nested. You can see announce4.cpp on GitHub.

Https://github.com/actor-framework/actor-framework/blob/master/examples/type_system/announce_4.cpp

Finally, there is an article to talk about your own Announce5 code understanding and adaptation of it.

Ask a fan, oh oh ~

CAF (c + + actor Framework) (serialization, no serialization, direct transmission) (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.