Commit 0bf5d7d5 authored by neverlord's avatar neverlord

coding style

parent 54f080df
......@@ -104,14 +104,12 @@ object ActorCreation {
if (args(0) == "threaded") {
val newMax = (1 << n) + 100
System.setProperty("actors.maxPoolSize", newMax.toString)
//actor {
(new ThreadedTestee(self)).start ! Spread(n)
receive {
case Result(v) =>
if (v != (1 << n))
Console.println("ERROR: expected " + (1 << n) + ", received " + v)
}
//}
(new ThreadedTestee(self)).start ! Spread(n)
receive {
case Result(v) =>
if (v != (1 << n))
Console.println("ERROR: expected " + (1 << n) + ", received " + v)
}
}
else if (args(0) == "threadless") {
actor {
......
......@@ -44,32 +44,23 @@ using std::uint32_t;
using namespace cppa;
struct testee : fsm_actor<testee>
{
struct testee : fsm_actor<testee> {
actor_ptr parent;
behavior init_state;
testee(const actor_ptr& pptr) : parent(pptr)
{
init_state =
(
on(atom("spread"), 0) >> [=]()
{
testee(const actor_ptr& pptr) : parent(pptr) {
init_state = (
on(atom("spread"), 0) >> [=]() {
send(parent, atom("result"), (uint32_t) 1);
become_void();
},
on<atom("spread"), int>() >> [=](int x)
{
on<atom("spread"), int>() >> [=](int x) {
any_tuple msg = make_cow_tuple(atom("spread"), x - 1);
spawn(new testee(this)) << msg;
spawn(new testee(this)) << msg;
become
(
on<atom("result"), uint32_t>() >> [=](uint32_t r1)
{
become
(
on<atom("result"), uint32_t>() >> [=](uint32_t r2)
{
become (
on<atom("result"), uint32_t>() >> [=](uint32_t r1) {
become (
on<atom("result"), uint32_t>() >> [=](uint32_t r2) {
send(parent, atom("result"), r1 + r2);
become_void();
}
......@@ -81,27 +72,19 @@ struct testee : fsm_actor<testee>
}
};
void stacked_testee(actor_ptr parent)
{
receive
(
on(atom("spread"), 0) >> [&]()
{
void stacked_testee(actor_ptr parent) {
receive (
on(atom("spread"), 0) >> [&]() {
send(parent, atom("result"), (uint32_t) 1);
},
on<atom("spread"), int>() >> [&](int x)
{
on<atom("spread"), int>() >> [&](int x) {
any_tuple msg = make_cow_tuple(atom("spread"), x-1);
spawn(stacked_testee, self) << msg;
spawn(stacked_testee, self) << msg;
receive
(
on<atom("result"), uint32_t>() >> [&](uint32_t v1)
{
receive
(
on<atom("result"),uint32_t>() >> [&](uint32_t v2)
{
receive (
on<atom("result"), uint32_t>() >> [&](uint32_t v1) {
receive (
on<atom("result"),uint32_t>() >> [&](uint32_t v2) {
send(parent, atom("result"), v1 + v2);
}
);
......@@ -111,48 +94,38 @@ void stacked_testee(actor_ptr parent)
);
}
void usage()
{
void usage() {
cout << "usage: actor_creation (stacked|event-based) POW" << endl
<< " creates 2^POW actors" << endl
<< endl;
}
int main(int argc, char** argv)
{
if (argc == 3)
{
int main(int argc, char** argv) {
if (argc == 3) {
int num = rd<int>(argv[2]);
if (strcmp(argv[1], "stacked") == 0)
{
if (strcmp(argv[1], "stacked") == 0) {
send(spawn(stacked_testee, self), atom("spread"), num);
}
else if (strcmp(argv[1], "event-based") == 0)
{
else if (strcmp(argv[1], "event-based") == 0) {
send(spawn(new testee(self)), atom("spread"), num);
}
else
{
else {
usage();
return 1;
}
receive
(
on<atom("result"),uint32_t>() >> [=](uint32_t value)
{
receive (
on<atom("result"),uint32_t>() >> [=](uint32_t value) {
//cout << "value = " << value << endl
// << "expected => 2^" << num << " = "
// << (1 << num) << endl;
if (value != (((uint32_t) 1) << num))
{
if (value != (((uint32_t) 1) << num)) {
cerr << "ERROR: received wrong result!\n";
}
}
);
await_all_others_done();
}
else
{
else {
usage();
return 1;
}
......
This diff is collapsed.
......@@ -45,19 +45,14 @@ using std::int64_t;
using namespace cppa;
struct fsm_receiver : fsm_actor<fsm_receiver>
{
struct fsm_receiver : fsm_actor<fsm_receiver> {
int64_t m_value;
behavior init_state;
fsm_receiver(int64_t max) : m_value(0)
{
init_state =
(
on(atom("msg")) >> [=]()
{
fsm_receiver(int64_t max) : m_value(0) {
init_state = (
on(atom("msg")) >> [=]() {
++m_value;
if (m_value == max)
{
if (m_value == max) {
become_void();
}
}
......@@ -65,63 +60,49 @@ struct fsm_receiver : fsm_actor<fsm_receiver>
}
};
void receiver(int64_t max)
{
void receiver(int64_t max) {
int64_t value;
receive_while(gref(value) < max)
//receive_while([&]() { return value < max; })
(
on(atom("msg")) >> [&]()
{
receive_while(gref(value) < max) (
on(atom("msg")) >> [&]() {
++value;
}
);
}
void sender(actor_ptr whom, int64_t count)
{
void sender(actor_ptr whom, int64_t count) {
any_tuple msg = make_cow_tuple(atom("msg"));
for (int64_t i = 0; i < count; ++i)
{
for (int64_t i = 0; i < count; ++i) {
whom->enqueue(nullptr, msg);
}
}
void usage()
{
void usage() {
cout << "usage: mailbox_performance "
"(stacked|event-based) (sending threads) (msg per thread)" << endl
<< endl;
}
int main(int argc, char** argv)
{
if (argc == 4)
{
int main(int argc, char** argv) {
if (argc == 4) {
int64_t num_sender = rd<int64_t>(argv[2]);
int64_t num_msgs = rd<int64_t>(argv[3]);
actor_ptr testee;
if (strcmp(argv[1], "stacked") == 0)
{
if (strcmp(argv[1], "stacked") == 0) {
testee = spawn(receiver, num_sender * num_msgs);
}
else if (strcmp(argv[1], "event-based") == 0)
{
else if (strcmp(argv[1], "event-based") == 0) {
testee = spawn(new fsm_receiver(num_sender * num_msgs));
}
else
{
else {
usage();
return 1;
}
for (int64_t i = 0; i < num_sender; ++i)
{
for (int64_t i = 0; i < num_sender; ++i) {
detail::thread(sender, testee, num_msgs).detach();
}
await_all_others_done();
}
else
{
else {
usage();
return 1;
}
......
......@@ -53,12 +53,10 @@ using std::int64_t;
using namespace cppa;
template<typename T>
T rd(char const* cstr)
{
T rd(char const* cstr) {
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
if (endptr == nullptr || *endptr != '\0') {
std::string errstr;
errstr += "\"";
errstr += cstr;
......@@ -68,14 +66,12 @@ T rd(char const* cstr)
return result;
}
void usage()
{
void usage() {
cerr << "usage: matching (cow_tuple|object_array) {NUM_LOOPS}" << endl;
exit(1);
}
int main(int argc, char** argv)
{
int main(int argc, char** argv) {
announce<list<int>>();
if (argc != 3) usage();
auto num_loops = rd<int64_t>(argv[2]);
......@@ -86,8 +82,7 @@ int main(int argc, char** argv)
any_tuple m5;
any_tuple m6;
if (strcmp(argv[1], "cow_tuple") == 0)
{
if (strcmp(argv[1], "cow_tuple") == 0) {
m1 = make_cow_tuple(atom("msg1"), 0);
m2 = make_cow_tuple(atom("msg2"), 0.0);
m3 = make_cow_tuple(atom("msg3"), list<int>{0});
......@@ -95,8 +90,7 @@ int main(int argc, char** argv)
m5 = make_cow_tuple(atom("msg5"), 0, 0, 0);
m6 = make_cow_tuple(atom("msg6"), 0, 0.0, "0");
}
else if (strcmp(argv[1], "object_array") == 0)
{
else if (strcmp(argv[1], "object_array") == 0) {
auto m1o = new detail::object_array;
m1o->push_back(object::from(atom("msg1")));
m1o->push_back(object::from(0));
......@@ -127,8 +121,7 @@ int main(int argc, char** argv)
m6o->push_back(object::from(std::string("0")));
m6 = any_tuple{m6o};
}
else
{
else {
usage();
}
int64_t m1matched = 0;
......@@ -137,8 +130,7 @@ int main(int argc, char** argv)
int64_t m4matched = 0;
int64_t m5matched = 0;
int64_t m6matched = 0;
auto part_fun =
(
auto part_fun = (
on<atom("msg1"), int>() >> [&]() { ++m1matched; },
on<atom("msg2"), double>() >> [&]() { ++m2matched; },
on<atom("msg3"), list<int> >() >> [&]() { ++m3matched; },
......@@ -146,8 +138,7 @@ int main(int argc, char** argv)
on<atom("msg5"), int, int, int>() >> [&]() { ++m5matched; },
on<atom("msg6"), int, double, string>() >> [&]() { ++m6matched; }
);
for (int64_t i = 0; i < num_loops; ++i)
{
for (int64_t i = 0; i < num_loops; ++i) {
part_fun(m1);
part_fun(m2);
part_fun(m3);
......
This diff is collapsed.
......@@ -18,41 +18,33 @@ struct result { uint32_t value; };
using namespace Theron;
struct testee : Actor
{
struct testee : Actor {
Address m_parent;
bool m_first_result_received;
uint32_t m_first_result;
std::vector<ActorRef> m_children;
void spread_handler(const spread& arg, const Address)
{
if (arg.value == 0)
{
void spread_handler(const spread& arg, const Address) {
if (arg.value == 0) {
Send(result{1}, m_parent);
}
else
{
else {
spread msg = {arg.value-1};
Parameters params = {GetAddress()};
for (int i = 0; i < 2; ++i)
{
for (int i = 0; i < 2; ++i) {
m_children.push_back(GetFramework().CreateActor<testee>(params));
m_children.back().Push(msg, GetAddress());
}
}
}
void result_handler(const result& arg, const Address)
{
if (!m_first_result_received)
{
void result_handler(const result& arg, const Address) {
if (!m_first_result_received) {
m_first_result_received = true;
m_first_result = arg.value;
}
else
{
else {
m_children.clear();
Send(result{m_first_result + arg.value}, m_parent);
}
......@@ -60,25 +52,21 @@ struct testee : Actor
typedef struct { Address arg0; } Parameters;
testee(const Parameters& p) : m_parent(p.arg0), m_first_result_received(false)
{
testee(const Parameters& p) : m_parent(p.arg0), m_first_result_received(false) {
RegisterHandler(this, &testee::spread_handler);
RegisterHandler(this, &testee::result_handler);
}
};
void usage()
{
void usage() {
cout << "usage: theron_actor_creation _ POW" << endl
<< " creates 2^POW actors" << endl
<< endl;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
int main(int argc, char** argv) {
if (argc != 3) {
usage();
return 1;
}
......
......@@ -18,47 +18,39 @@ using namespace Theron;
int64_t t_max = 0;
struct receiver : Actor
{
struct receiver : Actor {
int64_t m_num;
void handler(const int64_t&, const Address from)
{
void handler(const int64_t&, const Address from) {
if (++m_num == t_max)
Send(t_max, from);
}
receiver() : m_num(0)
{
receiver() : m_num(0) {
RegisterHandler(this, &receiver::handler);
}
};
void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num)
{
void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) {
auto addr = ref.GetAddress();
int64_t msg;
for (int64_t i = 0; i < num; ++i) f.Send(msg, waiter, addr);
}
void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num)
{
void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) {
int64_t msg;
for (int64_t i = 0; i < num; ++i) ref.Push(msg, waiter);
}
void usage()
{
void usage() {
cout << "usage ('push'|'send') (num_threads) (num_messages)" << endl;
exit(1);
}
int main(int argc, char** argv)
{
if (argc != 4)
{
int main(int argc, char** argv) {
if (argc != 4) {
usage();
}
enum { invalid_impl, push_impl, send_impl } impl = invalid_impl;
......@@ -74,8 +66,7 @@ int main(int argc, char** argv)
ActorRef aref(framework.CreateActor<receiver>());
std::list<std::thread> threads;
auto impl_fun = (impl == push_impl) ? send_sender : push_sender;
for (int64_t i = 0; i < num_sender; ++i)
{
for (int64_t i = 0; i < num_sender; ++i) {
threads.push_back(std::thread(impl_fun, std::ref(framework), aref, receiverAddr, num_msgs));
}
r.Wait();
......
......@@ -30,40 +30,32 @@ struct master_done { };
struct worker_done { };
struct worker : Actor
{
void handle_calc(const calc_msg& msg, Address from)
{
struct worker : Actor {
void handle_calc(const calc_msg& msg, Address from) {
factorize(msg.value);
}
void handle_master_done(const master_done&, Address from)
{
void handle_master_done(const master_done&, Address from) {
Send(worker_done(), from);
}
worker()
{
worker() {
RegisterHandler(this, &worker::handle_calc);
RegisterHandler(this, &worker::handle_master_done);
}
};
struct chain_link : Actor
{
struct chain_link : Actor {
Address next;
void handle_token(const token_msg& msg, Address)
{
void handle_token(const token_msg& msg, Address) {
Send(msg, next);
}
typedef struct { Address next; } Parameters;
chain_link(const Parameters& p) : next(p.next)
{
chain_link(const Parameters& p) : next(p.next) {
RegisterHandler(this, &chain_link::handle_token);
}
};
struct master : Actor
{
struct master : Actor {
Address mc;
int iteration;
int max_iterations;
......@@ -72,20 +64,17 @@ struct master : Actor
int ring_size;
int initial_token_value;
std::vector<ActorRef> m_children;
void new_ring()
{
void new_ring() {
m_children.clear();
w.Push(calc_msg{s_task_n}, GetAddress());
next = GetAddress();
for (int i = 1; i < ring_size; ++i)
{
for (int i = 1; i < ring_size; ++i) {
m_children.push_back(GetFramework().CreateActor<chain_link>(chain_link::Parameters{next}));
next = m_children.back().GetAddress();
}
Send(token_msg{initial_token_value}, next);
}
void handle_init(const init_msg& msg, Address)
{
void handle_init(const init_msg& msg, Address) {
w = GetFramework().CreateActor<worker>();
iteration = 0;
ring_size = msg.ring_size;
......@@ -93,40 +82,32 @@ struct master : Actor
max_iterations = msg.iterations;
new_ring();
}
void handle_token(const token_msg& msg, Address)
{
if (msg.value == 0)
{
if (++iteration < max_iterations)
{
void handle_token(const token_msg& msg, Address) {
if (msg.value == 0) {
if (++iteration < max_iterations) {
new_ring();
}
else
{
else {
w.Push(master_done(), GetAddress());
}
}
else
{
else {
Send(token_msg{msg.value - 1}, next);
}
}
void handle_worker_done(const worker_done&, Address)
{
void handle_worker_done(const worker_done&, Address) {
Send(master_done(), mc);
w = ActorRef::Null();
}
typedef struct { Address mc; } Parameters;
master(const Parameters& p) : mc(p.mc), iteration(0)
{
master(const Parameters& p) : mc(p.mc), iteration(0) {
RegisterHandler(this, &master::handle_init);
RegisterHandler(this, &master::handle_token);
RegisterHandler(this, &master::handle_worker_done);
}
};
void usage()
{
void usage() {
cout << "usage: mailbox_performance "
"'send' (num rings) (ring size) "
"(initial token value) (repetitions)"
......@@ -135,8 +116,7 @@ void usage()
exit(1);
}
int main(int argc, char** argv)
{
int main(int argc, char** argv) {
if (argc != 6) usage();
if (strcmp("send", argv[1]) != 0) usage();
int num_rings = rd<int>(argv[2]);
......@@ -146,12 +126,10 @@ int main(int argc, char** argv)
Receiver r;
Framework framework(num_cores());
std::vector<ActorRef> masters;
for (int i = 0; i < num_rings; ++i)
{
for (int i = 0; i < num_rings; ++i) {
masters.push_back(framework.CreateActor<master>(master::Parameters{r.GetAddress()}));
}
for (ActorRef& m : masters)
{
for (ActorRef& m : masters) {
m.Push(init_msg{ring_size, inital_token_value, repetitions}, r.GetAddress());
}
for (int i = 0; i < num_rings; ++i) r.Wait();
......
......@@ -37,8 +37,7 @@
#include <stdexcept>
#include <algorithm>
inline std::vector<std::string> split(std::string const& str, char delim)
{
inline std::vector<std::string> split(std::string const& str, char delim) {
std::vector<std::string> result;
std::stringstream strs{str};
std::string tmp;
......@@ -47,12 +46,10 @@ inline std::vector<std::string> split(std::string const& str, char delim)
}
inline std::string join(std::vector<std::string> const& vec,
std::string const& delim = "")
{
std::string const& delim = "") {
if (vec.empty()) return "";
auto result = vec.front();
for (auto i = vec.begin() + 1; i != vec.end(); ++i)
{
for (auto i = vec.begin() + 1; i != vec.end(); ++i) {
result += delim;
result += *i;
}
......@@ -60,12 +57,10 @@ inline std::string join(std::vector<std::string> const& vec,
}
template<typename T>
T rd(char const* cstr)
{
T rd(char const* cstr) {
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
if (endptr == nullptr || *endptr != '\0') {
std::string errstr;
errstr += "\"";
errstr += cstr;
......@@ -75,12 +70,10 @@ T rd(char const* cstr)
return result;
}
int num_cores()
{
int num_cores() {
char cbuf[100];
FILE* cmd = popen("/bin/cat /proc/cpuinfo | /bin/grep processor | /usr/bin/wc -l", "r");
if (fgets(cbuf, 100, cmd) == 0)
{
if (fgets(cbuf, 100, cmd) == 0) {
throw std::runtime_error("cannot determine number of cores");
}
pclose(cmd);
......@@ -90,24 +83,19 @@ int num_cores()
return rd<int>(cbuf);
}
std::vector<uint64_t> factorize(uint64_t n)
{
std::vector<uint64_t> factorize(uint64_t n) {
std::vector<uint64_t> result;
if (n <= 3)
{
if (n <= 3) {
result.push_back(n);
return std::move(result);
}
uint64_t d = 2;
while(d < n)
{
if((n % d) == 0)
{
while(d < n) {
if((n % d) == 0) {
result.push_back(d);
n /= d;
}
else
{
else {
d = (d == 2) ? 3 : (d + 2);
}
}
......
......@@ -4,16 +4,13 @@
using std::cout;
using std::endl;
struct pseudo_worker
{
struct pseudo_worker {
int m_value;
pseudo_worker() : m_value(0) { }
void operator()()
{
for (;;)
{
void operator()() {
for (;;) {
++m_value;
cout << "value = " << m_value << endl;
cppa_fibre_yield(0);
......@@ -21,22 +18,18 @@ struct pseudo_worker
}
};
void coroutine()
{
auto pw = reinterpret_cast<pseudo_worker*>(cppa_fibre_init_switch_arg());
(*pw)();
void coroutine() {
auto pw = reinterpret_cast<pseudo_worker*>(cppa_fibre_init_switch_arg()); (*pw)();
}
int main()
{
int main() {
pseudo_worker pw;
cppa_fibre fself;
cppa_fibre fcoroutine;
cppa_fibre_ctor(&fself);
cppa_fibre_ctor2(&fcoroutine, coroutine, &pw);
cppa_fibre_initialize(&fcoroutine);
for (int i = 1; i < 11; ++i)
{
for (int i = 1; i < 11; ++i) {
cout << "i = " << i << endl;
cppa_fibre_switch(&fself, &fcoroutine);
}
......
......@@ -58,8 +58,7 @@ namespace cppa {
* or {@link cppa::local_actor local_actor}.
*/
template<class Base>
class abstract_actor : public Base
{
class abstract_actor : public Base {
typedef std::unique_ptr<attachable> attachable_ptr;
typedef detail::lock_guard<detail::mutex> guard_type;
......@@ -69,23 +68,18 @@ class abstract_actor : public Base
typedef detail::recursive_queue_node mailbox_element;
typedef intrusive::single_reader_queue<mailbox_element> mailbox_type;
bool attach(attachable* ptr) // override
{
if (ptr == nullptr)
{
bool attach(attachable* ptr) { // override
if (ptr == nullptr) {
guard_type guard(m_mtx);
return m_exit_reason.load() == exit_reason::not_exited;
}
else
{
else {
attachable_ptr uptr(ptr);
std::uint32_t reason;
// lifetime scope of guard
{
{ // lifetime scope of guard
guard_type guard(m_mtx);
reason = m_exit_reason.load();
if (reason == exit_reason::not_exited)
{
if (reason == exit_reason::not_exited) {
m_attachables.push_back(std::move(uptr));
return true;
}
......@@ -95,18 +89,15 @@ class abstract_actor : public Base
}
}
void detach(const attachable::token& what) // override
{
void detach(const attachable::token& what) { // override
attachable_ptr uptr;
// lifetime scope of guard
{
{ // lifetime scope of guard
guard_type guard(m_mtx);
auto end = m_attachables.end();
auto i = std::find_if(
m_attachables.begin(), end,
[&](attachable_ptr& p) { return p->matches(what); });
if (i != end)
{
if (i != end) {
uptr = std::move(*i);
m_attachables.erase(i);
}
......@@ -114,24 +105,19 @@ class abstract_actor : public Base
// uptr will be destroyed here, without locked mutex
}
void link_to(intrusive_ptr<actor>& other) // override
{
void link_to(intrusive_ptr<actor>& other) { // override
(void) link_to_impl(other);
}
void unlink_from(intrusive_ptr<actor>& other) // override
{
void unlink_from(intrusive_ptr<actor>& other) { // override
(void) unlink_from_impl(other);
}
bool remove_backlink(intrusive_ptr<actor>& other) // override
{
if (other && other != this)
{
bool remove_backlink(intrusive_ptr<actor>& other) { // override
if (other && other != this) {
guard_type guard(m_mtx);
auto i = std::find(m_links.begin(), m_links.end(), other);
if (i != m_links.end())
{
if (i != m_links.end()) {
m_links.erase(i);
return true;
}
......@@ -139,26 +125,21 @@ class abstract_actor : public Base
return false;
}
bool establish_backlink(intrusive_ptr<actor>& other) // override
{
bool establish_backlink(intrusive_ptr<actor>& other) { // override
std::uint32_t reason = exit_reason::not_exited;
if (other && other != this)
{
if (other && other != this) {
guard_type guard(m_mtx);
reason = m_exit_reason.load();
if (reason == exit_reason::not_exited)
{
if (reason == exit_reason::not_exited) {
auto i = std::find(m_links.begin(), m_links.end(), other);
if (i == m_links.end())
{
if (i == m_links.end()) {
m_links.push_back(other);
return true;
}
}
}
// send exit message without lock
if (reason != exit_reason::not_exited)
{
if (reason != exit_reason::not_exited) {
other->enqueue(this, make_cow_tuple(atom("EXIT"), reason));
}
return false;
......@@ -172,39 +153,31 @@ class abstract_actor : public Base
typedef detail::lock_guard<util::shared_spinlock> lock_type;
inline mailbox_element* fetch_node(actor* sender, any_tuple msg)
{
inline mailbox_element* fetch_node(actor* sender, any_tuple msg) {
mailbox_element* result = nullptr;
// lifetime scope of guard
{
{ // lifetime scope of guard
lock_type guard{m_nodes_lock};
if (m_nodes.not_empty())
{
if (m_nodes.not_empty()) {
result = m_nodes.back();
m_nodes.pop_back();
}
}
if (result)
{
if (result) {
result->next = nullptr;
result->marked = false;
result->sender = sender;
result->msg = std::move(msg);
}
else
{
else {
result = new mailbox_element(sender, std::move(msg));
}
return result;
}
inline void release_node(mailbox_element* node)
{
// lifetime scope of guard
{
inline void release_node(mailbox_element* node) {
{ // lifetime scope of guard
lock_type guard{m_nodes_lock};
if (m_nodes.full() == false)
{
if (m_nodes.full() == false) {
m_nodes.push_back(node);
return;
}
......@@ -214,25 +187,20 @@ class abstract_actor : public Base
template<typename... Args>
abstract_actor(Args&&... args) : Base(std::forward<Args>(args)...)
, m_exit_reason(exit_reason::not_exited)
{
, m_exit_reason(exit_reason::not_exited) {
// pre-allocate some nodes
for (size_t i = 0; i < m_nodes.max_size() / 2; ++i)
{
for (size_t i = 0; i < m_nodes.max_size() / 2; ++i) {
m_nodes.push_back(new mailbox_element);
}
}
void cleanup(std::uint32_t reason)
{
void cleanup(std::uint32_t reason) {
if (reason == exit_reason::not_exited) return;
decltype(m_links) mlinks;
decltype(m_attachables) mattachables;
// lifetime scope of guard
{
{ // lifetime scope of guard
guard_type guard(m_mtx);
if (m_exit_reason != exit_reason::not_exited)
{
if (m_exit_reason != exit_reason::not_exited) {
// already exited
return;
}
......@@ -244,31 +212,25 @@ class abstract_actor : public Base
m_attachables.clear();
}
// send exit messages
for (actor_ptr& aptr : mlinks)
{
for (actor_ptr& aptr : mlinks) {
aptr->enqueue(this, make_cow_tuple(atom("EXIT"), reason));
}
for (attachable_ptr& ptr : mattachables)
{
for (attachable_ptr& ptr : mattachables) {
ptr->actor_exited(reason);
}
}
bool link_to_impl(intrusive_ptr<actor>& other)
{
if (other && other != this)
{
bool link_to_impl(intrusive_ptr<actor>& other) {
if (other && other != this) {
guard_type guard(m_mtx);
// send exit message if already exited
if (exited())
{
if (exited()) {
other->enqueue(this, make_cow_tuple(atom("EXIT"),
m_exit_reason.load()));
}
// add link if not already linked to other
// (checked by establish_backlink)
else if (other->establish_backlink(this))
{
else if (other->establish_backlink(this)) {
m_links.push_back(other);
return true;
}
......@@ -276,12 +238,10 @@ class abstract_actor : public Base
return false;
}
bool unlink_from_impl(intrusive_ptr<actor>& other)
{
bool unlink_from_impl(intrusive_ptr<actor>& other) {
guard_type guard(m_mtx);
// remove_backlink returns true if this actor is linked to other
if (other && !exited() && other->remove_backlink(this))
{
if (other && !exited() && other->remove_backlink(this)) {
auto i = std::find(m_links.begin(), m_links.end(), other);
CPPA_REQUIRE(i != m_links.end());
m_links.erase(i);
......@@ -293,8 +253,7 @@ class abstract_actor : public Base
private:
// @pre m_mtx.locked()
bool exited() const
{
bool exited() const {
return m_exit_reason.load() != exit_reason::not_exited;
}
......
......@@ -47,8 +47,7 @@ namespace cppa {
/**
* @brief Base class for all event-based actor implementations.
*/
class abstract_event_based_actor : public detail::abstract_scheduled_actor
{
class abstract_event_based_actor : public detail::abstract_scheduled_actor {
typedef detail::abstract_scheduled_actor super;
......@@ -74,8 +73,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
std::vector<std::unique_ptr<detail::recursive_queue_node> > m_cache;
enum handle_message_result
{
enum handle_message_result {
drop_msg,
msg_handled,
cache_msg
......@@ -98,8 +96,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* does not accidently uses receive() instead of become().
*/
template<typename... Args>
void receive(Args&&...)
{
void receive(Args&&...) {
static_assert((sizeof...(Args) + 1) < 1,
"You shall not use receive in an event-based actor. "
"Use become() instead.");
......@@ -109,8 +106,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error.
*/
template<typename... Args>
void receive_loop(Args&&... args)
{
void receive_loop(Args&&... args) {
receive(std::forward<Args>(args)...);
}
......@@ -118,8 +114,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error.
*/
template<typename... Args>
void receive_while(Args&&... args)
{
void receive_while(Args&&... args) {
receive(std::forward<Args>(args)...);
}
......@@ -127,8 +122,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error.
*/
template<typename... Args>
void do_receive(Args&&... args)
{
void do_receive(Args&&... args) {
receive(std::forward<Args>(args)...);
}
......
......@@ -52,8 +52,7 @@ typedef std::uint32_t actor_id;
/**
* @brief Base class for all actor implementations.
*/
class actor : public channel
{
class actor : public channel {
public:
......@@ -224,23 +223,19 @@ typedef intrusive_ptr<actor> actor_ptr;
* inline and template member function implementations *
******************************************************************************/
inline const process_information& actor::parent_process() const
{
inline const process_information& actor::parent_process() const {
return *m_parent_process;
}
inline process_information_ptr actor::parent_process_ptr() const
{
inline process_information_ptr actor::parent_process_ptr() const {
return m_parent_process;
}
inline std::uint32_t actor::id() const
{
inline std::uint32_t actor::id() const {
return m_id;
}
inline bool actor::is_proxy() const
{
inline bool actor::is_proxy() const {
return m_is_proxy;
}
......@@ -248,39 +243,33 @@ template<typename T>
bool actor::attach(std::unique_ptr<T>&& ptr,
typename std::enable_if<
std::is_base_of<attachable,T>::value
>::type*)
{
>::type*) {
return attach(static_cast<attachable*>(ptr.release()));
}
template<class F>
class functor_attachable : public attachable
{
class functor_attachable : public attachable {
F m_functor;
public:
template<class FArg>
functor_attachable(FArg&& arg) : m_functor(std::forward<FArg>(arg))
{
functor_attachable(FArg&& arg) : m_functor(std::forward<FArg>(arg)) {
}
void actor_exited(std::uint32_t reason)
{
void actor_exited(std::uint32_t reason) {
m_functor(reason);
}
bool matches(const attachable::token&)
{
bool matches(const attachable::token&) {
return false;
}
};
template<typename F>
bool actor::attach_functor(F&& ftor)
{
bool actor::attach_functor(F&& ftor) {
typedef typename util::rm_ref<F>::type f_type;
return attach(new functor_attachable<f_type>(std::forward<F>(ftor)));
}
......
......@@ -45,8 +45,7 @@ class actor_proxy : public actor { };
#else // CPPA_DOCUMENTATION
class actor_proxy : public abstract_actor<actor>
{
class actor_proxy : public abstract_actor<actor> {
typedef abstract_actor<actor> super;
......
......@@ -110,16 +110,14 @@ bool announce(const std::type_info& tinfo, uniform_type_info* utype);
*/
template<class C, class Parent, typename... Args>
std::pair<C Parent::*, util::abstract_uniform_type_info<C>*>
compound_member(C Parent::*c_ptr, const Args&... args)
{
compound_member(C Parent::*c_ptr, const Args&... args) {
return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) };
}
// deals with getter returning a mutable reference
template<class C, class Parent, typename... Args>
std::pair<C& (Parent::*)(), util::abstract_uniform_type_info<C>*>
compound_member(C& (Parent::*c_ptr)(), const Args&... args)
{
compound_member(C& (Parent::*c_ptr)(), const Args&... args) {
return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) };
}
......@@ -129,8 +127,7 @@ template<class Parent, typename GRes,
std::pair<std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>,
util::abstract_uniform_type_info<typename util::rm_ref<GRes>::type>*>
compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>& gspair,
const Args&... args)
{
const Args&... args) {
return { gspair, new detail::default_uniform_type_info_impl<typename util::rm_ref<GRes>::type>(args...) };
}
......@@ -142,8 +139,7 @@ compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)
* otherwise @c false.
*/
template<typename T, typename... Args>
inline bool announce(const Args&... args)
{
inline bool announce(const Args&... args) {
return announce(typeid(T),
new detail::default_uniform_type_info_impl<T>(args...));
}
......
......@@ -51,8 +51,7 @@ namespace cppa {
* @brief Describes a fixed-length copy-on-write tuple
* with elements of any type.
*/
class any_tuple
{
class any_tuple {
public:
......@@ -129,15 +128,13 @@ class any_tuple
inline bool empty() const { return size() == 0; }
template<typename T>
inline const T& get_as(size_t p) const
{
inline const T& get_as(size_t p) const {
CPPA_REQUIRE(*(type_at(p)) == typeid(T));
return *reinterpret_cast<T const*>(at(p));
}
template<typename T>
inline T& get_as_mutable(size_t p)
{
inline T& get_as_mutable(size_t p) {
CPPA_REQUIRE(*(type_at(p)) == typeid(T));
return *reinterpret_cast<T*>(mutable_at(p));
}
......@@ -150,13 +147,11 @@ class any_tuple
inline const cow_ptr<detail::abstract_tuple>& vals() const { return m_vals; }
inline const cow_ptr<detail::abstract_tuple>& cvals() const { return m_vals; }
inline std::type_info const* type_token() const
{
inline std::type_info const* type_token() const {
return m_vals->type_token();
}
inline detail::tuple_impl_info impl_type() const
{
inline detail::tuple_impl_info impl_type() const {
return m_vals->impl_type();
}
......@@ -166,8 +161,7 @@ class any_tuple
util::is_iterable<
typename util::rm_ref<T>::type
>::value
>::type* = 0)
{
>::type* = 0) {
static constexpr bool can_optimize = std::is_reference<T>::value
&& !std::is_const<T>::value;
std::integral_constant<bool, can_optimize> token;
......@@ -180,8 +174,7 @@ class any_tuple
util::is_iterable<
typename util::rm_ref<T>::type
>::value == false
>::type* = 0)
{
>::type* = 0) {
typedef typename util::rm_ref<T>::type vtype;
typedef typename detail::implicit_conversions<vtype>::type converted;
static_assert(util::is_legal_tuple_type<converted>::value,
......@@ -194,8 +187,7 @@ class any_tuple
return any_tuple{simple_view(std::forward<T>(value), token)};
}
void force_detach()
{
void force_detach() {
m_vals.detach();
}
......@@ -211,22 +203,19 @@ class any_tuple
template<typename T>
static inline tup_ptr simple_view(T& value,
std::integral_constant<bool, true>)
{
std::integral_constant<bool, true>) {
return new detail::tuple_view<T>(&value);
}
template<typename First, typename Second>
static inline tup_ptr simple_view(std::pair<First, Second>& p,
std::integral_constant<bool, true>)
{
std::integral_constant<bool, true>) {
return new detail::tuple_view<First, Second>(&p.first, &p.second);
}
template<typename T>
static inline tup_ptr simple_view(T&& value,
std::integral_constant<bool, false>)
{
std::integral_constant<bool, false>) {
typedef typename util::rm_ref<T>::type vtype;
typedef typename detail::implicit_conversions<vtype>::type converted;
return new detail::tuple_vals<converted>(std::forward<T>(value));
......@@ -234,23 +223,20 @@ class any_tuple
template<typename First, typename Second>
static inline any_tuple view(std::pair<First, Second> p,
std::integral_constant<bool, false>)
{
std::integral_constant<bool, false>) {
return new detail::tuple_vals<First, Second>(std::move(p.first),
std::move(p.second));
}
template<typename T>
static inline detail::abstract_tuple* container_view(T& value,
std::integral_constant<bool, true>)
{
std::integral_constant<bool, true>) {
return new detail::container_tuple_view<T>(&value);
}
template<typename T>
static inline detail::abstract_tuple* container_view(T&& value,
std::integral_constant<bool, false>)
{
std::integral_constant<bool, false>) {
typedef typename util::rm_ref<T>::type ctype;
return new detail::container_tuple_view<T>(new ctype(std::forward<T>(value)), true);
}
......@@ -260,22 +246,19 @@ class any_tuple
/**
* @relates any_tuple
*/
inline bool operator==(const any_tuple& lhs, const any_tuple& rhs)
{
inline bool operator==(const any_tuple& lhs, const any_tuple& rhs) {
return lhs.equals(rhs);
}
/**
* @relates any_tuple
*/
inline bool operator!=(const any_tuple& lhs, const any_tuple& rhs)
{
inline bool operator!=(const any_tuple& lhs, const any_tuple& rhs) {
return !(lhs == rhs);
}
template<typename... Args>
inline any_tuple make_any_tuple(Args&&... args)
{
inline any_tuple make_any_tuple(Args&&... args) {
return make_cow_tuple(std::forward<Args>(args)...);
}
......
......@@ -40,19 +40,16 @@ namespace cppa {
*/
struct anything { };
inline bool operator==(const anything&, const anything&)
{
inline bool operator==(const anything&, const anything&) {
return true;
}
inline bool operator!=(const anything&, const anything&)
{
inline bool operator!=(const anything&, const anything&) {
return false;
}
template<typename T>
struct is_anything
{
struct is_anything {
static constexpr bool value = std::is_same<T, anything>::value;
};
......
......@@ -45,8 +45,7 @@ std::string to_string(const atom_value& a);
* @brief Creates an atom from given string literal.
*/
template<size_t Size>
constexpr atom_value atom(char const (&str) [Size])
{
constexpr atom_value atom(char const (&str) [Size]) {
// last character is the NULL terminator
static_assert(Size <= 11, "only 10 characters are allowed");
return static_cast<atom_value>(detail::atom_val(str, 0xF));
......
......@@ -39,8 +39,7 @@ namespace cppa {
/**
* @brief Callback utility class.
*/
class attachable
{
class attachable {
attachable(const attachable&) = delete;
attachable& operator=(const attachable&) = delete;
......@@ -54,8 +53,7 @@ class attachable
/**
* @brief Represents a pointer to a value with its RTTI.
*/
struct token
{
struct token {
/**
* @brief Denotes the type of @c ptr.
*/
......@@ -65,8 +63,7 @@ class attachable
*/
void const* ptr;
inline token(const std::type_info& msubtype, void const* mptr)
: subtype(msubtype), ptr(mptr)
{
: subtype(msubtype), ptr(mptr) {
}
};
......
......@@ -49,8 +49,7 @@ namespace cppa {
/**
* @brief Describes the behavior of an actor.
*/
class behavior
{
class behavior {
friend behavior operator,(partial_function&& lhs, behavior&& rhs);
......@@ -62,53 +61,39 @@ class behavior
behavior() = default;
behavior(behavior&&) = default;
inline behavior(partial_function&& fun) : m_fun(std::move(fun))
{
inline behavior(partial_function&& fun) : m_fun(std::move(fun)) {
}
template<typename... Cases>
behavior(const match_expr<Cases...>& me) : m_fun(me) { }
inline behavior(util::duration tout, std::function<void()>&& handler)
: m_timeout(tout), m_timeout_handler(std::move(handler))
{
: m_timeout(tout), m_timeout_handler(std::move(handler)) {
}
behavior& operator=(behavior&&) = default;
//behavior& operator=(partial_function&& pfun)
//{
// m_fun = std::move(pfun);
// return *this;
//}
inline void handle_timeout() const
{
inline void handle_timeout() const {
m_timeout_handler();
}
inline const util::duration& timeout() const
{
inline const util::duration& timeout() const {
return m_timeout;
}
inline partial_function& get_partial_function()
{
inline partial_function& get_partial_function() {
return m_fun;
}
inline bool operator()(any_tuple& value)
{
inline bool operator()(any_tuple& value) {
return m_fun(value);
}
inline bool operator()(any_tuple const& value)
{
inline bool operator()(any_tuple const& value) {
return m_fun(value);
}
inline bool operator()(any_tuple&& value)
{
inline bool operator()(any_tuple&& value) {
return m_fun(std::move(value));
}
......@@ -125,21 +110,18 @@ class behavior
template<typename... Lhs>
behavior operator,(const match_expr<Lhs...>& lhs,
behavior&& rhs)
{
behavior&& rhs) {
rhs.get_partial_function() = lhs;
return std::move(rhs);
}
template<typename Arg0>
behavior bhvr_collapse(Arg0&& arg)
{
behavior bhvr_collapse(Arg0&& arg) {
return {std::forward<Arg0>(arg)};
}
template<typename Arg0, typename Arg1, typename... Args>
behavior bhvr_collapse(Arg0&& arg0, Arg1&& arg1, Args&&... args)
{
behavior bhvr_collapse(Arg0&& arg0, Arg1&& arg1, Args&&... args) {
return bhvr_collapse((std::forward<Arg0>(arg0), std::forward<Arg1>(arg1)),
std::forward<Args>(args)...);
}
......@@ -149,8 +131,7 @@ typename std::enable_if<
util::disjunction<std::is_same<behavior, Args>...>::value,
behavior
>::type
match_expr_concat(Args&&... args)
{
match_expr_concat(Args&&... args) {
return bhvr_collapse(std::forward<Args>(args)...);
}
......@@ -164,26 +145,22 @@ typename std::enable_if<
>::value == false,
partial_function
>::type
match_expr_concat(Args&&... args)
{
match_expr_concat(Args&&... args) {
return mexpr_concat_convert(std::forward<Args>(args)...);
}
inline partial_function match_expr_concat(partial_function&& pfun)
{
inline partial_function match_expr_concat(partial_function&& pfun) {
return std::move(pfun);
}
inline behavior match_expr_concat(behavior&& bhvr)
{
inline behavior match_expr_concat(behavior&& bhvr) {
return std::move(bhvr);
}
namespace detail {
template<typename... Ts>
struct select_bhvr
{
struct select_bhvr {
static constexpr bool timed =
util::disjunction<std::is_same<behavior, Ts>...>::value;
typedef typename util::if_else_c<timed,
......
......@@ -39,8 +39,7 @@ namespace cppa {
* @brief Implements the deserializer interface with
* a binary serialization protocol.
*/
class binary_deserializer : public deserializer
{
class binary_deserializer : public deserializer {
char const* pos;
char const* end;
......
......@@ -42,8 +42,7 @@ namespace detail { class binary_writer; }
* @brief Implements the serializer interface with
* a binary serialization protocol.
*/
class binary_serializer : public serializer
{
class binary_serializer : public serializer {
friend class detail::binary_writer;
......
......@@ -47,8 +47,7 @@ class any_tuple;
* This interface describes an entity that can receive messages
* and is implemented by {@link actor} and {@link group}.
*/
class channel : public ref_counted
{
class channel : public ref_counted {
friend class actor;
friend class group;
......
......@@ -88,8 +88,7 @@
#define CPPA_REQUIRE(unused) ((void) 0)
#endif // CPPA_DEBUG
#define CPPA_CRITICAL__(error, file, line) \
{ \
#define CPPA_CRITICAL__(error, file, line) { \
printf("%s:%u: critical error: '%s'\n", file, line, error); \
exit(7); \
} ((void) 0)
......
......@@ -46,8 +46,7 @@ namespace cppa {
* {@link ref_counted}.
*/
template<typename T>
class cow_ptr
{
class cow_ptr {
public:
......@@ -63,35 +62,29 @@ class cow_ptr
template<typename Y>
cow_ptr(const cow_ptr<Y>& other) : m_ptr(const_cast<Y*>(other.get())) { }
inline void swap(cow_ptr& other)
{
inline void swap(cow_ptr& other) {
m_ptr.swap(other.m_ptr);
}
cow_ptr& operator=(cow_ptr&& other)
{
cow_ptr& operator=(cow_ptr&& other) {
swap(other);
return *this;
}
cow_ptr& operator=(const cow_ptr& other)
{
cow_ptr& operator=(const cow_ptr& other) {
cow_ptr tmp{other};
swap(tmp);
return *this;
}
template<typename Y>
cow_ptr& operator=(const cow_ptr<Y>& other)
{
cow_ptr& operator=(const cow_ptr<Y>& other) {
cow_ptr tmp{other};
swap(tmp);
return *this;
}
void detach()
{
(void) detached_ptr();
void detach() { (void) detached_ptr();
}
inline void reset(T* value = nullptr) { m_ptr.reset(value); }
......@@ -114,11 +107,9 @@ class cow_ptr
intrusive_ptr<T> m_ptr;
T* detached_ptr()
{
T* detached_ptr() {
T* ptr = m_ptr.get();
if (!ptr->unique())
{
if (!ptr->unique()) {
//T* new_ptr = detail::copy_of(ptr, copy_of_token());
T* new_ptr = ptr->copy();
cow_ptr tmp(new_ptr);
......
......@@ -63,8 +63,7 @@ class local_actor;
* @brief A fixed-length copy-on-write cow_tuple.
*/
template<typename... ElementTypes>
class cow_tuple
{
class cow_tuple {
static_assert(sizeof...(ElementTypes) > 0, "tuple is empty");
......@@ -94,24 +93,21 @@ class cow_tuple
/**
* @brief Initializes each element with its default constructor.
*/
cow_tuple() : m_vals(new data_type)
{
cow_tuple() : m_vals(new data_type) {
}
/**
* @brief Initializes the cow_tuple with @p args.
* @param args Initialization values.
*/
cow_tuple(const ElementTypes&... args) : m_vals(new data_type(args...))
{
cow_tuple(const ElementTypes&... args) : m_vals(new data_type(args...)) {
}
/**
* @brief Initializes the cow_tuple with @p args.
* @param args Initialization values.
*/
cow_tuple(ElementTypes&&... args) : m_vals(new data_type(std::move(args)...))
{
cow_tuple(ElementTypes&&... args) : m_vals(new data_type(std::move(args)...)) {
}
cow_tuple(cow_tuple&&) = default;
......@@ -119,19 +115,16 @@ class cow_tuple
cow_tuple& operator=(cow_tuple&&) = default;
cow_tuple& operator=(const cow_tuple&) = default;
inline static cow_tuple from(cow_ptr_type ptr)
{
inline static cow_tuple from(cow_ptr_type ptr) {
return {priv_ctor{}, std::move(ptr)};
}
inline static cow_tuple from(cow_ptr_type ptr,
const util::fixed_vector<size_t, num_elements>& mv)
{
const util::fixed_vector<size_t, num_elements>& mv) {
return {priv_ctor{}, decorated_type::create(std::move(ptr), mv)};
}
inline static cow_tuple offset_subtuple(cow_ptr_type ptr, size_t offset)
{
inline static cow_tuple offset_subtuple(cow_ptr_type ptr, size_t offset) {
CPPA_REQUIRE(offset > 0);
return {priv_ctor{}, decorated_type::create(std::move(ptr), offset)};
}
......@@ -139,24 +132,21 @@ class cow_tuple
/**
* @brief Gets the size of this cow_tuple.
*/
inline size_t size() const
{
inline size_t size() const {
return sizeof...(ElementTypes);
}
/**
* @brief Gets a const pointer to the element at position @p p.
*/
inline void const* at(size_t p) const
{
inline void const* at(size_t p) const {
return m_vals->at(p);
}
/**
* @brief Gets a mutable pointer to the element at position @p p.
*/
inline void* mutable_at(size_t p)
{
inline void* mutable_at(size_t p) {
return m_vals->mutable_at(p);
}
......@@ -164,13 +154,11 @@ class cow_tuple
* @brief Gets {@link uniform_type_info uniform type information}
* of the element at position @p p.
*/
inline uniform_type_info const* type_at(size_t p) const
{
inline uniform_type_info const* type_at(size_t p) const {
return m_vals->type_at(p);
}
inline const cow_ptr<detail::abstract_tuple>& vals() const
{
inline const cow_ptr<detail::abstract_tuple>& vals() const {
return m_vals;
}
......@@ -180,8 +168,7 @@ template<typename TypeList>
struct cow_tuple_from_type_list;
template<typename... Types>
struct cow_tuple_from_type_list< util::type_list<Types...> >
{
struct cow_tuple_from_type_list< util::type_list<Types...> > {
typedef cow_tuple<Types...> type;
};
......@@ -223,23 +210,20 @@ cow_tuple<Args...> make_cow_tuple(Args&&... args);
#else
template<size_t N, typename... Types>
const typename util::at<N, Types...>::type& get(const cow_tuple<Types...>& tup)
{
const typename util::at<N, Types...>::type& get(const cow_tuple<Types...>& tup) {
typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type const*>(tup.at(N));
}
template<size_t N, typename... Types>
typename util::at<N, Types...>::type& get_ref(cow_tuple<Types...>& tup)
{
typename util::at<N, Types...>::type& get_ref(cow_tuple<Types...>& tup) {
typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type*>(tup.mutable_at(N));
}
template<typename... Args>
cow_tuple<typename detail::strip_and_convert<Args>::type...>
make_cow_tuple(Args&&... args)
{
make_cow_tuple(Args&&... args) {
return {std::forward<Args>(args)...};
}
......@@ -254,8 +238,7 @@ make_cow_tuple(Args&&... args)
*/
template<typename... LhsTypes, typename... RhsTypes>
inline bool operator==(const cow_tuple<LhsTypes...>& lhs,
const cow_tuple<RhsTypes...>& rhs)
{
const cow_tuple<RhsTypes...>& rhs) {
return util::compare_tuples(lhs, rhs);
}
......@@ -268,8 +251,7 @@ inline bool operator==(const cow_tuple<LhsTypes...>& lhs,
*/
template<typename... LhsTypes, typename... RhsTypes>
inline bool operator!=(const cow_tuple<LhsTypes...>& lhs,
const cow_tuple<RhsTypes...>& rhs)
{
const cow_tuple<RhsTypes...>& rhs) {
return !(lhs == rhs);
}
......
......@@ -473,8 +473,7 @@ void demonitor(actor_ptr& whom);
* @brief Spans a new context-switching actor.
* @returns A pointer to the spawned {@link actor Actor}.
*/
inline actor_ptr spawn(scheduled_actor* what)
{
inline actor_ptr spawn(scheduled_actor* what) {
return get_scheduler()->spawn(what);
}
......@@ -485,8 +484,7 @@ inline actor_ptr spawn(scheduled_actor* what)
* @returns A pointer to the spawned {@link actor Actor}.
*/
template<scheduling_hint Hint>
inline actor_ptr spawn(std::function<void()> what)
{
inline actor_ptr spawn(std::function<void()> what) {
return get_scheduler()->spawn(std::move(what), Hint);
}
......@@ -495,36 +493,31 @@ inline actor_ptr spawn(std::function<void()> what)
* @brief Spans a new event-based actor.
* @returns A pointer to the spawned {@link actor Actor}.
*/
inline actor_ptr spawn(std::function<void()> what)
{
inline actor_ptr spawn(std::function<void()> what) {
return get_scheduler()->spawn(std::move(what), scheduled);
}
template<typename T>
struct spawn_fwd_
{
struct spawn_fwd_ {
static inline T&& _(T&& arg) { return std::move(arg); }
static inline T& _(T& arg) { return arg; }
static inline T const& _(T const& arg) { return arg; }
};
template<>
struct spawn_fwd_<self_type>
{
struct spawn_fwd_<self_type> {
static inline actor_ptr _(self_type const&) { return self; }
};
template<typename F, typename Arg0, typename... Args>
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args)
{
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
return spawn(std::bind(std::move(what),
spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0),
spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...));
}
template<scheduling_hint Hint, typename F, typename Arg0, typename... Args>
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args)
{
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
return spawn<Hint>(std::bind(std::move(what),
spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0),
spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...));
......@@ -546,8 +539,7 @@ spawn(F&& what, const Args&... args)
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type
{
>::type {
typedef typename util::rm_ref<F>::type ftype;
std::integral_constant<bool, std::is_function<ftype>::value> is_fun;
auto ptr = detail::get_behavior(is_fun, std::forward<F>(what), args...);
......@@ -565,8 +557,7 @@ spawn(F&& what, const Args&... args)
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type
{
>::type {
return spawn<scheduled>(std::forward<F>(what), args...);
}
*/
......@@ -595,15 +586,13 @@ channel_ptr& operator<<(channel_ptr& whom, const any_tuple& what);
#else
template<class C, typename Arg0, typename... Args>
void send(intrusive_ptr<C>& whom, const Arg0& arg0, const Args&... args)
{
void send(intrusive_ptr<C>& whom, const Arg0& arg0, const Args&... args) {
static_assert(std::is_base_of<channel, C>::value, "C is not a channel");
if (whom) self->send_message(whom.get(), make_cow_tuple(arg0, args...));
}
template<class C, typename Arg0, typename... Args>
void send(intrusive_ptr<C>&& whom, const Arg0& arg0, const Args&... args)
{
void send(intrusive_ptr<C>&& whom, const Arg0& arg0, const Args&... args) {
static_assert(std::is_base_of<channel, C>::value, "C is not a channel");
intrusive_ptr<C> tmp(std::move(whom));
send(tmp, arg0, args...);
......@@ -611,8 +600,7 @@ void send(intrusive_ptr<C>&& whom, const Arg0& arg0, const Args&... args)
// matches "send(this, ...)" in event-based actors
template<typename Arg0, typename... Args>
inline void send(local_actor* whom, const Arg0& arg0, const Args&... args)
{
inline void send(local_actor* whom, const Arg0& arg0, const Args&... args) {
CPPA_REQUIRE(whom != nullptr);
whom->enqueue(whom, make_cow_tuple(arg0, args...));
}
......@@ -620,8 +608,7 @@ inline void send(local_actor* whom, const Arg0& arg0, const Args&... args)
// matches send(self, ...);
template<typename Arg0, typename... Args>
inline void send(const self_type&, const Arg0& arg0, const Args&... args)
{
inline void send(const self_type&, const Arg0& arg0, const Args&... args) {
send(static_cast<local_actor*>(self), arg0, args...);
}
......@@ -630,8 +617,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value,
intrusive_ptr<C>&
>::type
operator<<(intrusive_ptr<C>& whom, const any_tuple& what)
{
operator<<(intrusive_ptr<C>& whom, const any_tuple& what) {
if (whom) self->send_message(whom.get(), what);
return whom;
}
......@@ -641,8 +627,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value,
intrusive_ptr<C>
>::type
operator<<(intrusive_ptr<C>&& whom, const any_tuple& what)
{
operator<<(intrusive_ptr<C>&& whom, const any_tuple& what) {
intrusive_ptr<C> tmp(std::move(whom));
tmp << what;
return std::move(tmp);
......@@ -653,8 +638,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value,
intrusive_ptr<C>&
>::type
operator<<(intrusive_ptr<C>& whom, any_tuple&& what)
{
operator<<(intrusive_ptr<C>& whom, any_tuple&& what) {
if (whom) self->send_message(whom.get(), std::move(what));
return whom;
}
......@@ -664,8 +648,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value,
intrusive_ptr<C>
>::type
operator<<(intrusive_ptr<C>&& whom, any_tuple&& what)
{
operator<<(intrusive_ptr<C>&& whom, any_tuple&& what) {
intrusive_ptr<C> tmp(std::move(whom));
tmp << std::move(what);
return std::move(tmp);
......@@ -682,8 +665,7 @@ const self_type& operator<<(const self_type& s, any_tuple&& what);
* @brief Sends a message to the sender of the last received message.
*/
template<typename Arg0, typename... Args>
void reply(const Arg0& arg0, const Args&... args)
{
void reply(const Arg0& arg0, const Args&... args) {
send(self->last_sender(), arg0, args...);
}
......@@ -695,8 +677,7 @@ void reply(const Arg0& arg0, const Args&... args)
* @param data Any number of values for the message content.
*/
template<typename Duration, typename... Data>
void future_send(actor_ptr whom, const Duration& rel_time, const Data&... data)
{
void future_send(actor_ptr whom, const Duration& rel_time, const Data&... data) {
get_scheduler()->future_send(whom, rel_time, data...);
}
......@@ -706,8 +687,7 @@ void future_send(actor_ptr whom, const Duration& rel_time, const Data&... data)
* @see future_send()
*/
template<typename Duration, typename... Data>
void delayed_reply(const Duration& rel_time, Data const... data)
{
void delayed_reply(const Duration& rel_time, Data const... data) {
future_send(self->last_sender(), rel_time, data...);
}
......@@ -717,8 +697,7 @@ void delayed_reply(const Duration& rel_time, Data const... data)
* @warning This function will cause a deadlock if
* called from multiple actors.
*/
inline void await_all_others_done()
{
inline void await_all_others_done() {
detail::actor_count_wait_until((self.unchecked() == nullptr) ? 0 : 1);
}
......
......@@ -45,8 +45,7 @@ class object;
* @ingroup TypeSystem
* @brief Technology-independent deserialization interface.
*/
class deserializer
{
class deserializer {
deserializer(const deserializer&) = delete;
deserializer& operator=(const deserializer&) = delete;
......
......@@ -50,8 +50,7 @@
namespace cppa { namespace detail {
// A spawned, scheduled Actor.
class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
{
class abstract_scheduled_actor : public abstract_actor<scheduled_actor> {
typedef abstract_actor<scheduled_actor> super;
......@@ -59,28 +58,22 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
std::atomic<int> m_state;
filter_result filter_msg(any_tuple const& msg)
{
filter_result filter_msg(any_tuple const& msg) {
auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr;
if ( msg.size() == 2
&& msg.type_at(0) == arr[0]
&& msg.type_at(1) == arr[1])
{
&& msg.type_at(1) == arr[1]) {
auto v0 = *reinterpret_cast<const atom_value*>(msg.at(0));
auto v1 = *reinterpret_cast<const std::uint32_t*>(msg.at(1));
if (v0 == atom("EXIT"))
{
if (this->m_trap_exit == false)
{
if (v1 != exit_reason::normal)
{
if (v0 == atom("EXIT")) {
if (this->m_trap_exit == false) {
if (v1 != exit_reason::normal) {
quit(v1);
}
return normal_exit_signal;
}
}
else if (v0 == atom(":Timeout"))
{
else if (v0 == atom(":Timeout")) {
return (v1 == m_active_timeout_id) ? timeout_message
: expired_timeout_message;
}
......@@ -88,24 +81,19 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
return ordinary_message;
}
bool has_pending_timeout()
{
bool has_pending_timeout() {
return m_has_pending_timeout_request;
}
void request_timeout(const util::duration& d)
{
if (d.valid())
{
void request_timeout(const util::duration& d) {
if (d.valid()) {
get_scheduler()->future_send(this, d, atom(":Timeout"), ++m_active_timeout_id);
m_has_pending_timeout_request = true;
}
}
void reset_timeout()
{
if (m_has_pending_timeout_request)
{
void reset_timeout() {
if (m_has_pending_timeout_request) {
++m_active_timeout_id;
m_has_pending_timeout_request = false;
}
......@@ -125,33 +113,26 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
abstract_scheduled_actor(int state = done)
: super(true), m_state(state)
, m_has_pending_timeout_request(false)
, m_active_timeout_id(0)
{
, m_active_timeout_id(0) {
}
bool pending_enqueue(actor* sender, any_tuple msg)
{
bool pending_enqueue(actor* sender, any_tuple msg) {
return enqueue_node(super::fetch_node(sender, std::move(msg)), pending);
}
void quit(std::uint32_t reason)
{
void quit(std::uint32_t reason) {
this->cleanup(reason);
throw actor_exited(reason);
}
void enqueue(actor* sender, any_tuple msg)
{
void enqueue(actor* sender, any_tuple msg) {
enqueue_node(super::fetch_node(sender, std::move(msg)));
}
int compare_exchange_state(int expected, int new_value)
{
int compare_exchange_state(int expected, int new_value) {
int e = expected;
do
{
if (m_state.compare_exchange_weak(e, new_value))
{
do {
if (m_state.compare_exchange_weak(e, new_value)) {
return new_value;
}
}
......@@ -162,33 +143,24 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
private:
bool enqueue_node(typename super::mailbox_element* node,
int target_state = ready)
{
int target_state = ready) {
CPPA_REQUIRE(node->marked == false);
if (this->m_mailbox._push_back(node))
{
for (;;)
{
if (this->m_mailbox._push_back(node)) {
for (;;) {
int state = m_state.load();
switch (state)
{
case blocked:
{
if (m_state.compare_exchange_weak(state, target_state))
{
switch (state) {
case blocked: {
if (m_state.compare_exchange_weak(state, target_state)) {
CPPA_REQUIRE(this->m_scheduler != nullptr);
if (target_state == ready)
{
if (target_state == ready) {
this->m_scheduler->enqueue(this);
}
return true;
}
break;
}
case about_to_block:
{
if (m_state.compare_exchange_weak(state, ready))
{
case about_to_block: {
if (m_state.compare_exchange_weak(state, ready)) {
return false;
}
break;
......
......@@ -44,14 +44,12 @@
namespace cppa { namespace detail {
enum tuple_impl_info
{
enum tuple_impl_info {
statically_typed,
dynamically_typed
};
class abstract_tuple : public ref_counted
{
class abstract_tuple : public ref_counted {
tuple_impl_info m_impl_type;
......@@ -97,31 +95,26 @@ class abstract_tuple : public ref_counted
};
struct full_eq_type
{
struct full_eq_type {
constexpr full_eq_type() { }
template<class Tuple>
inline bool operator()(const tuple_iterator<Tuple>& lhs,
const tuple_iterator<Tuple>& rhs) const
{
const tuple_iterator<Tuple>& rhs) const {
return lhs.type() == rhs.type()
&& lhs.type()->equals(lhs.value(), rhs.value());
}
};
struct types_only_eq_type
{
struct types_only_eq_type {
constexpr types_only_eq_type() { }
template<class Tuple>
inline bool operator()(const tuple_iterator<Tuple>& lhs,
uniform_type_info const* rhs ) const
{
uniform_type_info const* rhs ) const {
return lhs.type() == rhs;
}
template<class Tuple>
inline bool operator()(uniform_type_info const* lhs,
const tuple_iterator<Tuple>& rhs) const
{
const tuple_iterator<Tuple>& rhs) const {
return lhs == rhs.type();
}
};
......
......@@ -45,8 +45,7 @@
namespace cppa { namespace detail {
class actor_proxy_cache
{
class actor_proxy_cache {
public:
......@@ -59,19 +58,15 @@ class actor_proxy_cache
template<typename Fun>
void erase_all(process_information::node_id_type const& nid,
std::uint32_t process_id,
Fun fun)
{
Fun fun) {
key_tuple lb{nid, process_id, std::numeric_limits<actor_id>::min()};
key_tuple ub{nid, process_id, std::numeric_limits<actor_id>::max()};
{
key_tuple ub{nid, process_id, std::numeric_limits<actor_id>::max()}; {
lock_guard<util::shared_spinlock> guard{m_lock};
auto e = m_entries.end();
auto first = m_entries.lower_bound(lb);
if (first != e)
{
if (first != e) {
auto last = m_entries.upper_bound(ub);
for (auto i = first; i != last; ++i)
{
for (auto i = first; i != last; ++i) {
fun(i->second);
}
m_entries.erase(first, last);
......@@ -86,8 +81,7 @@ class actor_proxy_cache
actor_id> // (remote) actor id
key_tuple;
struct key_tuple_less
{
struct key_tuple_less {
bool operator()(key_tuple const& lhs, key_tuple const& rhs) const;
};
......
......@@ -42,8 +42,7 @@
namespace cppa { namespace detail {
class actor_registry
{
class actor_registry {
public:
......
......@@ -40,8 +40,7 @@
namespace cppa { namespace detail {
class addressed_message
{
class addressed_message {
public:
......@@ -53,38 +52,31 @@ class addressed_message
addressed_message& operator=(addressed_message&&) = default;
addressed_message& operator=(const addressed_message&) = default;
inline actor_ptr& sender()
{
inline actor_ptr& sender() {
return m_sender;
}
inline const actor_ptr& sender() const
{
inline const actor_ptr& sender() const {
return m_sender;
}
inline channel_ptr& receiver()
{
inline channel_ptr& receiver() {
return m_receiver;
}
inline const channel_ptr& receiver() const
{
inline const channel_ptr& receiver() const {
return m_receiver;
}
inline any_tuple& content()
{
inline any_tuple& content() {
return m_content;
}
inline const any_tuple& content() const
{
inline const any_tuple& content() const {
return m_content;
}
inline bool empty() const
{
inline bool empty() const {
return m_content.empty();
}
......@@ -98,8 +90,7 @@ class addressed_message
bool operator==(const addressed_message& lhs, const addressed_message& rhs);
inline bool operator!=(const addressed_message& lhs, const addressed_message& rhs)
{
inline bool operator!=(const addressed_message& lhs, const addressed_message& rhs) {
return !(lhs == rhs);
}
......
......@@ -34,8 +34,7 @@
namespace cppa { namespace detail { namespace {
// encodes ASCII characters to 6bit encoding
constexpr char encoding_table[] =
{
constexpr char encoding_table[] = {
/* ..0 ..1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..A ..B ..C ..D ..E ..F */
/* 0.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 1.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
......@@ -52,13 +51,11 @@ constexpr char decoding_table[] = " 0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
"abcdefghijklmnopqrstuvwxyz";
constexpr std::uint64_t next_interim(std::uint64_t current, size_t char_code)
{
constexpr std::uint64_t next_interim(std::uint64_t current, size_t char_code) {
return (current << 6) | encoding_table[(char_code <= 0x7F) ? char_code : 0];
}
constexpr std::uint64_t atom_val(char const* cstr, std::uint64_t interim = 0)
{
constexpr std::uint64_t atom_val(char const* cstr, std::uint64_t interim = 0) {
return (*cstr == '\0') ? interim
: atom_val(cstr + 1,
next_interim(interim,
......
......@@ -37,50 +37,42 @@
namespace cppa { namespace detail {
template<typename T>
struct boxed
{
struct boxed {
typedef util::wrapped<T> type;
};
template<typename T>
struct boxed< util::wrapped<T> >
{
struct boxed< util::wrapped<T> > {
typedef util::wrapped<T> type;
};
template<>
struct boxed<anything>
{
struct boxed<anything> {
typedef anything type;
};
template<typename T>
struct is_boxed
{
struct is_boxed {
static constexpr bool value = false;
};
template<typename T>
struct is_boxed< util::wrapped<T> >
{
struct is_boxed< util::wrapped<T> > {
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>()>
{
struct is_boxed<util::wrapped<T>()> {
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(&)()>
{
struct is_boxed<util::wrapped<T>(&)()> {
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(*)()>
{
struct is_boxed<util::wrapped<T>(*)()> {
static constexpr bool value = true;
};
......
......@@ -41,8 +41,7 @@
namespace cppa { namespace detail {
template<size_t ChunkSize, size_t MaxBufferSize, typename DataType = char>
class buffer
{
class buffer {
DataType* m_data;
size_t m_written;
......@@ -50,33 +49,25 @@ class buffer
size_t m_final_size;
template<typename F>
bool append_impl(F&& fun, bool throw_on_error)
{
bool append_impl(F&& fun, bool throw_on_error) {
auto recv_result = fun();
if (recv_result == 0)
{
if (recv_result == 0) {
// connection closed
if (throw_on_error)
{
if (throw_on_error) {
std::ios_base::failure("cannot read from a closed pipe/socket");
}
return false;
}
else if (recv_result < 0)
{
switch (errno)
{
case EAGAIN:
{
else if (recv_result < 0) {
switch (errno) {
case EAGAIN: {
// rdflags or sfd is set to non-blocking,
// this is not treated as error
return true;
}
default:
{
default: {
// a "real" error occured;
if (throw_on_error)
{
if (throw_on_error) {
char* cstr = strerror(errno);
std::string errmsg = cstr;
free(cstr);
......@@ -92,45 +83,36 @@ class buffer
public:
buffer() : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0)
{
buffer() : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) {
}
buffer(buffer&& other)
: m_data(other.m_data), m_written(other.m_written)
, m_allocated(other.m_allocated), m_final_size(other.m_final_size)
{
, m_allocated(other.m_allocated), m_final_size(other.m_final_size) {
other.m_data = nullptr;
other.m_written = other.m_allocated = other.m_final_size = 0;
}
~buffer()
{
~buffer() {
delete[] m_data;
}
void clear()
{
void clear() {
m_written = 0;
}
void reset(size_t new_final_size = 0)
{
void reset(size_t new_final_size = 0) {
m_written = 0;
m_final_size = new_final_size;
if (new_final_size > m_allocated)
{
if (new_final_size > MaxBufferSize)
{
if (new_final_size > m_allocated) {
if (new_final_size > MaxBufferSize) {
throw std::ios_base::failure("maximum buffer size exceeded");
}
auto remainder = (new_final_size % ChunkSize);
if (remainder == 0)
{
if (remainder == 0) {
m_allocated = new_final_size;
}
else
{
else {
m_allocated = (new_final_size - remainder) + ChunkSize;
}
delete[] m_data;
......@@ -138,51 +120,41 @@ class buffer
}
}
bool ready()
{
bool ready() {
return m_written == m_final_size;
}
// pointer to the current write position
DataType* wr_ptr()
{
DataType* wr_ptr() {
return m_data + m_written;
}
size_t size()
{
size_t size() {
return m_written;
}
size_t final_size()
{
size_t final_size() {
return m_final_size;
}
size_t remaining()
{
size_t remaining() {
return m_final_size - m_written;
}
void inc_written(size_t value)
{
void inc_written(size_t value) {
m_written += value;
}
DataType* data()
{
DataType* data() {
return m_data;
}
inline bool full()
{
inline bool full() {
return remaining() == 0;
}
bool append_from_file_descriptor(int fd, bool throw_on_error = false)
{
auto fun = [=]() -> int
{
bool append_from_file_descriptor(int fd, bool throw_on_error = false) {
auto fun = [=]() -> int {
return ::read(fd, this->wr_ptr(), this->remaining());
};
return append_impl(fun, throw_on_error);
......@@ -190,10 +162,8 @@ class buffer
bool append_from(native_socket_type sfd,
int rdflags = 0,
bool throw_on_error = false)
{
auto fun = [=]() -> int
{
bool throw_on_error = false) {
auto fun = [=]() -> int {
return ::recv(sfd, this->wr_ptr(), this->remaining(), rdflags);
};
return append_impl(fun, throw_on_error);
......
......@@ -38,8 +38,7 @@ namespace cppa { class message; }
namespace cppa { namespace detail {
// public part of the actor interface
struct channel : ref_counted
{
struct channel : ref_counted {
virtual void enqueue_msg(const message& msg) = 0;
};
......
......@@ -41,8 +41,7 @@
namespace cppa { namespace detail {
template<class Container>
class container_tuple_view : public abstract_tuple
{
class container_tuple_view : public abstract_tuple {
typedef abstract_tuple super;
......@@ -51,40 +50,34 @@ class container_tuple_view : public abstract_tuple
typedef typename Container::value_type value_type;
container_tuple_view(Container* c, bool take_ownership = false)
: super(tuple_impl_info::dynamically_typed), m_ptr(c)
{
: super(tuple_impl_info::dynamically_typed), m_ptr(c) {
CPPA_REQUIRE(c != nullptr);
if (!take_ownership) m_ptr.get_deleter().disable();
}
size_t size() const
{
size_t size() const {
return m_ptr->size();
}
abstract_tuple* copy() const
{
abstract_tuple* copy() const {
return new container_tuple_view{new Container(*m_ptr), true};
}
void const* at(size_t pos) const
{
void const* at(size_t pos) const {
CPPA_REQUIRE(pos < size());
auto i = m_ptr->begin();
std::advance(i, pos);
return &(*i);
}
void* mutable_at(size_t pos)
{
void* mutable_at(size_t pos) {
CPPA_REQUIRE(pos < size());
auto i = m_ptr->begin();
std::advance(i, pos);
return &(*i);
}
uniform_type_info const* type_at(size_t) const
{
uniform_type_info const* type_at(size_t) const {
return static_types_array<value_type>::arr[0];
}
......
......@@ -58,8 +58,7 @@ namespace cppa { namespace detail {
*/
class converted_thread_context
: public nestable_receive_actor<converted_thread_context,
abstract_actor<local_actor> >
{
abstract_actor<local_actor> > {
typedef nestable_receive_actor<converted_thread_context,
abstract_actor<local_actor> >
......
......@@ -50,8 +50,7 @@
namespace cppa { namespace detail {
template<typename... ElementTypes>
class decorated_tuple : public abstract_tuple
{
class decorated_tuple : public abstract_tuple {
typedef abstract_tuple super;
......@@ -65,47 +64,39 @@ class decorated_tuple : public abstract_tuple
typedef cow_ptr<abstract_tuple> cow_pointer_type;
static inline cow_pointer_type create(cow_pointer_type d,
const vector_type& v)
{
const vector_type& v) {
return cow_pointer_type{new decorated_tuple(std::move(d), v)};
}
// creates a subtuple form @p d with an offset
static inline cow_pointer_type create(cow_pointer_type d, size_t offset)
{
static inline cow_pointer_type create(cow_pointer_type d, size_t offset) {
return cow_pointer_type{new decorated_tuple(std::move(d), offset)};
}
virtual void* mutable_at(size_t pos)
{
virtual void* mutable_at(size_t pos) {
CPPA_REQUIRE(pos < size());
return m_decorated->mutable_at(m_mapping[pos]);
}
virtual size_t size() const
{
virtual size_t size() const {
return sizeof...(ElementTypes);
}
virtual decorated_tuple* copy() const
{
virtual decorated_tuple* copy() const {
return new decorated_tuple(*this);
}
virtual void const* at(size_t pos) const
{
virtual void const* at(size_t pos) const {
CPPA_REQUIRE(pos < size());
return m_decorated->at(m_mapping[pos]);
}
virtual uniform_type_info const* type_at(size_t pos) const
{
virtual uniform_type_info const* type_at(size_t pos) const {
CPPA_REQUIRE(pos < size());
return m_decorated->type_at(m_mapping[pos]);
}
std::type_info const* type_token() const
{
std::type_info const* type_token() const {
return static_type_list<ElementTypes...>::list;
}
......@@ -116,8 +107,7 @@ class decorated_tuple : public abstract_tuple
decorated_tuple(cow_pointer_type d, const vector_type& v)
: super(tuple_impl_info::statically_typed)
, m_decorated(std::move(d)), m_mapping(v)
{
, m_decorated(std::move(d)), m_mapping(v) {
# ifdef CPPA_DEBUG
const cow_pointer_type& ptr = m_decorated; // prevent detaching
# endif
......@@ -127,8 +117,7 @@ class decorated_tuple : public abstract_tuple
}
decorated_tuple(cow_pointer_type d, size_t offset)
: super(tuple_impl_info::statically_typed), m_decorated(std::move(d))
{
: super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) {
# ifdef CPPA_DEBUG
const cow_pointer_type& ptr = m_decorated; // prevent detaching
# endif
......@@ -149,8 +138,7 @@ template<typename TypeList>
struct decorated_cow_tuple_from_type_list;
template<typename... Types>
struct decorated_cow_tuple_from_type_list< util::type_list<Types...> >
{
struct decorated_cow_tuple_from_type_list< util::type_list<Types...> > {
typedef decorated_tuple<Types...> type;
};
......
......@@ -34,8 +34,7 @@
namespace cppa { namespace detail {
template<typename T>
class disablable_delete
{
class disablable_delete {
bool m_enabled;
......@@ -45,8 +44,7 @@ class disablable_delete
inline void disable() { m_enabled = false; }
inline void operator()(T* ptr)
{
inline void operator()(T* ptr) {
if (m_enabled) delete ptr;
}
......
......@@ -35,8 +35,7 @@
namespace cppa { namespace detail {
struct empty_tuple : abstract_tuple
{
struct empty_tuple : abstract_tuple {
using abstract_tuple::const_iterator;
......
......@@ -33,8 +33,7 @@
namespace cppa { namespace detail {
enum filter_result
{
enum filter_result {
normal_exit_signal,
expired_timeout_message,
timeout_message,
......
......@@ -43,8 +43,7 @@ namespace cppa { namespace detail {
// default: <true, false, F>
template<bool IsFunctionPtr, bool HasArguments, typename F, typename... Args>
class ftor_behavior : public scheduled_actor
{
class ftor_behavior : public scheduled_actor {
F m_fun;
......@@ -57,8 +56,7 @@ class ftor_behavior : public scheduled_actor
};
template<typename F, typename... Args>
class ftor_behavior<true, true, F, Args...> : public scheduled_actor
{
class ftor_behavior<true, true, F, Args...> : public scheduled_actor {
static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0");
......@@ -80,8 +78,7 @@ class ftor_behavior<true, true, F, Args...> : public scheduled_actor
};
template<typename F>
class ftor_behavior<false, false, F> : public scheduled_actor
{
class ftor_behavior<false, false, F> : public scheduled_actor {
F m_fun;
......@@ -96,8 +93,7 @@ class ftor_behavior<false, false, F> : public scheduled_actor
};
template<typename F, typename... Args>
class ftor_behavior<false, true, F, Args...> : public scheduled_actor
{
class ftor_behavior<false, true, F, Args...> : public scheduled_actor {
static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0");
......@@ -112,13 +108,11 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor
public:
ftor_behavior(const F& f, const Args&... args) : m_fun(f), m_args(args...)
{
ftor_behavior(const F& f, const Args&... args) : m_fun(f), m_args(args...) {
}
ftor_behavior(F&& f,const Args&... args) : m_fun(std::move(f))
, m_args(args...)
{
, m_args(args...) {
}
virtual void act() { util::apply_tuple(m_fun, m_args); }
......@@ -126,8 +120,7 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor
};
template<typename R>
scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)())
{
scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)()) {
static_assert(std::is_convertible<R, scheduled_actor*>::value == false,
"Spawning a function returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior "
......@@ -136,8 +129,7 @@ scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)())
}
template<typename F>
scheduled_actor* get_behavior(std::integral_constant<bool,false>, F&& ftor)
{
scheduled_actor* get_behavior(std::integral_constant<bool,false>, F&& ftor) {
static_assert(std::is_convertible<decltype(ftor()), scheduled_actor*>::value == false,
"Spawning a functor returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior "
......@@ -150,8 +142,7 @@ template<typename F, typename Arg0, typename... Args>
scheduled_actor* get_behavior(std::integral_constant<bool,true>,
F fptr,
const Arg0& arg0,
const Args&... args)
{
const Args&... args) {
static_assert(std::is_convertible<decltype(fptr(arg0, args...)), scheduled_actor*>::value == false,
"Spawning a function returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior "
......@@ -164,8 +155,7 @@ template<typename F, typename Arg0, typename... Args>
scheduled_actor* get_behavior(std::integral_constant<bool,false>,
F ftor,
const Arg0& arg0,
const Args&... args)
{
const Args&... args) {
static_assert(std::is_convertible<decltype(ftor(arg0, args...)), scheduled_actor*>::value == false,
"Spawning a functor returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior "
......
......@@ -39,8 +39,7 @@
namespace cppa { namespace detail {
class group_manager
{
class group_manager {
public:
......
......@@ -46,8 +46,7 @@ namespace cppa { class local_actor; }
namespace cppa { namespace detail {
template<typename T>
struct implicit_conversions
{
struct implicit_conversions {
typedef typename util::replace_type<T, std::string,
std::is_same<T, char const*>,
std::is_same<T, char*>,
......@@ -76,8 +75,7 @@ struct implicit_conversions
};
template<typename T>
struct strip_and_convert
{
struct strip_and_convert {
typedef typename implicit_conversions<typename util::rm_ref<T>::type>::type
type;
};
......
......@@ -48,8 +48,7 @@
namespace cppa { namespace detail {
class invokable
{
class invokable {
invokable(const invokable&) = delete;
invokable& operator=(const invokable&) = delete;
......@@ -73,72 +72,59 @@ class invokable
};
enum mapping_policy
{
enum mapping_policy {
do_not_map,
map_to_bool,
map_to_option
};
template<mapping_policy, class Pattern> // do_not_map
struct pattern_policy
{
struct pattern_policy {
Pattern m_pattern;
template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(const any_tuple& value) const
{
bool types_match(const any_tuple& value) const {
return matches_types(value, m_pattern);
}
bool could_invoke(const any_tuple& value) const
{
bool could_invoke(const any_tuple& value) const {
return matches(value, m_pattern);
}
template<typename Fun>
bool call(const Fun& fun, any_tuple& value) const
{
bool call(const Fun& fun, any_tuple& value) const {
fun(value);
return true;
}
template<typename Fun>
bool call_unsafe(const Fun& fun, any_tuple& value) const
{
bool call_unsafe(const Fun& fun, any_tuple& value) const {
fun(value);
return true;
}
};
template<class Pattern>
struct pattern_policy<map_to_option, Pattern>
{
struct pattern_policy<map_to_option, Pattern> {
Pattern m_pattern;
template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(const any_tuple& value) const
{
bool types_match(const any_tuple& value) const {
return matches_types(value, m_pattern);
}
bool could_invoke(const any_tuple& value) const
{
bool could_invoke(const any_tuple& value) const {
return matches(value, m_pattern);
}
template<typename Fun>
bool call(const Fun& fun, any_tuple& value) const
{
bool call(const Fun& fun, any_tuple& value) const {
auto result = moving_tuple_cast(value, m_pattern);
if (result)
{
if (result) {
util::apply_tuple(fun, *result);
return true;
}
return false;
}
template<typename Fun>
bool call_unsafe(const Fun& fun, any_tuple& value) const
{
bool call_unsafe(const Fun& fun, any_tuple& value) const {
auto result = unsafe_tuple_cast(value, m_pattern);
if (result)
{
if (result) {
util::apply_tuple(fun, *result);
return true;
}
......@@ -147,34 +133,27 @@ struct pattern_policy<map_to_option, Pattern>
};
template<class Pattern>
struct pattern_policy<map_to_bool, Pattern>
{
struct pattern_policy<map_to_bool, Pattern> {
Pattern m_pattern;
template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(const any_tuple& value) const
{
bool types_match(const any_tuple& value) const {
return matches_types(value, m_pattern);
}
bool could_invoke(const any_tuple& value) const
{
bool could_invoke(const any_tuple& value) const {
return matches(value, m_pattern);
}
template<typename Fun>
bool call(const Fun& fun, any_tuple& value) const
{
if (could_invoke(value))
{
bool call(const Fun& fun, any_tuple& value) const {
if (could_invoke(value)) {
fun();
return true;
}
return false;
}
template<typename Fun>
bool call_unsafe(const Fun& fun, any_tuple& value) const
{
if (could_invoke(value))
{
bool call_unsafe(const Fun& fun, any_tuple& value) const {
if (could_invoke(value)) {
fun();
return true;
}
......@@ -182,33 +161,27 @@ struct pattern_policy<map_to_bool, Pattern>
}
};
struct dummy_policy
{
inline bool types_match(const any_tuple&) const
{
struct dummy_policy {
inline bool types_match(const any_tuple&) const {
return true;
}
inline bool could_invoke(const any_tuple&) const
{
inline bool could_invoke(const any_tuple&) const {
return true;
}
template<typename Fun>
inline bool call(const Fun& fun, any_tuple&) const
{
inline bool call(const Fun& fun, any_tuple&) const {
fun();
return true;
}
template<typename Fun>
inline bool call_unsafe(const Fun& fun, any_tuple&) const
{
inline bool call_unsafe(const Fun& fun, any_tuple&) const {
fun();
return true;
}
};
template<typename Fun, class Policy>
struct invokable_impl : public invokable
{
struct invokable_impl : public invokable {
Fun m_fun;
Policy m_policy;
......@@ -216,35 +189,29 @@ struct invokable_impl : public invokable
template<typename Arg0, typename... Args>
invokable_impl(Arg0&& arg0, Args&&... args)
: m_fun(std::forward<Arg0>(arg0))
, m_policy(std::forward<Args>(args)...)
{
, m_policy(std::forward<Args>(args)...) {
}
bool invoke(any_tuple& value) const
{
bool invoke(any_tuple& value) const {
return m_policy.call(m_fun, value);
}
bool unsafe_invoke(any_tuple& value) const
{
bool unsafe_invoke(any_tuple& value) const {
return m_policy.call_unsafe(m_fun, value);
}
bool types_match(const any_tuple& value) const
{
bool types_match(const any_tuple& value) const {
return m_policy.types_match(value);
}
bool could_invoke(const any_tuple& value) const
{
bool could_invoke(const any_tuple& value) const {
return m_policy.could_invoke(value);
}
};
template<class ArgTypes>
constexpr mapping_policy get_mapping_policy()
{
constexpr mapping_policy get_mapping_policy() {
return (ArgTypes::size == 0)
? map_to_bool
: (( std::is_same<typename ArgTypes::head, any_tuple>::value
......@@ -257,22 +224,19 @@ template<class Container>
struct filtered;
template<typename... Ts>
struct filtered<util::type_list<Ts...> >
{
struct filtered<util::type_list<Ts...> > {
typedef typename util::tl_filter_not<util::type_list<Ts...>, is_anything>::type
types;
};
template<typename... Ts>
struct filtered<pattern<Ts...> >
{
struct filtered<pattern<Ts...> > {
typedef typename filtered<util::type_list<Ts...>>::types types;
};
template<typename Fun, class Pattern>
struct select_invokable_impl
{
struct select_invokable_impl {
typedef typename util::get_arg_types<Fun>::types qualified_arg_types;
typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type
arg_types;
......@@ -281,8 +245,7 @@ struct select_invokable_impl
};
template<typename Fun>
struct select_invokable_impl<Fun, pattern<anything> >
{
struct select_invokable_impl<Fun, pattern<anything> > {
typedef typename util::get_arg_types<Fun>::types qualified_arg_types;
typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type
arg_types;
......@@ -296,11 +259,9 @@ struct select_invokable_impl<Fun, pattern<anything> >
template<class Pattern, typename Fun>
std::unique_ptr<invokable> get_invokable_impl(Fun&& fun,
std::unique_ptr<value_matcher>&& vm)
{
std::unique_ptr<value_matcher>&& vm) {
typedef std::unique_ptr<invokable> result;
if (vm)
{
if (vm) {
typedef typename select_invokable_impl<Fun, Pattern>::type impl1;
return result{new impl1{std::forward<Fun>(fun), std::move(vm)}};
}
......@@ -310,8 +271,7 @@ std::unique_ptr<invokable> get_invokable_impl(Fun&& fun,
}
template<class Pattern, typename Fun>
std::unique_ptr<invokable> get_invokable_impl(Fun&& fun)
{
std::unique_ptr<invokable> get_invokable_impl(Fun&& fun) {
typedef typename Pattern::types pattern_types;
typedef typename select_invokable_impl<Fun, pattern_types>::type impl;
return std::unique_ptr<invokable>{new impl(std::forward<Fun>(fun))};
......
......@@ -37,25 +37,20 @@
namespace cppa { namespace detail {
template<typename List, bool HasPrimitiveValues>
struct list_member_util
{
struct list_member_util {
typedef typename List::value_type value_type;
static constexpr primitive_type vptype = type_to_ptype<value_type>::ptype;
void operator()(const List& list, serializer* s) const
{
void operator()(const List& list, serializer* s) const {
s->begin_sequence(list.size());
for (auto i = list.begin(); i != list.end(); ++i)
{
for (auto i = list.begin(); i != list.end(); ++i) {
s->write_value(*i);
}
s->end_sequence();
}
void operator()(List& list, deserializer* d) const
{
void operator()(List& list, deserializer* d) const {
list.clear();
auto size = d->begin_sequence();
for (decltype(size) i = 0; i < size; ++i)
{
for (decltype(size) i = 0; i < size; ++i) {
list.push_back(get<value_type>(d->read_value(vptype)));
}
d->end_sequence();
......@@ -63,33 +58,27 @@ struct list_member_util
};
template<typename List>
struct list_member_util<List, false>
{
struct list_member_util<List, false> {
typedef typename List::value_type value_type;
uniform_type_info const* m_value_type;
list_member_util() : m_value_type(uniform_typeid<value_type>())
{
list_member_util() : m_value_type(uniform_typeid<value_type>()) {
}
void operator()(const List& list, serializer* s) const
{
void operator()(const List& list, serializer* s) const {
s->begin_sequence(list.size());
for (auto i = list.begin(); i != list.end(); ++i)
{
for (auto i = list.begin(); i != list.end(); ++i) {
m_value_type->serialize(&(*i), s);
}
s->end_sequence();
}
void operator()(List& list, deserializer* d) const
{
void operator()(List& list, deserializer* d) const {
list.clear();
value_type tmp;
auto size = d->begin_sequence();
for (decltype(size) i = 0; i < size; ++i)
{
for (decltype(size) i = 0; i < size; ++i) {
m_value_type->deserialize(&tmp, d);
list.push_back(tmp);
}
......@@ -98,22 +87,19 @@ struct list_member_util<List, false>
};
template<typename List>
class list_member : public util::abstract_uniform_type_info<List>
{
class list_member : public util::abstract_uniform_type_info<List> {
typedef typename List::value_type value_type;
list_member_util<List, util::is_primitive<value_type>::value> m_helper;
public:
void serialize(void const* obj, serializer* s) const
{
void serialize(void const* obj, serializer* s) const {
auto& list = *reinterpret_cast<List const*>(obj);
m_helper(list, s);
}
void deserialize(void* obj, deserializer* d) const
{
void deserialize(void* obj, deserializer* d) const {
auto& list = *reinterpret_cast<List*>(obj);
m_helper(list, d);
}
......
......@@ -49,18 +49,15 @@ struct map_member_util;
// std::set with primitive value
template<typename T>
struct map_member_util<T, false, true>
{
struct map_member_util<T, false, true> {
primitive_member<T> impl;
void serialize_value(const T& what, serializer* s) const
{
void serialize_value(const T& what, serializer* s) const {
impl.serialize(&what, s);
}
template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const
{
void deserialize_and_insert(M& map, deserializer* d) const {
T value;
impl.deserialize(&value, d);
map.insert(std::move(value));
......@@ -69,22 +66,18 @@ struct map_member_util<T, false, true>
// std::set with non-primitive value
template<typename T>
struct map_member_util<T, false, false>
{
struct map_member_util<T, false, false> {
uniform_type_info const* m_type;
map_member_util() : m_type(uniform_typeid<T>())
{
map_member_util() : m_type(uniform_typeid<T>()) {
}
void serialize_value(const T& what, serializer* s) const
{
void serialize_value(const T& what, serializer* s) const {
m_type->serialize(&what, s);
}
template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const
{
void deserialize_and_insert(M& map, deserializer* d) const {
T value;
m_type->deserialize(&value, d);
map.insert(std::move(value));
......@@ -93,8 +86,7 @@ struct map_member_util<T, false, false>
// std::map
template<typename T>
struct map_member_util<T, true, false>
{
struct map_member_util<T, true, false> {
// std::map defines its first half of value_type as const
typedef typename std::remove_const<typename T::first_type>::type first_type;
......@@ -103,16 +95,14 @@ struct map_member_util<T, true, false>
pair_member<first_type, second_type> impl;
void serialize_value(const T& what, serializer* s) const
{
void serialize_value(const T& what, serializer* s) const {
// impl needs a pair without const modifier
std::pair<first_type, second_type> p(what.first, what.second);
impl.serialize(&p, s);
}
template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const
{
void deserialize_and_insert(M& map, deserializer* d) const {
std::pair<first_type, second_type> p;
impl.deserialize(&p, d);
std::pair<const first_type, second_type> v(std::move(p.first),
......@@ -123,8 +113,7 @@ struct map_member_util<T, true, false>
};
template<typename Map>
class map_member : public util::abstract_uniform_type_info<Map>
{
class map_member : public util::abstract_uniform_type_info<Map> {
typedef typename Map::key_type key_type;
typedef typename Map::value_type value_type;
......@@ -135,24 +124,20 @@ class map_member : public util::abstract_uniform_type_info<Map>
public:
void serialize(void const* obj, serializer* s) const
{
void serialize(void const* obj, serializer* s) const {
auto& mp = *reinterpret_cast<Map const*>(obj);
s->begin_sequence(mp.size());
for (const auto& val : mp)
{
for (const auto& val : mp) {
m_helper.serialize_value(val, s);
}
s->end_sequence();
}
void deserialize(void* obj, deserializer* d) const
{
void deserialize(void* obj, deserializer* d) const {
auto& mp = *reinterpret_cast<Map*>(obj);
mp.clear();
size_t mp_size = d->begin_sequence();
for (size_t i = 0; i < mp_size; ++i)
{
for (size_t i = 0; i < mp_size; ++i) {
m_helper.deserialize_and_insert(mp, d);
}
d->end_sequence();
......
This diff is collapsed.
......@@ -39,8 +39,7 @@
namespace cppa { namespace detail {
class mock_scheduler : public scheduler
{
class mock_scheduler : public scheduler {
public:
......
This diff is collapsed.
......@@ -35,8 +35,7 @@
namespace cppa { namespace detail {
class network_manager
{
class network_manager {
public:
......
......@@ -39,8 +39,7 @@
namespace cppa { namespace detail {
class object_array : public abstract_tuple
{
class object_array : public abstract_tuple {
typedef abstract_tuple super;
......
......@@ -43,8 +43,7 @@ const utype& uniform_type_info();
namespace cppa { namespace detail {
template<typename T>
struct obj_impl : object
{
struct obj_impl : object {
T m_value;
obj_impl() : m_value() { }
obj_impl(const T& v) : m_value(v) { }
......@@ -52,12 +51,10 @@ struct obj_impl : object
virtual const utype& type() const { return uniform_type_info<T>(); }
virtual void* mutable_value() { return &m_value; }
virtual void const* value() const { return &m_value; }
virtual void serialize(serializer& s) const
{
virtual void serialize(serializer& s) const {
s << m_value;
}
virtual void deserialize(deserializer& d)
{
virtual void deserialize(deserializer& d) {
d >> m_value;
}
};
......
......@@ -42,8 +42,7 @@
namespace cppa { namespace detail {
template<typename T1, typename T2>
class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>>
{
class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>> {
static constexpr primitive_type ptype1 = type_to_ptype<T1>::ptype;
static constexpr primitive_type ptype2 = type_to_ptype<T2>::ptype;
......@@ -55,15 +54,13 @@ class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>>
public:
void serialize(void const* obj, serializer* s) const
{
void serialize(void const* obj, serializer* s) const {
auto& p = *reinterpret_cast<pair_type const*>(obj);
primitive_variant values[2] = { p.first, p.second };
s->write_tuple(2, values);
}
void deserialize(void* obj, deserializer* d) const
{
void deserialize(void* obj, deserializer* d) const {
primitive_type ptypes[2] = { ptype1, ptype2 };
primitive_variant values[2];
d->read_tuple(2, ptypes, values);
......
......@@ -39,8 +39,7 @@
namespace cppa { namespace detail {
struct po_message
{
struct po_message {
atom_value flag;
native_socket_type fd;
actor_id aid;
......
This diff is collapsed.
......@@ -42,8 +42,7 @@ namespace cppa { namespace detail {
// uniform_type_info implementation for primitive data types.
template<typename T>
class primitive_member : public util::abstract_uniform_type_info<T>
{
class primitive_member : public util::abstract_uniform_type_info<T> {
static constexpr primitive_type ptype = type_to_ptype<T>::ptype;
......@@ -51,13 +50,11 @@ class primitive_member : public util::abstract_uniform_type_info<T>
public:
void serialize(void const* obj, serializer* s) const
{
void serialize(void const* obj, serializer* s) const {
s->write_value(*reinterpret_cast<T const*>(obj));
}
void deserialize(void* obj, deserializer* d) const
{
void deserialize(void* obj, deserializer* d) const {
primitive_variant val(d->read_value(ptype));
*reinterpret_cast<T*>(obj) = std::move(get<T>(val));
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -62,8 +62,7 @@ struct ptype_to_type :
util::if_else_c<PT == pt_u16string, std::u16string,
util::if_else_c<PT == pt_u32string, std::u32string,
// default case
void > > > > > > > > > > > > > >
{
void > > > > > > > > > > > > > > {
};
} } // namespace cppa::detail
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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