Skip to content

Commit e9748ce

Browse files
committed
static cast
1 parent 262ea8f commit e9748ce

5 files changed

Lines changed: 74 additions & 74 deletions

File tree

code/missioneditor/sexp_tree_actions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@ void SexpTreeActions::add_default_modifier(const sexp_container& container)
342342
item.set_data("0");
343343
type_to_use |= SEXPT_NUMBER;
344344
} else {
345-
UNREACHABLE("Unknown map container key type %d", (int)container.type);
345+
UNREACHABLE("Unknown map container key type %d", static_cast<int>(container.type));
346346
}
347347
} else if (container.is_list()) {
348348
item.set_data(get_all_list_modifiers()[0].name);
349349
type_to_use |= SEXPT_STRING;
350350
} else {
351-
UNREACHABLE("Unknown container type %d", (int)container.type);
351+
UNREACHABLE("Unknown container type %d", static_cast<int>(container.type));
352352
}
353353

354354
item.type = type_to_use;
@@ -650,7 +650,7 @@ void SexpTreeActions::delete_sexp_tree_variable(const char* var_name)
650650

651651
int old_item_index = _model.item_index;
652652

653-
for (int idx = 0; idx < (int)_model.tree_nodes.size(); idx++) {
653+
for (int idx = 0; idx < static_cast<int>(_model.tree_nodes.size()); idx++) {
654654
if (_model.tree_nodes[idx].type & SEXPT_VARIABLE) {
655655
if (strstr(_model.tree_nodes[idx].text, search_str) != nullptr) {
656656
Assertion((_model.tree_nodes[idx].type & SEXPT_NUMBER) || (_model.tree_nodes[idx].type & SEXPT_STRING), "Invalid variable type");
@@ -695,7 +695,7 @@ void SexpTreeActions::modify_sexp_tree_variable(const char* old_name, int sexp_v
695695

696696
sprintf(search_str, "%s(", old_name);
697697

698-
for (int idx = 0; idx < (int)_model.tree_nodes.size(); idx++) {
698+
for (int idx = 0; idx < static_cast<int>(_model.tree_nodes.size()); idx++) {
699699
if (_model.tree_nodes[idx].type & SEXPT_VARIABLE) {
700700
if (strstr(_model.tree_nodes[idx].text, search_str) != nullptr) {
701701
_model.item_index = idx;
@@ -869,11 +869,11 @@ bool SexpTreeActions::rename_container_nodes(const SCP_string& old_name, const S
869869
"Attempt to rename container nodes with empty name. Please report!");
870870
Assertion(new_name.length() <= sexp_container::NAME_MAX_LENGTH,
871871
"Attempt to rename container nodes with name %s that is too long (%d > %d). Please report!",
872-
new_name.c_str(), (int)new_name.length(), sexp_container::NAME_MAX_LENGTH);
872+
new_name.c_str(), static_cast<int>(new_name.length()), sexp_container::NAME_MAX_LENGTH);
873873

874874
bool renamed_anything = false;
875875

876-
for (int node_idx = 0; node_idx < (int)_model.tree_nodes.size(); node_idx++) {
876+
for (int node_idx = 0; node_idx < static_cast<int>(_model.tree_nodes.size()); node_idx++) {
877877
if (_model.is_matching_container_node(node_idx, old_name)) {
878878
strcpy_s(_model.tree_nodes[node_idx].text, new_name.c_str());
879879
_ui.ui_set_item_text(_model.tree_nodes[node_idx].handle, new_name.c_str());

code/missioneditor/sexp_tree_model.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void sexp_list_item::set_op(int op_num)
3939
int i;
4040

4141
if (op_num >= FIRST_OP) { // do we have an op value instead of an op number (index)?
42-
for (i = 0; i < (int)Operators.size(); i++)
42+
for (i = 0; i < static_cast<int>(Operators.size()); i++)
4343
if (op_num == Operators[i].value)
4444
op_num = i; // convert op value to op number
4545
}
@@ -252,7 +252,7 @@ SexpTreeModel::~SexpTreeModel() = default;
252252
// Scan for the first unused slot in the tree_nodes array. Returns -1 if none available.
253253
int SexpTreeModel::find_free_node() const
254254
{
255-
for (int i = 0; i < (int)tree_nodes.size(); i++) {
255+
for (int i = 0; i < static_cast<int>(tree_nodes.size()); i++) {
256256
if (tree_nodes[i].type == SEXPT_UNUSED)
257257
return i;
258258
}
@@ -267,17 +267,17 @@ int SexpTreeModel::allocate_node()
267267

268268
// need more tree nodes?
269269
if (node < 0) {
270-
int old_size = (int)tree_nodes.size();
270+
int old_size = static_cast<int>(tree_nodes.size());
271271

272272
Assertion(TREE_NODE_INCREMENT > 0, "Invalid tree node increment");
273273

274274
// allocate in blocks of TREE_NODE_INCREMENT
275275
tree_nodes.resize(tree_nodes.size() + TREE_NODE_INCREMENT);
276276

277-
mprintf(("Bumping dynamic tree node limit from %d to %d...\n", old_size, (int)tree_nodes.size()));
277+
mprintf(("Bumping dynamic tree node limit from %d to %d...\n", old_size, static_cast<int>(tree_nodes.size())));
278278

279279
#ifndef NDEBUG
280-
for (int i = old_size; i < (int)tree_nodes.size(); i++) {
280+
for (int i = old_size; i < static_cast<int>(tree_nodes.size()); i++) {
281281
sexp_tree_item* item = &tree_nodes[i];
282282
Assertion(item->type == SEXPT_UNUSED, "Invalid tree node type");
283283
}
@@ -848,7 +848,7 @@ int SexpTreeModel::query_restricted_opf_range(int opf)
848848
// Returns -1 if the node has no valid parent.
849849
int SexpTreeModel::get_sibling_place(int node) const
850850
{
851-
if (tree_nodes[node].parent < 0 || tree_nodes[node].parent > (int)tree_nodes.size())
851+
if (!SCP_vector_inbounds(tree_nodes, tree_nodes[node].parent))
852852
return -1;
853853

854854
const sexp_tree_item* myparent = &tree_nodes[tree_nodes[node].parent];
@@ -946,7 +946,7 @@ const char* SexpTreeModel::help(int code)
946946
{
947947
int i;
948948

949-
i = (int)Sexp_help.size();
949+
i = static_cast<int>(Sexp_help.size());
950950
while (i--) {
951951
if (Sexp_help[i].id == code)
952952
break;
@@ -1161,7 +1161,7 @@ int SexpTreeModel::get_container_usage_count(const SCP_string& container_name) c
11611161
{
11621162
int count = 0;
11631163

1164-
for (int node_idx = 0; node_idx < (int)tree_nodes.size(); node_idx++) {
1164+
for (int node_idx = 0; node_idx < static_cast<int>(tree_nodes.size()); node_idx++) {
11651165
if (is_matching_container_node(node_idx, container_name)) {
11661166
count++;
11671167
}
@@ -1182,7 +1182,7 @@ bool SexpTreeModel::is_matching_container_node(int node, const SCP_string& conta
11821182
// (OPF_CONTAINER_NAME, OPF_LIST_CONTAINER_NAME, or OPF_MAP_CONTAINER_NAME).
11831183
bool SexpTreeModel::is_container_name_argument(int node) const
11841184
{
1185-
Assertion(node >= 0 && node < (int)tree_nodes.size(),
1185+
Assertion(SCP_vector_inbounds(tree_nodes, node),
11861186
"Attempt to check if out-of-range node %d is a container name argument. Please report!",
11871187
node);
11881188

@@ -1308,7 +1308,7 @@ bool SexpTreeModel::ctx_handle_labeled_root(SexpContextMenuState& state) const
13081308
state.can_edit_text = state.is_root_editable;
13091309
state.can_copy = false;
13101310

1311-
int num_ops = (int)Operators.size();
1311+
int num_ops = static_cast<int>(Operators.size());
13121312
state.op_add_enabled.assign(num_ops, false);
13131313
state.op_replace_enabled.assign(num_ops, false);
13141314
state.op_insert_enabled.assign(num_ops, false);
@@ -1731,10 +1731,10 @@ int SexpTreeModel::ctx_compute_replace_type(SexpContextMenuState& state)
17311731
state.can_replace_number = true;
17321732
state.can_replace_string = false;
17331733
} else {
1734-
UNREACHABLE("Map container with type %d has unknown key type", (int)container.type);
1734+
UNREACHABLE("Map container with type %d has unknown key type", static_cast<int>(container.type));
17351735
}
17361736
} else {
1737-
UNREACHABLE("Unknown container type %d", (int)container.type);
1737+
UNREACHABLE("Unknown container type %d", static_cast<int>(container.type));
17381738
}
17391739
} else if (state.replace_count == 1 && container.is_list() &&
17401740
get_list_modifier(tree_nodes[first_modifier_node].text) == ListModifier::AT_INDEX) {
@@ -1792,7 +1792,7 @@ void SexpTreeModel::ctx_compute_insert_type(SexpContextMenuState& state) const
17921792
void SexpTreeModel::ctx_compute_operator_enablement(SexpContextMenuState& state) const
17931793
{
17941794
int parent = tree_nodes[item_index].parent;
1795-
int num_ops = (int)Operators.size();
1795+
int num_ops = static_cast<int>(Operators.size());
17961796
state.op_add_enabled.assign(num_ops, false);
17971797
state.op_replace_enabled.assign(num_ops, false);
17981798
state.op_insert_enabled.assign(num_ops, false);
@@ -1895,7 +1895,7 @@ void SexpTreeModel::ctx_validate_clipboard(SexpContextMenuState& state, int repl
18951895
if (state.add_type == OPR_STRING && !SexpTreeOPF::is_container_name_opf_type(replace_opf_type))
18961896
state.can_paste_add = true;
18971897
} else {
1898-
UNREACHABLE("Unknown container data type %d", (int)container.type);
1898+
UNREACHABLE("Unknown container data type %d", static_cast<int>(container.type));
18991899
}
19001900
}
19011901

@@ -1951,7 +1951,7 @@ SexpTreeModel::HelpTextResult SexpTreeModel::compute_help_text(int node_index, c
19511951
{
19521952
HelpTextResult result;
19531953

1954-
if (node_index < 0 || node_index >= (int)tree_nodes.size() || !tree_nodes[node_index].type) {
1954+
if (!SCP_vector_inbounds(tree_nodes, node_index) || !tree_nodes[node_index].type) {
19551955
result.help_text = node_comment;
19561956
return result;
19571957
}

code/missioneditor/sexp_tree_opf.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_null()
5555
int i;
5656
sexp_list_item head;
5757

58-
for (i=0; i<(int)Operators.size(); i++)
58+
for (i=0; i<static_cast<int>(Operators.size()); i++)
5959
if (query_operator_return_type(i) == OPR_NULL)
6060
head.add_op(i);
6161

@@ -67,7 +67,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_flexible_argument()
6767
int i;
6868
sexp_list_item head;
6969

70-
for (i=0; i<(int)Operators.size(); i++)
70+
for (i=0; i<static_cast<int>(Operators.size()); i++)
7171
if (query_operator_return_type(i) == OPR_FLEXIBLE_ARGUMENT)
7272
head.add_op(i);
7373

@@ -91,7 +91,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_bool(int parent_node)
9191

9292
}
9393

94-
for (i=0; i<(int)Operators.size(); i++) {
94+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
9595
if (query_operator_return_type(i) == OPR_BOOL) {
9696
if ( !only_basic || (only_basic && ((Operators[i].value == OP_TRUE) || (Operators[i].value == OP_FALSE))) ) {
9797
head.add_op(i);
@@ -107,7 +107,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_positive()
107107
int i, z;
108108
sexp_list_item head;
109109

110-
for (i=0; i<(int)Operators.size(); i++) {
110+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
111111
z = query_operator_return_type(i);
112112
// Goober5000's number hack
113113
if ((z == OPR_NUMBER) || (z == OPR_POSITIVE))
@@ -122,7 +122,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_number()
122122
int i, z;
123123
sexp_list_item head;
124124

125-
for (i=0; i<(int)Operators.size(); i++) {
125+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
126126
z = query_operator_return_type(i);
127127
if ((z == OPR_NUMBER) || (z == OPR_POSITIVE))
128128
head.add_op(i);
@@ -244,7 +244,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_iff()
244244
int i;
245245
sexp_list_item head;
246246

247-
for (i=0; i< (int)Iff_info.size(); i++)
247+
for (i=0; i< static_cast<int>(Iff_info.size()); i++)
248248
head.add_data(Iff_info[i].iff_name);
249249

250250
return head.next;
@@ -351,7 +351,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_arrival_anchor_all()
351351

352352
for (restrict_to_players = 0; restrict_to_players < 2; restrict_to_players++)
353353
{
354-
for (i = 0; i < (int)Iff_info.size(); i++)
354+
for (i = 0; i < static_cast<int>(Iff_info.size()); i++)
355355
{
356356
char tmp[NAME_LENGTH + 15];
357357
stuff_special_arrival_anchor_name(tmp, i, restrict_to_players, false);
@@ -384,7 +384,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_ai_goal(int parent_node)
384384
n = ship_name_lookup(_model.tree_nodes[child].text, 1);
385385
if (n >= 0) {
386386
// add operators if it's an ai-goal and ai-goal is allowed for that ship
387-
for (i=0; i<(int)Operators.size(); i++) {
387+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
388388
if ( (query_operator_return_type(i) == OPR_AI_GOAL) && query_sexp_ai_goal_valid(Operators[i].value, n) )
389389
head.add_op(i);
390390
}
@@ -395,14 +395,14 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_ai_goal(int parent_node)
395395
for (w=0; w<Wings[z].wave_count; w++) {
396396
n = Wings[z].ship_index[w];
397397
// add operators if it's an ai-goal and ai-goal is allowed for that ship
398-
for (i=0; i<(int)Operators.size(); i++) {
398+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
399399
if ( (query_operator_return_type(i) == OPR_AI_GOAL) && query_sexp_ai_goal_valid(Operators[i].value, n) )
400400
head.add_op(i);
401401
}
402402
}
403403
// when dealing with the special argument add them all. It's up to the FREDder to ensure invalid orders aren't given
404404
} else if (!strcmp(_model.tree_nodes[child].text, SEXP_ARGUMENT_STRING)) {
405-
for (i=0; i<(int)Operators.size(); i++) {
405+
for (i=0; i<static_cast<int>(Operators.size()); i++) {
406406
if (query_operator_return_type(i) == OPR_AI_GOAL) {
407407
head.add_op(i);
408408
}
@@ -433,7 +433,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_docker_point(int parent_node, int a
433433

434434
Assertion(parent_node >= 0, "Invalid parent node");
435435
Assertion(!stricmp(_model.tree_nodes[parent_node].text, "ai-dock") || !stricmp(_model.tree_nodes[parent_node].text, "set-docked") ||
436-
get_operator_const(_model.tree_nodes[parent_node].text) >= (int)First_available_operator_id, "Invalid node type");
436+
get_operator_const(_model.tree_nodes[parent_node].text) >= static_cast<int>(First_available_operator_id), "Invalid node type");
437437

438438
if (!stricmp(_model.tree_nodes[parent_node].text, "ai-dock"))
439439
{
@@ -456,7 +456,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_docker_point(int parent_node, int a
456456
sh = ship_name_lookup(_model.tree_nodes[z].text, 1);
457457
}
458458
// for Lua sexps
459-
else if (get_operator_const(_model.tree_nodes[parent_node].text) >= (int)First_available_operator_id)
459+
else if (get_operator_const(_model.tree_nodes[parent_node].text) >= static_cast<int>(First_available_operator_id))
460460
{
461461
int this_index = get_dynamic_parameter_index(_model.tree_nodes[parent_node].text, arg_num);
462462

@@ -712,7 +712,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_ship_wing_wholeteam()
712712
int i;
713713
sexp_list_item head;
714714

715-
for (i = 0; i < (int)Iff_info.size(); i++)
715+
for (i = 0; i < static_cast<int>(Iff_info.size()); i++)
716716
head.add_data(Iff_info[i].iff_name);
717717

718718
head.add_list(get_listing_opf_ship_wing());
@@ -725,7 +725,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_ship_wing_shiponteam_point()
725725
int i;
726726
sexp_list_item head;
727727

728-
for (i = 0; i < (int)Iff_info.size(); i++)
728+
for (i = 0; i < static_cast<int>(Iff_info.size()); i++)
729729
{
730730
char tmp[NAME_LENGTH + 7];
731731
sprintf(tmp, "<any %s>", Iff_info[i].iff_name);
@@ -915,7 +915,7 @@ sexp_list_item *SexpTreeOPF::get_listing_opf_medal_name()
915915
int i;
916916
sexp_list_item head;
917917

918-
for (i = 0; i < (int)Medals.size(); i++)
918+
for (i = 0; i < static_cast<int>(Medals.size()); i++)
919919
{
920920
// don't add Rank or the Ace badges
921921
if ((i == Rank_medal_index) || (Medals[i].kills_needed > 0))
@@ -1925,7 +1925,7 @@ sexp_list_item *SexpTreeOPF::get_container_modifiers(int con_data_node) const
19251925

19261926
list = get_map_container_modifiers(con_data_node);
19271927
} else {
1928-
UNREACHABLE("Unknown container type %d", (int)p_container->type);
1928+
UNREACHABLE("Unknown container type %d", static_cast<int>(p_container->type));
19291929
}
19301930

19311931
if (list) {
@@ -1964,15 +1964,15 @@ sexp_list_item *SexpTreeOPF::get_map_container_modifiers(int con_data_node) cons
19641964
Assertion(container.is_map(),
19651965
"Found map modifier for non-map container %s with type %d. Please report!",
19661966
_model.tree_nodes[con_data_node].text,
1967-
(int)container.type);
1967+
static_cast<int>(container.type));
19681968

19691969
int type = SEXPT_VALID | SEXPT_MODIFIER;
19701970
if (any(container.type & ContainerType::STRING_KEYS)) {
19711971
type |= SEXPT_STRING;
19721972
} else if (any(container.type & ContainerType::NUMBER_KEYS)) {
19731973
type |= SEXPT_NUMBER;
19741974
} else {
1975-
UNREACHABLE("Unknown map container key type %d", (int)container.type);
1975+
UNREACHABLE("Unknown map container key type %d", static_cast<int>(container.type));
19761976
}
19771977

19781978
for (const auto &kv_pair : container.map_data) {
@@ -2012,7 +2012,7 @@ sexp_list_item *SexpTreeOPF::check_for_dynamic_sexp_enum(int opf)
20122012

20132013
int item = opf - First_available_opf_id;
20142014

2015-
if (item < (int)Dynamic_enums.size()) {
2015+
if (item < static_cast<int>(Dynamic_enums.size())) {
20162016

20172017
for (const SCP_string& enum_item : Dynamic_enums[item].list) {
20182018
head.add_data(enum_item.c_str());
@@ -2811,7 +2811,7 @@ int SexpTreeOPF::query_default_argument_available(int op, int i) const
28112811

28122812
default:
28132813
if (!Dynamic_enums.empty()) {
2814-
if ((type - First_available_opf_id) < (int)Dynamic_enums.size()) {
2814+
if ((type - First_available_opf_id) < static_cast<int>(Dynamic_enums.size())) {
28152815
return 1;
28162816
} else {
28172817
UNREACHABLE("Unhandled SEXP argument type!");
@@ -2903,10 +2903,10 @@ int SexpTreeOPF::get_default_value(sexp_list_item* item, char* text_buf, int op,
29032903
temp = 100;
29042904
break;
29052905
case 11:
2906-
temp = (int)EMP_DEFAULT_INTENSITY;
2906+
temp = static_cast<int>(EMP_DEFAULT_INTENSITY);
29072907
break;
29082908
case 12:
2909-
temp = (int)EMP_DEFAULT_TIME;
2909+
temp = static_cast<int>(EMP_DEFAULT_TIME);
29102910
break;
29112911
default:
29122912
temp = 0;

0 commit comments

Comments
 (0)