]> git.lyx.org Git - lyx.git/blob - src/support/filename.h
remove unused stuff
[lyx.git] / src / support / filename.h
1 // -*- C++ -*-
2 /**
3  * \file filename.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 FILENAME_H
13 #define FILENAME_H
14
15 #include <string>
16
17
18 namespace lyx {
19 namespace support {
20
21
22 /**
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.
26  */
27 class FileName {
28 public:
29         /// Constructor for empty filenames
30         FileName();
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.
35          */
36         explicit FileName(std::string const & abs_filename);
37         virtual ~FileName();
38         virtual void set(std::string const & filename);
39         virtual void erase();
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_; }
44         /**
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.
47          */
48         std::string const toFilesystemEncoding() const;
49 protected:
50         /// The absolute file name.
51         /// The encoding is currently unspecified, anything else than ASCII
52         /// may or may not work.
53         std::string name_;
54 };
55
56
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 &);
62
63
64 /**
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.
69  */
70 class DocFileName : public FileName {
71 public:
72         DocFileName();
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?
75          */
76         DocFileName(std::string const & abs_filename, bool save_abs_path = true);
77
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.
82          */
83         void set(std::string const & filename, std::string const & buffer_path);
84
85         void erase();
86
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;
92
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.
96          *
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
100          *  the mangled name.
101          *
102          *  An example of a mangled name:
103          *  C:/foo bar/baz.eps -> 0C__foo_bar_baz.eps
104          *
105          *  It is guaranteed that
106          *  - two different filenames have different mangled names
107          *  - two FileName instances with the same filename have identical
108          *    mangled names.
109          *
110          *  Only the mangled file name is returned. It is not prepended
111          *  with @c dir.
112          */
113         std::string const
114         mangledFilename(std::string const & dir = std::string()) const;
115
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;
120
121 private:
122         bool save_abs_path_;
123         /// Cache for isZipped() because zippedFile() is expensive
124         mutable bool zipped_;
125         /// Is zipped_ valid?
126         mutable bool zipped_valid_;
127 };
128
129
130 bool operator==(DocFileName const &, DocFileName const &);
131 bool operator!=(DocFileName const &, DocFileName const &);
132
133
134 } // namespace support
135 } // namespace lyx
136
137 #endif