diff --git a/src/common/AudioSettings.hxx b/src/common/AudioSettings.hxx index 8ddd88142..61199da82 100644 --- a/src/common/AudioSettings.hxx +++ b/src/common/AudioSettings.hxx @@ -40,17 +40,17 @@ class AudioSettings lanczos_3 = 3 }; - static constexpr const char* SETTING_PRESET = "audio.preset"; - static constexpr const char* SETTING_SAMPLE_RATE = "audio.sample_rate"; - static constexpr const char* SETTING_FRAGMENT_SIZE = "audio.fragment_size"; - static constexpr const char* SETTING_BUFFER_SIZE = "audio.buffer_size"; - static constexpr const char* SETTING_HEADROOM = "audio.headroom"; - static constexpr const char* SETTING_RESAMPLING_QUALITY = "audio.resampling_quality"; - static constexpr const char* SETTING_STEREO = "audio.stereo"; - static constexpr const char* SETTING_VOLUME = "audio.volume"; - static constexpr const char* SETTING_DEVICE = "audio.device"; - static constexpr const char* SETTING_ENABLED = "audio.enabled"; - static constexpr const char* SETTING_DPC_PITCH = "audio.dpc_pitch"; + static constexpr string_view SETTING_PRESET = "audio.preset"; + static constexpr string_view SETTING_SAMPLE_RATE = "audio.sample_rate"; + static constexpr string_view SETTING_FRAGMENT_SIZE = "audio.fragment_size"; + static constexpr string_view SETTING_BUFFER_SIZE = "audio.buffer_size"; + static constexpr string_view SETTING_HEADROOM = "audio.headroom"; + static constexpr string_view SETTING_RESAMPLING_QUALITY = "audio.resampling_quality"; + static constexpr string_view SETTING_STEREO = "audio.stereo"; + static constexpr string_view SETTING_VOLUME = "audio.volume"; + static constexpr string_view SETTING_DEVICE = "audio.device"; + static constexpr string_view SETTING_ENABLED = "audio.enabled"; + static constexpr string_view SETTING_DPC_PITCH = "audio.dpc_pitch"; static constexpr Preset DEFAULT_PRESET = Preset::highQualityMediumLag; static constexpr uInt32 DEFAULT_SAMPLE_RATE = 44100; diff --git a/src/common/JPGLibrary.cxx b/src/common/JPGLibrary.cxx index ebeceedd2..4a84cf82b 100644 --- a/src/common/JPGLibrary.cxx +++ b/src/common/JPGLibrary.cxx @@ -36,14 +36,9 @@ JPGLibrary::JPGLibrary(OSystem& osystem) void JPGLibrary::loadImage(const string& filename, FBSurface& surface, VariantList& metaData) { - const auto loadImageERROR = [](const char* s) { - if(s) - throw runtime_error(s); - }; - std::ifstream in(filename, std::ios_base::binary | std::ios::ate); if(!in.is_open()) - loadImageERROR("No image found"); + throw runtime_error("No image found"); const size_t size = in.tellg(); in.clear(); in.seekg(0); @@ -52,10 +47,10 @@ void JPGLibrary::loadImage(const string& filename, FBSurface& surface, if(size > myFileBuffer.capacity()) myFileBuffer.reserve(size * 1.5); if(!in.read(myFileBuffer.data(), size)) - loadImageERROR("JPG image data reading failed"); + throw runtime_error("JPG image data reading failed"); if(njDecode(myFileBuffer.data(), static_cast(size))) - loadImageERROR("Error decoding the JPG image"); + throw runtime_error("Error decoding the JPG image"); // Read the entire image in one go myReadInfo.buffer = njGetImage(); diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index cd49155cf..da6b941b4 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -40,11 +40,10 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface, VariantLi png_uint_32 iwidth{0}, iheight{0}; int bit_depth{0}, color_type{0}, interlace_type{0}; - const auto loadImageERROR = [&](const char* s) { + const auto loadImageERROR = [&](string_view s) { if(png_ptr) png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : nullptr, nullptr); - if(s) - throw runtime_error(s); + throw runtime_error(string{s}); }; std::ifstream in(filename, std::ios_base::binary); @@ -186,11 +185,10 @@ void PNGLibrary::saveImageToDisk(std::ofstream& out, const vector& ro png_structp png_ptr{nullptr}; png_infop info_ptr{nullptr}; - const auto saveImageERROR = [&](const char* s) { + const auto saveImageERROR = [&](string_view s) { if(png_ptr) png_destroy_write_struct(&png_ptr, &info_ptr); - if(s) - throw runtime_error(s); + throw runtime_error(string{s}); }; // Create the PNG saving context structure diff --git a/src/common/PaletteHandler.cxx b/src/common/PaletteHandler.cxx index c2d133459..85b9c3f00 100644 --- a/src/common/PaletteHandler.cxx +++ b/src/common/PaletteHandler.cxx @@ -44,9 +44,9 @@ PaletteHandler::PaletteType PaletteHandler::toPaletteType(string_view name) cons } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string PaletteHandler::toPaletteName(PaletteType type) +string_view PaletteHandler::toPaletteName(PaletteType type) { - const string SETTING_NAMES[static_cast(PaletteType::NumTypes)] = { + static constexpr std::array SETTING_NAMES = { SETTING_STANDARD, SETTING_Z26, SETTING_USER, SETTING_CUSTOM }; @@ -56,7 +56,7 @@ string PaletteHandler::toPaletteName(PaletteType type) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PaletteHandler::cyclePalette(int direction) { - const string MESSAGES[PaletteType::NumTypes] = { + static constexpr std::array MESSAGES = { "Standard Stella", "Z26", "User-defined", "Custom" }; int type = toPaletteType(myOSystem.settings().getString("palette")); @@ -66,8 +66,8 @@ void PaletteHandler::cyclePalette(int direction) static_cast(PaletteType::MinType), static_cast(PaletteType::MaxType)); } while(type == PaletteType::User && !myUserPaletteDefined); - const string palette = toPaletteName(static_cast(type)); - const string message = MESSAGES[type] + " palette"; + const string_view palette = toPaletteName(static_cast(type)); + const string message = string{MESSAGES[type]} + " palette"; myOSystem.frameBuffer().showTextMessage(message); @@ -138,7 +138,8 @@ void PaletteHandler::showAdjustableMessage() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PaletteHandler::cycleAdjustable(int direction) { - const bool isCustomPalette = SETTING_CUSTOM == myOSystem.settings().getString("palette"); + const bool isCustomPalette = + SETTING_CUSTOM == myOSystem.settings().getString("palette"); bool isCustomAdj = false; do { diff --git a/src/common/PaletteHandler.hxx b/src/common/PaletteHandler.hxx index 2e4e082c4..396721c35 100644 --- a/src/common/PaletteHandler.hxx +++ b/src/common/PaletteHandler.hxx @@ -27,10 +27,10 @@ class PaletteHandler { public: // Setting names of palette types - static constexpr const char* SETTING_STANDARD = "standard"; - static constexpr const char* SETTING_Z26 = "z26"; - static constexpr const char* SETTING_USER = "user"; - static constexpr const char* SETTING_CUSTOM = "custom"; + static constexpr string_view SETTING_STANDARD = "standard"; + static constexpr string_view SETTING_Z26 = "z26"; + static constexpr string_view SETTING_USER = "user"; + static constexpr string_view SETTING_CUSTOM = "custom"; // Phase shift default and limits static constexpr float DEF_NTSC_SHIFT = 26.2F; @@ -187,7 +187,7 @@ class PaletteHandler @return The palette's settings name */ - static string toPaletteName(PaletteType type); + static string_view toPaletteName(PaletteType type); /** Display current adjustable with gauge bar message @@ -260,7 +260,7 @@ class PaletteHandler uInt32 myCurrentAdjustable{0}; struct AdjustableTag { - const char* const name{nullptr}; + string_view name; float* value{nullptr}; }; const std::array myAdjustables = diff --git a/src/common/tv_filters/NTSCFilter.hxx b/src/common/tv_filters/NTSCFilter.hxx index aec8454c2..8a61d5969 100644 --- a/src/common/tv_filters/NTSCFilter.hxx +++ b/src/common/tv_filters/NTSCFilter.hxx @@ -144,7 +144,7 @@ class NTSCFilter Preset myPreset{Preset::OFF}; struct AdjustableTag { - const char* const type{nullptr}; + string_view type; float* value{nullptr}; }; uInt32 myCurrentAdjustable{0}; diff --git a/src/debugger/DiStella.hxx b/src/debugger/DiStella.hxx index 9f842d700..dbaa16431 100644 --- a/src/debugger/DiStella.hxx +++ b/src/debugger/DiStella.hxx @@ -195,13 +195,11 @@ class DiStella Enumeration of the 6502 read/write mode (if the opcode is reading or writing its operand) */ - enum class RWMode : uInt8 - { - READ, WRITE, NONE - }; + enum class RWMode : uInt8 { READ, WRITE, NONE }; - struct Instruction_tag { - const char* const mnemonic{nullptr}; + struct Instruction_tag + { + string_view mnemonic; AddressingMode addr_mode{AddressingMode::IMPLIED}; AccessMode source{AccessMode::NONE}; RWMode rw_mode{RWMode::NONE}; diff --git a/src/emucore/KidVid.cxx b/src/emucore/KidVid.cxx index 99a2b71c6..a86c76aab 100644 --- a/src/emucore/KidVid.cxx +++ b/src/emucore/KidVid.cxx @@ -71,7 +71,8 @@ void KidVid::update() const uInt32 songLength = ourSongStart[temp + 1] - ourSongStart[temp] - (262 * ClickFrames); // Play the remaining WAV file - const string& fileName = myOSystem.baseDir().getPath() + ((temp < 10) ? "KVSHARED.WAV" : getFileName()); + const string& fileName = myOSystem.baseDir().getPath() + + ((temp < 10) ? "KVSHARED.WAV": getFileName()); myOSystem.sound().playWav(fileName, ourSongStart[temp] + (songLength - mySongLength), mySongLength); myContinueSong = false; @@ -118,7 +119,7 @@ void KidVid::update() if(myTape) { static constexpr uInt32 gameNumber[4] = { 3, 1, 2, 3 }; - static constexpr const char* const gameName[6] = { + static constexpr string_view gameName[6] = { "Harmony Smurf", "Handy Smurf", "Greedy Smurf", "Big Number Hunt", "Great Letter Roundup", "Spooky Spelling Bee" }; diff --git a/src/emucore/MT24LC256.hxx b/src/emucore/MT24LC256.hxx index 588ca3513..467e2a920 100644 --- a/src/emucore/MT24LC256.hxx +++ b/src/emucore/MT24LC256.hxx @@ -80,7 +80,7 @@ class MT24LC256 void jpee_data_stop(); void jpee_clock_fall(); bool jpee_timercheck(int mode); - void jpee_logproc(const char* const st) { cerr << " " << st << endl; } + void jpee_logproc(string_view st) { cerr << " " << st << endl; } void update(); diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 23a1779f0..4dbe633ed 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -526,7 +526,7 @@ string OSystem::createConsole(const FSNode& rom, string_view md5sum, bool newrom { // Make sure there always is an id constexpr int ID_LEN = 32; - const char* const HEX_DIGITS = "0123456789ABCDEF"; + constexpr string_view HEX_DIGITS{ "0123456789ABCDEF" }; char id_chr[ID_LEN] = { 0 }; const Random rnd; diff --git a/src/emucore/Settings.hxx b/src/emucore/Settings.hxx index 55cb0d97b..b15203f5d 100644 --- a/src/emucore/Settings.hxx +++ b/src/emucore/Settings.hxx @@ -52,7 +52,7 @@ class Settings using Options = std::map>; static constexpr int SETTINGS_VERSION = 1; - static constexpr const char* SETTINGS_VERSION_KEY = "settings.version"; + static constexpr string_view SETTINGS_VERSION_KEY = "settings.version"; public: /** diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index fa22228b9..f93ac5e4b 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -257,7 +257,8 @@ void TIASurface::changeScanlineIntensity(int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TIASurface::ScanlineMask TIASurface::scanlineMaskType(int direction) { - const string Masks[static_cast(ScanlineMask::NumMasks)] = { + static constexpr + std::array(ScanlineMask::NumMasks)> Masks = { SETTING_STANDARD, SETTING_THIN, SETTING_PIXELS, @@ -286,7 +287,8 @@ TIASurface::ScanlineMask TIASurface::scanlineMaskType(int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIASurface::cycleScanlineMask(int direction) { - const string Names[static_cast(ScanlineMask::NumMasks)] = { + static constexpr + std::array(ScanlineMask::NumMasks)> Names = { "Standard", "Thin lines", "Pixelated", diff --git a/src/emucore/TIASurface.hxx b/src/emucore/TIASurface.hxx index a8f58760f..dac1ed93e 100644 --- a/src/emucore/TIASurface.hxx +++ b/src/emucore/TIASurface.hxx @@ -46,11 +46,11 @@ class TIASurface { public: // Setting names of palette types - static constexpr const char* SETTING_STANDARD = "standard"; - static constexpr const char* SETTING_THIN = "thin"; - static constexpr const char* SETTING_PIXELS = "pixels"; - static constexpr const char* SETTING_APERTURE = "aperture"; - static constexpr const char* SETTING_MAME = "mame"; + static constexpr string_view SETTING_STANDARD = "standard"; + static constexpr string_view SETTING_THIN = "thin"; + static constexpr string_view SETTING_PIXELS = "pixels"; + static constexpr string_view SETTING_APERTURE = "aperture"; + static constexpr string_view SETTING_MAME = "mame"; /** Creates a new TIASurface object diff --git a/src/gui/Font.hxx b/src/gui/Font.hxx index 8661aa24e..75dff086b 100644 --- a/src/gui/Font.hxx +++ b/src/gui/Font.hxx @@ -35,7 +35,7 @@ struct BBX /* based on The Microwindows Project http://microwindows.org */ struct FontDesc { - const char* const name; /* font name */ + string_view name; /* font name */ int maxwidth; /* max width in pixels */ int height; /* height in pixels */ int fbbw, fbbh, fbbx, fbby; /* max bounding box */