Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add "const" to some getters of Activities.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 5 Feb 2020 09:04:09 +0000 (10:04 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 5 Feb 2020 10:13:58 +0000 (11:13 +0100)
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Io.hpp
src/s4u/s4u_Activity.cpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp

index 6632ff7..e92d768 100644 (file)
@@ -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<AnyActivity*>(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<AnyActivity*>(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<AnyActivity*>(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
index 9869018..2e891c9 100644 (file)
@@ -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
index 1bd4230..67792c1 100644 (file)
@@ -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<s4u::Host*>& hosts,
                                                   const std::vector<double>& flops_amounts,
                                                   const std::vector<double>& 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;
 };
 
index 06f7e90..2ad47c0 100644 (file)
@@ -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;
 };
 
index 374eaea..3f7404e 100644 (file)
@@ -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_;
 }
index fdaf3bc..b088052 100644 (file)
@@ -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;
 }
index 64ee26d..72ab238 100644 (file)
@@ -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<kernel::activity::ExecImpl>(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<kernel::activity::ExecImpl>(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<kernel::activity::ExecImpl>(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();
index 68adbec..a99680a 100644 (file)
@@ -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<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });