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 <string>
30#include <vector>
31
32#include "line/reg/api_json.h"
33#include "line/reg/registry.h"
34
35namespace line {
36namespace reg {
37
38/** The arithmetic a call runs at: Real also carries the precision tier. */
39struct ArithSpec {
41 unsigned digits = 0; ///< significant decimal digits, Real only
42
43 /** Canonical text, e.g. "double", "exact", "real:50". */
44 std::string str() const;
45};
46
47/**
48 * Parse --arith. Accepts "double", "exact" and "real:<digits>"; anything else
49 * is an InputError listing the accepted forms. The port instantiates the
50 * high-precision backend at three fixed tiers (50, 100, 200 digits), so a
51 * request between tiers is rounded UP to the next one -- never down, so a
52 * caller never silently receives less precision than asked -- and str()
53 * reports the tier actually used. Above 200 digits the call is refused.
54 */
55ArithSpec parse_arith(const std::string& text);
56
57/** Names exposed over this boundary, sorted; a subset of the registry. */
58std::vector<std::string> api_exposed_functions();
59
60/** True when the named function has a dispatch entry. */
61bool api_is_exposed(const std::string& name);
62
63/**
64 * Invoke one API function.
65 *
66 * @param name MATLAB function name, e.g. "pfqn_ca"
67 * @param arith text of --arith, e.g. "exact" or "real:50"
68 * @param args object keyed by the MATLAB parameter names
69 * @return {"function", "arith", "results"}, results keyed by the MATLAB output
70 * names and encoded per the policy in api_json.h
71 * @throws UnsupportedError, InputError, NumericError
72 */
73Json api_invoke(const std::string& name, const std::string& arith, const Json& args);
74
75/** Human-readable rendering of the object api_invoke returns, for -o readable. */
76std::string api_render_readable(const Json& result);
77
78} // namespace reg
79} // namespace line
80
81#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.
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.
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