From: Arnaud Giersch Date: Fri, 27 Dec 2019 16:09:41 +0000 (+0100) Subject: [sonar] Constify pointer and reference parameters in examples/. X-Git-Tag: v3.25~207 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/329535631662ebf730c23f762762d38bf16663c3 [sonar] Constify pointer and reference parameters in examples/. --- diff --git a/examples/s4u/actor-migrate/s4u-actor-migrate.cpp b/examples/s4u/actor-migrate/s4u-actor-migrate.cpp index be035dfa52..b697d8bf02 100644 --- a/examples/s4u/actor-migrate/s4u-actor-migrate.cpp +++ b/examples/s4u/actor-migrate/s4u-actor-migrate.cpp @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example"); -static void worker(simgrid::s4u::Host* first, simgrid::s4u::Host* second) +static void worker(simgrid::s4u::Host* first, const simgrid::s4u::Host* second) { double flopAmount = first->get_speed() * 5 + second->get_speed() * 5; diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index a5e59bbc0e..84d3196a4c 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -172,12 +172,12 @@ bool Peer::hasFinished() } /** Indicates if the remote peer has a piece not stored by the local peer */ -bool Peer::isInterestedBy(Connection* remote_peer) +bool Peer::isInterestedBy(const Connection* remote_peer) const { return remote_peer->bitfield & (bitfield_ ^ ((1 << FILE_PIECES) - 1)); } -bool Peer::isInterestedByFree(Connection* remote_peer) +bool Peer::isInterestedByFree(const Connection* remote_peer) const { for (unsigned int i = 0; i < FILE_PIECES; i++) if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) diff --git a/examples/s4u/app-bittorrent/s4u-peer.hpp b/examples/s4u/app-bittorrent/s4u-peer.hpp index ecc5994743..428283007a 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.hpp +++ b/examples/s4u/app-bittorrent/s4u-peer.hpp @@ -25,7 +25,7 @@ public: explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){}; void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; } - bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; } + bool hasPiece(unsigned int piece) const { return bitfield & 1U << piece; } }; class Peer { @@ -53,17 +53,17 @@ public: std::string getStatus(); bool hasFinished(); int nbInterestedPeers(); - bool isInterestedBy(Connection* remote_peer); - bool isInterestedByFree(Connection* remote_peer); + bool isInterestedBy(const Connection* remote_peer) const; + bool isInterestedByFree(const Connection* remote_peer) const; void updateActivePeersSet(Connection* remote_peer); void updateInterestedAfterReceive(); void updateChokedPeers(); - bool hasNotPiece(unsigned int piece) { return not(bitfield_ & 1U << piece); } + bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); } bool hasCompletedPiece(unsigned int piece); unsigned int countPieces(unsigned int bitfield); /** Check that a piece is not currently being download by the peer. */ - bool isNotDownloadingPiece(unsigned int piece) { return not(current_pieces & 1U << piece); } + bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); } int partiallyDownloadedPiece(Connection* remote_peer); void updatePiecesCountFromBitfield(unsigned int bitfield); void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece); diff --git a/examples/s4u/dht-kademlia/answer.cpp b/examples/s4u/dht-kademlia/answer.cpp index 0afc935e84..4ffe046860 100644 --- a/examples/s4u/dht-kademlia/answer.cpp +++ b/examples/s4u/dht-kademlia/answer.cpp @@ -27,7 +27,7 @@ void Answer::print() /** @brief Merge two answers together, only keeping the best nodes * @param source the source of the nodes to add */ -unsigned int Answer::merge(Answer* source) +unsigned int Answer::merge(const Answer* source) { if (this == source) return 0; diff --git a/examples/s4u/dht-kademlia/answer.hpp b/examples/s4u/dht-kademlia/answer.hpp index ab93e99a7e..c5134788f5 100644 --- a/examples/s4u/dht-kademlia/answer.hpp +++ b/examples/s4u/dht-kademlia/answer.hpp @@ -23,10 +23,10 @@ public: std::vector> nodes; explicit Answer(unsigned int destination_id) : destination_id_(destination_id) {} virtual ~Answer() = default; - unsigned int getDestinationId() { return destination_id_; } + unsigned int getDestinationId() const { return destination_id_; } unsigned int getSize() { return size_; } void print(); - unsigned int merge(Answer* a); + unsigned int merge(const Answer* a); void trim(); bool destinationFound(); void addBucket(const kademlia::Bucket* bucket); diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index 961e8b91a1..8ab688c57f 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -93,7 +93,7 @@ void Node::sendFindNode(unsigned int id, unsigned int destination) * Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best * nodes */ -unsigned int Node::sendFindNodeToBest(Answer* node_list) +unsigned int Node::sendFindNodeToBest(const Answer* node_list) { unsigned int i = 0; unsigned int j = 0; @@ -268,7 +268,7 @@ void Node::randomLookup() } /** @brief Handles the answer to an incoming "find_node" task */ -void Node::handleFindNode(Message* msg) +void Node::handleFindNode(const Message* msg) { routingTableUpdate(msg->sender_id_); XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(), diff --git a/examples/s4u/dht-kademlia/node.hpp b/examples/s4u/dht-kademlia/node.hpp index 400461525e..a9f5bf9eaf 100644 --- a/examples/s4u/dht-kademlia/node.hpp +++ b/examples/s4u/dht-kademlia/node.hpp @@ -28,12 +28,12 @@ public: bool join(unsigned int known_id); void sendFindNode(unsigned int id, unsigned int destination); - unsigned int sendFindNodeToBest(Answer* node_list); + unsigned int sendFindNodeToBest(const Answer* node_list); void routingTableUpdate(unsigned int id); Answer* findClosest(unsigned int destination_id); bool findNode(unsigned int id_to_find, bool count_in_stats); void randomLookup(); - void handleFindNode(Message* msg); + void handleFindNode(const Message* msg); }; } // identifier functions diff --git a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp index d03ea86367..494030006a 100644 --- a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp +++ b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp @@ -19,7 +19,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_engine_filtering, "Messages specific for this s namespace filter { /* First example of thing that we can use as a filtering criteria: a simple boolean function */ -static bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host) +static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host) { return host->get_speed() > 50E6; } @@ -29,7 +29,7 @@ static bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host) */ class SingleCore { public: - bool operator()(simgrid::s4u::Host* host) { return host->get_core_count() == 1; } + bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; } }; /* This functor is a bit more complex, as it saves the current state when created. @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) /* Use a lambda function to filter hosts: We only want multicore hosts */ XBT_INFO("Hosts currently registered with this engine: %zu", e.get_host_count()); std::vector list = - e.get_filtered_hosts([](simgrid::s4u::Host* host) { return host->get_core_count() > 1; }); + e.get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->get_core_count() > 1; }); for (auto& host : list) XBT_INFO("The following hosts have more than one core: %s", host->get_cname()); diff --git a/examples/s4u/replay-comm/s4u-replay-comm.cpp b/examples/s4u/replay-comm/s4u-replay-comm.cpp index 95affd0985..580b9788fd 100644 --- a/examples/s4u/replay-comm/s4u-replay-comm.cpp +++ b/examples/s4u/replay-comm/s4u-replay-comm.cpp @@ -18,7 +18,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(replay_comm, "Messages specific for this msg exampl } else \ ((void)0) -static void log_action(simgrid::xbt::ReplayAction& action, double date) +static void log_action(const simgrid::xbt::ReplayAction& action, double date) { if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) { std::string s = boost::algorithm::join(action, " "); diff --git a/examples/s4u/replay-io/s4u-replay-io.cpp b/examples/s4u/replay-io/s4u-replay-io.cpp index 07ea1ea870..1602dda2a0 100644 --- a/examples/s4u/replay-io/s4u-replay-io.cpp +++ b/examples/s4u/replay-io/s4u-replay-io.cpp @@ -21,7 +21,7 @@ static std::unordered_map opened_files; } else \ ((void)0) -static void log_action(simgrid::xbt::ReplayAction& action, double date) +static void log_action(const simgrid::xbt::ReplayAction& action, double date) { if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) { std::string s = boost::algorithm::join(action, " "); diff --git a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp index f12994008a..34542e7c82 100644 --- a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp +++ b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp @@ -16,8 +16,7 @@ const char* buffer; /* Wh simgrid::s4u::SemaphorePtr sem_empty = simgrid::s4u::Semaphore::create(1); /* indicates whether the buffer is empty */ simgrid::s4u::SemaphorePtr sem_full = simgrid::s4u::Semaphore::create(0); /* indicates whether the buffer is full */ - -static void producer(std::vector* args) +static void producer(const std::vector* args) { for (auto str : *args) { sem_empty->acquire(); diff --git a/examples/smpi/replay/replay.cpp b/examples/smpi/replay/replay.cpp index 429a3a26a3..d8c23d0b41 100644 --- a/examples/smpi/replay/replay.cpp +++ b/examples/smpi/replay/replay.cpp @@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example") /* This shows how to extend the trace format by adding a new kind of events. This function is registered through xbt_replay_action_register() below. */ -static void action_blah(simgrid::xbt::ReplayAction& /*args*/) +static void action_blah(const simgrid::xbt::ReplayAction& /*args*/) { /* Add your answer to the blah event here. args is a strings array containing the blank-separated parameters found in the trace for this event instance. */ 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 8524a1a53c..5c0a1fe60a 100644 --- a/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp +++ b/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp @@ -65,7 +65,7 @@ static void smpi_replay_process(Job* job, simgrid::s4u::BarrierPtr barrier, int } // Sleeps for a given amount of time -static int sleeper_process(int* param) +static int sleeper_process(const int* param) { XBT_DEBUG("Sleeping for %d seconds", *param); simgrid::s4u::this_actor::sleep_for(*param); @@ -106,7 +106,7 @@ static int job_executor_process(Job* job) } // Executes a workload of SMPI processes -static int workload_executor_process(std::vector* workload) +static int workload_executor_process(const std::vector* workload) { for (Job* job : *workload) { // Let's wait until the job's waiting time if needed