mCRL2
Loading...
Searching...
No Matches
data_io.cpp
Go to the documentation of this file.
1// Author(s): Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#include "mcrl2/data/data_io.h"
11
12#include "mcrl2/atermpp/algorithm.h"
13#include "mcrl2/data/data_specification.h"
14
15using namespace mcrl2;
16using namespace mcrl2::data;
17
18static
20{
21 if (x.function() == core::detail::function_symbol_OpId())
22 {
23 return atermpp::aterm(core::detail::function_symbol_OpIdNoIndex(), x.begin(), --x.end());
24 }
25 return x;
26}
27
28static
30{
31 if (x.function() == core::detail::function_symbol_OpIdNoIndex())
32 {
33 const data::function_symbol& y = reinterpret_cast<const data::function_symbol&>(x);
35 }
36 return x;
37}
38
40{
41 return atermpp::aterm(core::detail::function_symbol_DataSpec(),
42 atermpp::aterm(core::detail::function_symbol_SortSpec(), atermpp::aterm_list(s.user_defined_sorts().begin(),s.user_defined_sorts().end()) +
43 atermpp::aterm_list(s.user_defined_aliases().begin(),s.user_defined_aliases().end())),
44 atermpp::aterm(core::detail::function_symbol_ConsSpec(), atermpp::aterm_list(s.user_defined_constructors().begin(),s.user_defined_constructors().end())),
45 atermpp::aterm(core::detail::function_symbol_MapSpec(), atermpp::aterm_list(s.user_defined_mappings().begin(),s.user_defined_mappings().end())),
46 atermpp::aterm(core::detail::function_symbol_DataEqnSpec(), atermpp::aterm_list(s.user_defined_equations().begin(),s.user_defined_equations().end())));
47}
48
49inline
51{
52 return atermpp::bottom_up_replace(x, add_index_impl);
53}
54
55inline
57{
58 return atermpp::bottom_up_replace(x, remove_index_impl);
59}
60
62{
63 atermpp::aterm_stream_state state(stream);
64 stream >> add_index_impl;
65
66 basic_sort_vector sorts;
67 alias_vector aliases;
68 function_symbol_vector constructors;
69 function_symbol_vector user_defined_mappings;
70 data_equation_vector user_defined_equations;
71
72 stream >> sorts;
73 stream >> aliases;
74 stream >> constructors;
75 stream >> user_defined_mappings;
76 stream >> user_defined_equations;
77
78 // Store the given information in a new data specification (to ignore existing elements of spec).
79 spec = data_specification(sorts, aliases, constructors, user_defined_mappings, user_defined_equations);
80
81 return stream;
82}
83
85{
86 atermpp::aterm_stream_state state(stream);
87 stream << remove_index_impl;
88
89 stream << spec.user_defined_sorts();
90 stream << spec.user_defined_aliases();
91 stream << spec.user_defined_constructors();
92 stream << spec.user_defined_mappings();
93 stream << spec.user_defined_equations();
94 return stream;
95}
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:62
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:51
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
Definition aterm_io.h:104
aterm_stream_state(aterm_stream &stream)
Definition aterm_io.h:106
A unordered_map class in which aterms can be stored.
\brief A function symbol
function_symbol(const core::identifier_string &name, const sort_expression &sort)
Constructor.
const core::identifier_string & name() const
const sort_expression & sort() const
atermpp::aterm remove_index(const atermpp::aterm &x)
Definition data_io.cpp:56
static atermpp::aterm remove_index_impl(const atermpp::aterm &x)
Definition data_io.cpp:19
static atermpp::aterm add_index_impl(const atermpp::aterm &x)
Definition data_io.cpp:29
atermpp::aterm add_index(const atermpp::aterm &x)
Definition data_io.cpp:50
aterm_istream & operator>>(aterm_istream &stream, aterm_transformer transformer)
Sets the given transformer to be applied to following reads.
Definition aterm_io.h:73
atermpp::aterm data_specification_to_aterm(const data_specification &s)
Definition data_io.cpp:39
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, data_specification &spec)
Reads a data specification from a stream.
Definition data_io.cpp:61