Changeset View
Changeset View
Standalone View
Standalone View
source/ps/GameSetup/CmdLineArgs.cpp
/* Copyright (C) 2022 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | |||||||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | |||||||||
* | * | |||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | |||||||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | |||||||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | |||||||||
* (at your option) any later version. | * (at your option) any later version. | |||||||||
* | * | |||||||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | |||||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||||||
* GNU General Public License for more details. | * GNU General Public License for more details. | |||||||||
* | * | |||||||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||||||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||||||
*/ | */ | |||||||||
#include "precompiled.h" | #include "precompiled.h" | |||||||||
#include "CmdLineArgs.h" | #include "CmdLineArgs.h" | |||||||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | |||||||||
#include "scriptinterface/Object.h" | ||||||||||
#include "scriptinterface/ScriptConversions.h" | ||||||||||
#include <algorithm> | #include <algorithm> | |||||||||
#include <iterator> | #include <iterator> | |||||||||
#include <string_view> | #include <string_view> | |||||||||
#include <unordered_map> | ||||||||||
CmdLineArgs g_CmdLineArgs; | CmdLineArgs g_CmdLineArgs; | |||||||||
vladislavbelov: Before system includes. | ||||||||||
namespace | namespace | |||||||||
{ | { | |||||||||
// Simple matcher for elements of the arguments container. | // Simple matcher for elements of the arguments container. | |||||||||
class IsKeyEqualTo | class IsKeyEqualTo | |||||||||
{ | { | |||||||||
public: | public: | |||||||||
IsKeyEqualTo(const CStr& value) : m_Value(value) {} | IsKeyEqualTo(const CStr& value) : m_Value(value) {} | |||||||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | ||||||||||
{ | { | |||||||||
return m_Arg0; | return m_Arg0; | |||||||||
} | } | |||||||||
std::vector<CStr> CmdLineArgs::GetArgsWithoutName() const | std::vector<CStr> CmdLineArgs::GetArgsWithoutName() const | |||||||||
{ | { | |||||||||
return m_ArgsWithoutName; | return m_ArgsWithoutName; | |||||||||
} | } | |||||||||
template<> void Script::ToJSVal<CmdLineArgs>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CmdLineArgs& val) | ||||||||||
Done Inline ActionsUseless space. vladislavbelov: Useless space. | ||||||||||
{ | ||||||||||
if (!Script::CreateObject(rq, ret)) | ||||||||||
return; | ||||||||||
std::unordered_map<CStr, std::vector<CStr>> args; | ||||||||||
phositUnsubmitted Not Done Inline Actionsstd::unordered_map and as the mapped_type an std::vector... sounds like it should be a std::unordered_multimap. phosit: `std::unordered_map` and as the `mapped_type` an `std::vector`... sounds like it should be a… | ||||||||||
wraitiiAuthorUnsubmitted Done Inline ActionsNot really worth doing when we can use our existing conversion tools for map/vector. Furthermore it maps better to the JS objects. wraitii: Not really worth doing when we can use our existing conversion tools for map/vector. | ||||||||||
for (const std::pair<CStr, CStr>& arg : val.m_Args) | ||||||||||
Done Inline Actionst is not a descriptive name. vladislavbelov: `t` is not a descriptive name. | ||||||||||
args.emplace(arg.first, std::vector<CStr>{}).first->second.emplace_back(arg.second); | ||||||||||
JS::RootedValue argVal(rq.cx); | ||||||||||
for (const decltype(args)::value_type& arg : args) | ||||||||||
phositUnsubmitted Not Done Inline Actions
decltype isn't more readable then auto. phosit: `decltype` isn't more readable then `auto`. | ||||||||||
wraitiiAuthorUnsubmitted Done Inline ActionsArguable but I'd agree wraitii: Arguable but I'd agree | ||||||||||
{ | ||||||||||
if (arg.second.size() == 1) | ||||||||||
{ | ||||||||||
if (arg.second[0].empty()) | ||||||||||
argVal = JS::UndefinedHandleValue; | ||||||||||
else | ||||||||||
Script::ToJSVal(rq, &argVal, arg.second[0]); | ||||||||||
Script::SetProperty(rq, ret, arg.first.c_str(), argVal); | ||||||||||
} | ||||||||||
else | ||||||||||
{ | ||||||||||
Script::ToJSVal(rq, &argVal, arg.second); | ||||||||||
Script::SetProperty(rq, ret, arg.first.c_str(), argVal); | ||||||||||
} | ||||||||||
} | ||||||||||
} |
Wildfire Games · Phabricator
Before system includes.