factory std
- Description:
Specifies standard functions of string formating, assertion verification and program line argument.
- These functions are accessible via the
aidesys::
prefix.
- These functions are accessible via the
Methods
(static) echo(message, …parameters) → {string}
- Description:
Returns a formatted message à-la printf.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string | The message, a string format à-la printf with more parameters if used. |
|
parameters |
anything |
<repeatable> |
Any message parameters. |
Returns:
The formated message.
- Type
- string
(static) alert(conditionopt, thrown, message, …parametersopt)
- Description:
Checks a condition at run-time and throws a fatal error exception and/or dumps a warning if not verified. Examples:
aidesys::alert(x == 0, "numerical-error", "division by zero");
to print a warning onstderr
and stop the program ifx==0
.aidesys::alert(x == 0, " numerical-error", "division by zero");
to print a warning onstderr
without stopping the program.aidesys::alert(verbose, "", "using aidesys::alert at %.0f", aidesys::now());
to simply echo a message if verbose.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
condition |
bool |
<optional> |
true
|
If the condition is true, an alert is issued. |
thrown |
string | The name of the thrown exception if the alert is raised.
|
||
message |
string | The message, a string format à-la printf with more parameters if used. |
||
parameters |
anything |
<optional> <repeatable> |
Any message parameters. |
Throws:
-
A
aide::exception
std::exception object- The
what()
method returns"$thrown:$message"
concatenating the expection label and related message.
// For instance the following construct catches a potential exception and reformulates the message:
try { aidesys::regexReplace(string, parseInput, parseOutput); } catch(std::exception& e) { aidesys::alert(true, "illegal-argument", "in symboling::RecordType::RecordType bad regex syntax: '%s'", e.what()); }
- The
- Type
- exception
Returns:
The condition value, unless an exception occurs.
(static) argv() → {Array.<string>}
- Description:
Returns the program command line.
- Corresponds to the
int main(int argc, const char *argv[])
parameters. - On OS not supporting the "/proc/" pseudo-filesystem (i.e., MasOS or Windows) the following construct must be used:
int main(int argc, const char *argv[]) { aidesys::argv(argc, argv); // main routine code }
- Corresponds to the
Returns:
A const std::vector<std::string>
with the program command line arguments.
- Type
- Array.<string>
(static) system(command, nolineopt, timeoutopt) → {string}
- Description:
Executes a system command and returns the stdout.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
command |
string | The command to execute. The command path must be absolute (e.g. /bin/pwd not pwd). |
||
noline |
bool |
<optional> |
false
|
If true replaces new lines and spaces by a unique space. |
timeout |
uint |
<optional> |
0
|
Optional timeout in milliseconds. |
Returns:
The command result, or an error message.
- Type
- string
(static) wfork(runner, timeoutopt, statusopt) → {string}
- Description:
Implements the execution of a runner in a child process, returning the stdout.
- The function is called with prefix
aidesys::wfork(·)
. - Typical usage:
struct MyClass { // Runner returned status unsigned int status; // Here the runner is an instance method, with some parameter. int runner(String name) { cout << "Hello " + name + "!"; return 0; } // Calls the runner in a child process with timeout std::string run(String name, unsigned int timeout) { // The lambda construction allows to use it capturing the related parameters. return aidesys::wfork([this, name]() { return runner(name); }, timeout, &status); ../..
- The function is called with prefix
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
runner |
function | A |
||
timeout |
uint |
<optional> |
0
|
An optional timeout value, in millisecond. No timeout if the value is |
status |
uint |
<optional> |
NULL
|
An optional
|
Returns:
The runner process sdtout.
- The method returns after the runner process ends or is on timeout.
- Type
- string
(static) wfork(runner, what, delay) → {pid}
- Description:
Implements the execution of a runner in a child process.
- The function corresponds to setTimeout() and setInterval() javascript timing methods.
Parameters:
Name | Type | Description |
---|---|---|
runner |
function | A |
what |
char | Either:
|
delay |
uint | The timeout or interval delay in millisecond. |
Returns:
The runner process pid:
- It allows to send a signal to the child process, such as
kill(timer_pid, SIGKILL);
(using#include <signal.h>
). - The method returns immediatly.
- The child process always exit with a '0' error code.
- Type
- pid