From 4389e5320dcaf2e4392eb87073fa545876157f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 11 Dec 2023 17:16:49 +0100 Subject: [PATCH] Rename files, classes and variables in relation to the configuration file In particular, makes clearer the distinction between configuration and configuration file. The former includes information that is not in the latter (command-line options.) --- src/{ConfigFile.cc => Configuration.cc} | 50 ++++++++++++------------- src/{ConfigFile.hh => Configuration.hh} | 19 +++++----- src/DynareMain.cc | 22 +++++------ src/ModFile.cc | 9 ++--- src/ModFile.hh | 4 +- src/meson.build | 2 +- 6 files changed, 53 insertions(+), 53 deletions(-) rename src/{ConfigFile.cc => Configuration.cc} (94%) rename src/{ConfigFile.hh => Configuration.hh} (88%) diff --git a/src/ConfigFile.cc b/src/Configuration.cc similarity index 94% rename from src/ConfigFile.cc rename to src/Configuration.cc index 3c25a74f..b03b9820 100644 --- a/src/ConfigFile.cc +++ b/src/Configuration.cc @@ -22,7 +22,7 @@ #include #include -#include "ConfigFile.hh" +#include "Configuration.hh" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" @@ -98,9 +98,9 @@ Cluster::Cluster(member_nodes_t member_nodes_arg) : member_nodes {move(member_no } } -ConfigFile::ConfigFile(bool parallel_arg, bool parallel_test_arg, - bool parallel_follower_open_mode_arg, bool parallel_use_psexec_arg, - string cluster_name_arg) : +Configuration::Configuration(bool parallel_arg, bool parallel_test_arg, + bool parallel_follower_open_mode_arg, bool parallel_use_psexec_arg, + string cluster_name_arg) : parallel {parallel_arg}, parallel_test {parallel_test_arg}, parallel_follower_open_mode {parallel_follower_open_mode_arg}, @@ -110,12 +110,12 @@ ConfigFile::ConfigFile(bool parallel_arg, bool parallel_test_arg, } void -ConfigFile::getConfigFileInfo(const filesystem::path& config_file) +Configuration::getConfigFileInfo(const filesystem::path& conffile_option) { using namespace boost; ifstream configFile; - if (config_file.empty()) + if (conffile_option.empty()) { filesystem::path defaultConfigFile; // Test OS and try to open default file @@ -162,10 +162,10 @@ ConfigFile::getConfigFileInfo(const filesystem::path& config_file) } else { - configFile.open(config_file, fstream::in); + configFile.open(conffile_option, fstream::in); if (!configFile.is_open()) { - cerr << "ERROR: Couldn't open file " << config_file.string() << endl; + cerr << "ERROR: Couldn't open file " << conffile_option.string() << endl; exit(EXIT_FAILURE); } } @@ -469,7 +469,7 @@ ConfigFile::getConfigFileInfo(const filesystem::path& config_file) } void -ConfigFile::addHooksConfFileElement(string global_init_file) +Configuration::addHooksConfFileElement(string global_init_file) { if (global_init_file.empty()) { @@ -482,7 +482,7 @@ ConfigFile::addHooksConfFileElement(string global_init_file) } void -ConfigFile::addPathsConfFileElement(vector includepath) +Configuration::addPathsConfFileElement(vector includepath) { if (includepath.empty()) { @@ -494,15 +494,15 @@ ConfigFile::addPathsConfFileElement(vector includepath) } void -ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, - const member_nodes_t& member_nodes, const string& name, - const string& computerName, const string& port, - int minCpuNbr, int maxCpuNbr, const string& userName, - const string& password, const string& remoteDrive, - const string& remoteDirectory, const string& programPath, - const string& programConfig, const string& matlabOctavePath, - bool singleCompThread, int numberOfThreadsPerJob, - const string& operatingSystem) +Configuration::addParallelConfFileElement(bool inNode, bool inCluster, + const member_nodes_t& member_nodes, const string& name, + const string& computerName, const string& port, + int minCpuNbr, int maxCpuNbr, const string& userName, + const string& password, const string& remoteDrive, + const string& remoteDirectory, const string& programPath, + const string& programConfig, + const string& matlabOctavePath, bool singleCompThread, + int numberOfThreadsPerJob, const string& operatingSystem) { //! ADD NODE if (inNode) @@ -546,7 +546,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, } void -ConfigFile::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()) @@ -684,7 +684,7 @@ ConfigFile::checkPass([[maybe_unused]] WarningConsolidation& warnings) const } void -ConfigFile::transformPass() +Configuration::transformPass() { if (!parallel && !parallel_test) return; @@ -711,7 +711,7 @@ ConfigFile::transformPass() } vector -ConfigFile::getIncludePaths() const +Configuration::getIncludePaths() const { vector include_paths; for (auto path : paths) @@ -722,7 +722,7 @@ ConfigFile::getIncludePaths() const } void -ConfigFile::writeHooks(ostream& output) const +Configuration::writeHooks(ostream& output) const { for (auto hook : hooks) for (const auto& mapit : hook.get_hooks()) @@ -730,7 +730,7 @@ ConfigFile::writeHooks(ostream& output) const } void -ConfigFile::writeCluster(ostream& output) const +Configuration::writeCluster(ostream& output) const { if (!parallel && !parallel_test) return; @@ -804,7 +804,7 @@ ConfigFile::writeCluster(ostream& output) const } void -ConfigFile::writeEndParallel(ostream& output) const +Configuration::writeEndParallel(ostream& output) const { if ((!parallel && !parallel_test) || !parallel_follower_open_mode) return; diff --git a/src/ConfigFile.hh b/src/Configuration.hh similarity index 88% rename from src/ConfigFile.hh rename to src/Configuration.hh index 29db1bb1..8e8a59e4 100644 --- a/src/ConfigFile.hh +++ b/src/Configuration.hh @@ -17,8 +17,8 @@ * along with Dynare. If not, see . */ -#ifndef CONFIG_FILE_HH -#define CONFIG_FILE_HH +#ifndef CONFIGURATION_HH +#define CONFIGURATION_HH #include #include @@ -64,7 +64,7 @@ public: class FollowerNode { - friend class ConfigFile; + friend class Configuration; public: FollowerNode(string computerName_arg, string port_arg, int minCpuNbr_arg, int maxCpuNbr_arg, @@ -86,7 +86,7 @@ protected: class Cluster { - friend class ConfigFile; + friend class Configuration; public: explicit Cluster(member_nodes_t member_nodes_arg); @@ -95,12 +95,13 @@ protected: member_nodes_t member_nodes; }; -//! The abstract representation of a "config" file -class ConfigFile +/* The abstract representation of the configuration. + Merges information from the command-line and from the configuration file. */ +class Configuration { public: - ConfigFile(bool parallel_arg, bool parallel_test_arg, bool parallel_follower_open_mode_arg, - bool parallel_use_psexec_arg, string cluster_name); + Configuration(bool parallel_arg, bool parallel_test_arg, bool parallel_follower_open_mode_arg, + bool parallel_use_psexec_arg, string cluster_name); private: const bool parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec; @@ -130,7 +131,7 @@ private: public: //! Parse config file - void getConfigFileInfo(const filesystem::path& parallel_config_file); + void getConfigFileInfo(const filesystem::path& conffile_option); //! Check Pass void checkPass(WarningConsolidation& warnings) const; //! Check Pass diff --git a/src/DynareMain.cc b/src/DynareMain.cc index ea63400a..8bf68792 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -31,7 +31,7 @@ #include -#include "ConfigFile.hh" +#include "Configuration.hh" #include "ExtendedPreprocessorTypes.hh" #include "ModFile.hh" #include "ParsingDriver.hh" @@ -53,7 +53,7 @@ usage() cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] " "[savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] " - "[conffile=parallel_config_path_and_filename] [parallel_follower_open_mode] " + "[conffile=path_to_config_file] [parallel_follower_open_mode] " "[parallel_test] [parallel_use_psexec=true|false]" << " [-D[=]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] " "[compute_xrefs] [output=second|third] [language=matlab|julia]" @@ -142,7 +142,7 @@ main(int argc, char** argv) bool console = false; bool nograph = false; bool nointeractive = false; - filesystem::path parallel_config_file; + filesystem::path conffile; bool parallel = false; string cluster_name; bool parallel_follower_open_mode @@ -234,7 +234,7 @@ main(int argc, char** argv) cerr << "Incorrect syntax for conffile option" << endl; usage(); } - parallel_config_file = s.substr(9); + conffile = s.substr(9); } else if (s == "parallel_follower_open_mode" || s == "parallel_slave_open_mode") // Kept for backward compatibility, see #86 @@ -461,15 +461,15 @@ main(int argc, char** argv) WarningConsolidation warnings(no_warn); // Process config file - ConfigFile config_file(parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec, - cluster_name); - config_file.getConfigFileInfo(parallel_config_file); - config_file.checkPass(warnings); - config_file.transformPass(); + Configuration config {parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec, + cluster_name}; + config.getConfigFileInfo(conffile); + config.checkPass(warnings); + config.transformPass(); // If Include option was passed to the [paths] block of the config file, add // it to paths before macroprocessing - for (const auto& it : config_file.getIncludePaths()) + for (const auto& it : config.getIncludePaths()) paths.emplace_back(it); /* @@ -540,7 +540,7 @@ main(int argc, char** argv) mod_file->writeJuliaOutput(basename); else mod_file->writeMOutput(basename, clear_all, clear_global, no_warn, console, nograph, - nointeractive, config_file, check_model_changes, minimal_workspace, + nointeractive, config, check_model_changes, minimal_workspace, compute_xrefs, mexext, matlabroot, onlymodel, gui, notime); /* Ensures that workers are not destroyed before they finish compiling. diff --git a/src/ModFile.cc b/src/ModFile.cc index a63bc673..eaa9a435 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -27,7 +27,6 @@ #include #include "ComputingTasks.hh" -#include "ConfigFile.hh" #include "ModFile.hh" #include "Shocks.hh" @@ -843,7 +842,7 @@ ModFile::remove_directory_with_matlab_lock(const filesystem::path& dir) void ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn, - bool console, bool nograph, bool nointeractive, const ConfigFile& config_file, + bool console, bool nograph, bool nointeractive, const Configuration& config, bool check_model_changes, bool minimal_workspace, bool compute_xrefs, const string& mexext, const filesystem::path& matlabroot, bool onlymodel, bool gui, bool notime) const @@ -916,7 +915,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, << "% Some global variables initialization" << endl << "%" << endl; if (!onlymodel) - config_file.writeHooks(mOutputFile); + config.writeHooks(mOutputFile); mOutputFile << "global_initialization;" << endl; if (minimal_workspace) @@ -1002,7 +1001,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, } if (!onlymodel) - config_file.writeCluster(mOutputFile); + config.writeCluster(mOutputFile); if (bytecode) mOutputFile << "if exist('bytecode') ~= 3" << endl @@ -1131,7 +1130,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, << "_results.mat'], 'options_mom_', '-append');" << endl << "end" << endl; - config_file.writeEndParallel(mOutputFile); + config.writeEndParallel(mOutputFile); if (!no_warn) { diff --git a/src/ModFile.hh b/src/ModFile.hh index a1e15cec..440fc01f 100644 --- a/src/ModFile.hh +++ b/src/ModFile.hh @@ -26,7 +26,7 @@ #include #include -#include "ConfigFile.hh" +#include "Configuration.hh" #include "DynamicModel.hh" #include "ExtendedPreprocessorTypes.hh" #include "ExternalFunctionsTable.hh" @@ -176,7 +176,7 @@ public: \param compute_xrefs if true, equation cross references will be computed */ void writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn, - bool console, bool nograph, bool nointeractive, const ConfigFile& config_file, + bool console, bool nograph, bool nointeractive, const Configuration& config, bool check_model_changes, bool minimal_workspace, bool compute_xrefs, const string& mexext, const filesystem::path& matlabroot, bool onlymodel, bool gui, bool notime) const; diff --git a/src/meson.build b/src/meson.build index f3829776..4dd87161 100644 --- a/src/meson.build +++ b/src/meson.build @@ -42,7 +42,7 @@ preprocessor_src = [ 'ComputingTasks.cc', 'ParsingDriver.cc', 'DataTree.cc', 'ModFile.cc', - 'ConfigFile.cc', + 'Configuration.cc', 'Statement.cc', 'ExprNode.cc', 'VariableDependencyGraph.cc',