The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
component.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2017 by Yurii Chernyi <terraninfo@terraninfo.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * A component of the AI framework
18  */
19 
20 #pragma once
21 
22 class config;
23 
24 #include <iostream>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 //silence "inherits via dominance" warnings
33 #pragma warning(disable:4250)
34 #endif
35 
36 //============================================================================
37 namespace ai {
38 
39 //TODO: find a good place for this
40 struct path_element {
42  : property()
43  , id()
44  , position(0)
45  {
46  }
47 
50  int position;
51 };
52 
54 typedef std::shared_ptr<base_property_handler> property_handler_ptr;
55 typedef std::map<std::string,property_handler_ptr> property_handler_map;
56 
57 class component {
58 public:
61  {
62  }
63 
64  virtual std::string get_id() const = 0;
65  virtual std::string get_name() const = 0;
66  virtual std::string get_engine() const = 0;
67  virtual ~component() {}
68  virtual component* get_child(const path_element &child);
69  virtual std::vector<component*> get_children(const std::string &type);
70  virtual std::vector<std::string> get_children_types();
71  virtual bool change_child(const path_element &child, const config &cfg);
72  virtual bool add_child(const path_element &child, const config &cfg);
73  virtual bool delete_child(const path_element &child);
74 
75  property_handler_map& property_handlers();
76 
77 private:
78  property_handler_map property_handlers_;
79 };
80 
82 public:
83  static bool add_component(component *root, const std::string &path, const config &cfg);
84  static bool change_component(component *root, const std::string &path, const config &cfg);
85  static bool delete_component(component *root, const std::string &path);
86  static std::string print_component_tree(component *root, const std::string &path);
87 
88  static component* get_component(component *root, const std::string &path);
89 };
90 
91 
92 } //end of namespace ai
93 
94 std::ostream &operator<<(std::ostream &o, const ai::path_element &e);
95 
96 #ifdef _MSC_VER
97 #pragma warning(pop)
98 #endif
virtual std::string get_id() const =0
virtual bool change_child(const path_element &child, const config &cfg)
Definition: component.cpp:91
std::vector< char_t > string
property_handler_map property_handlers_
Definition: component.hpp:78
static bool change_component(component *root, const std::string &path, const config &cfg)
Definition: component.cpp:204
virtual std::vector< component * > get_children(const std::string &type)
Definition: component.cpp:111
property_handler_map & property_handlers()
Definition: component.cpp:132
std::ostream & operator<<(std::ostream &o, const ai::path_element &e)
Definition: component.cpp:279
virtual bool add_child(const path_element &child, const config &cfg)
Definition: component.cpp:81
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
static component * get_component(component *root, const std::string &path)
Definition: component.cpp:267
virtual std::string get_engine() const =0
virtual component * get_child(const path_element &child)
Definition: component.cpp:71
std::string path
Definition: game_config.cpp:56
std::string property
Definition: component.hpp:48
std::string id
Definition: component.hpp:49
virtual std::string get_name() const =0
static bool delete_component(component *root, const std::string &path)
Definition: component.cpp:218
static bool add_component(component *root, const std::string &path, const config &cfg)
Definition: component.cpp:189
virtual bool delete_child(const path_element &child)
Definition: component.cpp:101
static std::string print_component_tree(component *root, const std::string &path)
Definition: component.cpp:249
virtual std::vector< std::string > get_children_types()
Definition: component.cpp:122
std::map< std::string, property_handler_ptr > property_handler_map
Definition: component.hpp:55
#define e
std::shared_ptr< base_property_handler > property_handler_ptr
Definition: component.hpp:53
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
virtual ~component()
Definition: component.hpp:67