mCRL2
Loading...
Searching...
No Matches
print_utility.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
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//
11
12#ifndef MCRL2_CORE_DETAIL_PRINT_UTILITY_H
13#define MCRL2_CORE_DETAIL_PRINT_UTILITY_H
14
15#include "mcrl2/core/print.h"
16
17namespace mcrl2
18{
19
20namespace core
21{
22
23namespace detail
24{
25
30template <typename Container>
31std::string print_container(const Container& v, const std::string& begin_marker = "(", const std::string& end_marker = ")", const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
32{
33 std::ostringstream out;
34 if (!message.empty())
35 {
36 out << "--- " << message << "---" << std::endl;
37 }
38 out << begin_marker;
39 if (boundary_spaces)
40 {
41 out << " ";
42 }
43 int index = 0;
44 for (auto i = v.begin(); i != v.end(); ++i)
45 {
46 if (print_index)
47 {
48 out << index++ << " ";
49 out << *i;
50 out << std::endl;
51 }
52 else
53 {
54 if (i != v.begin())
55 {
56 out << ", ";
57 }
58 out << *i;
59 }
60 }
61 if (boundary_spaces)
62 {
63 out << " ";
64 }
65 out << end_marker;
66 return out.str();
67}
68
73template <typename Container>
74std::string print_list(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
75{
76 return print_container(v, "[", "]", message, print_index, boundary_spaces);
77}
78
83template <typename Container>
84std::string print_set(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
85{
86 return print_container(v, "{", "}", message, print_index, boundary_spaces);
87}
88
93template <typename MapContainer>
94std::string print_map(const MapContainer& v, const std::string& message = "")
95{
96 std::ostringstream out;
97 if (!message.empty())
98 {
99 out << "--- " << message << "---" << std::endl;
100 }
101 out << "{";
102 for (auto i = v.begin(); i != v.end(); ++i)
103 {
104 if (i != v.begin())
105 {
106 out << ", ";
107 }
108 out << i->first << " -> " << i->second;
109 }
110 out << "}";
111 return out.str();
112}
113
116template <typename Container>
117std::string print_arguments(const Container& v)
118{
119 if (v.empty())
120 {
121 return "";
122 }
123 return print_container(v, "(", ")", "", false, false);
124}
125
126} // namespace detail
127
128} // namespace core
129
130} // namespace mcrl2
131
132#endif // MCRL2_CORE_DETAIL_PRINT_UTILITY_H
Functions for pretty printing ATerms.
std::string print_map(const MapContainer &v, const std::string &message="")
Creates a string representation of a map.
std::string print_container(const Container &v, const std::string &begin_marker="(", const std::string &end_marker=")", const std::string &message="", bool print_index=false, bool boundary_spaces=true)
Creates a string representation of a container using the pp pretty print function.
std::string print_list(const Container &v, const std::string &message="", bool print_index=false, bool boundary_spaces=true)
Creates a string representation of a container.
std::string print_set(const Container &v, const std::string &message="", bool print_index=false, bool boundary_spaces=true)
Creates a string representation of a container.
std::string print_arguments(const Container &v)
Prints a comma separated list of the elements of v. If v is empty, the empty string is returned.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72