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

Classes

class  Args
 Named-argument reader over the parsed JSON object. More...
struct  ArithSpec
 The arithmetic a call runs at: Real also carries the precision tier. More...
struct  DoubleOnly
 Wrap an Op whose registry entry lists Double ONLY. More...
struct  EncodeScalar
struct  EncodeScalar< double >
struct  EncodeScalar< Rational >
struct  EncodeScalar< Real< D > >
struct  NeedsTranscendental
 Wrap an Op whose registry entry lists Double and Real but NOT Exact. More...
struct  NumFromDecimal
struct  NumFromDecimal< double >
struct  NumFromDecimal< Rational >
struct  NumFromDecimal< Real< D > >

Typedefs

using Json = nlohmann::json
using Invoker = std::function<Json(const ArithSpec&, Args&)>
using DispatchTable = std::map<std::string, Invoker>
using LibraryOnlyTable = std::map<std::string, std::string>
 name -> why the function has no named-JSON-argument form.

Functions

ArithSpec parse_arith (const std::string &text)
 Parse –arith.
std::vector< std::string > api_exposed_functions ()
 Names exposed over this boundary, sorted; a subset of the registry.
bool api_is_exposed (const std::string &name)
 True when the named function has a dispatch entry.
std::map< std::string, std::string > api_library_only_functions ()
 Registered functions that can NEVER be carried by named JSON arguments, each with the reason (a callable argument, a random generator passed by reference, ...).
Json api_invoke (const std::string &name, const std::string &arith, const Json &args)
 Invoke one API function.
std::string api_render_readable (const Json &result)
 Human-readable rendering of the object api_invoke returns, for -o readable.
std::string shortest_decimal (double v)
 The shortest decimal literal that round-trips to v.
BigInt pow10_bigint (unsigned e)
Rational rational_from_decimal (const std::string &text)
 Exact value of a decimal literal, with no rounding anywhere: sign, digits, optional fraction and optional exponent are read symbolically and assembled as numerator over a power of ten.
double double_from_decimal (const std::string &text)
 double value of a decimal literal, including the "a/b" fraction form.
std::string decimal_text (const Json &j, const std::string &where)
 The decimal literal behind a JSON scalar, per the policy in the file header.
template<class T>
T number_from_json (const Json &j, const std::string &where)
template<class T>
Matrix< T > matrix_from_json (const Json &j, const std::string &where)
 A matrix from a JSON value: 2-D array as rows, 1-D array as a row vector, scalar as 1x1, empty array as the empty matrix.
template<class T>
std::vector< T > vector_from_json (const Json &j, const std::string &where)
 A flat numeric vector: 1-D array, or a 1-row / 1-column 2-D array.
std::vector< int > int_vector_from_json (const Json &j, const std::string &where)
 An integer vector; a non-integral entry is an error, never a truncation.
template<class T>
Json encode_scalar (const T &v)
template<class T>
Json encode_vector (const std::vector< T > &v)
template<class T>
Json encode_matrix (const Matrix< T > &m)
Json encode_ints (const std::vector< int > &v)
template<class T>
Json encode_matrices (const std::vector< Matrix< T > > &v)
 A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.
template<class T>
Json encode_vectors (const std::vector< std::vector< T > > &v)
 A list of vectors, the shape a per-class or per-segment result returns.
Json encode_count (std::size_t n)
 A count.
template<class Op>
Json run_at (const ArithSpec &s, Args &a)
 Run an operation at the selected arithmetic.
std::uint64_t required_seed (Args &a, const std::string &fn, const char *spelled="seed")
 The seed of a function whose port draws from a caller-owned generator.
template<class T>
Json encode_qsys_res (const qsys::QsysResT< T > &r)
 MATLAB's res struct of the exact queueing-system functions: one key per measure, in the reference's field order, scalars as scalars and row vectors as lists, plus analyzer.
qsys::QsysResOptions read_qsys_res_options (Args &a, bool with_nmax=true)
 The 'tPoints', 'percentiles' and 'nmax' options those functions share.
template<class Op>
Invoker make ()
const std::vector< void(*)(DispatchTable &)> & api_dispatch_registrars ()
const std::vector< void(*)(LibraryOnlyTable &)> & api_library_only_registrars ()
void register_api_mam (DispatchTable &t)
void register_library_only_mam (LibraryOnlyTable &t)
void register_api_mc (DispatchTable &t)
void register_library_only_mc (LibraryOnlyTable &t)
void register_api_misc (DispatchTable &t)
void register_library_only_misc (LibraryOnlyTable &t)
void register_api_pfqn_a (DispatchTable &t)
void register_library_only_pfqn_a (LibraryOnlyTable &t)
void register_api_pfqn_b (DispatchTable &t)
void register_library_only_pfqn_b (LibraryOnlyTable &t)
void register_api_qsys (DispatchTable &t)
void register_library_only_qsys (LibraryOnlyTable &t)
void register_api_trace (DispatchTable &t)
void register_library_only_trace (LibraryOnlyTable &t)

