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) → {bool}
- 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, "illegal-state", "division by zero");to print a warning onstderrand stop the program ifx==0.aidesys::alert(x == 0, " illegal-state", "division by zero");to print a warning onstderrwithout 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.
generates a
|
||
message |
string | The message, a string format à-la printf with more parameters if used. |
||
parameters |
anything |
<optional> <repeatable> |
Any message parameters. |
Throws:
-
A
aide::exceptionstd::exception object// 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()); }- Note: A
numerical-errorcan NOT be catched in a simpletry { } catch( ) { }construct because it is raised by a SIGFPE signal, thus outside the main program flow, and it is strongly recommended to stop the execution after such an error, because the variable state is spurious. If it is really important to catch such an exception, the following construct is to be used:
try { CATCH_SIGFPE( x = std::numeric_limits < double > ::signaling_NaN(); // Considering signaling NaN values … y = x + 1; // … generates a floating-point invalid operation numerical-error as soon as used. ); } catch(std::exception& e) { // Some suitable action } - Note: A
- Type
- exception
Returns:
The condition true or false value, unless an exception occurs.
- Type
- bool
(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, what, delay) → {pid}
- Description:
Implements the execution of a runner in a child process.
- The function corresponds to setTimeout() and setInterval() javascript timing methods.
- Its implementation is quite straightforward and provides a very basic example of using the C/C++ fork mechanism.
- The method returns immediatly.
- The child process always exit with a '0' error code.
- All childs processes are properly killed when program stops.
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, using
wfork_kill(pid);
- Type
- pid
(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