Skip to content

Commit 93b6916

Browse files
committed
Use wxString::Format only for true formatting
This removes usages of wxString::Format which were simply instances of converting or inserting numbers into strings. The re-written versions allow for type checking/selection at compile time, eliminating a source of runtime warning dialogs.
1 parent 7136c2c commit 93b6916

16 files changed

Lines changed: 161 additions & 105 deletions

src/gui/dleditmove.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,11 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
158158
labelSizer->Add(m_infosetName, 1, wxALL | wxEXPAND, 5);
159159
topSizer->Add(labelSizer, 0, wxALL | wxEXPAND, 0);
160160

161-
topSizer->Add(new wxStaticText(
162-
this, wxID_STATIC,
163-
wxString::Format(_("Number of members: %d"), p_infoset->GetMembers().size())),
164-
0, wxALL | wxALIGN_CENTER, 5);
161+
{
162+
wxString label;
163+
label << _("Number of members: ") << p_infoset->GetMembers().size();
164+
topSizer->Add(new wxStaticText(this, wxID_STATIC, label), 0, wxALL | wxALIGN_CENTER, 5);
165+
}
165166

166167
auto *playerSizer = new wxBoxSizer(wxHORIZONTAL);
167168
playerSizer->Add(new wxStaticText(this, wxID_STATIC, _("Belongs to player")), 0,
@@ -173,8 +174,9 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
173174
}
174175
else {
175176
for (const auto &player : p_infoset->GetGame()->GetPlayers()) {
176-
m_player->Append(wxString::Format(_T("%d: "), player->GetNumber()) +
177-
wxString(player->GetLabel().c_str(), *wxConvCurrent));
177+
wxString label;
178+
label << player->GetNumber() << ": " << player->GetLabel();
179+
m_player->Append(label);
178180
}
179181
m_player->SetSelection(p_infoset->GetPlayer()->GetNumber() - 1);
180182
}

src/gui/dleditnode.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ EditNodeDialog::EditNodeDialog(wxWindow *p_parent, const GameNode &p_node)
5555
for (const auto &infoset : p_node->GetGame()->GetChance()->GetInfosets()) {
5656
if (infoset->GetActions().size() == p_node->GetChildren().size()) {
5757
m_infosetList.push_back(infoset);
58-
m_infoset->Append(wxString::Format(_("Chance infoset %d"), infoset->GetNumber()));
58+
wxString label;
59+
label << _("Chance infoset ") << infoset->GetNumber();
60+
m_infoset->Append(label);
5961
if (infoset == p_node->GetInfoset()) {
6062
selection = m_infosetList.size();
6163
}
@@ -69,8 +71,10 @@ EditNodeDialog::EditNodeDialog(wxWindow *p_parent, const GameNode &p_node)
6971
for (const auto &infoset : player->GetInfosets()) {
7072
if (infoset->GetActions().size() == p_node->GetChildren().size()) {
7173
m_infosetList.push_back(infoset);
72-
m_infoset->Append(wxString::Format(_("Player %d, Infoset %d"), player->GetNumber(),
73-
infoset->GetNumber()));
74+
wxString label;
75+
label << _("Player ") << player->GetNumber() << _(", Infoset ")
76+
<< infoset->GetNumber();
77+
m_infoset->Append(label);
7478
if (infoset == p_node->GetInfoset()) {
7579
selection = m_infosetList.size();
7680
}

src/gui/dlefglayout.cc

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,28 @@ LayoutNodesPanel::LayoutNodesPanel(wxWindow *p_parent, const TreeRenderConfig &p
100100
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Horizontal size of nodes")), 0,
101101
wxALIGN_CENTER_VERTICAL | wxALL, 5);
102102

103-
constexpr int NODE_LENGTH_MIN = 5;
104-
constexpr int NODE_LENGTH_MAX = 100;
105-
106-
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetNodeSize()),
107-
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, NODE_LENGTH_MIN,
108-
NODE_LENGTH_MAX);
109-
gridSizer->Add(m_nodeSize, 1, wxEXPAND | wxALL, 5);
103+
{
104+
constexpr int NODE_LENGTH_MIN = 5;
105+
constexpr int NODE_LENGTH_MAX = 100;
106+
wxString label;
107+
label << p_settings.GetNodeSize();
108+
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize,
109+
wxSP_ARROW_KEYS, NODE_LENGTH_MIN, NODE_LENGTH_MAX);
110+
gridSizer->Add(m_nodeSize, 1, wxEXPAND | wxALL, 5);
111+
}
110112

111113
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Vertical spacing between terminal nodes")), 0,
112114
wxALIGN_CENTER_VERTICAL | wxALL, 5);
113115

