changeset 366:68fd4de63eae

create temporary files file a given extension
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Feb 2013 09:32:53 +0100
parents cda6938a8c6f
children 301f2831489c
files Core/Uuid.cpp Core/Uuid.h
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Uuid.cpp	Wed Feb 06 18:01:45 2013 +0100
+++ b/Core/Uuid.cpp	Thu Feb 07 09:32:53 2013 +0100
@@ -96,7 +96,7 @@
     }
 
 
-    TemporaryFile::TemporaryFile()
+    static std::string CreateTemporaryPath(const char* extension)
     {
 #if BOOST_HAS_FILESYSTEM_V3 == 1
       boost::filesystem::path tmpDir = boost::filesystem::temp_directory_path();
@@ -107,8 +107,27 @@
 #endif
 
       // We use UUID to create unique path to temporary files
-      tmpDir /= "Orthanc-" + Orthanc::Toolbox::GenerateUuid();
-      path_ = tmpDir.string();
+      std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid();
+
+      if (extension != NULL)
+      {
+        filename.append(extension);
+      }
+
+      tmpDir /= filename;
+      return tmpDir.string();
+    }
+
+
+    TemporaryFile::TemporaryFile()
+    {
+      path_ = CreateTemporaryPath(NULL);
+    }
+
+
+    TemporaryFile::TemporaryFile(const char* extension)
+    {
+      path_ = CreateTemporaryPath(extension);
     }
 
 
--- a/Core/Uuid.h	Wed Feb 06 18:01:45 2013 +0100
+++ b/Core/Uuid.h	Thu Feb 07 09:32:53 2013 +0100
@@ -59,6 +59,8 @@
     public:
       TemporaryFile();
 
+      TemporaryFile(const char* extension);
+
       ~TemporaryFile();
 
       const std::string& GetPath() const