67 virtual bool handle_delete(
const path_element &child) = 0;
68 virtual std::vector< component* > handle_get_children() = 0;
76 typedef std::shared_ptr<T>
ptr;
80 : factory_(construction_factory), property_(property), values_(values){}
86 if (i!=values_.end()){
93 if (!handle_delete(child)) {
100 return handle_add(child,cfg);
105 if (!cfg[
"id"].empty()) {
107 with_same_id.
id = cfg[
"id"].str();
110 handle_delete(with_same_id);
114 return do_add(i-values_.begin(),cfg);
120 if (child.
id ==
"*") {
126 if (i!=values_.end()){
136 std::vector<component*> children;
137 for (ptr v : values_) {
138 children.push_back(&*v);
152 pos = values_.size();
155 call_factory(values,cfg);
157 for (ptr
b : values ) {
158 values_.insert(values_.begin()+pos+j,
b);
164 std::function<void(ptr_vector&, const config&)>
factory_;
187 if (child.
id ==
"default_facet") {
188 return default_.get();
196 if (child.
id ==
"default_facet") {
198 this->call_factory(values,cfg);
199 default_ = values.back();
208 children.push_back(default_.get());
221 typedef std::shared_ptr<T>
ptr;
224 aspect_property_handler(
const std::string &property, aspect_map &aspects, std::function<
void(aspect_map&,
const config&, std::string)> &construction_factory)
225 : property_(property), aspects_(aspects), factory_(construction_factory)
232 typename aspect_map::const_iterator
a = aspects_.find(child.
id);
233 if (a!=aspects_.end()){
241 if (aspects_.find(child.
id) == aspects_.end()) {
245 cfg[
"name"] =
"composite_aspect";
247 cfg[
"id"] = child.
id;
248 factory_(aspects_, cfg, child.
id);
260 if (child.
id ==
"*") {
262 for (
typename aspect_map::value_type
a : aspects_) {
263 b |=
a.second->delete_all_facets();
273 std::vector<component*> children;
274 for (
typename aspect_map::value_type
a : aspects_) {
275 children.push_back(&*
a.second);
284 std::function<void(aspect_map&, const config&, std::string)>
factory_;
291 std::vector<std::shared_ptr<X>>& values, std::function<
void(std::vector<std::shared_ptr<X>>&,
const config&)> construction_factory)
293 property_handlers.emplace(property,
299 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)
301 property_handlers.emplace(property,
307 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)
309 property_handlers.emplace(property,
const std::string property_
std::vector< component * > handle_get_children()
bool has_attribute(config_key_type key) const
void call_factory(ptr_vector &vec, const config &cfg)
bool handle_add(const path_element &, const config &)
bool handle_add(const path_element &child, const config &cfg)
vector_property_handler(const std::string &property, ptr_vector &values, std::function< void(ptr_vector &, const config &)> &construction_factory)
Definitions for the interface to Wesnoth Markup Language (WML).
static 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)
std::vector< component * > handle_get_children()
bool handle_delete(const path_element &child)
bool handle_delete(const path_element &child)
facets_property_handler(const std::string &property, ptr_vector &values, ptr &def, std::function< void(ptr_vector &, const config &)> &construction_factory)
A small explanation about what's going on here: Each action has access to two game_info objects First...
component * handle_get(const path_element &child)
bool operator()(const T &t)
std::vector< component * > handle_get_children()
virtual ~base_property_handler()
std::vector< std::shared_ptr< T > > ptr_vector
path_element_matches(const path_element &element)
A component of the AI framework.
bool handle_change(const path_element &child, config cfg)
const std::string & property_
vector_property_handler< T >::ptr ptr
virtual ~path_element_matches()
bool do_add(int pos, const config &cfg)
component * handle_get(const path_element &child)
std::function< void(ptr_vector &, const config &)> factory_
std::map< std::string, ptr > aspect_map
bool handle_change(const path_element &child, config cfg)
std::map< std::string, property_handler_ptr > property_handler_map
component * handle_get(const path_element &child)
std::function< void(aspect_map &, const config &, std::string)> factory_
vector_property_handler< T >::ptr_vector ptr_vector
static 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)
std::shared_ptr< base_property_handler > property_handler_ptr
A config object defines a single node in a WML file, with access to child nodes.
bool handle_change(const path_element &child, config cfg)
std::string::const_iterator iterator
static 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)
aspect_property_handler(const std::string &property, aspect_map &aspects, std::function< void(aspect_map &, const config &, std::string)> &construction_factory)