LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
36
namespace
line
{
37
namespace
reg
{
38
39
/** The arithmetic a call runs at: Real also carries the precision tier. */
40
struct
ArithSpec
{
41
Arith
mode
=
Arith::Double
;
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
*/
56
ArithSpec
parse_arith
(
const
std::string& text);
57
58
/** Names exposed over this boundary, sorted; a subset of the registry. */
59
std::vector<std::string>
api_exposed_functions
();
60
61
/** True when the named function has a dispatch entry. */
62
bool
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
*/
71
std::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
*/
83
Json
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. */
86
std::string
api_render_readable
(
const
Json
& result);
87
88
}
// namespace reg
89
}
// namespace line
90
91
#endif
// LINE_REG_API_DISPATCH_H
api_json.h
The one conversion policy between JSON and the templated API layer.
line::reg
Definition
api_dispatch.h:37
line::reg::Json
nlohmann::json Json
Definition
api_json.h:63
line::reg::api_render_readable
std::string api_render_readable(const Json &result)
Human-readable rendering of the object api_invoke returns, for -o readable.
Definition
api_dispatch.cpp:3335
line::reg::parse_arith
ArithSpec parse_arith(const std::string &text)
Parse –arith.
Definition
api_dispatch.cpp:206
line::reg::api_exposed_functions
std::vector< std::string > api_exposed_functions()
Names exposed over this boundary, sorted; a subset of the registry.
Definition
api_dispatch.cpp:3223
line::reg::api_library_only_functions
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...
Definition
api_dispatch.cpp:3229
line::reg::api_is_exposed
bool api_is_exposed(const std::string &name)
True when the named function has a dispatch entry.
Definition
api_dispatch.cpp:3233
line::reg::api_invoke
Json api_invoke(const std::string &name, const std::string &arith, const Json &args)
Invoke one API function.
Definition
api_dispatch.cpp:3237
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
line::Arith
Arith
Definition
registry.h:26
line::Arith::Double
@ Double
Definition
registry.h:26
registry.h
Coverage registry of the C++ port.
line::reg::ArithSpec
The arithmetic a call runs at: Real also carries the precision tier.
Definition
api_dispatch.h:40
line::reg::ArithSpec::str
std::string str() const
Canonical text, e.g.
Definition
api_dispatch.cpp:197
line::reg::ArithSpec::mode
Arith mode
Definition
api_dispatch.h:41
line::reg::ArithSpec::digits
unsigned digits
significant decimal digits, Real only
Definition
api_dispatch.h:42
include
line
reg
api_dispatch.h
Generated by
1.18.0