LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
api_dispatch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_REG_API_DISPATCH_H
6#define LINE_REG_API_DISPATCH_H
7
8/**
9 * @file
10 * @ingroup line_reg
11 * Direct invocation of a single API function from named JSON arguments.
12 *
13 * This is the entry point behind the CLI's --api flag and the one a pybind11
14 * or MEX gateway should call, so that all hosts share one dispatch table and
15 * one conversion policy (include/line/reg/api_json.h).
16 *
17 * Three refusals, all explicit and all by name, because the port is
18 * incremental and a caller must never be able to mistake "not wired" for a
19 * result:
20 * - a name absent from the registry is not ported to C++ at all;
21 * - a name in the registry but not in the dispatch table is ported and
22 * tested but not yet exposed over this boundary;
23 * - an arithmetic the registry does not list for that function is refused
24 * naming the modes it does list.
25 * No path returns an empty result, a zero, or a value from a different
26 * arithmetic than the caller asked for.
27 */
28
29#include <map>
30#include <string>
31#include <vector>
32
33#include "line/reg/api_json.h"
34#include "line/reg/registry.h"
35
36namespace line {
37namespace reg {
38
39/** The arithmetic a call runs at: Real also carries the precision tier. */
40struct ArithSpec {
42 unsigned digits = 0; ///< significant decimal digits, Real only
43
44 /** Canonical text, e.g. "double", "exact", "real:50". */
45 std::string str() const;
46};
47
48/**
49 * Parse --arith. Accepts "double", "exact" and "real:<digits>"; anything else
50 * is an InputError listing the accepted forms. The port instantiates the
51 * high-precision backend at three fixed tiers (50, 100, 200 digits), so a
52 * request between tiers is rounded UP to the next one -- never down, so a
53 * caller never silently receives less precision than asked -- and str()
54 * reports the tier actually used. Above 200 digits the call is refused.
55 */
56ArithSpec parse_arith(const std::string& text);
57
58/** Names exposed over this boundary, sorted; a subset of the registry. */
59std::vector<std::string> api_exposed_functions();
60
61/** True when the named function has a dispatch entry. */
62bool api_is_exposed(const std::string& name);
63
64/**
65 * Registered functions that can NEVER be carried by named JSON arguments, each
66 * with the reason (a callable argument, a random generator passed by
67 * reference, ...). api_invoke refuses them with that reason. Together with
68 * api_exposed_functions() and the model-level sn/lqn domains this partitions
69 * the registry, and a test holds it to that.
70 */
71std::map<std::string, std::string> api_library_only_functions();
72
73/**
74 * Invoke one API function.
75 *
76 * @param name MATLAB function name, e.g. "pfqn_ca"
77 * @param arith text of --arith, e.g. "exact" or "real:50"
78 * @param args object keyed by the MATLAB parameter names
79 * @return {"function", "arith", "results"}, results keyed by the MATLAB output
80 * names and encoded per the policy in api_json.h
81 * @throws UnsupportedError, InputError, NumericError
82 */
83Json api_invoke(const std::string& name, const std::string& arith, const Json& args);
84
85/** Human-readable rendering of the object api_invoke returns, for -o readable. */
86std::string api_render_readable(const Json& result);
87
88} // namespace reg
89} // namespace line
90
91#endif // LINE_REG_API_DISPATCH_H
The one conversion policy between JSON and the templated API layer.
nlohmann::json Json
Definition api_json.h:63
std::string api_render_readable(const Json &result)
Human-readable rendering of the object api_invoke returns, for -o readable.
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.
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 calla...
bool api_is_exposed(const std::string &name)
True when the named function has a dispatch entry.
Json api_invoke(const std::string &name, const std::string &arith, const Json &args)
Invoke one API function.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Arith
Definition registry.h:26
Coverage registry of the C++ port.
The arithmetic a call runs at: Real also carries the precision tier.
std::string str() const
Canonical text, e.g.
unsigned digits
significant decimal digits, Real only