Commit 61edf7f4 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

tgba: simplify usage of named properties

* src/tgba/tgba.hh, src/tgba/tgba.cc (set_named_prop): Add a template
version.
(get_named_prop): Hide the old version, and supply a template version
that casts.
* src/bin/ltlcross.cc, src/hoaparse/hoaparse.yy, src/tgbaalgos/hoa.cc,
src/tgbaalgos/product.cc: Adjust usage.
parent 5a1e38d9
......@@ -1244,8 +1244,7 @@ namespace
state_set& s)
{
auto aut = m->get_aut();
auto ps = static_cast<const spot::product_states*>
(aut->get_named_prop("product-states"));
auto ps = aut->get_named_prop<const spot::product_states>("product-states");
unsigned c = m->scc_count();
for (unsigned n = 0; n < c; ++n)
if (m->is_accepting_scc(n) || m->is_trivial(n))
......
......@@ -359,9 +359,7 @@ header-item: "States:" INT
}
| "name:" STRING
{
res.h->aut->set_named_prop("automaton-name", $2, [](void* name) {
delete static_cast<std::string*>(name);
});
res.h->aut->set_named_prop("automaton-name", $2);
}
| "properties:" properties
| HEADERNAME header-spec
......
......@@ -98,7 +98,7 @@ namespace spot
}
void*
tgba::get_named_prop(std::string s) const
tgba::get_named_prop_(std::string s) const
{
auto i = named_prop_.find(s);
if (i == named_prop_.end())
......
......@@ -665,12 +665,28 @@ namespace spot
std::pair<void*,
std::function<void(void*)>>> named_prop_;
#endif
void* get_named_prop_(std::string s) const;
public:
#ifndef SWIG
void set_named_prop(std::string s,
void* val, std::function<void(void*)> destructor);
void* get_named_prop(std::string s) const;
template<typename T>
void set_named_prop(std::string s, T* val)
{
set_named_prop(s, val, [](void *p) { delete static_cast<T*>(p); });
}
template<typename T>
T* get_named_prop(std::string s) const
{
void* p = get_named_prop_(s);
if (!p)
return nullptr;
return static_cast<T*>(p);
}
#endif
bool has_single_acc_set() const
......
......@@ -250,9 +250,9 @@ namespace spot
const char nl = newline ? '\n' : ' ';
os << "HOA: v1" << nl;
auto* n = aut->get_named_prop("automaton-name");
auto n = aut->get_named_prop<std::string>("automaton-name");
if (n)
escape_str(os << "name: \"", *static_cast<std::string*>(n)) << '"' << nl;
escape_str(os << "name: \"", *n) << '"' << nl;
else if (f)
escape_str(os << "name: \"", to_string(f)) << '"' << nl;
os << "States: " << num_states << nl
......
......@@ -56,9 +56,7 @@ namespace spot
+ right->acc().num_sets());
auto v = new product_states;
res->set_named_prop("product-states", v, [](void* vv) {
delete static_cast<product_states*>(vv);
});
res->set_named_prop("product-states", v);
auto new_state =
[&](unsigned left_state, unsigned right_state) -> unsigned
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment