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.
This commit is contained in:
Charles Dang 2018-04-29 06:09:03 +11:00
parent 1e846aced2
commit ba150c0298
6 changed files with 14 additions and 17 deletions

View file

@ -379,8 +379,7 @@ public:
: typesafe_aspect<T>(context, cfg, id)
{
this->name_ = "standard_aspect";
std::shared_ptr<T> value(new T(config_value_translator<T>::cfg_to_value(this->cfg_)));
this->value_= value;
this->value_ = std::make_shared<T>(config_value_translator<T>::cfg_to_value(this->cfg_));
LOG_STREAM(debug, aspect::log()) << "standard aspect has value: "<< std::endl << config_value_translator<T>::value_to_cfg(this->get()) << std::endl;
}
@ -502,8 +501,7 @@ public:
aspect_ptr get_new_instance( readonly_context &context, const config &cfg, const std::string &id)
{
std::shared_ptr<ASPECT> _a(new ASPECT(context,cfg,id));
aspect_ptr a = _a;
aspect_ptr a = std::make_shared<ASPECT>(context, cfg, id);
a->on_create();
return a;
}
@ -544,8 +542,7 @@ public:
aspect_ptr get_new_instance( readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr<lua_ai_context>& l_ctx)
{
std::shared_ptr<ASPECT> _a(new ASPECT(context,cfg,id,l_ctx));
aspect_ptr a = _a;
aspect_ptr a = std::make_shared<ASPECT>(context, cfg, id, l_ctx);
a->on_create();
return a;
}

View file

@ -165,7 +165,7 @@ public:
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<ENGINE>(ai, cfg);
}
};

View file

@ -290,24 +290,24 @@ template<typename X>
static inline void register_vector_property(property_handler_map& property_handlers, const std::string& property,
std::vector<std::shared_ptr<X>>& values, std::function<void(std::vector<std::shared_ptr<X>>&, const config&)> construction_factory)
{
property_handler_ptr handler_ptr(new vector_property_handler<X>(property, values, construction_factory));
property_handlers.emplace(property, handler_ptr);
property_handlers.emplace(property,
std::make_shared<vector_property_handler<X>>(property, values, construction_factory));
}
template<typename X>
static inline void register_facets_property(property_handler_map& property_handlers, const std::string& property,
std::vector<std::shared_ptr<X>>& values, std::shared_ptr<X>& def, std::function<void(std::vector<std::shared_ptr<X>>&, const config&)> construction_factory)
{
property_handler_ptr handler_ptr(new facets_property_handler<X>(property, values, def, construction_factory));
property_handlers.emplace(property, handler_ptr);
property_handlers.emplace(property,
std::make_shared<facets_property_handler<X>>(property, values, def, construction_factory));
}
template<typename X>
static inline void register_aspect_property(property_handler_map& property_handlers, const std::string& property,
std::map<std::string, std::shared_ptr<X>>& aspects, std::function<void(std::map<std::string, std::shared_ptr<X>>&, const config&, std::string)> construction_factory)
{
property_handler_ptr handler_ptr(new aspect_property_handler<X>(property, aspects, construction_factory));
property_handlers.emplace(property, handler_ptr);
property_handlers.emplace(property,
std::make_shared<aspect_property_handler<X>>(property, aspects, construction_factory));
}
} //of namespace ai

View file

@ -181,7 +181,7 @@ public:
}
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<CANDIDATE_ACTION>(ai, cfg);
}
};

View file

@ -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<stage_side_formulas>(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<stage_unit_formulas>(context, cfg, *formula_ai_);
} else {
ERR_AI_ENGINE_FAI << "unknown type of formula_ai stage: ["<< name <<"]"<<std::endl;
}

View file

@ -1092,7 +1092,7 @@ protected:
public:
ai_formula_function(const std::string& name, ai::formula_ai& ai) : formula_function(name), ai_(ai) {}
function_expression_ptr generate_function_expression(const std::vector<expression_ptr>& args) const {
return function_expression_ptr(new T(args, ai_));
return std::make_shared<T>(args, ai_);
}
};