More conversion of 'const char*' to string_view.

This commit is contained in:
Stephen Anthony 2022-12-21 19:24:37 -03:30
parent 60346c78cf
commit 1fa2e98988
14 changed files with 52 additions and 57 deletions

View File

@ -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;

View File

@ -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<int>(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();

View File

@ -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<png_bytep>& 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

View File

@ -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<int>(PaletteType::NumTypes)] = {
static constexpr std::array<string_view, PaletteType::NumTypes> 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<string_view, PaletteType::NumTypes> 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<int>(PaletteType::MinType), static_cast<int>(PaletteType::MaxType));
} while(type == PaletteType::User && !myUserPaletteDefined);
const string palette = toPaletteName(static_cast<PaletteType>(type));
const string message = MESSAGES[type] + " palette";
const string_view palette = toPaletteName(static_cast<PaletteType>(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 {

View File

@ -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<AdjustableTag, NUM_ADJUSTABLES> myAdjustables =

View File

@ -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};

View File

@ -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};

View File

@ -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"
};

View File

@ -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();

View File

@ -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;

View File

@ -52,7 +52,7 @@ class Settings
using Options = std::map<string, Variant, std::less<>>;
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:
/**

View File

@ -257,7 +257,8 @@ void TIASurface::changeScanlineIntensity(int direction)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TIASurface::ScanlineMask TIASurface::scanlineMaskType(int direction)
{
const string Masks[static_cast<int>(ScanlineMask::NumMasks)] = {
static constexpr
std::array<string_view, static_cast<int>(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<int>(ScanlineMask::NumMasks)] = {
static constexpr
std::array<string_view, static_cast<int>(ScanlineMask::NumMasks)> Names = {
"Standard",
"Thin lines",
"Pixelated",

View File

@ -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

View File

@ -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 */