12#ifndef MCRL2_DATA_DETAIL_DATA_PROPERTY_MAP_H
13#define MCRL2_DATA_DETAIL_DATA_PROPERTY_MAP_H
15#include "mcrl2/data/variable.h"
26template <
typename Derived =
void >
55 std::ostringstream out;
72 return data::pp(v) +
":" + data::pp(v.sort());
75 template <
typename Container >
78 std::set<std::string> elements;
80 for (
auto i = v.begin(); i != v.end(); ++i)
82 elements.insert(
static_cast< Derived
const& >(*
this).print(*i));
85 return utilities::string_join(elements,
", ");
88 template <
typename Container >
91 return (print_separators) ? add_separators< Container >(print(v)) : print(v);
99 return std::stoul(utilities::remove_whitespace(text));
104 std::vector<std::string> v = utilities::split(text,
",");
105 std::for_each(v.begin(), v.end(), utilities::trim);
106 return std::set<std::string>(v.begin(), v.end());
133 out <<
"Difference in property " <<
property <<
" detected: " <<
x <<
" versus " <<
y <<
"\n";
145 template <
typename T>
160 out <<
"Difference in property " <<
property <<
" detected:";
181 return "ERROR: unknown property " +
property +
" encountered!";
227 for (
const std::string& line: utilities::split(text,
"\n"))
229 std::vector<std::string> words = utilities::split(line,
"=");
230 if (words.size() == 2)
232 utilities::trim(words[0]);
233 utilities::trim(words[1]);
234 m_data[words[0]] = words[1];
249 unsigned int n = max_key_length();
250 std::vector<std::string> lines;
251 for (
const auto & i : m_data)
253 lines.push_back(align(i.first, n) +
" = " + i.second);
255 return utilities::string_join(lines,
"\n");
268 auto i = m_data.find(key);
269 if (i == m_data.end())
271 throw mcrl2::runtime_error(
"property_map: could not find key " + key);
282 std::ostringstream out;
283 for (
const auto & i : m_data)
285 auto j = other.data().find(i.first);
286 if (j != other.data().end())
288 out <<
static_cast< Derived
const& >(*
this).compare_property(i.first, i.second, j->second);
295template <
typename PropertyMap>
298 PropertyMap map2(expected_result);
299 std::string result = map1.compare(map2);
302 std::cerr <<
"------------------------------" << std::endl;
303 std::cerr <<
" Failed test " << std::endl;
304 std::cerr <<
"------------------------------" << std::endl;
305 std::cerr << message << std::endl;
306 std::cerr <<
"--- expected result ---" << std::endl;
307 std::cerr << expected_result << std::endl;
308 std::cerr <<
"--- found result ---" << std::endl;
309 std::cerr << map1.to_string() << std::endl;
310 std::cerr <<
"--- differences ---" << std::endl;
311 std::cerr << result << std::endl;
313 return result.empty();
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.
unsigned int parse_unsigned_int(std::string const &text) const
const std::map< std::string, std::string > & data() const
Returns the stored properties.
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::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 operator[](const std::string &key) const
Returns the value corresponding to key. Throws an exception if the key is not found.
std::string print(std::size_t n) 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.
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
bool compare_property_maps(const std::string &message, const PropertyMap &map1, const std::string &expected_result)