From: Arnaud Giersch Date: Thu, 2 Jul 2020 19:42:09 +0000 (+0200) Subject: [sonar] Declare functions "const" in examples/ and teshsuite/. X-Git-Tag: v3.26~509 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f1671393f75bd162d50e64573db72c0e80cd137f [sonar] Declare functions "const" in examples/ and teshsuite/. --- diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index bff3790308..ee1e6ef49a 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -75,7 +75,7 @@ public: 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); diff --git a/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp b/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp index 5a945a4305..5e3c614826 100644 --- a/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp +++ b/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp @@ -20,7 +20,7 @@ public: XBT_INFO("Exiting now (done sleeping or got killed)."); }); } - void operator()() + void operator()() const { XBT_INFO("Hello! I go to sleep."); simgrid::s4u::this_actor::sleep_for(10); diff --git a/examples/s4u/actor-yield/s4u-actor-yield.cpp b/examples/s4u/actor-yield/s4u-actor-yield.cpp index 6abfa67f5a..9ad18b8c0f 100644 --- a/examples/s4u/actor-yield/s4u-actor-yield.cpp +++ b/examples/s4u/actor-yield/s4u-actor-yield.cpp @@ -20,7 +20,7 @@ class yielder { public: explicit yielder(std::vector args) { number_of_yields = std::stod(args[1]); } - void operator()() + void operator()() const { for (int i = 0; i < number_of_yields; i++) simgrid::s4u::this_actor::yield(); diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 994d7ac6f9..65db116a64 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -159,7 +159,7 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece) } } -std::string Peer::getStatus() +std::string Peer::getStatus() const { std::string res; for (unsigned i = 0; i < FILE_PIECES; i++) @@ -167,7 +167,7 @@ std::string Peer::getStatus() return res; } -bool Peer::hasFinished() +bool Peer::hasFinished() const { return bitfield_ == (1U << FILE_PIECES) - 1U; } @@ -193,7 +193,7 @@ void Peer::updatePiecesCountFromBitfield(unsigned int bitfield) pieces_count[i]++; } -unsigned int Peer::countPieces(unsigned int bitfield) +unsigned int Peer::countPieces(unsigned int bitfield) const { unsigned int count = 0U; unsigned int n = bitfield; @@ -204,7 +204,7 @@ unsigned int Peer::countPieces(unsigned int bitfield) return count; } -int Peer::nbInterestedPeers() +int Peer::nbInterestedPeers() const { int nb = 0; for (auto const& kv : connected_peers) @@ -629,7 +629,7 @@ void Peer::updateBitfieldBlocks(int piece, int block_index, int block_length) bitfield_blocks |= (1ULL << static_cast(piece * PIECES_BLOCKS + i)); } -bool Peer::hasCompletedPiece(unsigned int piece) +bool Peer::hasCompletedPiece(unsigned int piece) const { for (unsigned int i = 0; i < PIECES_BLOCKS; i++) if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i))) @@ -637,7 +637,7 @@ bool Peer::hasCompletedPiece(unsigned int piece) return true; } -int Peer::getFirstMissingBlockFrom(int piece) +int Peer::getFirstMissingBlockFrom(int piece) const { for (unsigned int i = 0; i < PIECES_BLOCKS; i++) if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i))) @@ -646,7 +646,7 @@ int Peer::getFirstMissingBlockFrom(int piece) } /** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */ -int Peer::partiallyDownloadedPiece(const Connection* remote_peer) +int Peer::partiallyDownloadedPiece(const Connection* remote_peer) const { for (unsigned int i = 0; i < FILE_PIECES; i++) if (remotePeerHasMissingPiece(remote_peer, i) && isNotDownloadingPiece(i) && getFirstMissingBlockFrom(i) > 0) diff --git a/examples/s4u/app-bittorrent/s4u-peer.hpp b/examples/s4u/app-bittorrent/s4u-peer.hpp index 0175e26fb7..4a3c84cf7e 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.hpp +++ b/examples/s4u/app-bittorrent/s4u-peer.hpp @@ -52,9 +52,9 @@ public: Peer& operator=(const Peer&) = delete; void operator()(); - std::string getStatus(); - bool hasFinished(); - int nbInterestedPeers(); + std::string getStatus() const; + bool hasFinished() const; + int nbInterestedPeers() const; bool isInterestedBy(const Connection* remote_peer) const; bool isInterestedByFree(const Connection* remote_peer) const; void updateActivePeersSet(Connection* remote_peer); @@ -62,19 +62,19 @@ public: void updateChokedPeers(); bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); } - bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) + bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) const { return hasNotPiece(piece) && remote_peer->hasPiece(piece); } - bool hasCompletedPiece(unsigned int piece); - unsigned int countPieces(unsigned int bitfield); + bool hasCompletedPiece(unsigned int piece) const; + unsigned int countPieces(unsigned int bitfield) const; /** Check that a piece is not currently being download by the peer. */ bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); } - int partiallyDownloadedPiece(const Connection* remote_peer); + int partiallyDownloadedPiece(const Connection* remote_peer) const; void updatePiecesCountFromBitfield(unsigned int bitfield); void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece); void updateBitfieldBlocks(int piece, int block_index, int block_length); - int getFirstMissingBlockFrom(int piece); + int getFirstMissingBlockFrom(int piece) const; int selectPieceToDownload(const Connection* remote_peer); void requestNewPieceTo(Connection* remote_peer); diff --git a/examples/s4u/app-bittorrent/s4u-tracker.hpp b/examples/s4u/app-bittorrent/s4u-tracker.hpp index 8fc72ce6dd..acdb129379 100644 --- a/examples/s4u/app-bittorrent/s4u-tracker.hpp +++ b/examples/s4u/app-bittorrent/s4u-tracker.hpp @@ -17,8 +17,8 @@ class TrackerQuery { public: explicit TrackerQuery(int peer_id, simgrid::s4u::Mailbox* return_mailbox) : peer_id(peer_id), return_mailbox(return_mailbox){}; - int getPeerId() { return peer_id; } - simgrid::s4u::Mailbox* getReturnMailbox() { return return_mailbox; } + int getPeerId() const { return peer_id; } + simgrid::s4u::Mailbox* getReturnMailbox() const { return return_mailbox; } }; class TrackerAnswer { @@ -27,7 +27,7 @@ class TrackerAnswer { public: explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ {} void addPeer(int peer) { peers.insert(peer); } - const std::set& getPeers() { return peers; } + const std::set& getPeers() const { return peers; } }; class Tracker { diff --git a/examples/s4u/async-waitall/s4u-async-waitall.cpp b/examples/s4u/async-waitall/s4u-async-waitall.cpp index 141d7498dc..0818656606 100644 --- a/examples/s4u/async-waitall/s4u-async-waitall.cpp +++ b/examples/s4u/async-waitall/s4u-async-waitall.cpp @@ -32,7 +32,7 @@ public: msg_size = std::stod(args[2]); receivers_count = std::stol(args[3]); } - void operator()() + void operator()() const { // sphinx-doc: init-begin (this line helps the doc to build; ignore it) /* Vector in which we store all ongoing communications */ diff --git a/examples/s4u/async-waitany/s4u-async-waitany.cpp b/examples/s4u/async-waitany/s4u-async-waitany.cpp index ef890fe424..d4ef016a4d 100644 --- a/examples/s4u/async-waitany/s4u-async-waitany.cpp +++ b/examples/s4u/async-waitany/s4u-async-waitany.cpp @@ -37,7 +37,7 @@ public: msg_size = std::stod(args[2]); receivers_count = std::stol(args[3]); } - void operator()() + void operator()() const { /* Vector in which we store all ongoing communications */ std::vector pending_comms; diff --git a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp index fe914e77cc..fbfdec60f3 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord-node.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord-node.cpp @@ -364,7 +364,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) +void Node::remoteNotify(int notify_id, int predecessor_candidate_id) const { ChordMessage* message = new ChordMessage(NOTIFY); message->request_id = predecessor_candidate_id; diff --git a/examples/s4u/dht-chord/s4u-dht-chord.hpp b/examples/s4u/dht-chord/s4u-dht-chord.hpp index bac34b5cac..4b9e85f8d6 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.hpp @@ -81,7 +81,7 @@ public: int remoteFindSuccessor(int ask_to, int id); void notify(int predecessor_candidate_id); - void remoteNotify(int notify_id, int predecessor_candidate_id); + void remoteNotify(int notify_id, int predecessor_candidate_id) const; void stabilize(); void handleMessage(ChordMessage* message); diff --git a/examples/s4u/dht-kademlia/answer.cpp b/examples/s4u/dht-kademlia/answer.cpp index 6d5515cc76..8e3b0ab786 100644 --- a/examples/s4u/dht-kademlia/answer.cpp +++ b/examples/s4u/dht-kademlia/answer.cpp @@ -11,7 +11,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(kademlia_node); namespace kademlia { /** @brief Prints a answer_t, for debugging purposes */ -void Answer::print() +void Answer::print() const { XBT_INFO("Searching %08x, size %zu", destination_id_, nodes_.size()); unsigned int i = 0; diff --git a/examples/s4u/dht-kademlia/answer.hpp b/examples/s4u/dht-kademlia/answer.hpp index de5e1c9e83..2c11211797 100644 --- a/examples/s4u/dht-kademlia/answer.hpp +++ b/examples/s4u/dht-kademlia/answer.hpp @@ -23,7 +23,7 @@ public: unsigned int getDestinationId() const { return destination_id_; } size_t getSize() const { return nodes_.size(); } const std::vector>& getNodes() const { return nodes_; } - void print(); + void print() const; unsigned int merge(const Answer* a); void trim(); bool destinationFound() const; diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index c8ac4633f5..265cdc06d3 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -76,7 +76,7 @@ bool Node::join(unsigned int known_id) * @param id node we are querying * @param destination node we are trying to find. */ -void Node::sendFindNode(unsigned int id, unsigned int destination) +void Node::sendFindNode(unsigned int id, unsigned int destination) const { /* Gets the mailbox to send to */ simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id)); @@ -94,7 +94,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(const Answer* node_list) +unsigned int Node::sendFindNodeToBest(const Answer* node_list) const { unsigned int i = 0; unsigned int j = 0; @@ -281,7 +281,7 @@ void Node::handleFindNode(const Message* msg) msg->answer_to_->put_init(answer, 1)->detach(kademlia::destroy); } -void Node::displaySuccessRate() +void Node::displaySuccessRate() const { XBT_INFO("%u/%u FIND_NODE have succeeded", find_node_success, find_node_success + find_node_failed); } diff --git a/examples/s4u/dht-kademlia/node.hpp b/examples/s4u/dht-kademlia/node.hpp index ab64fa7252..f65106c77a 100644 --- a/examples/s4u/dht-kademlia/node.hpp +++ b/examples/s4u/dht-kademlia/node.hpp @@ -24,17 +24,17 @@ public: explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {} Node(const Node&) = delete; Node& operator=(const Node&) = delete; - unsigned int getId() { return id_; } + unsigned int getId() const { return id_; } bool join(unsigned int known_id); - void sendFindNode(unsigned int id, unsigned int destination); - unsigned int sendFindNodeToBest(const Answer* node_list); + void sendFindNode(unsigned int id, unsigned int destination) const; + unsigned int sendFindNodeToBest(const Answer* node_list) const; 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(const Message* msg); - void displaySuccessRate(); + void displaySuccessRate() const; }; } // namespace kademlia // identifier functions diff --git a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp index 639e1edc88..b240d22c27 100644 --- a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp +++ b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp @@ -29,7 +29,7 @@ static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host) */ class SingleCore { public: - bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; } + bool operator()(const simgrid::s4u::Host* host) const { return host->get_core_count() == 1; } }; /* This functor is a bit more complex, as it saves the current state when created. 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 46f1e02851..bdc66291b2 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.cpp +++ b/examples/s4u/io-file-system/s4u-io-file-system.cpp @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category"); class MyHost { public: - void show_info(std::vector const& disks) + void show_info(std::vector const& disks) const { XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->get_cname()); @@ -24,7 +24,7 @@ public: } } - void operator()() + void operator()() const { std::vector const& disks = simgrid::s4u::Host::current()->get_disks(); diff --git a/examples/s4u/replay-comm/s4u-replay-comm.cpp b/examples/s4u/replay-comm/s4u-replay-comm.cpp index 5f3071c803..0543bc5b98 100644 --- a/examples/s4u/replay-comm/s4u-replay-comm.cpp +++ b/examples/s4u/replay-comm/s4u-replay-comm.cpp @@ -35,7 +35,7 @@ public: simgrid::xbt::replay_runner(actor_name, trace_filename); } - void operator()() + void operator()() const { // Nothing to do here } diff --git a/examples/s4u/replay-io/s4u-replay-io.cpp b/examples/s4u/replay-io/s4u-replay-io.cpp index f5205e47d3..509995ccc5 100644 --- a/examples/s4u/replay-io/s4u-replay-io.cpp +++ b/examples/s4u/replay-io/s4u-replay-io.cpp @@ -44,7 +44,7 @@ public: simgrid::xbt::replay_runner(actor_name, nullptr); } - void operator()() + void operator()() const { // Nothing to do here } diff --git a/teshsuite/s4u/actor-suspend/actor-suspend.cpp b/teshsuite/s4u/actor-suspend/actor-suspend.cpp index b34d160df1..e509b37a94 100644 --- a/teshsuite/s4u/actor-suspend/actor-suspend.cpp +++ b/teshsuite/s4u/actor-suspend/actor-suspend.cpp @@ -18,7 +18,7 @@ simgrid::s4u::ActorPtr receiver; class Receiver { public: - void operator()() + void operator()() const { XBT_INFO("Starting."); auto mailbox = simgrid::s4u::Mailbox::by_name("receiver"); @@ -29,7 +29,7 @@ public: class Suspender { public: - void operator()() + void operator()() const { XBT_INFO("Suspend the receiver..."); receiver->suspend();