1#ifndef SDL3PP_PROCESS_H_
2#define SDL3PP_PROCESS_H_
4#include <SDL3/SDL_process.h>
5#include "SDL3pp_iostream.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
89 SDL_PROCESS_STDIO_INHERITED;
93 SDL_PROCESS_STDIO_NULL;
291 auto data =
static_cast<char*
>(SDL_ReadProcess(
get(), &size, exitcode));
323 if (data.
empty())
return {};
324 size_t sz = data.
size() /
sizeof(T);
427 bool Wait(
bool block,
int* exitcode)
429 return SDL_WaitProcess(
get(), block, exitcode);
490 void reset(SDL_Process* newResource = {})
492 SDL_DestroyProcess(
release(newResource));
511 constexpr explicit Process(SDL_Process* resource = {})
516 constexpr Process(
const Process& other) =
delete;
538namespace prop::process {
540constexpr auto CREATE_ARGS_POINTER = SDL_PROP_PROCESS_CREATE_ARGS_POINTER;
542constexpr auto CREATE_ENVIRONMENT_POINTER =
543 SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER;
545constexpr auto CREATE_STDIN_NUMBER = SDL_PROP_PROCESS_CREATE_STDIN_NUMBER;
547constexpr auto CREATE_STDIN_POINTER = SDL_PROP_PROCESS_CREATE_STDIN_POINTER;
549constexpr auto CREATE_STDOUT_NUMBER = SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER;
551constexpr auto CREATE_STDOUT_POINTER = SDL_PROP_PROCESS_CREATE_STDOUT_POINTER;
553constexpr auto CREATE_STDERR_NUMBER = SDL_PROP_PROCESS_CREATE_STDERR_NUMBER;
555constexpr auto CREATE_STDERR_POINTER = SDL_PROP_PROCESS_CREATE_STDERR_POINTER;
557constexpr auto CREATE_STDERR_TO_STDOUT_BOOLEAN =
558 SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN;
560constexpr auto CREATE_BACKGROUND_BOOLEAN =
561 SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN;
563constexpr auto PID_NUMBER = SDL_PROP_PROCESS_PID_NUMBER;
565constexpr auto STDIN_POINTER = SDL_PROP_PROCESS_STDIN_POINTER;
567constexpr auto STDOUT_POINTER = SDL_PROP_PROCESS_STDOUT_POINTER;
569constexpr auto STDERR_POINTER = SDL_PROP_PROCESS_STDERR_POINTER;
571constexpr auto BACKGROUND_BOOLEAN = SDL_PROP_PROCESS_BACKGROUND_BOOLEAN;
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
constexpr bool empty() const
True if size() == 0.
Definition SDL3pp_ownPtr.h:70
T * release()
Release control on object.
Definition SDL3pp_ownPtr.h:87
constexpr size_t size() const
Size.
Definition SDL3pp_ownPtr.h:79
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Process * release(SDL_Process * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Process * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
SDL_ProcessIO ProcessIO
Description of where standard I/O should be directed when creating a process.
Definition SDL3pp_process.h:86
constexpr ProcessIO PROCESS_STDIO_APP
The I/O stream is connected to a new IOStreamBase that the application can read or write.
Definition SDL3pp_process.h:99
constexpr ProcessIO PROCESS_STDIO_NULL
The I/O stream is ignored.
Definition SDL3pp_process.h:92
constexpr ProcessIO PROCESS_STDIO_REDIRECT
The I/O stream is redirected to an existing IOStreamBase.
Definition SDL3pp_process.h:104
constexpr ProcessIO PROCESS_STDIO_INHERITED
The I/O stream is inherited from the application.
Definition SDL3pp_process.h:88
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Handle to a non owned iOStream.
Definition SDL3pp_iostream.h:1505
An opaque handle representing a system process.
Definition SDL3pp_process.h:119
IOStreamRef GetInput()
Get the IOStreamBase associated with process standard input.
Definition SDL3pp_process.h:351
OwnArray< T > ReadAs(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:320
ProcessBase(const char *const *args, bool pipe_stdio)
Create a new process.
Definition SDL3pp_process.h:162
StringResult Read(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:288
ProcessBase(PropertiesBase &props)
Create a new process with the specified properties.
Definition SDL3pp_process.h:227
void Kill(bool force)
Stop a process.
Definition SDL3pp_process.h:395
PropertiesRef GetProperties() const
Get the properties associated with a process.
Definition SDL3pp_process.h:259
bool Wait(bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:427
IOStreamRef GetOutput()
Get the IOStreamBase associated with process standard output.
Definition SDL3pp_process.h:374
Handle to a non owned process.
Definition SDL3pp_process.h:442
void reset(SDL_Process *newResource={})
Destroy a previously created process object.
Definition SDL3pp_process.h:490
ProcessRef & operator=(ProcessRef other)
Assignment operator.
Definition SDL3pp_process.h:469
constexpr ProcessRef(const ProcessRef &other)
Copy constructor.
Definition SDL3pp_process.h:448
constexpr ProcessRef(ProcessRef &&other)
Move constructor.
Definition SDL3pp_process.h:456
constexpr ~ProcessRef()=default
Default constructor.
Handle to an owned process.
Definition SDL3pp_process.h:505
constexpr Process(SDL_Process *resource={})
Constructs from the underlying resource.
Definition SDL3pp_process.h:511
constexpr Process(Process &&other)=default
Move constructor.
~Process()
Frees up resource when object goes out of scope.
Definition SDL3pp_process.h:526
Process & operator=(Process other)
Assignment operator.
Definition SDL3pp_process.h:531
Wrap properties id.
Definition SDL3pp_properties.h:203
Handle to a non owned properties.
Definition SDL3pp_properties.h:693
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:153