highlight: improve support for highlighted edges

* spot/twa/twa.cc, spot/twa/twa.hh: Add a way to
remove named properties.
* spot/twa/twagraph.cc: Clear highlight-edges on operations
that reorder the edge vector.
* spot/twaalgos/randomize.cc, spot/twaalgos/randomize.hh:
Preserve highlighted state, but not highlighted edges.
* spot/twaalgos/hoa.cc: Adjust output of highlight-edge
when the edges are not stored in order.
* tests/core/readsave.test, tests/core/tgbagraph.test,
tests/core/twagraph.cc: More test cases.
This commit is contained in:
Alexandre Duret-Lutz 2016-07-18 12:01:40 +02:00
parent e17a617bc2
commit 39332fb118
9 changed files with 128 additions and 23 deletions

View file

@ -69,6 +69,17 @@ namespace spot
return !couvreur99(a)->check();
}
void
twa::set_named_prop(std::string s, std::nullptr_t)
{
auto p = named_prop_.find(s);
if (p == named_prop_.end())
return;
p->second.second(p->second.first);
named_prop_.erase(p);
return;
}
void
twa::set_named_prop(std::string s,
void* val, std::function<void(void*)> destructor)

View file

@ -22,6 +22,7 @@
#pragma once
#include <cstddef>
#include <spot/twa/fwd.hh>
#include <spot/twa/acc.hh>
#include <spot/twa/bdddict.hh>
@ -952,7 +953,7 @@ namespace spot
#ifndef SWIG
/// \brief Declare a named property
///
/// Arbitrary object can be attached to automata. Those are called
/// Arbitrary objects can be attached to automata. Those are called
/// named properties. They are used for instance to name all the
/// state of an automaton.
///
@ -969,15 +970,16 @@ namespace spot
/// \brief Declare a named property
///
/// Arbitrary object can be attached to automata. Those are called
/// Arbitrary objects can be attached to automata. Those are called
/// named properties. They are used for instance to name all the
/// state of an automaton.
///
///
/// This function attaches the object \a val to the current automaton,
/// under the name \a s.
///
/// The object will be automatically destroyed when the automaton
/// is destroyed.
/// When the automaton is destroyed, the \a destructor function will
/// be called to destroy the attached object.
///
/// See https://spot.lrde.epita.fr/concepts.html#named-properties
/// for a list of named properties used by Spot.
@ -987,6 +989,18 @@ namespace spot
set_named_prop(s, val, [](void *p) { delete static_cast<T*>(p); });
}
/// \brief Erase a named property
///
/// Arbitrary objects can be attached to automata. Those are called
/// named properties. They are used for instance to name all the
/// state of an automaton.
///
/// This function removes the property \a s if it exists.
///
/// See https://spot.lrde.epita.fr/concepts.html#named-properties
/// for a list of named properties used by Spot.
void set_named_prop(std::string s, std::nullptr_t);
/// \brief Retrieve a named property
///
/// Because named property can be object of any type, retrieving

View file

@ -45,6 +45,7 @@ namespace spot
void twa_graph::merge_edges()
{
set_named_prop("highlight-edges", nullptr);
g_.remove_dead_edges_();
typedef graph_t::edge_storage_t tr_t;
@ -272,8 +273,7 @@ namespace spot
void twa_graph::defrag_states(std::vector<unsigned>&& newst,
unsigned used_states)
{
auto* names = get_named_prop<std::vector<std::string>>("state-names");
if (names)
if (auto* names = get_named_prop<std::vector<std::string>>("state-names"))
{
unsigned size = names->size();
for (unsigned s = 0; s < size; ++s)
@ -285,6 +285,18 @@ namespace spot
}
names->resize(used_states);
}
if (auto hs = get_named_prop<std::map<unsigned, unsigned>>
("highlight-states"))
{
std::map<unsigned, unsigned> hs2;
for (auto p: *hs)
{
unsigned dst = newst[p.first];
if (dst != -1U)
hs2[dst] = p.second;
}
std::swap(*hs, hs2);
}
g_.defrag_states(std::move(newst), used_states);
}