Typedef Documentation

◆ DispatchTable

using line::reg::DispatchTable = std::map<std::string, Invoker>

Definition at line 43 of file api_dispatch_detail.h.

◆ Invoker

using line::reg::Invoker = std::function<Json(const ArithSpec&, Args&)>

Definition at line 42 of file api_dispatch_detail.h.

◆ Json

using line::reg::Json = nlohmann::json

Definition at line 63 of file api_json.h.

◆ LibraryOnlyTable

using line::reg::LibraryOnlyTable = std::map<std::string, std::string>

name -> why the function has no named-JSON-argument form.

Definition at line 46 of file api_dispatch_detail.h.

Function Documentation

◆ api_dispatch_registrars()

const std::vector< void(*)(DispatchTable &)> & line::reg::api_dispatch_registrars ( )
inline

◆ api_exposed_functions()

std::vector< std::string > line::reg::api_exposed_functions ( )

Names exposed over this boundary, sorted; a subset of the registry.

Definition at line 3223 of file api_dispatch.cpp.

References api_exposed_functions().

Referenced by api_exposed_functions(), and api_invoke().

◆ api_invoke()

Json line::reg::api_invoke ( const std::string & name,
const std::string & arith,
const Json & args )

Invoke one API function.

Parameters
nameMATLAB function name, e.g. "pfqn_ca"
arithtext of –arith, e.g. "exact" or "real:50"
argsobject keyed by the MATLAB parameter names
Returns
{"function", "arith", "results"}, results keyed by the MATLAB output names and encoded per the policy in api_json.h
Exceptions
UnsupportedError,InputError,NumericError

Definition at line 3237 of file api_dispatch.cpp.

References api_exposed_functions(), api_invoke(), line::api_supports(), line::ApiEntry::arith, line::arith_name(), line::ApiEntry::domain, line::find_api(), parse_arith(), and line::UnsupportedError::UnsupportedError().

Referenced by api_invoke(), and run_invocation().

◆ api_is_exposed()

bool line::reg::api_is_exposed ( const std::string & name)

True when the named function has a dispatch entry.

Definition at line 3233 of file api_dispatch.cpp.

References api_is_exposed().

Referenced by api_is_exposed().

◆ api_library_only_functions()

std::map< std::string, std::string > line::reg::api_library_only_functions ( )

Registered functions that can NEVER be carried by named JSON arguments, each with the reason (a callable argument, a random generator passed by reference, ...).

api_invoke refuses them with that reason. Together with api_exposed_functions() and the model-level sn/lqn domains this partitions the registry, and a test holds it to that.

Definition at line 3229 of file api_dispatch.cpp.

References api_library_only_functions().

Referenced by api_library_only_functions().

◆ api_library_only_registrars()

◆ api_render_readable()

std::string line::reg::api_render_readable ( const Json & result)

Human-readable rendering of the object api_invoke returns, for -o readable.

Definition at line 3335 of file api_dispatch.cpp.

References api_render_readable().

Referenced by api_render_readable(), and run_invocation().

◆ decimal_text()

std::string line::reg::decimal_text ( const Json & j,
const std::string & where )
inline

The decimal literal behind a JSON scalar, per the policy in the file header.

Definition at line 199 of file api_json.h.

References decimal_text(), line::InputError::InputError(), and shortest_decimal().

Referenced by decimal_text(), int_vector_from_json(), and number_from_json().

◆ double_from_decimal()

double line::reg::double_from_decimal ( const std::string & text)
inline

double value of a decimal literal, including the "a/b" fraction form.

Definition at line 154 of file api_json.h.

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

Referenced by double_from_decimal(), line::reg::NumFromDecimal< double >::parse(), and line::reg::NumFromDecimal< Real< D > >::parse().

◆ encode_count()

Json line::reg::encode_count ( std::size_t n)
inline

A count.

Written as a plain JSON integer at every arithmetic: an iteration count or a dimension is exact in all of them, so wrapping it in the {"double",...} envelope the scalars use would suggest a precision question that a cardinal number does not have.

Definition at line 378 of file api_json.h.

References encode_count().

Referenced by encode_count().

◆ encode_ints()

Json line::reg::encode_ints ( const std::vector< int > & v)
inline

Definition at line 350 of file api_json.h.

References encode_ints().

Referenced by encode_ints().

◆ encode_matrices()

template<class T>
Json line::reg::encode_matrices ( const std::vector< Matrix< T > > & v)

A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.

Definition at line 358 of file api_json.h.

References encode_matrices(), and encode_matrix().

Referenced by encode_matrices().

◆ encode_matrix()

template<class T>
Json line::reg::encode_matrix ( const Matrix< T > & m)

◆ encode_qsys_res()

template<class T>
Json line::reg::encode_qsys_res ( const qsys::QsysResT< T > & r)

MATLAB's res struct of the exact queueing-system functions: one key per measure, in the reference's field order, scalars as scalars and row vectors as lists, plus analyzer.

Definition at line 138 of file api_dispatch_detail.h.

References line::qsys::QsysResT< T >::analyzer, encode_qsys_res(), encode_scalar(), encode_vector(), line::qsys::QsysResT< T >::fields, line::qsys::QsysResFieldT< T >::name, line::qsys::QsysResFieldT< T >::scalar, and line::qsys::QsysResFieldT< T >::value.

Referenced by encode_qsys_res().

◆ encode_scalar()

template<class T>
Json line::reg::encode_scalar ( const T & v)

Definition at line 328 of file api_json.h.

References encode_scalar().

Referenced by encode_matrix(), encode_qsys_res(), encode_scalar(), and encode_vector().

◆ encode_vector()

template<class T>
Json line::reg::encode_vector ( const std::vector< T > & v)

Definition at line 333 of file api_json.h.

References encode_scalar(), and encode_vector().

Referenced by encode_qsys_res(), encode_vector(), and encode_vectors().

◆ encode_vectors()

template<class T>
Json line::reg::encode_vectors ( const std::vector< std::vector< T > > & v)

A list of vectors, the shape a per-class or per-segment result returns.

Definition at line 366 of file api_json.h.

References encode_vector(), and encode_vectors().

Referenced by encode_vectors().

◆ int_vector_from_json()

std::vector< int > line::reg::int_vector_from_json ( const Json & j,
const std::string & where )
inline

◆ make()

template<class Op>
Invoker line::reg::make ( )

◆ matrix_from_json()

template<class T>
Matrix< T > line::reg::matrix_from_json ( const Json & j,
const std::string & where )

A matrix from a JSON value: 2-D array as rows, 1-D array as a row vector, scalar as 1x1, empty array as the empty matrix.

Ragged rows are an error.

Definition at line 223 of file api_json.h.

References line::InputError::InputError(), line::Matrix< T >::Matrix(), matrix_from_json(), and number_from_json().

Referenced by line::reg::Args::matrices(), line::reg::Args::matrix(), matrix_from_json(), line::reg::Args::matrix_or_empty(), and vector_from_json().

◆ number_from_json()

template<class T>
T line::reg::number_from_json ( const Json & j,
const std::string & where )

◆ parse_arith()

ArithSpec line::reg::parse_arith ( const std::string & text)

Parse –arith.

Accepts "double", "exact" and "real:<digits>"; anything else is an InputError listing the accepted forms. The port instantiates the high-precision backend at three fixed tiers (50, 100, 200 digits), so a request between tiers is rounded UP to the next one – never down, so a caller never silently receives less precision than asked – and str() reports the tier actually used. Above 200 digits the call is refused.

Definition at line 206 of file api_dispatch.cpp.

References line::reg::ArithSpec::digits, line::Double, line::Exact, line::InputError::InputError(), line::reg::ArithSpec::mode, parse_arith(), line::Real, and line::UnsupportedError::UnsupportedError().

Referenced by api_invoke(), parse_arith(), and run_invocation().

◆ pow10_bigint()

BigInt line::reg::pow10_bigint ( unsigned e)
inline

Definition at line 86 of file api_json.h.

References pow10_bigint().

Referenced by pow10_bigint(), and rational_from_decimal().

◆ rational_from_decimal()

Rational line::reg::rational_from_decimal ( const std::string & text)
inline

Exact value of a decimal literal, with no rounding anywhere: sign, digits, optional fraction and optional exponent are read symbolically and assembled as numerator over a power of ten.

Definition at line 97 of file api_json.h.

References line::InputError::InputError(), pow10_bigint(), and rational_from_decimal().

Referenced by int_vector_from_json(), line::reg::NumFromDecimal< Rational >::parse(), and rational_from_decimal().

◆ read_qsys_res_options()

qsys::QsysResOptions line::reg::read_qsys_res_options ( Args & a,
bool with_nmax = true )
inline

