Skip to content

Commit cc948a6

Browse files
committed
Put everything in Gambit::GUI namespace
1 parent 9cc9cb3 commit cc948a6

52 files changed

Lines changed: 340 additions & 257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/gui/analysis.cc

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,27 @@
3232
#include "analysis.h"
3333
#include "gamedoc.h"
3434

35-
using namespace Gambit;
36-
35+
namespace Gambit::GUI {
3736
//=========================================================================
3837
// class AnalysisProfileList
3938
//=========================================================================
4039

4140
// Use anonymous namespace to make these helpers private
4241
namespace {
4342

44-
class gbtNotNashException final : public std::runtime_error {
43+
class NotNashException final : public std::runtime_error {
4544
public:
46-
gbtNotNashException() : std::runtime_error("Output line does not contain a Nash equilibrium") {}
47-
~gbtNotNashException() noexcept override = default;
45+
NotNashException() : std::runtime_error("Output line does not contain a Nash equilibrium") {}
46+
~NotNashException() noexcept override = default;
4847
};
4948

5049
template <class T>
5150
MixedStrategyProfile<T> OutputToMixedProfile(GameDocument *p_doc, const wxString &p_text)
5251
{
53-
MixedStrategyProfile<T> profile(p_doc->GetGame()->NewMixedStrategyProfile((T)0.0));
54-
55-
wxStringTokenizer tok(p_text, wxT(","));
52+
MixedStrategyProfile<T> profile(p_doc->GetGame()->NewMixedStrategyProfile(static_cast<T>(0.0)));
5653

57-
if (tok.GetNextToken() == wxT("NE")) {
58-
if (tok.CountTokens() == (unsigned int)profile.MixedProfileLength()) {
54+
if (wxStringTokenizer tok(p_text, wxT(",")); tok.GetNextToken() == wxT("NE")) {
55+
if (tok.CountTokens() == static_cast<unsigned int>(profile.MixedProfileLength())) {
5956
for (size_t i = 1; i <= profile.MixedProfileLength(); i++) {
6057
profile[i] =
6158
lexical_cast<Rational>(std::string((const char *)tok.GetNextToken().mb_str()));
@@ -64,7 +61,7 @@ MixedStrategyProfile<T> OutputToMixedProfile(GameDocument *p_doc, const wxString
6461
}
6562
}
6663

67-
throw gbtNotNashException();
64+
throw NotNashException();
6865
}
6966

7067
template <class T>
@@ -75,16 +72,15 @@ MixedBehaviorProfile<T> OutputToBehavProfile(GameDocument *p_doc, const wxString
7572
wxStringTokenizer tok(p_text, wxT(","));
7673

7774
if (tok.GetNextToken() == wxT("NE")) {
78-
if (tok.CountTokens() == (unsigned int)profile.BehaviorProfileLength()) {
75+
if (tok.CountTokens() == static_cast<unsigned int>(profile.BehaviorProfileLength())) {
7976
for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) {
80-
profile[i] =
81-
lexical_cast<Rational>(std::string((const char *)tok.GetNextToken().mb_str()));
77+
profile[i] = lexical_cast<Rational>(std::string(tok.GetNextToken().mb_str()));
8278
}
8379
return profile;
8480
}
8581
}
8682

87-
throw gbtNotNashException();
83+
throw NotNashException();
8884
}
8985

9086
} // end anonymous namespace
@@ -110,7 +106,7 @@ template <class T> void AnalysisProfileList<T>::AddOutput(const wxString &p_outp
110106
m_current = m_mixedProfiles.size();
111107
}
112108
}
113-
catch (gbtNotNashException &) {
109+
catch (NotNashException &) {
114110
}
115111
}
116112

@@ -124,12 +120,7 @@ template <class T> void AnalysisProfileList<T>::BuildNfg()
124120

125121
template <class T> int AnalysisProfileList<T>::NumProfiles() const
126122
{
127-
if (m_doc->IsTree()) {
128-
return m_behavProfiles.size();
129-
}
130-
else {
131-
return m_mixedProfiles.size();
132-
}
123+
return (m_doc->IsTree()) ? m_behavProfiles.size() : m_mixedProfiles.size();
133124
}
134125

135126
template <class T> void AnalysisProfileList<T>::Clear()
@@ -149,12 +140,12 @@ namespace {
149140
template <class T>
150141
MixedStrategyProfile<T> TextToMixedProfile(GameDocument *p_doc, const wxString &p_text)
151142
{
152-
MixedStrategyProfile<T> profile(p_doc->GetGame()->NewMixedStrategyProfile((T)0));
143+
MixedStrategyProfile<T> profile(p_doc->GetGame()->NewMixedStrategyProfile(static_cast<T>(0)));
153144

154145
wxStringTokenizer tok(p_text, wxT(","));
155146

156147
for (size_t i = 1; i <= profile.MixedProfileLength(); i++) {
157-
profile[i] = lexical_cast<Rational>(std::string((const char *)tok.GetNextToken().mb_str()));
148+
profile[i] = lexical_cast<Rational>(std::string(tok.GetNextToken().mb_str()));
158149
}
159150

160151
return profile;
@@ -167,7 +158,7 @@ MixedBehaviorProfile<T> TextToBehavProfile(GameDocument *p_doc, const wxString &
167158

168159
wxStringTokenizer tok(p_text, wxT(","));
169160
for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) {
170-
profile[i] = lexical_cast<Rational>(std::string((const char *)tok.GetNextToken().mb_str()));
161+
profile[i] = lexical_cast<Rational>(std::string(tok.GetNextToken().mb_str()));
171162
}
172163

173164
return profile;
@@ -183,15 +174,13 @@ template <class T> void AnalysisProfileList<T>::Load(TiXmlNode *p_analysis)
183174
{
184175
Clear();
185176

186-
TiXmlNode *description = p_analysis->FirstChild("description");
187-
if (description) {
177+
if (TiXmlNode *description = p_analysis->FirstChild("description")) {
188178
m_description = wxString(description->FirstChild()->Value(), *wxConvCurrent);
189179
}
190180

191181
for (TiXmlNode *node = p_analysis->FirstChild("profile"); node;
192182
node = node->NextSiblingElement()) {
193-
const char *type = node->ToElement()->Attribute("type");
194-
if (!strcmp(type, "behav")) {
183+
if (const char *type = node->ToElement()->Attribute("type"); !strcmp(type, "behav")) {
195184
const MixedBehaviorProfile<T> profile =
196185
TextToBehavProfile<T>(m_doc, wxString(node->FirstChild()->Value(), *wxConvCurrent));
197186
m_behavProfiles.push_back(std::make_shared<MixedBehaviorProfile<T>>(profile));
@@ -217,10 +206,8 @@ template <class T> std::string AnalysisProfileList<T>::GetPayoff(int pl, int p_i
217206
return lexical_cast<std::string>(m_behavProfiles[index]->GetPayoff(pl),
218207
m_doc->GetStyle().NumDecimals());
219208
}
220-
else {
221-
return lexical_cast<std::string>(m_mixedProfiles[index]->GetPayoff(pl),
222-
m_doc->GetStyle().NumDecimals());
223-
}
209+
return lexical_cast<std::string>(m_mixedProfiles[index]->GetPayoff(pl),
210+
m_doc->GetStyle().NumDecimals());
224211
}
225212
catch (std::out_of_range &) {
226213
return "";
@@ -255,10 +242,8 @@ std::string AnalysisProfileList<T>::GetBeliefProb(const GameNode &p_node, int p_
255242
return lexical_cast<std::string>(m_behavProfiles[index]->GetBeliefProb(p_node),
256243
m_doc->GetStyle().NumDecimals());
257244
}
258-
else {
259-
// We don't compute assessments yet!
260-
return "*";
261-
}
245+
// We don't compute assessments yet!
246+
return "*";
262247
}
263248
catch (std::out_of_range &) {
264249
return "";
@@ -312,10 +297,8 @@ std::string AnalysisProfileList<T>::GetInfosetValue(const GameNode &p_node, int
312297
return lexical_cast<std::string>(m_behavProfiles[index]->GetPayoff(p_node->GetInfoset()),
313298
m_doc->GetStyle().NumDecimals());
314299
}
315-
else {
316-
// In the absence of beliefs, this is not well-defined in general
317-
return "*";
318-
}
300+
// In the absence of beliefs, this is not well-defined in general
301+
return "*";
319302
}
320303
catch (std::out_of_range &) {
321304
return "";
@@ -387,10 +370,8 @@ std::string AnalysisProfileList<T>::GetActionValue(const GameNode &p_node, int p
387370
m_behavProfiles[index]->GetPayoff(p_node->GetInfoset()->GetAction(p_act)),
388371
m_doc->GetStyle().NumDecimals());
389372
}
390-
else {
391-
// In the absence of beliefs, this is not well-defined
392-
return "*";
393-
}
373+
// In the absence of beliefs, this is not well-defined
374+
return "*";
394375
}
395376
catch (std::out_of_range &) {
396377
return "";
@@ -431,7 +412,7 @@ template <class T> void AnalysisProfileList<T>::Save(std::ostream &p_file) const
431412
p_file << "<analysis type=\"list\">\n";
432413

433414
p_file << "<description>\n";
434-
p_file << (const char *)m_description.mb_str() << "\n";
415+
p_file << static_cast<const char *>(m_description.mb_str()) << "\n";
435416
p_file << "</description>\n";
436417

437418
if (m_doc->IsTree()) {
@@ -472,3 +453,5 @@ template <class T> void AnalysisProfileList<T>::Save(std::ostream &p_file) const
472453
// Explicit instantiations
473454
template class AnalysisProfileList<double>;
474455
template class AnalysisProfileList<Rational>;
456+
457+
} // namespace Gambit::GUI

src/gui/analysis.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2121
//
2222

23-
#ifndef ANALYSIS_H
24-
#define ANALYSIS_H
23+
#ifndef GAMBIT_GUI_ANALYSIS_H
24+
#define GAMBIT_GUI_ANALYSIS_H
2525

2626
class TiXmlNode;
27-
class GameDocument;
2827

2928
//
3029
// This file contains classes which manage the output of analysis tools.
@@ -34,7 +33,9 @@ class GameDocument;
3433
// output of stable sets or convex components of equilibria, etc.)
3534
//
3635

37-
using namespace Gambit;
36+
namespace Gambit::GUI {
37+
38+
class GameDocument;
3839

3940
class AnalysisOutput {
4041
protected:
@@ -187,4 +188,6 @@ template <class T> class AnalysisProfileList final : public AnalysisOutput {
187188
//@}
188189
};
189190

190-
#endif // ANALYSIS_H
191+
} // namespace Gambit::GUI
192+
193+
#endif // GAMBIT_GUI_ANALYSIS_H

src/gui/app.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "app.h"
3535
#include "gameframe.h"
3636

37-
Application::Application() : m_fileHistory(10) {}
37+
namespace Gambit::GUI {
3838

3939
bool Application::OnInit()
4040
{
@@ -74,7 +74,7 @@ bool Application::OnInit()
7474
// If we don't have any game files -- whether because none were
7575
// specified on the command line, or because those specified couldn't
7676
// be read -- create a default document.
77-
const Gambit::Game efg = Gambit::NewTree();
77+
const Game efg = NewTree();
7878
efg->NewPlayer()->SetLabel("Player 1");
7979
efg->NewPlayer()->SetLabel("Player 2");
8080
efg->SetTitle("Untitled Extensive Game");
@@ -96,7 +96,7 @@ AppLoadResult Application::LoadFile(const wxString &p_filename)
9696
return GBT_APP_OPEN_FAILED;
9797
}
9898

99-
auto *doc = new GameDocument(Gambit::NewTree());
99+
auto *doc = new GameDocument(NewTree());
100100
if (doc->LoadDocument(p_filename)) {
101101
doc->SetFilename(p_filename);
102102
m_fileHistory.AddFileToHistory(p_filename);
@@ -109,7 +109,7 @@ AppLoadResult Application::LoadFile(const wxString &p_filename)
109109
}
110110

111111
try {
112-
const Gambit::Game nfg = Gambit::ReadGame(infile);
112+
const Game nfg = ReadGame(infile);
113113

114114
m_fileHistory.AddFileToHistory(p_filename);
115115
m_fileHistory.Save(*wxConfigBase::Get());
@@ -118,7 +118,7 @@ AppLoadResult Application::LoadFile(const wxString &p_filename)
118118
(void)new GameFrame(nullptr, doc);
119119
return GBT_APP_FILE_OK;
120120
}
121-
catch (Gambit::InvalidFileException &) {
121+
catch (InvalidFileException &) {
122122
return GBT_APP_PARSE_FAILED;
123123
}
124124
}
@@ -135,4 +135,6 @@ bool Application::AreDocumentsModified() const
135135
std::mem_fn(&GameDocument::IsModified));
136136
}
137137

138-
IMPLEMENT_APP(Application)
138+
} // namespace Gambit::GUI
139+
140+
IMPLEMENT_APP(Gambit::GUI::Application)

src/gui/app.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@
2020
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2121
//
2222

23-
#ifndef GAMBIT_APP_H
24-
#define GAMBIT_APP_H
23+
#ifndef GAMBIT_GUI_APP_H
24+
#define GAMBIT_GUI_APP_H
2525

2626
#include <wx/wx.h>
2727
#include <wx/config.h> // for wxConfig
2828
#include <wx/docview.h> // for wxFileHistory
2929

30-
using namespace Gambit;
30+
namespace Gambit::GUI {
3131

3232
class GameDocument;
3333

3434
enum AppLoadResult { GBT_APP_FILE_OK = 0, GBT_APP_OPEN_FAILED = 1, GBT_APP_PARSE_FAILED = 2 };
3535

3636
class Application final : public wxApp {
3737
wxString m_currentDir; /* Current position in directory tree. */
38-
wxFileHistory m_fileHistory;
38+
wxFileHistory m_fileHistory{10};
3939
std::list<GameDocument *> m_documents;
4040

4141
bool OnInit() override;
4242

4343
public:
44-
Application();
44+
Application() = default;
4545
~Application() override = default;
4646

4747
const wxString &GetCurrentDir() { return m_currentDir; }
@@ -73,6 +73,8 @@ class Application final : public wxApp {
7373
//@}
7474
};
7575

76-
DECLARE_APP(Application)
76+
} // namespace Gambit::GUI
7777

78-
#endif // GAMBIT_APP_H
78+
DECLARE_APP(Gambit::GUI::Application)
79+
80+
#endif // GAMBIT_GUI_APP_H

src/gui/dlabout.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "dlabout.h"
3030
#include "bitmaps/gambitbig.xpm"
3131

32+
namespace Gambit::GUI {
3233
static wxStaticText *FormattedText(wxWindow *p_parent, const wxString &p_label,
3334
const wxFont &p_font)
3435
{
@@ -40,7 +41,7 @@ static wxStaticText *FormattedText(wxWindow *p_parent, const wxString &p_label,
4041
AboutDialog::AboutDialog(wxWindow *p_parent)
4142
: wxDialog(p_parent, wxID_ANY, _T("About Gambit..."), wxDefaultPosition, wxDefaultSize)
4243
{
43-
SetFont(wxFont(12, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
44+
wxWindow::SetFont(wxFont(12, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
4445
auto *topSizer = new wxBoxSizer(wxVERTICAL);
4546

4647
topSizer->Add(new wxStaticBitmap(this, wxID_STATIC, wxBitmap(gambitbig_xpm)), 0,
@@ -61,7 +62,7 @@ AboutDialog::AboutDialog(wxWindow *p_parent)
6162
wxFont(12, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)),
6263
0, wxTOP | wxALIGN_CENTER, 20);
6364
topSizer->Add(
64-
FormattedText(this, _T("http://www.wxwidgets.org"),
65+
FormattedText(this, _T("https://www.wxwidgets.org"),
6566
wxFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)),
6667
0, wxALIGN_CENTER, 5);
6768

@@ -99,6 +100,7 @@ AboutDialog::AboutDialog(wxWindow *p_parent)
99100
topSizer->Fit(this);
100101
topSizer->SetSizeHints(this);
101102

102-
Layout();
103+
wxTopLevelWindowBase::Layout();
103104
CenterOnParent();
104105
}
106+
} // namespace Gambit::GUI

src/gui/dlabout.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2121
//
2222

23-
#ifndef DLABOUT_H
24-
#define DLABOUT_H
23+
#ifndef GAMBIT_GUI_DLABOUT_H
24+
#define GAMBIT_GUI_DLABOUT_H
2525

26-
class AboutDialog : public wxDialog {
26+
namespace Gambit::GUI {
27+
class AboutDialog final : public wxDialog {
2728
public:
2829
explicit AboutDialog(wxWindow *p_parent);
2930
~AboutDialog() override = default;
3031
};
32+
} // namespace Gambit::GUI
3133

32-
#endif // DLABOUT_H
34+
#endif // GAMBIT_GUI_DLABOUT_H

0 commit comments

Comments
 (0)