From: Arnaud Giersch Date: Wed, 5 Feb 2020 09:04:09 +0000 (+0100) Subject: Add "const" to some getters of Activities. X-Git-Tag: v3.26~1036 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/28eb3a76b321b4aa13364641811925a2f8af769a?ds=sidebyside Add "const" to some getters of Activities. --- diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index 6632ff7e77..e92d768c4a 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -88,15 +88,15 @@ public: /** Cancel that activity */ virtual Activity* cancel() = 0; /** Retrieve the current state of the activity */ - Activity::State get_state() { return state_; } + Activity::State get_state() const { return state_; } void set_state(Activity::State state) { state_ = state; } /** Tests whether the given activity is terminated yet. This is a pure function. */ virtual bool test() = 0; - virtual const char* get_cname() = 0; - virtual const std::string& get_name() = 0; + virtual const char* get_cname() const = 0; + virtual const std::string& get_name() const = 0; /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */ - virtual double get_remaining(); + virtual double get_remaining() const; /** Set the [remaining] amount of work that this Activity will entail * * It is forbidden to change the amount of work once the Activity is started */ @@ -149,8 +149,8 @@ public: name_ = name; return static_cast(this); } - const std::string& get_name() { return name_; } - const char* get_cname() { return name_.c_str(); } + const std::string& get_name() const override { return name_; } + const char* get_cname() const override { return name_.c_str(); } AnyActivity* set_tracing_category(const std::string& category) { @@ -158,7 +158,7 @@ public: tracing_category_ = category; return static_cast(this); } - const std::string& get_tracing_category() { return tracing_category_; } + const std::string& get_tracing_category() const { return tracing_category_; } AnyActivity* set_user_data(void* data) { @@ -166,7 +166,7 @@ public: return static_cast(this); } - void* get_user_data() { return user_data_; } + void* get_user_data() const { return user_data_; } #ifndef DOXYGEN /* The refcounting is done in the ancestor class, Activity, but we want each of the classes benefiting of the CRTP * (Exec, Comm, etc) to have smart pointers too, so we define these methods here, that forward the ptr_release and diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 9869018004..2e891c9249 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -113,11 +113,11 @@ public: CommPtr set_tracing_category(const std::string& category); /** Retrieve the mailbox on which this comm acts */ - Mailbox* get_mailbox(); + Mailbox* get_mailbox() const; /** Retrieve the size of the received data. Not to be mixed with @ref Activity::set_remaining() */ - size_t get_dst_data_size(); + size_t get_dst_data_size() const; - Actor* get_sender(); + Actor* get_sender() const; }; } // namespace s4u } // namespace simgrid diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 1bd4230d97..67792c1efb 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -52,7 +52,7 @@ public: Exec* start() override = 0; /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on * parallel executions. */ - virtual double get_remaining_ratio() = 0; + virtual double get_remaining_ratio() const = 0; virtual ExecPtr set_host(Host* host) = 0; Exec* wait() override; @@ -90,8 +90,8 @@ public: ExecPtr set_host(Host* host) override; - double get_remaining() override; - double get_remaining_ratio() override; + double get_remaining() const override; + double get_remaining_ratio() const override; }; class XBT_PUBLIC ExecPar : public Exec { @@ -107,8 +107,8 @@ public: friend XBT_PUBLIC ExecPtr this_actor::exec_init(const std::vector& hosts, const std::vector& flops_amounts, const std::vector& bytes_amounts); - double get_remaining() override; - double get_remaining_ratio() override; + double get_remaining() const override; + double get_remaining_ratio() const override; Exec* start() override; }; diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index 06f7e90916..2ad47c0493 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -46,7 +46,7 @@ public: Io* cancel() override; bool test() override; - double get_remaining() override; + double get_remaining() const override; sg_size_t get_performed_ioops() const; }; diff --git a/src/s4u/s4u_Activity.cpp b/src/s4u/s4u_Activity.cpp index 374eaeae5d..3f7404ed2a 100644 --- a/src/s4u/s4u_Activity.cpp +++ b/src/s4u/s4u_Activity.cpp @@ -21,7 +21,7 @@ void Activity::wait_until(double time_limit) wait_for(time_limit - now); } -double Activity::get_remaining() +double Activity::get_remaining() const { return remains_; } diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index fdaf3bcbda..b088052cc1 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -97,7 +97,7 @@ CommPtr Comm::set_dst_data(void** buff) return this; } -size_t Comm::get_dst_data_size() +size_t Comm::get_dst_data_size() const { xbt_assert(state_ == State::FINISHED, "You cannot use %s before your communication terminated", __FUNCTION__); return dst_buff_size_; @@ -241,12 +241,12 @@ bool Comm::test() return false; } -Mailbox* Comm::get_mailbox() +Mailbox* Comm::get_mailbox() const { return mailbox_; } -Actor* Comm::get_sender() +Actor* Comm::get_sender() const { return sender_ ? sender_->ciface() : nullptr; } diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 64ee26d95b..72ab23817d 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -166,7 +166,7 @@ ExecPtr ExecSeq::set_host(Host* host) return this; } -double ExecSeq::get_remaining() +double ExecSeq::get_remaining() const { return kernel::actor::simcall( [this]() { return boost::static_pointer_cast(pimpl_)->get_remaining(); }); @@ -176,7 +176,7 @@ double ExecSeq::get_remaining() * * The returned value is between 0 (completely done) and 1 (nothing done yet). */ -double ExecSeq::get_remaining_ratio() +double ExecSeq::get_remaining_ratio() const { return kernel::actor::simcall( [this]() { return boost::static_pointer_cast(pimpl_)->get_seq_remaining_ratio(); }); @@ -204,13 +204,13 @@ Exec* ExecPar::start() return this; } -double ExecPar::get_remaining_ratio() +double ExecPar::get_remaining_ratio() const { return kernel::actor::simcall( [this]() { return boost::static_pointer_cast(pimpl_)->get_par_remaining_ratio(); }); } -double ExecPar::get_remaining() +double ExecPar::get_remaining() const { XBT_WARN("Calling get_remaining() on a parallel execution is not allowed. Call get_remaining_ratio() instead."); return get_remaining_ratio(); diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index 68adbec381..a99680ae49 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -90,7 +90,7 @@ bool Io::test() } /** @brief Returns the amount of flops that remain to be done */ -double Io::get_remaining() +double Io::get_remaining() const { return kernel::actor::simcall( [this]() { return boost::static_pointer_cast(pimpl_)->get_remaining(); });