Skip to content

Commit

Permalink
Bad const_cast. Shoo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jul 11, 2019
1 parent 7705d24 commit 2352a45
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/display_context.cpp
Expand Up @@ -20,10 +20,6 @@
#include "units/unit.hpp"
#include "units/map.hpp"

std::vector<std::string>& display_context::hidden_label_categories_ref() {
return const_cast<std::vector<std::string>&>(this->hidden_label_categories());
}

const team& display_context::get_team(int side) const
{
return teams().at(side - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/display_context.hpp
Expand Up @@ -38,7 +38,7 @@ class display_context
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;
virtual const std::vector<std::string> & hidden_label_categories() const = 0;
std::vector<std::string> & hidden_label_categories_ref();
virtual std::vector<std::string> & hidden_label_categories() = 0;
const team& get_team(int side) const;

// this one is only a template function to prevent compilation erros when class team is an incomplete type.
Expand Down
5 changes: 5 additions & 0 deletions src/editor/map/map_context.hpp
Expand Up @@ -159,6 +159,11 @@ class map_context : public display_context
return lbl_categories_;
}

virtual std::vector<std::string>& hidden_label_categories() override
{
return lbl_categories_;
}

/**
* Replace the [time]s of the currently active area.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/game_board.hpp
Expand Up @@ -126,6 +126,11 @@ class game_board : public display_context
return labels_;
}

virtual std::vector<std::string>& hidden_label_categories() override
{
return labels_;
}

// Copy and swap idiom, because we have a scoped pointer.

game_board(const game_board & other);
Expand Down
2 changes: 1 addition & 1 deletion src/game_state.cpp
Expand Up @@ -223,7 +223,7 @@ void game_state::init(const config& level, play_controller & pc)
// Labels from players in your ignore list default to hidden
if(preferences::is_ignored(board_.teams_[i].current_player())) {
std::string label_cat = "side:" + std::to_string(i + 1);
board_.hidden_label_categories_ref().push_back(label_cat);
board_.hidden_label_categories().push_back(label_cat);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/label_settings.cpp
Expand Up @@ -117,7 +117,7 @@ bool label_settings::execute(display_context& dc) {
hidden_categories.push_back(lbl.first);
}
}
dc.hidden_label_categories_ref().swap(hidden_categories);
dc.hidden_label_categories().swap(hidden_categories);
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/pathfind/teleport.cpp
Expand Up @@ -75,12 +75,14 @@ class ignore_units_display_context : public display_context {
const gamemap & map() const override { return *gm_; }
const std::vector<team> & teams() const override { return *tm_; }
const std::vector<std::string> & hidden_label_categories() const override { return *lbls_; }
std::vector<std::string>& hidden_label_categories() override { return lbls_dummy_; }

This comment has been minimized.

Copy link
@jyrkive

jyrkive Jul 11, 2019

Member

If this isn't supposed to be used, I'd prefer throwing an exception.


private:
const unit_map * um_;
const gamemap * gm_;
const std::vector<team> * tm_;
const std::vector<std::string> * lbls_;
std::vector<std::string> lbls_dummy_;
};

class ignore_units_filter_context : public filter_context {
Expand Down

0 comments on commit 2352a45

Please sign in to comment.