12#ifndef _EXPORT_MACRO_H_
13#define _EXPORT_MACRO_H_
34 unsigned t() const noexcept {
return Tx *
Ty; }
35 unsigned r() const noexcept {
return Rx *
Ry; }
36 unsigned _() const noexcept {
return t() *
r(); }
38 std::map<std::string, std::pair<unsigned, unsigned>>
nodes_xy;
42 std::pair<unsigned, unsigned>
xy(std::string
id)
const {
45 }
catch (
const std::out_of_range& e) {
47 _log.
err() <<
"No '" +
id +
"' node when replacing macro (`SIZE[<id>]`, `BEAM[<id>]`, `GRID[<id>]`)!"
49 Term::error(
"No '" +
id +
"' node when replacing macro (`SIZE[<id>]`, `BEAM[<id>]`, `GRID[<id>]`)!");
54 unsigned x(std::string
id)
const {
return xy(
id).first; }
55 unsigned y(std::string
id)
const {
return xy(
id).second; }
57 auto&& x_and_y = this->
xy(
id);
58 return x_and_y.first * x_and_y.second;
67 std::vector<std::vector<std::vector<std::pair<std::string, std::string>>>>
alg_custom;
69 std::map<std::string, std::string>
custom;
78 std::string
replaceMacro(
const std::string& s,
int job_cnt,
int alg_cnt)
const;
88 const std::map<std::string, std::pair<std::string, bool>>
_constants = {
89 { R
"(CHS\.PATHS_NUM)", { "CHS_paths_num",
false } },
90 { R
"(CHS\.CHANNELS\[(.*\w+.*)\])", { "CHS_channels[$1]",
true } },
91 { R
"(CHS\.CHANNELS\[(.*\w+.*)\]\.ID)", { "CHS_channels_id[$1]",
false } },
92 { R
"(CHS\.NODES\[(.*\w+.*)\]\.ID)", { "CHS_nodes_id[$1]",
false } },
93 { R
"(CHS\.FROM\[(.*\w+.*)\])", { "CHS_from[$1]",
false } },
94 { R
"(CHS\.FROM\[(.*\w+.*)\]\.INDEX)", { "CHS_from[$1]",
false } },
95 { R
"(CHS\.FROM\[(.*\w+.*)\]\.ID)", { "CHS_nodes_id[" +
constantStr({
"CHS_from[$1]",
false }) +
"]",
false } },
96 { R
"(CHS\.TO\[(.*\w+.*)\])", { "CHS_to[$1]",
false } },
97 { R
"(CHS\.TO\[(.*\w+.*)\]\.INDEX)", { "CHS_to[$1]",
false } },
98 { R
"(CHS\.TO\[(.*\w+.*)\]\.ID)", { "CHS_nodes_id[" +
constantStr({
"CHS_to[$1]",
false }) +
"]",
false } },
99 { R
"(CHS\[(.*\w+.*)\]\.JUMPS_NUM)", { "CHS_i_jumps_num[$1]",
false } },
100 { R
"(CHS\[(.*\w+.*)\]\.SIZE)", { "CHS_i_size[$1]",
false } },
101 { R
"(CHS\.ALL_CHANNELS\[(.*\w+.*)\]\.INDEX)", { "CHS_all_channels_index[$1]",
false } },
102 { R
"(CHS\.ALL_CHANNELS\[(.*\w+.*)\])",
103 { "CHS_channels[" +
constantStr({
"CHS_all_channels_index[$1]",
false }) +
"]",
true } },
104 { R
"(CHS\.ALL_CHANNELS\[(.*\w+.*)\]\.ID)",
105 { "CHS_channels_id[" +
constantStr({
"CHS_all_channels_index[$1]",
false }) +
"]",
false } },
106 { R
"(CHS\.NUM_CHANNELS_ACC\[(.*\w+.*)\])", { "CHS_num_channels_acc[$1]",
false } },
107 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\])",
108 { "CHS_channels[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
"]",
110 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.ID)",
111 { "CHS_channels_id[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
114 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.FROM)",
115 { "CHS_from[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
"]",
117 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.FROM\.INDEX)",
118 { "CHS_from[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
"]",
120 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.FROM\.ID)",
123 constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
128 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.TO)",
129 { "CHS_to[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
"]",
131 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.TO\.INDEX)",
132 { "CHS_to[" +
constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
"]",
134 { R
"(CHS\[(.*\w+.*)\]\[(.*\w+.*)\]\.TO\.ID)",
137 constantStr({
"CHS_all_channels_index[CHS_num_channels_acc[$1] + ($2)]",
false }) +
152 std::string
constantStr(
const std::pair<std::string, bool>& v)
const;
164 std::string
replace(
const std::string& s,
const std::string& key,
const std::string& val,
171 return type == Type::PRE ?
"Predefined" :
type == Type::USER ?
"User" :
"User Priority";
174inline std::string
Macro::replace(
const std::string& s,
const std::string& key,
const std::string& val,
176 auto r = std::regex_replace(s, std::regex(
"`" + key +
"`"), val);
177 if (r != s)
_log.
info() <<
"Macro Replace (" <<
typeName(
type) <<
"): " << key <<
" -> " << val << std::endl;
182 if (v.first.empty())
return "";
184 if (v.second)
return "(*mmCEsim_Consts_"s + v.first +
")";
185 else return "mmCEsim_Consts_"s + v.first;
186 }
else return v.first;
std::ofstream & err()
Write error message to the log file.
Definition: log.h:117
std::ofstream & info()
Write infomation to the log file.
Definition: log.h:107
static void error(const T &msg)
Print error message.
Definition: term.h:178
Lang
Export language.
Definition: lang.h:20
@ CPP
C++ with Armadillo library.
Log _log
The shared Log variable.
Definition: log.cpp:53
static const Macro macro_none
Definition: macro.h:168
type
Definition: version_bump.py:14
std::string _cascaded_channel
Definition: macro.h:72
std::string typeName(Type type) const noexcept
Get the name of Type.
Definition: macro.h:170
std::vector< std::vector< std::string > > alg_params
Definition: macro.h:66
std::string constantStr(const std::pair< std::string, bool > &v) const
Definition: macro.h:181
std::vector< unsigned > alg_num
Definition: macro.h:64
std::map< std::string, std::string > beamforming
Definition: macro.h:71
std::map< std::string, std::string > custom_priority
Definition: macro.h:68
const std::map< std::string, std::pair< std::string, bool > > _constants
Definition: macro.h:88
std::vector< std::vector< std::vector< std::pair< std::string, std::string > > > > alg_custom
Definition: macro.h:67
XY_Size _N
Definition: macro.h:73
std::string replace(const std::string &s, const std::string &key, const std::string &val, Type type=Type::PRE) const
RegEx replace.
Definition: macro.h:174
std::map< std::string, std::string > custom
Definition: macro.h:69
std::string replaceMacro(const std::string &s, int job_cnt, int alg_cnt) const
Definition: macro.cpp:73
unsigned job_num
Definition: macro.h:63
XY_Size _G
Definition: macro.h:73
XY_Size _B
Definition: macro.h:73
Lang lang
Definition: macro.h:74
bool replaceXY(std::string &r) const
Definition: macro.cpp:15
std::vector< std::vector< std::string > > alg_names
Definition: macro.h:65
std::map< std::string, std::string > custom_in_alg
Definition: macro.h:70
bool hasKey(std::string id) const noexcept
Definition: macro.h:40
unsigned x(std::string id) const
Definition: macro.h:54
unsigned y(std::string id) const
Definition: macro.h:55
unsigned x_mul_y(std::string id) const
Definition: macro.h:56
unsigned Rx
Definition: macro.h:31
unsigned Tx
Definition: macro.h:29
std::pair< unsigned, unsigned > xy(std::string id) const
Definition: macro.h:42
unsigned t() const noexcept
Definition: macro.h:34
unsigned _() const noexcept
Definition: macro.h:36
unsigned Ry
Definition: macro.h:32
unsigned Ty
Definition: macro.h:30
unsigned r() const noexcept
Definition: macro.h:35
std::map< std::string, std::pair< unsigned, unsigned > > nodes_xy
Definition: macro.h:38