114-
constexpr int Y_SPACING_MIN = 15;
115-
constexpr int Y_SPACING_MAX = 60;
116-
117-
m_terminalSpacing = new wxSpinCtrl(
118-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetTerminalSpacing()),
119-
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, Y_SPACING_MIN, Y_SPACING_MAX);
120-
gridSizer->Add(m_terminalSpacing, 1, wxEXPAND | wxALL, 5);
116+
{
117+
constexpr int Y_SPACING_MIN = 15;
118+
constexpr int Y_SPACING_MAX = 60;
119+
wxString label;
120+
label << p_settings.GetTerminalSpacing();
121+
m_terminalSpacing = new wxSpinCtrl(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize,
122+
wxSP_ARROW_KEYS, Y_SPACING_MIN, Y_SPACING_MAX);
123+
gridSizer->Add(m_terminalSpacing, 1, wxEXPAND | wxALL, 5);
124+
}
121125

122126
sizeSizer->Add(gridSizer, 1, wxALL | wxEXPAND, 5);
123127
topSizer->Add(sizeSizer, 0, wxALL | wxALIGN_CENTER, 5);
@@ -151,12 +155,6 @@ class LayoutBranchesPanel : public wxPanel {
151155
LayoutBranchesPanel::LayoutBranchesPanel(wxWindow *p_parent, const TreeRenderConfig &p_settings)
152156
: wxPanel(p_parent, wxID_ANY)
153157
{
154-
constexpr int BRANCH_LENGTH_MIN = 0;
155-
constexpr int BRANCH_LENGTH_MAX = 100;
156-
157-
constexpr int TINE_LENGTH_MIN = 20;
158-
constexpr int TINE_LENGTH_MAX = 100;
159-
160158
auto *topSizer = new wxBoxSizer(wxVERTICAL);
161159

162160
auto *styleBoxSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Drawing branches"));
@@ -186,19 +184,29 @@ LayoutBranchesPanel::LayoutBranchesPanel(wxWindow *p_parent, const TreeRenderCon
186184
auto *gridSizer = new wxFlexGridSizer(2);
187185
gridSizer->AddGrowableCol(1);
188186

189-
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch fork")), 0,
190-
wxALIGN_CENTER_VERTICAL | wxALL, 5);
191-
m_branchLength = new wxSpinCtrl(
192-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetBranchLength()), wxDefaultPosition,
193-
wxDefaultSize, wxSP_ARROW_KEYS, BRANCH_LENGTH_MIN, BRANCH_LENGTH_MAX);
194-
gridSizer->Add(m_branchLength, 1, wxALL | wxEXPAND, 5);
187+
{
188+
constexpr int BRANCH_LENGTH_MIN = 0;
189+
constexpr int BRANCH_LENGTH_MAX = 100;
190+
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch fork")), 0,
191+
wxALIGN_CENTER_VERTICAL | wxALL, 5);
192+
wxString label;
193+
label << p_settings.GetBranchLength();
194+
m_branchLength = new wxSpinCtrl(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize,
195+
wxSP_ARROW_KEYS, BRANCH_LENGTH_MIN, BRANCH_LENGTH_MAX);
196+
gridSizer->Add(m_branchLength, 1, wxALL | wxEXPAND, 5);
197+
}
195198

