Home | History | Annotate | Download | only in quipper
      1 // Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMIUMOS_WIDE_PROFILING_SCOPED_TEMP_PATH_H_
      6 #define CHROMIUMOS_WIDE_PROFILING_SCOPED_TEMP_PATH_H_
      7 
      8 #include <string>
      9 
     10 #include "base/macros.h"
     11 
     12 #include "compat/string.h"
     13 
     14 namespace quipper {
     15 
     16 // Used to create a temporary file or directory.
     17 class ScopedTempPath {
     18  public:
     19   ScopedTempPath() {}
     20   // The temporary path will be removed when the object is destroyed.
     21   virtual ~ScopedTempPath();
     22   const string& path() const { return path_; }
     23 
     24  protected:
     25   string path_;
     26 
     27  private:
     28   DISALLOW_COPY_AND_ASSIGN(ScopedTempPath);
     29 };
     30 
     31 class ScopedTempFile : public ScopedTempPath {
     32  public:
     33   // Create a temporary file.  If successful, the path will be stored in
     34   // |path_|.  If not, |path_| will be an empty string.
     35   ScopedTempFile();
     36   // A temporary file is created using mkstemp() by adding "XXXXXX" to
     37   // |prefix|.
     38   explicit ScopedTempFile(string prefix);
     39 };
     40 
     41 class ScopedTempDir : public ScopedTempPath {
     42  public:
     43   // Create a temporary directory.  If successful, the path will be stored in
     44   // |path_|.  If not, |path_| will be an empty string.
     45   ScopedTempDir();
     46   // A temporary file is created using mkdtemp() by adding "XXXXXX" to
     47   // |prefix|.
     48   explicit ScopedTempDir(string prefix);
     49 };
     50 
     51 }  // namespace quipper
     52 
     53 #endif  // CHROMIUMOS_WIDE_PROFILING_SCOPED_TEMP_PATH_H_
     54