The Battle for Wesnoth  1.13.4+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 - 2016 by Yurii Chernyi <[email protected]>
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 #ifndef AI_COMPOSITE_COMPONENT_HPP_INCLUDED
21 #define AI_COMPOSITE_COMPONENT_HPP_INCLUDED
22 
23 class config;
24 
25 #include <iostream>
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #ifdef _MSC_VER
33 #pragma warning(push)
34 //silence "inherits via dominance" warnings
35 #pragma warning(disable:4250)
36 #endif
37 
38 //============================================================================
39 namespace ai {
40 
41 //TODO: find a good place for this
42 struct path_element {
44  : property()
45  , id()
46  , position(0)
47  {
48  }
49 
52  int position;
53 };
54 
57 typedef std::map<std::string,property_handler_ptr> property_handler_map;
58 
59 class component {
60 public:
63  {
64  }
65 
66  virtual std::string get_id() const = 0;
67  virtual std::string get_name() const = 0;
68  virtual std::string get_engine() const = 0;
69  virtual ~component() {}
70  virtual component* get_child(const path_element &child);
71  virtual std::vector<component*> get_children(const std::string &type);
72  virtual std::vector<std::string> get_children_types();
73  virtual bool change_child(const path_element &child, const config &cfg);
74  virtual bool add_child(const path_element &child, const config &cfg);
75  virtual bool delete_child(const path_element &child);
76 
77  property_handler_map& property_handlers();
78 
79 private:
80  property_handler_map property_handlers_;
81 };
82 
84 public:
85  static bool add_component(component *root, const std::string &path, const config &cfg);
86  static bool change_component(component *root, const std::string &path, const config &cfg);
87  static bool delete_component(component *root, const std::string &path);
88  static std::string print_component_tree(component *root, const std::string &path);
89 
90  static component* get_component(component *root, const std::string &path);
91 };
92 
93 
94 } //end of namespace ai
95 
96 std::ostream &operator<<(std::ostream &o, const ai::path_element &e);
97 
98 #ifdef _MSC_VER
99 #pragma warning(pop)
100 #endif
101 
102 #endif
virtual std::string get_id() const =0
virtual bool change_child(const path_element &child, const config &cfg)
Definition: component.cpp:92
property_handler_map property_handlers_
Definition: component.hpp:80
static bool change_component(component *root, const std::string &path, const config &cfg)
Definition: component.cpp:205
virtual std::vector< component * > get_children(const std::string &type)
Definition: component.cpp:112
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
property_handler_map & property_handlers()
Definition: component.cpp:133
std::ostream & operator<<(std::ostream &o, const ai::path_element &e)
Definition: component.cpp:280
virtual bool add_child(const path_element &child, const config &cfg)
Definition: component.cpp:82
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
static component * get_component(component *root, const std::string &path)
Definition: component.cpp:268
GLsizei const char ** path
Definition: glew.h:4654
GLuint id
Definition: glew.h:1647
virtual std::string get_engine() const =0
virtual component * get_child(const path_element &child)
Definition: component.cpp:72
INT property
Definition: wglew.h:144
std::string property
Definition: component.hpp:50
std::string id
Definition: component.hpp:51
virtual std::string get_name() const =0
static bool delete_component(component *root, const std::string &path)
Definition: component.cpp:219
static bool add_component(component *root, const std::string &path, const config &cfg)
Definition: component.cpp:190
virtual bool delete_child(const path_element &child)
Definition: component.cpp:102
static std::string print_component_tree(component *root, const std::string &path)
Definition: component.cpp:250
virtual std::vector< std::string > get_children_types()
Definition: component.cpp:123
std::map< std::string, property_handler_ptr > property_handler_map
Definition: component.hpp:57
#define e
boost::shared_ptr< base_property_handler > property_handler_ptr
Definition: component.hpp:55
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual ~component()
Definition: component.hpp:69
GLsizei const GLcharARB ** string
Definition: glew.h:4503