LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
"
26
#include "
line/lang/qn/network_builder.h
"
27
28
namespace
line
{
29
namespace
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
*/
37
template
<
class
T>
38
qn::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
44
namespace
jmt_import_detail
{
45
46
/** The extension without its dot, `fileparts`' third output minus the '.'. */
47
inline
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
*/
64
template
<
class
T>
65
qn::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
line::qn::Network
A queueing network under construction.
Definition
network_builder.h:108
line::qn::Network::raw_struct
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
Definition
network_builder.h:1837
jmva_reader.h
Port of matlab/src/io/JMVA2LINE.m (and jline.io.M2M.JMVA2LINE): a JMT .jmva product-form model read i...
jsim_reader.h
Read a JMT .jsim / .jsimg / .jsimw model into a qn::Network.
line::io::jmt_import_detail
Definition
jmt_import.h:44
line::io::jmt_import_detail::extension
std::string extension(const std::string &path)
The extension without its dot, fileparts' third output minus the '.
Definition
jmt_import.h:47
line::io::jmva_detail::file_stem
std::string file_stem(const std::string &path)
Basename without directory or extension, MATLAB's [~,fname] = fileparts.
Definition
jmva_reader.h:131
line::io
Definition
code_gen.h:68
line::io::read_jsim
qn::Network< T > read_jsim(const std::string &path, const std::string &name=std::string())
Read a JSIM document into a Network.
Definition
jsim_reader.h:294
line::io::jmt2line
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
line::io::jmva2line
qn::Network< T > jmva2line(const std::string &path, const std::string &name=std::string())
Port of JMVA2LINE(filename, modelName).
Definition
jmva_reader.h:149
line::io::jsim2line
qn::Network< T > jsim2line(const std::string &path, const std::string &name=std::string())
Port of JSIM2LINE(filename, modelName).
Definition
jmt_import.h:38
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
network_builder.h
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
include
line
io
jmt_import.h
Generated by
1.18.0