196-
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch tine")), 1,
197-
wxALIGN_CENTER_VERTICAL | wxALL, 5);
198-
m_tineLength = new wxSpinCtrl(
199-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetTineLength()), wxDefaultPosition,
200-
wxDefaultSize, wxSP_ARROW_KEYS, TINE_LENGTH_MIN, TINE_LENGTH_MAX);
201-
gridSizer->Add(m_tineLength, 1, wxALL | wxEXPAND, 5);
199+
{
200+
constexpr int TINE_LENGTH_MIN = 20;
201+
constexpr int TINE_LENGTH_MAX = 100;
202+
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch tine")), 1,
203+
wxALIGN_CENTER_VERTICAL | wxALL, 5);
204+
wxString label;
205+
label << p_settings.GetTineLength();
206+
m_tineLength = new wxSpinCtrl(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize,
207+
wxSP_ARROW_KEYS, TINE_LENGTH_MIN, TINE_LENGTH_MAX);
208+
gridSizer->Add(m_tineLength, 1, wxALL | wxEXPAND, 5);
209+
}
202210

203211
lengthSizer->Add(gridSizer, 1, wxALL | wxEXPAND, 5);
204212
topSizer->Add(lengthSizer, 0, wxALL | wxALIGN_CENTER, 5);

