Rename Turn into TurnData (step 2)

This commit is contained in:
Olivier Teulière 2012-10-06 01:57:39 +02:00
parent fa345a9f7b
commit 471dcf90e1
12 changed files with 36 additions and 36 deletions

View file

@ -37,7 +37,7 @@ class Player;
class PlayedRack; class PlayedRack;
class Round; class Round;
class Rack; class Rack;
class Turn; class TurnData;
using namespace std; using namespace std;

View file

@ -36,7 +36,7 @@ INIT_LOGGER(game, History);
History::History() History::History()
{ {
Turn* t = new Turn(); TurnData *t = new TurnData();
m_history.clear(); m_history.clear();
m_history.push_back(t); m_history.push_back(t);
} }
@ -44,7 +44,7 @@ History::History()
History::~History() History::~History()
{ {
BOOST_FOREACH(Turn *turn, m_history) BOOST_FOREACH(TurnData *turn, m_history)
{ {
delete turn; delete turn;
} }
@ -70,7 +70,7 @@ void History::setCurrentRack(const PlayedRack &iPld)
} }
const Turn& History::getPreviousTurn() const const TurnData& History::getPreviousTurn() const
{ {
int idx = m_history.size() - 2; int idx = m_history.size() - 2;
ASSERT(0 <= idx , "No previous turn"); ASSERT(0 <= idx , "No previous turn");
@ -78,7 +78,7 @@ const Turn& History::getPreviousTurn() const
} }
const Turn& History::getTurn(unsigned int n) const const TurnData& History::getTurn(unsigned int n) const
{ {
ASSERT(n < m_history.size(), "Wrong turn number"); ASSERT(n < m_history.size(), "Wrong turn number");
return *(m_history[n]); return *(m_history[n]);
@ -100,14 +100,14 @@ void History::playMove(unsigned int iPlayer,
const Move &iMove, const Move &iMove,
const PlayedRack &iNewRack) const PlayedRack &iNewRack)
{ {
Turn * current_turn = m_history.back(); TurnData * current_turn = m_history.back();
// Set the number and the round // Set the number and the round
current_turn->setPlayer(iPlayer); current_turn->setPlayer(iPlayer);
current_turn->setMove(iMove); current_turn->setMove(iMove);
// Create a new turn // Create a new turn
Turn * next_turn = new Turn(); TurnData * next_turn = new TurnData();
next_turn->setPlayedRack(iNewRack); next_turn->setPlayedRack(iNewRack);
m_history.push_back(next_turn); m_history.push_back(next_turn);
} }
@ -120,13 +120,13 @@ void History::removeLastTurn()
if (idx > 1) if (idx > 1)
{ {
Turn *t = m_history.back(); TurnData *t = m_history.back();
m_history.pop_back(); m_history.pop_back();
delete t; delete t;
} }
// Now we have the previous played round in back() // Now we have the previous played round in back()
Turn *t = m_history.back(); TurnData *t = m_history.back();
t->setPlayer(0); t->setPlayer(0);
//t->setRound(Round()); //t->setRound(Round());
#ifdef BACK_REMOVE_RACK_NEW_PART #ifdef BACK_REMOVE_RACK_NEW_PART
@ -178,7 +178,7 @@ wstring History::toString() const
_swprintf(buff, 4, L"%ld", m_history.size()); _swprintf(buff, 4, L"%ld", m_history.size());
rs = L"history size = " + wstring(buff) + L"\n\n"; rs = L"history size = " + wstring(buff) + L"\n\n";
#endif #endif
BOOST_FOREACH(const Turn *turn, m_history) BOOST_FOREACH(const TurnData *turn, m_history)
{ {
rs += turn->toString() + L"\n"; rs += turn->toString() + L"\n";
} }

View file

@ -31,7 +31,7 @@ using std::wstring;
using std::vector; using std::vector;
class Move; class Move;
class Turn; class TurnData;
class PlayedRack; class PlayedRack;
/** /**
@ -40,7 +40,7 @@ class PlayedRack;
* - one for the complete game * - one for the complete game
* - one for each player * - one for each player
* *
* The top of the history is an empty Turn until it has been filled * The top of the history is an empty TurnData until it has been filled
* and the game is up to a new turn. So a History object is never empty. * and the game is up to a new turn. So a History object is never empty.
* However, the getSize() method only returns the number of complete * However, the getSize() method only returns the number of complete
* turns, and can therefore return 0. * turns, and can therefore return 0.
@ -69,10 +69,10 @@ public:
void setCurrentRack(const PlayedRack &iPld); void setCurrentRack(const PlayedRack &iPld);
/// Get the previous (complete) turn /// Get the previous (complete) turn
const Turn& getPreviousTurn() const; const TurnData& getPreviousTurn() const;
/// Get turn 'n' (starting at 0) /// Get turn 'n' (starting at 0)
const Turn& getTurn(unsigned int) const; const TurnData& getTurn(unsigned int) const;
/** /**
* Return true if the history doesn't contain at least one move * Return true if the history doesn't contain at least one move
@ -102,7 +102,7 @@ public:
wstring toString() const; wstring toString() const;
private: private:
vector<Turn*> m_history; vector<TurnData*> m_history;
}; };
#endif #endif

View file

@ -30,7 +30,7 @@
using std::wstring; using std::wstring;
class Turn; class TurnData;
class Rack; class Rack;

View file

@ -24,19 +24,19 @@
#include "turn_data.h" #include "turn_data.h"
INIT_LOGGER(game, Turn); INIT_LOGGER(game, TurnData);
// FIXME: move set to an arbitrary one (no move). It would be better to get rid of this // FIXME: move set to an arbitrary one (no move). It would be better to get rid of this
// constructor completely // constructor completely
Turn::Turn() TurnData::TurnData()
: m_playerId(0), m_warningsNb(0), : m_playerId(0), m_warningsNb(0),
m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0) m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
{ {
} }
Turn::Turn(unsigned int iPlayerId, const PlayedRack& iPldRack, TurnData::TurnData(unsigned int iPlayerId, const PlayedRack& iPldRack,
const Move& iMove) const Move& iMove)
: m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove), : m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove),
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0) m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
@ -44,7 +44,7 @@ Turn::Turn(unsigned int iPlayerId, const PlayedRack& iPldRack,
} }
wstring Turn::toString() const wstring TurnData::toString() const
{ {
wostringstream oss; wostringstream oss;
oss << m_pldrack.toString() << L" " << m_move.toString() oss << m_pldrack.toString() << L" " << m_move.toString()

View file

@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/ *****************************************************************************/
#ifndef TURN_H_ #ifndef TURN_DATA_H_
#define TURN_H_ #define TURN_DATA_H_
#include <string> #include <string>
#include "pldrack.h" #include "pldrack.h"
@ -31,19 +31,19 @@ using std::wstring;
/** /**
* A Turn is the information about one 'move' done by a player. * A TurnData is the information about one 'move' done by a player.
* It consists of the player who played, the rack, and the actual move. * It consists of the player who played, the rack, and the actual move.
* *
* This class has no logic, it is merely there to aggregate corresponding * This class has no logic, it is merely there to aggregate corresponding
* data. * data.
*/ */
class Turn class TurnData
{ {
DEFINE_LOGGER(); DEFINE_LOGGER();
public: public:
Turn(); TurnData();
Turn(unsigned int iPlayerId, TurnData(unsigned int iPlayerId,
const PlayedRack& iPldRack, const Move& iMove); const PlayedRack& iPldRack, const Move& iMove);
void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; } void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; }
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; } void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }

