Thrill  0.1
temporary_directory.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/vfs/temporary_directory.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015 Alexander Noe <[email protected]>
7  * Copyright (C) 2015-2016 Timo Bingmann <[email protected]>
8  *
9  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
10  ******************************************************************************/
11 
12 #pragma once
13 #ifndef THRILL_VFS_TEMPORARY_DIRECTORY_HEADER
14 #define THRILL_VFS_TEMPORARY_DIRECTORY_HEADER
15 
16 #include <string>
17 
18 namespace thrill {
19 namespace vfs {
20 
21 /*!
22  * A class which creates a temporary directory in the current directory and
23  * returns it via get(). When the object is destroyed the temporary directory is
24  * wiped non-recursively.
25  */
27 {
28 public:
29  //! Create a temporary directory, returns its name without trailing /.
30  static std::string make_directory(const char* sample = "thrill-testsuite-");
31 
32  //! wipe temporary directory NON RECURSIVELY!
33  static void wipe_directory(const std::string& tmp_dir, bool do_rmdir);
34 
36  : dir_(make_directory())
37  { }
38 
40  wipe_directory(dir_, true);
41  }
42 
43  //! non-copyable: delete copy-constructor
44  TemporaryDirectory(const TemporaryDirectory&) = delete;
45  //! non-copyable: delete assignment operator
47 
48  //! return the temporary directory name
49  const std::string& get() const { return dir_; }
50 
51  //! wipe contents of directory
52  void wipe() const {
53  wipe_directory(dir_, false);
54  }
55 
56 private:
58 };
59 
60 } // namespace vfs
61 } // namespace thrill
62 
63 #endif // !THRILL_VFS_TEMPORARY_DIRECTORY_HEADER
64 
65 /******************************************************************************/
void wipe() const
wipe contents of directory
TemporaryDirectory & operator=(const TemporaryDirectory &)=delete
non-copyable: delete assignment operator
static std::string make_directory(const char *sample="thrill-testsuite-")
Create a temporary directory, returns its name without trailing /.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
static void wipe_directory(const std::string &tmp_dir, bool do_rmdir)
wipe temporary directory NON RECURSIVELY!
A class which creates a temporary directory in the current directory and returns it via get()...