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
31 /** Constructor for nonempty filenames.
32 * explicit because we don't want implicit conversion of relative
33 * paths in function arguments (e.g. of unlink).
34 * \param abs_filename the file in question. Must have an absolute path.
36 explicit FileName(std::string const & abs_filename);
38 virtual void set(std::string const & filename);
40 /// Is this filename empty?
41 bool empty() const { return name_.empty(); }
42 /// get the absolute file name
43 std::string const absFilename() const { return name_; }
45 * Get the file name in the encoding used by the file system.
46 * Only use this for accessing the file, e.g. with an fstream.
48 std::string const toFilesystemEncoding() const;
50 /// The absolute file name.
51 /// The encoding is currently unspecified, anything else than ASCII
52 /// may or may not work.
57 bool operator==(FileName const &, FileName const &);
58 bool operator!=(FileName const &, FileName const &);
59 bool operator<(FileName const &, FileName const &);
60 bool operator>(FileName const &, FileName const &);
61 std::ostream & operator<<(std::ostream &, FileName const &);
65 * Class for storing file names that appear in documents (e. g. child
66 * documents, included figures etc).
67 * The file name must not denote a file in our temporary directory, but a
68 * file that the user chose.
70 class DocFileName : public FileName {
73 /** \param abs_filename the file in question. Must have an absolute path.
74 * \param save_abs_path how is the file to be output to file?
76 DocFileName(std::string const & abs_filename, bool save_abs_path = true);
78 /** \param filename the file in question. May have either a relative
79 * or an absolute path.
80 * \param buffer_path if \c filename has a relative path, generate
81 * the absolute path using this.
83 void set(std::string const & filename, std::string const & buffer_path);
87 bool saveAbsPath() const { return save_abs_path_; }
88 /// \param buffer_path if empty, uses `pwd`
89 std::string const relFilename(std::string const & buffer_path = std::string()) const;
90 /// \param buf_path if empty, uses `pwd`
91 std::string const outputFilename(std::string const & buf_path = std::string()) const;
93 /** @returns a mangled representation of the absolute file name
94 * suitable for use in the temp dir when, for example, converting
95 * an image file to another format.
97 * @param dir the directory that will contain this file with
98 * its mangled name. This information is used by the mangling
99 * algorithm when determining the maximum allowable length of
102 * An example of a mangled name:
103 * C:/foo bar/baz.eps -> 0C__foo_bar_baz.eps
105 * It is guaranteed that
106 * - two different filenames have different mangled names
107 * - two FileName instances with the same filename have identical
110 * Only the mangled file name is returned. It is not prepended
114 mangledFilename(std::string const & dir = std::string()) const;
116 /// \return true if the file is compressed.
117 bool isZipped() const;
118 /// \return the absolute file name without its .gz, .z, .Z extension
119 std::string const unzippedFilename() const;
123 /// Cache for isZipped() because zippedFile() is expensive
124 mutable bool zipped_;
125 /// Is zipped_ valid?
126 mutable bool zipped_valid_;
130 bool operator==(DocFileName const &, DocFileName const &);
131 bool operator!=(DocFileName const &, DocFileName const &);
134 } // namespace support