Skip to content

Commit

Permalink
Model directory is created if not existing and a runtime exception is… (
Browse files Browse the repository at this point in the history
#5)

… thrown if creation fails, and model file name is logged
  • Loading branch information
GeirHo authored Jul 5, 2024
2 parents de1ea5e + eacbd5f commit 04bda1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"${workspaceFolder}/**",
"/usr/include/c++/14/",
"/usr/include/linux/",
"/usr/include/",
"/home/GHo/Documents/Code/NebulOuS/Solver/",
"/home/GHo/Documents/Code/Theron++/",
"/home/GHo/Documents/Code/CxxOpts/include/",
Expand All @@ -31,6 +32,7 @@
"/home/GHo/Documents/Code/Theron++/",
"/home/GHo/Documents/Code/CxxOpts/include/",
"/opt/AMPL/amplapi/include/",
"/usr/include/",
"/usr/include/c++/14/",
"/usr/include/linux/"
],
Expand Down
3 changes: 3 additions & 0 deletions AMPLSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ std::string AMPLSolver::SaveFile( std::string_view TheName,

if( TheFile.is_open() )
{
Theron::ConsoleOutput Output;
Output << "AMPL Solver saving the file: " << TheFileName << std::endl;

TheFile << TheContent;
TheFile.close();
return TheFileName;
Expand Down
18 changes: 17 additions & 1 deletion SolverComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,24 @@ int main( int NumberOfCLIOptions, char ** CLIOptionStrings )

std::filesystem::path ModelDirectory( CLIValues["ModelDir"].as<std::string>() );

if( ModelDirectory.empty() || !std::filesystem::exists( ModelDirectory ) )
if( ModelDirectory.empty() )
ModelDirectory = std::filesystem::temp_directory_path();
else if ( !std::filesystem::exists( ModelDirectory ) )
{
if( !std::filesystem::create_directory( ModelDirectory ) )
{
std::source_location Location = std::source_location::current();
std::ostringstream ErrorMessage;

ErrorMessage << "[" << Location.file_name() << " at line "
<< Location.line() << "in function "
<< Location.function_name() <<"] "
<< "The requested model directory " << ModelDirectory
<< " does not exist and cannot be created";

throw std::runtime_error( ErrorMessage.str() );
}
}

// --------------------------------------------------------------------------
// AMQ options
Expand Down

0 comments on commit 04bda1b

Please sign in to comment.