From fde63ab63d776f60717181c36961cde86cb6d23d Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 18 Mar 2019 14:13:07 +0100 Subject: [PATCH] Add some const qualifier, needed for later changes. --- include/simgrid/kernel/routing/NetPoint.hpp | 6 +++--- include/simgrid/s4u/Actor.hpp | 6 +++--- include/simgrid/s4u/Link.hpp | 4 ++-- include/simgrid/s4u/VirtualMachine.hpp | 2 +- include/xbt/Extendable.hpp | 12 ++++-------- src/instr/instr_paje_containers.cpp | 2 +- src/instr/instr_paje_containers.hpp | 2 +- src/kernel/activity/ExecImpl.cpp | 2 +- src/kernel/activity/ExecImpl.hpp | 2 +- src/s4u/s4u_Actor.cpp | 9 ++------- src/s4u/s4u_Link.cpp | 4 ++-- src/surf/cpu_interface.cpp | 3 ++- src/surf/cpu_interface.hpp | 2 +- src/surf/network_interface.cpp | 2 +- src/surf/network_interface.hpp | 2 +- src/surf/network_ns3.cpp | 2 +- src/surf/network_ns3.hpp | 2 +- 17 files changed, 28 insertions(+), 36 deletions(-) diff --git a/include/simgrid/kernel/routing/NetPoint.hpp b/include/simgrid/kernel/routing/NetPoint.hpp index 7984766ca9..24b11488a3 100644 --- a/include/simgrid/kernel/routing/NetPoint.hpp +++ b/include/simgrid/kernel/routing/NetPoint.hpp @@ -36,9 +36,9 @@ public: /** @brief the NetZone in which this NetPoint is included */ NetZoneImpl* get_englobing_zone() { return englobing_zone_; } - bool is_netzone() { return component_type_ == Type::NetZone; } - bool is_host() { return component_type_ == Type::Host; } - bool is_router() { return component_type_ == Type::Router; } + bool is_netzone() const { return component_type_ == Type::NetZone; } + bool is_host() const { return component_type_ == Type::Host; } + bool is_router() const { return component_type_ == Type::Router; } static simgrid::xbt::signal on_creation; diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 1ccfd6afe2..28e5e37da0 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -207,7 +207,7 @@ public: /** Retrieves the name of that actor as a C string */ const char* get_cname() const; /** Retrieves the host on which that actor is running */ - Host* get_host(); + Host* get_host() const; /** Retrieves the actor ID of that actor */ aid_t get_pid() const; /** Retrieves the actor ID of that actor's creator */ @@ -236,7 +236,7 @@ public: * It will be set to true if the actor was killed or failed because of an exception, * while it will remain to false if the actor terminated gracefully. */ - void on_exit(const std::function& fun); + void on_exit(const std::function& fun) const; /** Sets the time at which that actor should be killed */ void set_kill_time(double time); @@ -286,7 +286,7 @@ public: static void kill_all(); /** Returns the internal implementation of this actor */ - kernel::actor::ActorImpl* get_impl(); + kernel::actor::ActorImpl* get_impl() const { return pimpl_; } /** Retrieve the property value (or nullptr if not set) */ std::unordered_map* diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index be6dfb2449..07b0e85e55 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -45,10 +45,10 @@ public: const char* get_cname() const; /** @brief Get the bandwidth in bytes per second of current Link */ - double get_bandwidth(); + double get_bandwidth() const; /** @brief Get the latency in seconds of current Link */ - double get_latency(); + double get_latency() const; /** @brief Describes how the link is shared between flows */ SharingPolicy get_sharing_policy(); diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index b2bd8aa175..25f2e1b05e 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -38,7 +38,7 @@ public: DESTROYED }; - vm::VirtualMachineImpl* get_impl() { return pimpl_vm_; } + vm::VirtualMachineImpl* get_impl() const { return pimpl_vm_; } void start(); void suspend(); void resume(); diff --git a/include/xbt/Extendable.hpp b/include/xbt/Extendable.hpp index 5acaebed94..37a7d41c59 100644 --- a/include/xbt/Extendable.hpp +++ b/include/xbt/Extendable.hpp @@ -26,7 +26,7 @@ class Extension { public: explicit constexpr Extension() : id_(INVALID_ID) {} std::size_t id() const { return id_; } - bool valid() { return id_ != INVALID_ID; } + bool valid() const { return id_ != INVALID_ID; } }; /** An Extendable is an object that you can extend with external elements. @@ -83,7 +83,7 @@ public: } // Type-unsafe versions of the facet access methods: - void* extension(std::size_t rank) + void* extension(std::size_t rank) const { if (rank >= extensions_.size()) return nullptr; @@ -101,11 +101,7 @@ public: } // Type safe versions of the facet access methods: - template - U* extension(Extension rank) - { - return static_cast(extension(rank.id())); - } + template U* extension(Extension rank) const { return static_cast(extension(rank.id())); } template void extension_set(Extension rank, U* value, bool use_dtor = true) { @@ -113,7 +109,7 @@ public: } // Convenience extension access when the type has a associated EXTENSION ID: - template U* extension() { return extension(U::EXTENSION_ID); } + template U* extension() const { return extension(U::EXTENSION_ID); } template void extension_set(U* p) { extension_set(U::EXTENSION_ID, p); } }; diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 49271aaae2..dedda24885 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -59,7 +59,7 @@ RouterContainer::RouterContainer(const std::string& name, Container* father) trivaNodeTypes.insert(type_->get_name()); } -HostContainer::HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father) +HostContainer::HostContainer(simgrid::s4u::Host const& host, NetZoneContainer* father) : Container::Container(host.get_name(), "HOST", father) { xbt_assert(father, "Only the Root container has no father"); diff --git a/src/instr/instr_paje_containers.hpp b/src/instr/instr_paje_containers.hpp index e4c33e6700..17241ef8db 100644 --- a/src/instr/instr_paje_containers.hpp +++ b/src/instr/instr_paje_containers.hpp @@ -58,7 +58,7 @@ public: class HostContainer : public Container { public: - HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father); + HostContainer(simgrid::s4u::Host const& host, NetZoneContainer* father); }; } } diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index bffe2f5197..462eb70c90 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -117,7 +117,7 @@ void ExecImpl::cancel() surf_action_->cancel(); } -double ExecImpl::get_remaining() +double ExecImpl::get_remaining() const { return surf_action_ ? surf_action_->get_remains() : 0; } diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index e784634c3b..ea96c28ec3 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -29,7 +29,7 @@ public: void cancel(); void post() override; void finish() override; - double get_remaining(); + double get_remaining() const; double get_seq_remaining_ratio(); double get_par_remaining_ratio(); void set_bound(double bound); // deprecated. To be removed in v3.25 diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index b44df1471f..7f2a401b04 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -113,7 +113,7 @@ void Actor::on_exit(const std::function& fun, void* data) /* d on_exit([fun, data](bool exit) { fun(exit, data); }); } -void Actor::on_exit(const std::function& fun) +void Actor::on_exit(const std::function& fun) const { simix::simcall( [this, fun] { SIMIX_process_on_exit(pimpl_, [fun](int a, void* /*data*/) { fun(a != 0); }, nullptr); }); @@ -138,7 +138,7 @@ void Actor::migrate(Host* new_host) s4u::Actor::on_migration_end(this); } -s4u::Host* Actor::get_host() +s4u::Host* Actor::get_host() const { return this->pimpl_->get_host(); } @@ -223,11 +223,6 @@ void Actor::kill() }); } -kernel::actor::ActorImpl* Actor::get_impl() -{ - return pimpl_; -} - // ***** Static functions ***** ActorPtr Actor::by_pid(aid_t pid) diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 86f5c313bc..3b349735b5 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -49,12 +49,12 @@ bool Link::is_used() return this->pimpl_->is_used(); } -double Link::get_latency() +double Link::get_latency() const { return this->pimpl_->get_latency(); } -double Link::get_bandwidth() +double Link::get_bandwidth() const { return this->pimpl_->get_bandwidth(); } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index c507a90954..83a6e16d01 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -186,7 +186,8 @@ void CpuAction::set_state(Action::State state) } /** @brief returns a list of all CPUs that this action is using */ -std::list CpuAction::cpus() { +std::list CpuAction::cpus() const +{ std::list retlist; int llen = get_variable()->get_number_of_constraint(); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index cdecf0e16d..27aa3c9f8f 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -179,7 +179,7 @@ public: void set_state(simgrid::kernel::resource::Action::State state) override; void update_remains_lazy(double now) override; - std::list cpus(); + std::list cpus() const; void suspend() override; void resume() override; diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 9bdcd82cb2..b430e8f447 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -170,7 +170,7 @@ void NetworkAction::set_state(Action::State state) } /** @brief returns a list of all Links that this action is using */ -std::list NetworkAction::links() +std::list NetworkAction::links() const { std::list retlist; int llen = get_variable()->get_number_of_constraint(); diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index de80df17ee..c3dbfc04a4 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -198,7 +198,7 @@ public: NetworkAction(Model* model, double cost, bool failed, lmm::Variable* var) : Action(model, cost, failed, var){}; void set_state(Action::State state) override; - virtual std::list links(); + virtual std::list links() const; double latency_ = {}; double lat_current_ = {}; diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 0a71792214..109906a1e2 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -339,7 +339,7 @@ void NetworkNS3Action::resume() { THROW_UNIMPLEMENTED; } -std::list NetworkNS3Action::links() +std::list NetworkNS3Action::links() const { THROW_UNIMPLEMENTED; } diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index 632fe81ccc..af200b8daf 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -50,7 +50,7 @@ public: void suspend() override; void resume() override; - std::list links() override; + std::list links() const override; void update_remains_lazy(double now) override; // private: -- 2.20.1