A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use typed Mailbox::get<>() instead of using static_cast everywhere.
[simgrid.git]
/
examples
/
s4u
/
actor-create
/
s4u-actor-create.cpp
diff --git
a/examples/s4u/actor-create/s4u-actor-create.cpp
b/examples/s4u/actor-create/s4u-actor-create.cpp
index
9809d5f
..
d8ce9e8
100644
(file)
--- a/
examples/s4u/actor-create/s4u-actor-create.cpp
+++ b/
examples/s4u/actor-create/s4u-actor-create.cpp
@@
-33,9
+33,9
@@
static void receiver(const std::string& mailbox_name)
XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
- const
std::string* msg1 = static_cast<std::string*>(mailbox->get()
);
- const
std::string* msg2 = static_cast<std::string*>(mailbox->get()
);
- const
std::string* msg3 = static_cast<std::string*>(mailbox->get()
);
+ const
auto* msg1 = mailbox->get<std::string>(
);
+ const
auto* msg2 = mailbox->get<std::string>(
);
+ const
auto* msg3 = mailbox->get<std::string>(
);
XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
delete msg1;
delete msg2;
XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
delete msg1;
delete msg2;
@@
-44,15
+44,14
@@
static void receiver(const std::string& mailbox_name)
}
/* Our second class of actors is also a function */
}
/* Our second class of actors is also a function */
-static
int
forwarder(int argc, char** argv)
+static
void
forwarder(int argc, char** argv)
{
xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1);
simgrid::s4u::Mailbox* in = simgrid::s4u::Mailbox::by_name(argv[1]);
simgrid::s4u::Mailbox* out = simgrid::s4u::Mailbox::by_name(argv[2]);
{
xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1);
simgrid::s4u::Mailbox* in = simgrid::s4u::Mailbox::by_name(argv[1]);
simgrid::s4u::Mailbox* out = simgrid::s4u::Mailbox::by_name(argv[2]);
-
std::string* msg = static_cast<std::string*>(in->get()
);
+
auto* msg = in->get<std::string>(
);
XBT_INFO("Forward '%s'.", msg->c_str());
out->put(msg, msg->size());
XBT_INFO("Forward '%s'.", msg->c_str());
out->put(msg, msg->size());
- return 0;
}
/* Declares a third class of actors which sends a message to the mailbox 'mb42'.
}
/* Declares a third class of actors which sends a message to the mailbox 'mb42'.
@@
-76,7
+75,7
@@
public:
msg = args[1];
mbox = args[2];
}
msg = args[1];
mbox = args[2];
}
- void operator()() /* This is the main code of the actor */
+ void operator()()
const
/* This is the main code of the actor */
{
XBT_INFO("Hello s4u, I have something to send");
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mbox);
{
XBT_INFO("Hello s4u, I have something to send");
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mbox);