mCRL2
Loading...
Searching...
No Matches
file_utility.h
Go to the documentation of this file.
1// Author(s): Sjoerd Cranen
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/utilities/file_utility.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_UTILITIES_FILE_UTILITY_H
13#define MCRL2_UTILITIES_FILE_UTILITY_H
14
15#include "mcrl2/utilities/exception.h"
16#include "mcrl2/utilities/logger.h"
17#include <fstream>
18
19namespace mcrl2
20{
21
22namespace utilities
23{
24
25/// \brief Returns true if the given filename has the extension ext. The extension does not start with a dot.
26inline
27bool has_extension(const std::string& filename, const std::string& extension)
28{
29 assert(extension.size()>=1 && extension[0]!='.'); // The extension should not start with a dot and consist out of at least one character.
30 std::string dotted_extension="."+extension;
31 if (filename.size()<dotted_extension.size())
32 {
33 return false;
34 }
35 const std::string filename_extension = filename.substr(filename.size()-dotted_extension.size());
36 return filename_extension==dotted_extension;
37}
38
40{
41 protected:
46
47 public:
49 : file_format("unknown", "Unknown format", false)
50 {
51 }
52
53 file_format(const std::string& shortname, const std::string& description, bool is_text_format)
54 : m_shortname(shortname), m_description(description), m_text_format(is_text_format)
55 { }
56
57 void add_extension(const std::string& ext)
58 {
59 m_extensions.push_back(ext);
60 }
61
62 const std::string& shortname() const { return m_shortname; }
63
64 const std::string& description() const { return m_description; }
65
66 bool text_format() const { return m_text_format; }
67
68 bool matches(const std::string& filename) const
69 {
70 for (const std::string& ext: m_extensions)
71 {
72 if (has_extension(filename,ext))
73 {
74 return true;
75 }
76 }
77 return false;
78 }
79
80 bool operator==(const file_format& other) const
81 {
82 return m_shortname == other.m_shortname;
83 }
84
85 bool operator<(const file_format& other) const
86 {
87 return m_shortname < other.m_shortname;
88 }
89};
90
91inline
92std::ostream& operator<<(std::ostream& stream, const file_format& format)
93{
94 return stream << format.shortname();
95}
96
97inline
98bool file_exists(const std::string& filename)
99{
100 if (FILE * file = fopen(filename.c_str(), "r"))
101 {
102 fclose(file);
103 return true;
104 }
105 return false;
106}
107
108} // namespace utilities
109
110} // namespace mcrl2
111
112#endif // MCRL2_UTILITIES_FILE_UTILITY_H
std::vector< std::string > m_extensions
const std::string & shortname() const
bool operator==(const file_format &other) const
bool operator<(const file_format &other) const
const std::string & description() const
Namespace for all data library functionality.
Definition data.cpp:22
rewrite_strategy
The strategy of the rewriter.
The main namespace for the PBES library.
void lps2pbes(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &output_format, const std::string &formula_filename, bool timed, bool structured, bool unoptimized, bool preprocess_modal_operators, bool generate_counter_example, bool check_only)
Definition lps2pbes.h:42
void pbesabstract(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, const std::string &parameter_selection, bool value_true)
pbes_rewriter_type
An enumerated type for the available pbes rewriters.
void txt2pbes(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &output_format, bool normalize)
Definition txt2pbes.h:21
void pbesstategraph(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, const pbesstategraph_options &options)
void lpsbisim2pbes(const std::string &input_filename1, const std::string &input_filename2, const std::string &output_filename, const utilities::file_format &output_format, bisimulation_type type, bool normalize)
void complps2pbes(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &output_format, const std::string &formula_filename)
void pbesrewr(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, data::rewrite_strategy rewrite_strategy, pbes_rewriter_type rewriter_type)
Definition pbesrewr.h:31
void pbesinfo(const std::string &input_filename, const std::string &input_file_message, const utilities::file_format &file_format, bool opt_full)
Definition pbesinfo.h:22
void pbespareqelm(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, data::rewrite_strategy rewrite_strategy, pbes_rewriter_type rewriter_type, bool ignore_initial_state)
void pbespp(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, core::print_format_type format, bool use_pfnf_printer)
Definition pbespp.h:22
void pbesparelm(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format)
Definition pbesparelm.h:22
bisimulation_type
An enumerated type for the available bisimulation types.
void pbesconstelm(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, data::rewrite_strategy rewrite_strategy, pbes_rewriter_type rewriter_type, bool compute_conditions, bool remove_redundant_equations, bool check_quantifiers)
void pbesabsinthe(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, const std::string &abstraction_file, absinthe_strategy strategy, bool print_used_function_symbols, bool enable_logging)
absinthe_strategy
The approximation strategies of the absinthe tool.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const