WIP: shorter mapping strings.

This commit is contained in:
Matthias Koefferlein 2020-12-19 00:56:45 +01:00
parent 5bd1cb8bd7
commit 3fbfb20727
3 changed files with 98 additions and 32 deletions

View File

@ -262,6 +262,43 @@ static std::string format_interval (ld_type l1, ld_type l2)
}
}
static std::vector<std::pair<ld_type, ld_type> >
extract_dt_intervals (const LayerMap::datatype_map &dt_map, int ll, bool &has_others)
{
std::vector<std::pair<ld_type, ld_type> > res;
for (LayerMap::datatype_map::const_iterator d = dt_map.begin (); d != dt_map.end (); ) {
if (d->second.find (ll) != d->second.end ()) {
std::pair<ld_type, ld_type> dpi = d->first;
if (d->second.size () > 1) {
has_others = true;
}
LayerMap::datatype_map::const_iterator dd = d;
++dd;
while (dd != dt_map.end () && dd->first.first == dpi.second && dd->second.find (ll) != dd->second.end ()) {
if (dd->second.size () > 1) {
has_others = true;
}
dpi.second = dd->first.second;
++dd;
}
d = dd;
res.push_back (dpi);
} else {
++d;
}
}
return res;
}
std::string
LayerMap::mapping_str (unsigned int ll) const
{
@ -269,36 +306,37 @@ LayerMap::mapping_str (unsigned int ll) const
bool f1 = true;
bool is_mmap = false;
for (ld_map::const_iterator l = m_ld_map.begin (); l != m_ld_map.end (); ++l) {
for (ld_map::const_iterator l = m_ld_map.begin (); l != m_ld_map.end (); ) {
std::pair<ld_type, ld_type> lti = l->first;
std::vector<std::pair<ld_type, ld_type> > dti = extract_dt_intervals (l->second, ll, is_mmap);
++l;
while (l != m_ld_map.end () && lti.second == l->first.first && extract_dt_intervals (l->second, ll, is_mmap) == dti) {
lti.second = l->first.second;
++l;
}
bool f2 = true;
for (datatype_map::const_iterator d = l->second.begin (); d != l->second.end (); ++d) {
for (std::vector<std::pair<ld_type, ld_type> >::const_iterator d = dti.begin (); d != dti.end (); ++d) {
if (d->second.find (ll) != d->second.end ()) {
// create a string representation
if (!f2) {
s += ",";
} else {
if (d->second.size () > 1) {
is_mmap = true;
if (!f1) {
s += ";";
}
f1 = false;
// create a string representation
if (!f2) {
s += ",";
} else {
if (!f1) {
s += ";";
}
f1 = false;
s += format_interval (l->first.first, l->first.second);
s += "/";
}
f2 = false;
s += format_interval (d->first.first, d->first.second);
s += format_interval (lti.first, lti.second);
s += "/";
}
f2 = false;
s += format_interval (d->first, d->second);
}

View File

@ -38,7 +38,7 @@ TEST(1)
EXPECT_EQ (lm.first_logical (db::LDPair (2, 0)).second, (unsigned int) 18);
EXPECT_EQ (lm.first_logical (db::LDPair (0, 0)).first, false);
EXPECT_EQ (lm.mapping_str (18), "1/0;2-5/0");
EXPECT_EQ (lm.mapping_str (18), "1-5/0");
EXPECT_EQ (lm.mapping_str (17), "1/5");
lm.map (db::LDPair (2, 2), 18);
@ -477,7 +477,7 @@ TEST(8)
// some
lm.mmap_expr ("*/1-10", n++);
EXPECT_EQ (lm.to_string (),
"layer_map('+*/0,1-10,11-*';'+*/1-10')"
"layer_map('+*/*';'+*/1-10')"
);
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
@ -485,7 +485,7 @@ TEST(8)
lm.mmap_expr ("*/5,15", n++);
EXPECT_EQ (lm.to_string (),
"layer_map('+*/0,1-4,5,6-10,11-14,15,16-*';'+*/1-4,5,6-10';'+*/5,15')"
"layer_map('+*/*';'+*/1-10';'+*/5,15')"
);
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
@ -496,8 +496,8 @@ TEST(8)
EXPECT_EQ (set2string (lm.logical (db::LDPair (0, 10))), "0,1");
// NOTE: the leading "+" indicates that the listed layers may go somewhere else, so we can't plainly map them
EXPECT_EQ (lm.mapping_str (0), "+*/0,1-4,5,6-10,11-14,15,16-*");
EXPECT_EQ (lm.mapping_str (1), "+*/1-4,5,6-10");
EXPECT_EQ (lm.mapping_str (0), "+*/*");
EXPECT_EQ (lm.mapping_str (1), "+*/1-10");
EXPECT_EQ (lm.mapping_str (2), "+*/5,15");
EXPECT_EQ (lm.mapping_str (3), "");
@ -516,7 +516,7 @@ TEST(8)
// some
lm.mmap_expr ("1-10/*", n++);
EXPECT_EQ (lm.to_string (),
"layer_map('+0/*;1-10/*;11-*/*';'+1-10/*')"
"layer_map('+*/*';'+1-10/*')"
);
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
@ -524,7 +524,7 @@ TEST(8)
lm.mmap_expr ("5,15/*", n++);
EXPECT_EQ (lm.to_string (),
"layer_map('+0/*;1-4/*;5/*;6-10/*;11-14/*;15/*;16-*/*';'+1-4/*;5/*;6-10/*';'+5/*;15/*')"
"layer_map('+*/*';'+1-10/*';'+5/*;15/*')"
);
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
@ -535,8 +535,8 @@ TEST(8)
EXPECT_EQ (set2string (lm.logical (db::LDPair (10, 0))), "0,1");
// NOTE: the leading "+" indicates that the listed layers may go somewhere else, so we can't plainly map them
EXPECT_EQ (lm.mapping_str (0), "+0/*;1-4/*;5/*;6-10/*;11-14/*;15/*;16-*/*");
EXPECT_EQ (lm.mapping_str (1), "+1-4/*;5/*;6-10/*");
EXPECT_EQ (lm.mapping_str (0), "+*/*");
EXPECT_EQ (lm.mapping_str (1), "+1-10/*");
EXPECT_EQ (lm.mapping_str (2), "+5/*;15/*");
EXPECT_EQ (lm.mapping_str (3), "");
@ -553,7 +553,7 @@ TEST(8)
// some
lm.mmap_expr ("1-10/0-20", n++);
EXPECT_EQ (lm.to_string (),
"layer_map('+0/*;1-10/0-20,21-*;11-*/*';'+1-10/0-20')"
"layer_map('+*/*';'+1-10/0-20')"
);
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
}

View File

@ -173,5 +173,33 @@
</tr>
</table>
<h2>Multi-mapping and unmapping</h2>
<p>
Layer mapping table support an advanced feature which is to duplicate input layers to
a number of output layers (1:n) mapping.
The feature is enabled by prepending a "+" to the mapping statement. The following
statement will first select layer 5/0 and additionally copy it to layer 1000/0:
</p>
<pre>5/0
+5/0: 1000/0
</pre>
<p>
Unmapping removes the mapping for a specific layer or range. It is specified by prepending "-"
to the mapping expression. The following statement will map all datatypes of layer 5 to 0 except
for datatype 10 which is not considered.
</p>
<pre>5/*: 5/0
-5/10
</pre>
<p>
Unmapping cancels the mappings specified previously, so the order of statements becomes important
when using unmapping and multi-mapping.
</p>
</doc>