Mercurial > hg > svcore
comparison base/TempDirectory.h @ 81:f277a171749d
* Pull out temporary directory management into its own class
* Make sure playback plugins get a default sample path in their original
play parameters configuration
* Save play parameters to .sv file (we aren't reloading yet though)
author | Chris Cannam |
---|---|
date | Tue, 25 Apr 2006 22:14:43 +0000 |
parents | |
children | 604bd4ee3ed4 |
comparison
equal
deleted
inserted
replaced
80:8739096929dd | 81:f277a171749d |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _TEMP_DIRECTORY_H_ | |
17 #define _TEMP_DIRECTORY_H_ | |
18 | |
19 #include <QString> | |
20 #include <QMutex> | |
21 | |
22 #include <exception> | |
23 | |
24 /** | |
25 * A class that manages the creation and removal of a temporary | |
26 * directory tree to store data during the program run. There is one | |
27 * root temporary directory for the program, created on demand and | |
28 * deleted when the program exits. | |
29 * | |
30 * This class is thread safe. | |
31 */ | |
32 | |
33 class TempDirectory | |
34 { | |
35 public: | |
36 static TempDirectory *instance(); | |
37 | |
38 virtual ~TempDirectory(); | |
39 | |
40 class DirectoryCreationFailed : virtual public std::exception | |
41 { | |
42 public: | |
43 DirectoryCreationFailed(QString directory) throw(); | |
44 virtual DirectoryCreationFailed::~DirectoryCreationFailed() throw() { } | |
45 virtual const char *what() const throw(); | |
46 | |
47 protected: | |
48 QString m_directory; | |
49 }; | |
50 | |
51 /** | |
52 * Create the root temporary directory if necessary, and return | |
53 * its path. Throw DirectoryCreationFailed if the directory | |
54 * cannot be created. | |
55 */ | |
56 QString getPath(); | |
57 | |
58 /** | |
59 * Create an immediate subdirectory of the root temporary | |
60 * directory of the given name, if it doesn't already exist, and | |
61 * return its path. Throw DirectoryCreationFailed if the | |
62 * directory cannot be created. | |
63 */ | |
64 QString getSubDirectoryPath(QString subdir); | |
65 | |
66 /** | |
67 * Delete the temporary directory (before exiting). | |
68 */ | |
69 void cleanup(); | |
70 | |
71 protected: | |
72 TempDirectory(); | |
73 void cleanupDirectory(QString tmpDir); | |
74 QString m_tmpdir; | |
75 QMutex m_mutex; | |
76 | |
77 static TempDirectory *m_instance; | |
78 }; | |
79 | |
80 | |
81 #endif |