Some general code cleanup.

This commit is contained in:
Leon Styhre 2022-09-07 19:59:27 +02:00
parent 8361c4f15c
commit c537de51ef
8 changed files with 56 additions and 57 deletions

View file

@ -208,7 +208,7 @@ void thegamesdb_generate_json_scraper_requests(
std::string platformQueryParam;
auto& platforms = params.system->getPlatformIds();
if (!platforms.empty()) {
bool first = true;
bool first {true};
platformQueryParam += "&filter%5Bplatform%5D=";
for (auto platformIt = platforms.cbegin(); // Line break.
platformIt != platforms.cend(); ++platformIt) {
@ -243,7 +243,7 @@ void thegamesdb_generate_json_scraper_requests(
{
resources.prepare();
std::string path = "https://api.thegamesdb.net/v1";
const std::string apiKey = std::string("apikey=") + resources.getApiKey();
const std::string apiKey {std::string("apikey=") + resources.getApiKey()};
path += "/Games/Images/GamesImages?" + apiKey + "&games_id=" + gameIDs;
@ -285,7 +285,7 @@ namespace
return "";
std::string out = "";
bool first = true;
bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_developers_map.find(getIntOrThrow(v[i]));
@ -306,8 +306,8 @@ namespace
if (!v.IsArray())
return "";
std::string out = "";
bool first = true;
std::string out;
bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_publishers_map.find(getIntOrThrow(v[i]));
@ -328,8 +328,8 @@ namespace
if (!v.IsArray())
return "";
std::string out = "";
bool first = true;
std::string out;
bool first {true};
for (int i = 0; i < static_cast<int>(v.Size()); ++i) {
auto mapIt = resources.gamesdb_new_genres_map.find(getIntOrThrow(v[i]));
@ -416,7 +416,7 @@ void processMediaURLs(const Value& images,
// Step through each game ID in the JSON server response.
for (auto it = images.MemberBegin(); it != images.MemberEnd(); ++it) {
result.gameID = it->name.GetString();
const Value& gameMedia = images[it->name];
const Value& gameMedia {images[it->name]};
result.coverUrl = "";
result.fanartUrl = "";
result.marqueeUrl = "";
@ -469,8 +469,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
doc.Parse(req->getContent().c_str());
if (doc.HasParseError()) {
std::string err = std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") +
GetParseError_En(doc.GetParseError());
std::string err {std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") +
GetParseError_En(doc.GetParseError())};
setError(err);
LOG(LogError) << err;
return;
@ -480,8 +480,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
if (doc.HasMember("data") && doc["data"].HasMember("images") &&
doc["data"]["images"].IsObject()) {
const Value& images = doc["data"]["images"];
const Value& base_url = doc["data"]["base_url"];
const Value& images {doc["data"]["images"]};
const Value& base_url {doc["data"]["base_url"]};
std::string baseImageUrlLarge;
if (base_url.HasMember("large") && base_url["large"].IsString()) {
@ -520,7 +520,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
return;
}
const Value& games = doc["data"]["games"];
const Value& games {doc["data"]["games"]};
resources.ensureResources();
for (int i = 0; i < static_cast<int>(games.Size()); ++i) {

View file

@ -55,7 +55,7 @@ namespace
void ensureScrapersResourcesDir()
{
std::string path = getScrapersResouceDir();
std::string path {getScrapersResouceDir()};
if (!Utils::FileSystem::exists(path))
Utils::FileSystem::createDirectory(path);
}
@ -146,7 +146,7 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req,
ensureScrapersResourcesDir();
std::ofstream fout(file_name);
std::ofstream fout {file_name};
fout << req->getContent();
fout.close();
loadResource(resource, resource_name, file_name);
@ -155,9 +155,8 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req,
std::unique_ptr<HttpReq> TheGamesDBJSONRequestResources::fetchResource(const std::string& endpoint)
{
std::string path = "https://api.thegamesdb.net/v1";
path += endpoint;
path += "?apikey=" + getApiKey();
std::string path {"https://api.thegamesdb.net/v1"};
path.append(endpoint).append("?apikey=").append(getApiKey());
return std::unique_ptr<HttpReq>(new HttpReq(path));
}
@ -166,7 +165,7 @@ int TheGamesDBJSONRequestResources::loadResource(std::unordered_map<int, std::st
const std::string& resource_name,
const std::string& file_name)
{
std::ifstream fin(file_name);
std::ifstream fin {file_name};
if (!fin.good())
return 1;

View file

@ -174,8 +174,8 @@ void GuiComponent::sortChildren()
const int GuiComponent::getChildIndex() const
{
std::vector<GuiComponent*>::iterator it =
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this);
std::vector<GuiComponent*>::iterator it {
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this)};
if (it != getParent()->mChildren.end())
return static_cast<int>(std::distance(getParent()->mChildren.begin(), it));
@ -250,7 +250,7 @@ void GuiComponent::setAnimation(Animation* anim,
{
assert(slot < MAX_ANIMATIONS);
AnimationController* oldAnim = mAnimationMap[slot];
AnimationController* oldAnim {mAnimationMap[slot]};
mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse);
if (oldAnim)
@ -340,7 +340,7 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
getParent()->getSize() :
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}};
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "");
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")};
if (!elem)
return;

View file

@ -82,7 +82,7 @@ HttpReq::HttpReq(const std::string& url)
}
// Set the url.
CURLcode err = curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str());
CURLcode err {curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str())};
if (err != CURLE_OK) {
mStatus = REQ_IO_ERROR;
onError(curl_easy_strerror(err));
@ -176,7 +176,7 @@ HttpReq::~HttpReq()
if (mHandle) {
s_requests.erase(mHandle);
CURLMcode merr = curl_multi_remove_handle(s_multi_handle, mHandle);
CURLMcode merr {curl_multi_remove_handle(s_multi_handle, mHandle)};
if (merr != CURLM_OK) {
LOG(LogError) << "Error removing curl_easy handle from curl_multi: "
@ -191,7 +191,7 @@ HttpReq::Status HttpReq::status()
{
if (mStatus == REQ_IN_PROGRESS) {
int handle_count;
CURLMcode merr = curl_multi_perform(s_multi_handle, &handle_count);
CURLMcode merr {curl_multi_perform(s_multi_handle, &handle_count)};
if (merr != CURLM_OK && merr != CURLM_CALL_MULTI_PERFORM) {
mStatus = REQ_IO_ERROR;
onError(curl_multi_strerror(merr));
@ -238,7 +238,7 @@ std::string HttpReq::getContent() const
// Return value is number of elements successfully read.
size_t HttpReq::write_content(void* buff, size_t size, size_t nmemb, void* req_ptr)
{
std::stringstream& ss = (static_cast<HttpReq*>(req_ptr))->mContent;
std::stringstream& ss {static_cast<HttpReq*>(req_ptr)->mContent};
ss.write(static_cast<char*>(buff), size * nmemb);
return nmemb;

View file

@ -41,26 +41,26 @@ namespace ThemeFlags
// These are only the most common flags shared accross multiple components, in addition
// to these there are many component-specific options.
enum PropertyFlags : unsigned int {
PATH = 0x00000001,
POSITION = 0x00000002,
SIZE = 0x00000004,
ORIGIN = 0x00000008,
COLOR = 0x00000010,
FONT_PATH = 0x00000020,
FONT_SIZE = 0x00000040,
ALIGNMENT = 0x00000080,
TEXT = 0x00000100,
METADATA = 0x00000200,
LETTER_CASE = 0x00000400,
PATH = 0x00000001,
POSITION = 0x00000002,
SIZE = 0x00000004,
ORIGIN = 0x00000008,
COLOR = 0x00000010,
FONT_PATH = 0x00000020,
FONT_SIZE = 0x00000040,
ALIGNMENT = 0x00000080,
TEXT = 0x00000100,
METADATA = 0x00000200,
LETTER_CASE = 0x00000400,
FORCE_UPPERCASE = 0x00000800, // For backward compatibility with legacy themes.
LINE_SPACING = 0x00001000,
DELAY = 0x00002000,
Z_INDEX = 0x00004000,
ROTATION = 0x00008000,
OPACITY = 0x00010000,
SATURATION = 0x00020000,
VISIBLE = 0x00040000,
ALL = 0xFFFFFFFF
LINE_SPACING = 0x00001000,
DELAY = 0x00002000,
Z_INDEX = 0x00004000,
ROTATION = 0x00008000,
OPACITY = 0x00010000,
SATURATION = 0x00020000,
VISIBLE = 0x00040000,
ALL = 0xFFFFFFFF
};
// clang-format on
} // namespace ThemeFlags

View file

@ -101,7 +101,7 @@ void FlexboxComponent::computeLayout()
mItemsPerLine = static_cast<unsigned int>(mItems.size());
}
glm::vec2 grid {};
glm::vec2 grid {0.0f, 0.0f};
if (mDirection == "row")
grid = {mItemsPerLine, mLines};

View file

@ -46,8 +46,8 @@ LottieAnimComponent::LottieAnimComponent()
glm::clamp(Settings::getInstance()->getInt("LottieMaxFileCache"), 0, 1024) * 1024 * 1024);
// Keep total cache size within 0 to 4096 MiB.
int maxTotalCache =
glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) * 1024 * 1024;
int maxTotalCache {glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) *
1024 * 1024};
if (mMaxTotalFrameCache != static_cast<size_t>(maxTotalCache))
mMaxTotalFrameCache = static_cast<size_t>(maxTotalCache);
@ -161,7 +161,7 @@ void LottieAnimComponent::setAnimation(const std::string& path)
}
// Some statistics for the file.
double duration = mAnimation->duration();
double duration {mAnimation->duration()};
mTotalFrames = mAnimation->totalFrame();
mFrameRate = mAnimation->frameRate();
mFrameSize = width * height * 4;
@ -229,7 +229,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")};
if (elem->has("size")) {
glm::vec2 size = elem->get<glm::vec2>("size");
glm::vec2 size {elem->get<glm::vec2>("size")};
if (size.x == 0.0f && size.y == 0.0f) {
LOG(LogWarning)
<< "LottieAnimComponent: Invalid theme configuration, <size> defined as \""
@ -411,7 +411,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
// to the texture caching used for images.
if (mCacheFrames && mLastRenderedFrame != -1 &&
mFrameCache.find(mLastRenderedFrame) == mFrameCache.end()) {
size_t newCacheSize = mCacheSize + mFrameSize;
size_t newCacheSize {mCacheSize + mFrameSize};
if (newCacheSize < mMaxCacheSize &&
mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) {
mFrameCache[mLastRenderedFrame] = mPictureRGBA;

View file

@ -42,15 +42,15 @@ public:
// clang-format off
enum Shader {
CORE = 0x00000001,
CORE = 0x00000001,
BLUR_HORIZONTAL = 0x00000002,
BLUR_VERTICAL = 0x00000004,
SCANLINES = 0x00000008
BLUR_VERTICAL = 0x00000004,
SCANLINES = 0x00000008
};
enum ShaderFlags {
BGRA_TO_RGBA = 0x00000001,
FONT_TEXTURE = 0x00000002,
BGRA_TO_RGBA = 0x00000001,
FONT_TEXTURE = 0x00000002,
POST_PROCESSING = 0x00000004,
CLIPPING = 0x00000008
};