Configuration file: simplify handling of GlobalInitFile option
There was some overengineering related to the Hook class.master
parent
328e8eef78
commit
1de83b7b12
|
@ -35,16 +35,6 @@
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
Configuration::Hook::Hook(string global_init_file_arg)
|
|
||||||
{
|
|
||||||
if (global_init_file_arg.empty())
|
|
||||||
{
|
|
||||||
cerr << "ERROR: The Hook must have a Global Initialization File argument." << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
hooks["global_init_file"] = move(global_init_file_arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
Configuration::Path::Path(vector<string> includepath_arg)
|
Configuration::Path::Path(vector<string> includepath_arg)
|
||||||
{
|
{
|
||||||
if (includepath_arg.empty())
|
if (includepath_arg.empty())
|
||||||
|
@ -170,7 +160,7 @@ Configuration::getConfigFileInfo(const filesystem::path& conffile_option,
|
||||||
}
|
}
|
||||||
|
|
||||||
string name, computerName, port, userName, password, remoteDrive, remoteDirectory, programPath,
|
string name, computerName, port, userName, password, remoteDrive, remoteDirectory, programPath,
|
||||||
programConfig, matlabOctavePath, operatingSystem, global_init_file;
|
programConfig, matlabOctavePath, operatingSystem;
|
||||||
vector<string> includepath;
|
vector<string> includepath;
|
||||||
int minCpuNbr {0}, maxCpuNbr {0};
|
int minCpuNbr {0}, maxCpuNbr {0};
|
||||||
int numberOfThreadsPerJob {1};
|
int numberOfThreadsPerJob {1};
|
||||||
|
@ -189,10 +179,7 @@ Configuration::getConfigFileInfo(const filesystem::path& conffile_option,
|
||||||
|
|
||||||
if (line == "[node]" || line == "[cluster]" || line == "[hooks]" || line == "[paths]")
|
if (line == "[node]" || line == "[cluster]" || line == "[hooks]" || line == "[paths]")
|
||||||
{
|
{
|
||||||
if (!global_init_file.empty())
|
if (!includepath.empty())
|
||||||
// we were just in [hooks]
|
|
||||||
addHooksConfFileElement(global_init_file);
|
|
||||||
else if (!includepath.empty())
|
|
||||||
// we were just in [paths]
|
// we were just in [paths]
|
||||||
addPathsConfFileElement(includepath);
|
addPathsConfFileElement(includepath);
|
||||||
else
|
else
|
||||||
|
@ -233,8 +220,7 @@ Configuration::getConfigFileInfo(const filesystem::path& conffile_option,
|
||||||
}
|
}
|
||||||
|
|
||||||
name = userName = computerName = port = password = remoteDrive = remoteDirectory
|
name = userName = computerName = port = password = remoteDrive = remoteDirectory
|
||||||
= programPath = programConfig = matlabOctavePath = operatingSystem = global_init_file
|
= programPath = programConfig = matlabOctavePath = operatingSystem = "";
|
||||||
= "";
|
|
||||||
includepath.clear();
|
includepath.clear();
|
||||||
minCpuNbr = maxCpuNbr = 0;
|
minCpuNbr = maxCpuNbr = 0;
|
||||||
numberOfThreadsPerJob = 1;
|
numberOfThreadsPerJob = 1;
|
||||||
|
@ -454,9 +440,7 @@ Configuration::getConfigFileInfo(const filesystem::path& conffile_option,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global_init_file.empty())
|
if (!includepath.empty())
|
||||||
addHooksConfFileElement(global_init_file);
|
|
||||||
else if (!includepath.empty())
|
|
||||||
addPathsConfFileElement(includepath);
|
addPathsConfFileElement(includepath);
|
||||||
else
|
else
|
||||||
addParallelConfFileElement(inNode, inCluster, member_nodes, name, computerName, port, minCpuNbr,
|
addParallelConfFileElement(inNode, inCluster, member_nodes, name, computerName, port, minCpuNbr,
|
||||||
|
@ -467,19 +451,6 @@ Configuration::getConfigFileInfo(const filesystem::path& conffile_option,
|
||||||
configFile.close();
|
configFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Configuration::addHooksConfFileElement(string global_init_file)
|
|
||||||
{
|
|
||||||
if (global_init_file.empty())
|
|
||||||
{
|
|
||||||
cerr << "ERROR: The global initialization file must be passed to the GlobalInitFile option."
|
|
||||||
<< endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
hooks.emplace_back(move(global_init_file));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Configuration::addPathsConfFileElement(vector<string> includepath)
|
Configuration::addPathsConfFileElement(vector<string> includepath)
|
||||||
{
|
{
|
||||||
|
@ -547,15 +518,6 @@ Configuration::addParallelConfFileElement(bool inNode, bool inCluster,
|
||||||
void
|
void
|
||||||
Configuration::checkPass([[maybe_unused]] WarningConsolidation& warnings) const
|
Configuration::checkPass([[maybe_unused]] WarningConsolidation& warnings) const
|
||||||
{
|
{
|
||||||
for (bool global_init_file_declared {false}; const auto& hook : hooks)
|
|
||||||
for (const auto& mapit : hook.get_hooks())
|
|
||||||
if (mapit.first == "global_init_file")
|
|
||||||
if (exchange(global_init_file_declared, true))
|
|
||||||
{
|
|
||||||
cerr << "ERROR: Only one global initialization file may be provided." << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parallel && !parallel_test)
|
if (!parallel && !parallel_test)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -723,9 +685,8 @@ Configuration::getIncludePaths() const
|
||||||
void
|
void
|
||||||
Configuration::writeHooks(ostream& output) const
|
Configuration::writeHooks(ostream& output) const
|
||||||
{
|
{
|
||||||
for (auto hook : hooks)
|
if (!global_init_file.empty())
|
||||||
for (const auto& mapit : hook.get_hooks())
|
output << "options_.global_init_file = '" << global_init_file << "';" << endl;
|
||||||
output << "options_." << mapit.first << " = '" << mapit.second << "';" << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -39,20 +39,6 @@ public:
|
||||||
private:
|
private:
|
||||||
using member_nodes_t = map<string, double>;
|
using member_nodes_t = map<string, double>;
|
||||||
|
|
||||||
class Hook
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Hook(string global_init_file_arg);
|
|
||||||
[[nodiscard]] map<string, string>
|
|
||||||
get_hooks() const
|
|
||||||
{
|
|
||||||
return hooks;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
map<string, string> hooks;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Path
|
class Path
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -94,15 +80,13 @@ private:
|
||||||
const string cluster_name;
|
const string cluster_name;
|
||||||
string firstClusterName;
|
string firstClusterName;
|
||||||
//! Hooks
|
//! Hooks
|
||||||
vector<Hook> hooks;
|
string global_init_file;
|
||||||
//! Paths
|
//! Paths
|
||||||
vector<Path> paths;
|
vector<Path> paths;
|
||||||
//! Cluster Table
|
//! Cluster Table
|
||||||
map<string, Cluster> clusters;
|
map<string, Cluster> clusters;
|
||||||
//! Node Map
|
//! Node Map
|
||||||
map<string, FollowerNode> follower_nodes;
|
map<string, FollowerNode> follower_nodes;
|
||||||
//! Add Hooks
|
|
||||||
void addHooksConfFileElement(string global_init_file);
|
|
||||||
//! Add Paths
|
//! Add Paths
|
||||||
void addPathsConfFileElement(vector<string> includepath);
|
void addPathsConfFileElement(vector<string> includepath);
|
||||||
//! Add a FollowerNode or a Cluster object
|
//! Add a FollowerNode or a Cluster object
|
||||||
|
|
Loading…
Reference in New Issue