Skip to content

Commit 3e0ca36

Browse files
committed
const and noexcept
1 parent 87eb75e commit 3e0ca36

10 files changed

Lines changed: 66 additions & 54 deletions

File tree

include/dtlmod/DTL.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class DTL {
2828

2929
protected:
3030
/// \cond EXCLUDE_FROM_DOCUMENTATION
31-
void lock() { mutex_->lock(); }
32-
void unlock() { mutex_->unlock(); }
31+
void lock() noexcept { mutex_->lock(); }
32+
void unlock() noexcept { mutex_->unlock(); }
3333
/// \endcond
3434

3535
public:
@@ -49,7 +49,7 @@ class DTL {
4949

5050
/// @brief Helper function to check whether some simulated actors are currently connected to the DTL.
5151
/// @return A boolean value.
52-
bool has_active_connections() const { return !active_connections_.empty(); }
52+
bool has_active_connections() const noexcept { return !active_connections_.empty(); }
5353

5454
/// @brief Add a data stream to the Data Transport Layer.
5555
/// @param name The name of the Stream to add to the DTL.
@@ -58,7 +58,7 @@ class DTL {
5858

5959
/// @brief Retrieve all streams declared in the Data Transport Layer.
6060
/// @return a map of handlers on Stream objects with their names as keys.
61-
const std::unordered_map<std::string, std::shared_ptr<Stream>>& get_all_streams() const { return streams_; }
61+
const std::unordered_map<std::string, std::shared_ptr<Stream>>& get_all_streams() const noexcept { return streams_; }
6262

6363
/// @brief Retrieve a data stream from the Data Transport Layer by its name.
6464
/// @param name The name of the Stream to retrieve.

include/dtlmod/Engine.hpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,26 @@ class Engine {
8282

8383
virtual void create_transport(const Transport::Method& transport_method) = 0;
8484

85-
void set_transport(std::shared_ptr<Transport> transport) { transport_ = transport; }
86-
[[nodiscard]] std::shared_ptr<Transport> get_transport() const { return transport_; }
85+
void set_transport(std::shared_ptr<Transport> transport) noexcept { transport_ = transport; }
86+
[[nodiscard]] std::shared_ptr<Transport> get_transport() const noexcept { return transport_; }
8787

8888
void add_publisher(sg4::ActorPtr actor);
89-
void rm_publisher(sg4::ActorPtr actor) { publishers_.erase(actor); }
90-
[[nodiscard]] bool is_publisher(sg4::ActorPtr actor) const { return publishers_.find(actor) != publishers_.end(); }
89+
void rm_publisher(sg4::ActorPtr actor) noexcept { publishers_.erase(actor); }
90+
[[nodiscard]] bool is_publisher(sg4::ActorPtr actor) const noexcept
91+
{
92+
return publishers_.find(actor) != publishers_.end();
93+
}
9194
// Synchronize publishers on engine closing
9295
[[nodiscard]] int is_last_publisher() const { return (pub_barrier_ && pub_barrier_->wait()); }
9396

9497
void add_subscriber(sg4::ActorPtr actor);
95-
void rm_subscriber(sg4::ActorPtr actor) { subscribers_.erase(actor); }
96-
[[nodiscard]] bool is_subscriber(sg4::ActorPtr actor) const { return subscribers_.find(actor) != subscribers_.end(); }
98+
void rm_subscriber(sg4::ActorPtr actor) noexcept { subscribers_.erase(actor); }
99+
[[nodiscard]] bool is_subscriber(sg4::ActorPtr actor) const noexcept
100+
{
101+
return subscribers_.find(actor) != subscribers_.end();
102+
}
97103
// Synchronize subscribers on engine closing
98-
[[nodiscard]] int is_last_subscriber() const { return subscribers_.empty(); }
104+
[[nodiscard]] int is_last_subscriber() const noexcept { return subscribers_.empty(); }
99105

100106
void set_metadata_file_name();
101107
/// \endcond
@@ -108,19 +114,21 @@ class Engine {
108114
}
109115
virtual ~Engine() = default;
110116
// Public accessors for Transport classes to access ActivitySets
111-
[[nodiscard]] sg4::ActivitySet& get_pub_transaction() { return pub_transaction_; }
112-
[[nodiscard]] sg4::ActivitySet& get_sub_transaction() { return sub_transaction_; }
113-
[[nodiscard]] const std::set<sg4::ActorPtr>& get_publishers() const { return publishers_; }
114-
[[nodiscard]] size_t get_num_publishers() const { return publishers_.size(); }
115-
[[nodiscard]] size_t get_num_subscribers() const { return subscribers_.size(); }
117+
[[nodiscard]] const sg4::ActivitySet& get_pub_transaction() const noexcept { return pub_transaction_; }
118+
[[nodiscard]] sg4::ActivitySet& get_pub_transaction() noexcept { return pub_transaction_; }
119+
[[nodiscard]] const sg4::ActivitySet& get_sub_transaction() const noexcept { return sub_transaction_; }
120+
[[nodiscard]] sg4::ActivitySet& get_sub_transaction() noexcept { return sub_transaction_; }
121+
[[nodiscard]] const std::set<sg4::ActorPtr>& get_publishers() const noexcept { return publishers_; }
122+
[[nodiscard]] size_t get_num_publishers() const noexcept { return publishers_.size(); }
123+
[[nodiscard]] size_t get_num_subscribers() const noexcept { return subscribers_.size(); }
116124
/// \endcond
117125

118126
/// @brief Helper function to print out the name of the Engine.
119127
/// @return the corresponding string
120-
[[nodiscard]] const std::string& get_name() const { return name_; }
128+
[[nodiscard]] const std::string& get_name() const noexcept { return name_; }
121129
/// @brief Helper function to print out the name of the Engine.
122130
/// @return the corresponding C-string
123-
[[nodiscard]] const char* get_cname() const { return name_.c_str(); }
131+
[[nodiscard]] const char* get_cname() const noexcept { return name_.c_str(); }
124132

125133
/// @brief Start a transaction on an Engine.
126134
void begin_transaction();
@@ -143,11 +151,11 @@ class Engine {
143151

144152
/// @brief Get the id of the current transaction (on the Publish side).
145153
/// @return The id of the ongoing transaction.
146-
[[nodiscard]] unsigned int get_current_transaction() const { return current_pub_transaction_id_; }
154+
[[nodiscard]] unsigned int get_current_transaction() const noexcept { return current_pub_transaction_id_; }
147155

148156
/// @brief Get the name of the file in which the engine stored metadata
149157
/// @return The name of the file.
150-
[[nodiscard]] const std::string& get_metadata_file_name() const { return metadata_file_; }
158+
[[nodiscard]] const std::string& get_metadata_file_name() const noexcept { return metadata_file_; }
151159

152160
/// @brief Close the Engine associated to a Stream.
153161
void close();

include/dtlmod/FileTransport.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ class FileTransport : public Transport {
3131
void close_pub_files() const;
3232
void close_sub_files(sg4::ActorPtr self);
3333
const std::vector<std::pair<std::shared_ptr<sgfs::File>, sg_size_t>>&
34-
get_to_write_in_transaction_by_actor(sg4::ActorPtr actor)
34+
get_to_write_in_transaction_by_actor(sg4::ActorPtr actor) noexcept
3535
{
3636
return to_write_in_transaction_[actor];
3737
}
38-
void clear_to_write_in_transaction(sg4::ActorPtr actor) { to_write_in_transaction_[actor].clear(); }
38+
void clear_to_write_in_transaction(sg4::ActorPtr actor) noexcept { to_write_in_transaction_[actor].clear(); }
3939

4040
const std::vector<std::pair<std::shared_ptr<sgfs::File>, sg_size_t>>&
41-
get_to_read_in_transaction_by_actor(sg4::ActorPtr actor)
41+
get_to_read_in_transaction_by_actor(sg4::ActorPtr actor) noexcept
4242
{
4343
return to_read_in_transaction_[actor];
4444
}
45-
void clear_to_read_in_transaction(sg4::ActorPtr actor) { to_read_in_transaction_[actor].clear(); }
45+
void clear_to_read_in_transaction(sg4::ActorPtr actor) noexcept { to_read_in_transaction_[actor].clear(); }
4646

4747
public:
4848
void put(std::shared_ptr<Variable> var, size_t size) override;

include/dtlmod/Metadata.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Metadata {
4040
const std::string& filename, sg4::ActorPtr publisher);
4141

4242
public:
43-
explicit Metadata(Variable* variable) : variable_(variable) {}
44-
unsigned int get_current_transaction() const
43+
explicit Metadata(Variable* variable) noexcept : variable_(variable) {}
44+
unsigned int get_current_transaction() const noexcept
4545
{
4646
return transaction_infos_.empty() ? 0 : (transaction_infos_.rbegin())->first;
4747
}

include/dtlmod/StagingTransport.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class StagingTransport : public Transport {
2626

2727
// Create a message queue to receive request for variable pieces from subscribers
2828
void set_publisher_put_requests_mq(const std::string& publisher_name);
29-
[[nodiscard]] sg4::MessageQueue* get_publisher_put_requests_mq(const std::string& publisher_name) const;
30-
[[nodiscard]] bool pending_put_requests_exist_for(const std::string& pub_name)
29+
[[nodiscard]] sg4::MessageQueue* get_publisher_put_requests_mq(const std::string& publisher_name) const noexcept;
30+
[[nodiscard]] bool pending_put_requests_exist_for(const std::string& pub_name) noexcept
3131
{
3232
return not pending_put_requests_[pub_name].empty();
3333
}
34-
[[nodiscard]] sg4::ActivityPtr wait_any_pending_put_request_for(const std::string& pub_name)
34+
[[nodiscard]] sg4::ActivityPtr wait_any_pending_put_request_for(const std::string& pub_name) noexcept
3535
{
3636
return pending_put_requests_[pub_name].wait_any();
3737
}

include/dtlmod/Stream.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ class Stream : public std::enable_shared_from_this<Stream> {
5151

5252
protected:
5353
/// \cond EXCLUDE_FROM_DOCUMENTATION
54-
[[nodiscard]] const Transport::Method& get_transport_method() const { return transport_method_; }
55-
[[nodiscard]] const std::unordered_map<std::string, std::shared_ptr<Variable>>& get_all_variables_internal() const
54+
[[nodiscard]] const Transport::Method& get_transport_method() const noexcept { return transport_method_; }
55+
[[nodiscard]] const std::unordered_map<std::string, std::shared_ptr<Variable>>&
56+
get_all_variables_internal() const noexcept
5657
{
5758
return variables_;
5859
}
59-
[[nodiscard]] const char* mode_to_str(Mode mode) const
60+
[[nodiscard]] const char* mode_to_str(Mode mode) const noexcept
6061
{
6162
return (mode == Mode::Publish) ? "Mode::Publish" : "Mode::Subscribe";
6263
}
63-
void close() { engine_ = nullptr; }
64+
void close() noexcept { engine_ = nullptr; }
6465

6566
// Helper methods for Stream::open
6667
void validate_open_parameters(const std::string& name, Mode mode) const;
@@ -79,10 +80,10 @@ class Stream : public std::enable_shared_from_this<Stream> {
7980

8081
/// @brief Helper function to print out the name of the Stream.
8182
/// @return The corresponding string
82-
[[nodiscard]] const std::string& get_name() const { return name_; }
83+
[[nodiscard]] const std::string& get_name() const noexcept { return name_; }
8384
/// @brief Helper function to print out the name of the Stream.
8485
/// @return The corresponding C-string
85-
[[nodiscard]] const char* get_cname() const { return name_.c_str(); }
86+
[[nodiscard]] const char* get_cname() const noexcept { return name_.c_str(); }
8687
/// @brief Helper function to print out the Engine::Type of the Stream.
8788
/// @return The corresponding C-string
8889
[[nodiscard]] const char* get_engine_type_str() const;
@@ -91,13 +92,13 @@ class Stream : public std::enable_shared_from_this<Stream> {
9192
[[nodiscard]] const char* get_transport_method_str() const;
9293
/// @brief Helper function to know the access Mode of the Stream.
9394
/// @return The corresponding Stream::Mode
94-
[[nodiscard]] Mode get_access_mode() const { return access_mode_; }
95+
[[nodiscard]] Mode get_access_mode() const noexcept { return access_mode_; }
9596
/// @brief Helper function to print out the access Mode of the Stream.
9697
/// @return The corresponding C-string
97-
[[nodiscard]] const char* get_access_mode_str() const { return mode_to_str(access_mode_); }
98+
[[nodiscard]] const char* get_access_mode_str() const noexcept { return mode_to_str(access_mode_); }
9899
/// @brief Helper function to know if the Stream does export metadata or not
99100
/// @return a boolean indicating if the Stream does export metadata or not
100-
[[nodiscard]] bool does_export_metadata() const { return metadata_export_; }
101+
[[nodiscard]] bool does_export_metadata() const noexcept { return metadata_export_; }
101102

102103
/// @brief Stream configuration function: set the Engine type to create.
103104
/// @param engine_type The type of Engine to create when opening the Stream.
@@ -124,10 +125,10 @@ class Stream : public std::enable_shared_from_this<Stream> {
124125

125126
/// @brief Helper function to obtain the number of actors connected to Stream in Mode::Publish.
126127
/// @return The number of publishers for that Stream.
127-
[[nodiscard]] size_t get_num_publishers() const { return engine_->get_num_publishers(); }
128+
[[nodiscard]] size_t get_num_publishers() const noexcept { return engine_->get_num_publishers(); }
128129
/// @brief Helper function to obtain the number of actors connected to Stream in Mode::Subscribe.
129130
/// @return The number of subscribers for that Stream.
130-
[[nodiscard]] size_t get_num_subscribers() const { return engine_->get_num_subscribers(); }
131+
[[nodiscard]] size_t get_num_subscribers() const noexcept { return engine_->get_num_subscribers(); }
131132

132133
/******* Variable Factory *******/
133134

include/dtlmod/Transport.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class Transport {
3232
public:
3333
enum class Method { Undefined, File, Mailbox, MQ };
3434

35-
explicit Transport(Engine* engine) : engine_(engine) {}
35+
explicit Transport(Engine* engine) noexcept : engine_(engine) {}
3636
virtual ~Transport() = default;
3737

38-
Engine* get_engine() { return engine_; }
38+
Engine* get_engine() noexcept { return engine_; }
3939

4040
virtual void put(std::shared_ptr<Variable> var, size_t simulated_size_in_bytes) = 0;
4141
virtual void get(std::shared_ptr<Variable> var) = 0;

include/dtlmod/Variable.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class Variable {
4444
public:
4545
/// \cond EXCLUDE_FROM_DOCUMENTATION
4646
// Public accessors for Transport classes
47-
void set_transaction_start(unsigned int start) { transaction_start_ = start; }
48-
[[nodiscard]] unsigned int get_transaction_start() const { return transaction_start_; }
49-
void set_transaction_count(unsigned int count) { transaction_count_ = count; }
50-
[[nodiscard]] unsigned int get_transaction_count() const { return transaction_count_; }
47+
void set_transaction_start(unsigned int start) noexcept { transaction_start_ = start; }
48+
[[nodiscard]] unsigned int get_transaction_start() const noexcept { return transaction_start_; }
49+
void set_transaction_count(unsigned int count) noexcept { transaction_count_ = count; }
50+
[[nodiscard]] unsigned int get_transaction_count() const noexcept { return transaction_count_; }
5151

5252
void set_local_start_and_count(sg4::ActorPtr actor,
5353
const std::pair<std::vector<size_t>, std::vector<size_t>>& local_start_and_count)
@@ -86,17 +86,17 @@ class Variable {
8686

8787
/// @brief Helper function to print out the name of the Variable.
8888
/// @return The corresponding string.
89-
[[nodiscard]] const std::string& get_name() const { return name_; }
89+
[[nodiscard]] const std::string& get_name() const noexcept { return name_; }
9090
/// @brief Helper function to print out the name of the Variable.
9191
/// @return The corresponding C-string.
92-
[[nodiscard]] const char* get_cname() const { return name_.c_str(); }
92+
[[nodiscard]] const char* get_cname() const noexcept { return name_.c_str(); }
9393

9494
/// @brief Get the shape of the Variable.
9595
/// @return A vector of the respective size in each dimension of the Variable.
96-
[[nodiscard]] const std::vector<size_t>& get_shape() const { return shape_; }
96+
[[nodiscard]] const std::vector<size_t>& get_shape() const noexcept { return shape_; }
9797
/// @brief Get the size of the elements stored in the Variable.
9898
/// @return The elements' size.
99-
[[nodiscard]] size_t get_element_size() const { return element_size_; }
99+
[[nodiscard]] size_t get_element_size() const noexcept { return element_size_; }
100100

101101
/// @brief Get the global size of the Variable.
102102
/// @return The computed size.

src/DTL.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ __attribute__((noreturn)) void DTL::connection_manager_init(std::shared_ptr<DTL>
103103
handler_mq->put_init(&dtl)->detach();
104104
} else { // Disconnection
105105
dtl->connection_manager_disconnect(sender);
106-
handler_mq->put_init(new bool(true))->detach();
106+
auto payload = std::make_unique<bool>(true);
107+
handler_mq->put_init(payload.release())->detach();
107108
if (!dtl->has_active_connections())
108109
XBT_WARN("The DTL has no active connection");
109110
}
@@ -126,14 +127,16 @@ void DTL::create(const std::string& filename)
126127

127128
std::shared_ptr<DTL> DTL::connect()
128129
{
129-
sg4::MessageQueue::by_name("dtlmod::connection_manager_connect")->put(new bool(true));
130+
auto payload = std::make_unique<bool>(true);
131+
sg4::MessageQueue::by_name("dtlmod::connection_manager_connect")->put(payload.release());
130132
const auto* handle = sg4::MessageQueue::by_name("dtlmod::connection_manager_handle")->get<std::shared_ptr<DTL>>();
131133
return *handle;
132134
}
133135

134136
void DTL::disconnect()
135137
{
136-
sg4::MessageQueue::by_name("dtlmod::connection_manager_connect")->put(new bool(false));
138+
auto payload = std::make_unique<bool>(false);
139+
sg4::MessageQueue::by_name("dtlmod::connection_manager_connect")->put(payload.release());
137140
sg4::MessageQueue::by_name("dtlmod::connection_manager_handle")->get_unique<bool>();
138141
}
139142

src/StagingTransport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void StagingTransport::set_publisher_put_requests_mq(const std::string& publishe
2525
publisher_put_requests_mq_[publisher_name] = sg4::MessageQueue::by_name(publisher_name);
2626
}
2727

28-
sg4::MessageQueue* StagingTransport::get_publisher_put_requests_mq(const std::string& publisher_name) const
28+
sg4::MessageQueue* StagingTransport::get_publisher_put_requests_mq(const std::string& publisher_name) const noexcept
2929
{
3030
return publisher_put_requests_mq_.at(publisher_name);
3131
}

0 commit comments

Comments
 (0)