◆ register_api_mam()

void line::reg::register_api_mam ( DispatchTable & t)

Definition at line 2096 of file api_dispatch_mam.cpp.

References make(), and register_api_mam().

Referenced by api_dispatch_registrars(), and register_api_mam().

◆ register_api_mc()

void line::reg::register_api_mc ( DispatchTable & t)

Definition at line 1287 of file api_dispatch_mc.cpp.

References make(), and register_api_mc().

Referenced by api_dispatch_registrars(), and register_api_mc().

◆ register_api_misc()

void line::reg::register_api_misc ( DispatchTable & t)

Definition at line 2937 of file api_dispatch_misc.cpp.

References make(), and register_api_misc().

Referenced by api_dispatch_registrars(), and register_api_misc().

◆ register_api_pfqn_a()

void line::reg::register_api_pfqn_a ( DispatchTable & t)

Definition at line 1722 of file api_dispatch_pfqn_a.cpp.

References make(), and register_api_pfqn_a().

Referenced by api_dispatch_registrars(), and register_api_pfqn_a().

◆ register_api_pfqn_b()

void line::reg::register_api_pfqn_b ( DispatchTable & t)

Definition at line 2487 of file api_dispatch_pfqn_b.cpp.

References make(), and register_api_pfqn_b().

Referenced by api_dispatch_registrars(), and register_api_pfqn_b().

◆ register_api_qsys()

void line::reg::register_api_qsys ( DispatchTable & t)

Definition at line 2485 of file api_dispatch_qsys.cpp.

References make(), and register_api_qsys().

Referenced by api_dispatch_registrars(), and register_api_qsys().

◆ register_api_trace()

void line::reg::register_api_trace ( DispatchTable & t)

Definition at line 1452 of file api_dispatch_trace.cpp.

References make(), and register_api_trace().

Referenced by api_dispatch_registrars(), and register_api_trace().

◆ register_library_only_mam()

void line::reg::register_library_only_mam ( LibraryOnlyTable & t)

◆ register_library_only_mc()

void line::reg::register_library_only_mc ( LibraryOnlyTable & t)

◆ register_library_only_misc()

void line::reg::register_library_only_misc ( LibraryOnlyTable & t)

◆ register_library_only_pfqn_a()

void line::reg::register_library_only_pfqn_a ( LibraryOnlyTable & t)

◆ register_library_only_pfqn_b()

void line::reg::register_library_only_pfqn_b ( LibraryOnlyTable & t)

◆ register_library_only_qsys()

void line::reg::register_library_only_qsys ( LibraryOnlyTable & t)

◆ register_library_only_trace()

void line::reg::register_library_only_trace ( LibraryOnlyTable & t)

◆ required_seed()

std::uint64_t line::reg::required_seed ( Args & a,
const std::string & fn,
const char * spelled = "seed" )
inline

The seed of a function whose port draws from a caller-owned generator.

REQUIRED, NEVER DEFAULTED. The MATLAB reference falls back to the session's global RNG state, which has no JSON form; a silent default seed would make every call that forgot it return the same "random" draw and look like an answer. So the caller names the stream, and the same seed reproduces the same result at the same arithmetic (lossn_mci set the convention).

Definition at line 125 of file api_dispatch_detail.h.

References line::reg::Args::count(), line::reg::Args::has(), line::InputError::InputError(), and required_seed().

Referenced by required_seed().

◆ run_at()

template<class Op>
Json line::reg::run_at ( const ArithSpec & s,
Args & a )

Run an operation at the selected arithmetic.

Op is a struct with a static member template run<T>(Args&) returning the results object; the arithmetic gate against the registry has already passed when this is reached, so every branch here is a mode the function genuinely supports.

Definition at line 55 of file api_dispatch_detail.h.

References line::reg::ArithSpec::digits, line::Double, line::Exact, line::InputError::InputError(), line::reg::ArithSpec::mode, line::Real, and run_at().

Referenced by make(), and run_at().

◆ shortest_decimal()

std::string line::reg::shortest_decimal ( double v)
inline

The shortest decimal literal that round-trips to v.

nlohmann::json does not retain the text of a number, so this reconstructs the literal a human wrote: for every double that came from a short decimal in the file, the reconstruction IS that decimal, because a double has at most one shortest round-tripping representation.

Definition at line 76 of file api_json.h.

References shortest_decimal().

Referenced by decimal_text(), and shortest_decimal().

◆ vector_from_json()

template<class T>
std::vector< T > line::reg::vector_from_json ( const Json & j,
const std::string & where )