mCRL2
Loading...
Searching...
No Matches
pbes_output_tool.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//
9/// \file mcrl2/pbes/pbes_output_tool.h
10/// \brief Base class for tools that produce a (P)BES as output.
11
12#ifndef MCRL2_PBES_PBES_OUTPUT_TOOL_H
13#define MCRL2_PBES_PBES_OUTPUT_TOOL_H
14
15#include "mcrl2/utilities/command_line_interface.h"
16#include "mcrl2/pbes/io.h"
17
18
19
20
21
22namespace mcrl2::pbes_system::tools
23{
24
25/// \brief Base class for filter tools that produce a pbes as output.
26/// \pre Tool provides output_filename()
27template <typename Tool>
28class pbes_output_tool: public Tool
29{
30 protected:
31
32 /// \brief The type of the pbes output format
34
35 /// \brief Returns the file formats that are available for this tool.
36 /// Override this method to change the standard behavior.
37 /// \return The set { pbes, text }
39 {
40 std::set<utilities::file_format> result;
41 result.insert(pbes_system::pbes_format_internal());
42 result.insert(pbes_system::pbes_format_text());
43 result.insert(pbes_system::pbes_format_internal_bes());
44 result.insert(pbes_system::pbes_format_pgsolver());
45 return result;
46 }
47
48 /// \brief Returns the default file format.
49 /// Override this method to change the standard behavior.
50 /// \return The default format is determined based on the extension of the output file.
51 // If this fails, pbes_format_internal() is returned.
52 virtual utilities::file_format default_output_format() const
53 {
54 utilities::file_format result= pbes_system::guess_format(Tool::output_filename());
55 if (result == utilities::file_format())
56 {
58 }
59 return result;
60 }
61
62 /// \brief Add options to an interface description. Also includes
63 /// output format options.
64 /// \param desc An interface description
65 void add_options(utilities::interface_description& desc) override
66 {
67 Tool::add_options(desc);
68 std::set<utilities::file_format> types = available_output_formats();
69 auto option_argument = utilities::make_enum_argument<std::string>("FORMAT");
70 for (const utilities::file_format& type: types)
71 {
72 option_argument.add_value_desc(type.shortname(), type.description(), type == default_output_format());
73 }
74 desc.add_option("out", option_argument, "use output format FORMAT:", 'o');
75 }
76
77 /// \brief Parse non-standard options
78 /// \param parser A command line parser
79 void parse_options(const utilities::command_line_parser& parser) override
80 {
81 Tool::parse_options(parser);
82 m_pbes_output_format = utilities::file_format();
83 if(parser.options.count("out"))
84 {
85 std::set<utilities::file_format> types = available_output_formats();
86 std::string arg = parser.option_argument_as<std::string>("out");
87 for (const utilities::file_format& type: types)
88 {
89 if (type.shortname() == arg)
90 {
91 m_pbes_output_format = type;
92 }
93 }
94 if (m_pbes_output_format == utilities::file_format())
95 {
96 mCRL2log(log::warning) << "Invalid input format given (" << arg << ").\n";
97 }
98 }
99 if (m_pbes_output_format == utilities::file_format())
100 {
101 m_pbes_output_format = default_output_format();
102 mCRL2log(log::verbose) << "Guessing output format: " << m_pbes_output_format.description()
103 << std::endl;
104 }
105 }
106
107
108 public:
109 /// \brief Constructor.
110 /// \param name The name of the tool
111 /// \param author The author(s) of the tool
112 /// \param what_is One-line "what is" description of the tool
113 /// \param tool_description The description of the tool
114 /// \param known_issues Known issues with the tool
115 pbes_output_tool(const std::string& name,
116 const std::string& author,
117 const std::string& what_is,
118 const std::string& tool_description,
119 std::string known_issues = "")
121 {}
122
123 /// \brief Destructor.
124 ~pbes_output_tool() override = default;
125
126 /// \brief Returns the output format
127 /// \return The output format
128 utilities::file_format pbes_output_format() const
129 {
130 return m_pbes_output_format;
131 }
132};
133
134} // namespace mcrl2::pbes_system::tools
135
136
137
138
139
140#endif // MCRL2_PBES_PBES_OUTPUT_TOOL_H
Base class for filter tools that produce a pbes as output.
virtual std::set< utilities::file_format > available_output_formats() const
Returns the file formats that are available for this tool. Override this method to change the standar...
void add_options(utilities::interface_description &desc) override
Add options to an interface description. Also includes output format options.
utilities::file_format m_pbes_output_format
The type of the pbes output format.
~pbes_output_tool() override=default
Destructor.
void parse_options(const utilities::command_line_parser &parser) override
Parse non-standard options.
virtual utilities::file_format default_output_format() const
Returns the default file format. Override this method to change the standard behavior.
utilities::file_format pbes_output_format() const
Returns the output format.
pbes_output_tool(const std::string &name, const std::string &author, const std::string &what_is, const std::string &tool_description, std::string known_issues="")
Constructor.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
const utilities::file_format & pbes_format_internal()
Definition io.h:39