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
00022 #ifndef AI_COMPOSITE_ENGINE_HPP_INCLUDED
00023 #define AI_COMPOSITE_ENGINE_HPP_INCLUDED
00024
00025 #include "component.hpp"
00026 #include "../contexts.hpp"
00027
00028 #include <algorithm>
00029 #include <iterator>
00030
00031
00032
00033 namespace ai {
00034
00035 class rca_context;
00036 class ai_context;
00037 class component;
00038
00039 class engine : public component {
00040 public:
00041 engine( readonly_context &context, const config &cfg );
00042
00043
00044 virtual ~engine();
00045
00046
00047 static void parse_aspect_from_config( readonly_context &context, const config &cfg, const std::string &id, std::back_insert_iterator<std::vector< aspect_ptr > > b );
00048
00049
00050 static void parse_goal_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b );
00051
00052
00053 static void parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b );
00054
00055
00056 static void parse_engine_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< engine_ptr > > b );
00057
00058
00059 static void parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b );
00060
00061
00062
00063 virtual void do_parse_aspect_from_config( const config &cfg, const std::string &id, std::back_insert_iterator< std::vector< aspect_ptr> > b );
00064
00065
00066
00067 virtual void do_parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b );
00068
00069
00070 virtual void do_parse_goal_from_config( const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b );
00071
00072
00073 virtual void do_parse_engine_from_config( const config &cfg, std::back_insert_iterator<std::vector< engine_ptr > > b );
00074
00075
00076
00077 virtual void do_parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b );
00078
00079
00080 virtual std::string evaluate(const std::string& str);
00081
00082 readonly_context& get_readonly_context();
00083
00084
00085
00086
00087 virtual void set_ai_context(ai_context_ptr context);
00088
00089 virtual ai_context_ptr get_ai_context();
00090
00091
00092
00093 virtual config to_config() const;
00094
00095
00096 virtual std::string get_id() const
00097 { return id_; }
00098
00099 virtual std::string get_engine() const
00100 { return engine_; }
00101
00102 virtual std::string get_name() const
00103 { return name_; }
00104
00105 protected:
00106 readonly_context &ai_;
00107 ai_context_ptr ai_context_;
00108
00109
00110 std::string engine_;
00111 std::string id_;
00112 std::string name_;
00113 };
00114
00115
00116 class engine_factory;
00117
00118 class engine_factory{
00119 public:
00120 typedef boost::shared_ptr< engine_factory > factory_ptr;
00121 typedef std::map<std::string, factory_ptr> factory_map;
00122 typedef std::pair<const std::string, factory_ptr> factory_map_pair;
00123
00124 static factory_map& get_list() {
00125 static factory_map *engine_factories;
00126 if (engine_factories==NULL) {
00127 engine_factories = new factory_map;
00128 }
00129 return *engine_factories;
00130 }
00131
00132 virtual engine_ptr get_new_instance( readonly_context &ai, const config &cfg ) = 0;
00133 virtual engine_ptr get_new_instance( readonly_context &ai, const std::string& name ) = 0;
00134
00135 engine_factory( const std::string &name )
00136 {
00137 factory_ptr ptr_to_this(this);
00138 get_list().insert(make_pair(name,ptr_to_this));
00139 }
00140
00141 virtual ~engine_factory() {}
00142 };
00143
00144
00145 template<class ENGINE>
00146 class register_engine_factory : public engine_factory {
00147 public:
00148 register_engine_factory( const std::string &name )
00149 : engine_factory( name )
00150 {
00151 }
00152
00153 virtual engine_ptr get_new_instance( readonly_context &ai, const config &cfg ){
00154 return engine_ptr(new ENGINE(ai,cfg));
00155 }
00156
00157 virtual engine_ptr get_new_instance( readonly_context &ai, const std::string& name ){
00158 config cfg;
00159 cfg["name"] = name;
00160 cfg["engine"] = "cpp";
00161 return engine_ptr(new ENGINE(ai,cfg));
00162 }
00163 };
00164
00165 }
00166
00167 #endif