ai/composite/component.hpp

Go to the documentation of this file.
00001 /* $Id: component.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * @file
00018  * A component of the AI framework
00019  */
00020 
00021 #ifndef AI_COMPOSITE_COMPONENT_HPP_INCLUDED
00022 #define AI_COMPOSITE_COMPONENT_HPP_INCLUDED
00023 
00024 class config;
00025 
00026 #include <iostream>
00027 #include <map>
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #ifdef _MSC_VER
00034 #pragma warning(push)
00035 //silence "inherits via dominance" warnings
00036 #pragma warning(disable:4250)
00037 #endif
00038 
00039 //============================================================================
00040 namespace ai {
00041 
00042 //TODO: find a good place for this
00043 struct path_element {
00044     path_element()
00045         : property()
00046         , id()
00047         , position(0)
00048     {
00049     }
00050 
00051     std::string property;
00052     std::string id;
00053     int position;
00054 };
00055 
00056 class base_property_handler;
00057 typedef boost::shared_ptr<base_property_handler> property_handler_ptr;
00058 typedef std::map<std::string,property_handler_ptr> property_handler_map;
00059 
00060 class component {
00061 public:
00062     component()
00063         : property_handlers_()
00064     {
00065     }
00066 
00067     virtual std::string get_id() const = 0;
00068     virtual std::string get_name() const = 0;
00069     virtual std::string get_engine() const = 0;
00070     virtual ~component() {};
00071     virtual component* get_child(const path_element &child);
00072     virtual std::vector<component*> get_children(const std::string &type);
00073     virtual std::vector<std::string> get_children_types();
00074     virtual bool change_child(const path_element &child, const config &cfg);
00075     virtual bool add_child(const path_element &child, const config &cfg);
00076     virtual bool delete_child(const path_element &child);
00077 
00078     property_handler_map& property_handlers();
00079 
00080 private:
00081     property_handler_map property_handlers_;
00082 };
00083 
00084 class component_manager {
00085 public:
00086     static bool add_component(component *root, const std::string &path, const config &cfg);
00087     static bool change_component(component *root, const std::string &path, const config &cfg);
00088     static bool delete_component(component *root, const std::string &path);
00089     static std::string print_component_tree(component *root, const std::string &path);
00090 };
00091 
00092 
00093 } //end of namespace ai
00094 
00095 std::ostream &operator<<(std::ostream &o, const ai::path_element &e);
00096 
00097 #ifdef _MSC_VER
00098 #pragma warning(pop)
00099 #endif
00100 
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:28 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs