Skip to content

Commit

Permalink
Add const to some more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rikardfalkeborn authored and Vultraz committed Apr 17, 2017
1 parent 343eb9a commit 94e73a7
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/gui/dialogs/chat_log.cpp
Expand Up @@ -105,7 +105,7 @@ class chat_log::model
msg_label->set_label("");
}

int count_of_pages()
int count_of_pages() const
{
int size = chat_log_history.size();
return (size % COUNT_PER_PAGE == 0) ? (size / COUNT_PER_PAGE)
Expand Down
14 changes: 7 additions & 7 deletions src/gui/dialogs/gamestate_inspector.cpp
Expand Up @@ -102,7 +102,7 @@ class gamestate_inspector::model
public:
std::string name;

std::string get_data_full()
std::string get_data_full() const
{
return data;
}
Expand Down Expand Up @@ -251,9 +251,9 @@ class single_mode_controller
gamestate_inspector::model& model();
gamestate_inspector::view& view();
gamestate_inspector::controller& c;
const config& vars();
const game_events::manager& events();
const display_context& dc();
const config& vars() const;
const game_events::manager& events() const;
const display_context& dc() const;
};

class variable_mode_controller : public single_mode_controller
Expand Down Expand Up @@ -495,15 +495,15 @@ gamestate_inspector::view& single_mode_controller::view() {
return c.view_;
}

const config& single_mode_controller::vars() {
const config& single_mode_controller::vars() const {
return c.vars_;
}

const game_events::manager& single_mode_controller::events() {
const game_events::manager& single_mode_controller::events() const {
return c.events_;
}

const display_context& single_mode_controller::dc() {
const display_context& single_mode_controller::dc() const {
return c.dc_;
}

Expand Down
4 changes: 2 additions & 2 deletions src/menu_events.cpp
Expand Up @@ -110,7 +110,7 @@ game_data & menu_handler::gamedata() { return gamestate().gamedata_; }
game_board & menu_handler::board() const { return gamestate().board_; }
unit_map& menu_handler::units() { return gamestate().board_.units_; }
std::vector<team>& menu_handler::teams() const { return gamestate().board_.teams_; }
const gamemap& menu_handler::map() { return gamestate().board_.map(); }
const gamemap& menu_handler::map() const { return gamestate().board_.map(); }

gui::floating_textbox& menu_handler::get_textbox(){
return textbox_info_;
Expand Down Expand Up @@ -1412,7 +1412,7 @@ void console_handler::do_theme() {
struct save_id_matches
{
save_id_matches(const std::string& save_id) : save_id_(save_id) {}
bool operator()(const team& t)
bool operator()(const team& t) const
{
return t.save_id() == save_id_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/menu_events.hpp
Expand Up @@ -125,7 +125,7 @@ class menu_handler : private chat_handler {
game_board & board() const;
unit_map& units();
std::vector<team>& teams() const;
const gamemap& map();
const gamemap& map() const;

const config& game_config_;

Expand Down
4 changes: 2 additions & 2 deletions src/mouse_handler_base.hpp
Expand Up @@ -168,8 +168,8 @@ class mouse_handler_base {
* Called when the middle click scrolling
*/
void set_scroll_start (int x, int y) { scroll_start_x_ = x; scroll_start_y_ = y; }
const SDL_Point get_scroll_start() { return{ scroll_start_x_, scroll_start_y_ }; }
bool scroll_started() { return scroll_started_; }
const SDL_Point get_scroll_start() const { return{ scroll_start_x_, scroll_start_y_ }; }
bool scroll_started() const { return scroll_started_; }

protected:
void cancel_dragging();
Expand Down
4 changes: 2 additions & 2 deletions src/pathfind/astarsearch.cpp
Expand Up @@ -122,7 +122,7 @@ class comp {

public:
comp(const std::vector<node>& n) : nodes_(n) { }
bool operator()(int a, int b) {
bool operator()(int a, int b) const {
return nodes_[b] < nodes_[a];
}
};
Expand All @@ -132,7 +132,7 @@ class indexer {

public:
indexer(size_t w) : w_(w) { }
size_t operator()(const map_location& loc) {
size_t operator()(const map_location& loc) const {
return loc.y * w_ + loc.x;
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/replay.cpp
Expand Up @@ -385,7 +385,7 @@ const std::vector<chat_msg>& replay::build_chat_log() const
return message_log;
}

config replay::get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type)
config replay::get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type) const
{
config res;

Expand Down Expand Up @@ -624,7 +624,7 @@ void replay::set_to_end()
base_->set_to_end();
}

bool replay::empty()
bool replay::empty() const
{
return ncommands() == 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/replay.hpp
Expand Up @@ -96,7 +96,7 @@ class replay
//undoable data includes moves such as placing a label or speaking, which is
//ignored by the undo system.
enum DATA_TYPE { ALL_DATA, NON_UNDO_DATA };
config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA);
config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA) const;

void undo();
/*
Expand All @@ -117,7 +117,7 @@ class replay
bool at_end() const;
void set_to_end();

bool empty();
bool empty() const;

enum MARK_SENT { MARK_AS_UNSENT, MARK_AS_SENT };
void add_config(const config& cfg, MARK_SENT mark=MARK_AS_UNSENT);
Expand Down
2 changes: 1 addition & 1 deletion src/replay_controller.hpp
Expand Up @@ -49,7 +49,7 @@ class replay_controller : public events::observer
bool can_execute_command(const hotkey::hotkey_command& cmd, int index) const;
bool is_controlling_view() const { return vision_.is_initialized(); }
bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
const std::shared_ptr<config>& get_reset_state() { return reset_state_; };
const std::shared_ptr<config>& get_reset_state() const { return reset_state_; };
void return_to_play_side(bool r = true) { return_to_play_side_ = r; }
void replay_show_everything();
void replay_show_each();
Expand Down
2 changes: 1 addition & 1 deletion src/saved_game.cpp
Expand Up @@ -449,7 +449,7 @@ void saved_game::expand_carryover()
}
}

bool saved_game::valid()
bool saved_game::valid() const
{
return this->starting_pos_type_ != STARTINGPOS_INVALID;
}
Expand Down
4 changes: 2 additions & 2 deletions src/saved_game.hpp
Expand Up @@ -79,13 +79,13 @@ class saved_game
/// takes care of generate_map=, generate_scenario=, map= attributes
/// This should be called before expanding carryover or mp_events because this might completely replace starting_pos_.
void expand_random_scenario();
bool valid();
bool valid() const;
/// @return the snapshot in the savefile (get_starting_pos)
config& set_snapshot(config snapshot);
void set_scenario(config scenario);
void remove_snapshot();

bool is_mid_game_save()
bool is_mid_game_save() const
{
return starting_pos_type_ == STARTINGPOS_SNAPSHOT;
}
Expand Down
4 changes: 2 additions & 2 deletions src/savegame.hpp
Expand Up @@ -191,8 +191,8 @@ class savegame
/** Customize the standard error message */
void set_error_message(const std::string& error_message) { error_message_ = error_message; }

const std::string& title() { return title_; }
const saved_game& gamestate() { return gamestate_; }
const std::string& title() const { return title_; }
const saved_game& gamestate() const { return gamestate_; }

/** If there needs to be some data fiddling before saving the game, this is the place to go. */
void before_save();
Expand Down
2 changes: 1 addition & 1 deletion src/server/metrics.cpp
Expand Up @@ -23,7 +23,7 @@
#include <iostream>

struct compare_samples_to_stringspan {
bool operator()(const simple_wml::string_span& a, const simple_wml::string_span& b)
bool operator()(const simple_wml::string_span& a, const simple_wml::string_span& b) const
{
return a < b;
}
Expand Down
2 changes: 1 addition & 1 deletion src/soundsource.cpp
Expand Up @@ -124,7 +124,7 @@ positional_source::~positional_source()
sound::reposition_sound(id_, DISTANCE_SILENT);
}

bool positional_source::is_global()
bool positional_source::is_global() const
{
return locations_.empty();
}
Expand Down
2 changes: 1 addition & 1 deletion src/soundsource.hpp
Expand Up @@ -59,7 +59,7 @@ class positional_source {
positional_source(const sourcespec &spec);
~positional_source();

bool is_global();
bool is_global() const;

void update(unsigned int time, const display &disp);
void update_positions(unsigned int time, const display &disp);
Expand Down
8 changes: 4 additions & 4 deletions src/synced_user_choice.hpp
Expand Up @@ -94,17 +94,17 @@ class user_choice_manager : events::pump_monitor
void search_in_replay();
public:
void pull();
bool finished()
bool finished() const
{ return required_.size() == res_.size(); }
bool has_local_choice()
bool has_local_choice() const
{ return local_choice_ != 0; }
/// Note: currently finished() does not imply !waiting() so you may need to check both.
bool waiting()
bool waiting() const
{ return local_choice_ == 0 && !oos_; }
void update_local_choice();
void ask_local_choice();
void fix_oos();
const std::string& wait_message() { return wait_message_; }
const std::string& wait_message() const { return wait_message_; }
/// @param name: the tagname for this user choice in the replay
/// @param sides: an array of team numbers (beginning with 1). the specified sides may not have an empty controller.
static std::map<int, config> get_user_choice_internal(const std::string &name, const mp_sync::user_choice &uch, const std::set<int>& sides);
Expand Down
2 changes: 1 addition & 1 deletion src/terrain/filter.cpp
Expand Up @@ -91,7 +91,7 @@ terrain_filter::terrain_filter_cache::terrain_filter_cache() :

namespace {
struct cfg_isor {
bool operator() (std::pair<const std::string,const vconfig> val) {
bool operator() (std::pair<const std::string,const vconfig> val) const {
return val.first == "or";
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/tod_manager.cpp
Expand Up @@ -516,7 +516,7 @@ bool tod_manager::next_turn(game_data* vars)
}


bool tod_manager::is_time_left()
bool tod_manager::is_time_left() const
{
return num_turns_ == -1 || turn_ <= num_turns_;
}
6 changes: 3 additions & 3 deletions src/tod_manager.hpp
Expand Up @@ -171,12 +171,12 @@ class tod_manager
*
* @returns True if time has not expired.
*/
bool is_time_left();
bool has_turn_event_fired()
bool is_time_left() const;
bool has_turn_event_fired() const
{ return has_turn_event_fired_; }
void turn_event_fired()
{ has_turn_event_fired_ = true; }
bool has_tod_bonus_changed()
bool has_tod_bonus_changed() const
{ return has_tod_bonus_changed_; }
private:

Expand Down
2 changes: 1 addition & 1 deletion src/video.cpp
Expand Up @@ -122,7 +122,7 @@ CVideo::~CVideo()
LOG_DP << "called SDL_Quit()\n";
}

bool CVideo::non_interactive()
bool CVideo::non_interactive() const
{
return fake_interactive ? false : (window == nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/video.hpp
Expand Up @@ -49,7 +49,7 @@ class CVideo {

static CVideo& get_singleton() { return *singleton_; }

bool non_interactive();
bool non_interactive() const;

const static int DefaultBpp = 32;

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/menu.hpp
Expand Up @@ -185,8 +185,8 @@ class menu : public scrollarea
void set_max_height(const int new_max_height);
void set_max_width(const int new_max_width);

int get_max_height() { return max_height_; }
int get_max_width() { return max_width_; }
int get_max_height() const { return max_height_; }
int get_max_width() const { return max_width_; }

size_t number_of_items() const { return items_.size(); }

Expand All @@ -203,8 +203,8 @@ class menu : public scrollarea
//this should be changed to a more object-oriented approach
void set_sorter(sorter *s);
void sort_by(int column);
int get_sort_by() {return sortby_;}
bool get_sort_reversed() {return sortreversed_;}
int get_sort_by() const {return sortby_;}
bool get_sort_reversed() const {return sortreversed_;}

protected:
bool item_ends_with_image(const std::string& item) const;
Expand Down

0 comments on commit 94e73a7

Please sign in to comment.