Core: Add initial process support (Process::SpawnDetached)

This commit is contained in:
SirLynix
2024-01-22 23:17:12 +01:00
committed by Jérôme Leclercq
parent 278e59934b
commit ac1422c221
13 changed files with 575 additions and 6 deletions

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_PROCESS_HPP
#define NAZARA_CORE_PROCESS_HPP
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp>
#include <NazaraUtils/Result.hpp>
#include <filesystem>
#include <span>
#include <string>
namespace Nz
{
using Pid = UInt32;
class NAZARA_CORE_API Process
{
public:
Process() = default;
Process(const Process&) = delete;
Process(Process&&) = delete;
~Process() = default;
Process& operator=(const Process&) = delete;
Process& operator=(Process&&) = delete;
static Result<Pid, std::string> SpawnDetached(const std::filesystem::path& program, std::span<const std::string> arguments = {}, const std::filesystem::path& workingDirectory = {}); };
}
#include <Nazara/Core/Process.inl>
#endif // NAZARA_CORE_PROCESS_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -36,6 +36,7 @@ namespace Nz
inline bool IsNumber(std::string_view str);
NAZARA_CORE_API void IterateOnCodepoints(std::string_view str, FunctionRef<bool(std::u32string_view characters)> callback);
NAZARA_CORE_API void IterateOnWideChars(std::string_view str, FunctionRef<bool(std::wstring_view characters)> callback);
NAZARA_CORE_API bool MatchPattern(std::string_view str, std::string_view pattern);
@@ -43,7 +44,9 @@ namespace Nz
NAZARA_CORE_API std::string PointerToString(const void* ptr);
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to);
template<typename T> std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, T from, T to);
template<typename T> std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, const T* from, const T* to);
template<typename T> std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, std::basic_string_view<T> from, std::basic_string_view<T> to);
inline bool StartsWith(std::string_view str, std::string_view s);
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, CaseIndependent);

View File

@@ -77,11 +77,28 @@ namespace Nz
return str;
}
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to)
template<typename T>
std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, T from, T to)
{
if (str.empty())
return str;
std::size_t startPos = 0;
while ((startPos = str.find(from, startPos)) != std::string::npos)
{
str[startPos] = to;
startPos++;
}
return str;
}
template<typename T>
std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, const T* from, const T* to)
{
return ReplaceStr(str, std::basic_string_view<T>(from), std::basic_string_view<T>(to));
}
template<typename T>
std::basic_string<T>& ReplaceStr(std::basic_string<T>& str, std::basic_string_view<T> from, std::basic_string_view<T> to)
{
std::size_t startPos = 0;
while ((startPos = str.find(from, startPos)) != std::string::npos)
{