3232#include " analysis.h"
3333#include " gamedoc.h"
3434
35- using namespace Gambit ;
36-
35+ namespace Gambit ::GUI {
3736// =========================================================================
38- // class gbtAnalysisProfileList
37+ // 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 >
51- MixedStrategyProfile<T> OutputToMixedProfile (gbtGameDocument *p_doc, const wxString &p_text)
50+ 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,32 +61,31 @@ MixedStrategyProfile<T> OutputToMixedProfile(gbtGameDocument *p_doc, const wxStr
6461 }
6562 }
6663
67- throw gbtNotNashException ();
64+ throw NotNashException ();
6865}
6966
7067template <class T >
71- MixedBehaviorProfile<T> OutputToBehavProfile (gbtGameDocument *p_doc, const wxString &p_text)
68+ MixedBehaviorProfile<T> OutputToBehavProfile (GameDocument *p_doc, const wxString &p_text)
7269{
7370 MixedBehaviorProfile<T> profile (p_doc->GetGame ());
7471
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
9187
92- template <class T > void gbtAnalysisProfileList <T>::AddOutput(const wxString &p_output)
88+ template <class T > void AnalysisProfileList <T>::AddOutput(const wxString &p_output)
9389{
9490 try {
9591 if (m_isBehav) {
@@ -110,64 +106,59 @@ template <class T> void gbtAnalysisProfileList<T>::AddOutput(const wxString &p_o
110106 m_current = m_mixedProfiles.size ();
111107 }
112108 }
113- catch (gbtNotNashException &) {
109+ catch (NotNashException &) {
114110 }
115111}
116112
117- template <class T > void gbtAnalysisProfileList <T>::BuildNfg()
113+ template <class T > void AnalysisProfileList <T>::BuildNfg()
118114{
119115 for (auto profile : m_behavProfiles) {
120116 m_mixedProfiles.push_back (
121117 std::make_shared<MixedStrategyProfile<T>>(profile->ToMixedProfile ()));
122118 }
123119}
124120
125- template <class T > int gbtAnalysisProfileList <T>::NumProfiles() const
121+ 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
135- template <class T > void gbtAnalysisProfileList <T>::Clear()
126+ template <class T > void AnalysisProfileList <T>::Clear()
136127{
137128 m_behavProfiles.clear ();
138129 m_mixedProfiles.clear ();
139130 m_current = 0 ;
140131}
141132
142133// -------------------------------------------------------------------------
143- // gbtAnalysisProfileList : Saving and loading profile lists
134+ // AnalysisProfileList : Saving and loading profile lists
144135// -------------------------------------------------------------------------
145136
146137// Use anonymous namespace to make these helpers private
147138namespace {
148139
149140template <class T >
150- MixedStrategyProfile<T> TextToMixedProfile (gbtGameDocument *p_doc, const wxString &p_text)
141+ 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;
161152}
162153
163154template <class T >
164- MixedBehaviorProfile<T> TextToBehavProfile (gbtGameDocument *p_doc, const wxString &p_text)
155+ MixedBehaviorProfile<T> TextToBehavProfile (GameDocument *p_doc, const wxString &p_text)
165156{
166157 MixedBehaviorProfile<T> profile (p_doc->GetGame ());
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;
@@ -179,19 +170,17 @@ MixedBehaviorProfile<T> TextToBehavProfile(gbtGameDocument *p_doc, const wxStrin
179170// Load a profile list from XML. Pass a node pointing to an
180171// <analysis> entry in the workbook file
181172//
182- template <class T > void gbtAnalysisProfileList <T>::Load(TiXmlNode *p_analysis)
173+ 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));
@@ -208,7 +197,7 @@ template <class T> void gbtAnalysisProfileList<T>::Load(TiXmlNode *p_analysis)
208197 }
209198}
210199
211- template <class T > std::string gbtAnalysisProfileList <T>::GetPayoff(int pl, int p_index) const
200+ template <class T > std::string AnalysisProfileList <T>::GetPayoff(int pl, int p_index) const
212201{
213202 const int index = (p_index == -1 ) ? m_current : p_index;
214203
@@ -217,18 +206,16 @@ template <class T> std::string gbtAnalysisProfileList<T>::GetPayoff(int pl, int
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 " " ;
227214 }
228215}
229216
230217template <class T >
231- std::string gbtAnalysisProfileList <T>::GetRealizProb(const GameNode &p_node, int p_index) const
218+ std::string AnalysisProfileList <T>::GetRealizProb(const GameNode &p_node, int p_index) const
232219{
233220 const int index = (p_index == -1 ) ? m_current : p_index;
234221
@@ -242,7 +229,7 @@ std::string gbtAnalysisProfileList<T>::GetRealizProb(const GameNode &p_node, int
242229}
243230
244231template <class T >
245- std::string gbtAnalysisProfileList <T>::GetBeliefProb(const GameNode &p_node, int p_index) const
232+ std::string AnalysisProfileList <T>::GetBeliefProb(const GameNode &p_node, int p_index) const
246233{
247234 const int index = (p_index == -1 ) ? m_current : p_index;
248235
@@ -255,19 +242,17 @@ std::string gbtAnalysisProfileList<T>::GetBeliefProb(const GameNode &p_node, int
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 " " ;
265250 }
266251}
267252
268253template <class T >
269- std::string gbtAnalysisProfileList <T>::GetNodeValue(const GameNode &p_node, int p_player,
270- int p_index) const
254+ std::string AnalysisProfileList <T>::GetNodeValue(const GameNode &p_node, int p_player,
255+ int p_index) const
271256{
272257 const int index = (p_index == -1 ) ? m_current : p_index;
273258
@@ -281,7 +266,7 @@ std::string gbtAnalysisProfileList<T>::GetNodeValue(const GameNode &p_node, int
281266}
282267
283268template <class T >
284- std::string gbtAnalysisProfileList <T>::GetInfosetProb(const GameNode &p_node, int p_index) const
269+ std::string AnalysisProfileList <T>::GetInfosetProb(const GameNode &p_node, int p_index) const
285270{
286271 const int index = (p_index == -1 ) ? m_current : p_index;
287272
@@ -299,7 +284,7 @@ std::string gbtAnalysisProfileList<T>::GetInfosetProb(const GameNode &p_node, in
299284}
300285
301286template <class T >
302- std::string gbtAnalysisProfileList <T>::GetInfosetValue(const GameNode &p_node, int p_index) const
287+ std::string AnalysisProfileList <T>::GetInfosetValue(const GameNode &p_node, int p_index) const
303288{
304289 const int index = (p_index == -1 ) ? m_current : p_index;
305290
@@ -312,19 +297,17 @@ std::string gbtAnalysisProfileList<T>::GetInfosetValue(const GameNode &p_node, i
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 " " ;
322305 }
323306}
324307
325308template <class T >
326- std::string gbtAnalysisProfileList <T>::GetActionProb(const GameNode &p_node, int p_act,
327- int p_index) const
309+ std::string AnalysisProfileList <T>::GetActionProb(const GameNode &p_node, int p_act,
310+ int p_index) const
328311{
329312 const int index = (p_index == -1 ) ? m_current : p_index;
330313
@@ -353,7 +336,7 @@ std::string gbtAnalysisProfileList<T>::GetActionProb(const GameNode &p_node, int
353336}
354337
355338template <class T >
356- std::string gbtAnalysisProfileList <T>::GetActionProb(int p_action, int p_index) const
339+ std::string AnalysisProfileList <T>::GetActionProb(int p_action, int p_index) const
357340{
358341 const int index = (p_index == -1 ) ? m_current : p_index;
359342
@@ -372,8 +355,8 @@ std::string gbtAnalysisProfileList<T>::GetActionProb(int p_action, int p_index)
372355}
373356
374357template <class T >
375- std::string gbtAnalysisProfileList <T>::GetActionValue(const GameNode &p_node, int p_act,
376- int p_index) const
358+ std::string AnalysisProfileList <T>::GetActionValue(const GameNode &p_node, int p_act,
359+ int p_index) const
377360{
378361 const int index = (p_index == -1 ) ? m_current : p_index;
379362
@@ -387,18 +370,16 @@ std::string gbtAnalysisProfileList<T>::GetActionValue(const GameNode &p_node, in
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 " " ;
397378 }
398379}
399380
400381template <class T >
401- std::string gbtAnalysisProfileList <T>::GetStrategyProb(int p_strategy, int p_index) const
382+ std::string AnalysisProfileList <T>::GetStrategyProb(int p_strategy, int p_index) const
402383{
403384 const int index = (p_index == -1 ) ? m_current : p_index;
404385
@@ -412,7 +393,7 @@ std::string gbtAnalysisProfileList<T>::GetStrategyProb(int p_strategy, int p_ind
412393}
413394
414395template <class T >
415- std::string gbtAnalysisProfileList <T>::GetStrategyValue(int p_strategy, int p_index) const
396+ std::string AnalysisProfileList <T>::GetStrategyValue(int p_strategy, int p_index) const
416397{
417398 const int index = (p_index == -1 ) ? m_current : p_index;
418399
@@ -426,12 +407,12 @@ std::string gbtAnalysisProfileList<T>::GetStrategyValue(int p_strategy, int p_in
426407 }
427408}
428409
429- template <class T > void gbtAnalysisProfileList <T>::Save(std::ostream &p_file) const
410+ template <class T > void AnalysisProfileList <T>::Save(std::ostream &p_file) const
430411{
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 ()) {
@@ -470,5 +451,7 @@ template <class T> void gbtAnalysisProfileList<T>::Save(std::ostream &p_file) co
470451}
471452
472453// Explicit instantiations
473- template class gbtAnalysisProfileList <double >;
474- template class gbtAnalysisProfileList <Rational>;
454+ template class AnalysisProfileList <double >;
455+ template class AnalysisProfileList <Rational>;
456+
457+ } // namespace Gambit::GUI
0 commit comments