]> git.lyx.org Git - lyx.git/blob - src/support/TempFile.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / support / TempFile.h
1 // -*- C++ -*-
2 /**
3  * \file TempFile.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Georg Baum
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef TEMPFILE_H
13 #define TEMPFILE_H
14
15 #include <string>
16
17 namespace lyx {
18 namespace support {
19
20 class FileName;
21
22 /**
23  * Class for safely creating temporary files without race conditions.
24  * The file is created in the constructor, and deleted in the destructor.
25  * You may do anything with the file (including deletion), but the instance
26  * of this class must stay alive as long as the file is needed.
27  * There is only one exception to this rule:
28  * If the file is supposed to be used by a different process then you need
29  * to be aware of OS specific file locking semantics: On windows, the file
30  * is opened with exclusive rights for the process which opened it. This
31  * is not the case on other OSes. Therefore, if the file is supposed to be
32  * used by a different process you need to sometheing similar to TempName
33  * in InsetExternal.cpp.
34  */
35 class TempFile {
36         /// noncopyable
37         TempFile(TempFile const &);
38         /// nonassignable
39         TempFile & operator=(TempFile const &);
40 public:
41         /**
42          *Create a temporary file with the given mask.
43          * \p mask must be in filesystem encoding, the template file
44          * will be created in the global temporary directory as given
45          * by 'package().temp_dir()'.
46          * If the mask contains "XXXXXX" this portion will be replaced by
47          * a uniquely generated string. If it does not contain this portion,
48          * it will be automatically appended using a dot. Therefore, please
49          * specify the "XXXXXX" portion if the extension of the generated
50          * name is important (e.g. for the converter machinery).
51          */
52         TempFile(std::string const & mask);
53         TempFile(FileName const & temp_dir, std::string const & mask);
54         ~TempFile();
55         /**
56          * Get the name of the temporary file.
57          * This is empty if the file could not be created.
58          */
59         FileName name() const;
60         /**
61          * Set whether the file should be automatically deleted in the
62          * destructor.
63          * Automatic deletion is the default, but it can be switched off if
64          * the file should be kept, because it should be renamed afterwards.
65          */
66         void setAutoRemove(bool autoremove);
67 private:
68         ///
69         struct Private;
70         Private * d;
71 };
72
73 } // namespace support
74 } // namespace lyx
75
76 #endif