From: Martin Quinson Date: Thu, 17 May 2018 19:54:16 +0000 (+0200) Subject: Enum values are in UPPER_SNAKE_CASE X-Git-Tag: v3.20~215^2~4 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/27f991037b8d3e6181741b3ca41df44b64b66d4d Enum values are in UPPER_SNAKE_CASE --- diff --git a/README.coding b/README.coding index 1154448c53..c2fd8fbfbe 100644 --- a/README.coding +++ b/README.coding @@ -24,7 +24,8 @@ SimGrid4 will follow the these rules: (because of a bug in Sonar coverage computation) C++ - fields, methods and variables are in snake_case() - - Classes and Enum are in UpperCamelCase + - Classes and Enum names are in UpperCamelCase + - Enum values are in UPPER_SNAKE_CASE (as constants) - public filenames: api_Class.cpp and api/Class.hpp. - Example: src/s4u/s4u_ConditionVariable.cpp and include/simgrid/s4u/ConditionVariable.hpp diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index b91347cb16..feb9d7b6de 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -32,7 +32,7 @@ public: Activity(Activity const&) = delete; Activity& operator=(Activity const&) = delete; - enum class State { inited = 0, started, canceled, errored, finished }; + enum class State { INITED = 0, STARTED, CANCELED, ERRORED, FINISHED }; /** Starts a previously created activity. * @@ -82,7 +82,7 @@ public: private: simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr; - Activity::State state_ = Activity::State::inited; + Activity::State state_ = Activity::State::INITED; double remains_ = 0; void* user_data_ = nullptr; }; // class diff --git a/src/s4u/s4u_Activity.cpp b/src/s4u/s4u_Activity.cpp index d3eaaefd23..9ef1d5f6a1 100644 --- a/src/s4u/s4u_Activity.cpp +++ b/src/s4u/s4u_Activity.cpp @@ -22,7 +22,7 @@ double Activity::get_remaining() Activity* Activity::set_remaining(double remains) { - xbt_assert(state_ == State::inited, "Cannot change the remaining amount of work once the Activity is started"); + xbt_assert(state_ == State::INITED, "Cannot change the remaining amount of work once the Activity is started"); remains_ = remains; return this; } diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index e9c1692b35..c231d1e59e 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -15,7 +15,7 @@ namespace simgrid { namespace s4u { Comm::~Comm() { - if (state_ == State::started && not detached_ && (pimpl_ == nullptr || pimpl_->state_ == SIMIX_RUNNING)) { + if (state_ == State::STARTED && not detached_ && (pimpl_ == nullptr || pimpl_->state_ == SIMIX_RUNNING)) { XBT_INFO("Comm %p freed before its completion. Detached: %d, State: %d", this, detached_, (int)state_); if (pimpl_ != nullptr) XBT_INFO("pimpl_->state: %d", pimpl_->state_); @@ -32,9 +32,9 @@ int Comm::wait_any_for(std::vector* comms_in, double timeout) intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr); }); for (auto const& comm : *comms_in) { - if (comm->state_ == Activity::State::inited) + if (comm->state_ == Activity::State::INITED) comm->start(); - xbt_assert(comm->state_ == Activity::State::started); + xbt_assert(comm->state_ == Activity::State::STARTED); simgrid::kernel::activity::ActivityImpl* ptr = comm->pimpl_.get(); intrusive_ptr_add_ref(ptr); xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, ptr); @@ -56,27 +56,27 @@ void Comm::wait_all(std::vector* comms) Activity* Comm::set_rate(double rate) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); rate_ = rate; return this; } Activity* Comm::set_src_data(void* buff) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); src_buff_ = buff; return this; } Activity* Comm::set_src_data_size(size_t size) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); src_buff_size_ = size; return this; } Activity* Comm::set_src_data(void* buff, size_t size) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); src_buff_ = buff; @@ -85,19 +85,19 @@ Activity* Comm::set_src_data(void* buff, size_t size) } Activity* Comm::set_dst_data(void** buff) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); dst_buff_ = buff; return this; } size_t Comm::get_dst_data_size() { - xbt_assert(state_ == State::finished); + xbt_assert(state_ == State::FINISHED); return dst_buff_size_; } Activity* Comm::set_dst_data(void** buff, size_t size) { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); dst_buff_ = buff; @@ -107,7 +107,7 @@ Activity* Comm::set_dst_data(void** buff, size_t size) Activity* Comm::start() { - xbt_assert(state_ == State::inited); + xbt_assert(state_ == State::INITED); if (src_buff_ != nullptr) { // Sender side pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, @@ -120,7 +120,7 @@ Activity* Comm::start() } else { xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver"); } - state_ = State::started; + state_ = State::STARTED; return this; } @@ -139,10 +139,10 @@ Activity* Comm::wait() Activity* Comm::wait(double timeout) { switch (state_) { - case State::finished: + case State::FINISHED: return this; - case State::inited: // It's not started yet. Do it in one simcall + case State::INITED: // It's not started yet. Do it in one simcall if (src_buff_ != nullptr) { simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, copy_data_function_, user_data_, timeout); @@ -150,12 +150,12 @@ Activity* Comm::wait(double timeout) simcall_comm_recv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_, user_data_, timeout, rate_); } - state_ = State::finished; + state_ = State::FINISHED; return this; - case State::started: + case State::STARTED: simcall_comm_wait(pimpl_, timeout); - state_ = State::finished; + state_ = State::FINISHED; return this; default: @@ -176,7 +176,7 @@ int Comm::test_any(std::vector* comms) Activity* Comm::detach() { - xbt_assert(state_ == State::inited, "You cannot detach communications once they are started (not implemented)."); + xbt_assert(state_ == State::INITED, "You cannot detach communications once they are started (not implemented)."); xbt_assert(src_buff_ != nullptr && src_buff_size_ != 0, "You can only detach sends, not recvs"); detached_ = true; return start(); @@ -192,16 +192,16 @@ Activity* Comm::cancel() bool Comm::test() { - xbt_assert(state_ == State::inited || state_ == State::started || state_ == State::finished); + xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED); - if (state_ == State::finished) + if (state_ == State::FINISHED) return true; - if (state_ == State::inited) + if (state_ == State::INITED) this->start(); if (simcall_comm_test(pimpl_)) { - state_ = State::finished; + state_ = State::FINISHED; return true; } return false; diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 607e50ebc5..94e63f78ce 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -17,14 +17,14 @@ Activity* Exec::start() { pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1. / priority_, 0., host_); boost::static_pointer_cast(pimpl_)->set_bound(bound_); - state_ = State::started; + state_ = State::STARTED; return this; } Activity* Exec::wait() { simcall_execution_wait(pimpl_); - state_ = State::finished; + state_ = State::FINISHED; return this; } @@ -37,16 +37,16 @@ Activity* Exec::wait(double timeout) /** @brief Returns whether the state of the exec is finished */ bool Exec::test() { - xbt_assert(state_ == State::inited || state_ == State::started || state_ == State::finished); + xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED); - if (state_ == State::finished) + if (state_ == State::FINISHED) return true; - if (state_ == State::inited) + if (state_ == State::INITED) this->start(); if (simcall_execution_test(pimpl_)) { - state_ = State::finished; + state_ = State::FINISHED; return true; } @@ -61,7 +61,7 @@ bool Exec::test() * Currently, this cannot be changed once the exec started. */ ExecPtr Exec::set_priority(double priority) { - xbt_assert(state_ == State::inited, "Cannot change the priority of an exec after its start"); + xbt_assert(state_ == State::INITED, "Cannot change the priority of an exec after its start"); priority_ = priority; return this; } @@ -72,7 +72,7 @@ ExecPtr Exec::set_priority(double priority) * Currently, this cannot be changed once the exec started. */ ExecPtr Exec::set_bound(double bound) { - xbt_assert(state_ == State::inited, "Cannot change the bound of an exec after its start"); + xbt_assert(state_ == State::INITED, "Cannot change the bound of an exec after its start"); bound_ = bound; return this; } @@ -82,9 +82,9 @@ ExecPtr Exec::set_bound(double bound) * The activity cannot be terminated already (but it may be started). */ ExecPtr Exec::set_host(Host* host) { - xbt_assert(state_ == State::inited || state_ == State::started, + xbt_assert(state_ == State::INITED || state_ == State::STARTED, "Cannot change the host of an exec once it's done (state: %d)", (int)state_); - if (state_ == State::started) + if (state_ == State::STARTED) boost::static_pointer_cast(pimpl_)->migrate(host); host_ = host; return this;