]> git.lyx.org Git - lyx.git/blob - src/support/globbing.h
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / globbing.h
1 // -*- C++ -*-
2 /**
3  * \file globbing.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GLOBBING_H
13 #define GLOBBING_H
14
15 #include <string>
16 #include <vector>
17
18 namespace lyx {
19 namespace support {
20
21 /** Given a string such as
22  *      "<glob> <glob> ... *.{abc,def} <glob>",
23  *  convert the csh-style brace expresions:
24  *      "<glob> <glob> ... *.abc *.def <glob>".
25  *  Requires no system support, so should work equally on Unix, Mac, Win32.
26  */
27 std::string const convert_brace_glob(std::string const & glob);
28
29
30 /** A wrapper for the Posix function 'glob'.
31  *  \param pattern the glob to be expanded. Eg "*.[Ch]".
32  *  \param flags flags to be passed to the system function. See 'man glob'.
33  *  \returns a vector of the files found to match \c pattern.
34  */
35 std::vector<std::string> const glob(std::string const & pattern, int flags = 0);
36
37
38 /** Given a string "<glob> <glob> <glob>", expand each glob in turn.
39  *  Any glob that cannot be expanded is ignored silently.
40  *  Invokes \c convert_brace_glob and \c glob internally, so use only
41  *  on systems supporting the Posix function 'glob'.
42  *  \param mask the string "<glob> <glob> <glob>".
43  *  \param directory (if not empty) the current working directory from
44  *  which \c glob is invoked.
45  *  \returns a vector of all matching file names.
46  */
47 std::vector<std::string> const
48 expand_globs(std::string const & mask,
49              std::string const & directory = std::string());
50
51
52 /** \c FileFilterList parses a Qt-style list of available file filters
53  *  to generate the corresponding vector.
54  *  For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
55  *  will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
56  *  will result in a vector of size 1 in which the description field is empty.
57  */
58 class FileFilterList {
59 public:
60         class Filter {
61                 std::string desc_;
62                 std::string globs_;
63         public:
64                 Filter(std::string const & d, std::string const & g)
65                         : desc_(d), globs_(g) {}
66                 std::string const & description() const { return desc_; }
67                 std::string const & globs() const { return globs_; }
68         };
69
70         /** \param qt_style_filter a list of available file filters.
71          *  Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
72          *  The "All files (*)" filter is always added to the list.
73          */
74         explicit FileFilterList(std::string const & qt_style_filter = std::string());
75         std::vector<Filter> const & filters() const { return filters_; }
76
77         /** \param expand pass each glob through \c convert_brace_glob.
78          *  \returns the equivalent of the string passed to the c-tor.
79          */
80         std::string const str(bool expand) const;
81
82 private:
83         void parse_filter(std::string const & filter);
84         std::vector<Filter> filters_;
85 };
86
87 } // namespace support
88 } // namespace lyx
89
90 #endif // NOT GLOBBING_H