Commit 37533b56 authored by GILLES Sebastien's avatar GILLES Sebastien

#1537 Add a create_if_necessary behaviour for FilesystemNS::Directory.

parent 166d0b37
......@@ -232,6 +232,7 @@ namespace MoReFEM
{
case FilesystemNS::behaviour::overwrite:
case FilesystemNS::behaviour::create:
case FilesystemNS::behaviour::create_if_necessary:
break;
case FilesystemNS::behaviour::ask:
case FilesystemNS::behaviour::quit:
......@@ -289,6 +290,7 @@ namespace MoReFEM
{
case FilesystemNS::behaviour::read:
break;
case FilesystemNS::behaviour::create_if_necessary:
case FilesystemNS::behaviour::overwrite:
case FilesystemNS::behaviour::create:
case FilesystemNS::behaviour::ask:
......
......@@ -123,12 +123,10 @@ namespace MoReFEM::FilesystemNS
{
case behaviour::ask:
case behaviour::overwrite:
Advanced::FilesystemNS::DirectoryNS::Remove(path_, invoking_file, invoking_line);
Advanced::FilesystemNS::DirectoryNS::Remove(path_, invoking_file, invoking_line);
assert(!Advanced::FilesystemNS::DirectoryNS::DoExist(path_));
Advanced::FilesystemNS::DirectoryNS::Create(path_, invoking_file, invoking_line);
break;
case behaviour::ignore:
break;
case behaviour::quit:
{
std::cout << "Directory '" << path_ << "' already exists; an abortion of the program is therefore "
......@@ -136,7 +134,8 @@ namespace MoReFEM::FilesystemNS
throw ExceptionNS::GracefulExit(invoking_file, invoking_line);
}
case behaviour::read:
// Do nothing: we expects it to exist!
case behaviour::create_if_necessary:
case behaviour::ignore:
break;
case behaviour::create:
{
......@@ -153,9 +152,9 @@ namespace MoReFEM::FilesystemNS
{
case behaviour::ask:
case behaviour::overwrite:
case behaviour::ignore:
case behaviour::quit:
case behaviour::create:
case behaviour::create_if_necessary:
Advanced::FilesystemNS::DirectoryNS::Create(path_, invoking_file, invoking_line);
break;
case behaviour::read:
......@@ -166,7 +165,8 @@ namespace MoReFEM::FilesystemNS
throw Exception(oconv.str(), __FILE__, __LINE__);
}
break;
case behaviour::ignore:
break;
}
}
}
......@@ -260,6 +260,9 @@ namespace MoReFEM::FilesystemNS
case behaviour::create:
out << "create";
break;
case behaviour::create_if_necessary:
out << "create_if_necessary";
break;
}
return out;
......
......@@ -31,13 +31,15 @@ namespace MoReFEM::FilesystemNS
* <ul>
* <li> overwrite: Remove the pre-existing one and recreate it.</li>
* <li> quit: Quit the program if the directory exists.</li>
* <li> ignore: Do not create the directory and use the existing one (including possible previous content).</li>
* <li> read: this mode expects the directory to exist and throws an exception otherwise.</li>
* <li> create: create a new directory - it is expected here it doesn't exist yet (and an exception is thrown if it
* does). </li>
* <li> create_if_necessary: create the directory if it doesn't exist yet
* <li> ask: Ask the end user if he wants to override or not. If he chooses not to do so, the program ends.
* Mpi is properly handled (the interface is properly rerouted to root processor which is the sole able to
* communicate with stdin).</li>
* <li> ignore: Do nothing - whether the directory exist or not. This might be useful if you want to set the behaviour later; I would nonetheless not
* recommend using this possibility much as we lose part of the appeal of using a class such as \a Directory doing so.</li>
* </ul>
*/
......@@ -52,9 +54,10 @@ namespace MoReFEM::FilesystemNS
overwrite,
ask,
quit,
ignore,
read,
create
create,
create_if_necessary,
ignore
};
//! \copydoc doxygen_hide_std_stream_out_overload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment