ALPSCore reference
unique_file.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #ifndef ALPS_UTILITY_TEMPORARY_FILENAME_HPP
8 #define ALPS_UTILITY_TEMPORARY_FILENAME_HPP
9 
10 #include <alps/config.hpp>
11 #include <string>
12 #include <boost/noncopyable.hpp>
13 
14 namespace alps {
15  namespace testing {
17  class unique_file : private boost::noncopyable {
18  public:
19  enum action_type {
24  };
25 
26  private:
27  std::string name_;
28  action_type action_;
29 
30  public:
35  explicit unique_file(const std::string& prefix, action_type action=KEEP_AFTER);
36 
38  const std::string& name() const { return name_; }
39 
41  ~unique_file();
42  };
43 
44 
46  inline std::string temporary_filename(const std::string& prefix) {
48  return uf.name();
49  }
50 
51 
52  } // testing::
53 } // alps::
54 #endif // ALPS_UTILITY_TEMPORARY_FILENAME_HPP
~unique_file()
Closes and optionally deletes the file.
Definition: unique_file.cpp:44
const std::string & name() const
Returns temporary file name.
Definition: unique_file.hpp:38
Keep the file when destroying the object.
Definition: unique_file.hpp:21
unique_file(const std::string &prefix, action_type action=KEEP_AFTER)
Generates a random file name with a given prefix.
Definition: unique_file.cpp:27
Remove the file when destroying the object.
Definition: unique_file.hpp:20
Resource manager: manages a file with unique name.
Definition: unique_file.hpp:17
Remove the file after constructing the object only.
Definition: unique_file.hpp:23
std::string temporary_filename(const std::string &prefix)
Convenience function: creates unique named file, returns its name.
Definition: unique_file.hpp:46
Remove the file after constructing the object, remove when destructing too.
Definition: unique_file.hpp:22