Merge master.
[dcpomatic.git] / src / lib / util.cc
index 1339be73d1044cf58192454984dc5a3de2a9f2c7..40e9d9c2eed730795a8f8476533ae16290c403c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
     Copyright (C) 2000-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
@@ -957,3 +957,38 @@ dependency_version_summary ()
 
        return s.str ();
 }
+
+ScopedTemporary::ScopedTemporary ()
+       : _open (0)
+{
+       _file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path ();
+}
+
+ScopedTemporary::~ScopedTemporary ()
+{
+       close ();       
+       boost::system::error_code ec;
+       boost::filesystem::remove (_file, ec);
+}
+
+char const *
+ScopedTemporary::c_str () const
+{
+       return _file.string().c_str ();
+}
+
+FILE*
+ScopedTemporary::open (char const * params)
+{
+       _open = fopen (c_str(), params);
+       return _open;
+}
+
+void
+ScopedTemporary::close ()
+{
+       if (_open) {
+               fclose (_open);
+               _open = 0;
+       }
+}