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
4241namespace {
4342
44- class gbtNotNashException final : public std::runtime_error {
43+ class NotNashException final : public std::runtime_error {
4544public:
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
5049template <class T >
5150MixedStrategyProfile<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
7067template <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
125121template <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
135126template <class T > void AnalysisProfileList<T>::Clear()
@@ -149,12 +140,12 @@ namespace {
149140template <class T >
150141MixedStrategyProfile<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
473454template class AnalysisProfileList <double >;
474455template class AnalysisProfileList <Rational>;
456+
457+ } // namespace Gambit::GUI
0 commit comments