diff --git a/src/cheat/BankRomCheat.cxx b/src/cheat/BankRomCheat.cxx index 5e37258fc..236d83dd1 100644 --- a/src/cheat/BankRomCheat.cxx +++ b/src/cheat/BankRomCheat.cxx @@ -21,11 +21,11 @@ #include "BankRomCheat.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BankRomCheat::BankRomCheat(OSystem& os, const string& name, const string& code) +BankRomCheat::BankRomCheat(OSystem& os, string_view name, string_view code) : Cheat(os, name, code) { if(myCode.length() == 7) - myCode = "0" + code; + myCode = "0" + string{code}; bank = unhex(myCode.substr(0, 2)); address = 0xf000 + unhex(myCode.substr(2, 3)); diff --git a/src/cheat/BankRomCheat.hxx b/src/cheat/BankRomCheat.hxx index c75b3ed96..91546731b 100644 --- a/src/cheat/BankRomCheat.hxx +++ b/src/cheat/BankRomCheat.hxx @@ -23,7 +23,7 @@ class BankRomCheat : public Cheat { public: - BankRomCheat(OSystem& os, const string& name, const string& code); + BankRomCheat(OSystem& os, string_view name, string_view code); ~BankRomCheat() override = default; bool enable() override; diff --git a/src/cheat/Cheat.hxx b/src/cheat/Cheat.hxx index 23dd757c5..b21187f34 100644 --- a/src/cheat/Cheat.hxx +++ b/src/cheat/Cheat.hxx @@ -25,7 +25,7 @@ class OSystem; class Cheat { public: - Cheat(OSystem& osystem, const string& name, const string& code) + Cheat(OSystem& osystem, string_view name, string_view code) : myOSystem{osystem}, myName{name == "" ? code : name}, myCode{code} { } @@ -41,7 +41,7 @@ class Cheat virtual void evaluate() = 0; protected: - static uInt16 unhex(const string& hex) + static uInt16 unhex(string_view hex) { int ret = 0; for(const auto c: hex) diff --git a/src/cheat/CheatManager.cxx b/src/cheat/CheatManager.cxx index b1cda388f..a506c3082 100644 --- a/src/cheat/CheatManager.cxx +++ b/src/cheat/CheatManager.cxx @@ -33,7 +33,7 @@ CheatManager::CheatManager(OSystem& osystem) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CheatManager::add(const string& name, const string& code, +bool CheatManager::add(string_view name, string_view code, bool enable, int idx) { const shared_ptr cheat = createCheat(name, code); @@ -79,7 +79,7 @@ void CheatManager::remove(int idx) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::addPerFrame(const string& name, const string& code, bool enable) +void CheatManager::addPerFrame(string_view name, string_view code, bool enable) { // The actual cheat will always be in the main list; we look there first shared_ptr cheat; @@ -117,7 +117,7 @@ void CheatManager::addPerFrame(const string& name, const string& code, bool enab } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::addOneShot(const string& name, const string& code) +void CheatManager::addOneShot(string_view name, string_view code) { // Evaluate this cheat once, and then immediately discard it const shared_ptr cheat = createCheat(name, code); @@ -126,7 +126,7 @@ void CheatManager::addOneShot(const string& name, const string& code) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr CheatManager::createCheat(const string& name, const string& code) const +shared_ptr CheatManager::createCheat(string_view name, string_view code) const { if(!isValidCode(code)) return nullptr; @@ -143,7 +143,7 @@ shared_ptr CheatManager::createCheat(const string& name, const string& co } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::parse(const string& cheats) +void CheatManager::parse(string_view cheats) { StringList s; string::size_type lastPos = cheats.find_first_not_of(',', 0); @@ -198,7 +198,7 @@ void CheatManager::parse(const string& cheats) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::enable(const string& code, bool enable) +void CheatManager::enable(string_view code, bool enable) { for(const auto& cheat: myCheatList) { @@ -263,7 +263,7 @@ void CheatManager::saveCheatDatabase() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::loadCheats(const string& md5sum) +void CheatManager::loadCheats(string_view md5sum) { myPerFrameList.clear(); myCheatList.clear(); @@ -287,7 +287,7 @@ void CheatManager::loadCheats(const string& md5sum) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatManager::saveCheats(const string& md5sum) +void CheatManager::saveCheats(string_view md5sum) { ostringstream cheats; for(uInt32 i = 0; i < myCheatList.size(); ++i) @@ -322,7 +322,7 @@ void CheatManager::saveCheats(const string& md5sum) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CheatManager::isValidCode(const string& code) +bool CheatManager::isValidCode(string_view code) { for(const auto c: code) if(!isxdigit(c)) diff --git a/src/cheat/CheatManager.hxx b/src/cheat/CheatManager.hxx index 0e1eea5cc..075fc21ae 100644 --- a/src/cheat/CheatManager.hxx +++ b/src/cheat/CheatManager.hxx @@ -49,7 +49,7 @@ class CheatManager @return Whether the cheat was created and enabled. */ - bool add(const string& name, const string& code, + bool add(string_view name, string_view code, bool enable = true, int idx = -1); /** @@ -68,7 +68,7 @@ class CheatManager @param code The actual cheatcode @param enable Add or remove the cheat to the per-frame list */ - void addPerFrame(const string& name, const string& code, bool enable); + void addPerFrame(string_view name, string_view code, bool enable); /** Creates and enables a one-shot cheat. One-shot cheats are the @@ -78,7 +78,7 @@ class CheatManager @param name Name of the cheat (not absolutely required) @param code The actual cheatcode (in hex) */ - void addOneShot(const string& name, const string& code); + void addOneShot(string_view name, string_view code); /** Enable/disabled the cheat specified by the given code. @@ -86,7 +86,7 @@ class CheatManager @param code The actual cheatcode to search for @param enable Enable/disable the cheat */ - void enable(const string& code, bool enable); + void enable(string_view code, bool enable); /** Returns the game cheatlist. @@ -111,17 +111,17 @@ class CheatManager /** Load cheats for ROM with given MD5sum to cheatlist(s). */ - void loadCheats(const string& md5sum); + void loadCheats(string_view md5sum); /** Saves cheats for ROM with given MD5sum to cheat map. */ - void saveCheats(const string& md5sum); + void saveCheats(string_view md5sum); /** Checks if a code is valid. */ - static bool isValidCode(const string& code); + static bool isValidCode(string_view code); private: /** @@ -132,14 +132,14 @@ class CheatManager @return The cheat (if was created), else nullptr. */ - shared_ptr createCheat(const string& name, const string& code) const; + shared_ptr createCheat(string_view name, string_view code) const; /** Parses a list of cheats and adds/enables each one. @param cheats Comma-separated list of cheats (without any names) */ - void parse(const string& cheats); + void parse(string_view cheats); private: OSystem& myOSystem; @@ -147,7 +147,7 @@ class CheatManager CheatList myCheatList; CheatList myPerFrameList; - std::map myCheatMap; + std::map> myCheatMap; string myCheatFile; // This is set each time a new cheat/ROM is loaded, for later diff --git a/src/cheat/CheetahCheat.cxx b/src/cheat/CheetahCheat.cxx index 36d706a95..271da4fa1 100644 --- a/src/cheat/CheetahCheat.cxx +++ b/src/cheat/CheetahCheat.cxx @@ -21,7 +21,7 @@ #include "CheetahCheat.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -CheetahCheat::CheetahCheat(OSystem& os, const string& name, const string& code) +CheetahCheat::CheetahCheat(OSystem& os, string_view name, string_view code) : Cheat(os, name, code), address{static_cast(0xf000 + unhex(code.substr(0, 3)))}, value{static_cast(unhex(code.substr(3, 2)))}, diff --git a/src/cheat/CheetahCheat.hxx b/src/cheat/CheetahCheat.hxx index 4742b7e41..f3ed33de9 100644 --- a/src/cheat/CheetahCheat.hxx +++ b/src/cheat/CheetahCheat.hxx @@ -23,7 +23,7 @@ class CheetahCheat : public Cheat { public: - CheetahCheat(OSystem& os, const string& name, const string& code); + CheetahCheat(OSystem& os, string_view name, string_view code); ~CheetahCheat() override = default; bool enable() override; diff --git a/src/cheat/RamCheat.cxx b/src/cheat/RamCheat.cxx index 51fd412b6..2d07ab8bb 100644 --- a/src/cheat/RamCheat.cxx +++ b/src/cheat/RamCheat.cxx @@ -23,7 +23,7 @@ #include "RamCheat.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -RamCheat::RamCheat(OSystem& os, const string& name, const string& code) +RamCheat::RamCheat(OSystem& os, string_view name, string_view code) : Cheat(os, name, code), address{static_cast(unhex(myCode.substr(0, 2)))}, value{static_cast(unhex(myCode.substr(2, 2)))} diff --git a/src/cheat/RamCheat.hxx b/src/cheat/RamCheat.hxx index 1fd897542..c69f8a079 100644 --- a/src/cheat/RamCheat.hxx +++ b/src/cheat/RamCheat.hxx @@ -23,7 +23,7 @@ class RamCheat : public Cheat { public: - RamCheat(OSystem& os, const string& name, const string& code); + RamCheat(OSystem& os, string_view name, string_view code); ~RamCheat() override = default; bool enable() override; diff --git a/src/common/FBBackendSDL2.cxx b/src/common/FBBackendSDL2.cxx index 83b199a2a..b3fb34cc0 100644 --- a/src/common/FBBackendSDL2.cxx +++ b/src/common/FBBackendSDL2.cxx @@ -454,14 +454,14 @@ bool FBBackendSDL2::createRenderer() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FBBackendSDL2::setTitle(const string& title) +void FBBackendSDL2::setTitle(string_view title) { ASSERT_MAIN_THREAD; myScreenTitle = title; if(myWindow) - SDL_SetWindowTitle(myWindow, title.c_str()); + SDL_SetWindowTitle(myWindow, string{title}.c_str()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FBBackendSDL2.hxx b/src/common/FBBackendSDL2.hxx index 80a5d4d03..353b7c800 100644 --- a/src/common/FBBackendSDL2.hxx +++ b/src/common/FBBackendSDL2.hxx @@ -78,7 +78,7 @@ class FBBackendSDL2 : public FBBackend @param title The title of the application / window */ - void setTitle(const string& title) override; + void setTitle(string_view title) override; /** Shows or hides the cursor based on the given boolean value. diff --git a/src/common/FSNodeFactory.hxx b/src/common/FSNodeFactory.hxx index f11568943..83884cb77 100644 --- a/src/common/FSNodeFactory.hxx +++ b/src/common/FSNodeFactory.hxx @@ -44,7 +44,7 @@ class FSNodeFactory enum class Type { SYSTEM, ZIP }; public: - static unique_ptr create(const string& path, Type type) + static unique_ptr create(string_view path, Type type) { switch(type) { diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 033235488..e779e6e61 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -26,7 +26,7 @@ #include "FSNodeZIP.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNodeZIP::FSNodeZIP(const string& p) +FSNodeZIP::FSNodeZIP(string_view p) { // Extract ZIP file and virtual file (if specified) const size_t pos = BSPF::findIgnoreCase(p, ".zip"); diff --git a/src/common/FSNodeZIP.hxx b/src/common/FSNodeZIP.hxx index 643b59c84..46cd860bf 100644 --- a/src/common/FSNodeZIP.hxx +++ b/src/common/FSNodeZIP.hxx @@ -40,11 +40,11 @@ class FSNodeZIP : public AbstractFSNode * * @param path String with the path the new node should point to. */ - explicit FSNodeZIP(const string& path); + explicit FSNodeZIP(string_view path); bool exists() const override; - const string& getName() const override { return _name; } - void setName(const string& name) override { _name = name; } + const string& getName() const override { return _name; } + void setName(string_view name) override { _name = name; } const string& getPath() const override { return _path; } string getShortPath() const override { return _shortPath; } bool hasParent() const override { return true; } @@ -56,7 +56,7 @@ class FSNodeZIP : public AbstractFSNode ////////////////////////////////////////////////////////// // For now, ZIP files cannot be modified in any way bool makeDir() override { return false; } - bool rename(const string& newfile) override { return false; } + bool rename(string_view) override { return false; } ////////////////////////////////////////////////////////// size_t getSize() const override { return _size; } diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index 44c54eb36..97581efd9 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -537,9 +537,9 @@ HSM::ScoreAddresses HighScoresManager::getPropScoreAddr(const json& jprops) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 HighScoresManager::fromHexStr(const string& addr) +uInt16 HighScoresManager::fromHexStr(string_view addr) { - string naked = addr; + string naked{addr}; if(const int pos = naked.find("0x") != std::string::npos) naked = naked.substr(pos + 1); diff --git a/src/common/HighScoresManager.hxx b/src/common/HighScoresManager.hxx index 9b1e18c6a..01fba6500 100644 --- a/src/common/HighScoresManager.hxx +++ b/src/common/HighScoresManager.hxx @@ -232,7 +232,7 @@ class HighScoresManager uInt16 defVal = 0); static HSM::ScoreAddresses getPropScoreAddr(const json& jprops); - static uInt16 fromHexStr(const string& addr); + static uInt16 fromHexStr(string_view addr); static Int32 fromBCD(uInt8 bcd); string hash(const HSM::ScoresData& data) const; diff --git a/src/common/Logger.cxx b/src/common/Logger.cxx index add0fc2b9..3bc786926 100644 --- a/src/common/Logger.cxx +++ b/src/common/Logger.cxx @@ -26,44 +26,46 @@ Logger& Logger::instance() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Logger::log(const string& message, Level level) +void Logger::log(string_view message, Level level) { instance().logMessage(message, level); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Logger::error(const string& message) +void Logger::error(string_view message) { instance().logMessage(message, Level::ERR); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Logger::info(const string& message) +void Logger::info(string_view message) { instance().logMessage(message, Level::INFO); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Logger::debug(const string& message) +void Logger::debug(string_view message) { instance().logMessage(message, Level::DEBUG); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Logger::logMessage(const string& message, Level level) +void Logger::logMessage(string_view message, Level level) { const std::lock_guard lock(mutex); if(level == Logger::Level::ERR) { cout << message << endl << std::flush; - myLogMessages += message + "\n"; + myLogMessages += message; + myLogMessages += "\n"; } else if(static_cast(level) <= myLogLevel || level == Logger::Level::ALWAYS) { if(myLogToConsole) cout << message << endl << std::flush; - myLogMessages += message + "\n"; + myLogMessages += message; + myLogMessages += "\n"; } } diff --git a/src/common/Logger.hxx b/src/common/Logger.hxx index 807d88403..cf2abd8a2 100644 --- a/src/common/Logger.hxx +++ b/src/common/Logger.hxx @@ -40,13 +40,13 @@ class Logger { static Logger& instance(); - static void log(const string& message, Level level = Level::ALWAYS); + static void log(string_view message, Level level = Level::ALWAYS); - static void error(const string& message); + static void error(string_view message); - static void info(const string& message); + static void info(string_view message); - static void debug(const string& message); + static void debug(string_view message); void setLogParameters(int logLevel, bool logToConsole); void setLogParameters(Level logLevel, bool logToConsole); @@ -66,7 +66,7 @@ class Logger { std::mutex mutex; private: - void logMessage(const string& message, Level level); + void logMessage(string_view message, Level level); Logger(const Logger&) = delete; Logger(Logger&&) = delete; diff --git a/src/common/MouseControl.cxx b/src/common/MouseControl.cxx index 15dbbbb3b..6d2932890 100644 --- a/src/common/MouseControl.cxx +++ b/src/common/MouseControl.cxx @@ -23,12 +23,12 @@ #include "MouseControl.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -MouseControl::MouseControl(Console& console, const string& mode) +MouseControl::MouseControl(Console& console, string_view mode) : myProps{console.properties()}, myLeftController{console.leftController()}, myRightController{console.rightController()} { - istringstream m_axis(mode); + istringstream m_axis(string{mode}); // TODO: fixed in C++20 string m_mode; m_axis >> m_mode; diff --git a/src/common/MouseControl.hxx b/src/common/MouseControl.hxx index ea0cfb145..6d5f146f5 100644 --- a/src/common/MouseControl.hxx +++ b/src/common/MouseControl.hxx @@ -55,7 +55,7 @@ class MouseControl @param console The console in use by the system @param mode Contains information about how to use the mouse axes/buttons */ - MouseControl(Console& console, const string& mode); + MouseControl(Console& console, string_view mode); /** Cycle through each available mouse control mode @@ -85,10 +85,10 @@ class MouseControl int xid{-1}, yid{-1}; string message; - explicit MouseMode(const string& msg = "") : message{msg} { } + explicit MouseMode(string_view msg = "") : message{msg} { } MouseMode(Controller::Type xt, int xi, Controller::Type yt, int yi, - const string& msg) + string_view msg) : xtype{xt}, ytype{yt}, xid{xi}, yid{yi}, message{msg} { } friend ostream& operator<<(ostream& os, const MouseMode& mm) diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index cb4a443b1..d855bc49c 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -217,7 +217,7 @@ bool PhysicalJoystickHandler::remove(int id) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool PhysicalJoystickHandler::remove(const string& name) +bool PhysicalJoystickHandler::remove(string_view name) { const auto it = myDatabase.find(name); if(it != myDatabase.end() && it->second.joy == nullptr) @@ -229,7 +229,7 @@ bool PhysicalJoystickHandler::remove(const string& name) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool PhysicalJoystickHandler::mapStelladaptors(const string& saport, int ID) +bool PhysicalJoystickHandler::mapStelladaptors(string_view saport, int ID) { bool erased = false; // saport will have two values: diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index 730422dd4..d44c8f561 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -73,8 +73,8 @@ class PhysicalJoystickHandler /** Return stick ID on success, -1 on failure. */ int add(const PhysicalJoystickPtr& stick); bool remove(int id); - bool remove(const string& name); - bool mapStelladaptors(const string& saport, int ID = -1); + bool remove(string_view name); + bool mapStelladaptors(string_view saport, int ID = -1); bool hasStelladaptors() const; void setDefaultMapping(Event::Type event, EventMode mode); @@ -126,7 +126,7 @@ class PhysicalJoystickHandler void changeDrivingSensitivity(int direction = +1); private: - using StickDatabase = std::map; + using StickDatabase = std::map>; using StickList = std::map; OSystem& myOSystem; diff --git a/src/common/PaletteHandler.cxx b/src/common/PaletteHandler.cxx index 94b719e0a..c2d133459 100644 --- a/src/common/PaletteHandler.cxx +++ b/src/common/PaletteHandler.cxx @@ -29,7 +29,7 @@ PaletteHandler::PaletteHandler(OSystem& system) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -PaletteHandler::PaletteType PaletteHandler::toPaletteType(const string& name) const +PaletteHandler::PaletteType PaletteHandler::toPaletteType(string_view name) const { if(name == SETTING_Z26) return PaletteType::Z26; @@ -301,7 +301,7 @@ void PaletteHandler::getAdjustables(Adjustable& adjustable) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PaletteHandler::setPalette(const string& name) +void PaletteHandler::setPalette(string_view name) { myOSystem.settings().setValue("palette", name); diff --git a/src/common/PaletteHandler.hxx b/src/common/PaletteHandler.hxx index ada3f1f48..2e4e082c4 100644 --- a/src/common/PaletteHandler.hxx +++ b/src/common/PaletteHandler.hxx @@ -113,7 +113,7 @@ class PaletteHandler @param name The palette to switch to */ - void setPalette(const string& name); + void setPalette(string_view name); /** Sets the palette from current settings. @@ -178,7 +178,7 @@ class PaletteHandler @return The palette type */ - PaletteType toPaletteType(const string& name) const; + PaletteType toPaletteType(string_view name) const; /** Convert enumeration to palette settings name. diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index 24653aec5..55de85cca 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -37,9 +37,9 @@ struct Point constexpr Point() = default; explicit constexpr Point(Int32 x1, Int32 y1) : x{x1}, y{y1} { } - explicit Point(const string& p) { + explicit Point(string_view p) { char c = '\0'; - istringstream buf(p); + istringstream buf(string{p}); // TODO: fixed in C++20 buf >> x >> c >> y; if(c != 'x') x = y = 0; @@ -60,9 +60,9 @@ struct Size constexpr Size() = default; explicit constexpr Size(uInt32 w1, uInt32 h1) : w{w1}, h{h1} { } - explicit Size(const string& s) { + explicit Size(string_view s) { char c = '\0'; - istringstream buf(s); + istringstream buf(string{s}); // TODO: fixed in C++20 buf >> w >> c >> h; if(c != 'x') w = h = 0; diff --git a/src/common/RewindManager.cxx b/src/common/RewindManager.cxx index 7c31bb92a..2ebde0303 100644 --- a/src/common/RewindManager.cxx +++ b/src/common/RewindManager.cxx @@ -96,7 +96,7 @@ void RewindManager::setup() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool RewindManager::addState(const string& message, bool timeMachine) +bool RewindManager::addState(string_view message, bool timeMachine) { // only check for Time Machine states, ignore for debugger if(timeMachine && myStateList.currentIsValid()) diff --git a/src/common/RewindManager.hxx b/src/common/RewindManager.hxx index 795927181..8c6bf425c 100644 --- a/src/common/RewindManager.hxx +++ b/src/common/RewindManager.hxx @@ -107,7 +107,7 @@ class RewindManager @param message Message to display when replaying this state */ - bool addState(const string& message, bool timeMachine = false); + bool addState(string_view message, bool timeMachine = false); /** Rewind numStates levels of the state list, and display the message associated diff --git a/src/common/StaggeredLogger.cxx b/src/common/StaggeredLogger.cxx index d7ab3d892..504cda434 100644 --- a/src/common/StaggeredLogger.cxx +++ b/src/common/StaggeredLogger.cxx @@ -36,7 +36,7 @@ namespace { } // namespace // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -StaggeredLogger::StaggeredLogger(const string& message, Logger::Level level) +StaggeredLogger::StaggeredLogger(string_view message, Logger::Level level) : myMessage{message}, myLevel{level} { diff --git a/src/common/StaggeredLogger.hxx b/src/common/StaggeredLogger.hxx index 76de24349..ad6389463 100644 --- a/src/common/StaggeredLogger.hxx +++ b/src/common/StaggeredLogger.hxx @@ -38,7 +38,7 @@ class StaggeredLogger { public: - StaggeredLogger(const string& message, Logger::Level level); + StaggeredLogger(string_view message, Logger::Level level); ~StaggeredLogger(); void log(); diff --git a/src/common/StateManager.cxx b/src/common/StateManager.cxx index 11689550a..d3c29ac1a 100644 --- a/src/common/StateManager.cxx +++ b/src/common/StateManager.cxx @@ -139,7 +139,7 @@ void StateManager::toggleTimeMachine() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool StateManager::addExtraState(const string& message) +bool StateManager::addExtraState(string_view message) { if(myActiveMode == Mode::TimeMachine) { diff --git a/src/common/StateManager.hxx b/src/common/StateManager.hxx index 6383accf2..eefbd2285 100644 --- a/src/common/StateManager.hxx +++ b/src/common/StateManager.hxx @@ -77,7 +77,7 @@ class StateManager Optionally adds one extra state when entering the Time Machine dialog; this uses the RewindManager for its functionality. */ - bool addExtraState(const string& message); + bool addExtraState(string_view message); /** Rewinds states; this uses the RewindManager for its functionality. diff --git a/src/common/StringParser.hxx b/src/common/StringParser.hxx index b39daed9d..645d23a89 100644 --- a/src/common/StringParser.hxx +++ b/src/common/StringParser.hxx @@ -34,9 +34,9 @@ class StringParser @param str The string to split */ - explicit StringParser(const string& str) + explicit StringParser(string_view str) { - istringstream buf(str); + istringstream buf(string{str}); // TODO: fixed in C++20 string line; while(std::getline(buf, line, '\n')) diff --git a/src/common/Variant.hxx b/src/common/Variant.hxx index edbad771b..f4fd060b7 100644 --- a/src/common/Variant.hxx +++ b/src/common/Variant.hxx @@ -45,6 +45,7 @@ class Variant Variant() = default; // NOLINT Variant(const string& s) : data{s} { } + Variant(string_view s) : data{s} { } Variant(const char* s) : data{s} { } Variant(Int32 i) { buf().str(""); buf() << i; data = buf().str(); } diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 7fe346714..8b8392073 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -193,6 +193,12 @@ namespace BSPF } // Convert string to integer, using default value on any error + inline int stringToInt(string_view s, const int defaultValue = 0) + { + try { return std::stoi(string{s}); } + catch(...) { return defaultValue; } + } + // TODO: remove this once we reimplement stoi inline int stringToInt(const string& s, const int defaultValue = 0) { try { return std::stoi(s); } @@ -285,7 +291,7 @@ namespace BSPF // (case sensitive for upper case characters in second string, except first one) // - the first character must match // - the following characters must appear in the order of the first string - inline bool matchesCamelCase(const string_view s1, const string_view s2) + inline bool matchesCamelCase(string_view s1, string_view s2) { // skip leading '_' for matching const uInt32 ofs = (s1[0] == '_' && s2[0] == '_') ? 1 : 0; @@ -330,7 +336,7 @@ namespace BSPF // @param str The searched string // @param pattern The pattern to search for // @return Position of pattern in string. - inline size_t matchWithJoker(const string& str, const string& pattern) + inline size_t matchWithJoker(string_view str, string_view pattern) { if(str.length() >= pattern.length()) { @@ -361,9 +367,9 @@ namespace BSPF // @param str The searched string // @param pattern The pattern to search for // @return True if pattern was found. - inline bool matchWithWildcards(const string& str, const string& pattern) + inline bool matchWithWildcards(string_view str, string_view pattern) { - string pat = pattern; + string pat{pattern}; // TODO: don't use copy // remove leading and trailing '*' size_t i = 0; @@ -394,7 +400,7 @@ namespace BSPF } // Modify 'str', replacing all occurrences of 'from' with 'to' - inline void replaceAll(string& str, const string& from, const string& to) + inline void replaceAll(string& str, string_view from, string_view to) { if(from.empty()) return; size_t start_pos = 0; @@ -407,11 +413,11 @@ namespace BSPF } // Trim leading and trailing whitespace from a string - inline string trim(const string& str) + inline string trim(string_view str) { const auto first = str.find_first_not_of(' '); return (first == string::npos) ? EmptyString : - str.substr(first, str.find_last_not_of(' ')-first+1); + string{str.substr(first, str.find_last_not_of(' ')-first+1)}; } // C++11 way to get local time diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 0f0bde82c..58daa0390 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -119,8 +119,8 @@ FBInitStatus Debugger::initializeVideo() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::start(const string& message, int address, bool read, - const string& toolTip) +bool Debugger::start(string_view message, int address, bool read, + string_view toolTip) { if(myOSystem.eventHandler().enterDebugMode()) { @@ -139,7 +139,7 @@ bool Debugger::start(const string& message, int address, bool read, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::startWithFatalError(const string& message) +bool Debugger::startWithFatalError(string_view message) { if(myOSystem.eventHandler().enterDebugMode()) { @@ -218,7 +218,7 @@ TrapArray& Debugger::writeTraps() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string Debugger::run(const string& command) +string Debugger::run(string_view command) { return myParser->run(command); } @@ -450,7 +450,7 @@ bool Debugger::writeTrap(uInt16 t) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Debugger::log(const string& triggerMsg) +void Debugger::log(string_view triggerMsg) { const CartDebug::Disassembly& disasm = myCartDebug->disassembly(); const int pc = myCpuDebug->pc(); @@ -719,7 +719,7 @@ string Debugger::showWatches() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Debugger::stringToValue(const string& stringval) +int Debugger::stringToValue(string_view stringval) { return myParser->decipher_arg(stringval); } @@ -745,7 +745,7 @@ void Debugger::saveOldState(bool clearDirtyPages) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Debugger::addState(const string& rewindMsg) +void Debugger::addState(string_view rewindMsg) { // Add another rewind level to the Time Machine buffer RewindManager& r = myOSystem.state().rewindManager(); @@ -788,7 +788,7 @@ void Debugger::setQuitState() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::addFunction(const string& name, const string& definition, +bool Debugger::addFunction(string_view name, string_view definition, Expression* exp, bool builtin) { myFunctions.emplace(name, unique_ptr(exp)); @@ -798,14 +798,14 @@ bool Debugger::addFunction(const string& name, const string& definition, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::isBuiltinFunction(const string& name) +bool Debugger::isBuiltinFunction(string_view name) { return std::any_of(ourBuiltinFunctions.cbegin(), ourBuiltinFunctions.cend(), [&](const auto& func) { return name == func.name; }); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::delFunction(const string& name) +bool Debugger::delFunction(string_view name) { const auto& iter = myFunctions.find(name); if(iter == myFunctions.end()) @@ -815,25 +815,25 @@ bool Debugger::delFunction(const string& name) if(isBuiltinFunction(name)) return false; - myFunctions.erase(name); + myFunctions.erase(string{name}); const auto& def_iter = myFunctionDefs.find(name); if(def_iter == myFunctionDefs.end()) return false; - myFunctionDefs.erase(name); + myFunctionDefs.erase(string{name}); return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const Expression& Debugger::getFunction(const string& name) const +const Expression& Debugger::getFunction(string_view name) const { const auto& iter = myFunctions.find(name); return iter != myFunctions.end() ? *(iter->second) : EmptyExpression; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const string& Debugger::getFunctionDef(const string& name) const +const string& Debugger::getFunctionDef(string_view name) const { const auto& iter = myFunctionDefs.find(name); return iter != myFunctionDefs.end() ? iter->second : EmptyString; diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 7944fb96b..48cd70d8f 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -67,8 +67,8 @@ class Debugger : public DialogContainer friend class M6502; public: - using FunctionMap = std::map>; - using FunctionDefMap = std::map; + using FunctionMap = std::map, std::less<>>; + using FunctionDefMap = std::map>; /** Create a new debugger parent object @@ -94,9 +94,9 @@ class Debugger : public DialogContainer @param message Message to display when entering debugger @param address An address associated with the message */ - bool start(const string& message = "", int address = -1, bool read = true, - const string& toolTip = ""); - bool startWithFatalError(const string& message = ""); + bool start(string_view message = "", int address = -1, bool read = true, + string_view toolTip = ""); + bool startWithFatalError(string_view message = ""); /** Wrapper method for EventHandler::leaveDebugMode() for those classes @@ -109,13 +109,13 @@ class Debugger : public DialogContainer */ void quit(); - bool addFunction(const string& name, const string& def, + bool addFunction(string_view name, string_view def, Expression* exp, bool builtin = false); - static bool isBuiltinFunction(const string& name); - bool delFunction(const string& name); - const Expression& getFunction(const string& name) const; + static bool isBuiltinFunction(string_view name); + bool delFunction(string_view name); + const Expression& getFunction(string_view name) const; - const string& getFunctionDef(const string& name) const; + const string& getFunctionDef(string_view name) const; FunctionDefMap getFunctionDefMap() const; static string builtinHelp(); @@ -194,7 +194,7 @@ class Debugger : public DialogContainer /** Run the debugger command and return the result. */ - string run(const string& command); + string run(string_view command); string autoExec(StringList* history); @@ -204,7 +204,7 @@ class Debugger : public DialogContainer Convert between string->integer and integer->string, taking into account the current base format. */ - int stringToValue(const string& stringval); + int stringToValue(string_view stringval); /* Convenience methods to get/set bit(s) in an 8-bit register */ static uInt8 set_bit(uInt8 input, uInt8 bit, bool on) @@ -296,7 +296,7 @@ class Debugger : public DialogContainer /** Saves a rewind state with the given message. */ - void addState(const string& rewindMsg); + void addState(string_view rewindMsg); /** Set initial state before entering the debugger. @@ -326,7 +326,7 @@ class Debugger : public DialogContainer bool readTrap(uInt16 t) const; bool writeTrap(uInt16 t) const; void clearAllTraps() const; - void log(const string& triggerMsg); + void log(string_view triggerMsg); // Set a bunch of RAM locations at once string setRAM(IntArray& args); diff --git a/src/debugger/DebuggerExpressions.hxx b/src/debugger/DebuggerExpressions.hxx index ff326d397..3ff313d2d 100644 --- a/src/debugger/DebuggerExpressions.hxx +++ b/src/debugger/DebuggerExpressions.hxx @@ -134,7 +134,7 @@ class EqualsExpression : public Expression class EquateExpression : public Expression { public: - EquateExpression(const string& label) : Expression(), myLabel{label} { } + EquateExpression(string_view label) : Expression(), myLabel{label} { } Int32 evaluate() const override { return Debugger::debugger().cartDebug().getAddress(myLabel); } @@ -146,7 +146,7 @@ class EquateExpression : public Expression class FunctionExpression : public Expression { public: - FunctionExpression(const string& label) : Expression(), myLabel{label} { } + FunctionExpression(string_view label) : Expression(), myLabel{label} { } Int32 evaluate() const override { return Debugger::debugger().getFunction(myLabel).evaluate(); } diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index c3055697f..15b3a7ed1 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -66,7 +66,7 @@ DebuggerParser::DebuggerParser(Debugger& d, Settings& s) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // main entry point: PromptWidget calls this method. -string DebuggerParser::run(const string& command) +string DebuggerParser::run(string_view command) { #if 0 // this was our parser test code. Left for reference. @@ -163,7 +163,7 @@ string DebuggerParser::exec(const FSNode& file, StringList* history) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DebuggerParser::outputCommandError(const string& errorMsg, int command) +void DebuggerParser::outputCommandError(string_view errorMsg, int command) { const string example = commands[command].extendedDesc.substr(commands[command].extendedDesc.find("Example:")); @@ -190,10 +190,10 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) // they're valid, or -1 if they're not. // decipher_arg may be called by the GUI as needed. It is also called // internally by DebuggerParser::run() -int DebuggerParser::decipher_arg(const string& str) +int DebuggerParser::decipher_arg(string_view str) { bool derefByte=false, derefWord=false, lobyte=false, hibyte=false, bin=false, dec=false; - string arg = str; + string arg{str}; const Base::Fmt defaultBase = Base::format(); @@ -330,7 +330,7 @@ string DebuggerParser::showWatches() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool DebuggerParser::getArgs(const string& command, string& verb) +bool DebuggerParser::getArgs(string_view command, string& verb) { ParseState state = ParseState::IN_COMMAND; size_t i = 0; @@ -2456,7 +2456,7 @@ void DebuggerParser::executeTrapWriteIf() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Wrapper function for trap(if)s -void DebuggerParser::executeTraps(bool read, bool write, const string& command, +void DebuggerParser::executeTraps(bool read, bool write, string_view command, bool hasCond) { const uInt32 ofs = hasCond ? 1 : 0, diff --git a/src/debugger/DebuggerParser.hxx b/src/debugger/DebuggerParser.hxx index d3e72ca04..2fb3fadd0 100644 --- a/src/debugger/DebuggerParser.hxx +++ b/src/debugger/DebuggerParser.hxx @@ -35,7 +35,7 @@ class DebuggerParser DebuggerParser(Debugger& debugger, Settings& settings); /** Run the given command, and return the result */ - string run(const string& command); + string run(string_view command); /** Execute parser commands given in 'file' */ string exec(const FSNode& file, StringList* history = nullptr); @@ -45,23 +45,23 @@ class DebuggerParser static void getCompletions(const char* in, StringList& completions); /** Evaluate the given expression using operators, current base, etc */ - int decipher_arg(const string& str); + int decipher_arg(string_view str); /** String representation of all watches currently defined */ string showWatches(); - static inline string red(const string& msg = "") + static inline string red(string_view msg = "") { - return char(kDbgColorRed & 0xff) + msg; + return char(kDbgColorRed & 0xff) + string{msg}; } - static inline string inverse(const string& msg = "") + static inline string inverse(string_view msg = "") { // ASCII DEL char, decimal 127 - return "\177" + msg; + return "\177" + string{msg}; } private: - bool getArgs(const string& command, string& verb); + bool getArgs(string_view command, string& verb); bool validateArgs(int cmd); string eval(); string saveScriptFile(string file); @@ -112,7 +112,7 @@ class DebuggerParser uInt32 end{0}; string condition; - Trap(bool r, bool w, uInt32 b, uInt32 e, const string& c) + Trap(bool r, bool w, uInt32 b, uInt32 e, string_view c) : read(r), write(w), begin(b), end(e), condition(c) {} }; @@ -146,7 +146,7 @@ class DebuggerParser void listTimers(); // output the error with the example provided for the command - void outputCommandError(const string& errorMsg, int command); + void outputCommandError(string_view errorMsg, int command); void executeDirective(Device::AccessType type); @@ -252,7 +252,7 @@ class DebuggerParser void executeTrapReadIf(); void executeTrapWrite(); void executeTrapWriteIf(); - void executeTraps(bool read, bool write, const string& command, bool cond = false); + void executeTraps(bool read, bool write, string_view command, bool cond = false); void executeTrapRW(uInt32 addr, bool read, bool write, bool add = true); // not exposed by debugger void executeType(); void executeUHex(); diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 1fb34cee3..27aafc9d1 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -1037,7 +1037,7 @@ string TIADebug::audFreq(uInt8 dist, uInt8 div) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string TIADebug::stringOnly(const string& value, bool changed) +string TIADebug::stringOnly(string_view value, bool changed) { ostringstream buf; @@ -1051,7 +1051,7 @@ string TIADebug::stringOnly(const string& value, bool changed) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string TIADebug::decWithLabel(const string& label, uInt16 value, +string TIADebug::decWithLabel(string_view label, uInt16 value, bool changed, uInt16 width) { ostringstream buf; @@ -1069,7 +1069,7 @@ string TIADebug::decWithLabel(const string& label, uInt16 value, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string TIADebug::hexWithLabel(const string& label, uInt16 value, +string TIADebug::hexWithLabel(string_view label, uInt16 value, bool changed, uInt16 width) { ostringstream buf; @@ -1087,7 +1087,7 @@ string TIADebug::hexWithLabel(const string& label, uInt16 value, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string TIADebug::binWithLabel(const string& label, uInt16 value, bool changed) +string TIADebug::binWithLabel(string_view label, uInt16 value, bool changed) { ostringstream buf; @@ -1104,13 +1104,13 @@ string TIADebug::binWithLabel(const string& label, uInt16 value, bool changed) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string TIADebug::boolWithLabel(const string& label, bool value, bool changed) +string TIADebug::boolWithLabel(string_view label, bool value, bool changed) { ostringstream buf; if(value) { - string l = label; + string l{label}; buf << "\177" << BSPF::toUpperCase(l) << "\177"; //return "+" + BSPF::toUpperCase(label); } diff --git a/src/debugger/TIADebug.hxx b/src/debugger/TIADebug.hxx index 472350231..445a23fcf 100644 --- a/src/debugger/TIADebug.hxx +++ b/src/debugger/TIADebug.hxx @@ -188,14 +188,14 @@ class TIADebug : public DebuggerSystem static string colorSwatch(uInt8 c); string audFreq(uInt8 dist, uInt8 div) const; - static string stringOnly(const string& value, bool changed = false); - static string decWithLabel(const string& label, uInt16 value, + static string stringOnly(string_view value, bool changed = false); + static string decWithLabel(string_view label, uInt16 value, bool changed = false, uInt16 width = 3); - static string hexWithLabel(const string& label, uInt16 value, + static string hexWithLabel(string_view label, uInt16 value, bool changed = false, uInt16 width = 2); - static string binWithLabel(const string& label, uInt16 value, + static string binWithLabel(string_view label, uInt16 value, bool changed = false); - static string boolWithLabel(const string& label, bool value, + static string boolWithLabel(string_view label, bool value, bool changed = false); private: diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index ad8e8b708..ba52d586e 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -582,7 +582,7 @@ void DataGridWidget::handleCommand(CommandSender* sender, int cmd, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DataGridWidget::setToolTip(int column, int row, const string& text) +void DataGridWidget::setToolTip(int column, int row, string_view text) { if(row >= 0 && row < _rows && column >= 0 && column < _cols) _toolTipList[row * _cols + column] = text; diff --git a/src/debugger/gui/DataGridWidget.hxx b/src/debugger/gui/DataGridWidget.hxx index a7c868d0b..9d6cca8eb 100644 --- a/src/debugger/gui/DataGridWidget.hxx +++ b/src/debugger/gui/DataGridWidget.hxx @@ -85,7 +85,7 @@ class DataGridWidget : public EditableWidget void setCrossed(bool enable); using EditableWidget::setToolTip; - void setToolTip(int column, int row, const string& text); + void setToolTip(int column, int row, string_view text); string getToolTip(const Common::Point& pos) const override; bool changedToolTip(const Common::Point& oldPos, const Common::Point& newPos) const override; diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index caff2019a..a5f6dc073 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -434,7 +434,7 @@ void DebuggerDialog::createFont() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DebuggerDialog::showFatalMessage(const string& msg) +void DebuggerDialog::showFatalMessage(string_view msg) { myFatalError = make_unique(this, *myLFont, msg, _w-20, _h-20, kDDExitFatalCmd, "Exit ROM", "Continue", "Fatal error"); diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index 04d4d77ba..c9a493442 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -49,7 +49,7 @@ class DebuggerDialog : public Dialog { public: // Note: these sizes make sure that all major tabs are fully visible - // cart dependend information (e.g. DPC+) may require more space + // cart dependend information (e.g. DPC+) may require more space enum { kSmallFontMinW = 1090, kSmallFontMinH = 720, kMediumFontMinW = 1160, kMediumFontMinH = 770, @@ -73,7 +73,7 @@ class DebuggerDialog : public Dialog ButtonWidget& rewindButton() const { return *myRewindButton; } ButtonWidget& unwindButton() const { return *myUnwindButton; } - void showFatalMessage(const string& msg); + void showFatalMessage(string_view msg); void saveConfig() override; private: diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index b3e655698..1f7b3db1b 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -569,10 +569,10 @@ int PromptWidget::historyDir(int& index, int direction) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PromptWidget::historyAdd(const string& entry) +void PromptWidget::historyAdd(string_view entry) { if(_historyIndex >= static_cast(_history.size())) - _history.push_back(entry); + _history.emplace_back(entry); else _history[_historyIndex] = entry; } @@ -882,7 +882,7 @@ void PromptWidget::putcharIntern(int c) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PromptWidget::print(const string& str) +void PromptWidget::print(string_view str) { for(const auto c: str) putcharIntern(c); diff --git a/src/debugger/gui/PromptWidget.hxx b/src/debugger/gui/PromptWidget.hxx index 510fc6ac4..6f74288c6 100644 --- a/src/debugger/gui/PromptWidget.hxx +++ b/src/debugger/gui/PromptWidget.hxx @@ -42,7 +42,7 @@ class PromptWidget : public Widget, public CommandSender ~PromptWidget() override = default; public: - void print(const string& str); + void print(string_view str); void printPrompt(); string saveBuffer(const FSNode& file); @@ -134,7 +134,7 @@ class PromptWidget : public Widget, public CommandSender bool _exitedEarly{false}; int historyDir(int& index, int direction); - void historyAdd(const string& entry); + void historyAdd(string_view entry); private: // Following constructors and assignment operators not supported diff --git a/src/debugger/gui/RamWidget.cxx b/src/debugger/gui/RamWidget.cxx index 6a6b4079d..25c0bcc31 100644 --- a/src/debugger/gui/RamWidget.cxx +++ b/src/debugger/gui/RamWidget.cxx @@ -31,7 +31,7 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h, uInt32 ramsize, uInt32 numrows, uInt32 pagesize, - const string& helpAnchor) + string_view helpAnchor) : Widget(boss, lfont, x, y, w, h), CommandSender(boss), _nfont{nfont}, @@ -393,7 +393,7 @@ void RamWidget::showInputBox(int cmd) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string RamWidget::doSearch(const string& str) +string RamWidget::doSearch(string_view str) { bool comparisonSearch = true; @@ -450,7 +450,7 @@ string RamWidget::doSearch(const string& str) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string RamWidget::doCompare(const string& str) +string RamWidget::doCompare(string_view str) { bool comparativeSearch = false; int searchVal = 0, offset = 0; @@ -475,7 +475,7 @@ string RamWidget::doCompare(const string& str) if(str[0] == '-') negative = true; - string tmp = str; + string tmp{str}; tmp.erase(0, 1); // remove the operator offset = instance().debugger().stringToValue(tmp); if(negative) diff --git a/src/debugger/gui/RamWidget.hxx b/src/debugger/gui/RamWidget.hxx index 7f4dfd4b4..80cf70d56 100644 --- a/src/debugger/gui/RamWidget.hxx +++ b/src/debugger/gui/RamWidget.hxx @@ -36,7 +36,7 @@ class RamWidget : public Widget, public CommandSender RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h, uInt32 ramsize, uInt32 numrows, uInt32 pagesize, - const string& helpAnchor); + string_view helpAnchor); ~RamWidget() override; void loadConfig() override; @@ -60,8 +60,8 @@ class RamWidget : public Widget, public CommandSender void fillGrid(bool updateOld); void showInputBox(int cmd); - string doSearch(const string& str); - string doCompare(const string& str); + string doSearch(string_view str); + string doCompare(string_view str); void doRestart(); void showSearchResults(); diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 872df6850..7def14b1a 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -27,12 +27,12 @@ #include "Cart.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cartridge::Cartridge(const Settings& settings, const string& md5) +Cartridge::Cartridge(const Settings& settings, string_view md5) : mySettings{settings} { - const auto to_uInt32 = [](const string& s, uInt32 pos) { - return static_cast(std::stoul(s.substr(pos, 8), nullptr, 16)); - }; + const auto to_uInt32 = [](string_view s, uInt32 pos) { + return static_cast(std::stoul(string{s.substr(pos, 8)}, nullptr, 16)); + }; // FIXME: convert to string_view by replacing std::stoul const uInt32 seed = to_uInt32(md5, 0) ^ to_uInt32(md5, 8) ^ to_uInt32(md5, 16) ^ to_uInt32(md5, 24); @@ -44,8 +44,7 @@ Cartridge::Cartridge(const Settings& settings, const string& md5) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Cartridge::setAbout(const string& about, const string& type, - const string& id) +void Cartridge::setAbout(string_view about, string_view type, string_view id) { myAbout = about; myDetectedType = type; diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index 4807be253..aff908bb2 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -63,13 +63,13 @@ class Cartridge : public Device @param settings A reference to the various settings (read-only) @param md5 The md5sum of the cart image */ - Cartridge(const Settings& settings, const string& md5); + Cartridge(const Settings& settings, string_view md5); ~Cartridge() override = default; /** Set/query some information about this cartridge. */ - void setAbout(const string& about, const string& type, const string& id); + void setAbout(string_view about, string_view type, string_view id); const string& about() const { return myAbout; } const string& detectedType() const { return myDetectedType; } const string& multiCartID() const { return myMultiCartID; } @@ -295,10 +295,9 @@ class Cartridge : public Device Informs the cartridge about the name of the nvram file it will use; not all carts support this. - @param nvramdir The full path of the nvram directory - @param romfile The name of the cart from ROM properties + @param path The full path of the nvram file */ - virtual void setNVRamFile(const string& nvramdir, const string& romfile) { } + virtual void setNVRamFile(string_view path) { } /** Thumbulator only supports 16-bit ARM code. Some Harmony/Melody drivers, diff --git a/src/emucore/CartARM.cxx b/src/emucore/CartARM.cxx index 98e43d0f8..f71613506 100644 --- a/src/emucore/CartARM.cxx +++ b/src/emucore/CartARM.cxx @@ -20,7 +20,7 @@ #include "CartARM.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -CartridgeARM::CartridgeARM(const string& md5, const Settings& settings) +CartridgeARM::CartridgeARM(const Settings& settings, string_view md5) : Cartridge(settings, md5) { } diff --git a/src/emucore/CartARM.hxx b/src/emucore/CartARM.hxx index 7c5c81f0a..519f81886 100644 --- a/src/emucore/CartARM.hxx +++ b/src/emucore/CartARM.hxx @@ -32,7 +32,7 @@ class CartridgeARM : public Cartridge friend class CartridgeARMWidget; public: - CartridgeARM(const string& md5, const Settings& settings); + CartridgeARM(const Settings& settings, string_view md5); ~CartridgeARM() override = default; /** diff --git a/src/emucore/CartBUS.cxx b/src/emucore/CartBUS.cxx index 99402c0cf..dc6a77801 100644 --- a/src/emucore/CartBUS.cxx +++ b/src/emucore/CartBUS.cxx @@ -46,8 +46,8 @@ static constexpr uInt32 getUInt32(const uInt8* _array, size_t _address) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeBUS::CartridgeBUS(const ByteBuffer& image, size_t size, - const string& md5, const Settings& settings) - : CartridgeARM(md5, settings), + string_view md5, const Settings& settings) + : CartridgeARM(settings, md5), myImage{make_unique(32_KB)} { // Copy the ROM image into my buffer diff --git a/src/emucore/CartBUS.hxx b/src/emucore/CartBUS.hxx index ceed187e4..6454e7bf4 100644 --- a/src/emucore/CartBUS.hxx +++ b/src/emucore/CartBUS.hxx @@ -41,7 +41,7 @@ class CartridgeBUS : public CartridgeARM friend class CartridgeBUSWidget; friend class CartridgeBUSInfoWidget; friend class CartridgeRamBUSWidget; - + enum class BUSSubtype { BUS0, // very old demos when BUS was in flux, not supported in Stella BUS1, // draconian_20161102.bin @@ -59,7 +59,7 @@ class CartridgeBUS : public CartridgeARM @param md5 The md5sum of the ROM image @param settings A reference to the various settings (read-only) */ - CartridgeBUS(const ByteBuffer& image, size_t size, const string& md5, + CartridgeBUS(const ByteBuffer& image, size_t size, string_view md5, const Settings& settings); ~CartridgeBUS() override = default; @@ -168,12 +168,12 @@ class CartridgeBUS : public CartridgeARM */ CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h) override; - + CartDebugWidget* infoWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h) override; #endif - + public: /** Get the byte at the specified address. @@ -220,7 +220,7 @@ class CartridgeBUS : public CartridgeARM uInt32 getDatastreamIncrement(uInt8 index) const; void setDatastreamIncrement(uInt8 index, uInt32 value); - + uInt32 getAddressMap(uInt8 index) const; void setAddressMap(uInt8 index, uInt32 value); @@ -269,16 +269,16 @@ class CartridgeBUS : public CartridgeARM // ARM cycle count from when the last callFunction() occurred uInt64 myARMCycles{0}; - + // Pointer to the array of datastream pointers uInt16 myDatastreamBase{0}; // was DSxPTR // Pointer to the array of datastream increments uInt16 myDatastreamIncrementBase{0}; // was DSxINC - + // Pointer to the array of datastream maps uInt16 myDatastreamMapBase{0}; // was DSMAPS - + // Pointer to the beginning of the waveform data block uInt16 myWaveformBase{0}; // was WAVEFORM @@ -302,7 +302,7 @@ class CartridgeBUS : public CartridgeARM uInt8 myMode{0}; uInt8 myFastJumpActive{false}; - + // BUS subtype BUSSubtype myBUSSubtype{BUSSubtype::BUS1}; diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index f4f3127eb..f20b91651 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -62,8 +62,8 @@ namespace { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size, - const string& md5, const Settings& settings) - : CartridgeARM(md5, settings) + string_view md5, const Settings& settings) + : CartridgeARM(settings, md5) { // Copy the ROM image into my buffer mySize = std::min(size, 512_KB); diff --git a/src/emucore/CartCDF.hxx b/src/emucore/CartCDF.hxx index c4aa0c367..df86e2f21 100644 --- a/src/emucore/CartCDF.hxx +++ b/src/emucore/CartCDF.hxx @@ -82,7 +82,7 @@ class CartridgeCDF : public CartridgeARM @param md5 The md5sum of the ROM image @param settings A reference to the various settings (read-only) */ - CartridgeCDF(const ByteBuffer& image, size_t size, const string& md5, + CartridgeCDF(const ByteBuffer& image, size_t size, string_view md5, const Settings& settings); ~CartridgeCDF() override = default; diff --git a/src/emucore/CartCTY.cxx b/src/emucore/CartCTY.cxx index 19e97ee19..17e3a615c 100644 --- a/src/emucore/CartCTY.cxx +++ b/src/emucore/CartCTY.cxx @@ -357,9 +357,9 @@ bool CartridgeCTY::load(Serializer& in) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CartridgeCTY::setNVRamFile(const string& nvramdir, const string& romfile) +void CartridgeCTY::setNVRamFile(string_view path) { - myEEPROMFile = nvramdir + romfile + "_eeprom.dat"; + myEEPROMFile = string{path} + "_eeprom.dat"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartCTY.hxx b/src/emucore/CartCTY.hxx index 89bf07052..6bf93a391 100644 --- a/src/emucore/CartCTY.hxx +++ b/src/emucore/CartCTY.hxx @@ -210,10 +210,9 @@ class CartridgeCTY : public Cartridge /** Informs the cartridge about the name of the nvram file it will use. - @param nvramdir The full path of the nvram directory - @param romfile The name of the cart from ROM properties + @param path The full path of the nvram file */ - void setNVRamFile(const string& nvramdir, const string& romfile) override; + void setNVRamFile(string_view path) override; #ifdef DEBUGGER_SUPPORT /** diff --git a/src/emucore/CartDPCPlus.cxx b/src/emucore/CartDPCPlus.cxx index 9916496d6..000f97f58 100644 --- a/src/emucore/CartDPCPlus.cxx +++ b/src/emucore/CartDPCPlus.cxx @@ -26,8 +26,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, size_t size, - const string& md5, const Settings& settings) - : CartridgeARM(md5, settings), + string_view md5, const Settings& settings) + : CartridgeARM(settings, md5), myImage{make_unique(32_KB)}, mySize{std::min(size, 32_KB)} { diff --git a/src/emucore/CartDPCPlus.hxx b/src/emucore/CartDPCPlus.hxx index e54596419..5de13c99f 100644 --- a/src/emucore/CartDPCPlus.hxx +++ b/src/emucore/CartDPCPlus.hxx @@ -55,7 +55,7 @@ class CartridgeDPCPlus : public CartridgeARM @param md5 The md5sum of the ROM image @param settings A reference to the various settings (read-only) */ - CartridgeDPCPlus(const ByteBuffer& image, size_t size, const string& md5, + CartridgeDPCPlus(const ByteBuffer& image, size_t size, string_view md5, const Settings& settings); ~CartridgeDPCPlus() override = default; diff --git a/src/emucore/CartFA2.cxx b/src/emucore/CartFA2.cxx index 631b32976..27ad7eca9 100644 --- a/src/emucore/CartFA2.cxx +++ b/src/emucore/CartFA2.cxx @@ -79,9 +79,9 @@ bool CartridgeFA2::poke(uInt16 address, uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CartridgeFA2::setNVRamFile(const string& nvramdir, const string& romfile) +void CartridgeFA2::setNVRamFile(string_view path) { - myFlashFile = nvramdir + romfile + "_flash.dat"; + myFlashFile = string{path} + "_flash.dat"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartFA2.hxx b/src/emucore/CartFA2.hxx index bfa373945..5007a129b 100644 --- a/src/emucore/CartFA2.hxx +++ b/src/emucore/CartFA2.hxx @@ -74,10 +74,9 @@ class CartridgeFA2 : public CartridgeFA /** Informs the cartridge about the name of the nvram file it will use. - @param nvramdir The full path of the nvram directory - @param romfile The name of the cart from ROM properties + @param path The full path of the nvram file */ - void setNVRamFile(const string& nvramdir, const string& romfile) override; + void setNVRamFile(string_view path) override; #ifdef DEBUGGER_SUPPORT /** diff --git a/src/emucore/CartMVC.cxx b/src/emucore/CartMVC.cxx index 8c5d75d48..beb652e72 100755 --- a/src/emucore/CartMVC.cxx +++ b/src/emucore/CartMVC.cxx @@ -56,7 +56,7 @@ class StreamReader : public Serializable public: StreamReader() { myBuffer1.fill(0); myBuffer2.fill(0); } - bool open(const string& path) { + bool open(string_view path) { myFile = Serializer(path, Serializer::Mode::ReadOnly); if(myFile) myFileSize = myFile.size(); @@ -738,7 +738,7 @@ class MovieCart : public Serializable public: MovieCart() { myROM.fill(0); } - bool init(const string& path); + bool init(string_view path); bool process(uInt16 address); bool save(Serializer& out) const override; @@ -837,7 +837,7 @@ class MovieCart : public Serializable }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool MovieCart::init(const string& path) +bool MovieCart::init(string_view path) { std::copy_n(kernelROM, 1_KB, myROM.data()); diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index dfc8c10e1..3415ecc3b 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -149,7 +149,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, // Let the cart know how to query for the 'Cartridge.StartBank' property myCart->setStartBankFromPropsFunc([this]() { - const string& startbank = myProperties.get(PropType::Cart_StartBank); + const string_view startbank = myProperties.get(PropType::Cart_StartBank); return (startbank == EmptyString || BSPF::equalsIgnoreCase(startbank, "AUTO")) ? -1 : BSPF::stringToInt(startbank); }); @@ -169,8 +169,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, // Add the real controllers for this system // This must be done before the debugger is initialized - const string& md5 = myProperties.get(PropType::Cart_MD5); - setControllers(md5); + setControllers(myProperties.get(PropType::Cart_MD5)); // Pause audio and clear framebuffer while autodetection runs myOSystem.sound().pause(true); @@ -238,7 +237,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, myConsoleInfo.BankSwitch = myCart->about(); // Some carts have an associated nvram file - myCart->setNVRamFile(myOSystem.nvramDir().getPath(), myConsoleInfo.CartName); + myCart->setNVRamFile(myOSystem.nvramDir().getPath() + myConsoleInfo.CartName); // Let the other devices know about the new console mySystem->consoleChanged(myConsoleTiming); @@ -360,13 +359,13 @@ string Console::formatFromFilename() const }}; // Get filename, and search using regex's above - const string& filename = myOSystem.romFile().getName(); + const string_view filename = myOSystem.romFile().getName(); for(const auto& pat: Pattern) { try { const std::regex rgx(pat[0], std::regex_constants::icase); - if(std::regex_search(filename, rgx)) + if(std::regex_search(filename.cbegin(), filename.cend(), rgx)) return pat[1]; } catch(...) @@ -676,7 +675,7 @@ FBInitStatus Console::initializeVideo(bool full) Common::Size(2 * myTIA->width(), myTIA->height()); const bool devSettings = myOSystem.settings().getBool("dev.settings"); - const string& title = string("Stella ") + STELLA_VERSION + + const string title = string{"Stella "} + STELLA_VERSION + ": \"" + myProperties.get(PropType::Cart_Name) + "\""; fbstatus = myOSystem.frameBuffer().createDisplay(title, BufferType::Emulator, size, false); @@ -837,7 +836,7 @@ void Console::createAudioQueue() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::setControllers(const string& romMd5) +void Console::setControllers(string_view romMd5) { // Check for CompuMate scheme; it is special in that a handler creates both // controllers for us, and associates them with the bankswitching class @@ -942,9 +941,8 @@ void Console::changeRightController(int direction) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -unique_ptr Console::getControllerPort(const Controller::Type type, - const Controller::Jack port, - const string& romMd5) +unique_ptr Console::getControllerPort( + const Controller::Type type, const Controller::Jack port, string_view romMd5) { unique_ptr controller; @@ -1002,7 +1000,8 @@ unique_ptr Console::getControllerPort(const Controller::Type type, { FSNode nvramfile = myOSystem.nvramDir(); nvramfile /= "atarivox_eeprom.dat"; - const Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) + const Controller::onMessageCallback callback = [&os = myOSystem] + (string_view msg) { const bool devSettings = os.settings().getBool("dev.settings"); if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) @@ -1016,7 +1015,8 @@ unique_ptr Console::getControllerPort(const Controller::Type type, { FSNode nvramfile = myOSystem.nvramDir(); nvramfile /= "savekey_eeprom.dat"; - const Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) + const Controller::onMessageCallback callback = [&os = myOSystem] + (string_view msg) { const bool devSettings = os.settings().getBool("dev.settings"); if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) @@ -1031,8 +1031,8 @@ unique_ptr Console::getControllerPort(const Controller::Type type, case Controller::Type::KidVid: { - const Controller::onMessageCallbackForced callback = - [&os = myOSystem](const string& msg, bool force) { + const Controller::onMessageCallbackForced callback = [&os = myOSystem] + (string_view msg, bool force) { const bool devSettings = os.settings().getBool("dev.settings"); if(force || os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) os.frameBuffer().showTextMessage(msg); @@ -1241,10 +1241,11 @@ void Console::toggleDeveloperSet(bool toggle) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::toggleTIABit(TIABit bit, const string& bitname, bool show, bool toggle) const +void Console::toggleTIABit(TIABit bit, string_view bitname, + bool show, bool toggle) const { const bool result = myTIA->toggleBit(bit, toggle ? 2 : 3); - const string message = bitname + (result ? " enabled" : " disabled"); + const string message = string{bitname} + (result ? " enabled" : " disabled"); myOSystem.frameBuffer().showTextMessage(message); } @@ -1259,10 +1260,12 @@ void Console::toggleBits(bool toggle) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::toggleTIACollision(TIABit bit, const string& bitname, bool show, bool toggle) const +void Console::toggleTIACollision(TIABit bit, string_view bitname, + bool show, bool toggle) const { const bool result = myTIA->toggleCollision(bit, toggle ? 2 : 3); - const string message = bitname + (result ? " collision enabled" : " collision disabled"); + const string message = string{bitname} + + (result ? " collision enabled" : " collision disabled"); myOSystem.frameBuffer().showTextMessage(message); } diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index dee74237c..d283eb3bc 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -81,7 +81,7 @@ class Console : public Serializable, public ConsoleIO /** Sets the left and right controllers for the console. */ - void setControllers(const string& romMd5); + void setControllers(string_view romMd5); /** Get the controller plugged into the specified jack @@ -424,11 +424,12 @@ class Console : public Serializable, public ConsoleIO Selects the left or right controller depending on ROM properties */ unique_ptr getControllerPort(const Controller::Type type, - const Controller::Jack port, const string& romMd5); + const Controller::Jack port, + string_view romMd5); - void toggleTIABit(TIABit bit, const string& bitname, + void toggleTIABit(TIABit bit, string_view bitname, bool show = true, bool toggle = true) const; - void toggleTIACollision(TIABit bit, const string& bitname, + void toggleTIACollision(TIABit bit, string_view bitname, bool show = true, bool toggle = true) const; private: diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index da1864111..ae049d0dd 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -134,15 +134,12 @@ string Controller::getPropName(const Type type) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Controller::Type Controller::getType(const string& propName) +Controller::Type Controller::getType(string_view propName) { for(int i = 0; i < static_cast(Type::LastType); ++i) - { if (BSPF::equalsIgnoreCase(propName, getPropName(Type{i}))) - { return Type{i}; - } - } + // special case if(BSPF::equalsIgnoreCase(propName, "KEYPAD")) return Type::Keyboard; diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 1e7bbfa7e..b1f3802d6 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -279,7 +279,7 @@ class Controller : public Serializable /** Returns the controller type of the given property name */ - static Type getType(const string& propName); + static Type getType(string_view propName); /** Sets the dead zone amount for real analog joysticks. diff --git a/src/emucore/DispatchResult.cxx b/src/emucore/DispatchResult.cxx index d18c1a14b..a5f5c78c6 100644 --- a/src/emucore/DispatchResult.cxx +++ b/src/emucore/DispatchResult.cxx @@ -31,8 +31,9 @@ void DispatchResult::setOk(uInt64 cycles) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DispatchResult::setDebugger(uInt64 cycles, const string& message, - const string& tooltip, int address, bool wasReadTrap) +void DispatchResult::setDebugger(uInt64 cycles, string_view message, + string_view tooltip, int address, + bool wasReadTrap) { myStatus = Status::debugger; myCycles = cycles; @@ -51,7 +52,7 @@ void DispatchResult::setFatal(uInt64 cycles) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DispatchResult::setMessage(const string& message) +void DispatchResult::setMessage(string_view message) { myMessage = message; } diff --git a/src/emucore/DispatchResult.hxx b/src/emucore/DispatchResult.hxx index 77a0f6ea9..7dda1e5b7 100644 --- a/src/emucore/DispatchResult.hxx +++ b/src/emucore/DispatchResult.hxx @@ -31,34 +31,45 @@ class DispatchResult uInt64 getCycles() const { return myCycles; } - const string& getMessage() const { assertStatus(Status::debugger, Status::fatal); return myMessage; } + const string& getMessage() const { + assertStatus(Status::debugger, Status::fatal); + return myMessage; + } - int getAddress() const { assertStatus(Status::debugger); return myAddress; } + int getAddress() const { + assertStatus(Status::debugger); + return myAddress; + } - bool wasReadTrap() const { assertStatus(Status::debugger); return myWasReadTrap; } + bool wasReadTrap() const { + assertStatus(Status::debugger); + return myWasReadTrap; + } - const string& getToolTip() const { assertStatus(Status::debugger, Status::fatal); return myToolTip; } + const string& getToolTip() const { + assertStatus(Status::debugger, Status::fatal); + return myToolTip; + } bool isSuccess() const; void setOk(uInt64 cycles); - void setDebugger(uInt64 cycles, const string& message = "", - const string& tooltip = "", int address = -1, bool wasReadTrap = true); + void setDebugger(uInt64 cycles, string_view message = "", + string_view tooltip = "", int address = -1, + bool wasReadTrap = true); void setFatal(uInt64 cycles); - void setMessage(const string& message); + void setMessage(string_view message); private: - void assertStatus(Status status) const - { + void assertStatus(Status status) const { if (myStatus != status) throw runtime_error("invalid status for operation"); } - template void assertStatus(Status status, Ts... more) const - { + template void assertStatus(Status status, Ts... more) const { if (myStatus == status) return; assertStatus(more...); diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index a6dc84a73..293fb1d0a 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -181,7 +181,7 @@ void EventHandler::removePhysicalJoystick(int id) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandler::mapStelladaptors(const string& saport) +void EventHandler::mapStelladaptors(string_view saport) { #ifdef JOYSTICK_SUPPORT myPJoyHandler->mapStelladaptors(saport); @@ -1767,7 +1767,7 @@ void EventHandler::handleConsoleStartupEvents() if(myOSystem.settings().getBool("holdselect")) handleEvent(Event::ConsoleSelect); - const string& holdjoy0 = myOSystem.settings().getString("holdjoy0"); + const string_view holdjoy0 = myOSystem.settings().getString("holdjoy0"); if(BSPF::containsIgnoreCase(holdjoy0, "U")) handleEvent(Event::LeftJoystickUp); @@ -1780,7 +1780,7 @@ void EventHandler::handleConsoleStartupEvents() if(BSPF::containsIgnoreCase(holdjoy0, "F")) handleEvent(Event::LeftJoystickFire); - const string& holdjoy1 = myOSystem.settings().getString("holdjoy1"); + const string_view holdjoy1 = myOSystem.settings().getString("holdjoy1"); if(BSPF::containsIgnoreCase(holdjoy1, "U")) handleEvent(Event::RightJoystickUp); if(BSPF::containsIgnoreCase(holdjoy1, "D")) @@ -2056,7 +2056,7 @@ json EventHandler::convertLegacyComboMapping(string list) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandler::removePhysicalJoystickFromDatabase(const string& name) +void EventHandler::removePhysicalJoystickFromDatabase(string_view name) { #ifdef JOYSTICK_SUPPORT myPJoyHandler->remove(name); @@ -2496,7 +2496,7 @@ string EventHandler::keyAtIndex(int idx, Event::Group group) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandler::setMouseControllerMode(const string& enable) +void EventHandler::setMouseControllerMode(string_view enable) { if(myOSystem.hasConsole()) { diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 050e88912..f5898160c 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -79,7 +79,7 @@ class EventHandler @param saport How to map the ports ('lr' or 'rl') */ - void mapStelladaptors(const string& saport); + void mapStelladaptors(string_view saport); /** Toggles if all four joystick directions are allowed at once @@ -145,7 +145,7 @@ class EventHandler Currently, this will be one of the following values: 'always', 'analog', 'never' */ - void setMouseControllerMode(const string& enable); + void setMouseControllerMode(string_view enable); void changeMouseControllerMode(int direction = +1); void changeMouseCursor(int direction = +1); @@ -338,7 +338,7 @@ class EventHandler Remove the physical joystick identified by 'name' from the joystick database, only if it is not currently active. */ - void removePhysicalJoystickFromDatabase(const string& name); + void removePhysicalJoystickFromDatabase(string_view name); /** Enable/disable text events (distinct from single-key events). diff --git a/src/emucore/FBBackend.hxx b/src/emucore/FBBackend.hxx index 43c2dc2af..123014bc2 100644 --- a/src/emucore/FBBackend.hxx +++ b/src/emucore/FBBackend.hxx @@ -88,7 +88,7 @@ class FBBackend @param title The title of the application / window */ - virtual void setTitle(const string& title) = 0; + virtual void setTitle(string_view title) = 0; /** Shows or hides the cursor based on the given boolean value. diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index 27ae1e8ea..9930dbad7 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -297,7 +297,7 @@ void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FBSurface::splitString(const GUI::Font& font, const string& s, int w, +void FBSurface::splitString(const GUI::Font& font, string_view s, int w, string& left, string& right) { #ifdef GUI_SUPPORT @@ -335,7 +335,7 @@ void FBSurface::splitString(const GUI::Font& font, const string& s, int w, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int FBSurface::drawString(const GUI::Font& font, const string& s, +int FBSurface::drawString(const GUI::Font& font, string_view s, int x, int y, int w, int h, ColorId color, TextAlign align, int deltax, bool useEllipsis, ColorId shadowColor, @@ -344,7 +344,7 @@ int FBSurface::drawString(const GUI::Font& font, const string& s, int lines = 0; #ifdef GUI_SUPPORT - string inStr = s; + string inStr{s}; // draw multiline string while(inStr.length() && h >= font.getFontHeight() * 2) @@ -374,7 +374,7 @@ int FBSurface::drawString(const GUI::Font& font, const string& s, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int FBSurface::drawString(const GUI::Font& font, const string& s, +int FBSurface::drawString(const GUI::Font& font, string_view s, int x, int y, int w, ColorId color, TextAlign align, int deltax, bool useEllipsis, ColorId shadowColor, diff --git a/src/emucore/FBSurface.hxx b/src/emucore/FBSurface.hxx index 808d816b4..27ffa43b2 100644 --- a/src/emucore/FBSurface.hxx +++ b/src/emucore/FBSurface.hxx @@ -228,10 +228,13 @@ class FBSurface @return Number of lines drawn */ - virtual int drawString(const GUI::Font& font, const string& s, int x, int y, int w, int h, - ColorId color, TextAlign align = TextAlign::Left, - int deltax = 0, bool useEllipsis = true, ColorId shadowColor = kNone, - size_t linkStart = string::npos, size_t linkLen = string::npos, + virtual int drawString(const GUI::Font& font, string_view s, int x, int y, + int w, int h, ColorId color, + TextAlign align = TextAlign::Left, + int deltax = 0, bool useEllipsis = true, + ColorId shadowColor = kNone, + size_t linkStart = string::npos, + size_t linkLen = string::npos, bool underline = false); /** @@ -254,10 +257,12 @@ class FBSurface @return x coordinate of end of string */ - virtual int drawString(const GUI::Font& font, const string& s, int x, int y, int w, - ColorId color, TextAlign align = TextAlign::Left, - int deltax = 0, bool useEllipsis = true, ColorId shadowColor = kNone, - size_t linkStart = string::npos, size_t linkLen = string::npos, + virtual int drawString(const GUI::Font& font, string_view s, int x, int y, + int w, ColorId color, TextAlign align = TextAlign::Left, + int deltax = 0, bool useEllipsis = true, + ColorId shadowColor = kNone, + size_t linkStart = string::npos, + size_t linkLen = string::npos, bool underline = false); /** @@ -269,7 +274,7 @@ class FBSurface @param left The left part of the split string @param right The right part of the split string */ - static void splitString(const GUI::Font& font, const string& s, int w, + static void splitString(const GUI::Font& font, string_view s, int w, string& left, string& right); /** diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 091f2a4f8..cd61d19f1 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -26,13 +26,13 @@ FSNode::FSNode(const AbstractFSNodePtr& realNode) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNode::FSNode(const string& path) +FSNode::FSNode(string_view path) { setPath(path); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FSNode::setPath(const string& path) +void FSNode::setPath(string_view path) { // Only create a new object when necessary if (path == getPath()) @@ -48,7 +48,7 @@ void FSNode::setPath(const string& path) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNode& FSNode::operator/=(const string& path) +FSNode& FSNode::operator/=(string_view path) { if (path != EmptyString) { @@ -230,7 +230,7 @@ const string& FSNode::getName() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FSNode::setName(const string& name) +void FSNode::setName(string_view name) { if (_realNode) _realNode->setName(name); @@ -249,7 +249,7 @@ string FSNode::getShortPath() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string FSNode::getNameWithExt(const string& ext) const +string FSNode::getNameWithExt(string_view ext) const { if (!_realNode) return EmptyString; @@ -259,11 +259,13 @@ string FSNode::getNameWithExt(const string& ext) const _realNode->getName().substr(pos+1); pos = s.find_last_of('.'); - return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext; + return (pos != string::npos) + ? s.replace(pos, string::npos, ext) + : s + string{ext}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string FSNode::getPathWithExt(const string& ext) const +string FSNode::getPathWithExt(string_view ext) const { if (!_realNode) return EmptyString; @@ -271,7 +273,9 @@ string FSNode::getPathWithExt(const string& ext) const string s = _realNode->getPath(); const size_t pos = s.find_last_of('.'); - return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext; + return (pos != string::npos) + ? s.replace(pos, string::npos, ext) + : s + string{ext}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -321,7 +325,7 @@ bool FSNode::makeDir() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FSNode::rename(const string& newfile) +bool FSNode::rename(string_view newfile) { return (_realNode && _realNode->exists()) ? _realNode->rename(newfile) : false; } diff --git a/src/emucore/FSNode.hxx b/src/emucore/FSNode.hxx index 66342eada..110724a88 100644 --- a/src/emucore/FSNode.hxx +++ b/src/emucore/FSNode.hxx @@ -83,7 +83,7 @@ class FSNode * operating system doesn't support the concept), some other directory is * used (usually the root directory). */ - explicit FSNode(const string& path); + explicit FSNode(string_view path); /** * Assignment operators. @@ -106,7 +106,7 @@ class FSNode * Append the given path to the node, adding a directory separator * when necessary. Modelled on the C++17 fs::path API. */ - FSNode& operator/=(const string& path); + FSNode& operator/=(string_view path); /** * By default, the output operator simply outputs the fully-qualified @@ -159,7 +159,7 @@ class FSNode * @return the file name */ const string& getName() const; - void setName(const string& name); + void setName(string_view name); /** * Return a string representation of the file which can be passed to fopen(). @@ -241,7 +241,7 @@ class FSNode * * @return bool true if the node was renamed, false otherwise. */ - bool rename(const string& newfile); + bool rename(string_view newfile); /** * Get the size of the current node path. @@ -302,13 +302,13 @@ class FSNode * and replace the extension (if present) with the given one. If no * extension is present, the given one is appended instead. */ - string getNameWithExt(const string& ext = "") const; - string getPathWithExt(const string& ext = "") const; + string getNameWithExt(string_view ext = "") const; + string getPathWithExt(string_view ext = "") const; private: explicit FSNode(const AbstractFSNodePtr& realNode); AbstractFSNodePtr _realNode; - void setPath(const string& path); + void setPath(string_view path); }; @@ -370,7 +370,7 @@ class AbstractFSNode * implementation for more information. */ virtual const string& getName() const = 0; - virtual void setName(const string& name) = 0; + virtual void setName(string_view name) = 0; /** * Returns the 'path' of the current node, usable in fopen(). @@ -443,7 +443,7 @@ class AbstractFSNode * * @return bool true if the node was renamed, false otherwise. */ - virtual bool rename(const string& newfile) = 0; + virtual bool rename(string_view newfile) = 0; /** * Get the size of the current node path. @@ -504,12 +504,12 @@ class AbstractFSNode * @param str String containing the path. * @return Pointer to the first char of the last component inside str. */ - static const char* lastPathComponent(const string& str) + static const char* lastPathComponent(string_view str) { if(str.empty()) return ""; - const char* const start = str.c_str(); + const char* const start = str.data(); const char* cur = start + str.size() - 2; while (cur >= start && !(*cur == '/' || *cur == '\\')) diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index b81394ebd..7cd0a0eb8 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -174,7 +174,7 @@ void FrameBuffer::setupFonts() GUI::consoleDesc, GUI::consoleMediumDesc, GUI::stellaMediumDesc, GUI::stellaLargeDesc, GUI::stella12x24tDesc, GUI::stella14x28tDesc, GUI::stella16x32tDesc}; - const string& dialogFont = myOSystem.settings().getString("dialogfont"); + const string_view dialogFont = myOSystem.settings().getString("dialogfont"); const FontDesc fd = getFontDesc(dialogFont); // The general font used in all UI elements @@ -202,13 +202,13 @@ void FrameBuffer::setupFonts() } // The font used by the ROM launcher - const string& lf = myOSystem.settings().getString("launcherfont"); + const string_view lf = myOSystem.settings().getString("launcherfont"); myLauncherFont = make_unique(getFontDesc(lf)); // 8x13 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FontDesc FrameBuffer::getFontDesc(const string& name) +FontDesc FrameBuffer::getFontDesc(string_view name) { if(name == "small") return GUI::consoleDesc; // 8x13 @@ -228,7 +228,7 @@ FontDesc FrameBuffer::getFontDesc(const string& name) #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, +FBInitStatus FrameBuffer::createDisplay(string_view title, BufferType type, Common::Size size, bool honourHiDPI) { ++myInitializedCount; @@ -609,7 +609,8 @@ void FrameBuffer::updateInEmulationMode(float framesPerSecond) #ifdef GUI_SUPPORT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::createMessage(const string& message, MessagePosition position, bool force) +void FrameBuffer::createMessage(string_view message, MessagePosition position, + bool force) { // Only show messages if they've been enabled if(myMsg.surface == nullptr || !(force || myOSystem.settings().getBool("uimessages"))) @@ -637,8 +638,8 @@ void FrameBuffer::createMessage(const string& message, MessagePosition position, #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::showTextMessage(const string& message, MessagePosition position, - bool force) +void FrameBuffer::showTextMessage(string_view message, + MessagePosition position, bool force) { #ifdef GUI_SUPPORT const int fontWidth = font().getMaxCharWidth(); @@ -653,7 +654,7 @@ void FrameBuffer::showTextMessage(const string& message, MessagePosition positio } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::showGaugeMessage(const string& message, const string& valueText, +void FrameBuffer::showGaugeMessage(string_view message, string_view valueText, float value, float minValue, float maxValue) { #ifdef GUI_SUPPORT diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 7863b3895..3af019b2a 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -83,7 +83,7 @@ class FrameBuffer @return Status of initialization (see FBInitStatus 'enum') */ - FBInitStatus createDisplay(const string& title, BufferType type, + FBInitStatus createDisplay(string_view title, BufferType type, Common::Size size, bool honourHiDPI = true); /** @@ -109,7 +109,7 @@ class FrameBuffer @param position Onscreen position for the message @param force Force showing this message, even if messages are disabled */ - void showTextMessage(const string& message, + void showTextMessage(string_view message, MessagePosition position = MessagePosition::BottomCenter, bool force = false); /** @@ -121,7 +121,7 @@ class FrameBuffer @param minValue The minimal value of the gauge bar @param maxValue The maximal value of the gauge bar */ - void showGaugeMessage(const string& message, const string& valueText, + void showGaugeMessage(string_view message, string_view valueText, float value, float minValue = 0.F, float maxValue = 100.F); bool messageShown() const; @@ -324,7 +324,7 @@ class FrameBuffer @return The description of the font */ - static FontDesc getFontDesc(const string& name); + static FontDesc getFontDesc(string_view name); #endif /** @@ -407,7 +407,7 @@ class FrameBuffer @param position Onscreen position for the message @param force Force showing this message, even if messages are disabled */ - void createMessage(const string& message, MessagePosition position, + void createMessage(string_view message, MessagePosition position, bool force = false); #endif diff --git a/src/emucore/KidVid.cxx b/src/emucore/KidVid.cxx index 7170c031b..99a2b71c6 100644 --- a/src/emucore/KidVid.cxx +++ b/src/emucore/KidVid.cxx @@ -26,7 +26,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KidVid::KidVid(Jack jack, const Event& event, const OSystem& osystem, - const System& system, const string& romMd5, + const System& system, string_view romMd5, const onMessageCallbackForced& callback) : Controller(jack, event, system, Controller::Type::KidVid), myEnabled{myJack == Jack::Right}, diff --git a/src/emucore/KidVid.hxx b/src/emucore/KidVid.hxx index 583660473..e7f76cd14 100644 --- a/src/emucore/KidVid.hxx +++ b/src/emucore/KidVid.hxx @@ -49,7 +49,7 @@ class KidVid : public Controller @param callback Called to pass messages back to the parent controller */ KidVid(Jack jack, const Event& event, const OSystem& osystem, - const System& system, const string& romMd5, + const System& system, string_view romMd5, const onMessageCallbackForced& callback); ~KidVid() override = default; diff --git a/src/emucore/Lightgun.cxx b/src/emucore/Lightgun.cxx index 79584697e..fc6c4cbca 100644 --- a/src/emucore/Lightgun.cxx +++ b/src/emucore/Lightgun.cxx @@ -27,7 +27,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Lightgun::Lightgun(Jack jack, const Event& event, const System& system, - const string& romMd5, const FrameBuffer& frameBuffer) + string_view romMd5, const FrameBuffer& frameBuffer) : Controller(jack, event, system, Controller::Type::Lightgun), myFrameBuffer{frameBuffer} { diff --git a/src/emucore/Lightgun.hxx b/src/emucore/Lightgun.hxx index 550953f58..0b4e97ed3 100644 --- a/src/emucore/Lightgun.hxx +++ b/src/emucore/Lightgun.hxx @@ -43,7 +43,7 @@ class Lightgun : public Controller */ Lightgun(Jack jack, const Event& event, const System& system, - const string& romMd5, const FrameBuffer& frameBuffer); + string_view romMd5, const FrameBuffer& frameBuffer); ~Lightgun() override = default; public: diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index bcbe3fc09..1240bc0ca 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -568,10 +568,10 @@ void M6502::attach(Debugger& debugger) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 M6502::addCondBreak(Expression* e, const string& name, bool oneShot) +uInt32 M6502::addCondBreak(Expression* e, string_view name, bool oneShot) { myCondBreaks.emplace_back(e); - myCondBreakNames.push_back(name); + myCondBreakNames.emplace_back(name); updateStepStateByInstruction(); @@ -609,10 +609,10 @@ const StringList& M6502::getCondBreakNames() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 M6502::addCondSaveState(Expression* e, const string& name) +uInt32 M6502::addCondSaveState(Expression* e, string_view name) { myCondSaveStates.emplace_back(e); - myCondSaveStateNames.push_back(name); + myCondSaveStateNames.emplace_back(name); updateStepStateByInstruction(); @@ -650,10 +650,10 @@ const StringList& M6502::getCondSaveStateNames() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 M6502::addCondTrap(Expression* e, const string& name) +uInt32 M6502::addCondTrap(Expression* e, string_view name) { myTrapConds.emplace_back(e); - myTrapCondNames.push_back(name); + myTrapCondNames.emplace_back(name); updateStepStateByInstruction(); diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index 2160070cf..dd22546d7 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -236,19 +236,19 @@ class M6502 : public Serializable BreakpointMap& breakPoints() { return myBreakPoints; } // methods for 'breakif' handling - uInt32 addCondBreak(Expression* e, const string& name, bool oneShot = false); + uInt32 addCondBreak(Expression* e, string_view name, bool oneShot = false); bool delCondBreak(uInt32 idx); void clearCondBreaks(); const StringList& getCondBreakNames() const; // methods for 'savestateif' handling - uInt32 addCondSaveState(Expression* e, const string& name); + uInt32 addCondSaveState(Expression* e, string_view name); bool delCondSaveState(uInt32 idx); void clearCondSaveStates(); const StringList& getCondSaveStateNames() const; // methods for 'trapif' handling - uInt32 addCondTrap(Expression* e, const string& name); + uInt32 addCondTrap(Expression* e, string_view name); bool delCondTrap(uInt32 idx); void clearCondTraps(); const StringList& getCondTrapNames() const; diff --git a/src/emucore/MD5.cxx b/src/emucore/MD5.cxx index 2e3ddb44a..798645de4 100644 --- a/src/emucore/MD5.cxx +++ b/src/emucore/MD5.cxx @@ -301,11 +301,9 @@ static void Decode(uInt32* output, const uInt8* const input, uInt32 len) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string hash(const string& buffer) +string hash(string_view buffer) { - std::vector vec(buffer.begin(), buffer.end()); - - return hash(vec.data(), vec.size()); + return hash(reinterpret_cast(buffer.data()), buffer.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/MD5.hxx b/src/emucore/MD5.hxx index 748da758b..831bb0713 100644 --- a/src/emucore/MD5.hxx +++ b/src/emucore/MD5.hxx @@ -47,7 +47,7 @@ namespace MD5 { @return The message - digest */ - string hash(const string& buffer); + string hash(string_view buffer); } // namespace MD5 diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 095898426..f304c59af 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -207,7 +207,7 @@ bool OSystem::initialize(const Settings::Options& options) // Detect serial port for AtariVox-USB // If a previously set port is defined, use it; // otherwise use the first one found (if any) - const string& avoxport = mySettings->getString("avoxport"); + const string_view avoxport = mySettings->getString("avoxport"); const StringList ports = MediaFactory::createSerialPort()->portNames(); if(avoxport.empty() && !ports.empty()) @@ -277,7 +277,7 @@ void OSystem::setConfigPaths() // Make sure all required directories actually exist const auto buildDirIfRequired = [](FSNode& path, const FSNode& initialPath, - const string& pathToAppend = EmptyString) + string_view pathToAppend = EmptyString) { path = initialPath; if(pathToAppend != EmptyString) @@ -293,7 +293,7 @@ void OSystem::setConfigPaths() #endif #ifdef IMAGE_SUPPORT - const string& ssSaveDir = mySettings->getString("snapsavedir"); + const string_view ssSaveDir = mySettings->getString("snapsavedir"); if(ssSaveDir == EmptyString) mySnapshotSaveDir = userDir(); else @@ -301,7 +301,7 @@ void OSystem::setConfigPaths() if(!mySnapshotSaveDir.isDirectory()) mySnapshotSaveDir.makeDir(); - const string& ssLoadDir = mySettings->getString("snaploaddir"); + const string_view ssLoadDir = mySettings->getString("snaploaddir"); if(ssLoadDir == EmptyString) mySnapshotLoadDir = userDir(); else @@ -315,7 +315,7 @@ void OSystem::setConfigPaths() #if 0 // Debug code - auto dbgPath = [](const string& desc, const FSNode& location) + auto dbgPath = [](string_view desc, const FSNode& location) { cerr << desc << ": " << location << endl; }; @@ -331,7 +331,7 @@ void OSystem::setConfigPaths() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void OSystem::setUserDir(const string& path) +void OSystem::setUserDir(string_view path) { mySettings->setValue("userdir", path); @@ -416,8 +416,7 @@ void OSystem::createSound() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystem::createConsole(const FSNode& rom, const string& md5sum, - bool newrom) +string OSystem::createConsole(const FSNode& rom, string_view md5sum, bool newrom) { bool showmessage = false; @@ -567,7 +566,7 @@ bool OSystem::hasConsole() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool OSystem::createLauncher(const string& startdir) +bool OSystem::createLauncher(string_view startdir) { closeConsole(); @@ -666,7 +665,7 @@ unique_ptr OSystem::openConsole(const FSNode& romfile, string& md5) // Now create the cartridge string cartmd5 = md5; const string& type = props.get(PropType::Cart_Type); - const Cartridge::messageCallback callback = [&os = *this](const string& msg) + const Cartridge::messageCallback callback = [&os = *this](string_view msg) { const bool devSettings = os.settings().getBool("dev.settings"); diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index d9de8e9ff..dc4129051 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -365,7 +365,7 @@ class OSystem @return String indicating any error message (EmptyString for no errors) */ - string createConsole(const FSNode& rom, const string& md5 = "", + string createConsole(const FSNode& rom, string_view md5 = "", bool newrom = true); /** @@ -386,7 +386,7 @@ class OSystem @return True on successful creation, otherwise false */ - bool createLauncher(const string& startdir = ""); + bool createLauncher(string_view startdir = ""); /** Answers whether the ROM launcher was actually successfully used @@ -455,11 +455,11 @@ class OSystem Again, this is not supported on all systems, so it may be simply ignored. */ - static void overrideBaseDir(const string& path) { ourOverrideBaseDir = path; } + static void overrideBaseDir(string_view path) { ourOverrideBaseDir = path; } static void overrideBaseDirWithApp() { ourOverrideBaseDirWithApp = true; } // Update the path of the user directory - void setUserDir(const string& path); + void setUserDir(string_view path); public: ////////////////////////////////////////////////////////////////////// @@ -505,7 +505,7 @@ class OSystem they are free to ignore it */ virtual void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) = 0; + bool useappdir, string_view usedir) = 0; virtual void initPersistence(FSNode& basedir) = 0; diff --git a/src/emucore/OSystemStandalone.cxx b/src/emucore/OSystemStandalone.cxx index 225f434d4..f5ca62a71 100644 --- a/src/emucore/OSystemStandalone.cxx +++ b/src/emucore/OSystemStandalone.cxx @@ -51,6 +51,6 @@ shared_ptr OSystemStandalone::getHighscoreRep // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemStandalone::getBaseDirectories( - string& basedir, string& homedir, bool useappdir, const string& usedir) + string& basedir, string& homedir, bool useappdir, string_view usedir) { } diff --git a/src/emucore/OSystemStandalone.hxx b/src/emucore/OSystemStandalone.hxx index 0c59db71e..e1cec937f 100644 --- a/src/emucore/OSystemStandalone.hxx +++ b/src/emucore/OSystemStandalone.hxx @@ -41,7 +41,7 @@ class OSystemStandalone : public OSystem string describePresistence() override; void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override; + bool useappdir, string_view usedir) override; private: diff --git a/src/emucore/PlusROM.cxx b/src/emucore/PlusROM.cxx index 9ccb8117d..9143f17cf 100644 --- a/src/emucore/PlusROM.cxx +++ b/src/emucore/PlusROM.cxx @@ -47,7 +47,7 @@ using std::chrono::milliseconds; class PlusROMRequest { public: struct Destination { - Destination(const string& _host, const string& _path) + Destination(string_view _host, string_view _path) : host{_host}, path{_path} {} string host; @@ -55,7 +55,7 @@ class PlusROMRequest { }; struct PlusStoreId { - PlusStoreId(const string& _nick, const string& _id) + PlusStoreId(string_view _nick, string_view _id) : nick{_nick}, id{_id} {} string nick; @@ -369,7 +369,7 @@ void PlusROM::reset() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool PlusROM::isValidHost(const string& host) +bool PlusROM::isValidHost(string_view host) { // TODO: This isn't 100% either, as we're supposed to check for the length // of each part between '.' in the range 1 .. 63 @@ -377,11 +377,11 @@ bool PlusROM::isValidHost(const string& host) // library we decide to use static const std::regex rgx(R"(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$)", std::regex_constants::icase); - return std::regex_match(host, rgx); + return std::regex_match(host.cbegin(), host.cend(), rgx); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool PlusROM::isValidPath(const string& path) +bool PlusROM::isValidPath(string_view path) { // TODO: This isn't 100% // Perhaps a better function will be included with whatever network diff --git a/src/emucore/PlusROM.hxx b/src/emucore/PlusROM.hxx index bf1cc6696..678953148 100644 --- a/src/emucore/PlusROM.hxx +++ b/src/emucore/PlusROM.hxx @@ -157,8 +157,8 @@ class PlusROM : public Serializable } private: - static bool isValidHost(const string& host); - static bool isValidPath(const string& path); + static bool isValidHost(string_view host); + static bool isValidPath(string_view path); /** Receive data from all requests that have completed. diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 8c5548fe1..db981b05d 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -61,7 +61,7 @@ bool Properties::save(KeyValueRepository& repo) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Properties::set(PropType key, const string& value) +void Properties::set(PropType key, string_view value) { const auto pos = static_cast(key); if(pos < myProperties.size()) @@ -137,7 +137,7 @@ Properties& Properties::operator=(const Properties& properties) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Properties::setDefault(PropType key, const string& value) +void Properties::setDefault(PropType key, string_view value) { ourDefaultProperties[static_cast(key)] = value; } @@ -200,7 +200,7 @@ void Properties::setDefaults() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -PropType Properties::getPropType(const string& name) +PropType Properties::getPropType(string_view name) { for(size_t i = 0; i < NUM_PROPS; ++i) if(ourPropertyNames[i] == name) diff --git a/src/emucore/Props.hxx b/src/emucore/Props.hxx index 7c445f496..b69ad807f 100644 --- a/src/emucore/Props.hxx +++ b/src/emucore/Props.hxx @@ -106,7 +106,7 @@ class Properties @param key The key of the property to set @param value The value to assign to the property */ - void set(PropType key, const string& value); + void set(PropType key, string_view value); /** Print the attributes of this properties object @@ -148,7 +148,7 @@ class Properties @param key The key of the property to set @param value The value to assign to the property */ - static void setDefault(PropType key, const string& value); + static void setDefault(PropType key, string_view value); private: /** @@ -165,7 +165,7 @@ class Properties @param name The PropType key associated with the given string */ - static PropType getPropType(const string& name); + static PropType getPropType(string_view name); /** When printing each collection of ROM properties, it is useful to diff --git a/src/emucore/QuadTari.cxx b/src/emucore/QuadTari.cxx index ef7bbdec6..b1dbcbd42 100644 --- a/src/emucore/QuadTari.cxx +++ b/src/emucore/QuadTari.cxx @@ -70,7 +70,7 @@ unique_ptr QuadTari::addController(const Controller::Type type, bool { FSNode nvramfile = myOSystem.nvramDir(); const Controller::onMessageCallback callback = [&os = myOSystem] - (const string& msg) { + (string_view msg) { const bool devSettings = os.settings().getBool("dev.settings"); if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) os.frameBuffer().showTextMessage(msg); diff --git a/src/emucore/Serializer.cxx b/src/emucore/Serializer.cxx index 22434056c..8ea828f9b 100644 --- a/src/emucore/Serializer.cxx +++ b/src/emucore/Serializer.cxx @@ -22,14 +22,15 @@ using std::ios; using std::ios_base; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Serializer::Serializer(const string& filename, Mode m) +Serializer::Serializer(string_view filename, Mode m) { if(m == Mode::ReadOnly) { const FSNode node(filename); if(node.isFile() && node.isReadable()) { - unique_ptr str = make_unique(filename, ios::in | ios::binary); + unique_ptr str = make_unique( + string{filename}, ios::in | ios::binary); if(str && str->is_open()) { myStream = std::move(str); @@ -48,13 +49,14 @@ Serializer::Serializer(const string& filename, Mode m) // So we open in write and append mode - the write creates the file // when necessary, and the append doesn't delete any data if it // already exists - fstream temp(filename, ios::out | ios::app); + string f{filename}; + fstream temp(f, ios::out | ios::app); temp.close(); ios_base::openmode stream_mode = ios::in | ios::out | ios::binary; if(m == Mode::ReadWriteTrunc) stream_mode |= ios::trunc; - unique_ptr str = make_unique(filename, stream_mode); + unique_ptr str = make_unique(f, stream_mode); if(str && str->is_open()) { myStream = std::move(str); @@ -236,11 +238,10 @@ void Serializer::putDouble(double value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Serializer::putString(const string& str) +void Serializer::putString(string_view str) { - const auto len = static_cast(str.length()); - putInt(len); - myStream->write(str.data(), len); + putInt(static_cast(str.size())); + myStream->write(str.data(), str.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Serializer.hxx b/src/emucore/Serializer.hxx index a74c957c5..9a66b999d 100644 --- a/src/emucore/Serializer.hxx +++ b/src/emucore/Serializer.hxx @@ -49,7 +49,7 @@ class Serializer The valid() method must immediately be called to verify the stream was correctly initialized. */ - explicit Serializer(const string& filename, Mode m = Mode::ReadWrite); + explicit Serializer(string_view filename, Mode m = Mode::ReadWrite); Serializer(); public: @@ -207,11 +207,11 @@ class Serializer void putDouble(double value); /** - Writes a string to the current output stream. + Writes a string(view) to the current output stream. @param str The string to write to the output stream. */ - void putString(const string& str); + void putString(string_view str); /** Writes a boolean value to the current output stream. diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 6afaabeb1..fc9797ebc 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -192,7 +192,6 @@ Settings::Settings() setPermanent("confirmexit", false); setPermanent("autopause", false); - // Misc options setPermanent("loglevel", static_cast(Logger::Level::INFO)); setPermanent("logtoconsole", "0"); diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 9b73d3b71..0bd720088 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -1185,14 +1185,9 @@ bool TIA::enableFixedColors(bool enable) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool TIA::setFixedColorPalette(const string& colors) +bool TIA::setFixedColorPalette(string_view colors) { - string s = colors; - sort(s.begin(), s.end()); - if(s != "bgopry") - return false; - - for(int i = 0; i < 6; ++i) + for(size_t i = 0; i < std::max(6, colors.size()); ++i) { switch(colors[i]) { diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 77714b132..4e58cd150 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -420,7 +420,7 @@ class TIA : public Device @return True if colors were changed successfully, else false */ - bool setFixedColorPalette(const string& colors); + bool setFixedColorPalette(string_view colors); /** Enable/disable/query state of 'undriven/floating TIA pins'. diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx index edce60eb9..b0b99e626 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx @@ -42,7 +42,8 @@ void FrameLayoutDetector::simulateInput( } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FrameLayout FrameLayoutDetector::detectedLayout(bool detectPal60, bool detectNtsc50, const string& name) const +FrameLayout FrameLayoutDetector::detectedLayout(bool detectPal60, + bool detectNtsc50, string_view name) const { #if 0 // debug cerr << endl << name << endl; diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx index dd337d2a8..a1e35b4a6 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx @@ -40,8 +40,9 @@ class FrameLayoutDetector: public AbstractFrameManager /** * Return the detected frame layout. */ - FrameLayout detectedLayout(bool detectPal60 = false, bool detectNtsc50 = false, - const string& name = EmptyString) const; + FrameLayout detectedLayout(bool detectPal60 = false, + bool detectNtsc50 = false, + string_view name = EmptyString) const; /** * Simulate some input to pass a potential title screen. @@ -50,7 +51,6 @@ class FrameLayoutDetector: public AbstractFrameManager bool pressed); protected: - /** * Hook into vsync changes. */ @@ -72,7 +72,6 @@ class FrameLayoutDetector: public AbstractFrameManager void pixelColor(uInt8 color) override; private: - /** * This frame manager only tracks frame boundaries, so we have only two states. */ @@ -101,7 +100,6 @@ class FrameLayoutDetector: public AbstractFrameManager }; private: - /** * Change state and change internal state accordingly. */ @@ -113,7 +111,6 @@ class FrameLayoutDetector: public AbstractFrameManager void finalizeFrame(); private: - /** * The current state. */ @@ -138,7 +135,6 @@ class FrameLayoutDetector: public AbstractFrameManager std::array myColorCount{0}; private: - FrameLayoutDetector(const FrameLayoutDetector&) = delete; FrameLayoutDetector(FrameLayoutDetector&&) = delete; FrameLayoutDetector& operator=(const FrameLayoutDetector&) = delete; diff --git a/src/gui/AboutDialog.cxx b/src/gui/AboutDialog.cxx index a90793b42..b9501032e 100644 --- a/src/gui/AboutDialog.cxx +++ b/src/gui/AboutDialog.cxx @@ -112,7 +112,7 @@ AboutDialog::~AboutDialog() // NOLINT (we need an empty d'tor) void AboutDialog::updateStrings(int page, int lines, string& title) { int i = 0; - const auto ADD_ATEXT = [&](const string& d) { myDescStr[i] = d; i++; }; + const auto ADD_ATEXT = [&](string_view d) { myDescStr[i] = d; i++; }; const auto ADD_ALINE = [&]() { ADD_ATEXT(""); }; switch(page) @@ -315,14 +315,14 @@ void AboutDialog::handleCommand(CommandSender* sender, int cmd, int data, int id } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string AboutDialog::getUrl(const string& text) +string AboutDialog::getUrl(string_view text) { bool isUrl = false; size_t start = 0, len = 0; for(size_t i = 0; i < text.size(); ++i) { - const string remainder = text.substr(i); + const string_view remainder = text.substr(i); const char ch = text[i]; if(!isUrl @@ -344,7 +344,7 @@ string AboutDialog::getUrl(const string& text) } } if(len) - return text.substr(start, len); + return string{text.substr(start, len)}; else return EmptyString; } diff --git a/src/gui/AboutDialog.hxx b/src/gui/AboutDialog.hxx index 64c184c6c..95217a642 100644 --- a/src/gui/AboutDialog.hxx +++ b/src/gui/AboutDialog.hxx @@ -38,7 +38,7 @@ class AboutDialog : public Dialog void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void updateStrings(int page, int lines, string& title); void displayInfo(); - static string getUrl(const string& text); + static string getUrl(string_view text); void loadConfig() override { displayInfo(); } diff --git a/src/gui/CheckListWidget.cxx b/src/gui/CheckListWidget.cxx index 58968ea58..e2706a9b4 100644 --- a/src/gui/CheckListWidget.cxx +++ b/src/gui/CheckListWidget.cxx @@ -67,7 +67,7 @@ void CheckListWidget::setList(const StringList& list, const BoolArray& state) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::setLine(int line, const string& str, const bool& state) +void CheckListWidget::setLine(int line, string_view str, const bool& state) { if(line >= static_cast(_list.size())) return; diff --git a/src/gui/CheckListWidget.hxx b/src/gui/CheckListWidget.hxx index cc387fc4c..bda4d8a21 100644 --- a/src/gui/CheckListWidget.hxx +++ b/src/gui/CheckListWidget.hxx @@ -37,7 +37,7 @@ class CheckListWidget : public ListWidget ~CheckListWidget() override = default; void setList(const StringList& list, const BoolArray& state); - void setLine(int line, const string& str, const bool& state); + void setLine(int line, string_view str, const bool& state); bool getState(int line) const; bool getSelectedState() const { return getState(_selectedItem); } diff --git a/src/gui/ComboDialog.cxx b/src/gui/ComboDialog.cxx index d9bdc3fa8..471137516 100644 --- a/src/gui/ComboDialog.cxx +++ b/src/gui/ComboDialog.cxx @@ -51,7 +51,7 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, // Add event popup for 8 events myEvents.fill(nullptr); - const auto ADD_EVENT_POPUP = [&](int idx, const string& label) + const auto ADD_EVENT_POPUP = [&](int idx, string_view label) { myEvents[idx] = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, combolist, label); @@ -76,13 +76,13 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ComboDialog::show(Event::Type event, const string& name) +void ComboDialog::show(Event::Type event, string_view name) { // Make sure the event is allowed if(event >= Event::Combo1 && event <= Event::Combo16) { myComboEvent = event; - setTitle("Add events for " + name); + setTitle("Add events for " + string{name}); open(); } else diff --git a/src/gui/ComboDialog.hxx b/src/gui/ComboDialog.hxx index 5c94094d1..581dade1a 100644 --- a/src/gui/ComboDialog.hxx +++ b/src/gui/ComboDialog.hxx @@ -33,7 +33,7 @@ class ComboDialog : public Dialog ~ComboDialog() override = default; /** Place the dialog onscreen and center it */ - void show(Event::Type event, const string& name); + void show(Event::Type event, string_view name); private: void loadConfig() override; diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index e4ac74484..d1e8e5c55 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -169,7 +169,7 @@ const string& ContextMenu::getSelectedName() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ContextMenu::setSelectedName(const string& name) +void ContextMenu::setSelectedName(string_view name) { if(_selectedItem >= 0) _entries[_selectedItem].first = name; diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 583bccdfe..bca54e305 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -72,7 +72,7 @@ class ContextMenu : public Dialog, public CommandSender /** Accessor methods for the currently selected item. */ int getSelected() const; const string& getSelectedName() const; - void setSelectedName(const string& name); + void setSelectedName(string_view name); const Variant& getSelectedTag() const; /** This dialog uses its own positioning, so we override Dialog::setPosition() */ diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index f22e51303..ea167b831 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -430,7 +430,7 @@ void DeveloperDialog::addVideoTab(const GUI::Font& font) kM1ColourChangedCmd, kPFColourChangedCmd, kBLColourChangedCmd }; - const auto createDebugColourWidgets = [&](int idx, const string& desc) + const auto createDebugColourWidgets = [&](int idx, string_view desc) { int x = HBORDER + INDENT * 1; myDbgColour[idx] = new PopUpWidget(myTab, font, x, ypos - 1, @@ -766,7 +766,7 @@ void DeveloperDialog::setWidgetStates(SettingsSet set) myRandomizeTIAWidget->setState(myRandomizeTIA[set]); myRandomizeRAMWidget->setState(myRandomizeRAM[set]); - const string& cpurandom = myRandomizeCPU[set]; + const string_view cpurandom = myRandomizeCPU[set]; const std::array cpuregs = {"S", "A", "X", "Y", "P"}; for(int i = 0; i < 5; ++i) @@ -1408,7 +1408,7 @@ void DeveloperDialog::handleDebugColours(int idx, int color) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DeveloperDialog::handleDebugColours(const string& colors) +void DeveloperDialog::handleDebugColours(string_view colors) { for(int i = 0; i < DEBUG_COLORS; ++i) { diff --git a/src/gui/DeveloperDialog.hxx b/src/gui/DeveloperDialog.hxx index 71966d017..0de237247 100644 --- a/src/gui/DeveloperDialog.hxx +++ b/src/gui/DeveloperDialog.hxx @@ -165,7 +165,7 @@ class DeveloperDialog : public Dialog, DevSettingsHandler void handleTia(); void handleDebugColours(int idx, int color); - void handleDebugColours(const string& colors); + void handleDebugColours(string_view colors); void handleTimeMachine(); void handleSize(); diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 4f667c0a9..aeaec8d69 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -48,7 +48,7 @@ */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, - const string& title, int x, int y, int w, int h) + string_view title, int x, int y, int w, int h) : GuiObject(instance, parent, *this, x, y, w, h), _font{font}, _title{title}, @@ -148,7 +148,7 @@ void Dialog::close() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::setTitle(const string& title) +void Dialog::setTitle(string_view title) { _title = title; _h -= _th; @@ -188,7 +188,7 @@ void Dialog::initHelp() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::setHelpAnchor(const string& helpAnchor, bool debugger) +void Dialog::setHelpAnchor(string_view helpAnchor, bool debugger) { _helpAnchor = helpAnchor; _debuggerHelp = debugger; @@ -197,7 +197,7 @@ void Dialog::setHelpAnchor(const string& helpAnchor, bool debugger) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::setHelpURL(const string& helpURL) +void Dialog::setHelpURL(string_view helpURL) { _helpURL = helpURL; @@ -979,7 +979,7 @@ Widget* Dialog::findWidget(int x, int y) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::addOKBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText, int buttonWidth) + string_view okText, int buttonWidth) { const int buttonHeight = Dialog::buttonHeight(), BUTTON_GAP = Dialog::buttonGap(), @@ -998,7 +998,7 @@ void Dialog::addOKBGroup(WidgetArray& wid, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText, const string& cancelText, + string_view okText, string_view cancelText, bool focusOKButton, int buttonWidth) { const int buttonHeight = Dialog::buttonHeight(), @@ -1043,8 +1043,8 @@ void Dialog::addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::addDefaultsOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText, const string& cancelText, - const string& defaultsText, + string_view okText, string_view cancelText, + string_view defaultsText, bool focusOKButton) { const int buttonHeight = Dialog::buttonHeight(), @@ -1062,8 +1062,8 @@ void Dialog::addDefaultsOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::addDefaultsExtraOKCancelBGroup( WidgetArray& wid, const GUI::Font& font, - const string& extraText, int extraCmd, - const string& okText, const string& cancelText, const string& defaultsText, + string_view extraText, int extraCmd, + string_view okText, string_view cancelText, string_view defaultsText, bool focusOKButton) { const int buttonHeight = Dialog::buttonHeight(), diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index b3411ba9b..3cb84b6a9 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -52,7 +52,7 @@ class Dialog : public GuiObject Dialog(OSystem& instance, DialogContainer& parent, int x = 0, int y = 0, int w = 0, int h = 0); Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, - const string& title = "", int x = 0, int y = 0, int w = 0, int h = 0); + string_view title = "", int x = 0, int y = 0, int w = 0, int h = 0); ~Dialog() override; void clear(); @@ -96,12 +96,12 @@ class Dialog : public GuiObject */ void addRenderCallback(const RenderCallback& callback); - void setTitle(const string& title); + void setTitle(string_view title); bool hasTitle() { return !_title.empty(); } void initHelp(); - void setHelpAnchor(const string& helpAnchor, bool debugger = false); - void setHelpURL(const string& helpURL); + void setHelpAnchor(string_view helpAnchor, bool debugger = false); + void setHelpURL(string_view helpURL); virtual bool isShading() const { return true; } @@ -139,7 +139,7 @@ class Dialog : public GuiObject int fontHeight() const { return _font.getFontHeight(); } int fontWidth() const { return _font.getMaxCharWidth(); } int buttonHeight() const { return lineHeight() * 1.25; } - int buttonWidth(const string& label) const { + int buttonWidth(string_view label) const { return _font.getStringWidth(label) + fontWidth() * 2.5; } int buttonGap() const { return fontWidth(); } @@ -175,28 +175,28 @@ class Dialog : public GuiObject void addOKBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText = "OK", + string_view okText = "OK", int buttonWidth = 0); void addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText = "OK", - const string& cancelText = "Cancel", + string_view okText = "OK", + string_view cancelText = "Cancel", bool focusOKButton = true, int buttonWidth = 0); void addDefaultsOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, - const string& okText = "OK", - const string& cancelText = "Cancel", - const string& defaultsText = "Defaults", + string_view okText = "OK", + string_view cancelText = "Cancel", + string_view defaultsText = "Defaults", bool focusOKButton = true); // NOTE: This method, and the three above it, are due to be refactored at some // point, since the parameter list is kind of getting ridiculous void addDefaultsExtraOKCancelBGroup(WidgetArray& wid, const GUI::Font& font, - const string& extraText, int extraCmd, - const string& okText = "OK", - const string& cancelText = "Cancel", - const string& defaultsText = "Defaults", + string_view extraText, int extraCmd, + string_view okText = "OK", + string_view cancelText = "Cancel", + string_view defaultsText = "Defaults", bool focusOKButton = true); void processCancelWithoutWidget(bool state = true) { _processCancel = state; } diff --git a/src/gui/EditTextWidget.cxx b/src/gui/EditTextWidget.cxx index de3bdb61b..b2003f7cb 100644 --- a/src/gui/EditTextWidget.cxx +++ b/src/gui/EditTextWidget.cxx @@ -24,7 +24,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& text) + int x, int y, int w, int h, string_view text) : EditableWidget(boss, font, x, y, w, h + 2, text) { _flags = Widget::FLAG_ENABLED | Widget::FLAG_CLEARBG @@ -33,17 +33,13 @@ EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font, EditableWidget::startEditMode(); // We're always in edit mode if(_font.getFontHeight() < 24) - { _textOfs = 3; - } else - { _textOfs = 5; - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditTextWidget::setText(const string& str, bool changed) +void EditTextWidget::setText(string_view str, bool changed) { EditableWidget::setText(str, changed); diff --git a/src/gui/EditTextWidget.hxx b/src/gui/EditTextWidget.hxx index f566394b2..c905a2d49 100644 --- a/src/gui/EditTextWidget.hxx +++ b/src/gui/EditTextWidget.hxx @@ -26,10 +26,10 @@ class EditTextWidget : public EditableWidget { public: EditTextWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& text = ""); + int x, int y, int w, int h, string_view text = ""); ~EditTextWidget() override = default; - void setText(const string& str, bool changed = false) override; + void setText(string_view str, bool changed = false) override; // Get total width of widget static int calcWidth(const GUI::Font& font, int length = 0) @@ -38,9 +38,9 @@ class EditTextWidget : public EditableWidget + (font.getFontHeight() < 24 ? 3 * 2 : 5 * 2); } // Get total width of widget - static int calcWidth(const GUI::Font& font, const string& str) + static int calcWidth(const GUI::Font& font, string_view str) { - return calcWidth(font, static_cast(str.length())); + return calcWidth(font, static_cast(str.size())); } protected: diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index f6f206f22..f1a2e4eda 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -28,7 +28,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& str) + int x, int y, int w, int h, string_view str) : Widget(boss, font, x, y, w, h), CommandSender(boss), _editString{str}, @@ -43,7 +43,7 @@ EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditableWidget::setText(const string& str, bool changed) +void EditableWidget::setText(string_view str, bool changed) { const string oldEditString = _editString; _backupString = str; @@ -213,7 +213,7 @@ void EditableWidget::handleCommand(CommandSender* sender, int cmd, int data, int { if(cmd == ContextMenu::kItemSelectedCmd) { - const string& rmb = mouseMenu().getSelectedTag().toString(); + const string_view rmb = mouseMenu().getSelectedTag().toString(); if(rmb == "cut") { diff --git a/src/gui/EditableWidget.hxx b/src/gui/EditableWidget.hxx index c354213aa..697c3dfd1 100644 --- a/src/gui/EditableWidget.hxx +++ b/src/gui/EditableWidget.hxx @@ -47,10 +47,10 @@ class EditableWidget : public Widget, public CommandSender public: EditableWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& str = ""); + int x, int y, int w, int h, string_view str = ""); ~EditableWidget() override = default; - virtual void setText(const string& str, bool changed = false); + virtual void setText(string_view str, bool changed = false); void setMaxLen(int len) { _maxLen = len; } const string& getText() const { return _editString; } diff --git a/src/gui/FavoritesManager.cxx b/src/gui/FavoritesManager.cxx index f928f3908..790faf476 100644 --- a/src/gui/FavoritesManager.cxx +++ b/src/gui/FavoritesManager.cxx @@ -136,15 +136,15 @@ void FavoritesManager::clear() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FavoritesManager::addUser(const string& path) +void FavoritesManager::addUser(string_view path) { myUserSet.emplace(path); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FavoritesManager::removeUser(const string& path) +void FavoritesManager::removeUser(string_view path) { - myUserSet.erase(path); + myUserSet.erase(string{path}); // TODO: fixed in C++20 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -154,7 +154,7 @@ void FavoritesManager::removeAllUser() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FavoritesManager::toggleUser(const string& path) +bool FavoritesManager::toggleUser(string_view path) { const bool favorize = !existsUser(path); @@ -167,9 +167,9 @@ bool FavoritesManager::toggleUser(const string& path) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FavoritesManager::existsUser(const string& path) const +bool FavoritesManager::existsUser(string_view path) const { - return myUserSet.find(path) != myUserSet.end(); + return myUserSet.find(string{path}) != myUserSet.end(); // TODO: fixed in C++20 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -183,7 +183,7 @@ const FavoritesManager::UserList& FavoritesManager::userList() const if(!mySettings.getBool("altsorting")) std::sort(sortedList.begin(), sortedList.end(), - [](const string& a, const string& b) + [](string_view a, string_view b) { // Sort without path const FSNode aNode(a); @@ -191,7 +191,8 @@ const FavoritesManager::UserList& FavoritesManager::userList() const const bool realDir = aNode.isDirectory() && !BSPF::endsWithIgnoreCase(aNode.getPath(), ".zip"); - if(realDir != (bNode.isDirectory() && !BSPF::endsWithIgnoreCase(bNode.getPath(), ".zip"))) + if(realDir != (bNode.isDirectory() && + !BSPF::endsWithIgnoreCase(bNode.getPath(), ".zip"))) return realDir; return BSPF::compareIgnoreCase(aNode.getName(), bNode.getName()) < 0; }); @@ -199,14 +200,14 @@ const FavoritesManager::UserList& FavoritesManager::userList() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FavoritesManager::update(const string& path) +void FavoritesManager::update(string_view path) { addRecent(path); incPopular(path); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FavoritesManager::addRecent(const string& path) +void FavoritesManager::addRecent(string_view path) { // Always remove existing before adding at the end again removeRecent(path); @@ -218,7 +219,7 @@ void FavoritesManager::addRecent(const string& path) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FavoritesManager::removeRecent(const string& path) +bool FavoritesManager::removeRecent(string_view path) { auto it = std::find(myRecentList.begin(), myRecentList.end(), path); @@ -246,7 +247,7 @@ const FavoritesManager::RecentList& FavoritesManager::recentList() const sortedList.assign(myRecentList.begin(), myRecentList.end()); std::sort(sortedList.begin(), sortedList.end(), - [](const string& a, const string& b) + [](string_view a, string_view b) { // Sort alphabetical, without path const FSNode aNode(a); @@ -263,9 +264,9 @@ const FavoritesManager::RecentList& FavoritesManager::recentList() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FavoritesManager::removePopular(const string& path) +bool FavoritesManager::removePopular(string_view path) { - return myPopularMap.erase(path); + return myPopularMap.erase(string{path}); // TODO: fixed in C++20 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -275,7 +276,7 @@ void FavoritesManager::removeAllPopular() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FavoritesManager::incPopular(const string& path) +void FavoritesManager::incPopular(string_view path) { static constexpr uInt32 scale = 100; static constexpr double factor = 0.7; diff --git a/src/gui/FavoritesManager.hxx b/src/gui/FavoritesManager.hxx index a8d61057e..e7c91ffae 100644 --- a/src/gui/FavoritesManager.hxx +++ b/src/gui/FavoritesManager.hxx @@ -46,28 +46,28 @@ class FavoritesManager void clear(); // User favorites - void addUser(const string& path); - void removeUser(const string& path); + void addUser(string_view path); + void removeUser(string_view path); void removeAllUser(); - bool toggleUser(const string& path); - bool existsUser(const string& path) const; + bool toggleUser(string_view path); + bool existsUser(string_view path) const; const UserList& userList() const; - void update(const string& path); + void update(string_view path); // Recently played - bool removeRecent(const string& path); + bool removeRecent(string_view path); void removeAllRecent(); const RecentList& recentList() const; // Most popular - bool removePopular(const string& path); + bool removePopular(string_view path); void removeAllPopular(); const PopularList& popularList() const; private: - using PopularMap = std::map; + using PopularMap = std::map>; using UserSet = std::unordered_set; UserSet myUserSet; @@ -78,8 +78,8 @@ class FavoritesManager Settings& mySettings; private: - void addRecent(const string& path); - void incPopular(const string& path); + void addRecent(string_view path); + void incPopular(string_view path); const PopularList& sortedPopularList(bool sortByName = false) const; private: diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index d73b0e0c3..39aa9c7da 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -37,7 +37,7 @@ FileListWidget::FileListWidget(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FileListWidget::setDirectory(const FSNode& node, const string& select) +void FileListWidget::setDirectory(const FSNode& node, string_view select) { _node = node; @@ -56,7 +56,7 @@ void FileListWidget::setDirectory(const FSNode& node, const string& select) // Initialize history FSNode tmp = _node; - string name = select; + string name{select}; _history.clear(); while(tmp.hasParent()) @@ -76,7 +76,7 @@ void FileListWidget::setDirectory(const FSNode& node, const string& select) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FileListWidget::setLocation(const FSNode& node, const string& select) +void FileListWidget::setLocation(const FSNode& node, string_view select) { progress().resetProgress(); progress().open(); @@ -158,7 +158,7 @@ void FileListWidget::getChildren(const FSNode::CancelCheck& isCancelled) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FileListWidget::IconType FileListWidget::getIconType(const string& path) const +FileListWidget::IconType FileListWidget::getIconType(string_view path) const { const FSNode node(path); diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index 17aa4e07f..d38fb9590 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -81,8 +81,7 @@ class FileListWidget : public StringListWidget will instead be used, and the file will be selected @param select An optional entry to select (if applicable) */ - void setDirectory(const FSNode& node, - const string& select = EmptyString); + void setDirectory(const FSNode& node, string_view select = EmptyString); /** Descend into currently selected directory */ void selectDirectory(); @@ -114,7 +113,7 @@ class FileListWidget : public StringListWidget FSNode node; string selected; - explicit HistoryType(const FSNode& _hnode, const string& _hselected) + explicit HistoryType(const FSNode& _hnode, string_view _hselected) : node{_hnode}, selected{_hselected} {} }; enum class IconType { @@ -137,7 +136,7 @@ class FileListWidget : public StringListWidget protected: /** Very similar to setDirectory(), but also updates the history */ - void setLocation(const FSNode& node, const string& select); + void setLocation(const FSNode& node, string_view select); /** Select to home directory */ void selectHomeDir(); /** Select previous directory in history (if applicable) */ @@ -147,7 +146,7 @@ class FileListWidget : public StringListWidget virtual bool isDirectory(const FSNode& node) const; virtual void getChildren(const FSNode::CancelCheck& isCancelled); virtual void extendLists(StringList& list) { } - virtual IconType getIconType(const string& path) const; + virtual IconType getIconType(string_view path) const; virtual const Icon* getIcon(int i) const; int iconWidth() const; virtual bool fullPathToolTip() const { return false; } diff --git a/src/gui/Font.cxx b/src/gui/Font.cxx index 53b2d5a50..d5b0787d1 100644 --- a/src/gui/Font.cxx +++ b/src/gui/Font.cxx @@ -49,7 +49,7 @@ int Font::getCharWidth(uInt8 chr) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Font::getStringWidth(const string& str) const +int Font::getStringWidth(string_view str) const { // If no width table is specified, use the maximum width if(!myFontDesc.width) diff --git a/src/gui/Font.hxx b/src/gui/Font.hxx index e451e0ee6..8661aa24e 100644 --- a/src/gui/Font.hxx +++ b/src/gui/Font.hxx @@ -65,7 +65,7 @@ class Font int getCharWidth(uInt8 chr) const; - int getStringWidth(const string& str) const; + int getStringWidth(string_view str) const; private: FontDesc myFontDesc; diff --git a/src/gui/HelpDialog.cxx b/src/gui/HelpDialog.cxx index 005d749bf..1f2615684 100644 --- a/src/gui/HelpDialog.cxx +++ b/src/gui/HelpDialog.cxx @@ -98,7 +98,7 @@ HelpDialog::HelpDialog(OSystem& osystem, DialogContainer& parent, void HelpDialog::updateStrings(uInt8 page, uInt8 lines, string& title) { int i = 0; - const auto ADD_BIND = [&](const string& k, const string& d) + const auto ADD_BIND = [&](string_view k, string_view d) { myKeyStr[i] = k; myDescStr[i] = d; i++; }; @@ -109,7 +109,7 @@ void HelpDialog::updateStrings(uInt8 page, uInt8 lines, string& title) desc = instance().eventHandler().getMappingDesc(e, EventMode::kMenuMode); ADD_BIND(desc.length() ? desc : "None", d); }; - const auto ADD_TEXT = [&](const string& d) { ADD_BIND("", d); }; + const auto ADD_TEXT = [&](string_view d) { ADD_BIND("", d); }; const auto ADD_LINE = [&]() { ADD_BIND("", ""); }; setHelpAnchor("Hotkeys"); diff --git a/src/gui/InputTextDialog.cxx b/src/gui/InputTextDialog.cxx index fd2c4a810..5212ed0ac 100644 --- a/src/gui/InputTextDialog.cxx +++ b/src/gui/InputTextDialog.cxx @@ -29,7 +29,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, - const StringList& labels, const string& title) + const StringList& labels, string_view title) : Dialog(boss->instance(), boss->parent(), font, title), CommandSender(boss) { @@ -39,7 +39,7 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, - const StringList& labels, const string& title) + const StringList& labels, string_view title) : Dialog(boss->instance(), boss->parent(), lfont, title), CommandSender(boss) { @@ -48,22 +48,24 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& lfont, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - InputTextDialog::InputTextDialog(OSystem& osystem, DialogContainer& parent, - const GUI::Font& font, const string& label, - const string& title, int numInput) + const GUI::Font& font, string_view label, + string_view title, int numInput) : Dialog(osystem, parent, font, title), CommandSender(nullptr) { StringList labels; clear(); - labels.push_back(label); + labels.emplace_back(label); initialize(font, font, labels, - static_cast(label.length()) + (numInput ? numInput : 24) + 2, numInput); + static_cast(label.length()) + (numInput ? numInput : 24) + 2, + numInput); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont, - const StringList& labels, int widthChars, int numInput) + const StringList& labels, int widthChars, + int numInput) { const int lineHeight = Dialog::lineHeight(), fontHeight = Dialog::fontHeight(), @@ -166,7 +168,7 @@ void InputTextDialog::setPosition() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputTextDialog::setMessage(const string& title) +void InputTextDialog::setMessage(string_view title) { myMessage->setLabel(title); myErrorFlag = true; @@ -182,7 +184,7 @@ const string& InputTextDialog::getResult(int idx) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputTextDialog::setText(const string& str, int idx) +void InputTextDialog::setText(string_view str, int idx) { if(static_cast(idx) < myInput.size()) myInput[idx]->setText(str); @@ -196,7 +198,7 @@ void InputTextDialog::setTextFilter(const EditableWidget::TextFilter& f, int idx } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputTextDialog::setToolTip(const string& str, int idx) +void InputTextDialog::setToolTip(string_view str, int idx) { if(static_cast(idx) < myLabel.size()) myLabel[idx]->setToolTip(str); diff --git a/src/gui/InputTextDialog.hxx b/src/gui/InputTextDialog.hxx index b3378400b..5782869c1 100644 --- a/src/gui/InputTextDialog.hxx +++ b/src/gui/InputTextDialog.hxx @@ -30,12 +30,13 @@ class InputTextDialog : public Dialog, public CommandSender { public: InputTextDialog(GuiObject* boss, const GUI::Font& font, - const StringList& labels, const string& title = ""); + const StringList& labels, string_view title = ""); InputTextDialog(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, const StringList& labels, - const string& title = ""); - InputTextDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, - const string& label, const string& title, int numInput = 0); + string_view title = ""); + InputTextDialog(OSystem& osystem, DialogContainer& parent, + const GUI::Font& font, string_view label, string_view title, + int numInput = 0); ~InputTextDialog() override = default; @@ -47,18 +48,19 @@ class InputTextDialog : public Dialog, public CommandSender const string& getResult(int idx = 0); - void setText(const string& str, int idx = 0); + void setText(string_view str, int idx = 0); void setTextFilter(const EditableWidget::TextFilter& f, int idx = 0); - void setToolTip(const string& str, int idx = 0); + void setToolTip(string_view str, int idx = 0); void setEmitSignal(int cmd) { myCmd = cmd; } - void setMessage(const string& title); + void setMessage(string_view title); void setFocus(int idx = 0); protected: void initialize(const GUI::Font& lfont, const GUI::Font& nfont, - const StringList& labels, int widthChars = 39, int numInput = 0); + const StringList& labels, int widthChars = 39, + int numInput = 0); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; /** This dialog uses its own positioning, so we override Dialog::center() */ diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index f692f9229..0c246262f 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -565,10 +565,10 @@ string LauncherDialog::getRomDir() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool LauncherDialog::matchWithWildcardsIgnoreCase( - const string& str, const string& pattern) + string_view str, string_view pattern) { - string in = str; - string pat = pattern; + string in{str}; + string pat{pattern}; BSPF::toUpperCase(in); BSPF::toUpperCase(pat); @@ -1150,11 +1150,11 @@ void LauncherDialog::openContextMenu(int x, int y) string label; string shortcut; string key; - explicit ContextItem(const string& _label, const string& _shortcut, - const string& _key) + explicit ContextItem(string_view _label, string_view _shortcut, + string_view _key) : label{_label}, shortcut{_shortcut}, key{_key} {} // No shortcuts displayed in minimal UI - ContextItem(const string& _label, const string& _key) + ContextItem(string_view _label, string_view _key) : label{_label}, key{_key} {} }; using ContextList = std::vector; @@ -1393,17 +1393,17 @@ void LauncherDialog::removeAllFavorites() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::removeAll(const string& name) +void LauncherDialog::removeAll(string_view name) { StringList msg; msg.emplace_back("This will remove ALL ROMs from"); - msg.emplace_back("your '" + name + "' list!"); + msg.emplace_back("your '" + string{name} + "' list!"); msg.emplace_back(""); msg.emplace_back("Are you sure?"); myConfirmMsg = make_unique (this, _font, msg, _w, _h, kRmAllPop, - "Yes", "No", "Remove all " + name, false); + "Yes", "No", "Remove all " + string{name}, false); myConfirmMsg->show(); } diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index e16fde73c..7b6f6a196 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -139,8 +139,7 @@ class LauncherDialog : public Dialog, CommandSender @return True if pattern was found. */ - static bool matchWithWildcardsIgnoreCase(const string& str, - const string& pattern); + static bool matchWithWildcardsIgnoreCase(string_view str, string_view pattern); void applyFiltering(); @@ -165,7 +164,7 @@ class LauncherDialog : public Dialog, CommandSender void toggleSorting(); void handleFavoritesChanged(); void removeAllFavorites(); - void removeAll(const string& name); + void removeAll(string_view name); void removeAllPopular(); void removeAllRecent(); diff --git a/src/gui/LauncherFileListWidget.cxx b/src/gui/LauncherFileListWidget.cxx index 67cc3ef78..3ccefde96 100644 --- a/src/gui/LauncherFileListWidget.cxx +++ b/src/gui/LauncherFileListWidget.cxx @@ -105,11 +105,12 @@ void LauncherFileListWidget::getChildren(const FSNode::CancelCheck& isCancelled) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherFileListWidget::addFolder(StringList& list, int& offset, - const string& name, IconType icon) + string_view name, IconType icon) { + const string n = string{name}; _fileList.insert(_fileList.begin() + offset, - FSNode(_node.getPath() + name)); - list.insert(list.begin() + offset, name); + FSNode(_node.getPath() + n)); + list.insert(list.begin() + offset, n); _dirList.insert(_dirList.begin() + offset, ""); _iconTypeList.insert((_iconTypeList.begin() + offset), icon); @@ -186,7 +187,7 @@ void LauncherFileListWidget::updateFavorites() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool LauncherFileListWidget::isUserFavorite(const string& path) const +bool LauncherFileListWidget::isUserFavorite(string_view path) const { return myFavorites->existsUser(path); } @@ -220,7 +221,7 @@ void LauncherFileListWidget::removeFavorite() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherFileListWidget::userFavor(const string& path) +void LauncherFileListWidget::userFavor(string_view path) { size_t pos = 0; @@ -253,7 +254,7 @@ void LauncherFileListWidget::removeAllRecent() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FileListWidget::IconType LauncherFileListWidget::getIconType(const string& path) const +FileListWidget::IconType LauncherFileListWidget::getIconType(string_view path) const { if(!isUserFavorite(path)) return FileListWidget::getIconType(path); diff --git a/src/gui/LauncherFileListWidget.hxx b/src/gui/LauncherFileListWidget.hxx index 825c3c929..ebc55dd02 100644 --- a/src/gui/LauncherFileListWidget.hxx +++ b/src/gui/LauncherFileListWidget.hxx @@ -43,7 +43,7 @@ class LauncherFileListWidget : public FileListWidget void saveFavorites(bool force = false); void clearFavorites(); void updateFavorites(); - bool isUserFavorite(const string& path) const; + bool isUserFavorite(string_view path) const; void toggleUserFavorite(); void removeFavorite(); void removeAllUserFavorites(); @@ -55,9 +55,9 @@ class LauncherFileListWidget : public FileListWidget bool inUserDir() const { return myVirtualDir == user_name; } bool inRecentDir() const { return myVirtualDir == recent_name; } bool inPopularDir() const { return myVirtualDir == popular_name; } - bool isUserDir(const string& name) const { return name == user_name; } - bool isRecentDir(const string& name) const { return name == recent_name; } - bool isPopularDir(const string& name) const { return name == popular_name; } + bool isUserDir(string_view name) const { return name == user_name; } + bool isRecentDir(string_view name) const { return name == recent_name; } + bool isPopularDir(string_view name) const { return name == popular_name; } private: static const string user_name; @@ -72,10 +72,10 @@ class LauncherFileListWidget : public FileListWidget private: string startRomDir(); void getChildren(const FSNode::CancelCheck& isCancelled) override; - void userFavor(const string& path); - void addFolder(StringList& list, int& offset, const string& name, IconType icon); + void userFavor(string_view path); + void addFolder(StringList& list, int& offset, string_view name, IconType icon); void extendLists(StringList& list) override; - IconType getIconType(const string& path) const override; + IconType getIconType(string_view path) const override; const Icon* getIcon(int i) const override; bool fullPathToolTip() const override { return myInVirtualDir; } diff --git a/src/gui/ListWidget.cxx b/src/gui/ListWidget.cxx index 6c773fc6f..f71592118 100644 --- a/src/gui/ListWidget.cxx +++ b/src/gui/ListWidget.cxx @@ -89,7 +89,7 @@ void ListWidget::setSelected(int item) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ListWidget::setSelected(const string& item) +void ListWidget::setSelected(string_view item) { int selected = -1; if(!_list.empty()) diff --git a/src/gui/ListWidget.hxx b/src/gui/ListWidget.hxx index 38674e2c7..470c941c3 100644 --- a/src/gui/ListWidget.hxx +++ b/src/gui/ListWidget.hxx @@ -51,7 +51,7 @@ class ListWidget : public EditableWidget int getSelected() const { return _selectedItem; } void setSelected(int item); - void setSelected(const string& item); + void setSelected(string_view item); int getHighlighted() const { return _highlightedItem; } void setHighlighted(int item); diff --git a/src/gui/MessageBox.cxx b/src/gui/MessageBox.cxx index c03262d35..db0d2514d 100644 --- a/src/gui/MessageBox.cxx +++ b/src/gui/MessageBox.cxx @@ -27,10 +27,9 @@ namespace GUI { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, - const StringList& text, int max_w, int max_h, int okCmd, int cancelCmd, - const string& okText, const string& cancelText, - const string& title, - bool focusOKButton) + const StringList& text, int max_w, int max_h, int okCmd, + int cancelCmd, string_view okText, string_view cancelText, + string_view title, bool focusOKButton) : Dialog(boss->instance(), boss->parent(), font, title, 0, 0, max_w, max_h), CommandSender(boss), myOkCmd{okCmd}, @@ -46,9 +45,8 @@ MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text, int max_w, int max_h, int okCmd, - const string& okText, const string& cancelText, - const string& title, - bool focusOKButton) + string_view okText, string_view cancelText, + string_view title, bool focusOKButton) : MessageBox(boss, font, text, max_w, max_h, okCmd, 0, okText, cancelText, title, focusOKButton) { @@ -56,10 +54,9 @@ MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, - const string& text, int max_w, int max_h, int okCmd, - const string& okText, const string& cancelText, - const string& title, - bool focusOKButton) + string_view text, int max_w, int max_h, int okCmd, + string_view okText, string_view cancelText, + string_view title, bool focusOKButton) : MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h, okCmd, okText, cancelText, title, focusOKButton) { @@ -67,10 +64,9 @@ MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, - const string& text, int max_w, int max_h, int okCmd, int cancelCmd, - const string& okText, const string& cancelText, - const string& title, - bool focusOKButton) + string_view text, int max_w, int max_h, int okCmd, + int cancelCmd, string_view okText, string_view cancelText, + string_view title, bool focusOKButton) : MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h, okCmd, cancelCmd, okText, cancelText, title, focusOKButton) { diff --git a/src/gui/MessageBox.hxx b/src/gui/MessageBox.hxx index f1e15b8eb..ace4d7bff 100644 --- a/src/gui/MessageBox.hxx +++ b/src/gui/MessageBox.hxx @@ -36,23 +36,23 @@ class MessageBox : public Dialog, public CommandSender public: MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text, int max_w, int max_h, int okCmd = 0, int cancelCmd = 0, - const string& okText = "OK", const string& cancelText = "Cancel", - const string& title = "", + string_view okText = "OK", string_view cancelText = "Cancel", + string_view title = "", bool focusOKButton = true); MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text, int max_w, int max_h, int okCmd = 0, - const string& okText = "OK", const string& cancelText = "Cancel", - const string& title = "", + string_view okText = "OK", string_view cancelText = "Cancel", + string_view title = "", bool focusOKButton = true); - MessageBox(GuiObject* boss, const GUI::Font& font, const string& text, + MessageBox(GuiObject* boss, const GUI::Font& font, string_view text, int max_w, int max_h, int okCmd = 0, - const string& okText = "OK", const string& cancelText = "Cancel", - const string& title = "", + string_view okText = "OK", string_view cancelText = "Cancel", + string_view title = "", bool focusOKButton = true); - MessageBox(GuiObject* boss, const GUI::Font& font, const string& text, + MessageBox(GuiObject* boss, const GUI::Font& font, string_view text, int max_w, int max_h, int okCmd, int cancelCmd, - const string& okText = "OK", const string& cancelText = "Cancel", - const string& title = "", + string_view okText = "OK", string_view cancelText = "Cancel", + string_view title = "", bool focusOKButton = true); ~MessageBox() override = default; diff --git a/src/gui/MessageDialog.cxx b/src/gui/MessageDialog.cxx index 1ad61a015..fa7aa3eb3 100644 --- a/src/gui/MessageDialog.cxx +++ b/src/gui/MessageDialog.cxx @@ -68,7 +68,7 @@ void MessageDialog::handleCommand(CommandSender* sender, int cmd, int data, int } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void MessageDialog::setMessage(const string& title, const StringList& text, +void MessageDialog::setMessage(string_view title, const StringList& text, bool yesNo) { myTitle = title; @@ -77,7 +77,7 @@ void MessageDialog::setMessage(const string& title, const StringList& text, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void MessageDialog::setMessage(const string& title, const string& text, +void MessageDialog::setMessage(string_view title, string_view text, bool yesNo) { setMessage(title, StringParser(text).stringList(), yesNo); diff --git a/src/gui/MessageDialog.hxx b/src/gui/MessageDialog.hxx index 3ead58fda..d9130de5b 100644 --- a/src/gui/MessageDialog.hxx +++ b/src/gui/MessageDialog.hxx @@ -32,9 +32,9 @@ class MessageDialog : public Dialog ~MessageDialog() override; // Define the message displayed - static void setMessage(const string& title, const string& text, + static void setMessage(string_view title, string_view text, bool yesNo = false); - static void setMessage(const string& title, const StringList& text, + static void setMessage(string_view title, const StringList& text, bool yesNo = false); bool confirmed() { return myConfirmed; } diff --git a/src/gui/MessageMenu.cxx b/src/gui/MessageMenu.cxx index 4e6560e9c..21a80ec59 100644 --- a/src/gui/MessageMenu.cxx +++ b/src/gui/MessageMenu.cxx @@ -44,14 +44,14 @@ Dialog* MessageMenu::baseDialog() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void MessageMenu::setMessage(const string& title, const StringList& text, +void MessageMenu::setMessage(string_view title, const StringList& text, bool yesNo) { MessageDialog::setMessage(title, text, yesNo); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void MessageMenu::setMessage(const string& title, const string& text, bool yesNo) +void MessageMenu::setMessage(string_view title, string_view text, bool yesNo) { MessageDialog::setMessage(title, text, yesNo); } diff --git a/src/gui/MessageMenu.hxx b/src/gui/MessageMenu.hxx index a7d817f81..23c72cde4 100644 --- a/src/gui/MessageMenu.hxx +++ b/src/gui/MessageMenu.hxx @@ -37,9 +37,9 @@ class MessageMenu : public DialogContainer explicit MessageMenu(OSystem& osystem); ~MessageMenu() override; - static void setMessage(const string& title, const string& text, + static void setMessage(string_view title, string_view text, bool yesNo = false); - static void setMessage(const string& title, const StringList& text, + static void setMessage(string_view title, const StringList& text, bool yesNo = false); bool confirmed(); diff --git a/src/gui/MinUICommandDialog.cxx b/src/gui/MinUICommandDialog.cxx index 2520cb4e3..2caa37fe7 100644 --- a/src/gui/MinUICommandDialog.cxx +++ b/src/gui/MinUICommandDialog.cxx @@ -53,7 +53,7 @@ MinUICommandDialog::MinUICommandDialog(OSystem& osystem, DialogContainer& parent WidgetArray wid; int xoffset = HBORDER, yoffset = VBORDER + _th; - const auto ADD_CD_BUTTON = [&](const string& label, int cmd) + const auto ADD_CD_BUTTON = [&](string_view label, int cmd) { auto* b = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); diff --git a/src/gui/NavigationWidget.cxx b/src/gui/NavigationWidget.cxx index 75dcf6c99..931b4652b 100644 --- a/src/gui/NavigationWidget.cxx +++ b/src/gui/NavigationWidget.cxx @@ -153,7 +153,7 @@ NavigationWidget::PathWidget::PathWidget(GuiObject* boss, CommandReceiver* targe } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void NavigationWidget::PathWidget::setPath(const string& path) +void NavigationWidget::PathWidget::setPath(string_view path) { if(path == myLastPath) return; @@ -240,7 +240,7 @@ const string& NavigationWidget::PathWidget::getPath(int idx) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NavigationWidget::PathWidget::FolderLinkWidget::FolderLinkWidget( GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& text, const string& path) + int x, int y, int w, int h, string_view text, string_view path) : ButtonWidget(boss, font, x, y, w, h, text, kFolderClicked), myPath{path} { diff --git a/src/gui/NavigationWidget.hxx b/src/gui/NavigationWidget.hxx index 072562a1b..af425771b 100644 --- a/src/gui/NavigationWidget.hxx +++ b/src/gui/NavigationWidget.hxx @@ -41,11 +41,11 @@ class NavigationWidget : public Widget { public: FolderLinkWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& text, const string& path); + int x, int y, int w, int h, string_view text, string_view path); ~FolderLinkWidget() override = default; - void setPath(const string& path) { myPath = path; } - const string& getPath() const { return myPath; } + void setPath(string_view path) { myPath = path; } + const string& getPath() const { return myPath; } private: void drawWidget(bool hilite) override; @@ -67,7 +67,7 @@ class NavigationWidget : public Widget const GUI::Font& font, int x, int y, int w, int h); ~PathWidget() override = default; - void setPath(const string& path); + void setPath(string_view path); const string& getPath(int idx) const; private: diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 9d1040839..552c0e0a8 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -78,7 +78,7 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, _h += rowHeight + VGAP * 2; } - const auto ADD_OD_BUTTON = [&](const string& label, int cmd) + const auto ADD_OD_BUTTON = [&](string_view label, int cmd) { auto* bw = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); diff --git a/src/gui/PopUpWidget.cxx b/src/gui/PopUpWidget.cxx index c52751408..9bd9cd30e 100644 --- a/src/gui/PopUpWidget.cxx +++ b/src/gui/PopUpWidget.cxx @@ -27,7 +27,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PopUpWidget::PopUpWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, const VariantList& items, - const string& label, int labelWidth, int cmd) + string_view label, int labelWidth, int cmd) : EditableWidget(boss, font, x, y - 1, w, h + 2), _label{label}, _labelWidth{labelWidth} @@ -124,7 +124,7 @@ const string& PopUpWidget::getSelectedName() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PopUpWidget::setSelectedName(const string& name) +void PopUpWidget::setSelectedName(string_view name) { myMenu->setSelectedName(name); } diff --git a/src/gui/PopUpWidget.hxx b/src/gui/PopUpWidget.hxx index 79ad994e0..2c1c77fb0 100644 --- a/src/gui/PopUpWidget.hxx +++ b/src/gui/PopUpWidget.hxx @@ -38,7 +38,7 @@ class PopUpWidget : public EditableWidget public: PopUpWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, const VariantList& items, - const string& label = "", int labelWidth = 0, int cmd = 0); + string_view label = "", int labelWidth = 0, int cmd = 0); ~PopUpWidget() override = default; void setID(uInt32 id) override; @@ -61,7 +61,7 @@ class PopUpWidget : public EditableWidget int getSelected() const; const string& getSelectedName() const; - void setSelectedName(const string& name); + void setSelectedName(string_view name); const Variant& getSelectedTag() const; bool wantsFocus() const override { return true; } diff --git a/src/gui/ProgressDialog.cxx b/src/gui/ProgressDialog.cxx index 9d3aff65d..8bb74fc9a 100644 --- a/src/gui/ProgressDialog.cxx +++ b/src/gui/ProgressDialog.cxx @@ -28,7 +28,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font, - const string& message) + string_view message) : Dialog(boss->instance(), boss->parent(), font) { const int lineHeight = Dialog::lineHeight(), @@ -67,7 +67,7 @@ ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ProgressDialog::setMessage(const string& message) +void ProgressDialog::setMessage(string_view message) { const int buttonWidth = Dialog::buttonWidth("Cancel"), HBORDER = Dialog::hBorder(); diff --git a/src/gui/ProgressDialog.hxx b/src/gui/ProgressDialog.hxx index 45fdddab9..4e77ae69f 100644 --- a/src/gui/ProgressDialog.hxx +++ b/src/gui/ProgressDialog.hxx @@ -30,10 +30,10 @@ class ProgressDialog : public Dialog { public: ProgressDialog(GuiObject* boss, const GUI::Font& font, - const string& message = ""); + string_view message = ""); ~ProgressDialog() override = default; - void setMessage(const string& message); + void setMessage(string_view message); void setRange(int start, int finish, int step); void resetProgress(); void setProgress(int progress); diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index e3a0171c4..0d2860708 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -60,7 +60,7 @@ int TabWidget::getChildY() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int TabWidget::addTab(const string& title, int tabWidth) +int TabWidget::addTab(string_view title, int tabWidth) { // Add a new tab page const int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; diff --git a/src/gui/TabWidget.hxx b/src/gui/TabWidget.hxx index 21b692edf..35e91e37b 100644 --- a/src/gui/TabWidget.hxx +++ b/src/gui/TabWidget.hxx @@ -43,7 +43,7 @@ class TabWidget : public Widget, public CommandSender // First off, widget should allow non-dialog bosses, (i.e. also other widgets) // Could add a common base class for Widgets and Dialogs. // Then you add tabs using the following method, which returns a unique ID - int addTab(const string& title, int tabWidth = NO_WIDTH); + int addTab(string_view title, int tabWidth = NO_WIDTH); // Maybe we need to remove tabs again? Hm //void removeTab(int tabID); // Setting the active tab: @@ -82,9 +82,10 @@ class TabWidget : public Widget, public CommandSender bool enabled{true}; int tabWidth{0}; - explicit Tab(const string& t, int tw = NO_WIDTH, + explicit Tab(string_view t, int tw = NO_WIDTH, Widget* first = nullptr, Widget* parent = nullptr, bool e = true) - : title{t}, firstWidget{first}, parentWidget{parent}, enabled{e}, tabWidth{tw} { } + : title{t}, firstWidget{first}, parentWidget{parent}, enabled{e}, + tabWidth{tw} { } }; using TabList = vector; diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx index 0690aa889..8c98601c1 100644 --- a/src/gui/ToolTip.cxx +++ b/src/gui/ToolTip.cxx @@ -139,7 +139,7 @@ void ToolTip::release(bool emptyTip) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ToolTip::show(const string& tip) +void ToolTip::show(string_view tip) { myTipPos = myMousePos; @@ -153,7 +153,7 @@ void ToolTip::show(const string& tip) kTextColor))); // Calculate maximum width of drawn string lines uInt32 width = 0; - string inStr = tip; + string inStr{tip}; for(int i = 0; i < lines; ++i) { string leftStr, rightStr; diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx index f0e71b1fe..ff7196054 100644 --- a/src/gui/ToolTip.hxx +++ b/src/gui/ToolTip.hxx @@ -80,7 +80,7 @@ class ToolTip */ const shared_ptr& surface(); - void show(const string& tip); + void show(string_view tip); private: static constexpr uInt32 DELAY_TIME = 45; // display delay [frames] diff --git a/src/gui/UndoHandler.cxx b/src/gui/UndoHandler.cxx index 8c2e9882b..a0810074d 100644 --- a/src/gui/UndoHandler.cxx +++ b/src/gui/UndoHandler.cxx @@ -39,7 +39,7 @@ void UndoHandler::doChar() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool UndoHandler::endChars(const string& text) +bool UndoHandler::endChars(string_view text) { if(myCharMode) { @@ -51,7 +51,7 @@ bool UndoHandler::endChars(const string& text) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void UndoHandler::doo(const string& text) +void UndoHandler::doo(string_view text) { // clear redos for(; myRedoCount; myRedoCount--) @@ -62,7 +62,7 @@ void UndoHandler::doo(const string& text) myBuffer.pop_back(); // add text to buffer - myBuffer.push_front(text); + myBuffer.emplace_front(text); myCharMode = false; } @@ -91,7 +91,7 @@ bool UndoHandler::redo(string& text) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 UndoHandler::lastDiff(const string& text, const string& oldText) +uInt32 UndoHandler::lastDiff(string_view text, string_view oldText) { auto pos = static_cast(text.size()); diff --git a/src/gui/UndoHandler.hxx b/src/gui/UndoHandler.hxx index c1a964739..a16f981ad 100644 --- a/src/gui/UndoHandler.hxx +++ b/src/gui/UndoHandler.hxx @@ -15,7 +15,6 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ - #ifndef UNDO_HANDLER_HXX #define UNDO_HANDLER_HXX @@ -37,7 +36,7 @@ class UndoHandler void reset(); // Add input to undo buffer - void doo(const string& text); + void doo(string_view text); // Retrieve last input from undo buffer bool undo(string& text); // Retrieve next input from undo buffer @@ -46,10 +45,10 @@ class UndoHandler // Add single char for aggregation void doChar(); // Add aggregated single chars to undo buffer - bool endChars(const string& text); + bool endChars(string_view text); // Get index into text of last different character - static uInt32 lastDiff(const string& text, const string& oldText); + static uInt32 lastDiff(string_view text, string_view oldText); private: std::deque myBuffer; diff --git a/src/gui/WhatsNewDialog.cxx b/src/gui/WhatsNewDialog.cxx index 3fa5b8832..872cb9b7b 100644 --- a/src/gui/WhatsNewDialog.cxx +++ b/src/gui/WhatsNewDialog.cxx @@ -45,7 +45,7 @@ WhatsNewDialog::WhatsNewDialog(OSystem& osystem, DialogContainer& parent, setSize(MAX_CHARS * fontWidth + HBORDER * 2, max_h, max_w, max_h); - const string& version = instance().settings().getString("stella.version"); + const string_view version = instance().settings().getString("stella.version"); #ifdef RETRON77 add(ypos, "extensively redesigned and enhanced file launcher"); add(ypos, "improved controller mappings for Paddles"); @@ -90,13 +90,13 @@ WhatsNewDialog::WhatsNewDialog(OSystem& osystem, DialogContainer& parent, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void WhatsNewDialog::add(int& ypos, const string& text) +void WhatsNewDialog::add(int& ypos, string_view text) { const int lineHeight = Dialog::lineHeight(), fontHeight = Dialog::fontHeight(), HBORDER = Dialog::hBorder(); - const string DOT = "\x1f"; - string txt = DOT + " " + text; + string txt = "\x1f "; + txt += text; // automatically wrap too long texts while(txt.length() > MAX_CHARS) diff --git a/src/gui/WhatsNewDialog.hxx b/src/gui/WhatsNewDialog.hxx index ad25a4567..3f01241ff 100644 --- a/src/gui/WhatsNewDialog.hxx +++ b/src/gui/WhatsNewDialog.hxx @@ -28,7 +28,7 @@ class WhatsNewDialog : public Dialog ~WhatsNewDialog() override = default; private: - void add(int& ypos, const string& text); + void add(int& ypos, string_view text); private: // Following constructors and assignment operators not supported diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index 47bef00a1..f0aca5434 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -278,13 +278,13 @@ void Widget::setEnabled(bool e) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Widget::setToolTip(const string& text, Event::Type event1, EventMode mode) +void Widget::setToolTip(string_view text, Event::Type event1, EventMode mode) { setToolTip(text, event1, Event::Type::NoType, mode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Widget::setToolTip(const string& text, Event::Type event1, Event::Type event2, EventMode mode) +void Widget::setToolTip(string_view text, Event::Type event1, Event::Type event2, EventMode mode) { assert(text.length() <= ToolTip::MAX_LEN); @@ -352,7 +352,7 @@ bool Widget::hasToolTip() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Widget::setHelpAnchor(const string& helpAnchor, bool debugger) +void Widget::setHelpAnchor(string_view helpAnchor, bool debugger) { _helpAnchor = helpAnchor; _debuggerHelp = debugger; @@ -361,7 +361,7 @@ void Widget::setHelpAnchor(const string& helpAnchor, bool debugger) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Widget::setHelpURL(const string& helpURL) +void Widget::setHelpURL(string_view helpURL) { _helpURL = helpURL; @@ -528,7 +528,7 @@ void Widget::setDirtyInChain(Widget* start) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& text, TextAlign align, + string_view text, TextAlign align, ColorId shadowColor) : Widget(boss, font, x, y, w, h), CommandSender(boss), @@ -548,7 +548,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& text, TextAlign align, + string_view text, TextAlign align, ColorId shadowColor) : StaticTextWidget(boss, font, x, y, font.getStringWidth(text), font.getLineHeight(), text, align, shadowColor) @@ -562,7 +562,7 @@ void StaticTextWidget::setValue(int value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void StaticTextWidget::setLabel(const string& label) +void StaticTextWidget::setLabel(string_view label) { if(_label != label) { @@ -585,12 +585,12 @@ void StaticTextWidget::setLink(size_t start, int len, bool underline) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool StaticTextWidget::setUrl(const string& url, const string& label, - const string& placeHolder) +bool StaticTextWidget::setUrl(string_view url, string_view label, + string_view placeHolder) { #ifndef RETRON77 size_t start = string::npos, len = 0; - const string& text = label != EmptyString ? label : url; + const string_view text = label != EmptyString ? label : url; if(text != EmptyString) { @@ -692,7 +692,7 @@ void StaticTextWidget::drawWidget(bool hilite) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label, int cmd, bool repeat) + string_view label, int cmd, bool repeat) : StaticTextWidget(boss, font, x, y, w, h, label, TextAlign::Center), _repeat{repeat} { @@ -709,7 +709,7 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, - const string& label, int cmd, bool repeat) + string_view label, int cmd, bool repeat) : ButtonWidget(boss, font, x, y, font.getStringWidth(label) + dw, font.getLineHeight() + 4, label, cmd, repeat) { @@ -718,7 +718,7 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int cmd, bool repeat) + string_view label, int cmd, bool repeat) : ButtonWidget(boss, font, x, y, 20, label, cmd, repeat) { } @@ -751,7 +751,7 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, const GUI::Icon& icon, int bmx, - const string& label, + string_view label, int cmd, bool repeat) : ButtonWidget(boss, font, x, y, w + bmx * 1.5 + font.getStringWidth(label), h, label, cmd, repeat) @@ -857,7 +857,7 @@ void ButtonWidget::drawWidget(bool hilite) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheckboxWidget::CheckboxWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, const string& label, + int x, int y, string_view label, int cmd) : ButtonWidget(boss, font, x, y, font.getFontHeight() < 24 ? 16 : 24, font.getFontHeight() < 24 ? 16 : 24, label, cmd) @@ -1004,8 +1004,8 @@ void CheckboxWidget::drawWidget(bool hilite) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SliderWidget::SliderWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label, int labelWidth, int cmd, - int valueLabelWidth, const string& valueUnit, int valueLabelGap, + string_view label, int labelWidth, int cmd, + int valueLabelWidth, string_view valueUnit, int valueLabelGap, bool forceLabelSign) : ButtonWidget(boss, font, x, y, w, h, label, cmd), _labelWidth{labelWidth}, @@ -1032,8 +1032,8 @@ SliderWidget::SliderWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SliderWidget::SliderWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int labelWidth, int cmd, - int valueLabelWidth, const string& valueUnit, int valueLabelGap, + string_view label, int labelWidth, int cmd, + int valueLabelWidth, string_view valueUnit, int valueLabelGap, bool forceLabelSign) : SliderWidget(boss, font, x, y, font.getMaxCharWidth() * 10, font.getLineHeight(), label, labelWidth, cmd, valueLabelWidth, valueUnit, valueLabelGap, @@ -1079,7 +1079,7 @@ void SliderWidget::setStepValue(int value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SliderWidget::setValueLabel(const string& valueLabel) +void SliderWidget::setValueLabel(string_view valueLabel) { _valueLabel = valueLabel; setDirty(); @@ -1093,7 +1093,7 @@ void SliderWidget::setValueLabel(int value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SliderWidget::setValueUnit(const string& valueUnit) +void SliderWidget::setValueUnit(string_view valueUnit) { _valueUnit = valueUnit; setDirty(); diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 9b7c21ae9..14d1e3af5 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -114,9 +114,9 @@ class Widget : public GuiObject void setBGColorHi(ColorId color) { _bgcolorhi = color; setDirty(); } void setShadowColor(ColorId color) { _shadowcolor = color; setDirty(); } - void setToolTip(const string& text, + void setToolTip(string_view text, Event::Type event1 = Event::Type::NoType, EventMode = EventMode::kEmulationMode); - void setToolTip(const string& text, + void setToolTip(string_view text, Event::Type event1, Event::Type event2, EventMode = EventMode::kEmulationMode); void setToolTip(Event::Type event1, EventMode mode = EventMode::kEmulationMode); void setToolTip(Event::Type event1, Event::Type event2, @@ -125,8 +125,8 @@ class Widget : public GuiObject virtual bool changedToolTip(const Common::Point& oldPos, const Common::Point& newPos) const { return false; } - void setHelpAnchor(const string& helpAnchor, bool debugger = false); - void setHelpURL(const string& helpURL); + void setHelpAnchor(string_view helpAnchor, bool debugger = false); + void setHelpURL(string_view helpURL); virtual void loadConfig() { } @@ -212,25 +212,25 @@ class StaticTextWidget : public Widget, public CommandSender public: StaticTextWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& text = "", TextAlign align = TextAlign::Left, + string_view text = "", TextAlign align = TextAlign::Left, ColorId shadowColor = kNone); StaticTextWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& text = "", TextAlign align = TextAlign::Left, + string_view text = "", TextAlign align = TextAlign::Left, ColorId shadowColor = kNone); ~StaticTextWidget() override = default; void setCmd(int cmd) { _cmd = cmd; } virtual void setValue(int value); - void setLabel(const string& label); + void setLabel(string_view label); void setAlign(TextAlign align) { _align = align; setDirty(); } const string& getLabel() const { return _label; } bool isEditable() const { return _editable; } void setLink(size_t start = string::npos, int len = 0, bool underline = false); - bool setUrl(const string& url = EmptyString, const string& label = EmptyString, - const string& placeHolder = EmptyString); + bool setUrl(string_view url = EmptyString, string_view label = EmptyString, + string_view placeHolder = EmptyString); const string& getUrl() const { return _url; } protected: @@ -265,13 +265,13 @@ class ButtonWidget : public StaticTextWidget public: ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label, int cmd = 0, bool repeat = false); + string_view label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, - const string& label, int cmd = 0, bool repeat = false); + string_view label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int cmd = 0, bool repeat = false); + string_view label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, int dh, const uInt32* bitmap, int bmw, int bmh, @@ -283,7 +283,7 @@ class ButtonWidget : public StaticTextWidget ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, const GUI::Icon& icon, int bmx, - const string& label, + string_view label, int cmd = 0, bool repeat= false); ~ButtonWidget() override = default; @@ -327,7 +327,7 @@ class CheckboxWidget : public ButtonWidget public: CheckboxWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int cmd = 0); + string_view label, int cmd = 0); ~CheckboxWidget() override = default; void setEditable(bool editable); @@ -380,13 +380,13 @@ class SliderWidget : public ButtonWidget public: SliderWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label = "", int labelWidth = 0, int cmd = 0, - int valueLabelWidth = 0, const string& valueUnit = "", + string_view label = "", int labelWidth = 0, int cmd = 0, + int valueLabelWidth = 0, string_view valueUnit = "", int valueLabelGap = 0, bool forceLabelSign = false); SliderWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label = "", int labelWidth = 0, int cmd = 0, - int valueLabelWidth = 0, const string& valueUnit = "", + string_view label = "", int labelWidth = 0, int cmd = 0, + int valueLabelWidth = 0, string_view valueUnit = "", int valueLabelGap = 0, bool forceLabelSign = false); ~SliderWidget() override = default; @@ -399,10 +399,10 @@ class SliderWidget : public ButtonWidget int getMaxValue() const { return _valueMax; } void setStepValue(int value); int getStepValue() const { return _stepValue; } - void setValueLabel(const string& valueLabel); + void setValueLabel(string_view valueLabel); void setValueLabel(int value); const string& getValueLabel() const { return _valueLabel; } - void setValueUnit(const string& valueUnit); + void setValueUnit(string_view valueUnit); void setTickmarkIntervals(int numIntervals); diff --git a/src/os/libretro/FBBackendLIBRETRO.hxx b/src/os/libretro/FBBackendLIBRETRO.hxx index 8b05cae87..5cdea0fd9 100644 --- a/src/os/libretro/FBBackendLIBRETRO.hxx +++ b/src/os/libretro/FBBackendLIBRETRO.hxx @@ -93,7 +93,7 @@ class FBBackendLIBRETRO : public FBBackend int scaleX(int x) const override { return x; } int scaleY(int y) const override { return y; } - void setTitle(const string&) override { } + void setTitle(string_view) override { } void showCursor(bool) override { } bool fullScreen() const override { return true; } void getRGB(uInt32, uInt8*, uInt8*, uInt8*) const override { } diff --git a/src/os/libretro/FSNodeLIBRETRO.cxx b/src/os/libretro/FSNodeLIBRETRO.cxx index 195ba6509..80ae00134 100644 --- a/src/os/libretro/FSNodeLIBRETRO.cxx +++ b/src/os/libretro/FSNodeLIBRETRO.cxx @@ -33,7 +33,7 @@ FSNodeLIBRETRO::FSNodeLIBRETRO() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNodeLIBRETRO::FSNodeLIBRETRO(const string& p) +FSNodeLIBRETRO::FSNodeLIBRETRO(string_view p) : _name{p}, _path{p} { @@ -80,7 +80,7 @@ bool FSNodeLIBRETRO::makeDir() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FSNodeLIBRETRO::rename(const string& newfile) +bool FSNodeLIBRETRO::rename(string_view newfile) { return false; } diff --git a/src/os/libretro/FSNodeLIBRETRO.hxx b/src/os/libretro/FSNodeLIBRETRO.hxx index dcf7f3963..961ffce5b 100644 --- a/src/os/libretro/FSNodeLIBRETRO.hxx +++ b/src/os/libretro/FSNodeLIBRETRO.hxx @@ -31,11 +31,11 @@ class FSNodeLIBRETRO : public AbstractFSNode public: FSNodeLIBRETRO(); - explicit FSNodeLIBRETRO(const string& path); + explicit FSNodeLIBRETRO(string_view path); bool exists() const override; - const string& getName() const override { return _name; } - void setName(const string& name) override { _name = name; } + const string& getName() const override { return _name; } + void setName(string_view name) override { _name = name; } const string& getPath() const override { return _path; } string getShortPath() const override; bool hasParent() const override { return false; } @@ -44,7 +44,7 @@ class FSNodeLIBRETRO : public AbstractFSNode bool isReadable() const override; bool isWritable() const override; bool makeDir() override; - bool rename(const string& newfile) override; + bool rename(string_view newfile) override; bool getChildren(AbstractFSList& list, ListMode mode) const override; AbstractFSNodePtr getParent() const override; diff --git a/src/os/libretro/OSystemLIBRETRO.hxx b/src/os/libretro/OSystemLIBRETRO.hxx index 3e03ccf9e..e6324cb96 100644 --- a/src/os/libretro/OSystemLIBRETRO.hxx +++ b/src/os/libretro/OSystemLIBRETRO.hxx @@ -57,7 +57,7 @@ class OSystemLIBRETRO : public OSystem they are free to ignore it */ void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override + bool useappdir, string_view usedir) override { basedir = homedir = "." + slash; } diff --git a/src/os/macos/OSystemMACOS.cxx b/src/os/macos/OSystemMACOS.cxx index 4d40e8ecd..1c7451554 100644 --- a/src/os/macos/OSystemMACOS.cxx +++ b/src/os/macos/OSystemMACOS.cxx @@ -20,7 +20,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemMACOS::getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) + bool useappdir, string_view usedir) { basedir = "~/Library/Application Support/Stella/"; diff --git a/src/os/macos/OSystemMACOS.hxx b/src/os/macos/OSystemMACOS.hxx index 493b01a57..33d961ea5 100644 --- a/src/os/macos/OSystemMACOS.hxx +++ b/src/os/macos/OSystemMACOS.hxx @@ -47,7 +47,7 @@ class OSystemMACOS : public OSystemStandalone they are free to ignore it */ void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override; + bool useappdir, string_view usedir) override; private: // Following constructors and assignment operators not supported diff --git a/src/os/unix/FSNodePOSIX.cxx b/src/os/unix/FSNodePOSIX.cxx index 59639e65c..499405f20 100644 --- a/src/os/unix/FSNodePOSIX.cxx +++ b/src/os/unix/FSNodePOSIX.cxx @@ -31,7 +31,7 @@ FSNodePOSIX::FSNodePOSIX() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNodePOSIX::FSNodePOSIX(const string& path, bool verify) +FSNodePOSIX::FSNodePOSIX(string_view path, bool verify) : _path{path.length() > 0 ? path : "~"} // Default to home directory { // Expand '~' to the HOME environment variable @@ -203,9 +203,9 @@ bool FSNodePOSIX::makeDir() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FSNodePOSIX::rename(const string& newfile) +bool FSNodePOSIX::rename(string_view newfile) { - if (std::rename(_path.c_str(), newfile.c_str()) == 0) + if (std::rename(_path.c_str(), string{newfile}.c_str()) == 0) { _path = newfile; diff --git a/src/os/unix/FSNodePOSIX.hxx b/src/os/unix/FSNodePOSIX.hxx index a10611167..7ac34e100 100644 --- a/src/os/unix/FSNodePOSIX.hxx +++ b/src/os/unix/FSNodePOSIX.hxx @@ -58,11 +58,11 @@ class FSNodePOSIX : public AbstractFSNode * @param verify true if the isValid and isDirectory/isFile flags should * be verified during the construction. */ - explicit FSNodePOSIX(const string& path, bool verify = true); + explicit FSNodePOSIX(string_view path, bool verify = true); bool exists() const override { return access(_path.c_str(), F_OK) == 0; } - const string& getName() const override { return _displayName; } - void setName(const string& name) override { _displayName = name; } + const string& getName() const override { return _displayName; } + void setName(string_view name) override { _displayName = name; } const string& getPath() const override { return _path; } string getShortPath() const override; bool isDirectory() const override { return _isDirectory; } @@ -70,7 +70,7 @@ class FSNodePOSIX : public AbstractFSNode bool isReadable() const override { return access(_path.c_str(), R_OK) == 0; } bool isWritable() const override { return access(_path.c_str(), W_OK) == 0; } bool makeDir() override; - bool rename(const string& newfile) override; + bool rename(string_view newfile) override; size_t getSize() const override; bool hasParent() const override; diff --git a/src/os/unix/OSystemUNIX.cxx b/src/os/unix/OSystemUNIX.cxx index 91409c2ae..b3d376447 100644 --- a/src/os/unix/OSystemUNIX.cxx +++ b/src/os/unix/OSystemUNIX.cxx @@ -23,7 +23,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemUNIX::getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) + bool useappdir, string_view usedir) { // Use XDG_CONFIG_HOME if defined, otherwise use the default const char* const cfg_home = std::getenv("XDG_CONFIG_HOME"); // NOLINT diff --git a/src/os/unix/OSystemUNIX.hxx b/src/os/unix/OSystemUNIX.hxx index 30cbf2a05..39294062c 100644 --- a/src/os/unix/OSystemUNIX.hxx +++ b/src/os/unix/OSystemUNIX.hxx @@ -47,7 +47,7 @@ class OSystemUNIX : public OSystemStandalone they are free to ignore it */ void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override; + bool useappdir, string_view usedir) override; private: // Following constructors and assignment operators not supported diff --git a/src/os/windows/FSNodeWINDOWS.cxx b/src/os/windows/FSNodeWINDOWS.cxx index 57e878bff..9563a7298 100644 --- a/src/os/windows/FSNodeWINDOWS.cxx +++ b/src/os/windows/FSNodeWINDOWS.cxx @@ -26,7 +26,7 @@ #include "FSNodeWINDOWS.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNodeWINDOWS::FSNodeWINDOWS(const string& p) +FSNodeWINDOWS::FSNodeWINDOWS(string_view p) : _path{p.length() > 0 ? p : "~"} // Default to home directory { // Expand '~' to the users 'home' directory @@ -217,9 +217,9 @@ bool FSNodeWINDOWS::makeDir() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FSNodeWINDOWS::rename(const string& newfile) +bool FSNodeWINDOWS::rename(string_view newfile) { - if (!_isPseudoRoot && MoveFile(_path.c_str(), newfile.c_str()) != 0) + if (!_isPseudoRoot && MoveFile(_path.c_str(), string{newfile}.c_str()) != 0) return setFlags(); return false; diff --git a/src/os/windows/FSNodeWINDOWS.hxx b/src/os/windows/FSNodeWINDOWS.hxx index 12980caab..d080f094a 100644 --- a/src/os/windows/FSNodeWINDOWS.hxx +++ b/src/os/windows/FSNodeWINDOWS.hxx @@ -50,11 +50,11 @@ class FSNodeWINDOWS : public AbstractFSNode * * @param path String with the path the new node should point to. */ - explicit FSNodeWINDOWS(const string& path); + explicit FSNodeWINDOWS(string_view path); bool exists() const override; - const string& getName() const override { return _displayName; } - void setName(const string& name) override { _displayName = name; } + const string& getName() const override { return _displayName; } + void setName(string_view name) override { _displayName = name; } const string& getPath() const override { return _path; } string getShortPath() const override; bool isDirectory() const override { return _isDirectory; } @@ -62,7 +62,7 @@ class FSNodeWINDOWS : public AbstractFSNode bool isReadable() const override; bool isWritable() const override; bool makeDir() override; - bool rename(const string& newfile) override; + bool rename(string_view newfile) override; size_t getSize() const override; bool hasParent() const override { return !_isPseudoRoot; } diff --git a/src/os/windows/OSystemWINDOWS.cxx b/src/os/windows/OSystemWINDOWS.cxx index 8e33e9b0f..20a3664b9 100644 --- a/src/os/windows/OSystemWINDOWS.cxx +++ b/src/os/windows/OSystemWINDOWS.cxx @@ -23,7 +23,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemWINDOWS::getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) + bool useappdir, string_view usedir) { HomeFinder homefinder; FSNode appdata(homefinder.getAppDataPath()); diff --git a/src/os/windows/OSystemWINDOWS.hxx b/src/os/windows/OSystemWINDOWS.hxx index 8336d07e9..5b329d270 100644 --- a/src/os/windows/OSystemWINDOWS.hxx +++ b/src/os/windows/OSystemWINDOWS.hxx @@ -47,7 +47,7 @@ class OSystemWINDOWS : public OSystemStandalone they are free to ignore it */ void getBaseDirectories(string& basedir, string& homedir, - bool useappdir, const string& usedir) override; + bool useappdir, string_view usedir) override; private: // Following constructors and assignment operators not supported