Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ai.hpp"
00022 #include "aspect.hpp"
00023 #include "goal.hpp"
00024 #include "engine_default.hpp"
00025 #include "rca.hpp"
00026 #include "stage.hpp"
00027 #include "../../foreach.hpp"
00028 #include "../../log.hpp"
00029
00030 namespace ai {
00031
00032 static lg::log_domain log_ai_engine_cpp("ai/engine/cpp");
00033 #define DBG_AI_ENGINE_CPP LOG_STREAM(debug, log_ai_engine_cpp)
00034 #define LOG_AI_ENGINE_CPP LOG_STREAM(info, log_ai_engine_cpp)
00035 #define ERR_AI_ENGINE_CPP LOG_STREAM(err, log_ai_engine_cpp)
00036
00037 engine_cpp::engine_cpp( readonly_context &context, const config &cfg )
00038 : engine(context,cfg)
00039 {
00040 name_ = "cpp";
00041 }
00042
00043 engine_cpp::~engine_cpp()
00044 {
00045 }
00046
00047
00048 void engine_cpp::do_parse_aspect_from_config( const config &cfg, const std::string &id, std::back_insert_iterator<std::vector< aspect_ptr > > b )
00049 {
00050 const std::string aspect_factory_key = id+"*"+cfg["name"];
00051 aspect_factory::factory_map::iterator f = aspect_factory::get_list().find(aspect_factory_key);
00052 if (f == aspect_factory::get_list().end()){
00053 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN aspect["<<aspect_factory_key<<"]" << std::endl;
00054 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00055 return;
00056 }
00057 aspect_ptr new_aspect = f->second->get_new_instance(ai_,cfg,id);
00058 if (!new_aspect) {
00059 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE aspect, key=["<<aspect_factory_key<<"]"<< std::endl;
00060 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00061 return;
00062 }
00063 *b = new_aspect;
00064 }
00065
00066
00067 void engine_cpp::do_parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b ){
00068 candidate_action_factory::factory_map::iterator f = candidate_action_factory::get_list().find(cfg["name"]);
00069 if (f == candidate_action_factory::get_list().end()){
00070 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN candidate_action["<<cfg["name"]<<"]"<< std::endl;
00071 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00072 return;
00073 }
00074 candidate_action_ptr new_candidate_action = f->second->get_new_instance(context,cfg);
00075 if (!new_candidate_action) {
00076 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE candidate_action["<<cfg["name"]<<"]"<< std::endl;
00077 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00078 return;
00079 }
00080 *b = new_candidate_action;
00081
00082 }
00083
00084 void engine_cpp::do_parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b )
00085 {
00086 stage_factory::factory_map::iterator f = stage_factory::get_list().find(cfg["name"]);
00087 if (f == stage_factory::get_list().end()){
00088 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN stage["<<cfg["name"]<<"]"<< std::endl;
00089 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00090 return;
00091 }
00092 stage_ptr new_stage = f->second->get_new_instance(context,cfg);
00093 if (!new_stage) {
00094 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE stage["<<cfg["name"]<<"]"<< std::endl;
00095 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00096 return;
00097 }
00098 *b = new_stage;
00099 }
00100
00101
00102 void engine_cpp::do_parse_goal_from_config(const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b )
00103 {
00104 goal_factory::factory_map::iterator f = goal_factory::get_list().find(cfg["name"]);
00105 if (f == goal_factory::get_list().end()){
00106 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN goal["<<cfg["name"]<<"]"<< std::endl;
00107 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00108 return;
00109 }
00110 goal_ptr new_goal = f->second->get_new_instance(ai_,cfg);
00111 if (!new_goal) {
00112 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE goal["<<cfg["name"]<<"]"<< std::endl;
00113 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00114 return;
00115 }
00116 *b = new_goal;
00117 }
00118
00119
00120 void engine_cpp::do_parse_engine_from_config(const config &cfg, std::back_insert_iterator<std::vector< engine_ptr > > b )
00121 {
00122 engine_factory::factory_map::iterator f = engine_factory::get_list().find(cfg["name"]);
00123 if (f == engine_factory::get_list().end()){
00124 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN engine["<<cfg["name"]<<"]"<< std::endl;
00125 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00126 return;
00127 }
00128 engine_ptr new_engine = f->second->get_new_instance(ai_,cfg);
00129 if (!new_engine) {
00130 ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNABLE TO CREATE engine["<<cfg["name"]<<"]"<< std::endl;
00131 DBG_AI_ENGINE_CPP << "config snippet contains: " << std::endl << cfg << std::endl;
00132 return;
00133 }
00134 *b = new_engine;
00135 }
00136
00137
00138 }