Changed private inheritance into composition.

This commit is contained in:
Tommy Schmitz 2011-08-03 22:00:19 +00:00
parent d7602bfadb
commit 5553385f29
3 changed files with 13 additions and 16 deletions

View File

@ -36,11 +36,13 @@ namespace wb
* and reverts all changes on destruction.
*/
class mapbuilder_visitor
: protected visitor
: private visitor
, private enable_visit_all<mapbuilder_visitor>
{
friend class enable_visit_all<mapbuilder_visitor>;
friend class validate_visitor;
public:
mapbuilder_visitor(unit_map& unit_map);
virtual ~mapbuilder_visitor();
@ -52,7 +54,7 @@ public:
*/
void build_map();
protected:
private:
virtual void visit_move(move_ptr move);
virtual void visit_attack(attack_ptr attack);
virtual void visit_recruit(recruit_ptr recruit);
@ -70,9 +72,6 @@ protected:
//the ones controlled by the player whose turn it is currently.
void reset_moves();
private:
void visit_all() {enable_visit_all<mapbuilder_visitor>::visit_all();}
void restore_normal_map();
unit_map& unit_map_;

View File

@ -38,7 +38,7 @@ namespace wb
{
validate_visitor::validate_visitor(unit_map& unit_map)
: mapbuilder_visitor(unit_map)
: builder_(unit_map)
, viewer_actions_(*viewer_actions())
, actions_to_erase_()
, arg_itor_()
@ -48,13 +48,12 @@ validate_visitor::validate_visitor(unit_map& unit_map)
validate_visitor::~validate_visitor()
{
//~mapbuilder_visitor() gets called here automatically
}
bool validate_visitor::validate_actions()
{
//Temporarily reset all units' moves to full EXCEPT for the ones on viewer_side().
reset_moves(); //< protected fcn inherited from mapbuilder_visitor
builder_.reset_moves();
visit_all();
@ -171,7 +170,7 @@ void validate_visitor::visit_move(move_ptr move)
// Now call the superclass to apply the result of this move to the unit map,
// so that further pathfinding takes it into account.
move->set_valid(true);
mapbuilder_visitor::visit_move(move);
builder_.visit_move(move);
break;
case OBSTRUCTED:
move->set_valid(false);
@ -253,7 +252,7 @@ void validate_visitor::visit_recruit(recruit_ptr recruit)
if (recruit->is_valid())
{
mapbuilder_visitor::visit_recruit(recruit);
builder_.visit_recruit(recruit);
}
else
{
@ -300,7 +299,7 @@ void validate_visitor::visit_recall(recall_ptr recall)
if (recall->is_valid())
{
mapbuilder_visitor::visit_recall(recall);
builder_.visit_recall(recall);
}
else
{
@ -346,7 +345,7 @@ void validate_visitor::visit_suppose_dead(suppose_dead_ptr sup_d)
{
// Now call the superclass to apply the result of this move to the unit map,
// so that further pathfinding takes it into account.
mapbuilder_visitor::visit_suppose_dead(sup_d);
builder_.visit_suppose_dead(sup_d);
}
else
{

View File

@ -35,7 +35,7 @@ namespace wb
* * Some invalid actions are deleted.
*/
class validate_visitor
: private mapbuilder_visitor
: private visitor
, private enable_visit_all<validate_visitor>
{
friend class enable_visit_all<validate_visitor>;
@ -62,9 +62,8 @@ private:
//"Inherited" from enable_visit_all
bool visit(size_t team_index, team& t, side_actions& sa, side_actions::iterator itor)
{ arg_itor_=itor; return visitor::visit(team_index,t,sa,itor); }
using mapbuilder_visitor::pre_visit_team;
using enable_visit_all<validate_visitor>::post_visit_team;
using enable_visit_all<validate_visitor>::visit_all;
mapbuilder_visitor builder_;
side_actions& viewer_actions_;