Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(sonar) : replace new by make_shared or make_unique #322

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions broker/core/inc/com/centreon/broker/mapping/entry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,7 @@ class entry {
other._source = nullptr;
}

~entry() noexcept {
// This is not the better fix, but entries are static objects
// only destroyed at the end of the program.
// if (_source) {
// delete _source;
// _source = nullptr;
// }
}
~entry() noexcept = default;
entry& operator=(entry const&) = delete;
uint32_t get_attribute() const { return _attribute; }
bool get_bool(const io::data& d) const;
Expand Down
20 changes: 10 additions & 10 deletions broker/core/src/database/mysql_stmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void mysql_stmt::operator<<(io::data const& d) {

void mysql_stmt::bind_value_as_i32(int range, int value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_i32(range, value);
}

Expand Down Expand Up @@ -458,7 +458,7 @@ void mysql_stmt::bind_value_as_i32(std::string const& name, int value) {

void mysql_stmt::bind_value_as_u32(int range, uint32_t value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_u32(range, value);
}

Expand Down Expand Up @@ -493,7 +493,7 @@ void mysql_stmt::bind_value_as_u32(std::string const& name, uint32_t value) {
*/
void mysql_stmt::bind_value_as_i64(int range, int64_t value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_i64(range, value);
}

Expand Down Expand Up @@ -534,7 +534,7 @@ void mysql_stmt::bind_value_as_i64(std::string const& name, int64_t value) {
*/
void mysql_stmt::bind_value_as_u64(int range, uint64_t value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_u64(range, value);
}

Expand Down Expand Up @@ -575,7 +575,7 @@ void mysql_stmt::bind_value_as_u64(std::string const& name, uint64_t value) {
*/
void mysql_stmt::bind_value_as_f32(int range, float value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_f32(range, value);
}

Expand Down Expand Up @@ -610,7 +610,7 @@ void mysql_stmt::bind_value_as_f32(std::string const& name, float value) {
*/
void mysql_stmt::bind_value_as_f64(int range, double value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_f64(range, value);
}

Expand Down Expand Up @@ -639,7 +639,7 @@ void mysql_stmt::bind_value_as_f64(std::string const& name, double value) {

void mysql_stmt::bind_value_as_tiny(int range, char value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_tiny(range, value);
}

Expand Down Expand Up @@ -668,7 +668,7 @@ void mysql_stmt::bind_value_as_tiny(std::string const& name, char value) {

void mysql_stmt::bind_value_as_bool(int range, bool value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_bool(range, value);
}

Expand Down Expand Up @@ -697,7 +697,7 @@ void mysql_stmt::bind_value_as_bool(std::string const& name, bool value) {

void mysql_stmt::bind_value_as_str(int range, const fmt::string_view& value) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_str(range, value);
}

Expand Down Expand Up @@ -726,7 +726,7 @@ void mysql_stmt::bind_value_as_str(std::string const& name,

void mysql_stmt::bind_value_as_null(int range) {
if (!_bind)
_bind.reset(new database::mysql_bind(_param_count));
_bind = std::make_unique<database::mysql_bind>(_param_count);
_bind->set_value_as_null(range);
}

Expand Down
8 changes: 4 additions & 4 deletions engine/src/anomalydetection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ int anomalydetection::run_async_check(int check_options,
without_thresholds = "";

// Init check result info.
std::unique_ptr<check_result> check_result_info(
new check_result(service_check, this, checkable::check_active,
check_options, reschedule_check, latency, start_time,
start_time, false, true, service::state_ok, ""));
auto check_result_info = std::make_unique<check_result>(
service_check, this, checkable::check_active, check_options,
reschedule_check, latency, start_time, start_time, false, true,
service::state_ok, "");

oss.str("");
oss.setf(std::ios_base::fixed, std::ios_base::floatfield);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/broker/compatibility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void compatibility::copyright_module(broker::handle* mod) {
void compatibility::create_module(broker::handle* mod) {
if (mod) {
// Allocate memory.
std::unique_ptr<nebmodule> new_module(new nebmodule);
auto new_module = std::make_unique<nebmodule>();

// Module parameters.
new_module->filename = string::dup(mod->get_filename());
Expand Down
2 changes: 1 addition & 1 deletion engine/src/broker/handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void handle::open() {
return;

try {
_handle = std::shared_ptr<library>(new library(_filename));
_handle = std::make_shared<library>(_filename);
_handle->load();

int api_version(*static_cast<int*>(_handle->resolve("__neb_api_version")));
Expand Down
2 changes: 1 addition & 1 deletion engine/src/broker/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace com::centreon::engine::logging;
*/
std::shared_ptr<broker::handle> loader::add_module(std::string const& filename,
std::string const& args) {
std::shared_ptr<handle> module(new handle(filename, args));
auto module = std::make_shared<handle>(filename, args);
_modules.push_back(module);
return module;
}
Expand Down
4 changes: 2 additions & 2 deletions engine/src/commands/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ int cmd_add_comment(int cmd, time_t entry_time, char* args) {
return ERROR;

/* add the comment */
std::shared_ptr<comment> com{new comment(
auto com = std::make_shared<comment>(
(cmd == CMD_ADD_HOST_COMMENT) ? comment::host : comment::service,
comment::user, temp_host->get_host_id(), service_id, entry_time, user,
comment_data, persistent, comment::external, false, (time_t)0)};
comment_data, persistent, comment::external, false, (time_t)0);
uint64_t comment_id = com->get_comment_id();
comment::comments.insert({comment_id, com});
log_v2::external_command()->trace("{}, comment_id: {}, data: {}",
Expand Down
4 changes: 2 additions & 2 deletions engine/src/commands/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ uint64_t connector::run(const std::string& processed_cmd,

// Set query informations.
uint64_t command_id(get_uniq_id());
std::shared_ptr<query_info> info(new query_info);
auto info = std::make_shared<query_info>();
info->processed_cmd = processed_cmd;
info->start_time = timestamp::now();
info->timeout = timeout;
Expand Down Expand Up @@ -197,7 +197,7 @@ void connector::run(const std::string& processed_cmd,

// Set query informations.
uint64_t command_id(get_uniq_id());
std::shared_ptr<query_info> info(new query_info);
auto info = std::make_shared<query_info>();
info->processed_cmd = processed_cmd;
info->start_time = timestamp::now();
info->timeout = timeout;
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void applier::command::modify_object(configuration::command const& obj) {
// not referenced anywhere, only ::command objects are.
commands::command::commands.erase(obj.command_name());
if (obj.connector().empty()) {
std::shared_ptr<commands::raw> raw{new commands::raw(
obj.command_name(), obj.command_line(), &checks::checker::instance())};
auto raw = std::make_shared<commands::raw>(
obj.command_name(), obj.command_line(), &checks::checker::instance());
commands::command::commands[raw->get_name()] = raw;
} else {
connector_map::iterator found_con{
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void applier::connector::add_object(configuration::connector const& obj) {
config->connectors().insert(obj);

// Create connector.
std::shared_ptr<commands::connector> cmd(new commands::connector(
obj.connector_name(), processed_cmd, &checks::checker::instance()));
auto cmd = std::make_shared<commands::connector>(
obj.connector_name(), processed_cmd, &checks::checker::instance());
commands::connector::connectors[obj.connector_name()] = cmd;
}

Expand Down
3 changes: 1 addition & 2 deletions engine/src/configuration/applier/contactgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ void applier::contactgroup::add_object(configuration::contactgroup const& obj) {
config->contactgroups().insert(obj);

// Create contact group.
std::shared_ptr<engine::contactgroup> cg{new engine::contactgroup(obj)};

auto cg = std::make_shared<engine::contactgroup>(obj);
for (set_string::const_iterator it(obj.members().begin()),
end(obj.members().end());
it != end; ++it) {
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void applier::host::add_object(configuration::host const& obj) {
config->hosts().insert(obj);

// Create host.
std::shared_ptr<com::centreon::engine::host> h{new engine::host(
auto h = std::make_shared<com::centreon::engine::host>(
obj.host_id(), obj.host_name(), obj.display_name(), obj.alias(),
obj.address(), obj.check_period(),
static_cast<engine::host::host_state>(obj.initial_state()),
Expand Down Expand Up @@ -95,7 +95,7 @@ void applier::host::add_object(configuration::host const& obj) {
obj.have_coords_3d(),
true, // should_be_drawn, enabled by Nagios
obj.retain_status_information(), obj.retain_nonstatus_information(),
obj.obsess_over_host(), obj.timezone(), obj.icon_id())};
obj.obsess_over_host(), obj.timezone(), obj.icon_id());

engine::host::hosts.insert({h->name(), h});
engine::host::hosts_by_id.insert({obj.host_id(), h});
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/hostescalation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void applier::hostescalation::add_object(
config->hostescalations().insert(obj);

// Create host escalation.
std::shared_ptr<engine::hostescalation> he{new engine::hostescalation(
auto he = std::make_shared<engine::hostescalation>(
*obj.hosts().begin(), obj.first_notification(), obj.last_notification(),
obj.notification_interval(), obj.escalation_period(),
((obj.escalation_options() & configuration::hostescalation::down)
Expand All @@ -73,7 +73,7 @@ void applier::hostescalation::add_object(
((obj.escalation_options() & configuration::hostescalation::recovery)
? notifier::up
: notifier::none),
obj.uuid())};
obj.uuid());

// Add new items to the configuration state.
engine::hostescalation::hostescalations.insert({he->get_hostname(), he});
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/hostgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void applier::hostgroup::add_object(configuration::hostgroup const& obj) {
config->hostgroups().insert(obj);

// Create host group.
std::shared_ptr<com::centreon::engine::hostgroup> hg{new engine::hostgroup(
auto hg = std::make_shared<com::centreon::engine::hostgroup>(
obj.hostgroup_id(), obj.hostgroup_name(), obj.alias(), obj.notes(),
obj.notes_url(), obj.action_url())};
obj.notes_url(), obj.action_url());

// Add new items to the configuration state.
engine::hostgroup::hostgroups.insert({hg->get_group_name(), hg});
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/serviceescalation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void applier::serviceescalation::add_object(
config->serviceescalations().insert(obj);

// Create service escalation.
std::shared_ptr<engine::serviceescalation> se{new engine::serviceescalation(
auto se = std::make_shared<engine::serviceescalation>(
obj.hosts().front(), obj.service_description().front(),
obj.first_notification(), obj.last_notification(),
obj.notification_interval(), obj.escalation_period(),
Expand All @@ -83,7 +83,7 @@ void applier::serviceescalation::add_object(
configuration::serviceescalation::recovery)
? notifier::ok
: notifier::none),
obj.uuid())};
obj.uuid());

// Add new items to the global list.
engine::serviceescalation::serviceescalations.insert(
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/servicegroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ void applier::servicegroup::add_object(configuration::servicegroup const& obj) {
config->servicegroups().insert(obj);

// Create servicegroup.
std::shared_ptr<engine::servicegroup> sg{new engine::servicegroup(
auto sg = std::make_shared<engine::servicegroup>(
obj.servicegroup_id(), obj.servicegroup_name(), obj.alias(), obj.notes(),
obj.notes_url(), obj.action_url())};
obj.notes_url(), obj.action_url());

// Add new items to the list.
engine::servicegroup::servicegroups.insert({sg->get_group_name(), sg});
Expand Down
4 changes: 2 additions & 2 deletions engine/src/configuration/applier/timeperiod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void applier::timeperiod::add_object(configuration::timeperiod const& obj) {
config->timeperiods().insert(obj);

// Create time period.
std::shared_ptr<engine::timeperiod> tp{
new engine::timeperiod(obj.timeperiod_name(), obj.alias())};
auto tp =
std::make_shared<engine::timeperiod>(obj.timeperiod_name(), obj.alias());

engine::timeperiod::timeperiods.insert({obj.timeperiod_name(), tp});

Expand Down
36 changes: 18 additions & 18 deletions engine/src/configuration/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,41 @@ bool object::operator!=(object const& right) const noexcept {
object_ptr object::create(std::string const& type_name) {
object_ptr obj;
if (type_name == "service")
obj = object_ptr(new configuration::service());
obj = std::make_shared<configuration::service>();
else if (type_name == "host")
obj = object_ptr(new configuration::host());
obj = std::make_shared<configuration::host>();
else if (type_name == "contact")
obj = object_ptr(new configuration::contact());
obj = std::make_shared<configuration::contact>();
else if (type_name == "contactgroup")
obj = object_ptr(new configuration::contactgroup());
obj = std::make_shared<configuration::contactgroup>();
else if (type_name == "servicegroup")
obj = object_ptr(new configuration::servicegroup());
obj = std::make_shared<configuration::servicegroup>();
else if (type_name == "hostgroup")
obj = object_ptr(new configuration::hostgroup());
obj = std::make_shared<configuration::hostgroup>();
else if (type_name == "servicedependency")
obj = object_ptr(new configuration::servicedependency());
obj = std::make_shared<configuration::servicedependency>();
else if (type_name == "serviceescalation")
obj = object_ptr(new configuration::serviceescalation());
obj = std::make_shared<configuration::serviceescalation>();
else if (type_name == "hostdependency")
obj = object_ptr(new configuration::hostdependency());
obj = std::make_shared<configuration::hostdependency>();
else if (type_name == "hostescalation")
obj = object_ptr(new configuration::hostescalation());
obj = std::make_shared<configuration::hostescalation>();
else if (type_name == "command")
obj = object_ptr(new configuration::command());
obj = std::make_shared<configuration::command>();
else if (type_name == "timeperiod")
obj = object_ptr(new configuration::timeperiod());
obj = std::make_shared<configuration::timeperiod>();
else if (type_name == "connector")
obj = object_ptr(new configuration::connector());
obj = std::make_shared<configuration::connector>();
else if (type_name == "serviceextinfo")
obj = object_ptr(new configuration::serviceextinfo());
obj = std::make_shared<configuration::serviceextinfo>();
else if (type_name == "hostextinfo")
obj = object_ptr(new configuration::hostextinfo());
obj = std::make_shared<configuration::hostextinfo>();
else if (type_name == "anomalydetection")
obj = object_ptr(new configuration::anomalydetection());
obj = std::make_shared<configuration::anomalydetection>();
else if (type_name == "severity")
obj = object_ptr(new configuration::severity());
obj = std::make_shared<configuration::severity>();
else if (type_name == "tag")
obj = object_ptr(new configuration::tag());
obj = std::make_shared<configuration::tag>();
return obj;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/contact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ std::shared_ptr<contact> add_contact(
}

// Allocate memory for a new contact.
std::shared_ptr<contact> obj(new contact);
auto obj = std::make_shared<contact>();

try {
// Duplicate vars.
Expand Down
8 changes: 4 additions & 4 deletions engine/src/downtimes/host_downtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ int host_downtime::subscribe() {

/* add a non-persistent comment to the host or service regarding the scheduled
* outage */
std::shared_ptr<comment> com{
new comment(comment::host, comment::downtime, hst->get_host_id(), 0,
time(NULL), "(Centreon Engine Process)", oss.str(), false,
comment::internal, false, (time_t)0)};
auto com = std::make_shared<comment>(
comment::host, comment::downtime, hst->get_host_id(), 0, time(NULL),
"(Centreon Engine Process)", oss.str(), false, comment::internal, false,
(time_t)0);

comment::comments.insert({com->get_comment_id(), com});
_comment_id = com->get_comment_id();
Expand Down
7 changes: 4 additions & 3 deletions engine/src/events/loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ void loop::_dispatching() {
else {
if (notifier::soft == temp_service->get_state_type() &&
temp_service->get_current_state() != service::state_ok)
temp_service->set_next_check((time_t)(
temp_service->get_next_check() +
temp_service->retry_interval() * config->interval_length()));
temp_service->set_next_check(
(time_t)(temp_service->get_next_check() +
temp_service->retry_interval() *
config->interval_length()));
else
temp_service->set_next_check(
(time_t)(temp_service->get_next_check() +
Expand Down
Loading