4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
23 * Class for storing file names.
24 * The file name may be empty. If it is not empty it is an absolute path.
25 * The file may or may not exist.
29 /// Constructor for empty filenames (only needed for DocFileName)
32 /** Constructor for nonempty filenames.
33 * \param abs_filename the file in question. Must have an absolute path.
35 FileName(std::string const & abs_filename);
36 /// Is this filename empty?
37 bool empty() const { return name_.empty(); }
38 /// get the absolute file name
39 std::string const absFilename() const { return name_; }
41 /// The absolute file name.
42 /// The encoding is currently unspecified, anything else than ASCII
43 /// may or may not work.
48 bool operator==(FileName const &, FileName const &);
49 bool operator!=(FileName const &, FileName const &);
53 * Class for storing file names that appear in documents (e. g. child
54 * documents, included figures etc).
55 * The file name must not denote a file in our temporary directory, but a
56 * file that the user chose.
58 class DocFileName : public FileName {
61 /** \param abs_filename the file in question. Must have an absolute path.
62 * \param save_abs_path how is the file to be output to file?
64 DocFileName(std::string const & abs_filename, bool save_abs_path = true);
66 /** \param filename the file in question. May have either a relative
67 * or an absolute path.
68 * \param buffer_path if \c filename has a relative path, generate
69 * the absolute path using this.
71 void set(std::string const & filename, std::string const & buffer_path);
75 bool saveAbsPath() const { return save_abs_path_; }
76 /// \param buffer_path if empty, uses `pwd`
77 std::string const relFilename(std::string const & buffer_path = std::string()) const;
78 /// \param buf_path if empty, uses `pwd`
79 std::string const outputFilename(std::string const & buf_path = std::string()) const;
81 /** @returns a mangled representation of the absolute file name
82 * suitable for use in the temp dir when, for example, converting
83 * an image file to another format.
85 * @param dir the directory that will contain this file with
86 * its mangled name. This information is used by the mangling
87 * algorithm when determining the maximum allowable length of
90 * An example of a mangled name:
91 * C:/foo bar/baz.eps -> 0C__foo_bar_baz.eps
93 * It is guaranteed that
94 * - two different filenames have different mangled names
95 * - two FileName instances with the same filename have identical
98 * Only the mangled file name is returned. It is not prepended
102 mangledFilename(std::string const & dir = std::string()) const;
104 /// \return true if the file is compressed.
105 bool isZipped() const;
106 /// \return the absolute file name without its .gz, .z, .Z extension
107 std::string const unzippedFilename() const;
111 /// Cache for isZipped() because zippedFile() is expensive
112 mutable bool zipped_;
113 /// Is zipped_ valid?
114 mutable bool zipped_valid_;
118 bool operator==(DocFileName const &, DocFileName const &);
119 bool operator!=(DocFileName const &, DocFileName const &);
122 } // namespace support