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