View file

@ -168,7 +168,7 @@ void HistoryWidget::updateModel()
QColor color = Qt::black; QColor color = Qt::black;
const Turn& t = m_history->getTurn(i); const TurnData& t = m_history->getTurn(i);
const Move& m = t.getMove(); const Move& m = t.getMove();
// Set data common to all moves // Set data common to all moves

View file

@ -950,7 +950,7 @@ void MainWindow::onGamePrint()
nextHeight = curHeight + LINE_HEIGHT; nextHeight = curHeight + LINE_HEIGHT;
for (unsigned int i = 0; i < history.getSize(); ++i) for (unsigned int i = 0; i < history.getSize(); ++i)
{ {
const Turn &t = history.getTurn(i); const TurnData &t = history.getTurn(i);
const Move &m = t.getMove(); const Move &m = t.getMove();
curWidth = TEXT_OFFSET; curWidth = TEXT_OFFSET;

View file

@ -281,7 +281,7 @@ void StatsWidget::setModelText(const QModelIndex &iIndex,
void StatsWidget::setModelTurnData(const QModelIndex &iIndex, void StatsWidget::setModelTurnData(const QModelIndex &iIndex,
const Turn &iTurn, const Turn &iGameTurn) const TurnData &iTurn, const TurnData &iGameTurn)
{ {
// Set the text (score for the turn) // Set the text (score for the turn)
if (!iTurn.getMove().isNull()) if (!iTurn.getMove().isNull())
@ -327,7 +327,7 @@ void StatsWidget::setModelEventData(const QModelIndex &iIndex,
} }
QString StatsWidget::getTooltip(const Turn &iTurn, const Turn &iGameTurn) const QString StatsWidget::getTooltip(const TurnData &iTurn, const TurnData &iGameTurn) const
{ {
QString tooltip = _q("Rack: %1").arg(qfw(iTurn.getPlayedRack().toString())); QString tooltip = _q("Rack: %1").arg(qfw(iTurn.getPlayedRack().toString()));
const Move &move = iTurn.getMove(); const Move &move = iTurn.getMove();

View file

@ -28,7 +28,7 @@
class PublicGame; class PublicGame;
class Player; class Player;
class Turn; class TurnData;
class QTableView; class QTableView;
class QStandardItemModel; class QStandardItemModel;
class QVariant; class QVariant;
@ -70,7 +70,7 @@ private:
QModelIndex getIndex(int row, int col) const; QModelIndex getIndex(int row, int col) const;
QString getTooltip(const Turn &iTurn, const Turn &iGameTurn) const; QString getTooltip(const TurnData &iTurn, const TurnData &iGameTurn) const;
void setSectionHidden(int index, bool iHide); void setSectionHidden(int index, bool iHide);
void setModelSize(int rowCount, int colCount); void setModelSize(int rowCount, int colCount);
@ -78,7 +78,7 @@ private:
void setModelText(const QModelIndex &iIndex, const QVariant &iData, void setModelText(const QModelIndex &iIndex, const QVariant &iData,
bool useBoldFont = false); bool useBoldFont = false);
void setModelTurnData(const QModelIndex &iIndex, void setModelTurnData(const QModelIndex &iIndex,
const Turn &iTurn, const Turn &iGameTurn); const TurnData &iTurn, const TurnData &iGameTurn);
void setModelEventData(const QModelIndex &iIndex, void setModelEventData(const QModelIndex &iIndex,
int iEvent, const Player &iPlayer); int iEvent, const Player &iPlayer);
}; };

View file

@ -233,7 +233,7 @@ void GameIO::printGameDebug(ostream &out, const PublicGame &iGame)
out << " ===|===|==========|================|=====|=====|======" << endl; out << " ===|===|==========|================|=====|=====|======" << endl;
for (unsigned int i = 0; i < iGame.getHistory().getSize(); ++i) for (unsigned int i = 0; i < iGame.getHistory().getSize(); ++i)
{ {
const Turn &turn = iGame.getHistory().getTurn(i); const TurnData &turn = iGame.getHistory().getTurn(i);
const Move &move = turn.getMove(); const Move &move = turn.getMove();
format fmter("%1% | %2% | %3% | %4% | %5% | %6% | %7%"); format fmter("%1% | %2% | %3% | %4% | %5% | %6% | %7%");
fmter % padAndConvert(str(wformat(L"%1%") % (i + 1)), 5); fmter % padAndConvert(str(wformat(L"%1%") % (i + 1)), 5);

View file

@ -395,7 +395,7 @@ void CursesIntf::drawHistory(Box &ioBox) const
for (i = ioBox.getFirstLine(); for (i = ioBox.getFirstLine();
i < (int)m_game->getHistory().getSize() && i < ioBox.getLastLine(); i++) i < (int)m_game->getHistory().getSize() && i < ioBox.getLastLine(); i++)
{ {
const Turn& t = m_game->getHistory().getTurn(i); const TurnData& t = m_game->getHistory().getTurn(i);
const Move& m = t.getMove(); const Move& m = t.getMove();
if (m.isValid()) if (m.isValid())
{ {