LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line::util Namespace Reference

Classes

class  LineConsole
struct  ProcResult
 Outcome of a captured command. More...
class  TempDir

Enumerations

enum class  VerboseLevel { SILENT = 0 , STD = 1 , DEBUG = 2 }
 Session verbosity, the twin of MATLAB's VerboseLevel, jline.VerboseLevel and python's line_solver.constants.VerboseLevel. More...

Functions

std::string method_type (const std::string &solvername, const std::string &method)
 Banner classification of a solution method.
ProcResult capture (const std::vector< std::string > &argv, int timeoutSeconds, bool mergeStderr=false)
 Runs a command, capturing stdout and discarding stderr.
int run_inherit (const std::vector< std::string > &argv)
 Runs a command with the parent's stdout and stderr, e.g.
std::string trim (const std::string &s)
 Trims ASCII whitespace from both ends, as Java's String.trim() does.
std::string make_temp_dir (const std::string &prefix, bool mountable=false)
 Create a private scratch directory named after its caller.

Enumeration Type Documentation

◆ VerboseLevel

enum class line::util::VerboseLevel
strong

Session verbosity, the twin of MATLAB's VerboseLevel, jline.VerboseLevel and python's line_solver.constants.VerboseLevel.

The ordering matters and matches theirs: SILENT < STD < DEBUG.

This port had none until the console became DEBUG. A per-run bool verbose still travels with each solver's options and still means STD-or-SILENT; DEBUG is a SESSION level, because the console must also narrate the model compile, which happens before any solver options exist.

Enumerator
SILENT 
STD 
DEBUG 

Definition at line 57 of file line_console.h.

Function Documentation

◆ capture()

ProcResult line::util::capture ( const std::vector< std::string > & argv,
int timeoutSeconds,
bool mergeStderr = false )
inline

Runs a command, capturing stdout and discarding stderr.

mergeStderr sends the child's stderr down the SAME pipe instead, which is what MATLAB's [status, cmdout] = system(cmd) does and what a wrapper needs on the failure path: an external engine reports why it refused on stderr, and dropping it leaves the wrapper reporting an exit code and nothing else.

Parameters
argvthe command and its arguments, argv[0] resolved on PATH
timeoutSecondsdeadline; not positive waits indefinitely
mergeStderrcapture stderr too, interleaved with stdout
Returns
the exit code, the captured output and whether the deadline expired

Definition at line 82 of file subprocess.h.

References capture(), line::util::ProcResult::exitCode, line::util::ProcResult::out, and line::util::ProcResult::timedOut.

Referenced by capture(), line::io::docker_daemon_available(), line::io::docker_has_local_image(), line::qns::is_available(), line::jmt::jmt_run(), line::jmt::jmt_run_docker(), line::ldes::solver_ldes_text(), line::qns::solver_qns_run_analyzer(), and line::sym::sym_stop_container().

◆ make_temp_dir()

std::string line::util::make_temp_dir ( const std::string & prefix,
bool mountable = false )
inline

Create a private scratch directory named after its caller.

LINE_WORKSPACE_ROOT RELOCATES EVERY STAGED MODEL, exactly as it does in lineTempName.m, SysUtils.lineTempName and the native-Python wrappers. run-tests.sh sets it when it wraps lqns, lqsim or qnsolver in a container: the shim bind-mounts that root and nothing else, so a model left under TMPDIR is invisible to the binary, which then writes no result and is reported as having rejected the model. No wrapper here needs to know a container is involved.

mountable is the second argument of lineTempName: a snap-confined Docker daemon bind-mounts neither the system temp dir nor a dot-directory, so a caller that hands the directory to a container asks for a HOME-rooted one.

Parameters
prefixa short tag naming the caller, as lineTempName('qns') does
mountableroot under $HOME/.line rather than TMPDIR

Definition at line 84 of file tempdir.h.

References line::InputError::InputError(), and make_temp_dir().

Referenced by make_temp_dir(), and line::util::TempDir::TempDir().

◆ method_type()

std::string line::util::method_type ( const std::string & solvername,
const std::string & method )
inline

Banner classification of a solution method.

Lookup order: "<solver>.<method>", "<method>", the tail after each dot of the method (longest suffix first), the head before its first dot, "#<solver>", then "approximate,deterministic". The unknown-method default is the conservative one: claiming exactness a method does not have is the costlier error.

Parameters
solvernamebanner solver name, with or without the "Solver" prefix
methodresolved method label, possibly carrying a "default/" prefix

Definition at line 197 of file method_type.h.

References method_type().

Referenced by method_type().

◆ run_inherit()

int line::util::run_inherit ( const std::vector< std::string > & argv)
inline

Runs a command with the parent's stdout and stderr, e.g.

so a docker pull streams its progress. There is no deadline: a pull is long by nature and the user can see it working.

Parameters
argvthe command and its arguments
Returns
the exit code, or -1 if the command could not run

Definition at line 170 of file subprocess.h.

References run_inherit().

Referenced by line::io::docker_pull(), and run_inherit().

◆ trim()

std::string line::util::trim ( const std::string & s)
inline

Trims ASCII whitespace from both ends, as Java's String.trim() does.

Definition at line 181 of file subprocess.h.

References trim().

Referenced by line::io::docker_has_local_image(), line::ldes::solver_ldes_text(), line::sym::sym_resolve(), and trim().