LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
jmt_import.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_IO_JMT_IMPORT_H
6#define LINE_IO_JMT_IMPORT_H
7
8/**
9 * @file
10 * @ingroup line_io
11 * The MATLAB-named JMT import entry points: `JSIM2LINE` and the `JMT2LINE`
12 * dispatcher over `.jmva` / `.jsim` / `.jsimg` / `.jsimw`.
13 *
14 * `io::read_jsim` (jsim_reader.h) stays the implementation and keeps its name;
15 * `jsim2line` adds only the reference's naming rule, `fileparts` of the
16 * `<sim name=...>` attribute, so a model read from `model.jsimg` is called
17 * `model` as it is in MATLAB and the JAR, where `read_jsim` keeps the raw
18 * attribute.
19 */
20
21#include <iostream>
22#include <string>
23
24#include "line/io/jmva_reader.h"
25#include "line/io/jsim_reader.h"
27
28namespace line {
29namespace io {
30
31/**
32 * Port of `JSIM2LINE(filename, modelName)`.
33 *
34 * @param path a `.jsim`, `.jsimg` or `.jsimw` file
35 * @param name the model name; empty takes `fileparts` of the document's `<sim name>`
36 */
37template <class T>
38qn::Network<T> jsim2line(const std::string& path, const std::string& name = std::string()) {
39 qn::Network<T> net = read_jsim<T>(path, name);
40 if (name.empty()) net.raw_struct().name = jmva_detail::file_stem(net.raw_struct().name);
41 return net;
42}
43
45
46/** The extension without its dot, `fileparts`' third output minus the '.'. */
47inline std::string extension(const std::string& path) {
48 const std::size_t slash = path.find_last_of("/\\");
49 const std::size_t dot = path.find_last_of('.');
50 if (dot == std::string::npos || (slash != std::string::npos && dot < slash)) return "";
51 return path.substr(dot + 1);
52}
53
54} // namespace jmt_import_detail
55
56/**
57 * Port of `JMT2LINE(filename, modelName)`: dispatch on the extension.
58 *
59 * `.jmva` goes to `jmva2line`, `.jsim` / `.jsimg` / `.jsimw` to `jsim2line`.
60 * Any other extension is read as JSIM after the reference's warning, which in
61 * this port goes to stderr with the `[LINE] Warning:` prefix the io layer uses.
62 * The match is case-sensitive, as `switch fext` is in MATLAB.
63 */
64template <class T>
65qn::Network<T> jmt2line(const std::string& path, const std::string& name = std::string()) {
66 const std::string ext = jmt_import_detail::extension(path);
67 if (ext == "jmva") return jmva2line<T>(path, name);
68 if (ext == "jsim" || ext == "jsimg" || ext == "jsimw") return jsim2line<T>(path, name);
69 std::cerr << "[LINE] Warning: JMT2LINE: the file has unknown extension, trying to parse as a "
70 "JSIMG file."
71 << std::endl;
72 return jsim2line<T>(path, name);
73}
74
75} // namespace io
76} // namespace line
77
78#endif // LINE_IO_JMT_IMPORT_H
A queueing network under construction.
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
Port of matlab/src/io/JMVA2LINE.m (and jline.io.M2M.JMVA2LINE): a JMT .jmva product-form model read i...
Read a JMT .jsim / .jsimg / .jsimw model into a qn::Network.
std::string extension(const std::string &path)
The extension without its dot, fileparts' third output minus the '.
Definition jmt_import.h:47
std::string file_stem(const std::string &path)
Basename without directory or extension, MATLAB's [~,fname] = fileparts.
qn::Network< T > read_jsim(const std::string &path, const std::string &name=std::string())
Read a JSIM document into a Network.
qn::Network< T > jmt2line(const std::string &path, const std::string &name=std::string())
Port of JMT2LINE(filename, modelName): dispatch on the extension.
Definition jmt_import.h:65
qn::Network< T > jmva2line(const std::string &path, const std::string &name=std::string())
Port of JMVA2LINE(filename, modelName).
qn::Network< T > jsim2line(const std::string &path, const std::string &name=std::string())
Port of JSIM2LINE(filename, modelName).
Definition jmt_import.h:38
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...