src/gui/dlefglogit.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ LogitBehavList::LogitBehavList(wxWindow *p_parent, GameDocument *p_doc)
7474
wxString LogitBehavList::GetCellValue(const wxSheetCoords &p_coords)
7575
{
7676
if (IsRowLabelCell(p_coords)) {
77-
return wxString::Format(wxT("%d"), p_coords.GetRow() + 1);
77+
wxString label;
78+
label << (p_coords.GetRow() + 1);
79+
return label;
7880
}
7981
if (IsColLabelCell(p_coords)) {
8082
if (p_coords.GetCol() == 0) {
8183
return wxT("Lambda");
8284
}
8385
const GameAction action = m_doc->GetAction(p_coords.GetCol());
84-
return (wxString::Format(wxT("%d: "), action->GetInfoset()->GetNumber()) +
85-
wxString(action->GetLabel().c_str(), *wxConvCurrent));
86+
wxString label;
87+
label << action->GetInfoset()->GetNumber() << ": " << action->GetLabel();
88+
return label;
8689
}
8790
if (IsCornerLabelCell(p_coords)) {
8891
return wxT("#");

src/gui/dlefgreveal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ RevealMoveDialog::RevealMoveDialog(wxWindow *p_parent, const Game &p_game)
7171
for (const auto &player : players) {
7272
wxString label;
7373
if (!player->GetLabel().empty()) {
74-
label = wxString::FromUTF8(player->GetLabel());
74+
label << player->GetLabel();
7575
}
7676
else {
77-
label = wxString::Format("Player %u", player->GetNumber());
77+
label << "Player " << player->GetNumber();
7878
}
7979
auto *cb = new wxCheckBox(this, wxID_ANY, label);
8080
cb->SetValue(true);

src/gui/dlgameprop.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ GamePropertiesDialog::GamePropertiesDialog(wxWindow *p_parent, GameDocument *p_d
6363
wxALL, 5);
6464

6565
const Game game = m_doc->GetGame();
66-
boxSizer->Add(new wxStaticText(this, wxID_STATIC,
67-
wxString::Format(_("Number of players: %d"), game->NumPlayers())),
68-
0, wxALL, 5);
66+
{
67+
wxString label;
68+
label << _("Number of players: ") << game->NumPlayers();
69+
boxSizer->Add(new wxStaticText(this, wxID_STATIC, label), 0, wxALL, 5);
70+
}
6971
if (game->IsConstSum()) {
7072
boxSizer->Add(new wxStaticText(this, wxID_STATIC, _("This is a constant-sum game")), 0, wxALL,
7173
5);

src/gui/dlinsertmove.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ InsertMoveDialog::InsertMoveDialog(wxWindow *p_parent, GameDocument *p_doc)
4040
for (const auto &player : m_doc->GetGame()->GetPlayers()) {
4141
wxString s = _("Insert move for ");
4242
if (player->GetLabel() != "") {
43-
s += wxString(player->GetLabel().c_str(), *wxConvCurrent);
43+
s << player->GetLabel();
4444
}
4545
else {
46-
s += wxString::Format(_("player %d"), player->GetNumber());
46+
s << _("player ") << player->GetNumber();
4747
}
4848
m_playerItem->Append(s);
4949
}
@@ -58,18 +58,18 @@ InsertMoveDialog::InsertMoveDialog(wxWindow *p_parent, GameDocument *p_doc)
5858
for (const auto &infoset : player->GetInfosets()) {
5959
wxString s = _("at information set ");
6060
if (infoset->GetLabel() != "") {
61-
s += wxString(infoset->GetLabel().c_str(), *wxConvCurrent);
61+
s << infoset->GetLabel();
6262
}
6363
else {
64-
s += wxString::Format(wxT("%d"), infoset->GetNumber());
64+
s << infoset->GetNumber();
6565
}
6666

67-
s += wxString::Format(wxT(" (%d action"), infoset->GetActions().size());
67+
s << " (" << infoset->GetActions().size() << " action";
6868
if (infoset->GetActions().size() > 1) {
6969
s += wxT("s");
7070
}
7171

72-
s += wxString::Format(wxT(", %d member node"), infoset->GetMembers().size());
72+
s << ", " << infoset->GetMembers().size() << " member node";
7373
if (infoset->GetMembers().size() > 1) {
7474
s += wxT("s)");
7575
}
@@ -134,18 +134,18 @@ void InsertMoveDialog::OnPlayer(wxCommandEvent &)
134134
for (const auto &infoset : player->GetInfosets()) {
135135
wxString s = _("at information set ");
136136
if (infoset->GetLabel() != "") {
137-
s += wxString(infoset->GetLabel().c_str(), *wxConvCurrent);
137+
s << infoset->GetLabel();
138138
}
139139
else {
140-
s += wxString::Format(wxT("%d"), infoset->GetNumber());
140+
s << infoset->GetNumber();
141141
}
142142

143-
s += wxString::Format(wxT(" (%d action"), infoset->GetActions().size());
143+
s << " (" << infoset->GetActions().size() << " action";
144144
if (infoset->GetActions().size() > 1) {
145145
s += wxT("s");
146146
}
147147

148-
s += wxString::Format(wxT(", %d member node"), infoset->GetMembers().size());
148+
s << ", " << infoset->GetMembers().size() << " member node";
149149
if (infoset->GetMembers().size() > 1) {
150150
s += wxT("s)");
151151
}

src/gui/dlnashmon.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ void NashMonitorDialog::OnIdle(wxIdleEvent &p_event)
154154
msg << tis.ReadLine();
155155

156156
m_doc->DoAddOutput(*m_output, msg);
157-
m_countText->SetLabel(
158-
wxString::Format(wxT("Number of equilibria found so far: %d"), m_output->NumProfiles()));
159-
157+
wxString label;
158+
label << wxT("Number of equilibria found so far: ") << m_output->NumProfiles();
159+
m_countText->SetLabel(label);
160160
p_event.RequestMore();
161161
}
162162
else {
@@ -179,8 +179,9 @@ void NashMonitorDialog::OnEndProcess(wxProcessEvent &p_event)
179179

180180
if (!msg.empty()) {
181181
m_doc->DoAddOutput(*m_output, msg);
182-
m_countText->SetLabel(
183-
wxString::Format(wxT("Number of equilibria found so far: %d"), m_output->NumProfiles()));
182+
wxString label;
183+
label << wxT("Number of equilibria found so far: ") << m_output->NumProfiles();
184+
m_countText->SetLabel(label);
184185
}
185186
}
186187

src/gui/dlnfglogit.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ wxString LogitMixedSheet::GetCellValue(const wxSheetCoords &p_coords)
136136
}
137137

138138
if (IsRowLabelCell(p_coords)) {
139-
return wxString::Format(wxT("%d"), p_coords.GetRow() + 1);
139+
wxString label;
140+
label << (p_coords.GetRow() + 1);
141+
return label;
140142
}
141143
if (IsColLabelCell(p_coords)) {
142144
if (p_coords.GetCol() == 0) {
@@ -146,8 +148,9 @@ wxString LogitMixedSheet::GetCellValue(const wxSheetCoords &p_coords)
146148
for (const auto &player : m_doc->GetGame()->GetPlayers()) {
147149
for (const auto &strategy : player->GetStrategies()) {
148150
if (index++ == p_coords.GetCol()) {
149-
return (wxString::Format(wxT("%d: "), player->GetNumber()) +
150-
wxString(strategy->GetLabel().c_str(), *wxConvCurrent));
151+
wxString label;
152+
label << player->GetNumber() << ": " << strategy->GetLabel();
153+
return label;
151154
}
152155
}
153156
return wxT("");

src/gui/efgdisplay.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,9 @@ void EfgDisplay::OnMouseMotion(wxMouseEvent &p_event)
847847
image.CopyFromBitmap(bitmap);
848848
#endif // _WXMSW__
849849

850-
wxTextDataObject textData(wxString::Format(wxT("C%d"), node->GetNumber()));
850+
wxString label;
851+
label << "C" << node->GetNumber();
852+
wxTextDataObject textData(label);
851853
wxDropSource source(textData, this, image, image, image);
852854
/*wxDragResult result =*/source.DoDragDrop(true);
853855
}
@@ -862,7 +864,9 @@ void EfgDisplay::OnMouseMotion(wxMouseEvent &p_event)
862864
image.CopyFromBitmap(bitmap);
863865
#endif // _WXMSW__
864866

865-
wxTextDataObject textData(wxString::Format(wxT("I%d"), node->GetNumber()));
867+
wxString label;
868+
label << "I" << node->GetNumber();
869+
wxTextDataObject textData(label);
866870

867871
wxDropSource source(textData, this, image, image, image);
868872
/*wxDragResult result =*/source.DoDragDrop(wxDrag_DefaultMove);
@@ -877,7 +881,9 @@ void EfgDisplay::OnMouseMotion(wxMouseEvent &p_event)
877881
image.CopyFromBitmap(bitmap);
878882
#endif // _WXMSW__
879883

880-
wxTextDataObject textData(wxString::Format(wxT("M%d"), node->GetNumber()));
884+
wxString label;
885+
label << "M" << node->GetNumber();
886+
wxTextDataObject textData(label);
881887

882888
wxDropSource source(textData, this, image, image, image);
883889
/*wxDragResult result =*/source.DoDragDrop(wxDrag_DefaultMove);
@@ -897,17 +903,23 @@ void EfgDisplay::OnMouseMotion(wxMouseEvent &p_event)
897903
#endif // _WXMSW__
898904

899905
if (p_event.ControlDown()) {
900-
wxTextDataObject textData(wxString::Format(wxT("O%d"), node->GetNumber()));
906+
wxString label;
907+
label << "O" << node->GetNumber();
908+
wxTextDataObject textData(label);
901909
wxDropSource source(textData, this, image, image, image);
902910
/*wxDragResult result =*/source.DoDragDrop(true);
903911
}
904912
else if (p_event.ShiftDown()) {
905-
wxTextDataObject textData(wxString::Format(wxT("p%d"), node->GetNumber()));
913+
wxString label;
914+
label << "p" << node->GetNumber();
915+
wxTextDataObject textData(label);
906916
wxDropSource source(textData, this, image, image, image);
907917
/*wxDragResult result =*/source.DoDragDrop(true);
908918
}
909919
else {
910-
wxTextDataObject textData(wxString::Format(wxT("o%d"), node->GetNumber()));
920+
wxString label;
921+
label << "o" << node->GetNumber();
922+
wxTextDataObject textData(label);
911923
wxDropSource source(textData, this, image, image, image);
912924
/*wxDragResult result =*/source.DoDragDrop(wxDrag_DefaultMove);
913925
}

0 commit comments

Comments
 (0)