[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot dic/compdic.cpp dic/compdic.h dic/encodin...
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot dic/compdic.cpp dic/compdic.h dic/encodin... |
Date: |
Sat, 29 Jan 2011 23:47:23 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 11/01/29 23:47:22
Modified files:
dic : compdic.cpp compdic.h encoding.cpp logging.h
game : board_search.cpp board_search.h duplicate.cpp
duplicate.h freegame.cpp freegame.h game.cpp
game.h game_factory.cpp game_factory.h
game_io.cpp navigation.cpp navigation.h
training.cpp training.h turn_cmd.cpp
xml_reader.cpp xml_reader.h xml_writer.cpp
xml_writer.h
qt : dic_wizard.cpp main.cpp main_window.cpp
main_window.h tile_layout.cpp
utils : ncurses.cpp
Log message:
Simplified the looging macros, and added logs in various key places.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/compdic.cpp?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/compdic.h?cvsroot=eliot&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.cpp?cvsroot=eliot&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/logging.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/board_search.cpp?cvsroot=eliot&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/eliot/game/board_search.h?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.h?cvsroot=eliot&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_factory.cpp?cvsroot=eliot&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_factory.h?cvsroot=eliot&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_io.cpp?cvsroot=eliot&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/eliot/game/navigation.cpp?cvsroot=eliot&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/eliot/game/navigation.h?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/game/training.cpp?cvsroot=eliot&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/eliot/game/training.h?cvsroot=eliot&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn_cmd.cpp?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/xml_reader.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/xml_reader.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/xml_writer.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/xml_writer.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_wizard.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main.cpp?cvsroot=eliot&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.h?cvsroot=eliot&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/tile_layout.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/ncurses.cpp?cvsroot=eliot&r1=1.35&r2=1.36
Patches:
Index: dic/compdic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/compdic.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- dic/compdic.cpp 16 Jan 2011 21:30:31 -0000 1.22
+++ dic/compdic.cpp 29 Jan 2011 23:47:20 -0000 1.23
@@ -23,7 +23,6 @@
#include <fstream>
#include <sstream>
-#include <iostream>
#include <map>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
@@ -65,7 +64,7 @@
#define fmt(a) boost::format(a)
-INIT_LOGGER(CompDic::logger, "Compdic");
+INIT_LOGGER(dic, CompDic);
CompDic::CompDic()
: m_currentRec(0), m_maxRec(0), m_loadTime(0), m_buildTime(0)
@@ -186,7 +185,7 @@
ioEdges[i] = htonl(ioEdges[i]);
}
- LOG_TRACE(logger, fmt("writing %1% edges") % num);
+ LOG_TRACE(fmt("writing %1% edges") % num);
outFile.write((char*)ioEdges, num * sizeof(DicEdge));
}
Index: dic/compdic.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/compdic.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- dic/compdic.h 16 Jan 2011 21:30:31 -0000 1.3
+++ dic/compdic.h 29 Jan 2011 23:47:20 -0000 1.4
@@ -42,7 +42,7 @@
class CompDic
{
- DEFINE_LOGGER(logger);
+ DEFINE_LOGGER();
typedef boost::unordered_map<vector<DicEdge>, unsigned int> HashMap;
public:
Index: dic/encoding.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/encoding.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- dic/encoding.cpp 20 May 2010 20:27:47 -0000 1.15
+++ dic/encoding.cpp 29 Jan 2011 23:47:20 -0000 1.16
@@ -20,7 +20,6 @@
#include "config.h"
-#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdarg>
Index: dic/logging.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/logging.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- dic/logging.h 16 Jan 2011 21:30:31 -0000 1.1
+++ dic/logging.h 29 Jan 2011 23:47:20 -0000 1.2
@@ -26,25 +26,29 @@
#ifdef USE_LOGGING
# include <log4cxx/logger.h>
-# define DEFINE_LOGGER(logger) static log4cxx::LoggerPtr logger;
-# define INIT_LOGGER(logger, name) log4cxx::LoggerPtr
logger(log4cxx::Logger::getLogger(name))
+# define DEFINE_LOGGER() static log4cxx::LoggerPtr logger
+# define INIT_LOGGER(prefix, className) log4cxx::LoggerPtr
className::logger(log4cxx::Logger::getLogger(#prefix "." #className))
-# define LOG_TRACE(a, b) LOG4CXX_TRACE(a, b)
-# define LOG_DEBUG(a, b) LOG4CXX_DEBUG(a, b)
-# define LOG_INFO(a, b) LOG4CXX_INFO(a, b)
-# define LOG_WARN(a, b) LOG4CXX_WARN(a, b)
-# define LOG_ERROR(a, b) LOG4CXX_ERROR(a, b)
-# define LOG_FATAL(a, b) LOG4CXX_FATAL(a, b)
+# define LOG_TRACE(a) LOG4CXX_TRACE(logger, a)
+# define LOG_DEBUG(a) LOG4CXX_DEBUG(logger, a)
+# define LOG_INFO(a) LOG4CXX_INFO(logger, a)
+# define LOG_WARN(a) LOG4CXX_WARN(logger, a)
+# define LOG_ERROR(a) LOG4CXX_ERROR(logger, a)
+# define LOG_FATAL(a) LOG4CXX_FATAL(logger, a)
+# define LOG_ROOT_ERROR(a) LOG4CXX_ERROR(log4cxx::Logger::getRootLogger(), a)
+# define LOG_ROOT_FATAL(a) LOG4CXX_FATAL(log4cxx::Logger::getRootLogger(), a)
#else
-# define DEFINE_LOGGER(logger)
-# define INIT_LOGGER(logger, name)
+# define DEFINE_LOGGER()
+# define INIT_LOGGER(prefix, name)
-# define LOG_TRACE(a, b)
-# define LOG_DEBUG(a, b)
-# define LOG_INFO(a, b)
-# define LOG_WARN(a, b)
-# define LOG_ERROR(a, b)
-# define LOG_FATAL(a, b)
+# define LOG_TRACE(a)
+# define LOG_DEBUG(a)
+# define LOG_INFO(a)
+# define LOG_WARN(a)
+# define LOG_ERROR(a)
+# define LOG_FATAL(a)
+# define LOG_ROOT_ERROR(a)
+# define LOG_ROOT_FATAL(a)
#endif // USE_LOGGING
#endif
Index: game/board_search.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/board_search.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- game/board_search.cpp 17 Jan 2009 14:57:32 -0000 1.18
+++ game/board_search.cpp 29 Jan 2011 23:47:21 -0000 1.19
@@ -19,9 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
-#include "dic.h"
+#include <cwctype> // For towupper
#include "board_search.h"
+#include "dic.h"
#include "board.h"
#include "tile.h"
#include "rack.h"
Index: game/board_search.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/board_search.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- game/board_search.h 29 Nov 2009 16:01:32 -0000 1.2
+++ game/board_search.h 29 Jan 2011 23:47:21 -0000 1.3
@@ -25,6 +25,7 @@
#include "matrix.h"
class Dictionary;
+class Tile;
class Rack;
class Results;
class Round;
Index: game/duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- game/duplicate.cpp 6 Mar 2010 16:54:20 -0000 1.34
+++ game/duplicate.cpp 29 Jan 2011 23:47:21 -0000 1.35
@@ -45,9 +45,13 @@
#include "mark_played_cmd.h"
#include "ai_player.h"
#include "settings.h"
+#include "encoding.h"
#include "debug.h"
+INIT_LOGGER(game, Duplicate);
+
+
Duplicate::Duplicate(const Dictionary &iDic)
: Game(iDic)
{
@@ -177,6 +181,7 @@
void Duplicate::recordPlayerMove(const Move &iMove, Player &ioPlayer, bool
isForHuman)
{
+ LOG_INFO("Player " << ioPlayer.getId() << " plays: " <<
convertToMb(iMove.toString()));
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
pCmd->setAutoExecution(!isForHuman);
accessNavigation().addAndExecute(pCmd);
@@ -278,6 +283,7 @@
void Duplicate::endGame()
{
+ LOG_INFO("End of the game");
m_finished = true;
}
Index: game/duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- game/duplicate.h 29 Nov 2009 16:01:32 -0000 1.23
+++ game/duplicate.h 29 Jan 2011 23:47:21 -0000 1.24
@@ -23,6 +23,7 @@
#include "game.h"
#include "command.h"
+#include "logging.h"
class Player;
@@ -53,6 +54,7 @@
*/
class Duplicate: public Game
{
+ DEFINE_LOGGER();
friend class GameFactory;
friend class MarkPlayedCmd;
public:
Index: game/freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- game/freegame.cpp 29 Nov 2009 16:01:32 -0000 1.33
+++ game/freegame.cpp 29 Jan 2011 23:47:21 -0000 1.34
@@ -40,9 +40,12 @@
#include "ai_player.h"
#include "settings.h"
#include "turn.h"
+#include "encoding.h"
#include "debug.h"
+INIT_LOGGER(game, FreeGame);
+
FreeGame::FreeGame(const Dictionary &iDic)
: Game(iDic)
@@ -113,6 +116,7 @@
void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer,
bool isForHuman)
{
+ LOG_INFO("Player " << ioPlayer.getId() << " plays: " <<
convertToMb(iMove.toString()));
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
pCmd->setAutoExecution(!isForHuman);
accessNavigation().addAndExecute(pCmd);
@@ -189,6 +193,8 @@
// Adjust the scores of the players with the points of the remaining tiles
void FreeGame::endGame()
{
+ LOG_INFO("End of the game");
+
vector<Tile> tiles;
// TODO: According to the rules of the game in the ODS, a game can end in 3
Index: game/freegame.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- game/freegame.h 29 Nov 2009 16:01:32 -0000 1.18
+++ game/freegame.h 29 Jan 2011 23:47:21 -0000 1.19
@@ -22,6 +22,7 @@
#define FREEGAME_H_
#include "game.h"
+#include "logging.h"
class Player;
@@ -42,6 +43,7 @@
*/
class FreeGame: public Game
{
+ DEFINE_LOGGER();
friend class GameFactory;
public:
virtual GameMode getMode() const { return kFREEGAME; }
Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- game/game.cpp 29 Nov 2009 16:01:32 -0000 1.58
+++ game/game.cpp 29 Jan 2011 23:47:21 -0000 1.59
@@ -46,6 +46,8 @@
#include "debug.h"
+INIT_LOGGER(game, Game);
+
const unsigned int Game::RACK_SIZE = 7;
const int Game::BONUS_POINTS = 50;
@@ -77,6 +79,7 @@
void Game::shuffleRack()
{
+ LOG_DEBUG("Shuffling rack for player " << currPlayer());
PlayedRack pld = getCurrentPlayer().getCurrentRack();
pld.shuffle();
m_players[currPlayer()]->setCurrentRack(pld);
@@ -340,11 +343,10 @@
// Get the best word
const Round & bestRound = res.get(0);
-#ifdef DEBUG
- cout << "helperSetRackRandom(): initial rack: "
+ LOG_DEBUG("helperSetRackRandom(): initial rack: "
<< convertToMb(pld.toString()) << " (best word: "
- << convertToMb(bestRound.getWord()) << ")" << endl;
-#endif
+ << convertToMb(bestRound.getWord()) << ")");
+
// Identify the joker
for (unsigned int i = 0; i < bestRound.getWordLen(); ++i)
{
@@ -352,10 +354,9 @@
{
const Tile &jokerTile = bestRound.getTile(i);
Tile replacingTile(towupper(jokerTile.toChar()));
-#ifdef DEBUG
- cout << "helperSetRackRandom(): replacing Joker with "
- << convertToMb(replacingTile.toChar()) << endl;
-#endif
+ LOG_DEBUG("helperSetRackRandom(): replacing Joker with "
+ << convertToMb(replacingTile.toChar()));
+
// If the bag does not contain this letter anymore,
// simply keep the joker in the rack.
if (bag.in(replacingTile))
@@ -457,6 +458,10 @@
// The ID of the player is its position in the m_players vector
iPlayer->setId(getNPlayers());
m_players.push_back(iPlayer);
+
+ LOG_INFO("Adding player '" << convertToMb(iPlayer->getName())
+ << "' (" << (iPlayer->isHuman() ? "human" : "AI") << ")"
+ << " with ID " << iPlayer->getId());
}
Index: game/game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- game/game.h 29 Nov 2009 16:01:32 -0000 1.52
+++ game/game.h 29 Jan 2011 23:47:21 -0000 1.53
@@ -24,7 +24,7 @@
#include <string>
#include <vector>
-#include <iostream>
+#include "logging.h"
#include "bag.h"
#include "board.h"
#include "history.h"
@@ -48,6 +48,7 @@
*/
class Game
{
+ DEFINE_LOGGER();
public:
/// Game specs.
static const unsigned int RACK_SIZE;
Index: game/game_factory.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_factory.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- game/game_factory.cpp 29 Nov 2009 16:01:32 -0000 1.13
+++ game/game_factory.cpp 29 Jan 2011 23:47:21 -0000 1.14
@@ -45,6 +45,8 @@
#include "xml_reader.h"
+INIT_LOGGER(game, GameFactory);
+
GameFactory *GameFactory::m_factory = NULL;
@@ -76,6 +78,7 @@
Training *GameFactory::createTraining(const Dictionary &iDic)
{
+ LOG_INFO("Creating a training game");
Training *game = new Training(iDic);
return game;
}
@@ -83,6 +86,7 @@
FreeGame *GameFactory::createFreeGame(const Dictionary &iDic)
{
+ LOG_INFO("Creating a free game");
FreeGame *game = new FreeGame(iDic);
return game;
}
@@ -90,6 +94,7 @@
Duplicate *GameFactory::createDuplicate(const Dictionary &iDic)
{
+ LOG_INFO("Creating a duplicate game");
Duplicate *game = new Duplicate(iDic);
return game;
}
Index: game/game_factory.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_factory.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- game/game_factory.h 29 Nov 2009 16:01:32 -0000 1.12
+++ game/game_factory.h 29 Jan 2011 23:47:21 -0000 1.13
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
+#include "logging.h"
using std::string;
using std::wstring;
@@ -44,6 +45,7 @@
*/
class GameFactory
{
+ DEFINE_LOGGER();
public:
static GameFactory *Instance();
static void Destroy();
Index: game/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_io.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- game/game_io.cpp 29 Nov 2009 16:01:32 -0000 1.14
+++ game/game_io.cpp 29 Jan 2011 23:47:21 -0000 1.15
@@ -21,6 +21,7 @@
#include <cstring>
#include <cstdlib> // For atoi
+#include <cwctype> // For iswlower
#include <cstdio>
#include "dic.h"
Index: game/navigation.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/navigation.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- game/navigation.cpp 29 Nov 2009 16:01:32 -0000 1.10
+++ game/navigation.cpp 29 Jan 2011 23:47:21 -0000 1.11
@@ -28,6 +28,8 @@
#include "encoding.h"
+INIT_LOGGER(game, Navigation);
+
Navigation::Navigation()
: m_currTurn(0)
{
@@ -46,6 +48,7 @@
void Navigation::newTurn()
{
+ LOG_INFO("New turn");
lastTurn();
m_turnCommands.push_back(new TurnCmd);
++m_currTurn;
@@ -98,6 +101,7 @@
{
if (m_currTurn > 1)
{
+ LOG_DEBUG("Navigating to the previous turn");
--m_currTurn;
m_turnCommands[m_currTurn]->undo();
// Special case: when the last turn is empty, automatically
@@ -115,6 +119,7 @@
{
if (m_currTurn < m_turnCommands.size())
{
+ LOG_DEBUG("Navigating to the next turn");
m_turnCommands[m_currTurn]->execute();
++m_currTurn;
// Special case: when the last turn is empty, automatically
@@ -130,6 +135,7 @@
void Navigation::firstTurn()
{
+ LOG_DEBUG("Navigating to the first turn");
while (m_currTurn > 1)
{
prevTurn();
@@ -139,6 +145,7 @@
void Navigation::lastTurn()
{
+ LOG_DEBUG("Navigating to the last turn");
while (m_currTurn < m_turnCommands.size())
{
nextTurn();
@@ -148,6 +155,8 @@
void Navigation::clearFuture()
{
+ LOG_DEBUG("Erasing all the future turns");
+
// Replay the auto-execution turns
// (i.e. turns where only the AI was involved)
while (!isLastTurn() && m_turnCommands[m_currTurn]->isAutoExecution())
@@ -180,12 +189,12 @@
void Navigation::print() const
{
- cout << "=== Commands history ===" << endl;
- cout << "Current position right after turn " << m_currTurn - 1 << endl;
+ LOG_DEBUG("=== Commands history ===");
+ LOG_DEBUG("Current position right after turn " << m_currTurn - 1);
int index = 0;
BOOST_FOREACH(const Command *c, m_turnCommands)
{
- cout << index << " " << convertToMb(c->toString()) << endl;
+ LOG_DEBUG(index << " " << convertToMb(c->toString()));
++index;
}
}
Index: game/navigation.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/navigation.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- game/navigation.h 29 Nov 2009 16:01:32 -0000 1.5
+++ game/navigation.h 29 Jan 2011 23:47:21 -0000 1.6
@@ -22,6 +22,7 @@
#define NAVIGATION_H_
#include <vector>
+#include "logging.h"
class TurnCmd;
class Command;
@@ -31,6 +32,7 @@
class Navigation
{
+ DEFINE_LOGGER();
public:
Navigation();
~Navigation();
Index: game/training.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- game/training.cpp 29 Nov 2009 16:01:32 -0000 1.35
+++ game/training.cpp 29 Jan 2011 23:47:21 -0000 1.36
@@ -20,6 +20,7 @@
*****************************************************************************/
#include <algorithm>
+#include <cwctype> // For towupper
#if ENABLE_NLS
# include <libintl.h>
@@ -45,6 +46,9 @@
#include "debug.h"
+INIT_LOGGER(game, Training);
+
+
Training::Training(const Dictionary &iDic)
: Game(iDic), m_results(1000)
{
@@ -105,6 +109,7 @@
void Training::recordPlayerMove(const Move &iMove, Player &ioPlayer)
{
+ LOG_INFO("Player " << ioPlayer.getId() << " plays: " <<
convertToMb(iMove.toString()));
// Update the rack and the score of the current player
// PlayerMoveCmd::execute() must be called before Game::helperPlayMove()
// (called in this class in endTurn()).
Index: game/training.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- game/training.h 29 Nov 2009 16:01:32 -0000 1.26
+++ game/training.h 29 Jan 2011 23:47:21 -0000 1.27
@@ -27,6 +27,7 @@
#include "game.h"
#include "round.h"
#include "results.h"
+#include "logging.h"
class Player;
@@ -44,6 +45,7 @@
*/
class Training: public Game
{
+ DEFINE_LOGGER();
friend class GameFactory;
public:
virtual GameMode getMode() const { return kTRAINING; }
Index: game/turn_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn_cmd.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- game/turn_cmd.cpp 30 Nov 2008 20:55:46 -0000 1.4
+++ game/turn_cmd.cpp 29 Jan 2011 23:47:21 -0000 1.5
@@ -83,10 +83,10 @@
wstring TurnCmd::toString() const
{
wostringstream oss;
- oss << L"TurnCmd:" << endl;
+ oss << L"TurnCmd:";
BOOST_FOREACH(Command *cmd, m_commands)
{
- oss << L" " << cmd->toString() << endl;
+ oss << endl << L" " << cmd->toString();
}
return oss.str();
}
Index: game/xml_reader.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/xml_reader.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- game/xml_reader.cpp 6 Mar 2010 16:53:37 -0000 1.2
+++ game/xml_reader.cpp 29 Jan 2011 23:47:21 -0000 1.3
@@ -40,12 +40,17 @@
using namespace std;
+INIT_LOGGER(game, XmlReader);
+
Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
{
// Try to load the old format first
+ LOG_INFO("Parsing savegame '" << iFileName << "'");
+
try
{
+ LOG_DEBUG("Trying old format");
FILE *fin = fopen(iFileName.c_str(), "r");
if (fin != NULL)
{
@@ -53,14 +58,20 @@
fclose(fin);
if (game != NULL)
+ {
+ LOG_INFO("Savegame parsed successfully");
return game;
}
}
+ }
catch (const GameException &e)
{
// Ignore the exception
+ LOG_DEBUG("This doesn't look like the old format");
}
+ LOG_DEBUG("Trying XML format");
+
ifstream is(iFileName.c_str());
if (!is.is_open())
throw LoadGameException("Cannot open file '" + iFileName + "'");
@@ -79,6 +90,8 @@
Game *game = handler.getGame();
if (game == NULL)
throw LoadGameException(handler.errorMessage);
+
+ LOG_INFO("Savegame parsed successfully");
return game;
}
@@ -155,12 +168,8 @@
{
(void) namespaceURI;
(void) qName;
-#if 0
- if (!localName.empty())
- std::cout << "Start Element: " << namespaceURI << ":" << localName <<
std::endl;
- else
- std::cout << "Start Element: " << qName << std::endl;
-#endif
+ LOG_DEBUG("Start Element: " << (localName.empty() ? qName : namespaceURI +
":" + localName));
+
m_data.clear();
const string &tag = localName;
if (tag == "Player")
@@ -196,9 +205,8 @@
const string&)
{
(void) namespaceURI;
-#if 0
- std::cout << "endElement: " << namespaceURI << ":" << localName << "(" <<
m_data << ")" << std::endl;
-#endif
+ LOG_DEBUG("endElement: " << namespaceURI << ":" << localName << "(" <<
m_data << ")");
+
const string &tag = localName;
if (tag == "Mode")
{
@@ -276,16 +284,12 @@
throw LoadGameException("Rack invalid for the current dictionary:
" + m_data);
}
pldrack.setManual(rackStr);
-#if 0
- cerr << "loaded rack: " << convertToMb(pldrack.toString()) << endl;
-#endif
+ LOG_DEBUG("loaded rack: " << convertToMb(pldrack.toString()));
Player &p = getPlayer(m_players, m_attributes["playerid"]);
PlayerRackCmd *cmd = new PlayerRackCmd(p, pldrack);
m_game->accessNavigation().addAndExecute(cmd);
-#if 0
- cerr << "rack: " << convertToMb(pldrack.toString()) << endl;
-#endif
+ LOG_DEBUG("rack: " << convertToMb(pldrack.toString()));
}
else if (tag == "PlayerMove")
@@ -310,15 +314,14 @@
void XmlReader::characters(const string& ch)
{
m_data += ch;
-#if 0
- std::cout << "Characters: " << ch << std::endl;
-#endif
+ LOG_DEBUG("Characters: " << ch);
}
void XmlReader::warning(const Arabica::SAX::SAXParseException<string>&
exception)
{
errorMessage = string("warning: ") + exception.what();
+ LOG_WARN(errorMessage);
//throw LoadGameException(string("warning: ") + exception.what());
}
@@ -326,6 +329,7 @@
void XmlReader::error(const Arabica::SAX::SAXParseException<string>& exception)
{
errorMessage = string("error: ") + exception.what();
+ LOG_ERROR(errorMessage);
//throw LoadGameException(string("error: ") + exception.what());
}
@@ -333,6 +337,7 @@
void XmlReader::fatalError(const Arabica::SAX::SAXParseException<string>&
exception)
{
errorMessage = string("fatal error: ") + exception.what();
+ LOG_FATAL(errorMessage);
//throw LoadGameException(string("fatal error: ") + exception.what());
}
Index: game/xml_reader.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/xml_reader.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- game/xml_reader.h 29 Nov 2009 16:01:33 -0000 1.1
+++ game/xml_reader.h 29 Jan 2011 23:47:21 -0000 1.2
@@ -25,6 +25,7 @@
#include <SAX/Locator.hpp>
#include <SAX/Attributes.hpp>
#include <SAX/SAXException.hpp>
+#include "logging.h"
class Dictionary;
class Game;
@@ -36,6 +37,7 @@
class XmlReader : public Arabica::SAX::DefaultHandler<string>
{
+ DEFINE_LOGGER();
public:
virtual ~XmlReader() {}
Index: game/xml_writer.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/xml_writer.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- game/xml_writer.cpp 6 Mar 2010 16:54:20 -0000 1.2
+++ game/xml_writer.cpp 29 Jan 2011 23:47:21 -0000 1.3
@@ -39,6 +39,7 @@
using namespace std;
+INIT_LOGGER(game, XmlWriter);
static void addIndent(string &s)
{
@@ -81,6 +82,7 @@
void XmlWriter::write(const Game &iGame, const string &iFileName)
{
+ LOG_INFO("Saving game into '" << iFileName << "'");
ofstream out(iFileName.c_str());
if (!out.is_open())
throw SaveGameException("Cannot open file for writing: '" + iFileName
+ "'");
Index: game/xml_writer.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/xml_writer.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- game/xml_writer.h 29 Nov 2009 16:01:33 -0000 1.1
+++ game/xml_writer.h 29 Jan 2011 23:47:21 -0000 1.2
@@ -21,6 +21,7 @@
#define XML_WRITER_H_
#include <iosfwd>
+#include "logging.h"
class Game;
@@ -29,6 +30,7 @@
class XmlWriter
{
+ DEFINE_LOGGER();
public:
static void write(const Game &iGame, const string &iFileName);
};
Index: qt/dic_wizard.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_wizard.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- qt/dic_wizard.cpp 19 May 2010 19:28:09 -0000 1.5
+++ qt/dic_wizard.cpp 29 Jan 2011 23:47:21 -0000 1.6
@@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
-#include <iostream>
-
#include <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtGui/QHeaderView>
Index: qt/main.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- qt/main.cpp 17 Oct 2010 21:23:40 -0000 1.8
+++ qt/main.cpp 29 Jan 2011 23:47:21 -0000 1.9
@@ -22,10 +22,10 @@
#include <string>
#include <exception>
-#include <iostream>
#include <QApplication>
#include <QLocale>
#include <QTranslator>
+#include "logging.h"
#include "base_exception.h"
#include "stacktrace.h"
#include "main_window.h"
@@ -63,8 +63,7 @@
}
catch (const BaseException &e)
{
- cerr << "Exception caught: " << e.what() << endl;
- cerr << e.getStackTrace() << endl;
+ LOG_ROOT_ERROR("Exception caught: " << e.what() << "\n" <<
e.getStackTrace());
return false;
}
}
@@ -166,9 +165,8 @@
#ifdef HAVE_EXECINFO_H
static void bt_sighandler(int signum)
{
- cerr << "Segmentation fault!" << endl;
- cerr << "Backtrace:" << endl;
- cerr << StackTrace::GetStack() << endl;
+ LOG_ROOT_FATAL("Segmentation fault!");
+ LOG_ROOT_FATAL("Backtrace:\n" << StackTrace::GetStack());
// Restore the default handler to generate a nice core dump
signal(signum, SIG_DFL);
Index: qt/main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- qt/main_window.cpp 17 Oct 2010 21:24:18 -0000 1.39
+++ qt/main_window.cpp 29 Jan 2011 23:47:21 -0000 1.40
@@ -60,6 +60,8 @@
#include "coord.h"
+INIT_LOGGER(qt, MainWindow);
+
const char *MainWindow::m_windowName = "MainWindow";
MainWindow::MainWindow(QWidget *iParent)
@@ -67,6 +69,7 @@
m_prefsDialog(NULL), m_bagWindow(NULL), m_boardWindow(NULL),
m_historyWindow(NULL), m_dicToolsWindow(NULL), m_dicNameLabel(NULL)
{
+ LOG_DEBUG("Creating main window");
m_ui.setupUi(this);
createMenu();
readSettings();
@@ -79,10 +82,9 @@
// but we would lose the desktop integration...
unsigned int val = time(NULL);
srand(val);
-#ifdef DEBUG
+
// Make it easier to reproduce bugs
- cout << "Rand seed: " << val << endl;
-#endif
+ LOG_DEBUG("Rand seed: " << val);
QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)),
this, SLOT(updateForGame(const PublicGame*)));
@@ -162,6 +164,7 @@
QString dicPath = qs.value(PrefsDialog::kINTF_DIC_PATH, "").toString();
if (dicPath != "")
{
+ LOG_INFO("Using dictionary " << qtl(dicPath));
try
{
m_dic = new Dictionary(qtl(dicPath));
@@ -193,6 +196,8 @@
if (m_game == NULL)
return;
+ LOG_DEBUG("Destroying current game");
+
// Some controls, like the board, can live when there is no game.
// We only have to give them a NULL handler instead of the current one.
emit gameChangedNonConst(NULL);
@@ -202,6 +207,8 @@
delete m_game;
m_game = NULL;
+
+ LOG_DEBUG("Game destroyed");
}
@@ -217,8 +224,7 @@
m_actionHistoryLastTurn->setEnabled(!isLastTurn);
m_actionHistoryReplayTurn->setEnabled(!isLastTurn);
#ifdef DEBUG
- cout << endl << endl;
- m_game->printTurns();
+ //m_game->printTurns();
#endif
}
}
@@ -226,6 +232,7 @@
void MainWindow::prefsUpdated()
{
+ LOG_DEBUG("Preferences updated");
// Disconnect the training rack updates from the "Plus 1" tab of the
// dictionary tools
m_playersWidget->disconnect(SIGNAL(trainingRackUpdated(const QString&)));
@@ -295,6 +302,7 @@
void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
{
+ LOG_ERROR("Displayed error: " << qtl(iMsg));
if (iContext == "")
iContext = _q("Eliot - Error");
@@ -304,6 +312,7 @@
void MainWindow::displayInfoMsg(QString iMsg)
{
+ LOG_INFO("Displayed message: " << qtl(iMsg));
statusBar()->showMessage(iMsg);
}
@@ -364,6 +373,8 @@
return;
}
+ LOG_INFO("Loading new dictionary file: " << qtl(iFileName));
+
destroyCurrentGame();
try
@@ -437,7 +448,7 @@
false, QIcon(":/images/printer.png"));
menuFile->addSeparator();
addMenuAction(menuFile, _q("&Quit"), _q("Ctrl+Q"),
- _q("Quit Eliot"), SLOT(close()),
+ _q("Quit Eliot"), SLOT(onGameQuit()),
false, QIcon(":/images/quit_16px.png"));
QMenu *menuHistory = new QMenu(m_ui.menubar);
@@ -505,6 +516,8 @@
void MainWindow::onGameNew()
{
+ LOG_DEBUG("Starting a new game (unconfirmed)");
+
if (m_dic == NULL)
{
displayErrorMsg(_q("You have to select a dictionary (.dawg file) "
@@ -538,11 +551,11 @@
m_ui.groupBoxPlayers->show();
+ displayInfoMsg(_q("Game started"));
m_game->start();
emit gameChangedNonConst(m_game);
emit gameChanged(m_game);
emit gameUpdated();
- displayInfoMsg(_q("Game started"));
}
@@ -600,6 +613,7 @@
void MainWindow::onGamePrint()
{
+ LOG_DEBUG("Printing game (unconfirmed)");
if (m_game == NULL)
return;
@@ -607,6 +621,8 @@
QPrintDialog printDialog(&printer, this);
if (printDialog.exec() == QDialog::Accepted)
{
+ LOG_INFO("Printing game");
+
QPainter painter(&printer);
const History &history = m_game->getHistory();
@@ -740,10 +756,19 @@
// Total score
nextHeight += LINE_HEIGHT;
painter.drawText(curWidth, nextHeight, QString("%1").arg(score));
+
+ LOG_INFO("Game printed");
}
}
+void MainWindow::onGameQuit()
+{
+ LOG_INFO("Exiting");
+ close();
+}
+
+
void MainWindow::onSettingsPreferences()
{
if (m_prefsDialog == NULL)
Index: qt/main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- qt/main_window.h 17 Oct 2010 21:24:18 -0000 1.19
+++ qt/main_window.h 29 Jan 2011 23:47:21 -0000 1.20
@@ -24,6 +24,7 @@
#include <QMainWindow>
#include <ui/main_window.ui.h>
+#include "logging.h"
#include "coord_model.h"
@@ -41,6 +42,7 @@
class MainWindow: public QMainWindow
{
+ DEFINE_LOGGER();
Q_OBJECT;
public:
@@ -67,6 +69,7 @@
void onGameLoad();
void onGameSaveAs();
void onGamePrint();
+ void onGameQuit();
void onSettingsChooseDic();
void onSettingsCreateDic();
void onSettingsPreferences();
Index: qt/tile_layout.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/tile_layout.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- qt/tile_layout.cpp 1 Nov 2010 17:49:55 -0000 1.2
+++ qt/tile_layout.cpp 29 Jan 2011 23:47:21 -0000 1.3
@@ -19,8 +19,6 @@
*****************************************************************************/
#include <cmath>
-// XXX: tmp
-#include <iostream>
#include "tile_layout.h"
#include "tile_widget.h"
Index: utils/ncurses.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/ncurses.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- utils/ncurses.cpp 1 Feb 2010 21:26:11 -0000 1.35
+++ utils/ncurses.cpp 29 Jan 2011 23:47:22 -0000 1.36
@@ -33,6 +33,7 @@
#include <ctype.h>
#include <cstring> // For strlen
+#include <cwctype> // For iswalnum
#include <algorithm>
#include "ncurses.h"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot dic/compdic.cpp dic/compdic.h dic/encodin...,
Olivier Teulière <=