27 #include <boost/regex.hpp>
32 #define DBG_AI_COMPONENT LOG_STREAM(debug, log_ai_component)
33 #define LOG_AI_COMPONENT LOG_STREAM(info, log_ai_component)
34 #define ERR_AI_COMPONENT LOG_STREAM(err, log_ai_component)
65 return i->second->handle_get(child);
74 return i->second->handle_add(child,cfg);
83 return i->second->handle_change(child,cfg);
92 return i->second->handle_delete(child);
101 return i->second->handle_get_children();
104 return std::vector<component*>();
109 std::vector<std::string> types;
111 types.push_back(ph.first);
128 boost::regex re(R
"(([^\.^\[]+)(\[(\d*)\]|\[([^\]]+)\]|()))");
129 const int sub_matches[] {1,3,4};
130 boost::sregex_token_iterator
i(
path.begin(),
path.end(), re, sub_matches);
131 boost::sregex_token_iterator j;
135 std::vector< path_element > elements;
140 std::string position = *
i++;
142 if (position.empty()) {
147 }
catch (
const std::invalid_argument&) {
152 elements.push_back(pe);
154 if (elements.size()<1) {
161 c =
c->get_child(*k);
183 return c->add_child(tail, *ch);
198 return c->change_child(tail, *ch);
208 return c->delete_child(tail);
213 std::stringstream offset_ss;
214 for (
int i=0;
i<offset;++
i) {
217 const std::string &offset_str = offset_ss.str();
223 for (std::string
t : t_list) {
262 o <<
"property["<<
e.property<<
"] id["<<
e.id <<
"] position["<<
e.position<<
"]"<<std::endl;
static bool delete_component(component *root, const std::string &path)
static component * get_component(component *root, const std::string &path)
static bool change_component(component *root, const std::string &path, const config &cfg)
static bool add_component(component *root, const std::string &path, const config &cfg)
static std::string print_component_tree(component *root, const std::string &path)
virtual bool delete_child(const path_element &child)
virtual std::string get_engine() const =0
virtual bool change_child(const path_element &child, const config &cfg)
virtual component * get_child(const path_element &child)
virtual std::string get_name() const =0
virtual bool add_child(const path_element &child, const config &cfg)
virtual std::vector< component * > get_children(const std::string &type)
virtual std::string get_id() const =0
property_handler_map & property_handlers()
virtual std::vector< std::string > get_children_types()
property_handler_map property_handlers_
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
std::ostream & operator<<(std::ostream &o, const ai::path_element &e)
A component of the AI framework.
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
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)
static lg::log_domain log_ai_component("ai/component")
std::map< std::string, property_handler_ptr > property_handler_map
static component * find_component(component *root, const std::string &path, path_element &tail)
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
std::string::const_iterator iterator
static map_location::direction s