12#ifndef MCRL2_DATA_DETAIL_DATA_PROPERTY_MAP_H
13#define MCRL2_DATA_DETAIL_DATA_PROPERTY_MAP_H
32template <
typename Derived =
void >
38 template <
typename Container >
45 template <
typename Container >
52 std::map<std::string, std::string>
m_data;
57 std::string
print(std::size_t n)
const
59 std::ostringstream out;
64 std::string
print(std::string s)
const
79 template <
typename Container >
82 std::set<std::string> elements;
84 for (
auto i = v.begin(); i != v.end(); ++i)
86 elements.insert(
static_cast< Derived const&
>(*this).print(*i));
92 template <
typename Container >
95 return (print_separators) ? add_separators< Container >(
print(v)) :
print(v);
110 return std::set<std::string>(v.begin(), v.end());
115 std::set<std::multiset<std::string> > result;
117 for (
const std::string& ms: multisets)
122 result.insert(std::multiset<std::string>(v.begin(), v.end()));
132 std::string
compare(
const std::string& property,
unsigned int x,
unsigned int y)
const
136 std::ostringstream out;
137 out <<
"Difference in property " <<
property <<
" detected: " << x <<
" versus " << y <<
"\n";
149 template <
typename T>
150 std::string
compare(
const std::string& property,
const std::set<T>& x,
const std::set<T>& y)
const
152 std::ostringstream out;
156 std::set_difference(x.begin(), x.end(), y.begin(), y.end(), std::inserter(plus, plus.end()));
160 std::set_difference(y.begin(), y.end(), x.begin(), x.end(), std::inserter(minus, minus.
end()));
162 if (!plus.empty() || !minus.
empty())
164 out <<
"Difference in property " <<
property <<
" detected:";
165 for (
auto i = plus.begin(); i != plus.end(); ++i)
167 out <<
" +" <<
print(*i);
169 for (
auto i = minus.
begin(); i != minus.
end(); ++i)
171 out <<
" -" <<
print(*i);
183 std::string
compare_property(
const std::string& property,
const std::string& ,
const std::string& )
const
185 return "ERROR: unknown property " +
property +
" encountered!";
194 unsigned int result = 0;
197 result = (std::max)(
static_cast< std::size_t
>(result), i->first.size());
202 std::string
align(
const std::string& s,
unsigned int n)
const
208 return s + std::string(n - s.size(),
' ');
213 template <
typename Container>
214 std::set<core::identifier_string>
names(
const Container& v)
const
216 std::set<core::identifier_string> result;
217 for (
auto i = v.begin(); i != v.end(); ++i)
219 result.insert(i->name());
236 if (words.size() == 2)
240 m_data[words[0]] = words[1];
256 std::vector<std::string> lines;
259 lines.push_back(
align(i->first, n) +
" = " + i->second);
265 const std::map<std::string, std::string>&
data()
const
274 auto i =
m_data.find(key);
288 std::ostringstream out;
291 auto j = other.
data().find(i->first);
292 if (j != other.
data().end())
294 out << static_cast< Derived const& >(*this).compare_property(i->first, i->second, j->second);
301template <
typename PropertyMap>
304 PropertyMap map2(expected_result);
305 std::string result = map1.compare(map2);
308 std::cerr <<
"------------------------------" << std::endl;
309 std::cerr <<
" Failed test " << std::endl;
310 std::cerr <<
"------------------------------" << std::endl;
311 std::cerr << message << std::endl;
312 std::cerr <<
"--- expected result ---" << std::endl;
313 std::cerr << expected_result << std::endl;
314 std::cerr <<
"--- found result ---" << std::endl;
315 std::cerr << map1.to_string() << std::endl;
316 std::cerr <<
"--- differences ---" << std::endl;
317 std::cerr << result << std::endl;
319 return result.empty();
Term containing a string.
bool empty() const
Returns true if the term has no arguments.
const_iterator end() const
const_iterator begin() const
Base class for storing properties of mCRL2 types. Properties are (key, value) pairs stored as strings...
data_property_map(const std::string &text)
The strings may appear in a random order, and not all of them need to be present.
std::string print(std::string s) const
unsigned int parse_unsigned_int(std::string const &text) const
const std::map< std::string, std::string > & data() const
Returns the stored properties.
std::set< core::identifier_string > names(const Container &v) const
Collects the names of the elements of the container. The name of element x is retrieved by x....
std::string compare(const std::string &property, unsigned int x, unsigned int y) const
Compares two integers, and returns a message if they are different. If if they are equal the empty st...
std::string print(const core::identifier_string &s) const
void parse_text(const std::string &text)
Initializes the property map with text containing lines in KEY = VALUE format.
std::string print(const data::variable &v) const
std::map< std::string, std::string > m_data
Contains a normalized string representation of the properties.
std::string compare(const data_property_map &other) const
Compares this property map with another property map. The function compare_property must be defined p...
std::string compare_property(const std::string &property, const std::string &, const std::string &) const
Compares two values x and y of a given property. This function should be redefined in derived classes...
std::string operator[](const std::string &key) const
Returns the value corresponding to key. Throws an exception if the key is not found.
unsigned int max_key_length() const
Returns the maximum length of the property names.
std::string print(std::size_t n) const
static std::string add_separators(std::string const &c, typename std::enable_if< !atermpp::is_set< Container >::value >::type *=0)
Add start/end separators for set container types.
std::set< std::multiset< std::string > > parse_set_multiset_string(std::string const &text) const
std::set< std::string > parse_set_string(std::string const &text) const
std::string to_string() const
Returns a string representation of the properties.
data_property_map()
Default constructor for derived types.
std::string align(const std::string &s, unsigned int n) const
std::string compare(const std::string &property, const std::set< T > &x, const std::set< T > &y) const
Compares two sets and returns a string with the differences encountered. Elements present in the firs...
static std::string add_separators(std::string const &c, typename std::enable_if< atermpp::is_set< Container >::value >::type *=nullptr)
Add start/end separators for non-set container types.
std::string print(const Container &v, typename atermpp::enable_if_container< Container >::type *=nullptr) const
std::string print(const Container &v, bool print_separators, typename atermpp::enable_if_container< Container >::type *=nullptr) const
const sort_expression & sort() const
Standard exception class for reporting runtime errors.
bool compare_property_maps(const std::string &message, const PropertyMap &map1, const std::string &expected_result)
std::string pp(const abstraction &x)
std::string string_join(const Container &c, const std::string &separator)
Joins a sequence of strings. This is a replacement for boost::algorithm::join, since it gives stack o...
void trim(std::string &text)
Remove all trailing and leading spaces from the input.
std::string regex_replace(const std::string &src, const std::string &dest, const std::string &text)
Regular expression replacement in a string.
std::string remove_whitespace(const std::string &text)
Removes whitespace from a string.
std::vector< std::string > split(const std::string &line, const std::string &separators)
Split the text.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...