From c80e506ca90704241bcc5cc37c3736ae772e0b63 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 29 Apr 2018 06:09:03 +1100 Subject: [PATCH] AI: deployed std::make_shared in a whole bunch of places Also simplified a few instance of shared_ptr assignment. No need to create a temp ptr just to immediately assign them. (cherry-picked from commit ba150c02981fd07bdbc9c3ebf305600754d89aba) --- src/ai/composite/aspect.hpp | 9 +++------ src/ai/composite/engine.hpp | 2 +- src/ai/composite/property_handler.hpp | 12 ++++++------ src/ai/composite/rca.hpp | 2 +- src/ai/formula/engine_fai.cpp | 4 ++-- src/ai/formula/function_table.cpp | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/ai/composite/aspect.hpp b/src/ai/composite/aspect.hpp index 2410758b08a1..884e5c580ca3 100644 --- a/src/ai/composite/aspect.hpp +++ b/src/ai/composite/aspect.hpp @@ -379,8 +379,7 @@ class standard_aspect : public typesafe_aspect { : typesafe_aspect(context, cfg, id) { this->name_ = "standard_aspect"; - std::shared_ptr value(new T(config_value_translator::cfg_to_value(this->cfg_))); - this->value_= value; + this->value_ = std::make_shared(config_value_translator::cfg_to_value(this->cfg_)); LOG_STREAM(debug, aspect::log()) << "standard aspect has value: "<< std::endl << config_value_translator::value_to_cfg(this->get()) << std::endl; } @@ -502,8 +501,7 @@ class register_aspect_factory : public aspect_factory { aspect_ptr get_new_instance( readonly_context &context, const config &cfg, const std::string &id) { - std::shared_ptr _a(new ASPECT(context,cfg,id)); - aspect_ptr a = _a; + aspect_ptr a = std::make_shared(context, cfg, id); a->on_create(); return a; } @@ -544,8 +542,7 @@ class register_lua_aspect_factory : public lua_aspect_factory { aspect_ptr get_new_instance( readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr& l_ctx) { - std::shared_ptr _a(new ASPECT(context,cfg,id,l_ctx)); - aspect_ptr a = _a; + aspect_ptr a = std::make_shared(context, cfg, id, l_ctx); a->on_create(); return a; } diff --git a/src/ai/composite/engine.hpp b/src/ai/composite/engine.hpp index 9dd78bc9b90a..22ffa84207d9 100644 --- a/src/ai/composite/engine.hpp +++ b/src/ai/composite/engine.hpp @@ -165,7 +165,7 @@ class register_engine_factory : public engine_factory { config cfg; cfg["name"] = name; cfg["engine"] = "cpp"; // @Crab: what is the purpose of this line(neph) - return engine_ptr(new ENGINE(ai,cfg)); + return std::make_shared(ai, cfg); } }; diff --git a/src/ai/composite/property_handler.hpp b/src/ai/composite/property_handler.hpp index 3ad9a4490b8d..e89c5f99bd20 100644 --- a/src/ai/composite/property_handler.hpp +++ b/src/ai/composite/property_handler.hpp @@ -290,24 +290,24 @@ template static inline void register_vector_property(property_handler_map& property_handlers, const std::string& property, std::vector>& values, std::function>&, const config&)> construction_factory) { - property_handler_ptr handler_ptr(new vector_property_handler(property, values, construction_factory)); - property_handlers.emplace(property, handler_ptr); + property_handlers.emplace(property, + std::make_shared>(property, values, construction_factory)); } template static inline void register_facets_property(property_handler_map& property_handlers, const std::string& property, std::vector>& values, std::shared_ptr& def, std::function>&, const config&)> construction_factory) { - property_handler_ptr handler_ptr(new facets_property_handler(property, values, def, construction_factory)); - property_handlers.emplace(property, handler_ptr); + property_handlers.emplace(property, + std::make_shared>(property, values, def, construction_factory)); } template static inline void register_aspect_property(property_handler_map& property_handlers, const std::string& property, std::map>& aspects, std::function>&, const config&, std::string)> construction_factory) { - property_handler_ptr handler_ptr(new aspect_property_handler(property, aspects, construction_factory)); - property_handlers.emplace(property, handler_ptr); + property_handlers.emplace(property, + std::make_shared>(property, aspects, construction_factory)); } } //of namespace ai diff --git a/src/ai/composite/rca.hpp b/src/ai/composite/rca.hpp index cdb9f3c553c7..26fa62455a19 100644 --- a/src/ai/composite/rca.hpp +++ b/src/ai/composite/rca.hpp @@ -181,7 +181,7 @@ class register_candidate_action_factory : public candidate_action_factory { } virtual candidate_action_ptr get_new_instance( rca_context &ai, const config &cfg ){ - return candidate_action_ptr(new CANDIDATE_ACTION(ai,cfg)); + return std::make_shared(ai, cfg); } }; diff --git a/src/ai/formula/engine_fai.cpp b/src/ai/formula/engine_fai.cpp index d853bfb51a9e..fd059936f215 100644 --- a/src/ai/formula/engine_fai.cpp +++ b/src/ai/formula/engine_fai.cpp @@ -105,9 +105,9 @@ void engine_fai::do_parse_stage_from_config( ai_context &context, const config & // st_ptr = stage_ptr(new stage_rca_formulas(context,cfg,formula_ai_)); if (name=="side_formulas") { - st_ptr = stage_ptr(new stage_side_formulas(context,cfg,*formula_ai_)); + st_ptr = std::make_shared(context, cfg, *formula_ai_); } else if (name=="unit_formulas") { - st_ptr = stage_ptr(new stage_unit_formulas(context,cfg,*formula_ai_)); + st_ptr = std::make_shared(context, cfg, *formula_ai_); } else { ERR_AI_ENGINE_FAI << "unknown type of formula_ai stage: ["<< name <<"]"<& args) const { - return function_expression_ptr(new T(args, ai_)); + return std::make_shared(args, ai_); } };