Commit e3bce7a3 authored by neverlord's avatar neverlord

documentation folder

parent e39416ae
#include <utility>
#include <iostream>
#include "cppa/cppa.hpp"
using std::cout;
using std::endl;
using namespace cppa;
struct foo
{
int a;
int b;
};
bool operator==(const foo& lhs, const foo& rhs)
{
return lhs.a == rhs.a
&& lhs.b == rhs.b;
}
typedef std::pair<int,int> foo_pair;
int main(int, char**)
{
announce<foo>(&foo::a, &foo::b);
announce<foo_pair>(&foo_pair::first,
&foo_pair::second);
send(self(), foo{1,2});
send(self(), foo_pair{3,4});
send(self(), atom("done"));
receive_loop
(
on<atom("done")>() >> []()
{
exit(0);
},
on<foo_pair>() >> [](const foo_pair& val)
{
cout << "foo_pair("
<< val.first << ","
<< val.second << ")"
<< endl;
},
on<foo>() >> [](const foo& val)
{
cout << "foo("
<< val.a << ","
<< val.b << ")"
<< endl;
}
);
return 0;
}
#include <utility>
#include <iostream>
#include "cppa/cppa.hpp"
using std::cout;
using std::endl;
using std::make_pair;
using namespace cppa;
class foo
{
int m_a;
int m_b;
public:
foo() : m_a(0), m_b(0) { }
foo(int a0, int b0) : m_a(a0), m_b(b0) { }
foo(const foo&) = default;
foo& operator=(const foo&) = default;
int a() const { return m_a; }
void set_a(int val) { m_a = val; }
int b() const { return m_b; }
void set_b(int val) { m_b = val; }
};
bool operator==(const foo& lhs, const foo& rhs)
{
return lhs.a() == rhs.a()
&& lhs.b() == rhs.b();
}
int main(int, char**)
{
announce<foo>(make_pair(&foo::a, &foo::set_a),
make_pair(&foo::b, &foo::set_b));
send(self(), foo{1,2});
receive
(
on<foo>() >> [](const foo& val)
{
cout << "foo("
<< val.a() << ","
<< val.b() << ")"
<< endl;
}
);
return 0;
}
#include <utility>
#include <iostream>
#include "cppa/cppa.hpp"
using std::cout;
using std::endl;
using std::make_pair;
using namespace cppa;
class foo
{
int m_a;
int m_b;
public:
foo() : m_a(0), m_b(0) { }
foo(int a0, int b0) : m_a(a0), m_b(b0) { }
foo(const foo&) = default;
foo& operator=(const foo&) = default;
int a() const { return m_a; }
void a(int val) { m_a = val; }
int b() const { return m_b; }
void b(int val) { m_b = val; }
};
bool operator==(const foo& lhs, const foo& rhs)
{
return lhs.a() == rhs.a()
&& lhs.b() == rhs.b();
}
typedef int (foo::*foo_getter)() const;
typedef void (foo::*foo_setter)(int);
int main(int, char**)
{
foo_getter g1 = &foo::a;
foo_setter s1 = &foo::a;
foo_getter g2 = &foo::b;
foo_setter s2 = &foo::b;
announce<foo>(make_pair(g1, s1),
make_pair(g2, s2));
send(self(), foo{1,2});
receive
(
on<foo>() >> [](const foo& val)
{
cout << "foo("
<< val.a() << ","
<< val.b() << ")"
<< endl;
}
);
return 0;
}
#include <utility>
#include <iostream>
#include "cppa/cppa.hpp"
using std::cout;
using std::endl;
using std::make_pair;
using namespace cppa;
class foo
{
int m_a;
int m_b;
public:
foo() : m_a(0), m_b(0) { }
foo(int a0, int b0) : m_a(a0), m_b(b0) { }
foo(const foo&) = default;
foo& operator=(const foo&) = default;
int a() const { return m_a; }
void set_a(int val) { m_a = val; }
int b() const { return m_b; }
void set_b(int val) { m_b = val; }
};
bool operator==(const foo& lhs, const foo& rhs)
{
return lhs.a() == rhs.a()
&& lhs.b() == rhs.b();
}
struct bar
{
foo f;
int i;
};
bool operator==(const bar& lhs, const bar& rhs)
{
return lhs.f == rhs.f
&& lhs.i == rhs.i;
}
int main(int, char**)
{
announce<bar>(compound_member(&bar::f,
make_pair(&foo::a, &foo::set_a),
make_pair(&foo::b, &foo::set_b)),
&bar::i);
send(self(), bar{foo{1,2},3});
receive
(
on<bar>() >> [](const bar& val)
{
cout << "bar(foo("
<< val.f.a() << ","
<< val.f.b() << "),"
<< val.i << ")"
<< endl;
}
);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment