From: Arnaud Giersch Date: Sat, 3 Oct 2020 19:48:41 +0000 (+0200) Subject: [sonar] Replace redundant type with "auto" (examples/). X-Git-Tag: v3.26~399 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2c0aa88e3d941e79fc79d39e3e58224d282b76d3 [sonar] Replace redundant type with "auto" (examples/). --- diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index ee1e6ef49a..874e36ad81 100644 --- 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()); - const std::string* msg1 = static_cast(mailbox->get()); - const std::string* msg2 = static_cast(mailbox->get()); - const std::string* msg3 = static_cast(mailbox->get()); + const auto* msg1 = static_cast(mailbox->get()); + const auto* msg2 = static_cast(mailbox->get()); + const auto* msg3 = static_cast(mailbox->get()); XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str()); delete msg1; delete msg2; @@ -49,7 +49,7 @@ 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]); - std::string* msg = static_cast(in->get()); + auto* msg = static_cast(in->get()); XBT_INFO("Forward '%s'.", msg->c_str()); out->put(msg, msg->size()); } diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index d653c2a0ee..fe653ac776 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -78,7 +78,7 @@ bool Peer::getPeersFromTracker() { simgrid::s4u::Mailbox* tracker_mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX); // Build the task to send to the tracker - TrackerQuery* peer_request = new TrackerQuery(id, mailbox_); + auto* peer_request = new TrackerQuery(id, mailbox_); try { XBT_DEBUG("Sending a peer request to the tracker."); tracker_mailbox->put(peer_request, TRACKER_COMM_SIZE, GET_PEERS_TIMEOUT); @@ -89,7 +89,7 @@ bool Peer::getPeersFromTracker() } try { - TrackerAnswer* answer = static_cast(mailbox_->get(GET_PEERS_TIMEOUT)); + auto* answer = static_cast(mailbox_->get(GET_PEERS_TIMEOUT)); // Add the peers the tracker gave us to our peer list. for (auto const& peer_id : answer->getPeers()) if (id != peer_id) @@ -106,7 +106,7 @@ void Peer::sendHandshakeToAllPeers() { for (auto const& kv : connected_peers) { const Connection& remote_peer = kv.second; - Message* handshake = new Message(MESSAGE_HANDSHAKE, id, mailbox_); + auto* handshake = new Message(MESSAGE_HANDSHAKE, id, mailbox_); remote_peer.mailbox_->put_init(handshake, MESSAGE_HANDSHAKE_SIZE)->detach(); XBT_DEBUG("Sending a HANDSHAKE to %d", remote_peer.id); } diff --git a/examples/s4u/app-bittorrent/s4u-tracker.cpp b/examples/s4u/app-bittorrent/s4u-tracker.cpp index ee4a401941..ba7c3fd9fa 100644 --- a/examples/s4u/app-bittorrent/s4u-tracker.cpp +++ b/examples/s4u/app-bittorrent/s4u-tracker.cpp @@ -36,7 +36,7 @@ void Tracker::operator()() if (comm->test()) { // Retrieve the data sent by the peer. xbt_assert(received != nullptr); - TrackerQuery* tq = static_cast(received); + auto* tq = static_cast(received); // Add the peer to our peer list, if not already known. if (known_peers.find(tq->getPeerId()) == known_peers.end()) { @@ -44,7 +44,7 @@ void Tracker::operator()() } // Sending back peers to the requesting peer - TrackerAnswer* ta = new TrackerAnswer(TRACKER_QUERY_INTERVAL); + auto* ta = new TrackerAnswer(TRACKER_QUERY_INTERVAL); std::set::iterator next_peer; int nb_known_peers = static_cast(known_peers.size()); int max_tries = std::min(MAXIMUM_PEERS, nb_known_peers); diff --git a/examples/s4u/app-chainsend/s4u-app-chainsend.cpp b/examples/s4u/app-chainsend/s4u-app-chainsend.cpp index 6da10d6c2a..ffce1cde21 100644 --- a/examples/s4u/app-chainsend/s4u-app-chainsend.cpp +++ b/examples/s4u/app-chainsend/s4u-app-chainsend.cpp @@ -47,7 +47,7 @@ public: void joinChain() { - const ChainMessage* msg = static_cast(me->get()); + const auto* msg = static_cast(me->get()); prev = msg->prev_; next = msg->next_; total_pieces = msg->num_pieces; @@ -139,7 +139,7 @@ static void peer() { XBT_DEBUG("peer"); - Peer* p = new Peer(); + auto* p = new Peer(); double start_time = simgrid::s4u::Engine::get_clock(); p->joinChain(); @@ -158,7 +158,7 @@ static void broadcaster(int hostcount, unsigned int piece_count) { XBT_DEBUG("broadcaster"); - Broadcaster* bc = new Broadcaster(hostcount, piece_count); + auto* bc = new Broadcaster(hostcount, piece_count); bc->buildChain(); bc->sendFile(); diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp b/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp index 9c83964326..7dd386058f 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp @@ -67,7 +67,7 @@ public: { double compute_cost; do { - const double* msg = static_cast(mailbox->get()); + const auto* msg = static_cast(mailbox->get()); compute_cost = *msg; delete msg; diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp b/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp index a348d98c74..72ff9cdd1b 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp @@ -54,7 +54,7 @@ static void worker(std::vector args) double compute_cost; do { - const double* msg = static_cast(mailbox->get()); + const auto* msg = static_cast(mailbox->get()); compute_cost = *msg; delete msg; diff --git a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp index f80ef71e9b..9407c7cad3 100644 --- a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp +++ b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp @@ -12,12 +12,11 @@ static void pinger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str()); /* - Do the ping with a 1-Byte payload (latency bound) ... */ - double* payload = new double(); - *payload = simgrid::s4u::Engine::get_clock(); + auto* payload = new double(simgrid::s4u::Engine::get_clock()); mailbox_out->put(payload, 1); /* - ... then wait for the (large) pong */ - const double* sender_time = static_cast(mailbox_in->get()); + const auto* sender_time = static_cast(mailbox_in->get()); double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time; XBT_INFO("Payload received : large communication (bandwidth bound)"); @@ -30,15 +29,14 @@ static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str()); /* - Receive the (small) ping first ....*/ - const double* sender_time = static_cast(mailbox_in->get()); + const auto* sender_time = static_cast(mailbox_in->get()); double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time; XBT_INFO("Payload received : small communication (latency bound)"); XBT_INFO("Ping time (latency bound) %f", communication_time); delete sender_time; /* - ... Then send a 1GB pong back (bandwidth bound) */ - double* payload = new double(); - *payload = simgrid::s4u::Engine::get_clock(); + auto* payload = new double(simgrid::s4u::Engine::get_clock()); XBT_INFO("payload = %.3f", *payload); mailbox_out->put(payload, 1e9); diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index 9ead2ac9bb..ea3ad78def 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -40,10 +40,10 @@ public: XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); std::string msg = "Token"; neighbor_mailbox->put(&msg, token_size); - const std::string* res = static_cast(my_mailbox->get()); + const auto* res = static_cast(my_mailbox->get()); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); } else { - std::string* res = static_cast(my_mailbox->get()); + auto* res = static_cast(my_mailbox->get()); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); neighbor_mailbox->put(res, token_size); diff --git a/examples/s4u/cloud-capping/s4u-cloud-capping.cpp b/examples/s4u/cloud-capping/s4u-cloud-capping.cpp index 5860b857b2..b39b519125 100644 --- a/examples/s4u/cloud-capping/s4u-cloud-capping.cpp +++ b/examples/s4u/cloud-capping/s4u-cloud-capping.cpp @@ -56,8 +56,8 @@ static void test_dynamic_change() { simgrid::s4u::Host* pm0 = simgrid::s4u::Host::by_name("Fafard"); - simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); - simgrid::s4u::VirtualMachine* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); + auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); + auto* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); vm0->start(); vm1->start(); @@ -165,7 +165,7 @@ static void master_main() test_two_activities(pm0, pm0); XBT_INFO(" "); - simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); + auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); vm0->start(); XBT_INFO("# 3. Put a single activity on a VM. "); diff --git a/examples/s4u/cloud-migration/s4u-cloud-migration.cpp b/examples/s4u/cloud-migration/s4u-cloud-migration.cpp index 11c690be4e..b0ada3d4bf 100644 --- a/examples/s4u/cloud-migration/s4u-cloud-migration.cpp +++ b/examples/s4u/cloud-migration/s4u-cloud-migration.cpp @@ -30,7 +30,7 @@ static void master_main() simgrid::s4u::Host* pm1 = simgrid::s4u::Host::by_name("Tremblay"); simgrid::s4u::Host* pm2 = simgrid::s4u::Host::by_name("Bourassa"); - simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); + auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); vm0->set_ramsize(1e9); // 1Gbytes vm0->start(); @@ -48,8 +48,8 @@ static void master_main() vm0->destroy(); - vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); - simgrid::s4u::VirtualMachine* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); + vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); + auto* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); vm0->set_ramsize(1e9); // 1Gbytes vm1->set_ramsize(1e9); // 1Gbytes diff --git a/examples/s4u/cloud-simple/s4u-cloud-simple.cpp b/examples/s4u/cloud-simple/s4u-cloud-simple.cpp index f8b83b91aa..65cc5feb7e 100644 --- a/examples/s4u/cloud-simple/s4u-cloud-simple.cpp +++ b/examples/s4u/cloud-simple/s4u-cloud-simple.cpp @@ -33,7 +33,7 @@ struct s_payload { static void communication_tx_fun(std::vector args) { simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0)); - s_payload* payload = new s_payload; + auto* payload = new s_payload; payload->tx_actor_name = simgrid::s4u::Actor::self()->get_cname(); payload->tx_host = simgrid::s4u::this_actor::get_host(); payload->clock_sta = simgrid::s4u::Engine::get_clock(); @@ -47,7 +47,7 @@ static void communication_rx_fun(std::vector args) const char* host_name = simgrid::s4u::this_actor::get_host()->get_cname(); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0)); - const s_payload* payload = static_cast(mbox->get()); + const auto* payload = static_cast(mbox->get()); double clock_end = simgrid::s4u::Engine::get_clock(); XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name, @@ -95,7 +95,7 @@ static void master_main() "## Test 2 (started): check impact of running an activity inside a VM (there is no degradation for the moment)"); XBT_INFO("### Put a VM on a PM, and put an activity to the VM"); - simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); + auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); vm0->start(); launch_computation_worker(vm0); simgrid::s4u::this_actor::sleep_for(2); @@ -121,7 +121,7 @@ static void master_main() XBT_INFO("### Put two VMs on a PM, and put an activity to each VM"); vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1); vm0->start(); - simgrid::s4u::VirtualMachine* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); + auto* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1); launch_computation_worker(vm0); launch_computation_worker(vm1); simgrid::s4u::this_actor::sleep_for(2); diff --git a/examples/s4u/comm-dependent/s4u-comm-dependent.cpp b/examples/s4u/comm-dependent/s4u-comm-dependent.cpp index 0e5f9baa18..b1add65cf3 100644 --- a/examples/s4u/comm-dependent/s4u-comm-dependent.cpp +++ b/examples/s4u/comm-dependent/s4u-comm-dependent.cpp @@ -9,8 +9,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_dependent, "Messages specific for this s4u static void sender(simgrid::s4u::Mailbox* mailbox) { - double* computation_amount = new double(); - *computation_amount = simgrid::s4u::this_actor::get_host()->get_speed(); + auto* computation_amount = new double(simgrid::s4u::this_actor::get_host()->get_speed()); simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount)); simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6); diff --git a/examples/s4u/comm-ready/s4u-comm-ready.cpp b/examples/s4u/comm-ready/s4u-comm-ready.cpp index 85867a63f8..ec1cf062c5 100644 --- a/examples/s4u/comm-ready/s4u-comm-ready.cpp +++ b/examples/s4u/comm-ready/s4u-comm-ready.cpp @@ -48,7 +48,7 @@ static void peer(int argc, char** argv) simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName); std::string msgName = std::string("Message ") + std::to_string(i) + std::string(" from peer ") + std::to_string(my_id); - std::string* payload = new std::string(msgName); // copy the data we send: + auto* payload = new std::string(msgName); // copy the data we send: // 'msgName' is not a stable storage location XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str()); /* Create a communication representing the ongoing communication */ @@ -62,7 +62,7 @@ static void peer(int argc, char** argv) if (peer_id != my_id) { std::string mboxName = std::string("peer-") + std::to_string(peer_id); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName); - std::string* payload = new std::string("finalize"); // Make a copy of the data we will send + auto* payload = new std::string("finalize"); // Make a copy of the data we will send pending_comms.push_back(mbox->put_async(payload, msg_size)); XBT_INFO("Send 'finalize' to 'peer-%d'", peer_id); } @@ -75,7 +75,7 @@ static void peer(int argc, char** argv) while (pending_finalize_messages > 0) { if (my_mbox->ready()) { double start = simgrid::s4u::Engine::get_clock(); - const std::string* received = static_cast(my_mbox->get()); + const auto* received = static_cast(my_mbox->get()); double waiting_time = simgrid::s4u::Engine::get_clock() - start; xbt_assert( waiting_time == 0, diff --git a/examples/s4u/comm-suspend/s4u-comm-suspend.cpp b/examples/s4u/comm-suspend/s4u-comm-suspend.cpp index 144a0293aa..b0c7c8a65c 100644 --- a/examples/s4u/comm-suspend/s4u-comm-suspend.cpp +++ b/examples/s4u/comm-suspend/s4u-comm-suspend.cpp @@ -20,7 +20,7 @@ static void sender(int argc, char**) // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data - std::string* payload = new std::string("Sent message"); + auto* payload = new std::string("Sent message"); /* Create a communication representing the ongoing communication and then */ simgrid::s4u::CommPtr comm = mbox->put_init(payload, 13194230); @@ -49,7 +49,7 @@ static void receiver(int, char**) XBT_INFO("Wait for the message."); void* payload = mbox->get(); - const std::string* received = static_cast(payload); + const auto* received = static_cast(payload); XBT_INFO("I got '%s'.", received->c_str()); delete received; diff --git a/examples/s4u/comm-wait/s4u-comm-wait.cpp b/examples/s4u/comm-wait/s4u-comm-wait.cpp index 1664f4b058..b2e5314011 100644 --- a/examples/s4u/comm-wait/s4u-comm-wait.cpp +++ b/examples/s4u/comm-wait/s4u-comm-wait.cpp @@ -35,7 +35,7 @@ static void sender(int argc, char** argv) std::string msg_content = std::string("Message ") + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data - std::string* payload = new std::string(msg_content); + auto* payload = new std::string(msg_content); /* Create a communication representing the ongoing communication and then */ simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size); @@ -79,7 +79,7 @@ static void receiver(int, char**) comm->wait(); } - const std::string* received = static_cast(payload); + const auto* received = static_cast(payload); XBT_INFO("I got a '%s'.", received->c_str()); if (*received == "finalize") cont = false; // If it's a finalize message, we're done. diff --git a/examples/s4u/comm-waitall/s4u-comm-waitall.cpp b/examples/s4u/comm-waitall/s4u-comm-waitall.cpp index 34cb0f54e1..2c2a60bf7f 100644 --- a/examples/s4u/comm-waitall/s4u-comm-waitall.cpp +++ b/examples/s4u/comm-waitall/s4u-comm-waitall.cpp @@ -49,7 +49,7 @@ public: std::string msg_content = std::string("Message ") + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it - std::string* payload = new std::string(msg_content); + auto* payload = new std::string(msg_content); XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname()); @@ -89,7 +89,7 @@ public: { XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { - const std::string* received = static_cast(mbox->get()); + const auto* received = static_cast(mbox->get()); XBT_INFO("I got a '%s'.", received->c_str()); cont = (*received != "finalize"); // If it's a finalize message, we're done // Receiving the message was all we were supposed to do diff --git a/examples/s4u/comm-waitany/s4u-comm-waitany.cpp b/examples/s4u/comm-waitany/s4u-comm-waitany.cpp index 825de575fb..98b3e56258 100644 --- a/examples/s4u/comm-waitany/s4u-comm-waitany.cpp +++ b/examples/s4u/comm-waitany/s4u-comm-waitany.cpp @@ -52,7 +52,7 @@ public: std::string msg_content = std::string("Message ") + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it - std::string* payload = new std::string(msg_content); + auto* payload = new std::string(msg_content); XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname()); @@ -102,7 +102,7 @@ public: { XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { - const std::string* received = static_cast(mbox->get()); + const auto* received = static_cast(mbox->get()); XBT_INFO("I got a '%s'.", received->c_str()); cont = (*received != "finalize"); // If it's a finalize message, we're done // Receiving the message was all we were supposed to do diff --git a/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp b/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp index d887e37ecc..33597a461c 100644 --- a/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp +++ b/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp @@ -31,7 +31,7 @@ static void sender(int argc, char** argv) std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName); std::string msgName = std::string("Message ") + std::to_string(i); - std::string* payload = new std::string(msgName); // copy the data we send: + auto* payload = new std::string(msgName); // copy the data we send: // 'msgName' is not a stable storage location XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str()); @@ -45,7 +45,7 @@ static void sender(int argc, char** argv) for (int i = 0; i < receivers_count; i++) { std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName); - std::string* payload = new std::string("finalize"); // Make a copy of the data we will send + auto* payload = new std::string("finalize"); // Make a copy of the data we will send simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0); pending_comms.push_back(comm); @@ -71,7 +71,7 @@ static void receiver(int argc, char** argv) XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { - const std::string* received = static_cast(mbox->get()); + const auto* received = static_cast(mbox->get()); XBT_INFO("I got a '%s'.", received->c_str()); if (*received == "finalize") cont = false; // If it's a finalize message, we're done. diff --git a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp index fbfdec60f3..abb632b77c 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp @@ -104,7 +104,7 @@ void Node::leave() void Node::notifyAndQuit() { // send the PREDECESSOR_LEAVING to our successor - ChordMessage* pred_msg = new ChordMessage(PREDECESSOR_LEAVING); + auto* pred_msg = new ChordMessage(PREDECESSOR_LEAVING); pred_msg->request_id = pred_id_; pred_msg->answer_to = mailbox_; @@ -118,7 +118,7 @@ void Node::notifyAndQuit() if (pred_id_ != -1 && pred_id_ != id_) { // send the SUCCESSOR_LEAVING to our predecessor (only if I have one that is not me) - ChordMessage* succ_msg = new ChordMessage(SUCCESSOR_LEAVING); + auto* succ_msg = new ChordMessage(SUCCESSOR_LEAVING); succ_msg->request_id = fingers_[0]; succ_msg->answer_to = mailbox_; XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_); @@ -208,7 +208,7 @@ void Node::checkPredecessor() simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(pred_id_)); simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_is_alive"); - ChordMessage* message = new ChordMessage(PREDECESSOR_ALIVE); + auto* message = new ChordMessage(PREDECESSOR_ALIVE); message->request_id = pred_id_; message->answer_to = return_mailbox; @@ -248,7 +248,7 @@ int Node::remoteGetPredecessor(int ask_to) simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to)); simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_pred"); - ChordMessage* message = new ChordMessage(GET_PREDECESSOR); + auto* message = new ChordMessage(GET_PREDECESSOR); message->request_id = id_; message->answer_to = return_mailbox; @@ -269,7 +269,7 @@ int Node::remoteGetPredecessor(int ask_to) try { comm->wait_for(timeout); - const ChordMessage* answer = static_cast(data); + const auto* answer = static_cast(data); XBT_DEBUG("Received the answer to my 'Get Predecessor' request: the predecessor of node %d is %d", ask_to, answer->answer_id); predecessor_id = answer->answer_id; @@ -320,7 +320,7 @@ int Node::remoteFindSuccessor(int ask_to, int id) simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to)); simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_succ"); - ChordMessage* message = new ChordMessage(FIND_SUCCESSOR); + auto* message = new ChordMessage(FIND_SUCCESSOR); message->request_id = id_; message->answer_to = return_mailbox; @@ -366,7 +366,7 @@ void Node::notify(int predecessor_candidate_id) /* Notifies a remote node that its predecessor may have changed. */ void Node::remoteNotify(int notify_id, int predecessor_candidate_id) const { - ChordMessage* message = new ChordMessage(NOTIFY); + auto* message = new ChordMessage(NOTIFY); message->request_id = predecessor_candidate_id; message->answer_to = nullptr; @@ -510,7 +510,7 @@ void Node::operator()() if (comm_completed) { if (data != nullptr) { - ChordMessage* message = static_cast(data); + auto* message = static_cast(data); handleMessage(message); data = nullptr; } diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index f98c9ef032..c119239282 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia_node, "Messages specific for this example" namespace kademlia { static void destroy(void* message) { - const Message* msg = static_cast(message); + const auto* msg = static_cast(message); delete msg->answer_; delete msg; } @@ -40,7 +40,7 @@ bool Node::join(unsigned int known_id) XBT_DEBUG("Received an answer from the node I know."); got_answer = true; // retrieve the node list and ping them. - const Message* msg = static_cast(received_msg); + const auto* msg = static_cast(received_msg); node_list = msg->answer_; if (node_list) { for (auto const& contact : node_list->getNodes()) @@ -81,8 +81,8 @@ void Node::sendFindNode(unsigned int id, unsigned int destination) const simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id)); /* Build the task */ - Message* msg = new Message(id_, destination, simgrid::s4u::Mailbox::by_name(std::to_string(id_)), - simgrid::s4u::Host::current()->get_cname()); + auto* msg = new Message(id_, destination, simgrid::s4u::Mailbox::by_name(std::to_string(id_)), + simgrid::s4u::Host::current()->get_cname()); /* Send the task */ mailbox->put_init(msg, 1)->detach(kademlia::destroy); @@ -144,7 +144,7 @@ void Node::routingTableUpdate(unsigned int id) */ Answer* Node::findClosest(unsigned int destination_id) { - Answer* answer = new Answer(destination_id); + auto* answer = new Answer(destination_id); /* We find the corresponding bucket for the id */ const Bucket* bucket = table.findBucket(destination_id); int bucket_id = bucket->getId(); @@ -205,7 +205,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats) receive_comm = mailbox->get_async(&received_msg); if (receive_comm->test()) { - const Message* msg = static_cast(received_msg); + const auto* msg = static_cast(received_msg); // Check if what we have received is what we are looking for. if (msg->answer_ && msg->answer_->getDestinationId() == id_to_find) { routingTableUpdate(msg->sender_id_); @@ -273,7 +273,7 @@ void Node::handleFindNode(const Message* msg) XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(), msg->issuer_host_name_.c_str(), msg->destination_id_); // Building the answer to the request - Message* answer = + auto* answer = new Message(id_, msg->destination_id_, findClosest(msg->destination_id_), simgrid::s4u::Mailbox::by_name(std::to_string(id_)), simgrid::s4u::Host::current()->get_cname()); // Sending the answer diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp index 1912ef69ac..0c7f779269 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp @@ -52,7 +52,7 @@ static void node(int argc, char* argv[]) if (node.receive_comm->test()) { // There has been a message, we need to handle it ! - const kademlia::Message* msg = static_cast(node.received_msg); + const auto* msg = static_cast(node.received_msg); if (msg) { node.handleFindNode(msg); delete msg->answer_; diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index a44c445040..ff0359f568 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -52,7 +52,7 @@ static void receiver(std::vector args) void* res = mailbox->get(); xbt_free(res); } else { - void** data= new void*[flow_amount]; + auto* data = new void*[flow_amount]; // Start all comms in parallel, and wait for their completion in one shot std::vector comms; diff --git a/examples/s4u/energy-vm/s4u-energy-vm.cpp b/examples/s4u/energy-vm/s4u-energy-vm.cpp index 91b97bfa9d..d276c7e071 100644 --- a/examples/s4u/energy-vm/s4u-energy-vm.cpp +++ b/examples/s4u/energy-vm/s4u-energy-vm.cpp @@ -23,9 +23,9 @@ static void dvfs() /* Host 1 */ XBT_INFO("Creating and starting two VMs"); - simgrid::s4u::VirtualMachine* vm_host1 = new simgrid::s4u::VirtualMachine("vm_host1", host1, 1); + auto* vm_host1 = new simgrid::s4u::VirtualMachine("vm_host1", host1, 1); vm_host1->start(); - simgrid::s4u::VirtualMachine* vm_host2 = new simgrid::s4u::VirtualMachine("vm_host2", host2, 1); + auto* vm_host2 = new simgrid::s4u::VirtualMachine("vm_host2", host2, 1); vm_host2->start(); XBT_INFO("Create two activities on Host1: both inside a VM"); diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp index 7ec29991ba..d7ebe32c48 100644 --- a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp +++ b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp @@ -34,7 +34,7 @@ static void host() /* - Attach some user data to disk1 */ XBT_INFO("*** Get/set data for storage element: Disk1 ***"); - const std::string* data = static_cast(disk->get_data()); + const auto* data = static_cast(disk->get_data()); XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data"); diff --git a/examples/s4u/io-file-system/s4u-io-file-system.cpp b/examples/s4u/io-file-system/s4u-io-file-system.cpp index bdc66291b2..229479fe14 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.cpp +++ b/examples/s4u/io-file-system/s4u-io-file-system.cpp @@ -32,7 +32,7 @@ public: // Open an non-existing file to create it std::string filename = "/scratch/tmp/data.txt"; - simgrid::s4u::File* file = new simgrid::s4u::File(filename, nullptr); + auto* file = new simgrid::s4u::File(filename, nullptr); sg_size_t write = file->write(200000); // Write 200,000 bytes XBT_INFO("Create a %llu bytes file named '%s' on /scratch", write, filename.c_str()); @@ -57,7 +57,7 @@ public: // Test attaching some user data to the file file->set_data(new std::string("777")); - const std::string* file_data = static_cast(file->get_data()); + const auto* file_data = static_cast(file->get_data()); XBT_INFO("User data attached to the file: %s", file_data->c_str()); delete file_data; diff --git a/examples/s4u/maestro-set/s4u-maestro-set.cpp b/examples/s4u/maestro-set/s4u-maestro-set.cpp index 00982ec997..8188c9c5fd 100644 --- a/examples/s4u/maestro-set/s4u-maestro-set.cpp +++ b/examples/s4u/maestro-set/s4u-maestro-set.cpp @@ -40,7 +40,7 @@ static void ensure_other_tid() static void sender() { ensure_root_tid(); - std::string* payload = new std::string("some message"); + auto* payload = new std::string("some message"); simgrid::s4u::Mailbox::by_name("some mailbox")->put((void*)payload, 10e8); } @@ -48,7 +48,7 @@ static void receiver() { ensure_other_tid(); - const std::string* payload = static_cast(simgrid::s4u::Mailbox::by_name("some mailbox")->get()); + const auto* payload = static_cast(simgrid::s4u::Mailbox::by_name("some mailbox")->get()); XBT_INFO("Task received"); delete payload; } diff --git a/examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp b/examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp index 175d561863..2e23b12029 100644 --- a/examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp +++ b/examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp @@ -101,7 +101,7 @@ static void client(int id) XBT_INFO("Propositions changed : r=1, cs=0"); } - const Message* grant = static_cast(my_mailbox->get()); + const auto* grant = static_cast(my_mailbox->get()); if ((id == 1) && (grant->kind == Message::Kind::GRANT)) { cs = 1; diff --git a/examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp b/examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp index 74ca56f576..e642594ffa 100644 --- a/examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp +++ b/examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp @@ -35,8 +35,7 @@ static void server() static void client(int id) { - int* payload = new int(); - *payload = id; + auto* payload = new int(id); simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000); XBT_INFO("Sent!"); diff --git a/examples/s4u/mc-bugged2/s4u-mc-bugged2.cpp b/examples/s4u/mc-bugged2/s4u-mc-bugged2.cpp index 66c085e8b3..6555885d8e 100644 --- a/examples/s4u/mc-bugged2/s4u-mc-bugged2.cpp +++ b/examples/s4u/mc-bugged2/s4u-mc-bugged2.cpp @@ -43,10 +43,8 @@ static void server() static void client(int id) { - int* payload1 = new int(); - *payload1 = id; - int* payload2 = new int(); - *payload2 = id; + auto* payload1 = new int(id); + auto* payload2 = new int(id); XBT_INFO("Send %d", id); simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload1, 10000); diff --git a/examples/s4u/mc-electric-fence/s4u-mc-electric-fence.cpp b/examples/s4u/mc-electric-fence/s4u-mc-electric-fence.cpp index 66c250d73e..658363551e 100644 --- a/examples/s4u/mc-electric-fence/s4u-mc-electric-fence.cpp +++ b/examples/s4u/mc-electric-fence/s4u-mc-electric-fence.cpp @@ -32,8 +32,7 @@ static void server() static void client(int id) { - int* payload = new int(); - *payload = id; + auto* payload = new int(id); simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000); XBT_INFO("Sent!"); } diff --git a/examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp b/examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp index 7efc445d30..fb78611cee 100644 --- a/examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp +++ b/examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp @@ -18,7 +18,7 @@ static int server(int worker_amount) int value_got = -1; simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server"); for (int count = 0; count < worker_amount; count++) { - const int* msg = static_cast(mb->get()); + const auto* msg = static_cast(mb->get()); value_got = *msg; delete msg; } diff --git a/examples/s4u/network-ns3/s4u-network-ns3.cpp b/examples/s4u/network-ns3/s4u-network-ns3.cpp index d655c63ab9..3c150a4ba6 100644 --- a/examples/s4u/network-ns3/s4u-network-ns3.cpp +++ b/examples/s4u/network-ns3/s4u-network-ns3.cpp @@ -73,7 +73,7 @@ static void worker(int argc, char* argv[]) XBT_DEBUG("Worker started"); - const double* payload = static_cast(mbox->get()); + const auto* payload = static_cast(mbox->get()); count_finished--; if (count_finished == 0) { diff --git a/examples/s4u/platform-failures/s4u-platform-failures.cpp b/examples/s4u/platform-failures/s4u-platform-failures.cpp index f55e2b0b31..0d4006eec7 100644 --- a/examples/s4u/platform-failures/s4u-platform-failures.cpp +++ b/examples/s4u/platform-failures/s4u-platform-failures.cpp @@ -36,7 +36,7 @@ static void master(int argc, char* argv[]) for (int i = 0; i < number_of_tasks; i++) { mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); - double* payload = new double(comp_size); + auto* payload = new double(comp_size); try { XBT_INFO("Send a message to %s", mailbox->get_cname()); mailbox->put(payload, comm_size, 10.0); @@ -54,7 +54,7 @@ static void master(int argc, char* argv[]) for (int i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */ mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i)); - double* payload = new double(-1.0); + auto* payload = new double(-1.0); try { mailbox->put(payload, 0, 1.0); } catch (const simgrid::TimeoutException&) { @@ -77,7 +77,7 @@ static void worker(int argc, char* argv[]) while (true) { try { XBT_INFO("Waiting a message on %s", mailbox->get_cname()); - const double* payload = static_cast(mailbox->get()); + const auto* payload = static_cast(mailbox->get()); xbt_assert(payload != nullptr, "mailbox->get() failed"); double comp_size = *payload; delete payload; diff --git a/examples/s4u/replay-comm/s4u-replay-comm.cpp b/examples/s4u/replay-comm/s4u-replay-comm.cpp index d22c13c6d7..5d3a4305e9 100644 --- a/examples/s4u/replay-comm/s4u-replay-comm.cpp +++ b/examples/s4u/replay-comm/s4u-replay-comm.cpp @@ -53,8 +53,8 @@ public: static void send(simgrid::xbt::ReplayAction& action) { - uint64_t size = static_cast(std::stod(action[3])); - std::string* payload = new std::string(action[3]); + auto size = static_cast(std::stod(action[3])); + auto* payload = new std::string(action[3]); double clock = simgrid::s4u::Engine::get_clock(); simgrid::s4u::Mailbox* to = simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_name() + "_" + action[2]); ACT_DEBUG("Entering Send: %s (size: %" PRIu64 ") -- Actor %s on mailbox %s", NAME.c_str(), size, diff --git a/examples/s4u/replay-io/s4u-replay-io.cpp b/examples/s4u/replay-io/s4u-replay-io.cpp index 509995ccc5..6f6ae9de7d 100644 --- a/examples/s4u/replay-io/s4u-replay-io.cpp +++ b/examples/s4u/replay-io/s4u-replay-io.cpp @@ -57,7 +57,7 @@ public: std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name; ACT_DEBUG("Entering Open: %s (filename: %s)", NAME.c_str(), file_name.c_str()); - simgrid::s4u::File* file = new simgrid::s4u::File(file_name, NULL); + auto* file = new simgrid::s4u::File(file_name, NULL); opened_files.insert({full_name, file}); diff --git a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp index 3921539c1f..ed5a2b82ed 100644 --- a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp +++ b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp @@ -42,7 +42,7 @@ static void consumer() int main(int argc, char **argv) { - std::vector args = std::vector({"one", "two", "three", ""}); + std::vector args({"one", "two", "three", ""}); simgrid::s4u::Engine e(&argc, argv); e.load_platform("../../platforms/two_hosts.xml"); simgrid::s4u::Actor::create("producer", simgrid::s4u::Host::by_name("Tremblay"), producer, &args); diff --git a/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp b/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp index 191b8572a6..2e769f6ca8 100644 --- a/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp +++ b/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp @@ -79,8 +79,7 @@ static int sleeper_process(const int* param) static void pop_some_processes(int nb_processes, simgrid::s4u::Host* host) { for (int i = 0; i < nb_processes; ++i) { - int* param = new int; - *param = i + 1; + auto* param = new int(i + 1); simgrid::s4u::Actor::create("meh", host, sleeper_process, param); } } diff --git a/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp b/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp index 6ed9f330e9..901e2860ee 100644 --- a/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp +++ b/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp @@ -50,7 +50,7 @@ static void worker(std::vector args) double compute_cost; do { - const double* msg = static_cast(mailbox->get()); + const auto* msg = static_cast(mailbox->get()); compute_cost = *msg; delete msg;