The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
3 by Yurii Chernyi <terraninfo@terraninfo.net>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16/**
17 * @file
18 * A component of the AI framework
19 */
20
21#pragma once
22
23class config;
24
25#include <map>
26#include <memory>
27#include <string>
28#include <vector>
29
30//============================================================================
31namespace ai {
32
35 : property()
36 , id()
37 , position(0)
38 {
39 }
40
41 std::string property;
42 std::string id;
44};
45
47typedef std::shared_ptr<base_property_handler> property_handler_ptr;
48typedef std::map<std::string,property_handler_ptr> property_handler_map;
49
50class component {
51public:
54 {
55 }
56
57 virtual std::string get_id() const = 0;
58 virtual std::string get_name() const = 0;
59 virtual std::string get_engine() const = 0;
60 virtual ~component() {}
61 virtual component* get_child(const path_element &child) const;
62 virtual std::vector<component*> get_children(const std::string &type) const;
63 virtual std::vector<std::string> get_children_types() const;
64 virtual bool change_child(const path_element &child, const config &cfg);
65 virtual bool add_child(const path_element &child, const config &cfg);
66 virtual bool delete_child(const path_element &child);
67
69
70private:
72};
73
75public:
76 static bool add_component(component *root, const std::string &path, const config &cfg);
77 static bool change_component(component *root, const std::string &path, const config &cfg);
78 static bool delete_component(component *root, const std::string &path);
79 static std::string print_component_tree(component *root, const std::string &path);
80
81 static component* get_component(component *root, const std::string &path);
82};
83
84} //end of namespace ai
85
86std::ostream &operator<<(std::ostream &o, const ai::path_element &e);
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 component * get_child(const path_element &child) const
Definition component.cpp:61
virtual ~component()
Definition component.hpp:60
virtual bool delete_child(const path_element &child)
Definition component.cpp:88
virtual std::string get_engine() const =0
virtual bool change_child(const path_element &child, const config &cfg)
Definition component.cpp:79
virtual std::string get_name() const =0
virtual bool add_child(const path_element &child, const config &cfg)
Definition component.cpp:70
virtual std::vector< std::string > get_children_types() const
virtual std::string get_id() const =0
property_handler_map & property_handlers()
virtual std::vector< component * > get_children(const std::string &type) const
Definition component.cpp:97
property_handler_map property_handlers_
Definition component.hpp:71
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
std::ostream & operator<<(std::ostream &o, const ai::path_element &e)
const config * cfg
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition actions.cpp:59
std::shared_ptr< base_property_handler > property_handler_ptr
Definition component.hpp:47
std::map< std::string, property_handler_ptr > property_handler_map
Definition component.hpp:48
std::string property
Definition component.hpp:41
std::string id
Definition component.hpp:42
#define e