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){}
85 if (i!=values_.end()){
92 if (!handle_delete(child)) {
99 return handle_add(child,cfg);
104 if (!cfg[
"id"].empty()) {
106 with_same_id.
id = cfg[
"id"].str();
109 handle_delete(with_same_id);
113 return do_add(i-values_.begin(),cfg);
119 if (child.
id ==
"*") {
125 if (i!=values_.end()){
134 std::vector<component*> children;
135 for (ptr v : values_) {
136 children.push_back(&*v);
150 pos = values_.size();
153 call_factory(values,cfg);
155 for (ptr
b : values ) {
156 values_.insert(values_.begin()+pos+j,
b);
162 std::function<void(ptr_vector&, const config&)>
factory_;
183 if (child.
id ==
"default_facet") {
184 return default_.get();
192 if (child.
id ==
"default_facet") {
194 this->call_factory(values,cfg);
195 default_ = values.back();
204 children.push_back(default_.get());
215 typedef std::shared_ptr<T>
ptr;
218 aspect_property_handler(
const std::string &property, aspect_map &aspects, std::function<
void(aspect_map&,
const config&, std::string)> &construction_factory)
219 : property_(property), aspects_(aspects), factory_(construction_factory)
225 typename aspect_map::const_iterator
a = aspects_.find(child.
id);
226 if (a!=aspects_.end()){
234 if (aspects_.find(child.
id) == aspects_.end()) {
238 cfg[
"name"] =
"composite_aspect";
240 cfg[
"id"] = child.
id;
241 factory_(aspects_, cfg, child.
id);
253 if (child.
id ==
"*") {
255 for (
typename aspect_map::value_type
a : aspects_) {
256 b |=
a.second->delete_all_facets();
265 std::vector<component*> children;
266 for (
typename aspect_map::value_type
a : aspects_) {
267 children.push_back(&*
a.second);
276 std::function<void(aspect_map&, const config&, std::string)>
factory_;
282 std::vector<std::shared_ptr<X>>& values, std::function<
void(std::vector<std::shared_ptr<X>>&,
const config&)> construction_factory)
284 property_handlers.emplace(property,
290 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)
292 property_handlers.emplace(property,
298 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)
300 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)