From 3b9e9b6df1d124b29bfd3715b6cb12cdee18b2ea Mon Sep 17 00:00:00 2001 From: John Fultz Date: Mon, 17 Jul 2023 15:49:09 -0500 Subject: Fix up std:: namespace hygiene. * Remove all uses of `using namespace std` from header files (although a few specific cases of things like `using std::vector` remain) * Move all existing uses of `using namespace std` in cpp files to after the header includes * Make coordinating changes so it builds again. Qt6 builds on Windows were breaking because of namespace collision between std::byte and some version of `byte` in one of Qt's namespaces. That breakage is now fixed. It would be good to systematically clean up all `using` declarations in header files to ensure nothing is leaking out, but that's for another time. --- alphabetparameters.cpp | 1 + alphabetparameters.h | 6 +++--- bag.h | 2 -- board.h | 4 +--- boardparameters.cpp | 1 + boardparameters.h | 4 ++-- bogowinplayer.cpp | 1 + datamanager.cpp | 1 + datamanager.h | 10 ++++------ endgame.cpp | 1 + enumerator.h | 3 +-- game.cpp | 1 + game.h | 4 ++-- generator.h | 2 +- lexiconparameters.cpp | 1 + lexiconparameters.h | 6 ++++-- move.cpp | 1 + move.h | 4 +--- playerlist.h | 4 +--- preendgame.cpp | 1 + quacker/boardsetupdialog.cpp | 2 ++ quacker/boardsetupdialog.h | 2 -- quacker/graphicalboard.cpp | 2 ++ quacker/graphicalreporter.cpp | 2 ++ quacker/lexicondialog.cpp | 2 +- quacker/lexicondialog.h | 1 - quacker/lister.cpp | 3 ++- quacker/newgame.cpp | 2 ++ quacker/oppothread.cpp | 2 ++ quacker/quacker.cpp | 4 ++-- quacker/settings.cpp | 2 ++ quacker/settings.h | 2 -- quackleio/dawgfactory.cpp | 1 + quackleio/dawgfactory.h | 1 + quackleio/flexiblealphabet.cpp | 1 + quackleio/gaddagfactory.cpp | 2 ++ quackleio/gaddagfactory.h | 3 +++ rack.h | 2 -- reporter.cpp | 1 + sim.cpp | 1 + sim.h | 2 ++ strategyparameters.cpp | 1 + strategyparameters.h | 2 +- uv.h | 42 ++++++++++++++++++++---------------------- 44 files changed, 80 insertions(+), 63 deletions(-) diff --git a/alphabetparameters.cpp b/alphabetparameters.cpp index 34c4d14..9d14ceb 100644 --- a/alphabetparameters.cpp +++ b/alphabetparameters.cpp @@ -23,6 +23,7 @@ #include "datamanager.h" using namespace Quackle; +using namespace std; LetterString String::left(const LetterString &letterString, int number) { diff --git a/alphabetparameters.h b/alphabetparameters.h index 26e332e..bfbf00a 100644 --- a/alphabetparameters.h +++ b/alphabetparameters.h @@ -25,7 +25,7 @@ #include "fixedstring.h" #include "uv.h" -using namespace std; +using std::string; #define QUACKLE_MAXIMUM_ALPHABET_SIZE 55 #define QUACKLE_MINIMUM_ALPHABET_SIZE 1 @@ -213,7 +213,7 @@ inline void LetterParameter::setVowel(bool isVowel) m_isVowel = isVowel; } -typedef vector Alphabet; +typedef std::vector Alphabet; class AlphabetParameters { @@ -290,7 +290,7 @@ protected: int m_length; Alphabet m_alphabet; - typedef map LetterLookupMap; + typedef std::map LetterLookupMap; LetterLookupMap m_letterLookup; string m_alphabetName; diff --git a/bag.h b/bag.h index fd44d6e..295fe54 100644 --- a/bag.h +++ b/bag.h @@ -22,8 +22,6 @@ #include "alphabetparameters.h" #include "rack.h" -using namespace std; - namespace Quackle { diff --git a/board.h b/board.h index 3435b82..cf219aa 100644 --- a/board.h +++ b/board.h @@ -27,9 +27,7 @@ #include "move.h" #include "rack.h" -using namespace std; - -typedef bitset LetterBitset; +typedef std::bitset LetterBitset; #define QUACKLE_MAXIMUM_BOARD_SIZE LETTER_STRING_MAXIMUM_LENGTH #define QUACKLE_MINIMUM_BOARD_SIZE 7 diff --git a/boardparameters.cpp b/boardparameters.cpp index 5de6a8d..a77391a 100644 --- a/boardparameters.cpp +++ b/boardparameters.cpp @@ -19,6 +19,7 @@ #include "boardparameters.h" using namespace Quackle; +using namespace std; BoardParameters::BoardParameters() : m_width(15), m_height(15), m_startRow(7), m_startColumn(7) diff --git a/boardparameters.h b/boardparameters.h index 299c34c..b05d4b3 100644 --- a/boardparameters.h +++ b/boardparameters.h @@ -30,8 +30,8 @@ public: BoardParameters(); // Does not serialize name...caller still has to get/set name manually - void Serialize(ostream &stream); - static BoardParameters *Deserialize(istream &stream); + void Serialize(std::ostream &stream); + static BoardParameters *Deserialize(std::istream &stream); int width() const; void setWidth(int width); diff --git a/bogowinplayer.cpp b/bogowinplayer.cpp index 083a94b..124a601 100644 --- a/bogowinplayer.cpp +++ b/bogowinplayer.cpp @@ -29,6 +29,7 @@ //#define DEBUG_COMPUTERPLAYER using namespace Quackle; +using namespace std; SmartBogowin::SmartBogowin() { diff --git a/datamanager.cpp b/datamanager.cpp index ecfeedc..392a5ed 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -34,6 +34,7 @@ #define QUACKLDEBUG using namespace Quackle; +using namespace std; DataManager *DataManager::m_self = 0; diff --git a/datamanager.h b/datamanager.h index ca6ddd3..aa1bb3b 100644 --- a/datamanager.h +++ b/datamanager.h @@ -26,8 +26,6 @@ #include "playerlist.h" -using namespace std; - #define QUACKLE_DATAMANAGER Quackle::DataManager::self() #define QUACKLE_DATAMANAGER_EXISTS Quackle::DataManager::exists() #define QUACKLE_EVALUATOR Quackle::DataManager::self()->evaluator() @@ -125,11 +123,11 @@ public: string userDataDirectory() { return m_userDataDirectory; } void seedRandomNumbers(unsigned int seed); - void seedRandomNumbers(seed_seq& seed); + void seedRandomNumbers(std::seed_seq& seed); int randomInteger(int low, int high); template void shuffle(T& collection) { - lock_guard lock(m_RngMutex); + std::lock_guard lock(m_RngMutex); std::shuffle(collection.begin(), collection.end(), m_mersenneTwisterRng); } @@ -154,8 +152,8 @@ private: PlayerList m_computerPlayers; - mt19937_64 m_mersenneTwisterRng; - mutex m_RngMutex; + std::mt19937_64 m_mersenneTwisterRng; + std::mutex m_RngMutex; }; inline DataManager *DataManager::self() diff --git a/endgame.cpp b/endgame.cpp index 5ebd7c6..99583f3 100644 --- a/endgame.cpp +++ b/endgame.cpp @@ -28,6 +28,7 @@ // #define DEBUG_ENDGAME using namespace Quackle; +using namespace std; Endgame::Endgame() : m_logfileIsOpen(false), m_hasHeader(false), m_dispatch(0) diff --git a/enumerator.h b/enumerator.h index 5d2c2d9..eddef1f 100644 --- a/enumerator.h +++ b/enumerator.h @@ -20,11 +20,10 @@ #define QUACKLE_ENUMERATOR_H #include +using std::vector; #include "bag.h" -using namespace std; - namespace Quackle { class Bag; diff --git a/game.cpp b/game.cpp index aa5a63f..0f2963a 100644 --- a/game.cpp +++ b/game.cpp @@ -31,6 +31,7 @@ #define DEBUG_BAG using namespace Quackle; +using namespace std; Game::Game() : m_defaultComputerPlayer(0) diff --git a/game.h b/game.h index 7cf5708..98031f1 100644 --- a/game.h +++ b/game.h @@ -610,7 +610,7 @@ inline void GamePosition::setExplanatoryNote(const UVString &explanatoryNote) } // simple modifiable list of positions -typedef vector PositionList; +typedef std::vector PositionList; class Game; @@ -836,7 +836,7 @@ public: protected: History m_positions; - typedef map ComputerPlayerMap; + typedef std::map ComputerPlayerMap; ComputerPlayer *m_defaultComputerPlayer; ComputerPlayerMap m_computerPlayers; diff --git a/generator.h b/generator.h index 5a30f40..5fd0d54 100644 --- a/generator.h +++ b/generator.h @@ -25,7 +25,7 @@ #include "game.h" #include "move.h" -using namespace std; +using std::vector; namespace Quackle { diff --git a/lexiconparameters.cpp b/lexiconparameters.cpp index 4f8d53d..bf6851e 100644 --- a/lexiconparameters.cpp +++ b/lexiconparameters.cpp @@ -26,6 +26,7 @@ #include "uv.h" using namespace Quackle; +using namespace std; class Quackle::V0LexiconInterpreter : public LexiconInterpreter { diff --git a/lexiconparameters.h b/lexiconparameters.h index 3d1ac19..96943cc 100644 --- a/lexiconparameters.h +++ b/lexiconparameters.h @@ -23,6 +23,8 @@ #include "gaddag.h" +using std::vector; + namespace Quackle { @@ -31,8 +33,8 @@ class LexiconParameters; class LexiconInterpreter { public: - virtual void loadDawg(ifstream &file, LexiconParameters &lexparams) = 0; - virtual void loadGaddag(ifstream &file, LexiconParameters &lexparams) = 0; + virtual void loadDawg(std::ifstream &file, LexiconParameters &lexparams) = 0; + virtual void loadGaddag(std::ifstream &file, LexiconParameters &lexparams) = 0; virtual void dawgAt(const unsigned char *dawg, int index, unsigned int &p, Letter &letter, bool &t, bool &lastchild, bool &british, int &playability) const = 0; virtual int versionNumber() const = 0; virtual ~LexiconInterpreter() {}; diff --git a/move.cpp b/move.cpp index 9a023f4..7793f27 100644 --- a/move.cpp +++ b/move.cpp @@ -23,6 +23,7 @@ #include "move.h" using namespace Quackle; +using namespace std; bool operator==(const Move &move1, const Move &move2) { diff --git a/move.h b/move.h index 7a66945..1734197 100644 --- a/move.h +++ b/move.h @@ -23,8 +23,6 @@ #include "alphabetparameters.h" -using namespace std; - namespace Quackle { @@ -136,7 +134,7 @@ private: // comparison based on action, then tiles, then horizontalness, then startrow, then endcol bool operator<(const Quackle::Move &move1, const Quackle::Move &move2); -class MoveList : public vector +class MoveList : public std::vector { public: enum SortType { Equity, Score, Alphabetical, Win}; diff --git a/playerlist.h b/playerlist.h index 0f095e2..514de48 100644 --- a/playerlist.h +++ b/playerlist.h @@ -24,14 +24,12 @@ #include "alphabetparameters.h" #include "player.h" -using namespace std; - namespace Quackle { class Player; -class PlayerList : public vector +class PlayerList : public std::vector { public: PlayerList(); diff --git a/preendgame.cpp b/preendgame.cpp index 5a2ff71..0dc6b39 100644 --- a/preendgame.cpp +++ b/preendgame.cpp @@ -27,6 +27,7 @@ #include "resolvent.h" using namespace Quackle; +using namespace std; Preendgame::Preendgame() : m_initialCandidates(30), m_nestednessDenominatorBase(2) diff --git a/quacker/boardsetupdialog.cpp b/quacker/boardsetupdialog.cpp index 33c9f21..e1d8892 100644 --- a/quacker/boardsetupdialog.cpp +++ b/quacker/boardsetupdialog.cpp @@ -32,6 +32,8 @@ #include "widgetfactory.h" #include "settings.h" +using namespace std; + BoardSetupDialog::BoardSetupDialog(QWidget *parent) : QDialog(parent) { resize(700,550); diff --git a/quacker/boardsetupdialog.h b/quacker/boardsetupdialog.h index 0929b66..8a1a34c 100644 --- a/quacker/boardsetupdialog.h +++ b/quacker/boardsetupdialog.h @@ -25,8 +25,6 @@ #include #include -using namespace std; - class QCheckBox; class QComboBox; class QLineEdit; diff --git a/quacker/graphicalboard.cpp b/quacker/graphicalboard.cpp index 0fc3785..6b1d14b 100644 --- a/quacker/graphicalboard.cpp +++ b/quacker/graphicalboard.cpp @@ -33,6 +33,8 @@ #include "quackersettings.h" #include "settings.h" +using namespace std; + const double GraphicalBoardFrame::s_markOtherLengthMultiplier = 0.6; const double TileWidget::s_defaultLetterScale = 0.7; diff --git a/quacker/graphicalreporter.cpp b/quacker/graphicalreporter.cpp index 4c9fa43..a23cc97 100644 --- a/quacker/graphicalreporter.cpp +++ b/quacker/graphicalreporter.cpp @@ -39,6 +39,8 @@ const char *kHtmlHeader = "\n\n" ; +using namespace std; + GraphicalReporter::GraphicalReporter(const QString &outputDirectory, bool generateImages) : m_output(outputDirectory), m_generateImages(generateImages) { diff --git a/quacker/lexicondialog.cpp b/quacker/lexicondialog.cpp index 88e86b1..04092f1 100644 --- a/quacker/lexicondialog.cpp +++ b/quacker/lexicondialog.cpp @@ -278,7 +278,7 @@ void LexiconDialog::accept() void LexiconDialog::updateLexiconInformation(bool firstTime) { - QByteArray hash = m_wordFactory ? QByteArray(m_wordFactory->hashBytes(), 16).toHex() : ""; + QByteArray hash = m_wordFactory ? QByteArray(m_wordFactory->hashBytes(), 16).toHex() : QByteArray(""); QString text; QString lengthText; diff --git a/quacker/lexicondialog.h b/quacker/lexicondialog.h index 4e18398..2834a90 100644 --- a/quacker/lexicondialog.h +++ b/quacker/lexicondialog.h @@ -26,7 +26,6 @@ #include #include -using namespace std; using namespace Quackle; class QComboBox; diff --git a/quacker/lister.cpp b/quacker/lister.cpp index 644dd90..4cfc03e 100644 --- a/quacker/lister.cpp +++ b/quacker/lister.cpp @@ -17,7 +17,6 @@ */ #include -using namespace std; #include @@ -27,6 +26,8 @@ using namespace std; #include "lister.h" #include "customqsettings.h" +using namespace std; + ListerDialog::ListerDialog(QWidget *parent, const QString &settingsGroup, const QString &appName, int flags) : QDialog(parent), m_settingsGroup(settingsGroup), m_appName(appName), m_flags(flags) { diff --git a/quacker/newgame.cpp b/quacker/newgame.cpp index 001d37d..4d5c5a2 100644 --- a/quacker/newgame.cpp +++ b/quacker/newgame.cpp @@ -27,6 +27,8 @@ #include "newgame.h" #include "customqsettings.h" +using namespace std; + NewGameDialog::NewGameDialog(QWidget *parent) : QDialog(parent) { diff --git a/quacker/oppothread.cpp b/quacker/oppothread.cpp index ffeb1ec..c3df7a5 100644 --- a/quacker/oppothread.cpp +++ b/quacker/oppothread.cpp @@ -23,6 +23,8 @@ #include "oppothread.h" +using namespace std; + QuackerDispatch::QuackerDispatch(QObject *parent) : QObject(parent), m_shouldAbort(false) { diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index a244586..7ab54c0 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -19,8 +19,6 @@ #include #include -using namespace std; - #include #include @@ -55,6 +53,8 @@ using namespace std; #include "widgetfactory.h" #include "view.h" +using namespace std; + const int kExtraPlaysToKibitz = 15; TopLevel::TopLevel(QWidget *parent) diff --git a/quacker/settings.cpp b/quacker/settings.cpp index 41ff9a3..6ce139a 100644 --- a/quacker/settings.cpp +++ b/quacker/settings.cpp @@ -44,6 +44,8 @@ #include "graphicalboard.h" #include "lexicondialog.h" +using namespace std; + Settings *Settings::m_self = 0; Settings *Settings::self() { diff --git a/quacker/settings.h b/quacker/settings.h index e0736c0..d732692 100644 --- a/quacker/settings.h +++ b/quacker/settings.h @@ -31,8 +31,6 @@ class QCheckBox; class QPushButton; class QLabel; -using namespace std; - class Settings : public QWidget { Q_OBJECT diff --git a/quackleio/dawgfactory.cpp b/quackleio/dawgfactory.cpp index 60c797d..a320f5c 100644 --- a/quackleio/dawgfactory.cpp +++ b/quackleio/dawgfactory.cpp @@ -26,6 +26,7 @@ #include "dawgfactory.h" #include "util.h" +using namespace std; DawgFactory::DawgFactory(const QString &alphabetFile) : m_encodableWords(0), m_unencodableWords(0), m_duplicateWords(0), diff --git a/quackleio/dawgfactory.h b/quackleio/dawgfactory.h index 04e7cb3..0751df3 100644 --- a/quackleio/dawgfactory.h +++ b/quackleio/dawgfactory.h @@ -24,6 +24,7 @@ #include #include "flexiblealphabet.h" +using std::vector; class DawgFactory { public: diff --git a/quackleio/flexiblealphabet.cpp b/quackleio/flexiblealphabet.cpp index 91d339e..6baf113 100644 --- a/quackleio/flexiblealphabet.cpp +++ b/quackleio/flexiblealphabet.cpp @@ -22,6 +22,7 @@ #include "util.h" using namespace QuackleIO; +using namespace std; FlexibleAlphabetParameters::FlexibleAlphabetParameters() { diff --git a/quackleio/gaddagfactory.cpp b/quackleio/gaddagfactory.cpp index 5d20d38..3fe129d 100644 --- a/quackleio/gaddagfactory.cpp +++ b/quackleio/gaddagfactory.cpp @@ -24,6 +24,8 @@ #include "gaddagfactory.h" #include "util.h" +using namespace std; + GaddagFactory::GaddagFactory(const UVString &alphabetFile) : m_encodableWords(0), m_unencodableWords(0), m_alphas(NULL) { diff --git a/quackleio/gaddagfactory.h b/quackleio/gaddagfactory.h index 364e492..ace0555 100644 --- a/quackleio/gaddagfactory.h +++ b/quackleio/gaddagfactory.h @@ -20,8 +20,11 @@ #define QUACKLE_GADDAGFACTORY_H #include +#include #include "flexiblealphabet.h" +using std::vector; + // This isn't a strict maximum...you can go higher...but too much higher, and you risk overflowing // node pointers, which will get you garbage words. The OSPS dictionary is known to trigger // such overflows. diff --git a/rack.h b/rack.h index 65c98f7..3d35df2 100644 --- a/rack.h +++ b/rack.h @@ -21,8 +21,6 @@ #include "alphabetparameters.h" -using namespace std; - namespace Quackle { diff --git a/reporter.cpp b/reporter.cpp index 92435d6..246da4b 100644 --- a/reporter.cpp +++ b/reporter.cpp @@ -28,6 +28,7 @@ #include "reporter.h" using namespace Quackle; +using namespace std; void Reporter::reportPosition(const GamePosition &position, ComputerPlayer *computerPlayer, UVString *report) { diff --git a/sim.cpp b/sim.cpp index 8fa9cab..eb8461b 100644 --- a/sim.cpp +++ b/sim.cpp @@ -31,6 +31,7 @@ //#define DEBUG_SIM using namespace Quackle; +using namespace std; std::atomic_long SimmedMove::objectIdCounter{0}; diff --git a/sim.h b/sim.h index 0a46c89..6532294 100644 --- a/sim.h +++ b/sim.h @@ -30,6 +30,8 @@ #include "alphabetparameters.h" #include "game.h" +using std::vector; + namespace Quackle { diff --git a/strategyparameters.cpp b/strategyparameters.cpp index 88e66d1..336bf99 100644 --- a/strategyparameters.cpp +++ b/strategyparameters.cpp @@ -25,6 +25,7 @@ #include "strategyparameters.h" using namespace Quackle; +using namespace std; StrategyParameters::StrategyParameters() : m_hasSyn2(false) diff --git a/strategyparameters.h b/strategyparameters.h index 4398c51..12aa56f 100644 --- a/strategyparameters.h +++ b/strategyparameters.h @@ -60,7 +60,7 @@ protected: static const int m_bogowinArrayWidth = 601; static const int m_bogowinArrayHeight = 94; double m_bogowin[m_bogowinArrayWidth][m_bogowinArrayHeight]; - typedef map SuperLeavesMap; + typedef std::map SuperLeavesMap; SuperLeavesMap m_superleaves; bool m_hasSyn2; bool m_hasWorths; diff --git a/uv.h b/uv.h index b4a9a26..d792275 100644 --- a/uv.h +++ b/uv.h @@ -24,8 +24,6 @@ #include #include -using namespace std; - /** Beginning of define options */ // Whether to use wchar for Quackle's user-visible strings. @@ -38,30 +36,30 @@ using namespace std; #if QUACKLE_USE_WCHAR_FOR_USER_VISIBLE -typedef wstring UVString; +typedef std::wstring UVString; typedef wchar_t UVChar; -typedef wstringstream UVStringStream; -typedef wistream UVIStream; -typedef wostream UVOStream; -typedef wostringstream UVOStringStream; -typedef wistringstream UVIStringStream; -typedef wifstream UVIFStream; -typedef wofstream UVOFStream; -#define UVcout wcout -#define UVcerr wcerr +typedef std::wstringstream UVStringStream; +typedef std::wistream UVIStream; +typedef std::wostream UVOStream; +typedef std::wostringstream UVOStringStream; +typedef std::wistringstream UVIStringStream; +typedef std::wifstream UVIFStream; +typedef std::wofstream UVOFStream; +#define UVcout std::wcout +#define UVcerr std::wcerr #define MARK_UV(theString) L ## theString #else -typedef string UVString; +typedef std::string UVString; typedef char UVChar; -typedef stringstream UVStringStream; -typedef istream UVIStream; -typedef ostream UVOStream; -typedef istringstream UVIStringStream; -typedef ostringstream UVOStringStream; -typedef ifstream UVIFStream; -typedef ofstream UVOFStream; -#define UVcout cout -#define UVcerr cerr +typedef std::stringstream UVStringStream; +typedef std::istream UVIStream; +typedef std::ostream UVOStream; +typedef std::istringstream UVIStringStream; +typedef std::ostringstream UVOStringStream; +typedef std::ifstream UVIFStream; +typedef std::ofstream UVOFStream; +#define UVcout std::cout +#define UVcerr std::cerr #define MARK_UV(theString) theString #endif -- cgit v1.2.3