fw4spl
FileHolder.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <fwCore/spyLog.hpp>
8 #include <boost/filesystem/path.hpp>
9 #include <boost/filesystem/operations.hpp>
10 
11 #include "fwMemory/FileHolder.hpp"
12 
13 namespace fwMemory
14 {
15 
17 {
18  FileAutoDelete(const ::boost::filesystem::path &file) : m_path(file)
19  {
20  }
21 
23  {
24  if(!m_path.empty() && ::boost::filesystem::is_regular_file(m_path))
25  {
26  ::boost::system::error_code ec;
27  ::boost::filesystem::remove(m_path, ec);
28  OSLM_ERROR_IF("file remove failed : " << ec.message(), ec.value()!=0);
29  }
30  }
31 
32  ::boost::filesystem::path m_path;
33 };
34 
35 
36 //-----------------------------------------------------------------------------
37 
38 FileHolder::FileHolder(const ::boost::filesystem::path &file, bool autodelete) :
39  m_path(file)
40 {
41  if (autodelete)
42  {
43  m_autoDelete = std::make_shared< FileAutoDelete >( file );
44  }
45 }
46 
47 //-----------------------------------------------------------------------------
48 
49 
50 } // namespace fwMemory
51 
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
#define OSLM_ERROR_IF(message, cond)
Definition: spyLog.hpp:278