30 #include <boost/regex.hpp> 41 #define DBG_AI_COMPONENT LOG_STREAM(debug, log_ai_component) 42 #define LOG_AI_COMPONENT LOG_STREAM(info, log_ai_component) 43 #define ERR_AI_COMPONENT LOG_STREAM(err, log_ai_component) 73 if (i!=property_handlers_.end()) {
74 return i->second->handle_get(child);
82 if (i!=property_handlers_.end()) {
83 return i->second->handle_add(child,cfg);
91 if (i!=property_handlers_.end()) {
92 return i->second->handle_change(child,cfg);
100 if (i!=property_handlers_.end()) {
101 return i->second->handle_delete(child);
106 std::vector<component*> component::get_children(
const std::string &
type)
109 if (i!=property_handlers_.end()) {
110 return i->second->handle_get_children();
113 return std::vector<component*>();
116 std::vector<std::string> component::get_children_types()
118 std::vector<std::string> types;
119 for (property_handler_map::value_type &ph : property_handlers_) {
120 types.push_back(ph.first);
127 return property_handlers_;
137 boost::regex re(R
"""(([^\.^\[]+)(\[(\d*)\]|\[([^\]]+)\]|()))"""); 138 const int sub_matches[] {1,3,4};
139 boost::sregex_token_iterator
i(path.begin(), path.end(), re, sub_matches);
140 boost::sregex_token_iterator j;
144 std::vector< path_element > elements;
149 std::string position = *
i++;
151 if (position.empty()) {
156 }
catch (
const std::invalid_argument&) {
161 elements.push_back(pe);
163 if (elements.size()<1) {
210 bool component_manager::delete_component(
component *root,
const std::string &
path)
222 std::stringstream offset_ss;
223 for (
int i=0;
i<offset;++
i) {
226 const std::string &offset_str = offset_ss.str();
232 for (std::string
t : t_list) {
240 std::string component_manager::print_component_tree(
component *root,
const std::string &
path)
271 o <<
"property["<<e.
property<<
"] id["<<e.
id <<
"] position["<<e.
position<<
"]"<<std::endl;
virtual std::string get_id() const =0
virtual bool change_child(const path_element &child, const config &cfg)
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
virtual std::vector< component * > get_children(const std::string &type)
AI Support engine - creating specific ai components from config.
Definitions for the interface to Wesnoth Markup Language (WML).
virtual bool add_child(const path_element &child, const config &cfg)
static component * find_component(component *root, const std::string &path, path_element &tail)
A small explanation about what's going on here: Each action has access to two game_info objects First...
static void print_component(component *root, const std::string &type, std::stringstream &s, int offset)
virtual std::string get_engine() const =0
A component of the AI framework.
std::ostream & operator<<(std::ostream &o, const ai::path_element &e)
virtual component * get_child(const path_element &child)
virtual std::string get_name() const =0
static lg::log_domain log_ai_component("ai/component")
virtual bool delete_child(const path_element &child)
static map_location::DIRECTION s
const config & get_child(const std::string &key)
virtual std::vector< std::string > get_children_types()
std::map< std::string, property_handler_ptr > property_handler_map
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
std::string::const_iterator iterator