util::string_view, update pgl for new sf semantics

This commit is contained in:
Michael Scire 2021-01-18 05:20:27 -08:00 committed by SciresM
parent 83c04fa5d7
commit 3bb94aa146
13 changed files with 448 additions and 70 deletions

View file

@ -24,17 +24,17 @@ namespace ams::ncm::impl {
}
bool PathView::HasPrefix(std::string_view prefix) const {
bool PathView::HasPrefix(util::string_view prefix) const {
return this->path.compare(0, prefix.length(), prefix) == 0;
}
bool PathView::HasSuffix(std::string_view suffix) const {
bool PathView::HasSuffix(util::string_view suffix) const {
return this->path.compare(this->path.length() - suffix.length(), suffix.length(), suffix) == 0;
}
std::string_view PathView::GetFileName() const {
util::string_view PathView::GetFileName() const {
auto pos = this->path.find_last_of("/");
return pos != std::string_view::npos ? this->path.substr(pos + 1) : this->path;
return pos != util::string_view::npos ? this->path.substr(pos + 1) : this->path;
}
MountName CreateUniqueMountName() {

View file

@ -22,12 +22,12 @@ namespace ams::ncm::impl {
class PathView {
private:
std::string_view path; /* Nintendo uses util::string_view here. */
util::string_view path; /* Nintendo uses util::string_view here. */
public:
PathView(std::string_view p) : path(p) { /* ...*/ }
bool HasPrefix(std::string_view prefix) const;
bool HasSuffix(std::string_view suffix) const;
std::string_view GetFileName() const;
PathView(util::string_view p) : path(p) { /* ...*/ }
bool HasPrefix(util::string_view prefix) const;
bool HasSuffix(util::string_view suffix) const;
util::string_view GetFileName() const;
};
struct MountName {

View file

@ -18,10 +18,7 @@
namespace ams::pgl::srv {
void Initialize(ShellInterface *interface, MemoryResource *mr) {
/* Set the memory resource for the interface. */
interface->Initialize(mr);
void Initialize() {
/* Enable extra application threads, if we should. */
u8 enable_application_extra_thread;
const size_t sz = settings::fwdbg::GetSettingsItemValue(std::addressof(enable_application_extra_thread), sizeof(enable_application_extra_thread), "application_extra_thread", "enable_application_extra_thread");

View file

@ -25,16 +25,16 @@ namespace ams::pgl::srv {
static_assert(sizeof(HostPackageMountName) - 1 <= fs::MountNameLengthMax);
struct CaseInsensitiveCharTraits : public std::char_traits<char> {
static char to_upper(char c) {
static constexpr char to_upper(char c) {
return std::toupper(static_cast<unsigned char>(c));
}
static bool eq(char c1, char c2) {
static constexpr bool eq(char c1, char c2) {
return to_upper(c1) == to_upper(c2);
}
static bool lt(char c1, char c2) {
static constexpr bool lt(char c1, char c2) {
return to_upper(c1) < to_upper(c2);
}
static int compare(const char *s1, const char *s2, size_t n) {
static constexpr int compare(const char *s1, const char *s2, size_t n) {
while ( n-- != 0 ) {
if ( to_upper(*s1) < to_upper(*s2) ) return -1;
if ( to_upper(*s1) > to_upper(*s2) ) return 1;
@ -42,7 +42,7 @@ namespace ams::pgl::srv {
}
return 0;
}
static const char *find(const char *s, int n, char a) {
static constexpr const char *find(const char *s, int n, char a) {
auto const ua (to_upper(a));
while ( n-- != 0 )
{
@ -54,7 +54,7 @@ namespace ams::pgl::srv {
}
};
using PathView = std::basic_string_view<char, CaseInsensitiveCharTraits>;
using PathView = util::basic_string_view<char, CaseInsensitiveCharTraits>;
enum class ExtensionType {
None = 0,

View file

@ -20,12 +20,6 @@
namespace ams::pgl::srv {
namespace {
using ShellEventObjectFactory = ams::sf::ObjectFactory<ams::sf::MemoryResourceAllocationPolicy>;
}
Result ShellInterface::LaunchProgram(ams::sf::Out<os::ProcessId> out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags) {
return pgl::srv::LaunchProgram(out.GetPointer(), loc, pm_flags, pgl_flags);
}
@ -76,7 +70,7 @@ namespace ams::pgl::srv {
Result ShellInterface::GetShellEventObserver(ams::sf::Out<ams::sf::SharedPointer<pgl::sf::IEventObserver>> out) {
/* Allocate a new interface. */
auto session = ShellEventObjectFactory::CreateSharedEmplaced<pgl::sf::IEventObserver, ShellEventObserver>(this->memory_resource);
auto session = ObjectFactory::CreateSharedEmplaced<pgl::sf::IEventObserver, ShellEventObserver>(m_allocator);
R_UNLESS(session != nullptr, pgl::ResultOutOfMemory());
*out = std::move(session);