whiteboard/validate_visitor.hpp

Go to the documentation of this file.
00001 /* $Id: validate_visitor.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003  Copyright (C) 2010 - 2012 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
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  */
00019 
00020 #ifndef WB_VALIDATE_VISITOR_HPP_
00021 #define WB_VALIDATE_VISITOR_HPP_
00022 
00023 #include "mapbuilder.hpp"
00024 #include "side_actions.hpp"
00025 
00026 #include <set>
00027 
00028 namespace wb
00029 {
00030 
00031 /**
00032  * Works like mapbuilder, but with these differences:
00033  *   * Instead of stopping at viewer_team, it visits all actions of every team.
00034  *   * actions are evaluated for validity along the way.
00035  *   * Some invalid actions are deleted.
00036  */
00037 class validate_visitor
00038     : private visitor
00039 {
00040 public:
00041     explicit validate_visitor(unit_map& unit_map);
00042     virtual ~validate_visitor();
00043 
00044     /// @return false some actions had to be deleted during validation,
00045     /// which may warrant a second validation
00046     bool validate_actions();
00047 
00048 private:
00049     virtual void visit(move_ptr move);
00050     virtual void visit(attack_ptr attack);
00051     virtual void visit(recruit_ptr recruit);
00052     virtual void visit(recall_ptr recall);
00053     virtual void visit(suppose_dead_ptr sup_d);
00054 
00055     enum VALIDITY {VALID, OBSTRUCTED, WORTHLESS};
00056     VALIDITY evaluate_move_validity(move_ptr);
00057 
00058     bool no_previous_invalids(side_actions::iterator const&);
00059 
00060     struct helper: public mapbuilder
00061     {
00062         helper(unit_map& umap, validate_visitor& parent)
00063                 : mapbuilder(umap)
00064                 , parent_(parent)
00065             {}
00066         virtual void validate(side_actions::iterator const& itor);
00067         validate_visitor& parent_;
00068     };
00069     friend struct helper;
00070 
00071     helper builder_;
00072 
00073     side_actions& viewer_actions_;
00074 
00075     std::set<action_ptr> actions_to_erase_;
00076 
00077     //Parameter for the visit_***() fcns -- see helper::validate()
00078     side_actions::iterator arg_itor_;
00079 };
00080 
00081 }
00082 
00083 #endif /* WB_VALIDATE_VISITOR_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs